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