update_copyrights revision 9640c35421ba0bb4af6b6bfbff695d2a0ac560b3
1633838b8255282d10af15c5c84cee5a51466712Bob Halley#!/usr/local/bin/perl -w
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater#
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# Copyright (C) 2004-2010, 2012 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# Copyright (C) 1998-2001 Internet Software Consortium.
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater#
1633838b8255282d10af15c5c84cee5a51466712Bob Halley# Permission to use, copy, modify, and/or distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley# purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# copyright notice and this permission notice appear in all copies.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1633838b8255282d10af15c5c84cee5a51466712Bob Halley# PERFORMANCE OF THIS SOFTWARE.
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews# $Id$
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halleyrequire 5.002;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley# Map copyright owners to the files containing copyright messages.
29747dfe5e073a299b3681e01f5c55540f8bfed7Mark Andrews# The first line of the copyright message is not in the file;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# it is constructed by this script.
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley#
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley# Usage:
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley#
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley# perl util/update_copyrights <util/copyrights
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrencemy %owner2filename = (
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence "" => "util/COPYRIGHT",
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence "NAI" => "util/COPYRIGHT.NAI",
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence "NOM" => "util/COPYRIGHT.NOM",
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence "BSDI" => "util/COPYRIGHT.BSDI",
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence "BRIEF" => "util/COPYRIGHT.BRIEF",
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence "PORTION" => "util/COPYRIGHT.PORTION",
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley);
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley# Map each copyright owner name to a reference to an array containing
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley# the lines of the copyright message.
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonmy %owner2text = ();
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrewsmy $keyword_pat = '\$(Id:.*|Revision:.*|Id|Revision)\$';
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrewsforeach $owner (keys %owner2filename) {
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington my $f = $owner2filename{$owner};
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington open(COPYRIGHT, "<$f") || die "can't open $f: $!";
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews @copyright_text = <COPYRIGHT>;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington close(COPYRIGHT);
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $owner2text{$owner} = [ @copyright_text ];
bcff3198111e329e89cde7dac9d432b002477d80Mark Andrews}
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonmy %file_types = ();
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonmy %file_years = ();
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonmy $years_list;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonmy $parent;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington($dummy,$dummy,$dummy,$dummy,$this_month,$this_year,$dummy,$dummy,$dummy) = localtime(time());
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley$this_year += 1900;
84cb41f729e2a8526300dd7a6cffaa66da5cf6cdMark Andrews
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonwhile (<>) {
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington chomp;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington ($file, $type, $years) = split(/\s+/);
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $file_types{$file} = $type;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $file_years{$file} = $years;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington}
618e871c2eb80021673bedf083496ccd1bf65cd0Brian Wellington
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellingtonsub getyears {
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $parent = $_[0];
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $parent =~ s/PARENT://;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $years_list = $file_years{$parent};
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington if (defined($years_list) && $years_list =~ /^PARENT:/) {
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington print "BAD PARENT:$parent\n";
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington undefine($years_list);
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington }
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington}
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halleysub docbook {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $parent = $_[0];
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews $parent =~ s/\.[^.]*$/.docbook/;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $years_list = $file_years{$parent};
308c7ad5f68301d19f023af616f62f3e7cbce632Andreas Gustafsson}
04b8111f2137a9cf9b0b71228f76b3e40ffa1173Brian Wellington
04b8111f2137a9cf9b0b71228f76b3e40ffa1173Brian Wellingtonsub copyright {
ccad3c9ecbe8a1060ff7b407a318ccd592de536eBrian Wellington my $holder = shift;
ccad3c9ecbe8a1060ff7b407a318ccd592de536eBrian Wellington my $result = "";
ccad3c9ecbe8a1060ff7b407a318ccd592de536eBrian Wellington return $result unless (@_);
ccad3c9ecbe8a1060ff7b407a318ccd592de536eBrian Wellington $result = "$result <copyright>\n";
ccad3c9ecbe8a1060ff7b407a318ccd592de536eBrian Wellington $result = "$result <year>$_</year>\n" foreach (@_);
8224be5129daebea8f0f5e8be5f925679ec893f1Brian Wellington $result = "$result <holder>$holder</holder>\n";
8224be5129daebea8f0f5e8be5f925679ec893f1Brian Wellington $result = "$result </copyright>\n";
a413f94248ceed48a6b7aaa2fa1d2401fb8b9f30Brian Wellington return $result;
d14b749789121d9d502fa1348e9e73270e9b039fBob Halley}
63d1ef9e771b748ca9bf241dfc1f07d3730203faBob Halley
659175b7d430afe13b439e499442a964e2c9110fMark Andrewssub copyrights {
cd02757774252fe5b92dbd59a24b34721fb49ff4Bob Halley my $a = copyright("Internet Systems Consortium, Inc. (\"ISC\")",
cd02757774252fe5b92dbd59a24b34721fb49ff4Bob Halley grep({ $_ >= 2004} @_));
7b4dcbb89b71b17f5c16ca19a0e705e09509f063Bob Halley my $b = copyright("Internet Software Consortium.",
73af6575e00f8cf4942abce177f435797b9cfe41Brian Wellington grep({ $_ < 2004} @_));
322b0fb39dd1538c9f5021cd2f54d4c12684ecdbBrian Wellington return "$a$b";
3864eb0e9a73148ac744893b5367169761184db5Mark Andrews}
f53e43c37f2c978ccec0b49ed829426b213f9933Bob Halley
afbc02482008c58af2c98000209165f6880835f7Mark Andrewsforeach $file (keys %file_types) {
e1f16346db02486f751c6db683fffe53c866c186Andreas Gustafsson $typeandowner = $file_types{$file};
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews $years_list = $file_years{$file};
2ee24549b3dddd4046ee14257e1207cf2e34f29cBrian Wellington
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews if ( ! -f $file ) {
6850cdd4497424c9d42ade487edfde9fb9a47de9Brian Wellington print "$file: missing\n";
20a313a4581e7f85fb2ce37430a146b3538da841Mark Andrews next;
20a313a4581e7f85fb2ce37430a146b3538da841Mark Andrews }
b20ee662a7c847c9ef7b96ab9e5e34543efe5c0dMark Andrews # print "Doing: $file";
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington if ($years_list =~ /PARENT:/) {
6a56be50dd11702cb65347a57894ffd96a7e3501Andreas Gustafsson getyears($years_list);
1275a72e8db349ce249c84804b2b4861d33d4db7Brian Wellington if (!defined $years_list) {
15af30dfc1c54a02d252dcf4c6f3b8759eaf0327Bob Halley print "$file: has bad parent $parent\n";
15af30dfc1c54a02d252dcf4c6f3b8759eaf0327Bob Halley next;
58cbc05eb0b80510182496ad905cd407f3624dbeBrian Wellington }
a93cf7e83be621d3d68f51e37121a47a70a6757bMark Andrews }
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews
5ea0d11ca45bfd1ea9db8db07f18fbb02f500661Brian Wellington # copyright notice is now generated from the source.
a9ef4854464fcc56d95f72331b6e09e9563bb5f3Andreas Gustafsson next if ($years_list eq "DOCBOOK");
2c64908ae0d5b5a1cfead295d7526e7be550d3d3Mark Andrews
01446841be2b73f9a2ead74056df2d5342414041Andreas Gustafsson if ($years_list eq "DOCBOOK") {
ff1b064f5e2bf19c8e25f8927d23df5714e666edMark Andrews docbook($file);
b6279d0b4b19f041b29775e637074e09f38e5e11Brian Wellington if (!defined $years_list) {
231ffa6c85cd04d5d83f80643e26fdc3ff510138Brian Wellington print "$file: has bad parent $parent\n";
4b171ebd702d72200a4d7609f11c5f79d6b6f964Brian Wellington next;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews }
4d9f3f00d93fcb8743b1105e8cf82e862be220d1Mark Andrews }
5bd76af084edfdcd1cb4db9453ac781d32dde6f7Mark Andrews
5bd76af084edfdcd1cb4db9453ac781d32dde6f7Mark Andrews @years = split(/,/, $years_list);
5bd76af084edfdcd1cb4db9453ac781d32dde6f7Mark Andrews
5bd76af084edfdcd1cb4db9453ac781d32dde6f7Mark Andrews my ($type, $owner) = split(/\./, $typeandowner);
5bd76af084edfdcd1cb4db9453ac781d32dde6f7Mark Andrews $owner = "" if !defined $owner;
c86eed4bdecad9df12f992f9d743dfee3a6c5bdcMark Andrews
421e4cf66e4cba0b0751a34a9c027e39fe0474f9Mark Andrews $textp = $owner2text{$owner};
8b5de9701428e2b5eb50aba96af23dc1186124ddMark Andrews if (!defined $textp) {
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews print "$file: unknown copyright owner $owner\n";
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews next;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
d5ad558234adfef1b847b534dd7b4c6302cc5ea3Mark Andrews next if $type eq "X" or $type eq "BAT";
c5cde9d5a70c921da901a23845e740ccc7a8c4e4Mark Andrews
8d414d155953f89a4eff40f16878438a8c9228f3Mark Andrews $before_copyright = "";
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrews $c_comment = 0;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews $shell_comment = 0;
9b80f3a7c739a99b498a37a711a51b6a88df3a78Mark Andrews $m4_comment = 0;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews $sgml_comment = 0;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $zone_comment = 0;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews $man_comment = 0;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $python_comment = 0;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $start_comment = "";
894a2f61c9e3e51463bf21957c003d7c5636bdc5David Lawrence $end_comment = "";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $first = "";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley if ($type =~ /^(C|YACC|CONF-C)$/) {
894a2f61c9e3e51463bf21957c003d7c5636bdc5David Lawrence $c_comment = 1;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $start_comment = "/*\n";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $prefix = " * ";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $end_comment = " */\n";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley } elsif ($type =~ /^(SH|PERL|TCL|MAKE|CONF-SH|RNC)$/) {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $shell_comment = 1;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley } elsif ($type =~ /^PYTHON$/) {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $python_comment = 1;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $start_comment = "############################################################################\n";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $prefix = "# ";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $end_comment = "############################################################################\n"
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley } elsif ($type eq "ZONE" || $type eq "MC") {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $zone_comment = 1;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $prefix = "; ";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley } elsif ($type eq "MAN") {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein $man_comment = 1;
125d72976ab6b8fa6629a5ace276a86e9fef91acBrian Wellington $prefix = ".\\\" ";
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley } elsif ($type eq "M4") {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley $m4_comment = 1;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley $prefix = "dnl ";
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence } elsif ($type eq "HTML" || $type eq "SGML") {
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence $sgml_comment = 1;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence $start_comment = "<!--\n";
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence $prefix = " - ";
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence $end_comment = "-->\n";
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence } elsif ($type eq "TXT") {
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence $prefix = "";
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence } else {
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence print "$file: type '$type' not supported yet; skipping\n";
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence next;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley }
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley ($nonspaceprefix = $prefix) =~ s/\s+$//;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
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) {
if (/^\#\!/) {
$before_copyright = "$_";
$_ = <SOURCE>;
$_ = <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/ || /^<\?xml-stylesheet/ || /^<\?xml /) {
# print "SGML: $_";
$before_copyright = "$before_copyright$_";
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 ($type eq "TXT") {
if ($_ =~ /[Cc]opyright/) {
$/ = ""; # paragraph at a time
while (<SOURCE>) {
# Not very maintainable, but ok enough for now.
last unless
/[Cc]opyright/ ||
/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 = "";
$sftyears = "";
$nomyears = "";
#
# Internet Software Consortium: up to 2003
#
$last_year = 0;
$anchor_year = 0;
$years = "";
foreach $year (@years) {
if ($year >= 2004) { 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;
}
$sftyears = $years;
#
# 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) {
if ($year < 2004) { next; }
$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;
($firstline, $secondline, @otherlines) = @$textp;
$firstline =~ s/\@SYSYEARS\@/$sysyears/;
$secondline =~ s/\@SFTYEARS\@/$sftyears/;
print TARGET "$prefix$firstline";
if ($sftyears ne "" ) {
print TARGET $secondline =~ /^$/ ? $nonspaceprefix : $prefix;
print TARGET "$secondline";
}
foreach $_ (@otherlines) {
s:modify, and distribute:modify, and/or distribute: if ($andor);
print TARGET (/^$/ ? $nonspaceprefix : $prefix);
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" && $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*) /$1\t/ while (/^\t* /);
# 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);
s:<bookinfo>.*?</bookinfo>:<bookinfo>\n$r </bookinfo>:s;
}
my ($start, $end);
if ($type =~ /^PYTHON$/) {
($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): $!";
}
}