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