merge_copyrights revision 15a44745412679c30a6d022733925af70a38b715
012a352f4b26cfd874db8d06debc495c2303e8b2Bob Halley#!/usr/local/bin/perl -w
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence# Copyright (C) 1998-2000 Internet Software Consortium.
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley# Permission to use, copy, modify, and distribute this software for any
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley# purpose with or without fee is hereby granted, provided that the above
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley# copyright notice and this permission notice appear in all copies.
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
15a44745412679c30a6d022733925af70a38b715David Lawrence# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
15a44745412679c30a6d022733925af70a38b715David Lawrence# $Id: merge_copyrights,v 1.14 2000/07/27 09:54:55 tale Exp $
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley%file_types = ();
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley%file_years = ();
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
460b427411b72da26b1836b9424e2e70d65d9394David Lawrenceopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleywhile (<COPYRIGHTS>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley chomp;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($file, $type, $years) = split;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$file} = $type;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$file} = $years;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(COPYRIGHTS);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley$year += 1900;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence$find = "find . -type f -print";
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
460b427411b72da26b1836b9424e2e70d65d9394David Lawrenceopen(FILES, "$find | sort |") || die "can't start \"$find\": $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleywhile (<FILES>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley chomp;
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence next if (m%/\.\# | # CVS old conflict file
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence /CVS/ | # CVS directory
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence \.bak$ | # created by update_copyrights
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence /(dnssafe|openssl)/.*\.[ch]$ | # imported
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence doc/(draft|expired|rfc)/ # imported
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence %x);
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (!$file_types{$_}) {
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence # Strip any .in extension to find out the file's real type.
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence # .in files are processed by configure to produce the target file.
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence ($base = $_) =~ s/\.in$//;
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence if ($base =~ /\.(c|h|css)$/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "C";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.y$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "YACC";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.pl$/i) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "PERL";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.sh$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "SH";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.html$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "HTML";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.(man|[0-9])$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "MAN";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\/Makefile$/) {
c32b87bc54abacf95fb3b063d72b7d1855c1643bMichael Graff $file_types{$_} = "MAKE";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence } elsif ($base =~ /\/(named|rndc).?\.conf$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "CONF-C";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\/resolv.?\.conf$/) {
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $file_types{$_} = "CONF-SH";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.(db|hint)$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "ZONE";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /(\/\.cvsignore|\.gif|\.jpg)$/i) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "X";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "?";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $blksize,$blocks)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley = stat($_);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($sec,$min,$hour,$mday,$mon,$c_year,$wday,$yday,$isdst) =
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley localtime($ctime);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley localtime($mtime);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $c_year += 1900;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $m_year += 1900;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($m_year != $year || $c_year != $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print "$_: must set copyright year(s) manually\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$_} = "????";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$_} = "$year";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley # keep perl from issuing warnings about "used only once"
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $dev = $ino = $mode = $nlink = $uid = $gid = $rdev = $size = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $atime = $blksize = $blocks = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence print "$_: must set copyright year(s) manually\n";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence $file_years{$_} = "????";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence next;
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence }
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence next if $file_types{$_} eq "X";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley @years = split(/,/, $file_years{$_});
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $has_current = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley foreach $fyear (@years) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($fyear == $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $has_current = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (!$has_current) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $blksize,$blocks)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley = stat($_);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley localtime($mtime);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $m_year += 1900;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($m_year == $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$_} .= ",$year";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(FILES);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley die "can't open newcopyrights: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyforeach $file (sort(keys(%file_types))) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print NEWCOPYRIGHTS "$file";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $len = length($file);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($len >= 48) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $needed = int (48 - $len);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = int ($needed / 8);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($needed % 8 != 0) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs++;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley for ($i = 0; $i < $tabs; $i++) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley printf NEWCOPYRIGHTS "\t";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(NEWCOPYRIGHTS);