extract-contrib-string.pl revision 1.2.14.1 1 #!/usr/bin/env perl
2 #
3 # Copyright (c) 2004 Hubert Feyrer <hubert (at] feyrer.de>
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 # must display the following acknowledgement:
16 # This product includes software developed by Hubert Feyrer
17 # for the NetBSD Project.
18 # 4. The name of the author may not be used to endorse or promote products
19 # derived from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 #
33 # Extract BSD-mandated copyright messages for NetBSD documentation
34 #
35 # Usage:
36 # 1) find /usr/src -type f -print \
37 # | grep -v sys/compat/freebsd/freebsd_rtprio.h \
38 # | perl extract-contrib-string.pl
39 # >x
40 # 2) merge text after "--------" in "x" into
41 # src/distrib/notes/common/legal.common
42 #
43
44
45 $ack_line1="[aA]ll( commercial)?( marketing or)? advertising materials mentioning( features)?";
46 $ack_line2="display the following( acknowledge?ment)?";
47 $ack_endline=
48 '(\d\.\s*(Neither the name'
49 . '|The name of the company nor the name' # Wasn't my idea
50 . '|The name of the author may not'
51 . '|The name of .* must not be used to endorse'
52 . '|The names? (of )?.* nor the names? of'
53 . '|The names? (of )?.* or any of it\'?s members'
54 . '|Redistributions of any form whatsoever'
55 . '|The names .*"OpenSSL Toolkit.*" and .*"OpenSSL Project.*" must not be used))'
56 .'|(THIS SOFTWARE IS PROVIDED)'
57 .'|(The word \'cryptographic\' can be left out if)'
58 .'|(may be used to endorse)'
59 .'|(@end cartouche)'
60 .'|(Redistribution and use in source and binary forms)'
61 .'|(may not be used to endorse)'
62 .'|(\.IP 4)'
63 .'|(ALLOW FREE USE OF)'
64 .'|(materials provided with the distribution)'
65 .'|(@InsertRedistribution@)';
66
67 $known_bad_clause_3_wording=
68 'sys/compat/hpux/hpux_exec_aout.c' # cgd (at] NetBSD.org
69 .'|sys/compat/hpux/hpux_exec.c' # cgd (at] NetBSD.org
70 .'|usr.bin/lex/.*' # UCB
71 .'|usr.sbin/hilinfo/hilinfo.c' # CSS @ Utah
72 ;
73
74 sub warning {
75 local($fn,$msg) = @_;
76 print "XXX $fn line $.: $msg\n"
77 }
78
79
80 if ($ARGV[0]) {
81 $debug=1;
82 shift(@ARGV);
83 }
84
85
86 file:
87 while(<>) {
88 chomp();
89 $fn=$_;
90
91 open(F, "$fn") || die "cannot read $fn: $!\n";
92
93 line:
94 while(<F>) {
95 if (0 and /$ack_line2/i){
96 print "?> $_" if $debug;
97
98 if ($fn !~ m,$known_bad_clause_3_wording,) {
99 warning($fn, "clause 3 start not caught");
100 }
101 last line;
102 }
103
104 print "0> $_" if $debug;
105
106 if (/$ack_line1/i
107 or (/$ack_line2/ and $fn =~ m,$known_bad_clause_3_wording,)) {
108
109 print "1> $_" if $debug;
110
111 $_=<F>
112 unless $fn =~ m,$known_bad_clause_3_wording,;
113 if (/$ack_line2/i or $fn =~ m,$known_bad_clause_3_wording,){
114
115 print "2> $_" if $debug;
116
117 $msg="";
118 $cnt=0;
119 $_=<F>;
120 while(!/$ack_endline/i) {
121
122 print "C> $_" if $debug;
123
124 $msg .= $_;
125 $cnt++;
126 $_ = <F>;
127 if ($cnt > 10) {
128 warning($fn,"loooong copyright?");
129 last line;
130 }
131 }
132
133 print "E> $_" if $debug;
134
135 # post-process
136 $msg =~ s/^\@c\s*//g; # texinfo
137 $msg =~ s/\n\@c\s*/\n/g; # texinfo
138 $msg =~ s/^REM\s*//g; # BASIC?!?
139 $msg =~ s/\nREM\s*/\n/g; # BASIC?!?
140 $msg =~ s/^dnl\s*//g; # m4
141 $msg =~ s/\dnl\s*/\n/g; # m4
142 $msg =~ s/^\.\\"\s*//g; # *roff
143 $msg =~ s/\n\.\\"\s*/\n/g; # *roff
144 $msg =~ s/^[#\\\|";]*\s*//g; # sh etc.
145 $msg =~ s/\n[#\\\|";]\s*/\n/g; # sh etc.
146 $msg =~ s/^[ *]*//g; # C
147 $msg =~ s/\n[ *]*/\n/g; # C
148 $msg =~ s/\@cartouche\n//; # texinfo
149
150 $msg =~ s/
//g;
152 $msg =~ s/\s*\n/\n/g;
153 $msg =~ s/^\s*//;
154 $msg =~ s/\\\@/\@/g;
155 $msg =~ s/\n\n/\n/g;
156 $msg =~ s/^\s*"//;
157 $msg =~ s/"\s*$//;
158 $msg =~ s/^\s*``//;
159 $msg =~ s/''\s*$//;
160 $msg .= "\n" if $msg!~/\n$/;
161
162
163 # Split up into separate paragraphs
164 #
165 $msgs=$msg;
166 $msgs=~s/(This (software|product))/|$1/g;
167 $msgs=~s,^\|,,;
168 msg:
169 foreach $msg (split(/\|/, $msgs)) {
170 print ".\\\" File $fn:\n";
171 print "$msg";
172 print "\n";
173
174 # Figure out if there's a version w/ or w/o trailing dot
175 #
176 if ($msg =~ /\.\n$/) {
177 # check if there's a version of the same msg
178 # w/ a trailing dot
179 $msg2=$msg;
180 $msg2=~s,\.\n$,\n,;
181 if ($copyrights{"$msg2"}) {
182 # already there - skip
183 print "already there, w/o dot - skipping!\n"
184 if $debug;
185 next msg;
186 }
187
188 # ... maybe with other case?
189 $lc_msg2=lc($msg2);
190 if ($lc_copyrights{$lc_msg2}) {
191 print "already there, in different case - skipping\n"
192 if $debug;
193 next msg;
194 }
195 } else {
196 # check if there's a version of the same msg
197 # w/o the trailing dot
198 $msg2=$msg;
199 chomp($msg2);
200 $msg2.=".\n";
201 if ($copyrights{"$msg2"}) {
202 # already there - skip
203 print "already there, w/ dot - skipping!\n"
204 if $debug;
205 next msg;
206 }
207
208 # ... maybe with other case?
209 $lc_msg2=lc($msg2);
210 if ($lc_copyrights{$lc_msg2}) {
211 print "already there, in different case - skipping\n"
212 if $debug;
213 next msg;
214 }
215 }
216
217 $copyrights{$msg} = 1;
218 $lc_copyrights{$lc_msg} = 1;
219 }
220
221 } else {
222 print "?> $_" if $debug;
223
224 if ($fn !~ m,$known_bad_clause_3_wording,) {
225 warning($fn, "bad clause 3?");
226 }
227 last line;
228 }
229 }
230 }
231 close(F);
232 }
233
234
235 print "------------------------------------------------------------\n";
236
237 $firsttime=1;
238 foreach $msg (sort keys %copyrights) {
239 if ($firsttime) {
240 $firsttime=0;
241 } else {
242 print ".It\n";
243 }
244 print "$msg";
245 }
246