update_copyrights revision e6d6ce00e2bf0f6a755f8229212e35706e4035ae
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt#!/usr/local/bin/perl -w
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 1998, 1999 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# copyright notice and this permission notice appear in all copies.
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt#
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt# SOFTWARE.
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Huntif (@ARGV == 0) {
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt die "usage: update_copyrights <copyright_text>";
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt}
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt@copyright_text = ();
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Huntopen(COPYRIGHT, "<$ARGV[0]") || die "can't open $ARGV[0]: $!";
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt@copyright_text = <>;
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Huntclose(COPYRIGHT);
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Huntwhile (<>) {
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt ($file, $type, $years_list) = split(/\s+/);
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt @years = split(/,/, $years_list);
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt if ( ! -f $file ) {
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt print "$file: missing\n";
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt next;
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt }
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt if ($type eq "X") {
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt if ( ! -f $file ) {
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt print "$file: type X, but missing\n";
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt }
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt next;
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt }
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt $before_copyright = "";
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt $c_comment = 0;
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt $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";
}
print TARGET "${prefix}Copyright (C) ";
$first_year = 1;
foreach $year (@years) {
if (! $first_year) {
print TARGET ", ";
}
print TARGET "$year";
$first_year = 0;
}
print TARGET " Internet Software Consortium.\n";
print TARGET "$prefix\n";
foreach $_ (@copyright_text) {
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);
rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
rename("$file.new", "$file") || die "rename($file.new, $file): $!";
}