update_copyrights revision 828a5beda384130d5e2913dadd862924c53405bf
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley#!/usr/local/bin/perl -w
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley#
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley# Copyright (C) 1998, 1999, 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#
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5fbced719b71e659322b4ce3e4a39c9b039674c7Bob Halley# SOFTWARE.
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
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",
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
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson # XXXTALE lib/isc/commandline.c should probably also have special handling.
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $before_copyright = "";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $c_comment = 0;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $shell_comment = 0;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $m4_comment = 0;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $first = "";
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley if ($type eq "C") {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $c_comment = 1;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $prefix = " * ";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley } elsif ($type eq "SH" || $type eq "PERL" || $type eq "MAKE") {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $shell_comment = 1;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $prefix = "# ";
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley } elsif ($type eq "M4") {
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $m4_comment = 1;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $prefix = "dnl ";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley } else {
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley print "$file: type '$type' not supported yet; skipping\n";
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley open(SOURCE, "<$file") || die "can't open $file: $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $_ = <SOURCE>;
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>;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($_ eq "#\n") {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $_ = <SOURCE>;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
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 }
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley } elsif ($m4_comment && /^dnl /) {
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>) {
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley if ($_ !~ /^dnl /) {
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley $first = $_;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley last;
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley }
19ba7857f6bf38619eda1f1dae0eb05a6cdd2b77Bob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley } else {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first = $_;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
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 }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($c_comment) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET "/*\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $years = "";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first_year = 1;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley foreach $year (@years) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if (! $first_year) {
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $years .= ", ";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
5a6e6c2c9b2f6cf426aa2a682aa800765e26d540Andreas Gustafsson $years .= "$year";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first_year = 0;
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 }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($c_comment) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET " */\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($first eq "") {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley $first = <SOURCE>;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($first ne "") {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley if ($first !~ /^\s*$/) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley print TARGET "\n";
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET $first;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley while (<SOURCE>) {
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley print TARGET $_;
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(TARGET);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(SOURCE);
59a6d9cbcdbec6960d47e5871fb7e7c0253e1fb2Mark Andrews $mode = (stat $file)[2]&511;
59a6d9cbcdbec6960d47e5871fb7e7c0253e1fb2Mark Andrews chmod $mode, "$file.new";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley rename("$file.new", "$file") || die "rename($file.new, $file): $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}