merge_copyrights revision 5fa46bc91672ef5737aee6f99763161511566c24
0N/A#!/usr/local/bin/perl -w
0N/A#
0N/A# Copyright (C) 2004-2007, 2009-2012 Internet Systems Consortium, Inc. ("ISC")
0N/A# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
0N/A#
0N/A# Permission to use, copy, modify, and/or distribute this software for any
0N/A# purpose with or without fee is hereby granted, provided that the above
0N/A# copyright notice and this permission notice appear in all copies.
0N/A#
0N/A# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
0N/A# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
0N/A# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
0N/A# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
0N/A# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
0N/A# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
0N/A# PERFORMANCE OF THIS SOFTWARE.
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) = localtime(time());
0N/A$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
0N/A$year += 1900;
0N/A
0N/Aopen(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
0N/Awhile (<FILES>) {
0N/A chomp;
0N/A $exists{$_} = 1;
0N/A}
0N/Aclose(FILES);
0N/A
0N/Aopen(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
0N/Awhile (<CHANGES>) {
0N/A chomp;
0N/A
0N/A # this file isn't in the repository now
0N/A next unless ($exists{$_});
0N/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\//) {
0N/A $file_types{$_} = "X";
0N/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$/) {
0N/A $file_types{$_} = "YACC";
0N/A } elsif ($base =~ /\.pl$/i) {
0N/A $file_types{$_} = "PERL";
0N/A } elsif ($base =~ /\.sh$/) {
0N/A $file_types{$_} = "SH";
0N/A } elsif ($base =~ /\.docbook$/ ||
0N/A $base =~ /.xsl$/ ||
0N/A $base =~ /.xml$/) {
0N/A $file_types{$_} = "SGML";
0N/A } elsif ($base =~ /\.html$/) {
0N/A $file_types{$_} = "HTML";
0N/A } elsif ($base =~ /\.(man|[0-9])$/) {
0N/A $file_types{$_} = "MAN";
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 =~ /\/resolv.?\.conf$/) {
0N/A $file_types{$_} = "CONF-SH";
0N/A } elsif ($base =~ /\.(db|hint)$/) {
0N/A $file_types{$_} = "ZONE";
0N/A } elsif ($base =~ /(\/\.gitignore|\.gif|\.jpg|\.dsp|\.dsw|\.mak)$/i) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.rnc$/i) {
0N/A $file_types{$_} = "RNC";
0N/A } elsif ($base =~ /^\.\/EXCLUDED$/i) {
0N/A $file_types{$_} = "X";
0N/A } elsif ($base =~ /\.bat$/i) {
0N/A $file_types{$_} = "BAT";
0N/A } elsif ($base =~ /\/named\.args$/i) {
0N/A $file_types{$_} = "X";
0N/A } else {
0N/A $file_types{$_} = "?";
0N/A }
0N/A my $m_year = int(`sh util/file_year.sh $_`);
0N/A if ($m_year != $year) {
0N/A print "$_: must set copyright year(s) manually\n";
0N/A $file_years{$_} = "????";
0N/A } else {
0N/A $file_years{$_} = "$year";
0N/A }
0N/A } else {
0N/A if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
0N/A print "$_: must set copyright year(s) manually\n";
0N/A $file_years{$_} = "????";
0N/A next;
0N/A }
0N/A
0N/A # track the modification years even if we are not going to be
0N/A # updating the copyrights.
0N/A # next if $file_types{$_} eq "X";
0N/A next if ($file_years{$_} =~ /^PARENT:/);
0N/A next if ($file_years{$_} eq "DOCBOOK");
0N/A
0N/A my @years = split(/,/, $file_years{$_});
0N/A my $has_current = 0;
0N/A foreach my $fyear (@years) {
0N/A if ($fyear == $year) {
0N/A $has_current = 1;
0N/A }
0N/A }
0N/A if (!$has_current) {
0N/A $file_years{$_} .= ",$year";
0N/A }
0N/A }
0N/A}
0N/Aclose(CHANGES);
0N/A
0N/Aopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
0N/A die "can't open newcopyrights: $!";
0N/Aforeach my $file (sort(keys(%file_types))) {
0N/A print NEWCOPYRIGHTS "$file";
0N/A my $len = length($file);
0N/A my $tabs = 0;
0N/A if ($len >= 48) {
0N/A $tabs = 1;
0N/A } else {
0N/A my $needed = int (48 - $len);
0N/A $tabs = int ($needed / 8);
0N/A if ($needed % 8 != 0) {
0N/A $tabs++;
0N/A }
0N/A }
0N/A for (my $i = 0; $i < $tabs; $i++) {
0N/A printf NEWCOPYRIGHTS "\t";
0N/A }
0N/A printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
0N/A
0N/A if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
0N/A print "Unknown file type or year: $file\n";
0N/A }
0N/A}
0N/Aclose(NEWCOPYRIGHTS);
0N/A