update_copyrights revision 81e92fbafaa07bd8ccbbeb4b5926d548b5c4560e
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
b897c52f865b2fc4e220e2110b874e59c716456bBob Halleyif (@ARGV == 0) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley die "usage: update_copyrights <copyright_text>";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley@copyright_text = ();
b897c52f865b2fc4e220e2110b874e59c716456bBob Halleyopen(COPYRIGHT, "<$ARGV[0]") || die "can't open $ARGV[0]: $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley@copyright_text = <>;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halleyclose(COPYRIGHT);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
b897c52f865b2fc4e220e2110b874e59c716456bBob Halleywhile (<>) {
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley ($file, $type, $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
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence next if $type eq "X";
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence if ($type =~ /\.NAI$/) {
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence # XXX Not handled yet; co-copyrighted with Network Associates.
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence # lib/isc/commandline.c should probably also have special handling.
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence print "$file: co-copyrighted with Network Associates; ",
81e92fbafaa07bd8ccbbeb4b5926d548b5c4560eDavid Lawrence "update manually\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
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 }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET "${prefix}Copyright (C) ";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first_year = 1;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley foreach $year (@years) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if (! $first_year) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET ", ";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET "$year";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first_year = 0;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET " Internet Software Consortium.\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET "$prefix\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley foreach $_ (@copyright_text) {
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}