update_copyrights revision 828a5beda384130d5e2913dadd862924c53405bf
#!/usr/local/bin/perl -w
#
# Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
require 5.002;
# Map copyright owners to the files containing copyright messages.
# The first line of the copyright message is not in the file;
# it is constructed by this script.
my %owner2filename = (
"" => "util/COPYRIGHT",
"NAI" => "util/COPYRIGHT.NAI",
"PORTION" => "util/COPYRIGHT.PORTION",
);
# Map each copyright owner name to a reference to an array containing
# the lines of the copyright message.
my %owner2text = ();
foreach $owner (keys %owner2filename) {
my $f = $owner2filename{$owner};
open(COPYRIGHT, "<$f") || die "can't open $f: $!";
@copyright_text = <COPYRIGHT>;
close(COPYRIGHT);
$owner2text{$owner} = [ @copyright_text ];
}
while (<>) {
($file, $typeandowner, $years_list) = split(/\s+/);
@years = split(/,/, $years_list);
if ( ! -f $file ) {
print "$file: missing\n";
next;
}
my ($type, $owner) = split(/\./, $typeandowner);
$owner = "" if !defined $owner;
$textp = $owner2text{$owner};
if (!defined $textp) {
print "$file: unknown copyright owner $owner\n";
next;
}
next if $type eq "X";
# XXXTALE lib/isc/commandline.c should probably also have special handling.
$before_copyright = "";
$c_comment = 0;
$shell_comment = 0;
$m4_comment = 0;
$first = "";
if ($type eq "C") {
$c_comment = 1;
$prefix = " * ";
} elsif ($type eq "SH" || $type eq "PERL" || $type eq "MAKE") {
$shell_comment = 1;
$prefix = "# ";
} elsif ($type eq "M4") {
$m4_comment = 1;
$prefix = "dnl ";
} else {
print "$file: type '$type' not supported yet; skipping\n";
next;
}
open(SOURCE, "<$file") || die "can't open $file: $!";
$_ = <SOURCE>;
if ($c_comment && /^\/\*/) {
$_ = <SOURCE>;
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
if ($_ !~ /\*\//) {
while (<SOURCE>) {
if ($_ =~ /\*\//) {
last;
}
}
}
} elsif ($shell_comment) {
if (/^\#\!/) {
$before_copyright = "$_#\n";
$_ = <SOURCE>;
if ($_ eq "#\n") {
$_ = <SOURCE>;
}
}
if (/^\#/) {
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^\#/) {
$first = $_;
last;
}
}
} else {
$first = $_;
}
} elsif ($m4_comment && /^dnl /) {
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^dnl /) {
$first = $_;
last;
}
}
} else {
$first = $_;
}
open(TARGET, ">$file.new") || die "can't open $file.new: $!";
if ($before_copyright ne "") {
print TARGET $before_copyright;
}
if ($c_comment) {
print TARGET "/*\n";
}
$years = "";
$first_year = 1;
foreach $year (@years) {
if (! $first_year) {
$years .= ", ";
}
$years .= "$year";
$first_year = 0;
}
($firstline, @otherlines) = @$textp;
$firstline =~ s/\@YEARS\@/$years/;
print TARGET "$prefix$firstline";
foreach $_ (@otherlines) {
print TARGET "${prefix}$_";
}
if ($c_comment) {
print TARGET " */\n";
}
if ($first eq "") {
$first = <SOURCE>;
}
if ($first ne "") {
if ($first !~ /^\s*$/) {
print TARGET "\n";
}
print TARGET $first;
while (<SOURCE>) {
print TARGET $_;
}
}
close(TARGET);
close(SOURCE);
$mode = (stat $file)[2]&511;
chmod $mode, "$file.new";
rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
rename("$file.new", "$file") || die "rename($file.new, $file): $!";
}