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