merge_copyrights revision 12a3ab37fe6556406acdf92fc7c5f198d603ca2e
012a352f4b26cfd874db8d06debc495c2303e8b2Bob Halley#!/usr/local/bin/perl -w
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
33cc94f04cb44dc247f605a954e45e5adc699977Automatic Updater# Copyright (C) 2004-2007, 2009, 2010 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater# Permission to use, copy, modify, and/or 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.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# PERFORMANCE OF THIS SOFTWARE.
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
12a3ab37fe6556406acdf92fc7c5f198d603ca2eMark Andrews# $Id: merge_copyrights,v 1.40 2011/02/28 01:09:45 marka 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
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews util/newcopyrights | # our output
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
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews # Contributed code should maintain its own copyright.
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews if ($base =~ /\.\/contrib\//) {
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews $file_types{$_} = "X";
12a3ab37fe6556406acdf92fc7c5f198d603ca2eMark Andrews } elsif ($base =~ /\.\/unit\/atf-src\//) {
f5cfcbf2f7906fb59c2b8b9b8fc9c7a75ac44dabMark Andrews $file_types{$_} = "X";
2d46d268ccff30bb50e661b47c6496d23d9156c7Mark Andrews } elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
2d46d268ccff30bb50e661b47c6496d23d9156c7Mark Andrews $file_types{$_} = "X";
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews } elsif ($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";
596912ee9ca8eb14d30707ec286ab5d28bd39b3eMark Andrews } elsif ($base =~ /\.docbook$/ ||
8319af16557b81eba3277ee67215285f0823b587Mark Andrews $base =~ /.xsl$/ ||
8319af16557b81eba3277ee67215285f0823b587Mark Andrews $base =~ /.xml$/) {
aee5e9cbacd8f88325840b8a498876f4319b0890Mark Andrews $file_types{$_} = "SGML";
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";
7f9f8c13c5e5e26e0ba2b82c0900d11ecf6269ceMark Andrews } elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.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";
b616f6ed69209ab4c87f610b472aeb20760652f2Mark Andrews } elsif ($base =~ /(\/\.cvsignore|\.gif|\.jpg|\.dsp|\.dsw|\.mak)$/i) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "X";
2320f230995995595438a9d9301d84931fd266ceMark Andrews } elsif ($base =~ /\.rnc$/i) {
c427260a8678f2e99a2337fb95ec98d9c9ee8c05Mark Andrews $file_types{$_} = "RNC";
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews } elsif ($base =~ /^\.\/EXCLUDED$/i) {
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews $file_types{$_} = "X";
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews } elsif ($base =~ /\.bat$/i) {
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews $file_types{$_} = "BAT";
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
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews # track the modification years even if we are not going to be
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews # updating the copyrights.
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews # next if $file_types{$_} eq "X";
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews next if ($file_years{$_} =~ /^PARENT:/);
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews next if ($file_years{$_} eq "DOCBOOK");
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);