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