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