merge_copyrights revision 2d9bd38ec3fbbfe920757b8972d94f664a9b354b
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrews#!/usr/local/bin/perl -w
6fe48fb46e53ffc37542853a1edb74cb481b7d94Automatic Updater#
7a2a1b8b14fc804ac80612d7b98064095e445be5Automatic Updater# Copyright (C) 2004-2007, 2009-2012 Internet Systems Consortium, Inc. ("ISC")
7a42357217528037bdfedcb17eeebfe96ae4266aAutomatic Updater# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
1167fc7904c5f0a472f8df207ac46dd52c7f1ec8Automatic Updater#
0c39b3ed9409ecb277d5e32fa763a4e4d6598df8Automatic Updater# Permission to use, copy, modify, and/or distribute this software for any
46da3117812814a29432a8d9a9ccf8acdbfdadceAutomatic Updater# purpose with or without fee is hereby granted, provided that the above
6fe48fb46e53ffc37542853a1edb74cb481b7d94Automatic Updater# copyright notice and this permission notice appear in all copies.
fe84edc17e0d582cf7b4270f8df9d4742a107b1cAutomatic Updater#
79b273c187a4aa1016a62181983dfdd0521681aeMark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
90ff38a0d8deaf5f9c2aa5916d99b2e572d28738Automatic Updater# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
6c6a121295b30772cbf3dd75a51fb9d883051a0eAutomatic Updater# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater# PERFORMANCE OF THIS SOFTWARE.
bbde8dc56605130058a1540609264fa109da3b63Automatic Updater
bbde8dc56605130058a1540609264fa109da3b63Automatic Updater# $Id$
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews
e130ab53e992670e2a2ecf043976ac09f21358d1Automatic Updateruse strict;
3cc98b8ecedcbc8465f1cf2740b966b315662430Automatic Updater
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsmy %file_types = ();
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsmy %file_years = ();
bbde8dc56605130058a1540609264fa109da3b63Automatic Updatermy %exists = ();
bbde8dc56605130058a1540609264fa109da3b63Automatic Updater
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updaterwhile (<COPYRIGHTS>) {
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews chomp;
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater my ($file, $type, $years) = split;
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson $file_types{$file} = $type;
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_years{$file} = $years;
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater}
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafssonclose(COPYRIGHTS);
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updatermy ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
aa9c561961e9d877946ebaa8795fa2be054ab7bfEvan Hunt$year += 1900;
e130ab53e992670e2a2ecf043976ac09f21358d1Automatic Updater
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updateropen(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
aa9c561961e9d877946ebaa8795fa2be054ab7bfEvan Huntwhile (<FILES>) {
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater chomp;
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater $exists{$_} = 1;
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater}
aa9c561961e9d877946ebaa8795fa2be054ab7bfEvan Huntclose(FILES);
e130ab53e992670e2a2ecf043976ac09f21358d1Automatic Updater
2d2dc37599979c83495510f8af8d1756753aa2c5Automatic Updateropen(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
aa9c561961e9d877946ebaa8795fa2be054ab7bfEvan Huntwhile (<CHANGES>) {
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater chomp;
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater # this file isn't in the repository now
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater next unless ($exists{$_});
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater
cdfc81e048bd34c1d628380247bda6b80a89e20eAutomatic Updater next if (m%/\.\# | # CVS old conflict file
cdfc81e048bd34c1d628380247bda6b80a89e20eAutomatic Updater /CVS/ | # CVS directory
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater /.git/ | # git directory
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater util/newcopyrights | # our output
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater \.bak$ | # created by update_copyrights
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater /(dnssafe|openssl)/.*\.[ch]$ | # imported
eabc9c3c07cd956d3c436bd7614cb162dabdda76Mark Andrews doc/(draft|expired|rfc)/ # imported
eabc9c3c07cd956d3c436bd7614cb162dabdda76Mark Andrews %x);
eabc9c3c07cd956d3c436bd7614cb162dabdda76Mark Andrews
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington if (!$file_types{$_}) {
9cd5eb6fe0f26d65724b99216cb31dcdd12e4afdAutomatic Updater # Strip any .in extension to find out the file's real type.
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews # .in files are processed by configure to produce the target file.
6fe48fb46e53ffc37542853a1edb74cb481b7d94Automatic Updater my $base;
8e9f3b69914ee02a80b87c97b1f8093edb3e9ae0Automatic Updater ($base = $_) =~ s/\.in$//;
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews
930f6069e5aa157cf6987cdafd412f5757a5a558Automatic Updater # Contributed code should maintain its own copyright.
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews if ($base =~ /\.\/contrib\//) {
930f6069e5aa157cf6987cdafd412f5757a5a558Automatic Updater $file_types{$_} = "X";
80faf1588895fd26490f82f95a7a1b771df1c324Automatic Updater } elsif ($base =~ /\.\/unit\/atf-src\//) {
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews $file_types{$_} = "X";
6fe48fb46e53ffc37542853a1edb74cb481b7d94Automatic Updater } elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews $file_types{$_} = "X";
930f6069e5aa157cf6987cdafd412f5757a5a558Automatic Updater } elsif ($base =~ /\.(c|h|css)$/) {
693c4232dfdffaff672197d4b9fea944c64cf80aAutomatic Updater $file_types{$_} = "C";
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews } elsif ($base =~ /\.y$/) {
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_types{$_} = "YACC";
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson } elsif ($base =~ /\.pl$/i) {
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_types{$_} = "PERL";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater } elsif ($base =~ /\.py$/i) {
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews $file_types{$_} = "PYTHON";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater } elsif ($base =~ /\.sh$/) {
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson $file_types{$_} = "SH";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater } elsif ($base =~ /\.docbook$/ ||
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $base =~ /.xsl$/ ||
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson $base =~ /.xml$/) {
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_types{$_} = "SGML";
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater } elsif ($base =~ /\.html$/) {
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater $file_types{$_} = "HTML";
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews } elsif ($base =~ /\.(man|[0-9])$/) {
11af78f7dc35741bdab68dbab11b03daab005b28Automatic Updater $file_types{$_} = "MAN";
11af78f7dc35741bdab68dbab11b03daab005b28Automatic Updater } elsif ($base =~ /\/Makefile$/) {
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews $file_types{$_} = "MAKE";
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont } elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.conf$/) {
e130ab53e992670e2a2ecf043976ac09f21358d1Automatic Updater $file_types{$_} = "CONF-C";
8ccd7da886e93cd490fcb6f4c4e98a6514f35820Automatic Updater } elsif ($base =~ /\/resolv.?\.conf$/) {
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont $file_types{$_} = "CONF-SH";
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews } elsif ($base =~ /\.(db|hint)$/) {
e130ab53e992670e2a2ecf043976ac09f21358d1Automatic Updater $file_types{$_} = "ZONE";
a308b69ac66fadf66863484f301314d6e6a3f1d2Automatic Updater } elsif ($base =~ /(\/\.gitignore|\.gif|\.jpg|\.dsp|\.dsw|\.mak)$/i) {
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews $file_types{$_} = "X";
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews } elsif ($base =~ /\.rnc$/i) {
24bf1e02f03577db0feb50b80238c4150c96d05dAutomatic Updater $file_types{$_} = "RNC";
24bf1e02f03577db0feb50b80238c4150c96d05dAutomatic Updater } elsif ($base =~ /^\.\/EXCLUDED$/i) {
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews $file_types{$_} = "X";
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews } elsif ($base =~ /\.bat$/i) {
a308b69ac66fadf66863484f301314d6e6a3f1d2Automatic Updater $file_types{$_} = "BAT";
a308b69ac66fadf66863484f301314d6e6a3f1d2Automatic Updater } elsif ($base =~ /\/named\.args$/i) {
78f3ed4bc2fcd3d270bfd599804f3b27a1db4d91Mark Andrews $file_types{$_} = "X";
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews } else {
6fe48fb46e53ffc37542853a1edb74cb481b7d94Automatic Updater $file_types{$_} = "?";
82447d835d3ff5c658749b4e9b4f66166407b3eaAutomatic Updater }
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews my $m_year = int(`sh util/file_year.sh $_`);
24bf1e02f03577db0feb50b80238c4150c96d05dAutomatic Updater if ($m_year != $year) {
24bf1e02f03577db0feb50b80238c4150c96d05dAutomatic Updater print "$_: must set copyright year(s) manually\n";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_years{$_} = "????";
cdfc81e048bd34c1d628380247bda6b80a89e20eAutomatic Updater } else {
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_years{$_} = "$year";
fe80a4909bf62b602feaf246866e9d29f7654194Automatic Updater }
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater } else {
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
fe80a4909bf62b602feaf246866e9d29f7654194Automatic Updater print "$_: must set copyright year(s) manually\n";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $file_years{$_} = "????";
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater next;
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson }
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews # track the modification years even if we are not going to be
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson # updating the copyrights.
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater # next if $file_types{$_} eq "X";
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater next if ($file_years{$_} =~ /^PARENT:/);
dd65eb1efb40b1c47d57963192bfc54873b219beAutomatic Updater next if ($file_years{$_} eq "DOCBOOK");
133e6d43fa82e80d3798be4de00f4540f485ec6cAutomatic Updater
133e6d43fa82e80d3798be4de00f4540f485ec6cAutomatic Updater my @years = split(/,/, $file_years{$_});
133e6d43fa82e80d3798be4de00f4540f485ec6cAutomatic Updater my $has_current = 0;
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater foreach my $fyear (@years) {
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson if ($fyear == $year) {
f2770f6b39a9b2a98afb7a11ed105f73f1570c1eAutomatic Updater $has_current = 1;
4104e236f71eb5108fcfda6711878a97f6f4a8e7Automatic Updater }
8711e5c73ca872d59810760af0332194cbdd619bAutomatic Updater }
229ea4644b3a7d9c7fdaa43888e7f55ba01e2ee3Automatic Updater if (!$has_current) {
0ce87e5749aabb8eef1e0a37e4bd6e6ffa1d7196Automatic Updater $file_years{$_} .= ",$year";
6fe48fb46e53ffc37542853a1edb74cb481b7d94Automatic Updater }
229ea4644b3a7d9c7fdaa43888e7f55ba01e2ee3Automatic Updater }
f132a836c4e386b1af045dd8fe7106ae61b90bffAutomatic Updater}
8f2c45a35dd8c40bcc9caba8f7d40ce64fc27bcdAutomatic Updaterclose(CHANGES);
c6a0f4ae1d7183a16ffb196b86b647f870694796Automatic Updater
8f2c45a35dd8c40bcc9caba8f7d40ce64fc27bcdAutomatic Updateropen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
e130ab53e992670e2a2ecf043976ac09f21358d1Automatic Updater die "can't open newcopyrights: $!";
d145b64cacc8d9cda51f9924ec70cd4661c3e2cfAutomatic Updaterforeach my $file (sort(keys(%file_types))) {
8711e5c73ca872d59810760af0332194cbdd619bAutomatic Updater print NEWCOPYRIGHTS "$file";
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater my $len = length($file);
8f2c45a35dd8c40bcc9caba8f7d40ce64fc27bcdAutomatic Updater my $tabs = 0;
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater if ($len >= 48) {
8f2c45a35dd8c40bcc9caba8f7d40ce64fc27bcdAutomatic Updater $tabs = 1;
9c446b72069d0ab9f710502f4d7048e50875fccbAutomatic Updater } else {
e85565067cf73f8cc21ee29b11761659f1d47ee9Automatic Updater my $needed = int (48 - $len);
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater $tabs = int ($needed / 8);
bc0a53583d92309bebcf93c408e2f3247ebd3d3cAutomatic Updater if ($needed % 8 != 0) {
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater $tabs++;
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater }
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater }
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater for (my $i = 0; $i < $tabs; $i++) {
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater printf NEWCOPYRIGHTS "\t";
7f79131f9a8e804b93c57f3c679065cce878b726Automatic Updater }
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater
3f616e6f846be57b1717c6beaba0f74de9d5a7c6Automatic Updater if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
8f2c45a35dd8c40bcc9caba8f7d40ce64fc27bcdAutomatic Updater print "Unknown file type or year: $file\n";
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater }
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater}
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterclose(NEWCOPYRIGHTS);
9513a2a6670951f5cf5477fcfec9f933fcaff628Automatic Updater