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