2004-08-22 17:29:40 +04:00
|
|
|
|
#!/usr/bin/env perl
|
2004-08-22 01:55:47 +04:00
|
|
|
|
#
|
2008-05-16 23:09:10 +04:00
|
|
|
|
# Copyright (c) 2004, 2008 The NetBSD Foundation, Inc.
|
2004-08-22 01:55:47 +04:00
|
|
|
|
# All rights reserved.
|
2008-05-16 23:09:10 +04:00
|
|
|
|
#
|
|
|
|
|
# This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
|
# by Hubert Feyrer <hubert@feyrer.de>.
|
2004-08-22 01:55:47 +04:00
|
|
|
|
#
|
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
|
# are met:
|
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
|
#
|
2008-05-16 23:09:10 +04:00
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
|
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
|
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
|
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
2004-08-22 01:55:47 +04:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Extract BSD-mandated copyright messages for NetBSD documentation
|
|
|
|
|
#
|
|
|
|
|
# Usage:
|
|
|
|
|
# 1) find /usr/src -type f -print \
|
|
|
|
|
# | perl extract-contrib-string.pl
|
|
|
|
|
# >x
|
2008-05-20 02:19:51 +04:00
|
|
|
|
#
|
2004-08-22 01:55:47 +04:00
|
|
|
|
# 2) merge text after "--------" in "x" into
|
|
|
|
|
# src/distrib/notes/common/legal.common
|
|
|
|
|
#
|
2008-05-20 02:19:51 +04:00
|
|
|
|
# Options:
|
|
|
|
|
#
|
2008-05-21 03:30:21 +04:00
|
|
|
|
# perl extract-contrib-string.pl [-d] [-h] [-x] [-?]
|
2008-05-20 02:19:51 +04:00
|
|
|
|
#
|
|
|
|
|
# where
|
|
|
|
|
# -d debug output
|
|
|
|
|
# -h html output
|
2008-05-21 03:30:21 +04:00
|
|
|
|
# -x xml/docbook output
|
|
|
|
|
# -? display help/usage message
|
2004-08-22 01:55:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ack_line1="[aA]ll( commercial)?( marketing or)? advertising materials mentioning( features)?";
|
|
|
|
|
$ack_line2="display the following( acknowledge?ment)?";
|
|
|
|
|
$ack_endline=
|
|
|
|
|
'(\d\.\s*(Neither the name'
|
|
|
|
|
. '|The name of the company nor the name' # Wasn't my idea
|
|
|
|
|
. '|The name of the author may not'
|
|
|
|
|
. '|The name of .* must not be used to endorse'
|
|
|
|
|
. '|The names? (of )?.* nor the names? of'
|
|
|
|
|
. '|The names? (of )?.* or any of it\'?s members'
|
|
|
|
|
. '|Redistributions of any form whatsoever'
|
|
|
|
|
. '|The names .*"OpenSSL Toolkit.*" and .*"OpenSSL Project.*" must not be used))'
|
|
|
|
|
.'|(THIS SOFTWARE IS PROVIDED)'
|
|
|
|
|
.'|(The word \'cryptographic\' can be left out if)'
|
|
|
|
|
.'|(may be used to endorse)'
|
|
|
|
|
.'|(@end cartouche)'
|
|
|
|
|
.'|(Redistribution and use in source and binary forms)'
|
|
|
|
|
.'|(may not be used to endorse)'
|
|
|
|
|
.'|(\.IP 4)'
|
|
|
|
|
.'|(ALLOW FREE USE OF)'
|
|
|
|
|
.'|(materials provided with the distribution)'
|
|
|
|
|
.'|(@InsertRedistribution@)';
|
|
|
|
|
|
|
|
|
|
$known_bad_clause_3_wording=
|
2008-05-13 00:24:42 +04:00
|
|
|
|
'usr.bin/lex/.*' # UCB
|
2004-08-22 01:55:47 +04:00
|
|
|
|
.'|usr.sbin/hilinfo/hilinfo.c' # CSS @ Utah
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
sub warning {
|
|
|
|
|
local($fn,$msg) = @_;
|
|
|
|
|
print "XXX $fn line $.: $msg\n"
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-21 01:05:18 +04:00
|
|
|
|
while ($#ARGV >= 0) {
|
|
|
|
|
$debug=1 if ($ARGV[0] =~ /-d/i);
|
|
|
|
|
$html=1 if ($ARGV[0] =~ /-h/i);
|
|
|
|
|
$xml=1 if ($ARGV[0] =~ /-x/i);
|
2008-05-21 03:30:21 +04:00
|
|
|
|
$usage=1 if ($ARGV[0] =~ /-\?/);
|
2008-05-20 02:19:51 +04:00
|
|
|
|
shift(@ARGV);
|
|
|
|
|
}
|
2004-08-22 01:55:47 +04:00
|
|
|
|
|
2008-05-21 03:30:21 +04:00
|
|
|
|
if ($usage) {
|
|
|
|
|
print "usage: find /usr/src -type f -print |\n" .
|
|
|
|
|
" perl extract-contrib-string.pl [-h] [-x] [-?] [-d]\n" .
|
|
|
|
|
" where\n" .
|
|
|
|
|
" -h output html\n" .
|
|
|
|
|
" -x output xml/docbook\n" .
|
|
|
|
|
" -d debug\n" .
|
|
|
|
|
" -? display this help message\n";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-21 01:05:18 +04:00
|
|
|
|
$comments = !$html && !$xml;
|
2004-08-22 01:55:47 +04:00
|
|
|
|
|
|
|
|
|
file:
|
|
|
|
|
while(<>) {
|
|
|
|
|
chomp();
|
|
|
|
|
$fn=$_;
|
|
|
|
|
|
|
|
|
|
open(F, "$fn") || die "cannot read $fn: $!\n";
|
|
|
|
|
|
|
|
|
|
line:
|
|
|
|
|
while(<F>) {
|
|
|
|
|
if (0 and /$ack_line2/i){
|
|
|
|
|
print "?> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
if ($fn !~ m,$known_bad_clause_3_wording,) {
|
|
|
|
|
warning($fn, "clause 3 start not caught");
|
|
|
|
|
}
|
|
|
|
|
last line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print "0> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
if (/$ack_line1/i
|
|
|
|
|
or (/$ack_line2/ and $fn =~ m,$known_bad_clause_3_wording,)) {
|
|
|
|
|
|
|
|
|
|
print "1> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
$_=<F>
|
|
|
|
|
unless $fn =~ m,$known_bad_clause_3_wording,;
|
|
|
|
|
if (/$ack_line2/i or $fn =~ m,$known_bad_clause_3_wording,){
|
|
|
|
|
|
|
|
|
|
print "2> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
$msg="";
|
|
|
|
|
$cnt=0;
|
|
|
|
|
$_=<F>;
|
|
|
|
|
while(!/$ack_endline/i) {
|
|
|
|
|
|
|
|
|
|
print "C> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
$msg .= $_;
|
|
|
|
|
$cnt++;
|
|
|
|
|
$_ = <F>;
|
|
|
|
|
if ($cnt > 10) {
|
|
|
|
|
warning($fn,"loooong copyright?");
|
|
|
|
|
last line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print "E> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
# post-process
|
|
|
|
|
$msg =~ s/^REM\s*//g; # BASIC?!?
|
|
|
|
|
$msg =~ s/\nREM\s*/\n/g; # BASIC?!?
|
|
|
|
|
$msg =~ s/^dnl\s*//g; # m4
|
|
|
|
|
$msg =~ s/\dnl\s*/\n/g; # m4
|
2008-05-21 03:30:21 +04:00
|
|
|
|
$msg =~ s/^\s+-\s+//g; # seen in docbook files
|
|
|
|
|
$msg =~ s/\n\s+-\s+/ /g; #
|
2004-08-22 01:55:47 +04:00
|
|
|
|
$msg =~ s/^[#\\\|";]*\s*//g; # sh etc.
|
|
|
|
|
$msg =~ s/\n[#\\\|";]\s*/\n/g; # sh etc.
|
|
|
|
|
$msg =~ s/^[ *]*//g; # C
|
|
|
|
|
$msg =~ s/\n[ *]*/\n/g; # C
|
2008-05-20 02:19:51 +04:00
|
|
|
|
|
2008-05-21 03:30:21 +04:00
|
|
|
|
# *roff
|
|
|
|
|
while ($msg =~ /^\.\\"\s*/) {
|
|
|
|
|
$msg =~ s/^\.\\"\s*//o;
|
|
|
|
|
}
|
|
|
|
|
while ($msg =~ /\n\.\\"\s*/) {
|
|
|
|
|
$msg =~ s/\n\.\\"\s*/\n/o;
|
|
|
|
|
}
|
|
|
|
|
$msg =~ s/\n\.\\"\s*$/\n/g;
|
|
|
|
|
|
2008-05-20 02:19:51 +04:00
|
|
|
|
# C++/C99
|
|
|
|
|
while ($msg =~ /^\s*\/\/\s*/) {
|
|
|
|
|
$msg =~ s/^\s*\/\/\s*//o;
|
|
|
|
|
}
|
2008-05-21 03:30:21 +04:00
|
|
|
|
while ($msg =~ /\n\s*\/\/\s*$/) {
|
|
|
|
|
$msg =~ s/\n\s*\/\/\s*$//o;
|
|
|
|
|
}
|
|
|
|
|
$msg =~ s/\n\s*\/\/\s*/\n/g;
|
|
|
|
|
|
|
|
|
|
# C
|
|
|
|
|
while ($msg =~ /^\s*\*\s*/) {
|
|
|
|
|
$msg =~ s/^\s*\*\s*//o;
|
|
|
|
|
}
|
|
|
|
|
while ($msg =~ /\n\s*\*\s*$/) {
|
|
|
|
|
$msg =~ s/\n\s*\*\s*$//o;
|
2008-05-20 02:19:51 +04:00
|
|
|
|
}
|
2008-05-21 03:30:21 +04:00
|
|
|
|
$msg =~ s/\n\s*\*\s*/\n/g;
|
|
|
|
|
|
|
|
|
|
# texinfo @c
|
|
|
|
|
while ($msg =~ /^\s*\@c\s+/) {
|
|
|
|
|
$msg =~ s/^\s*\@c\s+//o;
|
|
|
|
|
}
|
|
|
|
|
while ($msg =~ /\n\s*\@c\s+$/) {
|
|
|
|
|
$msg =~ s/\n\s*\@c\s+$//o;
|
|
|
|
|
}
|
|
|
|
|
$msg =~ s/\n\s*\@c\s+/\n/g;
|
2008-05-20 02:19:51 +04:00
|
|
|
|
|
2004-08-22 01:55:47 +04:00
|
|
|
|
$msg =~ s/\@cartouche\n//; # texinfo
|
|
|
|
|
|
|
|
|
|
$msg =~ s/
//g;
|
|
|
|
|
$msg =~ s/\s*\n/\n/g;
|
|
|
|
|
$msg =~ s/^\s*//;
|
|
|
|
|
$msg =~ s/\\\@/\@/g;
|
|
|
|
|
$msg =~ s/\n\n/\n/g;
|
|
|
|
|
$msg =~ s/^\s*``//;
|
|
|
|
|
$msg =~ s/''\s*$//;
|
|
|
|
|
|
2006-12-25 21:39:47 +03:00
|
|
|
|
# Split up into separate paragraphs
|
2004-08-22 01:55:47 +04:00
|
|
|
|
#
|
|
|
|
|
$msgs=$msg;
|
|
|
|
|
$msgs=~s/(This (software|product))/|$1/g;
|
|
|
|
|
$msgs=~s,^\|,,;
|
|
|
|
|
msg:
|
|
|
|
|
foreach $msg (split(/\|/, $msgs)) {
|
2008-05-21 03:30:21 +04:00
|
|
|
|
while ($msg =~ /[\n\s]+$/) {
|
|
|
|
|
$msg =~ s/[\n\s]+$//o;
|
|
|
|
|
}
|
|
|
|
|
next if ($msg eq "");
|
2008-05-21 01:05:18 +04:00
|
|
|
|
if ($comments) {
|
2008-05-20 02:19:51 +04:00
|
|
|
|
print ".\\\" File $fn:\n";
|
|
|
|
|
print "$msg";
|
|
|
|
|
print "\n\n";
|
|
|
|
|
}
|
2004-08-22 01:55:47 +04:00
|
|
|
|
|
|
|
|
|
# Figure out if there's a version w/ or w/o trailing dot
|
|
|
|
|
#
|
2008-05-21 01:18:28 +04:00
|
|
|
|
if ($msg =~ /\.$/) {
|
2004-08-22 01:55:47 +04:00
|
|
|
|
# check if there's a version of the same msg
|
2008-05-21 01:18:28 +04:00
|
|
|
|
# w/o a trailing dot
|
2004-08-22 01:55:47 +04:00
|
|
|
|
$msg2=$msg;
|
2008-05-21 01:18:28 +04:00
|
|
|
|
$msg2=~s,\.$,,;
|
2004-08-22 01:55:47 +04:00
|
|
|
|
if ($copyrights{"$msg2"}) {
|
|
|
|
|
# already there - skip
|
|
|
|
|
print "already there, w/o dot - skipping!\n"
|
|
|
|
|
if $debug;
|
|
|
|
|
next msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ... maybe with other case?
|
|
|
|
|
$lc_msg2=lc($msg2);
|
|
|
|
|
if ($lc_copyrights{$lc_msg2}) {
|
2004-08-22 17:29:40 +04:00
|
|
|
|
print "already there, in different case - skipping\n"
|
2004-08-22 01:55:47 +04:00
|
|
|
|
if $debug;
|
|
|
|
|
next msg;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
# check if there's a version of the same msg
|
2008-05-21 01:18:28 +04:00
|
|
|
|
# with a trailing dot
|
2004-08-22 01:55:47 +04:00
|
|
|
|
$msg2=$msg;
|
2008-05-21 01:18:28 +04:00
|
|
|
|
$msg2.=".";
|
2004-08-22 01:55:47 +04:00
|
|
|
|
if ($copyrights{"$msg2"}) {
|
|
|
|
|
# already there - skip
|
|
|
|
|
print "already there, w/ dot - skipping!\n"
|
|
|
|
|
if $debug;
|
|
|
|
|
next msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ... maybe with other case?
|
|
|
|
|
$lc_msg2=lc($msg2);
|
|
|
|
|
if ($lc_copyrights{$lc_msg2}) {
|
2004-08-22 17:29:40 +04:00
|
|
|
|
print "already there, in different case - skipping\n"
|
2004-08-22 01:55:47 +04:00
|
|
|
|
if $debug;
|
|
|
|
|
next msg;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$copyrights{$msg} = 1;
|
|
|
|
|
$lc_copyrights{$lc_msg} = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
print "?> $_" if $debug;
|
|
|
|
|
|
|
|
|
|
if ($fn !~ m,$known_bad_clause_3_wording,) {
|
|
|
|
|
warning($fn, "bad clause 3?");
|
|
|
|
|
}
|
|
|
|
|
last line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
close(F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-05-20 02:19:51 +04:00
|
|
|
|
if ($html) {
|
|
|
|
|
print "<ul>\n";
|
|
|
|
|
foreach $msg (sort keys %copyrights) {
|
|
|
|
|
print "<li>$msg</li>\n";
|
|
|
|
|
}
|
|
|
|
|
print "</ul>\n";
|
2008-05-21 01:05:18 +04:00
|
|
|
|
} elsif ($xml) {
|
|
|
|
|
foreach $msg (sort keys %copyrights) {
|
|
|
|
|
print "<listitem>$msg</listitem>\n";
|
|
|
|
|
}
|
2008-05-20 02:19:51 +04:00
|
|
|
|
} else {
|
|
|
|
|
print "------------------------------------------------------------\n";
|
2004-08-22 01:55:47 +04:00
|
|
|
|
|
2008-05-20 02:19:51 +04:00
|
|
|
|
$firsttime=1;
|
|
|
|
|
foreach $msg (sort keys %copyrights) {
|
|
|
|
|
if ($firsttime) {
|
|
|
|
|
$firsttime=0;
|
|
|
|
|
} else {
|
|
|
|
|
print ".It\n";
|
|
|
|
|
}
|
|
|
|
|
print "$msg\n";
|
2004-08-22 01:55:47 +04:00
|
|
|
|
}
|
|
|
|
|
}
|