update_copyrights revision e107074f370ee86275bd64ab8bcaa429fec1c7e2
0N/A#!/usr/local/bin/perl -w
2195N/A#
0N/A# Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
0N/A# Copyright (C) 1998-2001 Internet Software Consortium.
0N/A#
0N/A# Permission to use, copy, modify, and distribute this software for any
0N/A# purpose with or without fee is hereby granted, provided that the above
0N/A# copyright notice and this permission notice appear in all copies.
0N/A#
0N/A# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
0N/A# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
0N/A# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
0N/A# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
0N/A# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
0N/A# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
0N/A# PERFORMANCE OF THIS SOFTWARE.
0N/A
0N/A# $Id: update_copyrights,v 1.36 2005/05/12 07:42:35 marka Exp $
1472N/A
1472N/Arequire 5.002;
1472N/A
0N/A# Map copyright owners to the files containing copyright messages.
0N/A# The first line of the copyright message is not in the file;
0N/A# it is constructed by this script.
1879N/A
1879N/Amy %owner2filename = (
1879N/A "" => "util/COPYRIGHT",
1879N/A "NAI" => "util/COPYRIGHT.NAI",
1879N/A "NOM" => "util/COPYRIGHT.NOM",
1879N/A "BSDI" => "util/COPYRIGHT.BSDI",
1879N/A "BRIEF" => "util/COPYRIGHT.BRIEF",
1879N/A "PORTION" => "util/COPYRIGHT.PORTION",
1879N/A);
1879N/A
2195N/A# Map each copyright owner name to a reference to an array containing
1879N/A# the lines of the copyright message.
1879N/A
1879N/Amy %owner2text = ();
1879N/A
1879N/Amy $keyword_pat = '\$(Id:.*|Revision:.*|Id|Revision)\$';
1879N/A
1879N/Aforeach $owner (keys %owner2filename) {
1879N/A my $f = $owner2filename{$owner};
1879N/A open(COPYRIGHT, "<$f") || die "can't open $f: $!";
1879N/A @copyright_text = <COPYRIGHT>;
1879N/A close(COPYRIGHT);
1879N/A $owner2text{$owner} = [ @copyright_text ];
0N/A}
0N/A
0N/Amy %file_types = ();
0N/Amy %file_years = ();
0N/Amy $years_list;
0N/Amy $parent;
0N/A
0N/Awhile (<>) {
0N/A chomp;
0N/A ($file, $type, $years) = split(/\s+/);
0N/A $file_types{$file} = $type;
0N/A $file_years{$file} = $years;
0N/A}
0N/A
0N/Asub getyears {
0N/A $parent = $_[0];
0N/A $parent =~ s/PARENT://;
0N/A $years_list = $file_years{$parent};
0N/A if (defined($years_list) && $years_list =~ /^PARENT:/) {
0N/A print "BAD PARENT:$parent\n";
0N/A undefine($years_list);
1703N/A }
1703N/A}
1703N/A
1703N/Asub docbook {
1703N/A $parent = $_[0];
1703N/A $parent =~ s/\.[^.]*$/.docbook/;
1703N/A $years_list = $file_years{$parent};
2195N/A}
2195N/A
2195N/Asub copyright {
2195N/A my $holder = shift;
2195N/A my $result = "";
2195N/A return $result unless (@_);
2195N/A $result = "$result <copyright>\n";
0N/A $result = "$result <year>$_</year>\n" foreach (@_);
2195N/A $result = "$result <holder>$holder</holder>\n";
0N/A $result = "$result </copyright>\n";
1703N/A return $result;
0N/A}
0N/A
0N/Asub copyrights {
0N/A my $a = copyright("Internet Systems Consortium, Inc. (\"ISC\")",
0N/A grep({ $_ >= 2004} @_));
0N/A my $b = copyright("Internet Software Consortium.",
0N/A grep({ $_ < 2004} @_));
0N/A return "$a$b";
0N/A}
0N/A
0N/Aforeach $file (keys %file_types) {
0N/A $typeandowner = $file_types{$file};
1703N/A $years_list = $file_years{$file};
0N/A
1703N/A if ( ! -f $file ) {
0N/A print "$file: missing\n";
0N/A next;
1202N/A }
0N/A
0N/A if ($years_list =~ /PARENT:/) {
0N/A getyears($years_list);
1703N/A if (!defined $years_list) {
0N/A print "$file: has bad parent $parent\n";
0N/A next;
0N/A }
1174N/A }
1174N/A
1174N/A if ($years_list eq "DOCBOOK") {
1174N/A docbook($file);
1174N/A if (!defined $years_list) {
1174N/A print "$file: has bad parent $parent\n";
1174N/A next;
1174N/A }
1174N/A }
1703N/A
1703N/A @years = split(/,/, $years_list);
1703N/A
1703N/A my ($type, $owner) = split(/\./, $typeandowner);
1703N/A $owner = "" if !defined $owner;
1703N/A
1174N/A $textp = $owner2text{$owner};
1703N/A if (!defined $textp) {
1703N/A print "$file: unknown copyright owner $owner\n";
1703N/A next;
0N/A }
0N/A
0N/A next if $type eq "X" or $type eq "BAT";
0N/A
0N/A $before_copyright = "";
0N/A $c_comment = 0;
0N/A $shell_comment = 0;
0N/A $m4_comment = 0;
0N/A $sgml_comment = 0;
1703N/A $zone_comment = 0;
0N/A $man_comment = 0;
0N/A $start_comment = "";
0N/A $end_comment = "";
0N/A $first = "";
0N/A if ($type =~ /^(C|YACC|CONF-C)$/) {
0N/A $c_comment = 1;
0N/A $start_comment = "/*\n";
1703N/A $prefix = " * ";
1703N/A $end_comment = " */\n";
1703N/A } elsif ($type =~ /^(SH|PERL|TCL|MAKE|CONF-SH)$/) {
1703N/A $shell_comment = 1;
1703N/A $prefix = "# ";
1703N/A } elsif ($type eq "ZONE" || $type eq "MC") {
1703N/A $zone_comment = 1;
1703N/A $prefix = "; ";
1703N/A } elsif ($type eq "MAN") {
1703N/A $man_comment = 1;
1703N/A $prefix = ".\\\" ";
1703N/A } elsif ($type eq "M4") {
1741N/A $m4_comment = 1;
1741N/A $prefix = "dnl ";
1741N/A } elsif ($type eq "HTML" || $type eq "SGML") {
1741N/A $sgml_comment = 1;
1741N/A $start_comment = "<!--\n";
1741N/A $prefix = " - ";
1741N/A $end_comment = "-->\n";
1741N/A } elsif ($type eq "TXT") {
1741N/A $prefix = "";
1741N/A } else {
1703N/A print "$file: type '$type' not supported yet; skipping\n";
1741N/A next;
1741N/A }
1741N/A
1741N/A ($nonspaceprefix = $prefix) =~ s/\s+$//;
1741N/A
1741N/A open(SOURCE, "<$file") || die "can't open $file: $!";
1741N/A $_ = <SOURCE>;
1741N/A if ($type eq "YACC") {
1741N/A unless ($_ eq "%{\n") {
1703N/A print "$file: unexpected yacc file start ",
1703N/A "(expected \"%{\\n\")\n";
1703N/A close(SOURCE);
1741N/A next;
1741N/A }
1703N/A $before_copyright = "$_";
1703N/A $_ = <SOURCE>;
1703N/A }
1703N/A if ($c_comment && /^\/\*/) {
1703N/A $_ = <SOURCE>;
1703N/A if ($_ !~ /[Cc]opyright/) {
1703N/A print "$file: non-copyright comment\n";
0N/A close(SOURCE);
0N/A next;
0N/A }
0N/A if ($_ !~ /\*\//) {
0N/A while (<SOURCE>) {
0N/A last if $_ =~ /\*\//;
0N/A }
0N/A }
0N/A } elsif ($shell_comment) {
0N/A if (/^\#\!/) {
0N/A $before_copyright = "$_#\n";
1703N/A $_ = <SOURCE>;
0N/A $_ = <SOURCE> if $_ eq "#\n";
0N/A }
0N/A if (/^\#/) {
0N/A if ($_ !~ /[Cc]opyright/) {
0N/A print "$file: non-copyright comment\n";
0N/A close(SOURCE);
0N/A next;
0N/A }
0N/A while (<SOURCE>) {
0N/A if ($_ !~ /^\#/) {
0N/A $first = $_;
0N/A last;
0N/A }
1703N/A }
1703N/A } else {
1703N/A $first = $_;
1703N/A }
1703N/A } elsif (($m4_comment || $zone_comment || $man_comment) &&
1703N/A /^\Q$nonspaceprefix\E/) {
1703N/A
1703N/A while (/^\Q$nonspaceprefix\E\s*$/) {
1703N/A $_ = <SOURCE>;
1703N/A }
1703N/A
1703N/A if ($_ !~ /[Cc]opyright/) {
1703N/A print "$file: non-copyright comment\n";
1703N/A close(SOURCE);
1703N/A next;
1703N/A }
1703N/A while (<SOURCE>) {
1703N/A if ($_ !~ /^\Q$nonspaceprefix\E/ ||
1703N/A $_ =~ /$keyword_pat/) {
1703N/A $first = $_;
1703N/A last;
1703N/A }
1703N/A }
1703N/A } elsif ($sgml_comment) {
1703N/A if (/^<!DOCTYPE/) {
1703N/A $before_copyright = $_;
1703N/A $_ = <SOURCE>;
1703N/A while (! /^<!/ ) {
1703N/A $before_copyright = "$before_copyright$_";
1703N/A $_ = <SOURCE>;
1703N/A }
1703N/A }
1703N/A if (/^<!/) {
1703N/A $_ = <SOURCE> if $_ eq "<!--\n";
1703N/A if ($_ !~ /[Cc]opyright/) {
1703N/A print "$file: non-copyright comment\n";
1703N/A close(SOURCE);
1703N/A next;
1703N/A }
1703N/A while (defined($_)) {
1703N/A last if s/.*-->//;
1703N/A $_ = <SOURCE>;
1703N/A }
1703N/A print "$file: unterminated comment\n"
1703N/A unless defined($_);
1703N/A if ($_ ne "\n") {
1703N/A $first = $_;
1703N/A } else {
1703N/A $first = <SOURCE>;
1703N/A }
1703N/A } else {
1703N/A $first = $_;
1703N/A }
1703N/A } elsif ($type eq "TXT") {
1703N/A if ($_ =~ /[Cc]opyright/) {
1703N/A $/ = ""; # paragraph at a time
1703N/A while (<SOURCE>) {
1703N/A # Not very maintainable, but ok enough for now.
1703N/A last unless
1703N/A /[Cc]opyright/ ||
1703N/A /See COPYRIGHT in the source root/ ||
1703N/A /Permission to use, copy, modify, and / ||
1703N/A /THE SOFTWARE IS PROVIDED "AS IS" AND /;
1703N/A }
1703N/A $/ = "\n";
1703N/A }
1703N/A $first = $_;
1703N/A } else {
1703N/A $first = $_;
1703N/A }
1703N/A
1703N/A $first = "" if ! defined($first);
1703N/A
1703N/A open(TARGET, ">$file.new") || die "can't open $file.new: $!";
1703N/A print TARGET $before_copyright if $before_copyright;
1703N/A print TARGET $start_comment if $start_comment;
1703N/A
1703N/A $sysyears = "";
1703N/A $sftyears = "";
1703N/A $nomyears = "";
1703N/A
1703N/A #
1703N/A # Internet Software Consortium: up to 2003
1703N/A #
1703N/A $last_year = 0;
1703N/A $anchor_year = 0;
1703N/A $years = "";
1703N/A foreach $year (@years) {
1703N/A if ($year >= 2004) { next; }
1703N/A if ($last_year != 0 && $year == $last_year + 1) {
1703N/A if ($year > $anchor_year + 1) {
1703N/A substr($years, $anchor_end) = "-$year";
1703N/A } else {
1703N/A $years .= ", $year";
1703N/A }
1703N/A } else {
1703N/A $years .= $last_year == 0 ? "$year" : ", $year";
1703N/A #if ($anchor_year != 0) {
1703N/A # print "$file: noncontiguous year: ",
1703N/A # "$year != $last_year + 1\n";
1703N/A #}
1703N/A $anchor_year = $year;
1703N/A $anchor_end = length($years);
1703N/A }
1703N/A
1703N/A $last_year = $year;
1703N/A }
1703N/A $sftyears = $years;
1703N/A
1703N/A #
1703N/A # Nominum: up to 2001.
1703N/A #
1703N/A $last_year = 0;
1703N/A $anchor_year = 0;
1703N/A $years = "";
1703N/A foreach $year (@years) {
1703N/A if ($year >= 2002) { next; }
1703N/A if ($last_year != 0 && $year == $last_year + 1) {
1703N/A if ($year > $anchor_year + 1) {
1703N/A substr($years, $anchor_end) = "-$year";
1703N/A } else {
1703N/A $years .= ", $year";
1703N/A }
1703N/A } else {
1703N/A $years .= $last_year == 0 ? "$year" : ", $year";
1703N/A #if ($anchor_year != 0) {
1703N/A # print "$file: noncontiguous year: ",
1703N/A # "$year != $last_year + 1\n";
1703N/A #}
1703N/A $anchor_year = $year;
1703N/A $anchor_end = length($years);
1703N/A }
1703N/A
1703N/A $last_year = $year;
1703N/A }
1703N/A $nomyears = $years;
1703N/A
1703N/A #
1703N/A # Internet Systems Consortium: 2004 onwards.
1703N/A #
1703N/A $last_year = 0;
1703N/A $anchor_year = 0;
1703N/A $years = "";
1703N/A $anchor_end = length($years);
1703N/A foreach $year (@years) {
1703N/A if ($year < 2004) { next; }
1703N/A if ($last_year != 0 && $year == $last_year + 1) {
1703N/A if ($year > $anchor_year + 1) {
1703N/A substr($years, $anchor_end) = "-$year";
1703N/A } else {
1703N/A $years .= ", $year";
1703N/A }
1703N/A } else {
1703N/A $years .= $last_year == 0 ? "$year" : ", $year";
1703N/A #if ($anchor_year != 0) {
1703N/A # print "$file: noncontiguous year: ",
1703N/A # "$year != $last_year + 1\n";
1703N/A #}
1703N/A $anchor_year = $year;
1703N/A $anchor_end = length($years);
1703N/A }
1703N/A
1703N/A $last_year = $year;
1703N/A }
1703N/A $sysyears = $years;
1703N/A
1703N/A ($firstline, $secondline, $thirdline, @otherlines) = @$textp;
1703N/A
1703N/A $firstline =~ s/\@SYSYEARS\@/$sysyears/;
1703N/A $secondline =~ s/\@SFTYEARS\@/$sftyears/;
1703N/A $thirdline =~ s/\@NOMYEARS\@/$nomyears/;
1703N/A
1703N/A print TARGET "$prefix$firstline";
1703N/A if ($sftyears ne "" ) {
1703N/A print TARGET $secondline =~ /^$/ ? $nonspaceprefix : $prefix;
1703N/A print TARGET "$secondline";
1703N/A }
1703N/A print TARGET $thirdline =~ /^$/ ? $nonspaceprefix : $prefix;
1703N/A print TARGET "$thirdline";
0N/A
0N/A foreach $_ (@otherlines) {
0N/A print TARGET (/^$/ ? $nonspaceprefix : $prefix);
0N/A print TARGET "$_";
0N/A }
0N/A print TARGET $end_comment if $end_comment;
0N/A
0N/A if ($first eq "") {
0N/A $first = <SOURCE>;
1703N/A }
0N/A
0N/A if (defined($first)) {
0N/A if ($type eq 'MAN') {
1703N/A print TARGET "$nonspaceprefix\n";
0N/A } else {
0N/A print TARGET "\n";
0N/A }
0N/A
0N/A undef $/;
1703N/A $_ = <SOURCE>;
0N/A $/ = "\n";
0N/A
0N/A if ($type eq 'SGML' && m:<docinfo>.*?</docinfo>:s) {
0N/A print "docinfo: $file\n";
0N/A my $r = copyrights(@years);
1703N/A s:<docinfo>.*?></docinfo>:<docinfo>\n$r </docinfo>:s;
1703N/A }
1703N/A if ($type eq 'SGML' && m:<bookinfo>.*?</bookinfo>:s) {
1703N/A print "bookinfo: $file\n";
0N/A my $r = copyrights(@years);
0N/A s:<bookinfo>.*?</bookinfo>:<bookinfo>\n$r </bookinfo>:s;
0N/A }
0N/A
0N/A my ($start, $end);
0N/A if ($start_comment ne "") {
0N/A ($start = $start_comment) =~ s/\s*\n/ /;
0N/A ($end = $end_comment) =~ s/^\s*(.*)\n/ $1\n/;
0N/A } elsif ($prefix ne "") {
0N/A ($start = $prefix) =~ s/\s*\n//;
0N/A $end = "\n";
0N/A } else {
0N/A $start = "";
0N/A $end = "\n";
0N/A }
0N/A
1703N/A if ($first !~ /$keyword_pat/ && $_ !~ /$keyword_pat/) {
0N/A $end = "\n$nonspaceprefix" if ($type eq "MAN");
0N/A print TARGET "$start\$";
0N/A print TARGET "Id";
0N/A print TARGET "\$$end\n";
0N/A }
0N/A
0N/A print TARGET $first if $first !~ /^\s*$/;
0N/A print TARGET $_;
0N/A }
0N/A close(TARGET);
0N/A close(SOURCE);
0N/A
0N/A $mode = (stat $file)[2]&511;
0N/A chmod $mode, "$file.new";
0N/A
0N/A if (system("cmp -s $file.new $file") == 0) {
0N/A unlink("$file.new");
0N/A } else {
0N/A rename("$file.new", "$file")
0N/A or die "rename($file.new, $file): $!";
0N/A }
0N/A}
0N/A