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