update_copyrights revision efd6c944a4ebd3fb65dc39f9172d322198b2b1d3
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley#!/usr/local/bin/perl -w
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halleydie "This program is being updated; talk to Bob.";
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob 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";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley if ($type eq "X") {
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley print "$file: X type; skipping\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley next;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
efd6c944a4ebd3fb65dc39f9172d322198b2b1d3Bob Halley if ($type eq "C") {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $c_comment = 1;
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>;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if (/^\/\*/) {
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 }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first = "";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley } else {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $first = $_;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley open(TARGET, ">$file.new") || die "can't open $file.new: $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($c_comment) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET "/*\n";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley $prefix = " * ";
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 }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley if ($first ne "") {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET $first;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley while (<SOURCE>) {
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley print TARGET $_;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley }
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(TARGET);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley close(SOURCE);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley rename("$file.new", "$file") || die "rename($file.new, $file): $!";
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}