update_copyrights revision 15a44745412679c30a6d022733925af70a38b715
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley#!/usr/local/bin/perl -w
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley#
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence# Copyright (C) 1998-2000 Internet Software Consortium.
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley#
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# Permission to use, copy, modify, and distribute this software for any
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# purpose with or without fee is hereby granted, provided that the above
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# copyright notice and this permission notice appear in all copies.
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley#
15a44745412679c30a6d022733925af70a38b715David Lawrence# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15a44745412679c30a6d022733925af70a38b715David Lawrence
15a44745412679c30a6d022733925af70a38b715David Lawrence# $Id: update_copyrights,v 1.17 2000/07/27 09:55:03 tale Exp $
e85ffb301b294d70ddc1d90234788403666bb944David Lawrence
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafssonrequire 5.002;
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson# Map copyright owners to the files containing copyright messages.
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson# The first line of the copyright message is not in the file;
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson# it is constructed by this script.
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafssonmy %owner2filename = (
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson "" => "util/COPYRIGHT",
828a5beda384130d5e2913dadd862924c53405bfAndreas Gustafsson "NAI" => "util/COPYRIGHT.NAI",
855bda3de3bf5d55288f7a1dc57df58b5ac780b0Andreas Gustafsson "BSDI" => "util/COPYRIGHT.BSDI",
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence "BRIEF" => "util/COPYRIGHT.BRIEF",
828a5beda384130d5e2913dadd862924c53405bfAndreas Gustafsson "PORTION" => "util/COPYRIGHT.PORTION",
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson);
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson# Map each copyright owner name to a reference to an array containing
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson# the lines of the copyright message.
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafssonmy %owner2text = ();
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafssonforeach $owner (keys %owner2filename) {
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson my $f = $owner2filename{$owner};
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson open(COPYRIGHT, "<$f") || die "can't open $f: $!";
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson @copyright_text = <COPYRIGHT>;
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson close(COPYRIGHT);
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $owner2text{$owner} = [ @copyright_text ];
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
b897c52f865b2fc4e220e2110b874e59c716456bBob Halleywhile (<>) {
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson ($file, $typeandowner, $years_list) = split(/\s+/);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley @years = split(/,/, $years_list);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ( ! -f $file ) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print "$file: missing\n";
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson my ($type, $owner) = split(/\./, $typeandowner);
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $owner = "" if !defined $owner;
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $textp = $owner2text{$owner};
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson if (!defined $textp) {
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson print "$file: unknown copyright owner $owner\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson next if $type eq "X";
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $before_copyright = "";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $c_comment = 0;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $shell_comment = 0;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $m4_comment = 0;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $html_comment = 0;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $zone_comment = 0;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $man_comment = 0;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $start_comment = "";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $end_comment = "";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $first = "";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($type =~ /^(C|YACC|CONF-C)/) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $c_comment = 1;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $start_comment = "/*\n";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $prefix = " * ";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $end_comment = " */\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($type =~ /^(SH|PERL|MAKE|CONF-SH)/) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $shell_comment = 1;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $prefix = "# ";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($type eq "ZONE") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $zone_comment = 1;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $prefix = "; ";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($type eq "MAN") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $man_comment = 1;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $prefix = ".\\\" ";
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley } elsif ($type eq "M4") {
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $m4_comment = 1;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $prefix = "dnl ";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($type eq "HTML") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $html_comment = 1;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $start_comment = "<!--\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $prefix = " - ";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $end_comment = "-->\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($type eq "TXT") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $prefix = "";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley } else {
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley print "$file: type '$type' not supported yet; skipping\n";
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
d7e7a17b7619a6de52951d095d3ee6463df41dfaDavid Lawrence
d7e7a17b7619a6de52951d095d3ee6463df41dfaDavid Lawrence ($nonspaceprefix = $prefix) =~ s/\s+$//;
d7e7a17b7619a6de52951d095d3ee6463df41dfaDavid Lawrence
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley open(SOURCE, "<$file") || die "can't open $file: $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $_ = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($type eq "YACC") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence unless ($_ eq "%{\n") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence print "$file: unexpected yacc file start (expected \"%{\\n\")\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence close(SOURCE);
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence next;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $before_copyright = "$_";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $_ = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($c_comment && /^\/\*/) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $_ = <SOURCE>;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($_ !~ /[Cc]opyright/) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print "$file: non-copyright comment\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(SOURCE);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($_ !~ /\*\//) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley while (<SOURCE>) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($_ =~ /\*\//) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley last;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley } elsif ($shell_comment) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if (/^\#\!/) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $before_copyright = "$_#\n";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $_ = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $_ = <SOURCE> if $_ eq "#\n";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if (/^\#/) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($_ !~ /[Cc]opyright/) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley print "$file: non-copyright comment\n";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley close(SOURCE);
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley next;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley while (<SOURCE>) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($_ !~ /^\#/) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $first = $_;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley last;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley } else {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $first = $_;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif (($m4_comment || $zone_comment || $man_comment) &&
d7e7a17b7619a6de52951d095d3ee6463df41dfaDavid Lawrence /^\Q$nonspaceprefix\E/) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence while (/^\Q$nonspaceprefix\E\s*$/) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $_ = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley if ($_ !~ /[Cc]opyright/) {
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley print "$file: non-copyright comment\n";
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley close(SOURCE);
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley next;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley }
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley while (<SOURCE>) {
d7e7a17b7619a6de52951d095d3ee6463df41dfaDavid Lawrence if ($_ !~ /^\Q$nonspaceprefix\E/) {
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $first = $_;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley last;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley }
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($html_comment) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if (/^<!DOCTYPE/) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $before_copyright = $_;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $_ = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if (/^<!/) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $_ = <SOURCE> if $_ eq "<!--\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($_ !~ /[Cc]opyright/) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence print "$file: non-copyright comment\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence close(SOURCE);
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence next;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence while (defined($_)) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence last if s/.*-->//;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $_ = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence print "$file: unterminated comment\n" unless defined($_);
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($_ ne "\n") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $first = $_;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } else {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $first = <SOURCE>;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } else {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $first = $_;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } elsif ($type eq "TXT") {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($_ =~ /[Cc]opyright/) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $/ = ""; # paragraph at a time
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence while (<SOURCE>) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence # Not very maintainable, but suitable enough for now.
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence last unless
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence /See COPYRIGHT in the source root/ ||
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence /Permission to use, copy, modify, and distribute / ||
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence /THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET /;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $/ = "\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $first = $_;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley } else {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first = $_;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $first = "" if ! defined($first);
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley open(TARGET, ">$file.new") || die "can't open $file.new: $!";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($before_copyright ne "") {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley print TARGET $before_copyright;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($start_comment) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence print TARGET $start_comment;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $years = "";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $last_year = 0;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $anchor_year = 0;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley foreach $year (@years) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($last_year != 0 && $year == $last_year + 1) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($year > $anchor_year + 1) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence substr($years, $anchor_end) = "-$year";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } else {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $years .= ", $year";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } else {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $years .= $last_year == 0 ? "$year" : ", $year";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($anchor_year != 0) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence print "$file: noncontiguous year: $year != $last_year + 1\n";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $anchor_year = $year;
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $anchor_end = length($years);
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence $last_year = $year;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson ($firstline, @otherlines) = @$textp;
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $firstline =~ s/\@YEARS\@/$years/;
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson print TARGET "$prefix$firstline";
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson foreach $_ (@otherlines) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET "${prefix}$_";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if ($end_comment) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence print TARGET $end_comment;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($first eq "") {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $first = <SOURCE>;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if (defined($first)) {
541ed6feaf687e97990ad19748faeec744158559David Lawrence print TARGET "\n";
541ed6feaf687e97990ad19748faeec744158559David Lawrence
541ed6feaf687e97990ad19748faeec744158559David Lawrence undef $/;
541ed6feaf687e97990ad19748faeec744158559David Lawrence $_ = <SOURCE>;
541ed6feaf687e97990ad19748faeec744158559David Lawrence $/ = "\n";
541ed6feaf687e97990ad19748faeec744158559David Lawrence
541ed6feaf687e97990ad19748faeec744158559David Lawrence my $pat = '\$(Id|Revision):.*\$';
541ed6feaf687e97990ad19748faeec744158559David Lawrence my ($start, $end);
541ed6feaf687e97990ad19748faeec744158559David Lawrence if ($start_comment ne "") {
541ed6feaf687e97990ad19748faeec744158559David Lawrence ($start = $start_comment) =~ s/\s*\n/ /;
541ed6feaf687e97990ad19748faeec744158559David Lawrence ($end = $end_comment) =~ s/^\s*(.*)\n/ $1\n/;
541ed6feaf687e97990ad19748faeec744158559David Lawrence } elsif ($prefix ne "") {
541ed6feaf687e97990ad19748faeec744158559David Lawrence ($start = $prefix) =~ s/\s*\n//;
541ed6feaf687e97990ad19748faeec744158559David Lawrence $end = "\n";
541ed6feaf687e97990ad19748faeec744158559David Lawrence } else {
541ed6feaf687e97990ad19748faeec744158559David Lawrence $start = "";
541ed6feaf687e97990ad19748faeec744158559David Lawrence $end = "\n";
541ed6feaf687e97990ad19748faeec744158559David Lawrence }
541ed6feaf687e97990ad19748faeec744158559David Lawrence
541ed6feaf687e97990ad19748faeec744158559David Lawrence if ($first !~ /$pat/ && $_ !~ /$pat/) {
e85ffb301b294d70ddc1d90234788403666bb944David Lawrence print TARGET "$start\$";
e85ffb301b294d70ddc1d90234788403666bb944David Lawrence print TARGET "Id: ";
e85ffb301b294d70ddc1d90234788403666bb944David Lawrence print TARGET "\$$end\n";
541ed6feaf687e97990ad19748faeec744158559David Lawrence }
541ed6feaf687e97990ad19748faeec744158559David Lawrence
541ed6feaf687e97990ad19748faeec744158559David Lawrence print TARGET $first if $first !~ /^\s*$/;
541ed6feaf687e97990ad19748faeec744158559David Lawrence print TARGET $_;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(TARGET);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(SOURCE);
59a6d9cbcdbec6960d47e5871fb7e7c0253e1fb2Mark Andrews $mode = (stat $file)[2]&511;
59a6d9cbcdbec6960d47e5871fb7e7c0253e1fb2Mark Andrews chmod $mode, "$file.new";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence if (system("cmp -s $file.new $file") == 0) {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence unlink("$file.new");
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence } else {
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence rename("$file.new", "$file") || die "rename($file.new, $file): $!";
4b598d8ae578861d5f3fc1333c9f84c9c9c8be7cDavid Lawrence }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}