update_copyrights revision a809c57ab263613c79999653ad28fbe47fa4bfa3
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#!/usr/local/bin/perl -w
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 1998-2001, 2004-2010, 2012-2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# License, v. 2.0. If a copy of the MPL was not distributed with this
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntrequire 5.002;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Map copyright owners to the files containing copyright messages.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# The first line of the copyright message is not in the file;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# it is constructed by this script.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Usage:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#
e13d04fda918c0c14c2247475bb99e0760d9a6a4Evan Hunt# perl util/update_copyrights <util/copyrights
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntmy %owner2filename = (
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "" => "util/COPYRIGHT",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "NAI" => "util/COPYRIGHT.NAI",
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt "NOM" => "util/COPYRIGHT.NOM",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "BSDI" => "util/COPYRIGHT.BSDI",
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "BRIEF" => "util/COPYRIGHT.BRIEF",
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "PORTION" => "util/COPYRIGHT.PORTION",
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# Map each copyright owner name to a reference to an array containing
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt# the lines of the copyright message.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntmy %owner2text = ();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsmy $keyword_pat = '\$(Id:.*|Revision:.*|Id|Revision)\$';
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsforeach $owner (keys %owner2filename) {
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt my $f = $owner2filename{$owner};
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews open(COPYRIGHT, "<$f") || die "can't open $f: $!";
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt @copyright_text = <COPYRIGHT>;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews close(COPYRIGHT);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $owner2text{$owner} = [ @copyright_text ];
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt}
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsmy %file_types = ();
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrewsmy %file_years = ();
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewsmy $years_list;
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrewsmy $parent;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews($dummy,$dummy,$dummy,$dummy,$this_month,$this_year,$dummy,$dummy,$dummy) = localtime(time());
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman$this_year += 1900;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewswhile (<>) {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews chomp;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews ($file, $type, $years) = split(/\s+/);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $file_types{$file} = $type;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $file_years{$file} = $years;
79f0eedd657d75889009226aa7ce23eeac28df5cMark Andrews}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntsub getyears {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $parent = $_[0];
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $parent =~ s/PARENT://;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $years_list = $file_years{$parent};
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews if (defined($years_list) && $years_list =~ /^PARENT:/) {
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt print "BAD PARENT:$parent\n";
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews undefine($years_list);
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt }
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews}
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
0cfb24736841b3e98bb25853229a0efabab88bddEvan Huntsub docbook {
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $parent = $_[0];
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews $parent =~ s/\.[^.]*$/.docbook/;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $years_list = $file_years{$parent};
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews}
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrewssub copyright {
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman my $holder = shift;
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews my $result = "";
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews return $result unless (@_);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $result = "$result <copyright>\n";
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $result = "$result <year>$_</year>\n" foreach (@_);
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $result = "$result <holder>$holder</holder>\n";
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews $result = "$result </copyright>\n";
a2ca594252024a7b26d2f6b1984cb6da6f5bd09cMark Andrews return $result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntsub copyrights {
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt my $a = copyright("Internet Systems Consortium, Inc. (\"ISC\")", @_);
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews return "$a";
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews}
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews
b4d8192d210290112e07b0e22b491c45c50ba696Evan Huntforeach $file (keys %file_types) {
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews $typeandowner = $file_types{$file};
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt $years_list = $file_years{$file};
c3b9fad5e3be639c9b36ff0ac921c30133da395cMar Andrews
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt if ( ! -f $file ) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print "$file: missing\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt next;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt # print "Doing: $file";
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt if ($years_list =~ /PARENT:/) {
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt getyears($years_list);
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt if (!defined $years_list) {
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt print "$file: has bad parent $parent\n";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt next;
215ef83bbed20727813a52ddcdbcd1455856638bMark Andrews }
215ef83bbed20727813a52ddcdbcd1455856638bMark Andrews }
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews # copyright notice is now generated from the source.
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews next if ($years_list eq "DOCBOOK");
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews if ($years_list eq "DOCBOOK") {
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews docbook($file);
a920fb9dc2ff16f32dd73e53469d0febcdcc6c11Mark Andrews if (!defined $years_list) {
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt print "$file: has bad parent $parent\n";
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt next;
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt }
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt }
9c03f13e18c1b0c32f62391a17300378605bbc7bEvan Hunt
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt @years = split(/,/, $years_list);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews my ($type, $owner) = split(/\./, $typeandowner);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $owner = "" if !defined $owner;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $textp = $owner2text{$owner};
42cf2ff7bad81c5a1f5d3be29d06e12504c3af24Evan Hunt if (!defined $textp) {
42cf2ff7bad81c5a1f5d3be29d06e12504c3af24Evan Hunt print "$file: unknown copyright owner $owner\n";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt next;
42cf2ff7bad81c5a1f5d3be29d06e12504c3af24Evan Hunt }
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt if ($file eq "./CHANGES" || $file eq "./EXCLUDED" ||
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt $file eq "./CHANGES.SE")
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt {
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt open(SOURCE, "<$file") || die "can't open $file: $!";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt my $body = "";
de52784e45e3a7a92c0d8ad843eb4db313bbfd97Mark Andrews while (<SOURCE>) {
de52784e45e3a7a92c0d8ad843eb4db313bbfd97Mark Andrews # Process leading white space.
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt # Remove 1-7 spaces followed by a tab into a single
de52784e45e3a7a92c0d8ad843eb4db313bbfd97Mark Andrews # tab if at start of line or proceeded by tabs.
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt s/^(\t*) {1,7}\t/$1\t/ while (/^\t* {1,7}\t/);
af850c4120c5bee9462de4def85d0b4c1b583963Mark Andrews s/^(\s{0,3}\d*\.)\s(\[\w{1,5}\])\s+(\S+)/$1\t$2\t\t$3/;
af850c4120c5bee9462de4def85d0b4c1b583963Mark Andrews s/^(\s{0,3}\d*\.)\s(\[\w{6,}\])\s+(\S+)/$1\t$2\t$3/;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt # Convert 8 spaces into tabs if at start of line
af850c4120c5bee9462de4def85d0b4c1b583963Mark Andrews # or preceeded by tabs.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt s/^(\t*) /$1\t/ while (/^\t* /);
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt # Remove trailing white space.
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt s/[ \t]*$//;
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt $body = "$body$_";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt }
8a2ab2b9203120c3e2a883a5ee8c0b5d60c1808cEvan Hunt $_ = $body;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews open(TARGET, ">$file.new") || die "can't open $file.new: $!";
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews print TARGET $_;
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews close(TARGET);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews close(SOURCE);
a266ab205bfd1c510022e2cd2a8cb62988242593Mark Andrews if (system("cmp -s $file.new $file") == 0) {
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt unlink("$file.new");
ef9f4d097794609e018963087fab10a8b51d8ad1Mark Andrews } else {
ef9f4d097794609e018963087fab10a8b51d8ad1Mark Andrews rename("$file.new", "$file")
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt or die "rename($file.new, $file): $!";
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt }
e7857b5ee05414961bb11f9e57f654163fae6acbckb }
e7857b5ee05414961bb11f9e57f654163fae6acbckb
e7857b5ee05414961bb11f9e57f654163fae6acbckb next if $type eq "X" or $type eq "BAT";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt
ef9f4d097794609e018963087fab10a8b51d8ad1Mark Andrews $before_copyright = "";
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt $c_comment = 0;
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt $shell_comment = 0;
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt $m4_comment = 0;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $sgml_comment = 0;
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt $mkd_comment = 0;
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt $zone_comment = 0;
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt $man_comment = 0;
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt $python_comment = 0;
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt $python_bin_comment = 0;
b66b333f59cf51ef87f973084a5023acd9317fb2Evan Hunt $start_comment = "";
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews $end_comment = "";
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews $first = "";
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews if ($type =~ /^(C|YACC|CONF-C)$/) {
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $c_comment = 1;
80fa3ef8517ff046a72c4cb1e785f30c9ef9ee75Mark Andrews $start_comment = "/*\n";
7829fad4093f2c1985b1efb7cea00287ff015d2bckb $prefix = " * ";
7829fad4093f2c1985b1efb7cea00287ff015d2bckb $end_comment = " */\n";
7829fad4093f2c1985b1efb7cea00287ff015d2bckb } elsif ($type =~ /^(SH|PERL|TCL|MAKE|CONF-SH|RNC)$/) {
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman $shell_comment = 1;
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman $prefix = "# ";
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman } elsif ($type =~ /^PYTHON-BIN$/) {
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman $python_bin_comment = 1;
ce376a81fa674d240197628ceb6113a4fa5a1ab3Mukund Sivaraman $start_comment = "############################################################################\n";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $prefix = "# ";
7829fad4093f2c1985b1efb7cea00287ff015d2bckb $end_comment = "############################################################################\n"
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews } elsif ($type =~ /^PYTHON$/) {
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews $python_comment = 1;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews $start_comment = "############################################################################\n";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $prefix = "# ";
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews $end_comment = "############################################################################\n"
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt } elsif ($type eq "ZONE" || $type eq "MC") {
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt $zone_comment = 1;
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt $prefix = "; ";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt } elsif ($type eq "MAN") {
501941f0b6cce74c2ff75b10aff3f230d5d37e4cEvan Hunt $man_comment = 1;
161e803a5608956271d8120be37a1b383d14b647Mark Andrews $prefix = ".\\\" ";
161e803a5608956271d8120be37a1b383d14b647Mark Andrews } elsif ($type eq "M4") {
161e803a5608956271d8120be37a1b383d14b647Mark Andrews $m4_comment = 1;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $prefix = "dnl ";
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt } elsif ($type eq "HTML" || $type eq "SGML") {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt $sgml_comment = 1;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt $start_comment = "<!--\n";
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt $prefix = " - ";
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt $end_comment = "-->\n";
161e803a5608956271d8120be37a1b383d14b647Mark Andrews } elsif ($type eq "MKD") {
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt $mkd_comment = 1;
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt $start_comment = "<!---\n";
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt $prefix = " - ";
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt $end_comment = "--->";
188690149b54145e1936898e565eb9eec139bbfeEvan Hunt } elsif ($type eq "TXT") {
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt $prefix = "";
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt } else {
5a75f61dd413720c16d229b24ebba6bd6ecdb738Evan Hunt print "$file: type '$type' not supported yet; skipping\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt next;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
99cbc3d3a4dcbd203146f62e37478aee1c8ee673Evan Hunt
b4d8192d210290112e07b0e22b491c45c50ba696Evan Hunt ($nonspaceprefix = $prefix) =~ s/\s+$//;
79f0eedd657d75889009226aa7ce23eeac28df5cMark Andrews
7829fad4093f2c1985b1efb7cea00287ff015d2bckb open(SOURCE, "<$file") || die "can't open $file: $!";
$_ = <SOURCE>;
if ($type eq "YACC") {
unless ($_ eq "%{\n") {
print "$file: unexpected yacc file start ",
"(expected \"%{\\n\")\n";
close(SOURCE);
next;
}
$before_copyright = "$_";
$_ = <SOURCE>;
}
if ($c_comment && /^\/\*/) {
$_ = <SOURCE>;
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
if ($_ !~ /\*\//) {
while (<SOURCE>) {
last if $_ =~ /\*\//;
}
}
} elsif ($shell_comment) {
if (/^\#\!/) {
$before_copyright = "$_#\n";
$_ = <SOURCE>;
$_ = <SOURCE> if $_ eq "#\n";
}
if (/^\#/) {
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^\#/) {
$first = $_;
last;
}
}
} else {
$first = $_;
}
} elsif ($python_comment || $python_bin_comment) {
if ($python_bin_comment && /^\#\!/) {
$before_copyright = "$_";
$_ = <SOURCE>;
$_ = <SOURCE> if $_ eq "#\n";
$_ = <SOURCE> if $_ eq "############################################################################\n";
} elsif ($python_comment && /^\#/) {
$_ = <SOURCE> if $_ eq "#\n";
$_ = <SOURCE> if $_ eq "############################################################################\n";
}
if (/^\#/) {
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^\#/) {
$first = $_;
last;
}
}
} else {
$first = $_;
}
} elsif (($m4_comment || $zone_comment || $man_comment) &&
/^\Q$nonspaceprefix\E/) {
while (/^\Q$nonspaceprefix\E\s*$/) {
$_ = <SOURCE>;
}
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^\Q$nonspaceprefix\E/ ||
$_ =~ /$keyword_pat/) {
$first = $_;
last;
}
}
} elsif ($sgml_comment) {
$before_copyright = "";
while (/^<!DOCTYPE/ || /^<!ENTITY/ || /^<\?xml-stylesheet/ || /^<\?xml /) {
# print "SGML: $_";
$before_copyright = "$before_copyright$_";
if (/\]>$/ ) {
$_ = <SOURCE>;
close(SOURCE) if (eof(SOURCE));
next;
}
if (/^<!DOCTYPE.*\[$/) {
while (!eof(SOURCE)) {
$_ = <SOURCE>;
next if (eof(SOURCE));
$before_copyright =
"$before_copyright$_";
if (/]>$/) {
$_ = <SOURCE>;
last;
}
}
close(SOURCE) if (eof(SOURCE));
next;
}
if (/>$/ ) {
$_ = <SOURCE>;
close(SOURCE) if (eof(SOURCE));
next;
}
$_ = <SOURCE>;
while (!eof(SOURCE) && ! /^<!/ ) {
$before_copyright = "$before_copyright$_";
$_ = <SOURCE>;
}
if (eof(SOURCE)) {
close(SOURCE);
next;
}
}
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 ($mkd_comment) {
$before_copyright = "";
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 if /Portions of this code/;
last unless
/[Cc]opyright/ ||
/This Source Code Form is subject to the terms of the Mozilla Public/ ||
/If a copy of the MPL was not distributed with this/ ||
/You can obtain one at http:\/\/mozilla.org\/MPL\/2.0\// ||
/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;
$sysyears = "";
$nomyears = "";
#
# Nominum: up to 2001.
#
$last_year = 0;
$anchor_year = 0;
$years = "";
foreach $year (@years) {
if ($year >= 2002) { next; }
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;
}
$nomyears = $years;
#
# Internet Systems Consortium: 2004 onwards.
#
$last_year = 0;
$anchor_year = 0;
$years = "";
$anchor_end = length($years);
my $andor = 0;
my $noid = 0;
foreach $year (@years) {
$andor = 1 if ($year >= 2007);
$noid = 1 if ($year > 2012 || ($year == 2012 && $this_month >= 5) );
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;
}
$sysyears = $years;
# make a copy
@lines = @$textp;
foreach $_ (@lines) {
next if (/\@SYSYEARS\@/ && $sysyears eq "");
s:modify, and distribute:modify, and/or distribute: if ($andor);
print TARGET (/^$/ ? $nonspaceprefix : $prefix);
s/\@SYSYEARS\@/$sysyears/;
s/\@NOMYEARS\@/$nomyears/;
print TARGET "$_";
}
print TARGET $end_comment if $end_comment;
if ($first eq "") {
$first = <SOURCE>;
}
if (defined($first)) {
if ($type eq 'MAN') {
print TARGET "$nonspaceprefix\n";
} else {
print TARGET "\n";
}
if (($type eq "C" || $type eq "CONF-C") &&
$sysyears =~ /$this_year/) {
my $body = "";
while (<SOURCE>) {
# Process leading white space.
# Remove 1-7 spaces followed by a tab into a single
# tab if at start of line or proceeded by tabs.
s/^(\t*) {1,7}\t/$1\t/ while (/^\t* {1,7}\t/);
# Convert 8 spaces into tabs if at start of line
# or preceeded by tabs.
s/^(\t*) {8}/$1\t/ while (/^\t* {8}/);
# Remove trailing white space.
s/[ \t]*$//;
$body = "$body$_";
}
$_ = $body;
} elsif (($type eq "SGML" || $type eq "HTML" ||
$type eq "MAKE") &&
$sysyears =~ /$this_year/) {
my $body = "";
while (<SOURCE>) {
# Remove trailing white space.
s/[ \t]*$//;
$body = "$body$_";
}
$_ = $body;
} else {
undef $/;
$_ = <SOURCE>;
$/ = "\n";
}
if ($type eq 'SGML' && m:<articleinfo>.*?</articleinfo>:s) {
# print "docinfo: $file\n";
my $r = copyrights(@years);
s:<articleinfo>.*?</articleinfo>:<articleinfo>\n$r </articleinfo>:s;
}
if ($type eq 'SGML' && m:<docinfo>.*?</docinfo>:s) {
# print "docinfo: $file\n";
my $r = copyrights(@years);
s:<docinfo>.*?</docinfo>:<docinfo>\n$r </docinfo>:s;
}
if ($type eq 'SGML' && m:<bookinfo>.*?</bookinfo>:s) {
# print "bookinfo: $file\n";
my $r = copyrights(@years);
$r .= " <xi:include href=\"releaseinfo.xml\"/>\n";
s:<bookinfo>.*?</bookinfo>:<bookinfo>\n$r </bookinfo>:s;
}
my ($start, $end);
if ($type =~ /^PYTHON(|-BIN)$/) {
($start = $prefix) =~ s/\s*\n//;
$end = "\n";
} elsif ($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 (!$noid && $first !~ /$keyword_pat/ &&
(!defined($_) || $_ !~ /$keyword_pat/)) {
$end = "\n$nonspaceprefix" if ($type eq "MAN");
print TARGET "$start\$";
print TARGET "Id";
print TARGET "\$$end\n";
}
print TARGET $first if $first !~ /^\s*$/;
print TARGET $_ if (defined($_));
}
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): $!";
}
}