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