merge_copyrights revision 1f50a0a44183410627e22d72c65a35974e235597
4de2612967d06c4fdbf524a62556a1e8118a006fxs#!/usr/local/bin/perl -w
4de2612967d06c4fdbf524a62556a1e8118a006fxs#
4de2612967d06c4fdbf524a62556a1e8118a006fxs# Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC")
4de2612967d06c4fdbf524a62556a1e8118a006fxs# Copyright (C) 1998-2001, 2003 Internet Software Consortium.
4de2612967d06c4fdbf524a62556a1e8118a006fxs#
4de2612967d06c4fdbf524a62556a1e8118a006fxs# Permission to use, copy, modify, and/or distribute this software for any
4de2612967d06c4fdbf524a62556a1e8118a006fxs# purpose with or without fee is hereby granted, provided that the above
4de2612967d06c4fdbf524a62556a1e8118a006fxs# copyright notice and this permission notice appear in all copies.
4de2612967d06c4fdbf524a62556a1e8118a006fxs#
4de2612967d06c4fdbf524a62556a1e8118a006fxs# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
4de2612967d06c4fdbf524a62556a1e8118a006fxs# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4de2612967d06c4fdbf524a62556a1e8118a006fxs# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
4de2612967d06c4fdbf524a62556a1e8118a006fxs# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4de2612967d06c4fdbf524a62556a1e8118a006fxs# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
4de2612967d06c4fdbf524a62556a1e8118a006fxs# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4de2612967d06c4fdbf524a62556a1e8118a006fxs# PERFORMANCE OF THIS SOFTWARE.
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs# $Id: merge_copyrights,v 1.36 2010/11/17 03:16:21 marka Exp $
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs%file_types = ();
4de2612967d06c4fdbf524a62556a1e8118a006fxs%file_years = ();
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxsopen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
4de2612967d06c4fdbf524a62556a1e8118a006fxswhile (<COPYRIGHTS>) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs chomp;
4de2612967d06c4fdbf524a62556a1e8118a006fxs ($file, $type, $years) = split;
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$file} = $type;
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_years{$file} = $years;
4de2612967d06c4fdbf524a62556a1e8118a006fxs}
4de2612967d06c4fdbf524a62556a1e8118a006fxsclose(COPYRIGHTS);
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
4de2612967d06c4fdbf524a62556a1e8118a006fxs$year += 1900;
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs$find = "find . -type f -print";
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxsopen(FILES, "$find | sort |") || die "can't start \"$find\": $!";
4de2612967d06c4fdbf524a62556a1e8118a006fxswhile (<FILES>) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs chomp;
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs next if (m%/\.\# | # CVS old conflict file
4de2612967d06c4fdbf524a62556a1e8118a006fxs /CVS/ | # CVS directory
4de2612967d06c4fdbf524a62556a1e8118a006fxs util/newcopyrights | # our output
4de2612967d06c4fdbf524a62556a1e8118a006fxs \.bak$ | # created by update_copyrights
4de2612967d06c4fdbf524a62556a1e8118a006fxs /(dnssafe|openssl)/.*\.[ch]$ | # imported
4de2612967d06c4fdbf524a62556a1e8118a006fxs doc/(draft|expired|rfc)/ # imported
4de2612967d06c4fdbf524a62556a1e8118a006fxs %x);
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs if (!$file_types{$_}) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs # Strip any .in extension to find out the file's real type.
4de2612967d06c4fdbf524a62556a1e8118a006fxs # .in files are processed by configure to produce the target file.
4de2612967d06c4fdbf524a62556a1e8118a006fxs ($base = $_) =~ s/\.in$//;
4de2612967d06c4fdbf524a62556a1e8118a006fxs
4de2612967d06c4fdbf524a62556a1e8118a006fxs # Contributed code should maintain its own copyright.
4de2612967d06c4fdbf524a62556a1e8118a006fxs if ($base =~ /\.\/contrib\//) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "X";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "X";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.(c|h|css)$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "C";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.y$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "YACC";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.pl$/i) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "PERL";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.sh$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "SH";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.docbook$/ ||
4de2612967d06c4fdbf524a62556a1e8118a006fxs $base =~ /.xsl$/ ||
4de2612967d06c4fdbf524a62556a1e8118a006fxs $base =~ /.xml$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "SGML";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.html$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "HTML";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\.(man|[0-9])$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "MAN";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\/Makefile$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "MAKE";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\/(named|rndc).{0,2}\.conf$/) {
4de2612967d06c4fdbf524a62556a1e8118a006fxs $file_types{$_} = "CONF-C";
4de2612967d06c4fdbf524a62556a1e8118a006fxs } elsif ($base =~ /\/resolv.?\.conf$/) {
$file_types{$_} = "CONF-SH";
} elsif ($base =~ /\.(db|hint)$/) {
$file_types{$_} = "ZONE";
} elsif ($base =~ /(\/\.cvsignore|\.gif|\.jpg|\.dsp|\.dsw|\.mak)$/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";
} else {
$file_types{$_} = "?";
}
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
$blksize,$blocks)
= stat($_);
($sec,$min,$hour,$mday,$mon,$c_year,$wday,$yday,$isdst) =
localtime($ctime);
($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
localtime($mtime);
$c_year += 1900;
$m_year += 1900;
if ($m_year != $year || $c_year != $year) {
print "$_: must set copyright year(s) manually\n";
$file_years{$_} = "????";
} else {
$file_years{$_} = "$year";
}
# keep perl from issuing warnings about "used only once"
$dev = $ino = $mode = $nlink = $uid = $gid = $rdev = $size = 0;
$atime = $blksize = $blocks = 0;
} 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");
@years = split(/,/, $file_years{$_});
$has_current = 0;
foreach $fyear (@years) {
if ($fyear == $year) {
$has_current = 1;
}
}
if (!$has_current) {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
$blksize,$blocks)
= stat($_);
($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
localtime($mtime);
$m_year += 1900;
if ($m_year == $year) {
$file_years{$_} .= ",$year";
}
}
}
}
close(FILES);
open(NEWCOPYRIGHTS, ">util/newcopyrights") ||
die "can't open newcopyrights: $!";
foreach $file (sort(keys(%file_types))) {
print NEWCOPYRIGHTS "$file";
$len = length($file);
if ($len >= 48) {
$tabs = 1;
} else {
$needed = int (48 - $len);
$tabs = int ($needed / 8);
if ($needed % 8 != 0) {
$tabs++;
}
}
for ($i = 0; $i < $tabs; $i++) {
printf NEWCOPYRIGHTS "\t";
}
printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
}
close(NEWCOPYRIGHTS);