update_copyrights revision 599a98b25ca10c501bdf3368eab2a2a951130949
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#!/usr/local/bin/perl -w
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#
6fe42ff85ced80bd2ccc49b429d36831b5f2a5b9Tinderbox User# Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# Copyright (C) 1998-2001 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# Permission to use, copy, modify, and/or distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# PERFORMANCE OF THIS SOFTWARE.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt# $Id: update_copyrights,v 1.49 2007/06/18 05:59:26 marka Exp $
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyerrequire 5.002;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer# Map copyright owners to the files containing copyright messages.
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer# The first line of the copyright message is not in the file;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews# it is constructed by this script.
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt# Usage:
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt#
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt# perl util/update_copyrights <util/copyrights
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Huntmy %owner2filename = (
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt "" => "util/COPYRIGHT",
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt "NAI" => "util/COPYRIGHT.NAI",
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt "NOM" => "util/COPYRIGHT.NOM",
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt "BSDI" => "util/COPYRIGHT.BSDI",
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt "BRIEF" => "util/COPYRIGHT.BRIEF",
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt "PORTION" => "util/COPYRIGHT.PORTION",
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt);
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt# Map each copyright owner name to a reference to an array containing
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt# the lines of the copyright message.
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Huntmy %owner2text = ();
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntmy $keyword_pat = '\$(Id:.*|Revision:.*|Id|Revision)\$';
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyerforeach $owner (keys %owner2filename) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt my $f = $owner2filename{$owner};
222d38735f97f771054e223b03f84c5858252332Evan Hunt open(COPYRIGHT, "<$f") || die "can't open $f: $!";
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer @copyright_text = <COPYRIGHT>;
222d38735f97f771054e223b03f84c5858252332Evan Hunt close(COPYRIGHT);
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence $owner2text{$owner} = [ @copyright_text ];
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntmy %file_types = ();
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyermy %file_years = ();
222d38735f97f771054e223b03f84c5858252332Evan Huntmy $years_list;
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrencemy $parent;
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntwhile (<>) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt chomp;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer ($file, $type, $years) = split(/\s+/);
222d38735f97f771054e223b03f84c5858252332Evan Hunt $file_types{$file} = $type;
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence $file_years{$file} = $years;
fdebae839745f79a7550aeb49d15a930523ec483David Lawrence}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafssonsub getyears {
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson $parent = $_[0];
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt $parent =~ s/PARENT://;
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt $years_list = $file_years{$parent};
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson if (defined($years_list) && $years_list =~ /^PARENT:/) {
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson print "BAD PARENT:$parent\n";
222d38735f97f771054e223b03f84c5858252332Evan Hunt undefine($years_list);
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt}
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyersub docbook {
222d38735f97f771054e223b03f84c5858252332Evan Hunt $parent = $_[0];
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence $parent =~ s/\.[^.]*$/.docbook/;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer $years_list = $file_years{$parent};
222d38735f97f771054e223b03f84c5858252332Evan Hunt}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyersub copyright {
222d38735f97f771054e223b03f84c5858252332Evan Hunt my $holder = shift;
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence my $result = "";
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer return $result unless (@_);
222d38735f97f771054e223b03f84c5858252332Evan Hunt $result = "$result <copyright>\n";
222d38735f97f771054e223b03f84c5858252332Evan Hunt $result = "$result <year>$_</year>\n" foreach (@_);
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer $result = "$result <holder>$holder</holder>\n";
222d38735f97f771054e223b03f84c5858252332Evan Hunt $result = "$result </copyright>\n";
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence return $result;
222d38735f97f771054e223b03f84c5858252332Evan Hunt}
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntsub copyrights {
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer my $a = copyright("Internet Systems Consortium, Inc. (\"ISC\")",
222d38735f97f771054e223b03f84c5858252332Evan Hunt grep({ $_ >= 2004} @_));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt my $b = copyright("Internet Software Consortium.",
222d38735f97f771054e223b03f84c5858252332Evan Hunt grep({ $_ < 2004} @_));
222d38735f97f771054e223b03f84c5858252332Evan Hunt return "$a$b";
222d38735f97f771054e223b03f84c5858252332Evan Hunt}
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Huntforeach $file (keys %file_types) {
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt $typeandowner = $file_types{$file};
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt $years_list = $file_years{$file};
222d38735f97f771054e223b03f84c5858252332Evan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt if ( ! -f $file ) {
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt print "$file: missing\n";
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt next;
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt }
222d38735f97f771054e223b03f84c5858252332Evan Hunt # print "Doing: $file";
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt if ($years_list =~ /PARENT:/) {
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt getyears($years_list);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt if (!defined $years_list) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt print "$file: has bad parent $parent\n";
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt next;
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
222d38735f97f771054e223b03f84c5858252332Evan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt # copyright notice is now generated from the source.
222d38735f97f771054e223b03f84c5858252332Evan Hunt next if ($years_list eq "DOCBOOK");
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($years_list eq "DOCBOOK") {
222d38735f97f771054e223b03f84c5858252332Evan Hunt docbook($file);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt if (!defined $years_list) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt print "$file: has bad parent $parent\n";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt next;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt }
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt @years = split(/,/, $years_list);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt my ($type, $owner) = split(/\./, $typeandowner);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $owner = "" if !defined $owner;
222d38735f97f771054e223b03f84c5858252332Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $textp = $owner2text{$owner};
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt if (!defined $textp) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt print "$file: unknown copyright owner $owner\n";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt next;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt }
222d38735f97f771054e223b03f84c5858252332Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt next if $type eq "X" or $type eq "BAT";
222d38735f97f771054e223b03f84c5858252332Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $before_copyright = "";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $c_comment = 0;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $shell_comment = 0;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $m4_comment = 0;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $sgml_comment = 0;
222d38735f97f771054e223b03f84c5858252332Evan Hunt $zone_comment = 0;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $man_comment = 0;
222d38735f97f771054e223b03f84c5858252332Evan Hunt $start_comment = "";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $end_comment = "";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $first = "";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt if ($type =~ /^(C|YACC|CONF-C)$/) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $c_comment = 1;
222d38735f97f771054e223b03f84c5858252332Evan Hunt $start_comment = "/*\n";
222d38735f97f771054e223b03f84c5858252332Evan Hunt $prefix = " * ";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $end_comment = " */\n";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt } elsif ($type =~ /^(SH|PERL|TCL|MAKE|CONF-SH|RNC)$/) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $shell_comment = 1;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $prefix = "# ";
222d38735f97f771054e223b03f84c5858252332Evan Hunt } elsif ($type eq "ZONE" || $type eq "MC") {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $zone_comment = 1;
222d38735f97f771054e223b03f84c5858252332Evan Hunt $prefix = "; ";
222d38735f97f771054e223b03f84c5858252332Evan Hunt } elsif ($type eq "MAN") {
222d38735f97f771054e223b03f84c5858252332Evan Hunt $man_comment = 1;
222d38735f97f771054e223b03f84c5858252332Evan Hunt $prefix = ".\\\" ";
222d38735f97f771054e223b03f84c5858252332Evan Hunt } elsif ($type eq "M4") {
222d38735f97f771054e223b03f84c5858252332Evan Hunt $m4_comment = 1;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt $prefix = "dnl ";
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt } elsif ($type eq "HTML" || $type eq "SGML") {
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt $sgml_comment = 1;
d58e33bfabfee19a035031dac633d36659738d56Evan Hunt $start_comment = "<!--\n";
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt $prefix = " - ";
222d38735f97f771054e223b03f84c5858252332Evan Hunt $end_comment = "-->\n";
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt } elsif ($type eq "TXT") {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $prefix = "";
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt } else {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt print "$file: type '$type' not supported yet; skipping\n";
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt next;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt ($nonspaceprefix = $prefix) =~ s/\s+$//;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt open(SOURCE, "<$file") || die "can't open $file: $!";
222d38735f97f771054e223b03f84c5858252332Evan Hunt $_ = <SOURCE>;
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($type eq "YACC") {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt unless ($_ eq "%{\n") {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt print "$file: unexpected yacc file start ",
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt "(expected \"%{\\n\")\n";
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt close(SOURCE);
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt next;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $before_copyright = "$_";
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $_ = <SOURCE>;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if ($c_comment && /^\/\*/) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $_ = <SOURCE>;
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($_ !~ /[Cc]opyright/) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt print "$file: non-copyright comment\n";
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt close(SOURCE);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt next;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if ($_ !~ /\*\//) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt while (<SOURCE>) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt last if $_ =~ /\*\//;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt } elsif ($shell_comment) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (/^\#\!/) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $before_copyright = "$_#\n";
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $_ = <SOURCE>;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt $_ = <SOURCE> if $_ eq "#\n";
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt }
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (/^\#/) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($_ !~ /[Cc]opyright/) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt print "$file: non-copyright comment\n";
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt close(SOURCE);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt next;
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt }
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt while (<SOURCE>) {
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt if ($_ !~ /^\#/) {
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt $first = $_;
222d38735f97f771054e223b03f84c5858252332Evan Hunt last;
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt }
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt }
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt } else {
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt $first = $_;
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt }
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt } elsif (($m4_comment || $zone_comment || $man_comment) &&
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt /^\Q$nonspaceprefix\E/) {
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt while (/^\Q$nonspaceprefix\E\s*$/) {
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt $_ = <SOURCE>;
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt }
ffff5d67926821d3db8df63bdd84a9cb1ce56739Evan Hunt
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if ($_ !~ /[Cc]opyright/) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews print "$file: non-copyright comment\n";
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews close(SOURCE);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews next;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews while (<SOURCE>) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if ($_ !~ /^\Q$nonspaceprefix\E/ ||
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews $_ =~ /$keyword_pat/) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews $first = $_;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews last;
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews }
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews } elsif ($sgml_comment) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews $before_copyright = "";
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews while (/^<!DOCTYPE/ || /^<\?xml-stylesheet/ || /^<\?xml /) {
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews # print "SGML: $_";
222d38735f97f771054e223b03f84c5858252332Evan Hunt $before_copyright = "$before_copyright$_";
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if (/>$/ ) {
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer $_ = <SOURCE>;
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer close(SOURCE) if (eof(SOURCE));
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer next;
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer }
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer $_ = <SOURCE>;
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer while (!eof(SOURCE) && ! /^<!/ ) {
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer $before_copyright = "$before_copyright$_";
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer $_ = <SOURCE>;
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer if (eof(SOURCE)) {
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer close(SOURCE);
222d38735f97f771054e223b03f84c5858252332Evan Hunt next;
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer }
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer if (/^<!/) {
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer $_ = <SOURCE> if $_ eq "<!--\n";
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($_ !~ /[Cc]opyright/) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt print "$file: non-copyright comment\n";
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer close(SOURCE);
222d38735f97f771054e223b03f84c5858252332Evan Hunt next;
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer }
222d38735f97f771054e223b03f84c5858252332Evan Hunt while (defined($_)) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt last if s/.*-->//;
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer $_ = <SOURCE>;
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer }
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson print "$file: unterminated comment\n"
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson unless defined($_);
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson if ($_ ne "\n") {
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson $first = $_;
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson } else {
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson $first = <SOURCE>;
6301757d64037b5a3684d7a765726f06f26712e5Mark Andrews }
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson } else {
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson $first = $_;
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson }
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson } elsif ($type eq "TXT") {
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson if ($_ =~ /[Cc]opyright/) {
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson $/ = ""; # paragraph at a time
0759eb6a0dab024873df528b0ffad804ea31615dMichael Sawyer while (<SOURCE>) {
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer # Not very maintainable, but ok enough for now.
222d38735f97f771054e223b03f84c5858252332Evan Hunt last unless
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer /[Cc]opyright/ ||
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer /See COPYRIGHT in the source root/ ||
222d38735f97f771054e223b03f84c5858252332Evan Hunt /Permission to use, copy, modify, and / ||
222d38735f97f771054e223b03f84c5858252332Evan Hunt /THE SOFTWARE IS PROVIDED "AS IS" AND /;
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer }
222d38735f97f771054e223b03f84c5858252332Evan Hunt $/ = "\n";
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer }
222d38735f97f771054e223b03f84c5858252332Evan Hunt $first = $_;
222d38735f97f771054e223b03f84c5858252332Evan Hunt } else {
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer $first = $_;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson }
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
222d38735f97f771054e223b03f84c5858252332Evan Hunt $first = "" if ! defined($first);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
222d38735f97f771054e223b03f84c5858252332Evan Hunt open(TARGET, ">$file.new") || die "can't open $file.new: $!";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson print TARGET $before_copyright if $before_copyright;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson print TARGET $start_comment if $start_comment;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $sysyears = "";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $sftyears = "";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $nomyears = "";
222d38735f97f771054e223b03f84c5858252332Evan Hunt
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson #
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson # Internet Software Consortium: up to 2003
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson #
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $last_year = 0;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $anchor_year = 0;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $years = "";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson foreach $year (@years) {
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson if ($year >= 2004) { next; }
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($last_year != 0 && $year == $last_year + 1) {
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson if ($year > $anchor_year + 1) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt substr($years, $anchor_end) = "-$year";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson } else {
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $years .= ", $year";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson }
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt } else {
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $years .= $last_year == 0 ? "$year" : ", $year";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson #if ($anchor_year != 0) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt # print "$file: noncontiguous year: ",
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson # "$year != $last_year + 1\n";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson #}
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $anchor_year = $year;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $anchor_end = length($years);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson }
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $last_year = $year;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson }
222d38735f97f771054e223b03f84c5858252332Evan Hunt $sftyears = $years;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson #
222d38735f97f771054e223b03f84c5858252332Evan Hunt # Nominum: up to 2001.
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson #
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $last_year = 0;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $anchor_year = 0;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson $years = "";
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson foreach $year (@years) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($year >= 2002) { next; }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($last_year != 0 && $year == $last_year + 1) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt if ($year > $anchor_year + 1) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews substr($years, $anchor_end) = "-$year";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews } else {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $years .= ", $year";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews } else {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $years .= $last_year == 0 ? "$year" : ", $year";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews #if ($anchor_year != 0) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews # print "$file: noncontiguous year: ",
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews # "$year != $last_year + 1\n";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews #}
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $anchor_year = $year;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $anchor_end = length($years);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
222d38735f97f771054e223b03f84c5858252332Evan Hunt $last_year = $year;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $nomyears = $years;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
222d38735f97f771054e223b03f84c5858252332Evan Hunt #
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews # Internet Systems Consortium: 2004 onwards.
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews #
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $last_year = 0;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $anchor_year = 0;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $years = "";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $anchor_end = length($years);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews foreach $year (@years) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($year < 2004) { next; }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($last_year != 0 && $year == $last_year + 1) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($year > $anchor_year + 1) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews substr($years, $anchor_end) = "-$year";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews } else {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $years .= ", $year";
222d38735f97f771054e223b03f84c5858252332Evan Hunt }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews } else {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $years .= $last_year == 0 ? "$year" : ", $year";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews #if ($anchor_year != 0) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt # print "$file: noncontiguous year: ",
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews # "$year != $last_year + 1\n";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews #}
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $anchor_year = $year;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $anchor_end = length($years);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $last_year = $year;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $sysyears = $years;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews ($firstline, $secondline, @otherlines) = @$textp;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $firstline =~ s/\@SYSYEARS\@/$sysyears/;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $secondline =~ s/\@SFTYEARS\@/$sftyears/;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET "$prefix$firstline";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($sftyears ne "" ) {
222d38735f97f771054e223b03f84c5858252332Evan Hunt print TARGET $secondline =~ /^$/ ? $nonspaceprefix : $prefix;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET "$secondline";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews foreach $_ (@otherlines) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET (/^$/ ? $nonspaceprefix : $prefix);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews s/\@NOMYEARS\@/$nomyears/;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET "$_";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET $end_comment if $end_comment;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($first eq "") {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $first = <SOURCE>;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (defined($first)) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($type eq 'MAN') {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET "$nonspaceprefix\n";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews } else {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews print TARGET "\n";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews }
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews undef $/;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $_ = <SOURCE>;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews $/ = "\n";
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if ($type eq 'SGML' && m:<articleinfo>.*?</articleinfo>:s) {
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington # print "docinfo: $file\n";
222d38735f97f771054e223b03f84c5858252332Evan Hunt my $r = copyrights(@years);
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington s:<articleinfo>.*?</articleinfo>:<articleinfo>\n$r </articleinfo>:s;
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington }
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington if ($type eq 'SGML' && m:<docinfo>.*?</docinfo>:s) {
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington # print "docinfo: $file\n";
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington my $r = copyrights(@years);
f0a1134d331b2aa871306c73d2787960918eaab1Andreas Gustafsson s:<docinfo>.*?</docinfo>:<docinfo>\n$r </docinfo>:s;
f0a1134d331b2aa871306c73d2787960918eaab1Andreas Gustafsson }
f0a1134d331b2aa871306c73d2787960918eaab1Andreas Gustafsson if ($type eq 'SGML' && m:<bookinfo>.*?</bookinfo>:s) {
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington # print "bookinfo: $file\n";
6301757d64037b5a3684d7a765726f06f26712e5Mark Andrews my $r = copyrights(@years);
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington s:<bookinfo>.*?</bookinfo>:<bookinfo>\n$r </bookinfo>:s;
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington }
222d38735f97f771054e223b03f84c5858252332Evan Hunt
222d38735f97f771054e223b03f84c5858252332Evan Hunt my ($start, $end);
e2f470bebb3a0c107bc4ac86c6920c21e50e83e0Brian Wellington if ($start_comment ne "") {
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews ($start = $start_comment) =~ s/\s*\n/ /;
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews ($end = $end_comment) =~ s/^\s*(.*)\n/ $1\n/;
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews } elsif ($prefix ne "") {
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews ($start = $prefix) =~ s/\s*\n//;
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews $end = "\n";
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews } else {
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews $start = "";
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews $end = "\n";
82f0630bae09598209cc37c1db00ff4356efee27Mark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews if ($first !~ /$keyword_pat/ && $_ !~ /$keyword_pat/) {
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews $end = "\n$nonspaceprefix" if ($type eq "MAN");
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews print TARGET "$start\$";
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews print TARGET "Id";
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews print TARGET "\$$end\n";
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews print TARGET $first if $first !~ /^\s*$/;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews print TARGET $_;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews }
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews close(TARGET);
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews close(SOURCE);
ea5334a36ebf7c833ec493345d86e04953041fdcEvan Hunt
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews $mode = (stat $file)[2]&511;
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews chmod $mode, "$file.new";
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews
16cc4a1f56d0f9a300419da7e75e3b72169e608aMark Andrews if (system("cmp -s $file.new $file") == 0) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews unlink("$file.new");
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt } else {
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt rename("$file.new", "$file")
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt or die "rename($file.new, $file): $!";
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt }
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt}
ac21f918f23ce95fd5be807428ee9e2c42319878Evan Hunt