merge_copyrights revision 0b72c791466d0807bcf22522b5ddb7da902c2720
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley#!/usr/local/bin/perl -w
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley%file_types = ();
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley%file_years = ();
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyopen(COPYRIGHTS, "<util/copyrights") || die "can't open copyrights: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleywhile (<COPYRIGHTS>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley chomp;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($file, $type, $years) = split;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$file} = $type;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$file} = $years;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(COPYRIGHTS);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley$year += 1900;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyopen(FILES, "<util/files") || die "can't open files: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleywhile (<FILES>) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley chomp;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (!$file_types{$_}) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($_ =~ /\.[chy]$/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "C";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } elsif ($_ =~ /\/Makefile\.in$/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "SH";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } elsif ($_ =~ /\/\.cvsignore$/) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "X";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_types{$_} = "?";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $blksize,$blocks)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley = stat($_);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($sec,$min,$hour,$mday,$mon,$c_year,$wday,$yday,$isdst) =
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley localtime($ctime);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley localtime($mtime);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $c_year += 1900;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $m_year += 1900;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($m_year != $year || $c_year != $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print "$_: must set copyright year(s) manually\n";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$_} = "????";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$_} = "$year";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley # keep perl from issuing warnings about "used only once"
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $dev = $ino = $mode = $nlink = $uid = $gid = $rdev = $size = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $atime = $blksize = $blocks = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($file_types{$_} eq "X" || $file_years{$_} eq "????") {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley next;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley @years = split(/,/, $file_years{$_});
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $has_current = 0;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley foreach $fyear (@years) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($fyear == $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $has_current = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (!$has_current) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $blksize,$blocks)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley = stat($_);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley localtime($mtime);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $m_year += 1900;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($m_year == $year) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $file_years{$_} .= ",$year";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(FILES);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyopen(NEWCOPYRIGHTS, ">util/newcopyrights") ||
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley die "can't open newcopyrights: $!";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyforeach $file (sort(keys(%file_types))) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley print NEWCOPYRIGHTS "$file";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $len = length($file);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($len >= 48) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = 1;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley } else {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $needed = int (48 - $len);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs = int ($needed / 8);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if ($needed % 8 != 0) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley $tabs++;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley for ($i = 0; $i < $tabs; $i++) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley printf NEWCOPYRIGHTS "\t";
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley }
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyclose(NEWCOPYRIGHTS);