-
Notifications
You must be signed in to change notification settings - Fork 58
/
refresh-copyright-and-license.pl
executable file
·146 lines (124 loc) · 3.41 KB
/
refresh-copyright-and-license.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/perl
$| = 1;
#
# Util routines
#
sub write_if_changed {
my $origtext = shift;
my $filetext = shift;
my $file = shift;
if ( $origtext ne $filetext ) {
print "Refreshing $file with new copyright text.";
open( OUT, ">", $file );
print OUT $filetext;
close(OUT);
print "\n";
}
else {
print "Skipping $file, no changes.\n";
}
}
sub slurp {
my $file = shift;
return do { local ($/); my $fh; open( $fh, $file ); <$fh> };
}
#
# Load in master files
#
my $lic_text = slurp("COPYING");
my $copy_text = slurp("copyright.txt");
if ( $ARGV[0] eq "--blank" ) {
shift @ARGV;
$copy_text = "";
$lic_text = "";
}
#
# Generate the src/LICENSE.h file
#
my $file = "src/LICENSE.h";
my $origtext = slurp($file);
my $tmp = "static const char *LicenseText = ";
$tmp .= " \"<html><body><pre><font size=-1>\\n\"\n";
foreach my $ln ( split( /[\r\n]/, $lic_text ) ) {
$ln =~ s/\\/\\\\/g;
$ln =~ s/"/\\"/g;
$tmp .= " \"$ln\\n\"\n";
}
$tmp .= " \"</font></pre></body></html>\\n\"\n;\n";
write_if_changed( $origtext, $tmp, $file );
#
# Generate the src/COPYRIGHT.h file
#
my $file = "src/COPYRIGHT.h";
my $origtext = slurp($file);
my $tmp = "static const char *CopyrightText = ";
$tmp .= " \"<pre>\\n\"\n";
foreach my $ln ( split( /[\r\n]/, $copy_text ) ) {
$ln =~ s/\\/\\\\/g;
$ln =~ s/"/\\"/g;
$tmp .= " \"$ln\\n\"\n";
}
$tmp .= " \"</pre>\\n\"\n;\n";
write_if_changed( $origtext, $tmp, $file );
#
# Generate the replacement C-style copyright
#
my $c_style = "\n/* BEGIN_COMMON_COPYRIGHT_HEADER\n *\n";
foreach my $ln ( split( /[\r\n]/, $copy_text ) ) {
$c_style .= " * $ln\n";
}
$c_style .= " *\n * END_COMMON_COPYRIGHT_HEADER */\n\n";
#
# Update all the C-style copyright text entries
#
foreach $file ( glob("src/*.h"), glob("src/*/*.h"), glob("src/*.cpp"),
glob("src/*/*.cpp") )
{
next if ( $file eq "src/LICENSE.h" );
next if ( $file eq "src/COPYRIGHT.h" );
local ($/);
my $filetext = slurp($file);
my $origtext = $filetext;
$filetext =~
s|\s*/\*\s*BEGIN_COMMON_COPYRIGHT_HEADER.*END_COMMON_COPYRIGHT_HEADER\s*\*/\s*|$c_style|sx;
write_if_changed( $origtext, $filetext, $file );
}
#
# Generate the replacement plain-style copyright
#
my $plain_style = "\n\nBEGIN_COMMON_COPYRIGHT_HEADER\n\n";
foreach my $ln ( split( /[\r\n]/, $copy_text ) ) {
$plain_style .= "$ln\n";
}
$plain_style .= "\nEND_COMMON_COPYRIGHT_HEADER\n\n";
#
# Update all the C-style copyright text entries
#
foreach $file ( "README", "debian/copyright" ) {
local ($/);
my $filetext = slurp($file);
my $origtext = $filetext;
$filetext =~
s|\s*BEGIN_COMMON_COPYRIGHT_HEADER.*END_COMMON_COPYRIGHT_HEADER\s*|$plain_style|sx;
write_if_changed( $origtext, $filetext, $file );
}
#
# Generate the replacement shell-style copyright
#
my $shell_style = "\n\n# BEGIN_COMMON_COPYRIGHT_HEADER\n#\n";
foreach my $ln ( split( /[\r\n]/, $copy_text ) ) {
$shell_style .= "# $ln\n";
}
$shell_style .= "#\n# END_COMMON_COPYRIGHT_HEADER\n\n";
#
# Update all the C-style copyright text entries
#
foreach $file ( glob("Makefile*"), glob("*/Makefile*"), glob("*/*/Makefile*") )
{
local ($/);
my $filetext = slurp($file);
my $origtext = $filetext;
$filetext =~
s|\s*\#\s*BEGIN_COMMON_COPYRIGHT_HEADER.*END_COMMON_COPYRIGHT_HEADER\s*|$shell_style|sx;
write_if_changed( $origtext, $filetext, $file );
}