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