merge_copyrights revision dafcb997e390efa4423883dafd100c975c4095d6
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj#!/usr/local/bin/perl -w
eb3def494ba5580320dfe1dd47b4d8b05519cb74gstein#
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj# Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj#
09bd86d0db1114ee23eda0a6eb76ca055877a1cftrawick# Permission to use, copy, modify, and distribute this software for any
09bd86d0db1114ee23eda0a6eb76ca055877a1cftrawick# purpose with or without fee is hereby granted, provided that the above
2deb319e6b3de239f45c16a3e9e836d44f1f7108rbb# copyright notice and this permission notice appear in all copies.
bd929c73ef04789b7183b840d8db6e01d03a4d86rbb#
70f6f32765cfaadd6da8de6f0fea97ddd72d8fadmanoj# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
e3838a090d22197ee5f0d2c10b5a3d5e6f550f6erbb# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
e3838a090d22197ee5f0d2c10b5a3d5e6f550f6erbb# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
91a71946d0fb28c0866139edef3dd59f36ba5b9cstoddard# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
91a71946d0fb28c0866139edef3dd59f36ba5b9cstoddard# PERFORMANCE OF THIS SOFTWARE.
91a71946d0fb28c0866139edef3dd59f36ba5b9cstoddard
91a71946d0fb28c0866139edef3dd59f36ba5b9cstoddard# $Id: merge_copyrights,v 1.18 2004/03/05 05:14:16 marka Exp $
91a71946d0fb28c0866139edef3dd59f36ba5b9cstoddard
bd929c73ef04789b7183b840d8db6e01d03a4d86rbb%file_types = ();
bd929c73ef04789b7183b840d8db6e01d03a4d86rbb%file_years = ();
bd929c73ef04789b7183b840d8db6e01d03a4d86rbb
bd929c73ef04789b7183b840d8db6e01d03a4d86rbbopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
632b0b53511f3bb9c32aa2869fbc73ee35081b38rbbwhile (<COPYRIGHTS>) {
632b0b53511f3bb9c32aa2869fbc73ee35081b38rbb chomp;
632b0b53511f3bb9c32aa2869fbc73ee35081b38rbb ($file, $type, $years) = split;
14cccaddba3a9263cf0d0ddc311e18f3e3dc9b0fgstein $file_types{$file} = $type;
f6a6245816cd866361da8c576b1f47c7a54b6610fanf $file_years{$file} = $years;
b7663b97a437dc089ac7a1a9ebd42e0c372a48b6gstein}
b7663b97a437dc089ac7a1a9ebd42e0c372a48b6gsteinclose(COPYRIGHTS);
b7663b97a437dc089ac7a1a9ebd42e0c372a48b6gstein
14cccaddba3a9263cf0d0ddc311e18f3e3dc9b0fgstein($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
14cccaddba3a9263cf0d0ddc311e18f3e3dc9b0fgstein$year += 1900;
14cccaddba3a9263cf0d0ddc311e18f3e3dc9b0fgstein
14cccaddba3a9263cf0d0ddc311e18f3e3dc9b0fgstein$find = "find . -type f -print";
14cccaddba3a9263cf0d0ddc311e18f3e3dc9b0fgstein
b7663b97a437dc089ac7a1a9ebd42e0c372a48b6gsteinopen(FILES, "$find | sort |") || die "can't start \"$find\": $!";
2a6c49cfaef5979a5a06098f3ce987cd76769409manojwhile (<FILES>) {
369edcdd0a9c5516c61e736ec2a6fc8fb0d92fe2manoj chomp;
369edcdd0a9c5516c61e736ec2a6fc8fb0d92fe2manoj
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj next if (m%/\.\# | # CVS old conflict file
85cbdc16ac57fa68ce1358a308269abcd417f4d9stoddard /CVS/ | # CVS directory
85cbdc16ac57fa68ce1358a308269abcd417f4d9stoddard util/newcopyrights | # our output
85cbdc16ac57fa68ce1358a308269abcd417f4d9stoddard \.bak$ | # created by update_copyrights
d208bda4a893cc81ed5d3ed1cdd7d706e012bd42stoddard /(dnssafe|openssl)/.*\.[ch]$ | # imported
d208bda4a893cc81ed5d3ed1cdd7d706e012bd42stoddard doc/(draft|expired|rfc)/ # imported
d208bda4a893cc81ed5d3ed1cdd7d706e012bd42stoddard %x);
d208bda4a893cc81ed5d3ed1cdd7d706e012bd42stoddard
10b386767f6c87b45937244371cb751f0b454d16wrowe if (!$file_types{$_}) {
10b386767f6c87b45937244371cb751f0b454d16wrowe # Strip any .in extension to find out the file's real type.
75960f20f88dad6bc67892c711c429946063d133stoddard # .in files are processed by configure to produce the target file.
75960f20f88dad6bc67892c711c429946063d133stoddard ($base = $_) =~ s/\.in$//;
75960f20f88dad6bc67892c711c429946063d133stoddard
75960f20f88dad6bc67892c711c429946063d133stoddard if ($base =~ /\.(c|h|css)$/) {
75960f20f88dad6bc67892c711c429946063d133stoddard $file_types{$_} = "C";
75960f20f88dad6bc67892c711c429946063d133stoddard } elsif ($base =~ /\.y$/) {
75960f20f88dad6bc67892c711c429946063d133stoddard $file_types{$_} = "YACC";
10b386767f6c87b45937244371cb751f0b454d16wrowe } elsif ($base =~ /\.pl$/i) {
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_types{$_} = "PERL";
10b386767f6c87b45937244371cb751f0b454d16wrowe } elsif ($base =~ /\.sh$/) {
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_types{$_} = "SH";
10b386767f6c87b45937244371cb751f0b454d16wrowe } elsif ($base =~ /\.html$/) {
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_types{$_} = "HTML";
10b386767f6c87b45937244371cb751f0b454d16wrowe } elsif ($base =~ /\.(man|[0-9])$/) {
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_types{$_} = "MAN";
10b386767f6c87b45937244371cb751f0b454d16wrowe } elsif ($base =~ /\/Makefile$/) {
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_types{$_} = "MAKE";
10b386767f6c87b45937244371cb751f0b454d16wrowe } elsif ($base =~ /\/(named|rndc).?\.conf$/) {
a9e07e4f90adcc7bc768db3055431c3dcd560cd1manoj $file_types{$_} = "CONF-C";
f6a6245816cd866361da8c576b1f47c7a54b6610fanf } elsif ($base =~ /\/resolv.?\.conf$/) {
f6a6245816cd866361da8c576b1f47c7a54b6610fanf $file_types{$_} = "CONF-SH";
97b758d0b174d7b7c5a1de1a583f5840ec3fc910trawick } elsif ($base =~ /\.(db|hint)$/) {
db3ccce11afac4fc1d4f51a65424412f7480c46cgstein $file_types{$_} = "ZONE";
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj } elsif ($base =~ /(\/\.cvsignore|\.gif|\.jpg)$/i) {
8bed76428f56e5c643174a2d6807c3f18016af5cbjh $file_types{$_} = "X";
8bed76428f56e5c643174a2d6807c3f18016af5cbjh } else {
8bed76428f56e5c643174a2d6807c3f18016af5cbjh $file_types{$_} = "?";
8bed76428f56e5c643174a2d6807c3f18016af5cbjh }
8bed76428f56e5c643174a2d6807c3f18016af5cbjh ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
cfc020d6d6fc9b31d8945915e65a8787a796eb73stoddard $blksize,$blocks)
cfc020d6d6fc9b31d8945915e65a8787a796eb73stoddard = stat($_);
cfc020d6d6fc9b31d8945915e65a8787a796eb73stoddard ($sec,$min,$hour,$mday,$mon,$c_year,$wday,$yday,$isdst) =
f824925ac58ff729289c017235eeb3bdd21ec3a2stoddard localtime($ctime);
f824925ac58ff729289c017235eeb3bdd21ec3a2stoddard ($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
f824925ac58ff729289c017235eeb3bdd21ec3a2stoddard localtime($mtime);
f824925ac58ff729289c017235eeb3bdd21ec3a2stoddard $c_year += 1900;
2aae6faee508221efbeaba5547ca79b7a20ef047stoddard $m_year += 1900;
2aae6faee508221efbeaba5547ca79b7a20ef047stoddard if ($m_year != $year || $c_year != $year) {
10b386767f6c87b45937244371cb751f0b454d16wrowe print "$_: must set copyright year(s) manually\n";
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_years{$_} = "????";
10b386767f6c87b45937244371cb751f0b454d16wrowe } else {
10b386767f6c87b45937244371cb751f0b454d16wrowe $file_years{$_} = "$year";
10b386767f6c87b45937244371cb751f0b454d16wrowe }
10b386767f6c87b45937244371cb751f0b454d16wrowe # keep perl from issuing warnings about "used only once"
10b386767f6c87b45937244371cb751f0b454d16wrowe $dev = $ino = $mode = $nlink = $uid = $gid = $rdev = $size = 0;
10b386767f6c87b45937244371cb751f0b454d16wrowe $atime = $blksize = $blocks = 0;
75960f20f88dad6bc67892c711c429946063d133stoddard } else {
a5ed555df952c85bc1b179f5981e8a6c54ba16e6stoddard if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
a5ed555df952c85bc1b179f5981e8a6c54ba16e6stoddard print "$_: must set copyright year(s) manually\n";
a5ed555df952c85bc1b179f5981e8a6c54ba16e6stoddard $file_years{$_} = "????";
a5ed555df952c85bc1b179f5981e8a6c54ba16e6stoddard next;
a5ed555df952c85bc1b179f5981e8a6c54ba16e6stoddard }
56ca30c968906053ae61acb218420667bb58d996rbb
56ca30c968906053ae61acb218420667bb58d996rbb next if $file_types{$_} eq "X";
56ca30c968906053ae61acb218420667bb58d996rbb
56ca30c968906053ae61acb218420667bb58d996rbb @years = split(/,/, $file_years{$_});
70f6f32765cfaadd6da8de6f0fea97ddd72d8fadmanoj $has_current = 0;
70f6f32765cfaadd6da8de6f0fea97ddd72d8fadmanoj foreach $fyear (@years) {
70f6f32765cfaadd6da8de6f0fea97ddd72d8fadmanoj if ($fyear == $year) {
56ca30c968906053ae61acb218420667bb58d996rbb $has_current = 1;
0bff2f28ef945280c17099c142126178a78e1e54manoj }
0bff2f28ef945280c17099c142126178a78e1e54manoj }
0bff2f28ef945280c17099c142126178a78e1e54manoj if (!$has_current) {
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard $blksize,$blocks)
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard = stat($_);
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard ($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard localtime($mtime);
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard $m_year += 1900;
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard if ($m_year == $year) {
9c09943bad734ebd5c7cc10bd6d63b75c4c6e056stoddard $file_years{$_} .= ",$year";
9c09943bad734ebd5c7cc10bd6d63b75c4c6e056stoddard }
9c09943bad734ebd5c7cc10bd6d63b75c4c6e056stoddard }
0bff2f28ef945280c17099c142126178a78e1e54manoj }
0bff2f28ef945280c17099c142126178a78e1e54manoj}
0bff2f28ef945280c17099c142126178a78e1e54manojclose(FILES);
9c09943bad734ebd5c7cc10bd6d63b75c4c6e056stoddard
75960f20f88dad6bc67892c711c429946063d133stoddardopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
1e585ba09ea32272e63c4c39c35491e975d21d98stoddard die "can't open newcopyrights: $!";
f03d292915be9977eaf74e9be7b0404aec226f84manojforeach $file (sort(keys(%file_types))) {
aa1faea36e4ae357bc603a2337b6adc54f5daec1manoj print NEWCOPYRIGHTS "$file";
bd929c73ef04789b7183b840d8db6e01d03a4d86rbb $len = length($file);
2a6c49cfaef5979a5a06098f3ce987cd76769409manoj if ($len >= 48) {
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj $tabs = 1;
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj } else {
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj $needed = int (48 - $len);
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj $tabs = int ($needed / 8);
ff849e4163ed879288f0df15f78b6c9d278ec804fanf if ($needed % 8 != 0) {
ff849e4163ed879288f0df15f78b6c9d278ec804fanf $tabs++;
9805ac88e1befa6dea11d8513023f150d8f8e807fanf }
9805ac88e1befa6dea11d8513023f150d8f8e807fanf }
9805ac88e1befa6dea11d8513023f150d8f8e807fanf for ($i = 0; $i < $tabs; $i++) {
9805ac88e1befa6dea11d8513023f150d8f8e807fanf printf NEWCOPYRIGHTS "\t";
df4a7c143b27b489dd2d865bb3f6668c8420b3a9fanf }
c03566fa0156d3a1500a42e4fe539e3e0fc8a11dgstein printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
c03566fa0156d3a1500a42e4fe539e3e0fc8a11dgstein}
c03566fa0156d3a1500a42e4fe539e3e0fc8a11dgsteinclose(NEWCOPYRIGHTS);
c03566fa0156d3a1500a42e4fe539e3e0fc8a11dgstein