update_copyrights revision e85ffb301b294d70ddc1d90234788403666bb944
0N/A#!/usr/local/bin/perl -w
3679N/A#
0N/A# Copyright (C) 1998-2000 Internet Software Consortium.
0N/A#
0N/A# Permission to use, copy, modify, and distribute this software for any
0N/A# purpose with or without fee is hereby granted, provided that the above
0N/A# copyright notice and this permission notice appear in all copies.
0N/A#
0N/A# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
0N/A# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
0N/A# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
0N/A# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
0N/A# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
0N/A# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
0N/A# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
0N/A# SOFTWARE.
0N/A
0N/A# $Id: update_copyrights,v 1.14 2000/06/22 22:24:05 tale Exp $
1472N/A
1472N/Arequire 5.002;
1472N/A
0N/A# Map copyright owners to the files containing copyright messages.
0N/A# The first line of the copyright message is not in the file;
0N/A# it is constructed by this script.
1879N/A
1879N/Amy %owner2filename = (
1879N/A "" => "util/COPYRIGHT",
1879N/A "NAI" => "util/COPYRIGHT.NAI",
1879N/A "BRIEF" => "util/COPYRIGHT.BRIEF",
1879N/A "PORTION" => "util/COPYRIGHT.PORTION",
1879N/A);
0N/A
0N/A# Map each copyright owner name to a reference to an array containing
0N/A# the lines of the copyright message.
535N/A
535N/Amy %owner2text = ();
535N/A
535N/Aforeach $owner (keys %owner2filename) {
0N/A my $f = $owner2filename{$owner};
0N/A open(COPYRIGHT, "<$f") || die "can't open $f: $!";
0N/A @copyright_text = <COPYRIGHT>;
0N/A close(COPYRIGHT);
263N/A $owner2text{$owner} = [ @copyright_text ];
263N/A}
0N/A
0N/Awhile (<>) {
263N/A ($file, $typeandowner, $years_list) = split(/\s+/);
263N/A @years = split(/,/, $years_list);
263N/A
535N/A if ( ! -f $file ) {
535N/A print "$file: missing\n";
535N/A next;
0N/A }
0N/A
0N/A my ($type, $owner) = split(/\./, $typeandowner);
263N/A $owner = "" if !defined $owner;
263N/A
535N/A $textp = $owner2text{$owner};
535N/A if (!defined $textp) {
535N/A print "$file: unknown copyright owner $owner\n";
535N/A next;
535N/A }
535N/A
0N/A next if $type eq "X";
263N/A
535N/A $before_copyright = "";
263N/A $c_comment = 0;
0N/A $shell_comment = 0;
0N/A $m4_comment = 0;
0N/A $html_comment = 0;
0N/A $zone_comment = 0;
0N/A $man_comment = 0;
0N/A $start_comment = "";
0N/A $end_comment = "";
0N/A $first = "";
0N/A if ($type =~ /^(C|YACC|CONF-C)/) {
0N/A $c_comment = 1;
535N/A $start_comment = "/*\n";
535N/A $prefix = " * ";
0N/A $end_comment = " */\n";
0N/A } elsif ($type =~ /^(SH|PERL|MAKE|CONF-SH)/) {
0N/A $shell_comment = 1;
535N/A $prefix = "# ";
535N/A } elsif ($type eq "ZONE") {
535N/A $zone_comment = 1;
0N/A $prefix = "; ";
263N/A } elsif ($type eq "MAN") {
263N/A $man_comment = 1;
535N/A $prefix = ".\\\" ";
535N/A } elsif ($type eq "M4") {
535N/A $m4_comment = 1;
263N/A $prefix = "dnl ";
263N/A } elsif ($type eq "HTML") {
263N/A $html_comment = 1;
263N/A $start_comment = "<!--\n";
263N/A $prefix = " - ";
0N/A $end_comment = "-->\n";
0N/A } elsif ($type eq "TXT") {
0N/A $prefix = "";
263N/A } else {
263N/A print "$file: type '$type' not supported yet; skipping\n";
263N/A next;
263N/A }
263N/A open(SOURCE, "<$file") || die "can't open $file: $!";
263N/A $_ = <SOURCE>;
263N/A if ($type eq "YACC") {
263N/A unless ($_ eq "%{\n") {
263N/A print "$file: unexpected yacc file start (expected \"%{\\n\")\n";
263N/A close(SOURCE);
0N/A next;
0N/A }
263N/A $before_copyright = "$_";
0N/A $_ = <SOURCE>;
0N/A }
0N/A if ($c_comment && /^\/\*/) {
0N/A $_ = <SOURCE>;
0N/A if ($_ !~ /[Cc]opyright/) {
0N/A print "$file: non-copyright comment\n";
0N/A close(SOURCE);
0N/A next;
0N/A }
0N/A if ($_ !~ /\*\//) {
0N/A while (<SOURCE>) {
0N/A if ($_ =~ /\*\//) {
0N/A last;
0N/A }
0N/A }
0N/A }
0N/A } elsif ($shell_comment) {
0N/A if (/^\#\!/) {
0N/A $before_copyright = "$_#\n";
0N/A $_ = <SOURCE>;
0N/A $_ = <SOURCE> if $_ eq "#\n";
0N/A }
0N/A if (/^\#/) {
0N/A if ($_ !~ /[Cc]opyright/) {
0N/A print "$file: non-copyright comment\n";
0N/A close(SOURCE);
0N/A next;
0N/A }
0N/A while (<SOURCE>) {
0N/A if ($_ !~ /^\#/) {
0N/A $first = $_;
3679N/A last;
0N/A }
1879N/A }
1879N/A } else {
$first = $_;
}
} elsif (($m4_comment || $zone_comment || $man_comment) &&
/^\Q$prefix\E/) {
($nonspaceprefix = $prefix) =~ s/\s+$//;
while (/^\Q$nonspaceprefix\E\s*$/) {
$_ = <SOURCE>;
}
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^\Q$prefix\E/) {
$first = $_;
last;
}
}
} elsif ($html_comment) {
if (/^<!DOCTYPE/) {
$before_copyright = $_;
$_ = <SOURCE>;
}
if (/^<!/) {
$_ = <SOURCE> if $_ eq "<!--\n";
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (defined($_)) {
last if s/.*-->//;
$_ = <SOURCE>;
}
print "$file: unterminated comment\n" unless defined($_);
if ($_ ne "\n") {
$first = $_;
} else {
$first = <SOURCE>;
}
} else {
$first = $_;
}
} elsif ($type eq "TXT") {
if ($_ =~ /[Cc]opyright/) {
$/ = ""; # paragraph at a time
while (<SOURCE>) {
# Not very maintainable, but suitable enough for now.
last unless
/See COPYRIGHT in the source root/ ||
/Permission to use, copy, modify, and distribute / ||
/THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET /;
}
$/ = "\n";
}
$first = $_;
} else {
$first = $_;
}
$first = "" if ! defined($first);
open(TARGET, ">$file.new") || die "can't open $file.new: $!";
if ($before_copyright ne "") {
print TARGET $before_copyright;
}
if ($start_comment) {
print TARGET $start_comment;
}
$years = "";
$last_year = 0;
$anchor_year = 0;
foreach $year (@years) {
if ($last_year != 0 && $year == $last_year + 1) {
if ($year > $anchor_year + 1) {
substr($years, $anchor_end) = "-$year";
} else {
$years .= ", $year";
}
} else {
$years .= $last_year == 0 ? "$year" : ", $year";
if ($anchor_year != 0) {
print "$file: noncontiguous year: $year != $last_year + 1\n";
}
$anchor_year = $year;
$anchor_end = length($years);
}
$last_year = $year;
}
($firstline, @otherlines) = @$textp;
$firstline =~ s/\@YEARS\@/$years/;
print TARGET "$prefix$firstline";
foreach $_ (@otherlines) {
print TARGET "${prefix}$_";
}
if ($end_comment) {
print TARGET $end_comment;
}
if ($first eq "") {
$first = <SOURCE>;
}
if (defined($first)) {
print TARGET "\n";
undef $/;
$_ = <SOURCE>;
$/ = "\n";
my $pat = '\$(Id|Revision):.*\$';
my ($start, $end);
if ($start_comment ne "") {
($start = $start_comment) =~ s/\s*\n/ /;
($end = $end_comment) =~ s/^\s*(.*)\n/ $1\n/;
} elsif ($prefix ne "") {
($start = $prefix) =~ s/\s*\n//;
$end = "\n";
} else {
$start = "";
$end = "\n";
}
if ($first !~ /$pat/ && $_ !~ /$pat/) {
print TARGET "$start\$";
print TARGET "Id: ";
print TARGET "\$$end\n";
}
print TARGET $first if $first !~ /^\s*$/;
print TARGET $_;
}
close(TARGET);
close(SOURCE);
$mode = (stat $file)[2]&511;
chmod $mode, "$file.new";
if (system("cmp -s $file.new $file") == 0) {
unlink("$file.new");
} else {
rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
rename("$file.new", "$file") || die "rename($file.new, $file): $!";
}
}