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