merge_copyrights revision 680cbc050aead48a0de9cdcea621f2747ca5ddc7
0N/A#!/usr/local/bin/perl -w
228N/A#
0N/A# Copyright (C) 1998-2001, 2003-2007, 2009-2017 Internet Systems Consortium, Inc. ("ISC")
0N/A#
0N/A# This Source Code Form is subject to the terms of the Mozilla Public
0N/A# License, v. 2.0. If a copy of the MPL was not distributed with this
0N/A# file, You can obtain one at http://mozilla.org/MPL/2.0/.
0N/A
0N/A# $Id$
0N/A
0N/Ause strict;
0N/A
0N/Amy %file_types = ();
0N/Amy %file_years = ();
0N/Amy %exists = ();
0N/A
0N/Aopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
0N/Awhile (<COPYRIGHTS>) {
0N/A chomp;
0N/A my ($file, $type, $years) = split;
0N/A $file_types{$file} = $type;
0N/A $file_years{$file} = $years;
0N/A}
0N/Aclose(COPYRIGHTS);
0N/A
0N/Amy ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
0N/A$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
0N/A$year += 1900;
370N/A
0N/Aopen(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
0N/Awhile (<FILES>) {
370N/A chomp;
0N/A $exists{$_} = 1;
0N/A}
285N/Aclose(FILES);
285N/A
0N/Aopen(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
0N/Awhile (<CHANGES>) {
0N/A chomp;
370N/A
0N/A # this file isn't in the repository now
0N/A next unless ($exists{$_});
366N/A
0N/A next if (m%/\.\# | # CVS old conflict file
0N/A /CVS/ | # CVS directory
0N/A /.git/ | # git directory
0N/A util/newcopyrights | # our output
0N/A \.bak$ | # created by update_copyrights
0N/A /(dnssafe|openssl)/.*\.[ch]$ | # imported
0N/A doc/(draft|expired|rfc)/ # imported
0N/A %x);
0N/A
0N/A if (!$file_types{$_}) {
0N/A # Strip any .in extension to find out the file's real type.
0N/A # .in files are processed by configure to produce the target file.
0N/A my $base;
0N/A ($base = $_) =~ s/\.in$//;
0N/A
0N/A # Contributed code should maintain its own copyright.
0N/A if ($base =~ /\.\/contrib\//) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.\/unit\/atf-src\//) {
331N/A $file_types{$_} = "X";
331N/A } elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.(c|h|css)$/) {
0N/A $file_types{$_} = "C";
0N/A } elsif ($base =~ /\.y$/) {
370N/A $file_types{$_} = "YACC";
0N/A } elsif ($base =~ /\.pl$/i) {
506N/A $file_types{$_} = "PERL";
0N/A } elsif ($base =~ /\.py$/i) {
0N/A $file_types{$_} = "PYTHON";
0N/A } elsif ($base =~ /\.sh$/) {
370N/A $file_types{$_} = "SH";
0N/A } elsif ($base =~ /\.docbook$/ ||
0N/A $base =~ /.xsl$/ ||
0N/A $base =~ /.xml$/) {
370N/A $file_types{$_} = "SGML";
0N/A } elsif ($base =~ /doc\/arm\/.*\.html$/) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.(sty|pdf|eps)$/) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.html$/) {
370N/A $file_types{$_} = "HTML";
0N/A $base =~ s/\.html$//;
0N/A $base = $base . ".docbook";
0N/A } elsif ($base =~ /\.(man|[0-9])$/) {
0N/A $file_types{$_} = "MAN";
0N/A $base =~ s/\.[0-9]$//;
0N/A $base = $base . ".docbook";
0N/A } elsif ($base =~ /\/Makefile$/) {
0N/A $file_types{$_} = "MAKE";
0N/A } elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.conf$/) {
0N/A $file_types{$_} = "CONF-C";
0N/A } elsif ($base =~ /\/checkconf\/(good|bad)-.*\.conf$/) {
370N/A $file_types{$_} = "CONF-C";
370N/A } elsif ($base =~ /\/resolv.?\.conf$/) {
370N/A $file_types{$_} = "CONF-SH";
370N/A } elsif ($base =~ /\.(db|hint)$/) {
0N/A $file_types{$_} = "ZONE";
0N/A } elsif ($base =~ /\.md$/) {
370N/A $file_types{$_} = "MKD";
370N/A } elsif ($base =~ /(\/\.(gitignore|gitattributes)|Atffile|Kyuafile|\.(gif|jpg))$/i) {
370N/A $file_types{$_} = "X";
370N/A } elsif ($base =~ /\.(def|dep|dsp|dsw|mak|sln)$/i) {
0N/A $file_types{$_} = "X";
370N/A } elsif ($base =~ /\.(vcxproj(|\.(user|filters)))$/i) {
370N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.rnc$/i) {
0N/A $file_types{$_} = "RNC";
370N/A } elsif ($base =~ /^\.\/EXCLUDED$/i) {
370N/A $file_types{$_} = "X";
370N/A } elsif ($base =~ /\.bat$/i) {
370N/A $file_types{$_} = "BAT";
0N/A } elsif ($base =~ /\.(key|private)$/i) {
370N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\/named\d{0,2}\.args$/i) {
0N/A $file_types{$_} = "X";
370N/A } elsif ($base =~ /\/named\.port$/i) {
370N/A $file_types{$_} = "X";
370N/A } elsif ($base =~ /\/named\.dropedns$/i) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\/named\.notcp$/i) {
370N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\/doc\/misc\/[-a-z]*\.zoneopt$/i) {
0N/A $file_types{$_} = "X";
370N/A } elsif ($base =~ /\/README$/i) {
370N/A $file_types{$_} = "TXT.BRIEF";
370N/A } else {
0N/A $file_types{$_} = "?";
0N/A }
370N/A my $m_year = int(`sh util/file_year.sh $_`);
370N/A if (($file_types{$_} eq "MAN" || $file_types{$_} eq "HTML") &&
370N/A $base =~ /\.docbook$/ && -e $base) {
0N/A $file_years{$_} = "DOCBOOK";
0N/A } elsif ($m_year != $year) {
370N/A print "$_: must set copyright year(s) manually\n";
370N/A $file_years{$_} = "????";
370N/A } else {
0N/A $file_years{$_} = "$year";
0N/A }
370N/A } else {
370N/A if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
0N/A print "$_: must set copyright year(s) manually\n";
0N/A $file_years{$_} = "????";
370N/A next;
370N/A }
370N/A
0N/A # track the modification years even if we are not going to be
440N/A # updating the copyrights.
449N/A # next if $file_types{$_} eq "X";
449N/A next if ($file_years{$_} =~ /^PARENT:/);
440N/A next if ($file_years{$_} eq "DOCBOOK");
440N/A
440N/A my @years = split(/,/, $file_years{$_});
449N/A my $has_current = 0;
449N/A foreach my $fyear (@years) {
449N/A if ($fyear == $year) {
449N/A $has_current = 1;
449N/A }
449N/A }
449N/A if (!$has_current) {
449N/A $file_years{$_} .= ",$year";
449N/A }
449N/A }
449N/A}
449N/Aclose(CHANGES);
449N/A
449N/Aopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
449N/A die "can't open newcopyrights: $!";
440N/Aforeach my $file (sort(keys(%file_types))) {
370N/A print NEWCOPYRIGHTS "$file";
370N/A my $len = length($file);
370N/A my $tabs = 0;
370N/A if ($len >= 48) {
$tabs = 1;
} else {
my $needed = int (48 - $len);
$tabs = int ($needed / 8);
if ($needed % 8 != 0) {
$tabs++;
}
}
for (my $i = 0; $i < $tabs; $i++) {
printf NEWCOPYRIGHTS "\t";
}
printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
print "Unknown file type or year: $file\n";
}
}
close(NEWCOPYRIGHTS);