Home | History | Annotate | Line # | Download | only in common
extract-contrib-string.pl revision 1.4
      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 #    | perl extract-contrib-string.pl
     38 #    >x
     39 # 2) merge text after "--------" in "x" into
     40 #    src/distrib/notes/common/legal.common
     41 #
     42 
     43 
     44 $ack_line1="[aA]ll( commercial)?( marketing or)? advertising materials mentioning( features)?";
     45 $ack_line2="display the following( acknowledge?ment)?";
     46 $ack_endline=
     47       '(\d\.\s*(Neither the name'
     48     .         '|The name of the company nor the name'	# Wasn't my idea
     49     .         '|The name of the author may not'
     50     .         '|The name of .* must not be used to endorse'
     51     .         '|The names? (of )?.* nor the names? of'
     52     .         '|The names? (of )?.* or any of it\'?s members'
     53     .         '|Redistributions of any form whatsoever'
     54     .         '|The names .*"OpenSSL Toolkit.*" and .*"OpenSSL Project.*" must not be used))'
     55     .'|(THIS SOFTWARE IS PROVIDED)'
     56     .'|(The word \'cryptographic\' can be left out if)'
     57     .'|(may be used to endorse)'
     58     .'|(@end cartouche)'
     59     .'|(Redistribution and use in source and binary forms)'
     60     .'|(may not be used to endorse)'
     61     .'|(\.IP 4)'
     62     .'|(ALLOW FREE USE OF)'
     63     .'|(materials provided with the distribution)'
     64     .'|(@InsertRedistribution@)';
     65 
     66 $known_bad_clause_3_wording=
     67       'usr.bin/lex/.*'				# UCB
     68     .'|usr.sbin/hilinfo/hilinfo.c'	   	# CSS @ Utah
     69     ;	
     70 
     71 sub warning {
     72     local($fn,$msg) = @_;
     73     print "XXX $fn line $.: $msg\n"
     74 }
     75 
     76 
     77 if ($ARGV[0]) {
     78     $debug=1;
     79     shift(@ARGV);
     80 }
     81 
     82 
     83 file:
     84 while(<>) {
     85     chomp();
     86     $fn=$_;
     87     
     88     open(F, "$fn") || die "cannot read $fn: $!\n";
     89 
     90   line:
     91     while(<F>) {
     92 	if (0 and /$ack_line2/i){
     93 	    print "?> $_" if $debug;
     94 	    
     95 	    if ($fn !~ m,$known_bad_clause_3_wording,) {
     96 		warning($fn, "clause 3 start not caught");
     97 	    }
     98 	    last line;
     99 	}
    100 	
    101 	print "0> $_" if $debug;
    102 
    103 	if (/$ack_line1/i
    104 	    or (/$ack_line2/ and $fn =~ m,$known_bad_clause_3_wording,)) {
    105 	    
    106 	    print "1> $_" if $debug;
    107 
    108 	    $_=<F>
    109 		unless $fn =~ m,$known_bad_clause_3_wording,;
    110 	    if (/$ack_line2/i or $fn =~ m,$known_bad_clause_3_wording,){
    111 		
    112 		print "2> $_" if $debug;
    113 		
    114 		$msg="";
    115 		$cnt=0;
    116 		$_=<F>;
    117 		while(!/$ack_endline/i) {
    118 		    
    119 		    print "C> $_" if $debug;
    120 
    121 		    $msg .= $_;
    122 		    $cnt++;
    123 		    $_ = <F>;
    124 		    if ($cnt > 10) {
    125 			warning($fn,"loooong copyright?");
    126 			last line;
    127 		    }
    128 		}
    129 
    130 		print "E> $_" if $debug;
    131 		
    132 		# post-process
    133 		$msg =~ s/^\@c\s*//g;			# texinfo
    134 		$msg =~ s/\n\@c\s*/\n/g;		# texinfo
    135 		$msg =~ s/^REM\s*//g;			# BASIC?!?
    136 		$msg =~ s/\nREM\s*/\n/g;		# BASIC?!?
    137 		$msg =~ s/^dnl\s*//g;			# m4
    138 		$msg =~ s/\dnl\s*/\n/g;			# m4
    139 		$msg =~ s/^\.\\"\s*//g;			# *roff
    140 		$msg =~ s/\n\.\\"\s*/\n/g;		# *roff
    141 		$msg =~ s/^[#\\\|";]*\s*//g;		# sh etc.
    142 		$msg =~ s/\n[#\\\|";]\s*/\n/g;		# sh etc.
    143 		$msg =~ s/^[ 	*]*//g;      		# C
    144 		$msg =~ s/\n[ 	*]*/\n/g;    		# C
    145 		$msg =~ s/^\s*\/\/\s*/ /g;		# C++/C99
    146 		$msg =~ s/\ns*\/\/\s*/ /g;		# C++/C99
    147 		$msg =~ s/\@cartouche\n//;              # texinfo
    148 
    149 		$msg =~ s/
//g;
    151 		$msg =~ s/\s*\n/\n/g;
    152 		$msg =~ s/^\s*//;
    153 		$msg =~ s/\\\@/\@/g;
    154 		$msg =~ s/\n\n/\n/g;
    155 	        $msg =~ s/^\s*"//;
    156 	        $msg =~ s/"\s*$//;
    157 	        $msg =~ s/^\s*``//;
    158 	        $msg =~ s/''\s*$//;
    159                 $msg .= "\n" if $msg!~/\n$/;
    160 
    161 
    162 		# Split up into separate paragraphs
    163 		#
    164 		$msgs=$msg;
    165 		$msgs=~s/(This (software|product))/|$1/g;
    166 		$msgs=~s,^\|,,;
    167 	      msg:
    168 		foreach $msg (split(/\|/, $msgs)) {
    169 		    print ".\\\" File $fn:\n";
    170 		    print "$msg";
    171 		    print "\n";
    172 		    
    173 		    # Figure out if there's a version w/ or w/o trailing dot
    174 		    # 
    175 		    if ($msg =~ /\.\n$/) {
    176 			# check if there's a version of the same msg
    177 			# w/ a trailing dot
    178 			$msg2=$msg;
    179 			$msg2=~s,\.\n$,\n,;
    180 			if ($copyrights{"$msg2"}) {
    181 			    # already there - skip
    182 			    print "already there, w/o dot - skipping!\n"
    183 				if $debug;
    184 			    next msg;
    185 			}
    186 			
    187 			# ... maybe with other case?
    188 			$lc_msg2=lc($msg2);
    189 			if ($lc_copyrights{$lc_msg2}) {
    190 			    print "already there, in different case - skipping\n"
    191 				if $debug;
    192 			    next msg;
    193 			}
    194 		    } else {
    195 			# check if there's a version of the same msg
    196 			# w/o the trailing dot
    197 			$msg2=$msg;
    198 			chomp($msg2);
    199 			$msg2.=".\n";
    200 			if ($copyrights{"$msg2"}) {
    201 			    # already there - skip
    202 			    print "already there, w/ dot - skipping!\n"
    203 				if $debug;
    204 			    next msg;
    205 			}
    206 			
    207 			# ... maybe with other case?
    208 			$lc_msg2=lc($msg2);
    209 			if ($lc_copyrights{$lc_msg2}) {
    210 			    print "already there, in different case - skipping\n"
    211 				if $debug;
    212 			    next msg;
    213 			}
    214 		    }
    215 
    216 		    $copyrights{$msg} = 1;
    217 		    $lc_copyrights{$lc_msg} = 1;
    218 		}		 
    219 
    220 	    } else {
    221 		print "?> $_" if $debug;
    222 
    223                 if ($fn !~ m,$known_bad_clause_3_wording,) {
    224 		    warning($fn, "bad clause 3?");
    225                 }
    226 		last line;
    227 	    }
    228 	}
    229     }
    230     close(F);
    231 }
    232 
    233 
    234 print "------------------------------------------------------------\n";
    235 
    236 $firsttime=1;
    237 foreach $msg (sort keys %copyrights) {
    238     if ($firsttime) {
    239 	$firsttime=0;
    240     } else {
    241 	print ".It\n";
    242     }
    243     print "$msg";
    244 }
    245