update_copyrights revision f4a7d04843eb62c92f2d4ff338da49ae86e3279b
012a352f4b26cfd874db8d06debc495c2303e8b2Bob Halley#!/usr/local/bin/perl -w
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
33cc94f04cb44dc247f605a954e45e5adc699977Automatic Updater# Copyright (C) 1998-2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater# purpose with or without fee is hereby granted, provided that the above
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley# copyright notice and this permission notice appear in all copies.
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
f5cfcbf2f7906fb59c2b8b9b8fc9c7a75ac44dabMark Andrews# $Id: update_copyrights,v 1.19 2000/08/01 00:46:14 tale Exp $
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyrequire 5.002;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley# Map copyright owners to the files containing copyright messages.
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence# The first line of the copyright message is not in the file;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley# it is constructed by this script.
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleymy %owner2filename = (
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley "" => "util/COPYRIGHT",
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley "NAI" => "util/COPYRIGHT.NAI",
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley "BSDI" => "util/COPYRIGHT.BSDI",
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley "BRIEF" => "util/COPYRIGHT.BRIEF",
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley "PORTION" => "util/COPYRIGHT.PORTION",
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley# Map each copyright owner name to a reference to an array containing
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence# the lines of the copyright message.
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
460b427411b72da26b1836b9424e2e70d65d9394David Lawrencemy %owner2text = ();
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyforeach $owner (keys %owner2filename) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence my $f = $owner2filename{$owner};
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence open(COPYRIGHT, "<$f") || die "can't open $f: $!";
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence @copyright_text = <COPYRIGHT>;
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews close(COPYRIGHT);
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $owner2text{$owner} = [ @copyright_text ];
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence}
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
460b427411b72da26b1836b9424e2e70d65d9394David Lawrencewhile (<>) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence ($file, $typeandowner, $years_list) = split(/\s+/);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley @years = split(/,/, $years_list);
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence if ( ! -f $file ) {
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence print "$file: missing\n";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence next;
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews }
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews my ($type, $owner) = split(/\./, $typeandowner);
f5cfcbf2f7906fb59c2b8b9b8fc9c7a75ac44dabMark Andrews $owner = "" if !defined $owner;
f5cfcbf2f7906fb59c2b8b9b8fc9c7a75ac44dabMark Andrews
2d46d268ccff30bb50e661b47c6496d23d9156c7Mark Andrews $textp = $owner2text{$owner};
2d46d268ccff30bb50e661b47c6496d23d9156c7Mark Andrews if (!defined $textp) {
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews print "$file: unknown copyright owner $owner\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley next;
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence }
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence next if $type eq "X";
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $before_copyright = "";
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $c_comment = 0;
596912ee9ca8eb14d30707ec286ab5d28bd39b3eMark Andrews $shell_comment = 0;
8319af16557b81eba3277ee67215285f0823b587Mark Andrews $m4_comment = 0;
8319af16557b81eba3277ee67215285f0823b587Mark Andrews $html_comment = 0;
aee5e9cbacd8f88325840b8a498876f4319b0890Mark Andrews $zone_comment = 0;
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $man_comment = 0;
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $start_comment = "";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $end_comment = "";
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $first = "";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence if ($type =~ /^(C|YACC|CONF-C)/) {
c32b87bc54abacf95fb3b063d72b7d1855c1643bMichael Graff $c_comment = 1;
7f9f8c13c5e5e26e0ba2b82c0900d11ecf6269ceMark Andrews $start_comment = "/*\n";
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $prefix = " * ";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $end_comment = " */\n";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($type =~ /^(SH|PERL|MAKE|CONF-SH)/) {
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $shell_comment = 1;
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $prefix = "# ";
b616f6ed69209ab4c87f610b472aeb20760652f2Mark Andrews } elsif ($type eq "ZONE") {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $zone_comment = 1;
2320f230995995595438a9d9301d84931fd266ceMark Andrews $prefix = "; ";
c427260a8678f2e99a2337fb95ec98d9c9ee8c05Mark Andrews } elsif ($type eq "MAN") {
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews $man_comment = 1;
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews $prefix = ".\\\" ";
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews } elsif ($type eq "M4") {
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews $m4_comment = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $prefix = "dnl ";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } elsif ($type eq "HTML") {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $html_comment = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $start_comment = "<!--\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $prefix = " - ";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $end_comment = "-->\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } elsif ($type eq "TXT") {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $prefix = "";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print "$file: type '$type' not supported yet; skipping\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley next;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($nonspaceprefix = $prefix) =~ s/\s+$//;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley open(SOURCE, "<$file") || die "can't open $file: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $_ = <SOURCE>;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($type eq "YACC") {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley unless ($_ eq "%{\n") {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print "$file: unexpected yacc file start ",
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley "(expected \"%{\\n\")\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley close(SOURCE);
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence next;
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence }
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence $before_copyright = "$_";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence $_ = <SOURCE>;
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence }
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence if ($c_comment && /^\/\*/) {
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews $_ = <SOURCE>;
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews if ($_ !~ /[Cc]opyright/) {
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews print "$file: non-copyright comment\n";
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews close(SOURCE);
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews next;
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($_ !~ /\*\//) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley while (<SOURCE>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley last if $_ =~ /\*\//;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } elsif ($shell_comment) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (/^\#\!/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $before_copyright = "$_#\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $_ = <SOURCE>;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $_ = <SOURCE> if $_ eq "#\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (/^\#/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($_ !~ /[Cc]opyright/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print "$file: non-copyright comment\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley close(SOURCE);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley next;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley while (<SOURCE>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($_ !~ /^\#/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $first = $_;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley last;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $first = $_;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } elsif (($m4_comment || $zone_comment || $man_comment) &&
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley /^\Q$nonspaceprefix\E/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley while (/^\Q$nonspaceprefix\E\s*$/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $_ = <SOURCE>;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($_ !~ /[Cc]opyright/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print "$file: non-copyright comment\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley close(SOURCE);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley next;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley while (<SOURCE>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($_ !~ /^\Q$nonspaceprefix\E/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $first = $_;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley 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 ok enough for now.
last unless
/See COPYRIGHT in the source root/ ||
/Permission to use, copy, modify, and / ||
/THE SOFTWARE IS PROVIDED "AS IS" AND /;
}
$/ = "\n";
}
$first = $_;
} else {
$first = $_;
}
$first = "" if ! defined($first);
open(TARGET, ">$file.new") || die "can't open $file.new: $!";
print TARGET $before_copyright if $before_copyright;
print TARGET $start_comment if $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 (/^$/ ? $nonspaceprefix : $prefix);
print TARGET "$_";
}
print TARGET $end_comment if $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.new", "$file")
or die "rename($file.new, $file): $!";
}
}