update_copyrights revision 10e873cb368b0ed17a328e5421a0411eb90da0cb
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont#!/usr/local/bin/perl -w
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont#
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# Copyright (C) 1998-2001 Internet Software Consortium.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont#
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# Permission to use, copy, modify, and distribute this software for any
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# purpose with or without fee is hereby granted, provided that the above
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# copyright notice and this permission notice appear in all copies.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont#
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# PERFORMANCE OF THIS SOFTWARE.
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# $Id: update_copyrights,v 1.42 2006/10/24 00:57:16 marka Exp $
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontrequire 5.002;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# Map copyright owners to the files containing copyright messages.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# The first line of the copyright message is not in the file;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# it is constructed by this script.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontmy %owner2filename = (
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "" => "util/COPYRIGHT",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "NAI" => "util/COPYRIGHT.NAI",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "NOM" => "util/COPYRIGHT.NOM",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "BSDI" => "util/COPYRIGHT.BSDI",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "BRIEF" => "util/COPYRIGHT.BRIEF",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "PORTION" => "util/COPYRIGHT.PORTION",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# Map each copyright owner name to a reference to an array containing
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# the lines of the copyright message.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontmy %owner2text = ();
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontmy $keyword_pat = '\$(Id:.*|Revision:.*|Id|Revision)\$';
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontforeach $owner (keys %owner2filename) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont my $f = $owner2filename{$owner};
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont open(COPYRIGHT, "<$f") || die "can't open $f: $!";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont @copyright_text = <COPYRIGHT>;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont close(COPYRIGHT);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $owner2text{$owner} = [ @copyright_text ];
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont}
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontmy %file_types = ();
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontmy %file_years = ();
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontmy $years_list;
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updatermy $parent;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontwhile (<>) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont chomp;
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater ($file, $type, $years) = split(/\s+/);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $file_types{$file} = $type;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $file_years{$file} = $years;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont}
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontsub getyears {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $parent = $_[0];
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $parent =~ s/PARENT://;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $years_list = $file_years{$parent};
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater if (defined($years_list) && $years_list =~ /^PARENT:/) {
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater print "BAD PARENT:$parent\n";
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater undefine($years_list);
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater }
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater}
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontsub docbook {
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater $parent = $_[0];
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $parent =~ s/\.[^.]*$/.docbook/;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $years_list = $file_years{$parent};
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont}
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontsub copyright {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont my $holder = shift;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont my $result = "";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont return $result unless (@_);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $result = "$result <copyright>\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $result = "$result <year>$_</year>\n" foreach (@_);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $result = "$result <holder>$holder</holder>\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $result = "$result </copyright>\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont return $result;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont}
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontsub copyrights {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont my $a = copyright("Internet Systems Consortium, Inc. (\"ISC\")",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont grep({ $_ >= 2004} @_));
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont my $b = copyright("Internet Software Consortium.",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont grep({ $_ < 2004} @_));
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont return "$a$b";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont}
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontforeach $file (keys %file_types) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $typeandowner = $file_types{$file};
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $years_list = $file_years{$file};
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ( ! -f $file ) {
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater print "$file: missing\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($years_list =~ /PARENT:/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont getyears($years_list);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if (!defined $years_list) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont print "$file: has bad parent $parent\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont # copyright notice is now generated from the source.
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next if ($years_list eq "DOCBOOK");
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($years_list eq "DOCBOOK") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont docbook($file);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if (!defined $years_list) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont print "$file: has bad parent $parent\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont @years = split(/,/, $years_list);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont my ($type, $owner) = split(/\./, $typeandowner);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $owner = "" if !defined $owner;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $textp = $owner2text{$owner};
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if (!defined $textp) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont print "$file: unknown copyright owner $owner\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next if $type eq "X" or $type eq "BAT";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $before_copyright = "";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $c_comment = 0;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $shell_comment = 0;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $m4_comment = 0;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $sgml_comment = 0;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $zone_comment = 0;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $man_comment = 0;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $start_comment = "";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $end_comment = "";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $first = "";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($type =~ /^(C|YACC|CONF-C)$/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $c_comment = 1;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $start_comment = "/*\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = " * ";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $end_comment = " */\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($type =~ /^(SH|PERL|TCL|MAKE|CONF-SH)$/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $shell_comment = 1;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = "# ";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($type eq "ZONE" || $type eq "MC") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $zone_comment = 1;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = "; ";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($type eq "MAN") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $man_comment = 1;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = ".\\\" ";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($type eq "M4") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $m4_comment = 1;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = "dnl ";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($type eq "HTML" || $type eq "SGML") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $sgml_comment = 1;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $start_comment = "<!--\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = " - ";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $end_comment = "-->\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($type eq "TXT") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $prefix = "";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } else {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont print "$file: type '$type' not supported yet; skipping\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont ($nonspaceprefix = $prefix) =~ s/\s+$//;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont open(SOURCE, "<$file") || die "can't open $file: $!";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $_ = <SOURCE>;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($type eq "YACC") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont unless ($_ eq "%{\n") {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont print "$file: unexpected yacc file start ",
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont "(expected \"%{\\n\")\n";
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater close(SOURCE);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $before_copyright = "$_";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $_ = <SOURCE>;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($c_comment && /^\/\*/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $_ = <SOURCE>;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($_ !~ /[Cc]opyright/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont print "$file: non-copyright comment\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont close(SOURCE);
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont next;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if ($_ !~ /\*\//) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont while (<SOURCE>) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont last if $_ =~ /\*\//;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($shell_comment) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont if (/^\#\!/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $before_copyright = "$_#\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $_ = <SOURCE>;
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $_ = <SOURCE> if $_ eq "#\n";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont }
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont 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) {
if (/^<!DOCTYPE/) {
$before_copyright = $_;
$_ = <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);
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;
}
$sysyears = $years;
($firstline, $secondline, $thirdline, @otherlines) = @$textp;
$firstline =~ s/\@SYSYEARS\@/$sysyears/;
$secondline =~ s/\@SFTYEARS\@/$sftyears/;
$thirdline =~ s/\@NOMYEARS\@/$nomyears/;
print TARGET "$prefix$firstline";
if ($sftyears ne "" ) {
print TARGET $secondline =~ /^$/ ? $nonspaceprefix : $prefix;
print TARGET "$secondline";
}
print TARGET $thirdline =~ /^$/ ? $nonspaceprefix : $prefix;
print TARGET "$thirdline";
foreach $_ (@otherlines) {
print TARGET (/^$/ ? $nonspaceprefix : $prefix);
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";
}
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 ($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 !~ /$keyword_pat/ && $_ !~ /$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 $_;
}
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): $!";
}
}