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