merge_copyrights revision 4c6bf2d14ee70f1966d4c18475f93211fbc928e1
197N/A#!/usr/local/bin/perl -w
197N/A#
197N/A# Copyright (C) 2004-2007, 2009-2015 Internet Systems Consortium, Inc. ("ISC")
197N/A# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
197N/A#
197N/A# Permission to use, copy, modify, and/or distribute this software for any
197N/A# purpose with or without fee is hereby granted, provided that the above
197N/A# copyright notice and this permission notice appear in all copies.
197N/A#
197N/A# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
197N/A# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
197N/A# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
197N/A# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
197N/A# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
197N/A# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
197N/A# PERFORMANCE OF THIS SOFTWARE.
197N/A
197N/A# $Id$
197N/A
197N/Ause strict;
197N/A
197N/Amy %file_types = ();
6727N/Amy %file_years = ();
197N/Amy %exists = ();
197N/A
3996N/Aopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
3996N/Awhile (<COPYRIGHTS>) {
197N/A chomp;
197N/A my ($file, $type, $years) = split;
1273N/A $file_types{$file} = $type;
197N/A $file_years{$file} = $years;
197N/A}
618N/Aclose(COPYRIGHTS);
1273N/A
1273N/Amy ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
197N/A$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
844N/A$year += 1900;
844N/A
197N/Aopen(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
1273N/Awhile (<FILES>) {
197N/A chomp;
3661N/A $exists{$_} = 1;
3661N/A}
197N/Aclose(FILES);
197N/A
197N/Aopen(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
197N/Awhile (<CHANGES>) {
197N/A chomp;
3996N/A
3996N/A # this file isn't in the repository now
3996N/A next unless ($exists{$_});
197N/A
6727N/A next if (m%/\.\# | # CVS old conflict file
197N/A /CVS/ | # CVS directory
6727N/A /.git/ | # git directory
6727N/A util/newcopyrights | # our output
6727N/A \.bak$ | # created by update_copyrights
197N/A /(dnssafe|openssl)/.*\.[ch]$ | # imported
197N/A doc/(draft|expired|rfc)/ # imported
197N/A %x);
197N/A
197N/A if (!$file_types{$_}) {
197N/A # Strip any .in extension to find out the file's real type.
197N/A # .in files are processed by configure to produce the target file.
197N/A my $base;
6727N/A ($base = $_) =~ s/\.in$//;
6727N/A
6727N/A # Contributed code should maintain its own copyright.
197N/A if ($base =~ /\.\/contrib\//) {
197N/A $file_types{$_} = "X";
197N/A } elsif ($base =~ /\.\/unit\/atf-src\//) {
197N/A $file_types{$_} = "X";
197N/A } elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
197N/A $file_types{$_} = "X";
197N/A } elsif ($base =~ /\.(c|h|css)$/) {
197N/A $file_types{$_} = "C";
3996N/A } elsif ($base =~ /\.y$/) {
$file_types{$_} = "YACC";
} elsif ($base =~ /\.pl$/i) {
$file_types{$_} = "PERL";
} elsif ($base =~ /\.py$/i) {
$file_types{$_} = "PYTHON";
} elsif ($base =~ /\.sh$/) {
$file_types{$_} = "SH";
} elsif ($base =~ /\.docbook$/ ||
$base =~ /.xsl$/ ||
$base =~ /.xml$/) {
$file_types{$_} = "SGML";
} elsif ($base =~ /doc\/arm\/.*\.html$/) {
$file_types{$_} = "X";
} elsif ($base =~ /\.(sty|pdf|eps)$/) {
$file_types{$_} = "X";
} elsif ($base =~ /\.html$/) {
$file_types{$_} = "HTML";
$base =~ s/\.html$//;
$base = $base . ".docbook";
} elsif ($base =~ /\.(man|[0-9])$/) {
$file_types{$_} = "MAN";
$base =~ s/\.[0-9]$//;
$base = $base . ".docbook";
} elsif ($base =~ /\/Makefile$/) {
$file_types{$_} = "MAKE";
} elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.conf$/) {
$file_types{$_} = "CONF-C";
} elsif ($base =~ /\/checkconf\/(good|bad)-.*\.conf$/) {
$file_types{$_} = "CONF-C";
} elsif ($base =~ /\/resolv.?\.conf$/) {
$file_types{$_} = "CONF-SH";
} elsif ($base =~ /\.(db|hint)$/) {
$file_types{$_} = "ZONE";
} elsif ($base =~ /\.mkd$/) {
$file_types{$_} = "MKD";
} elsif ($base =~ /(\/\.(gitignore|gitattributes)|Atffile|\.(gif|jpg))$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\.(def|dep|dsp|dsw|mak|sln)$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\.(vcxproj(|\.(user|filters)))$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\.rnc$/i) {
$file_types{$_} = "RNC";
} elsif ($base =~ /^\.\/EXCLUDED$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\.bat$/i) {
$file_types{$_} = "BAT";
} elsif ($base =~ /\/named\.args$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\/named\.port$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\/named\.dropedns$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\/named\.notcp$/i) {
$file_types{$_} = "X";
} elsif ($base =~ /\/README$/i) {
$file_types{$_} = "TXT.BRIEF";
} else {
$file_types{$_} = "?";
}
my $m_year = int(`sh util/file_year.sh $_`);
if (($file_types{$_} eq "MAN" || $file_types{$_} eq "HTML") &&
$base =~ /\.docbook$/ && -e $base) {
$file_years{$_} = "DOCBOOK";
} elsif ($m_year != $year) {
print "$_: must set copyright year(s) manually\n";
$file_years{$_} = "????";
} else {
$file_years{$_} = "$year";
}
} else {
if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
print "$_: must set copyright year(s) manually\n";
$file_years{$_} = "????";
next;
}
# track the modification years even if we are not going to be
# updating the copyrights.
# next if $file_types{$_} eq "X";
next if ($file_years{$_} =~ /^PARENT:/);
next if ($file_years{$_} eq "DOCBOOK");
my @years = split(/,/, $file_years{$_});
my $has_current = 0;
foreach my $fyear (@years) {
if ($fyear == $year) {
$has_current = 1;
}
}
if (!$has_current) {
$file_years{$_} .= ",$year";
}
}
}
close(CHANGES);
open(NEWCOPYRIGHTS, ">util/newcopyrights") ||
die "can't open newcopyrights: $!";
foreach my $file (sort(keys(%file_types))) {
print NEWCOPYRIGHTS "$file";
my $len = length($file);
my $tabs = 0;
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);