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