012a352f4b26cfd874db8d06debc495c2303e8b2Bob Halley#!/usr/local/bin/perl -w
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley#
93ca8abdf86dfe69d40c0bc5389151e0672780afTinderbox User# Copyright (C) 1998-2001, 2003-2007, 2009-2018 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
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) = gmtime(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";
ebb4655236b95b36982d999800497d2dd3096a7fMark Andrews if (open(PYTHON, $_)) {
ebb4655236b95b36982d999800497d2dd3096a7fMark Andrews my $line = <PYTHON>;
ebb4655236b95b36982d999800497d2dd3096a7fMark Andrews $file_types{$_} = "PYTHON-BIN" if ($line && $line =~ /^#!/);
ebb4655236b95b36982d999800497d2dd3096a7fMark Andrews close(PYTHON);
ebb4655236b95b36982d999800497d2dd3096a7fMark Andrews }
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 =~ /\.(sty|pdf|eps)$/) {
f7a6d4f915ce622d988916397f313b33ae954afcMark Andrews $file_types{$_} = "X";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.html$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "HTML";
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $base =~ s/\.html$//;
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $base = $base . ".docbook";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews } elsif ($base =~ /\.(man|[0-9])$/) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence $file_types{$_} = "MAN";
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $base =~ s/\.[0-9]$//;
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $base = $base . ".docbook";
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";
c3e6fbe4b7471d843d015e3f1737b7edb9d0c547Mark Andrews } elsif ($base =~ /\/checkconf\/(good|bad)-.*\.conf$/) {
c3e6fbe4b7471d843d015e3f1737b7edb9d0c547Mark Andrews $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";
fe9b24391db337a7ff2845f89a932ae82ebef5ecMark Andrews } elsif ($base =~ /\.md$/) {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews $file_types{$_} = "MKD";
9514777adda314e7db802fc139ac42332e54baa9Mark Andrews } elsif ($base =~ /(\/\.(gitignore|gitattributes)|Atffile|Kyuafile|\.(gif|jpg))$/i) {
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews $file_types{$_} = "X";
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews } elsif ($base =~ /\.(def|dep|dsp|dsw|mak|sln)$/i) {
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews $file_types{$_} = "X";
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews } elsif ($base =~ /\.(vcxproj(|\.(user|filters)))$/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";
2c4c405aeb7d3900ec2d4e4de888d47eae04ff82Mark Andrews } elsif ($base =~ /\.(key|private)$/i) {
2c4c405aeb7d3900ec2d4e4de888d47eae04ff82Mark Andrews $file_types{$_} = "X";
284595865d33d5062d930957c516f413f48fad57Mark Andrews } elsif ($base =~ /\/named\d{0,2}\.args$/i) {
43b3337ba58d70ca34f4d91e8c6c5e13a54af690Mark Andrews $file_types{$_} = "X";
f10370fd44f05fecc808d89c01b2d50df2b232f3Mark Andrews } elsif ($base =~ /\/named\.port$/i) {
f10370fd44f05fecc808d89c01b2d50df2b232f3Mark Andrews $file_types{$_} = "X";
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews } elsif ($base =~ /\/named\.dropedns$/i) {
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews $file_types{$_} = "X";
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews } elsif ($base =~ /\/named\.notcp$/i) {
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews $file_types{$_} = "X";
680cbc050aead48a0de9cdcea621f2747ca5ddc7Mark Andrews } elsif ($base =~ /\/doc\/misc\/[-a-z]*\.zoneopt$/i) {
680cbc050aead48a0de9cdcea621f2747ca5ddc7Mark Andrews $file_types{$_} = "X";
d3347bd01baee56e476982a7443ba18cdbaeebe1Mark Andrews } elsif ($base =~ /\/README$/i) {
d3347bd01baee56e476982a7443ba18cdbaeebe1Mark Andrews $file_types{$_} = "TXT.BRIEF";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "?";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my $m_year = int(`sh util/file_year.sh $_`);
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews if (($file_types{$_} eq "MAN" || $file_types{$_} eq "HTML") &&
4c6bf2d14ee70f1966d4c18475f93211fbc928e1Mark Andrews $base =~ /\.docbook$/ && -e $base) {
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews $file_years{$_} = "DOCBOOK";
66c9805347f24da946c17a881e489ffe2e89c25dMark Andrews } elsif ($m_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 } else {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews print "$_: must set copyright year(s) manually\n";
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence $file_years{$_} = "????";
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews next;
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews }
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
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my @years = split(/,/, $file_years{$_});
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my $has_current = 0;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt foreach my $fyear (@years) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($fyear == $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $has_current = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (!$has_current) {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt $file_years{$_} .= ",$year";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntclose(CHANGES);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley die "can't open newcopyrights: $!";
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntforeach my $file (sort(keys(%file_types))) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley 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 {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt my $needed = int (48 - $len);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = int ($needed / 8);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley 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
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews print "Unknown file type or year: $file\n";
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(NEWCOPYRIGHTS);