merge_copyrights revision d3347bd01baee56e476982a7443ba18cdbaeebe1
012a352f4b26cfd874db8d06debc495c2303e8b2Bob Halley#!/usr/local/bin/perl -w
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
5c144477062a5df657acee41a82051d38537fd38Tinderbox User# Copyright (C) 2004-2007, 2009-2014 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# Permission to use, copy, modify, and/or distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# PERFORMANCE OF THIS SOFTWARE.
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User# $Id$
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntuse strict;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntmy %file_types = ();
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntmy %file_years = ();
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntmy %exists = ();
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
460b427411b72da26b1836b9424e2e70d65d9394David Lawrenceopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleywhile (<COPYRIGHTS>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley chomp;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my ($file, $type, $years) = split;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$file} = $type;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$file} = $years;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(COPYRIGHTS);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
c7b785510e3f517a0c98c0b6b6e6ad8f359e9e4cMark Andrewsmy ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley$year += 1900;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntopen(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleywhile (<FILES>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley chomp;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt $exists{$_} = 1;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt}
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntclose(FILES);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntopen(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntwhile (<CHANGES>) {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt chomp;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt # this file isn't in the repository now
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt next unless ($exists{$_});
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence next if (m%/\.\# | # CVS old conflict file
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews /CVS/ | # CVS directory
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews /.git/ | # git directory
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews util/newcopyrights | # our output
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews \.bak$ | # created by update_copyrights
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews /(dnssafe|openssl)/.*\.[ch]$ | # imported
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews doc/(draft|expired|rfc)/ # imported
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews %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.
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my $base;
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";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.y$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "YACC";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.pl$/i) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "PERL";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.py$/i) {
2d9bd38ec3fbbfe920757b8972d94f664a9b354bMark Andrews $file_types{$_} = "PYTHON";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.sh$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "SH";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.docbook$/ ||
8319af16557b81eba3277ee67215285f0823b587Mark Andrews $base =~ /.xsl$/ ||
8319af16557b81eba3277ee67215285f0823b587Mark Andrews $base =~ /.xml$/) {
aee5e9cbacd8f88325840b8a498876f4319b0890Mark Andrews $file_types{$_} = "SGML";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /doc\/arm\/.*\.html$/) {
9e5854255178c04170bc98839282d4cf3fae7443Mark Andrews $file_types{$_} = "X";
f7a6d4f915ce622d988916397f313b33ae954afcMark Andrews } elsif ($base =~ /\.html$/) {
f7a6d4f915ce622d988916397f313b33ae954afcMark Andrews $file_types{$_} = "HTML";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.(man|[0-9])$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "MAN";
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews } elsif ($base =~ /\/Makefile$/) {
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $file_types{$_} = "MAKE";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.conf$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "CONF-C";
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews } elsif ($base =~ /\/checkconf\/(good|bad)-.*\.conf$/) {
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $file_types{$_} = "CONF-C";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\/resolv.?\.conf$/) {
c32b87bc54abacf95fb3b063d72b7d1855c1643bMichael Graff $file_types{$_} = "CONF-SH";
7f9f8c13c5e5e26e0ba2b82c0900d11ecf6269ceMark Andrews } elsif ($base =~ /\.(db|hint)$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "ZONE";
c3e6fbe4b7471d843d015e3f1737b7edb9d0c547Mark Andrews } elsif ($base =~ /(\/\.gitignore|Atffile|\.(gif|jpg))$/i) {
c3e6fbe4b7471d843d015e3f1737b7edb9d0c547Mark Andrews $file_types{$_} = "X";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.(def|dep|dsp|dsw|mak|sln)$/i) {
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence $file_types{$_} = "X";
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence } elsif ($base =~ /\.(vcxproj(|\.(user|filters)))$/i) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "X";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.rnc$/i) {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews $file_types{$_} = "RNC";
6376f6189950156cc1488c86f22b19dd4feec11cMark Andrews } elsif ($base =~ /^\.\/EXCLUDED$/i) {
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews $file_types{$_} = "X";
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews } elsif ($base =~ /\.bat$/i) {
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews $file_types{$_} = "BAT";
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews } elsif ($base =~ /\/named\.args$/i) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "X";
2320f230995995595438a9d9301d84931fd266ceMark Andrews } elsif ($base =~ /\/README$/i) {
c427260a8678f2e99a2337fb95ec98d9c9ee8c05Mark Andrews $file_types{$_} = "TXT.BRIEF";
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews } else {
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews $file_types{$_} = "?";
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews }
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews my $m_year = int(`sh util/file_year.sh $_`);
43b3337ba58d70ca34f4d91e8c6c5e13a54af690Mark Andrews if ($m_year != $year) {
43b3337ba58d70ca34f4d91e8c6c5e13a54af690Mark Andrews print "$_: must set copyright year(s) manually\n";
f10370fd44f05fecc808d89c01b2d50df2b232f3Mark Andrews $file_years{$_} = "????";
f10370fd44f05fecc808d89c01b2d50df2b232f3Mark Andrews } else {
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews $file_years{$_} = "$year";
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews }
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews } else {
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
d3347bd01baee56e476982a7443ba18cdbaeebe1Mark Andrews print "$_: must set copyright year(s) manually\n";
d3347bd01baee56e476982a7443ba18cdbaeebe1Mark Andrews $file_years{$_} = "????";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley next;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt # track the modification years even if we are not going to be
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews # updating the copyrights.
4c6bf2d14ee70f1966d4c18475f93211fbc928e1Mark Andrews # next if $file_types{$_} eq "X";
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews next if ($file_years{$_} =~ /^PARENT:/);
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews next if ($file_years{$_} eq "DOCBOOK");
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley my @years = split(/,/, $file_years{$_});
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley my $has_current = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley foreach my $fyear (@years) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($fyear == $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $has_current = 1;
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews }
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews }
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence if (!$has_current) {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews $file_years{$_} .= ",$year";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews }
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence }
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews}
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrewsclose(CHANGES);
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews die "can't open newcopyrights: $!";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrenceforeach my $file (sort(keys(%file_types))) {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt print NEWCOPYRIGHTS "$file";
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my $len = length($file);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my $tabs = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($len >= 48) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley my $needed = int (48 - $len);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = int ($needed / 8);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt if ($needed % 8 != 0) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs++;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt for (my $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};
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt print "Unknown file type or year: $file\n";
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(NEWCOPYRIGHTS);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley