update_copyrights revision 5fbced719b71e659322b4ce3e4a39c9b039674c7
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews#!/usr/local/bin/perl -w
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews#
f0cbe180f0ec1a660b397886c55c592bbbcbb4aeTinderbox User# Copyright (C) 1998, 1999 Internet Software Consortium.
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews#
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# Permission to use, copy, modify, and distribute this software for any
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# purpose with or without fee is hereby granted, provided that the above
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# copyright notice and this permission notice appear in all copies.
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews#
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews# SOFTWARE.
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrewsif (@ARGV == 0) {
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews die "usage: update_copyrights <copyright_text>";
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews}
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews@copyright_text = ();
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrewsopen(COPYRIGHT, "<$ARGV[0]") || die "can't open $ARGV[0]: $!";
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews@copyright_text = <>;
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrewsclose(COPYRIGHT);
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrewswhile (<>) {
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews ($file, $type, $years_list) = split(/\s+/);
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews @years = split(/,/, $years_list);
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews if ( ! -f $file ) {
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews print "$file: missing\n";
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews next;
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews }
db8938c993d3eaeae1d86feb1b5da511831a9014Mark Andrews if ($type eq "X") {
79521569952d5e2475f05e4397dc976f4685056eMark Andrews print "$file: X type; skipping\n";
79521569952d5e2475f05e4397dc976f4685056eMark Andrews next;
79521569952d5e2475f05e4397dc976f4685056eMark Andrews }
79521569952d5e2475f05e4397dc976f4685056eMark Andrews
79521569952d5e2475f05e4397dc976f4685056eMark Andrews $before_copyright = "";
79521569952d5e2475f05e4397dc976f4685056eMark Andrews $c_comment = 0;
79521569952d5e2475f05e4397dc976f4685056eMark Andrews $shell_comment = 0;
79521569952d5e2475f05e4397dc976f4685056eMark Andrews $first = "";
3635d8f9104e70e141a8f191a0e6c1502ceed2f3Mark Andrews if ($type eq "C") {
3635d8f9104e70e141a8f191a0e6c1502ceed2f3Mark Andrews $c_comment = 1;
$prefix = " * ";
} elsif ($type eq "SH" || $type eq "PERL" || $type eq "MAKE") {
$shell_comment = 1;
$prefix = "# ";
} else {
print "$file: type '$type' not supported yet; skipping\n";
next;
}
open(SOURCE, "<$file") || die "can't open $file: $!";
$_ = <SOURCE>;
if ($c_comment && /^\/\*/) {
$_ = <SOURCE>;
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
if ($_ !~ /\*\//) {
while (<SOURCE>) {
if ($_ =~ /\*\//) {
last;
}
}
}
} elsif ($shell_comment) {
if (/^\#\!/) {
$before_copyright = "$_#\n";
$_ = <SOURCE>;
if ($_ eq "#\n") {
$_ = <SOURCE>;
}
}
if (/^\#/) {
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (<SOURCE>) {
if ($_ !~ /^\#/) {
$first = $_;
last;
}
}
} else {
$first = $_;
}
} else {
$first = $_;
}
open(TARGET, ">$file.new") || die "can't open $file.new: $!";
if ($before_copyright ne "") {
print TARGET $before_copyright;
}
if ($c_comment) {
print TARGET "/*\n";
}
print TARGET "${prefix}Copyright (C) ";
$first_year = 1;
foreach $year (@years) {
if (! $first_year) {
print TARGET ", ";
}
print TARGET "$year";
$first_year = 0;
}
print TARGET " Internet Software Consortium.\n";
print TARGET "$prefix\n";
foreach $_ (@copyright_text) {
print TARGET "${prefix}$_";
}
if ($c_comment) {
print TARGET " */\n";
}
if ($first eq "") {
$first = <SOURCE>;
}
if ($first ne "") {
if ($first !~ /^\s*$/) {
print TARGET "\n";
}
print TARGET $first;
while (<SOURCE>) {
print TARGET $_;
}
}
close(TARGET);
close(SOURCE);
rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
rename("$file.new", "$file") || die "rename($file.new, $file): $!";
}