2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

support COPYRIGHT.BRIEF

support YACC, CONF-C, CONF-SH, ZONE, MAN, HTML and TXT types.
coalesce multiyear ranges into a hyphen-separated range.
complain about noncontiguous dates.
only generate .bak file if different from new file.
This commit is contained in:
David Lawrence
2000-06-22 17:49:46 +00:00
parent 460b427411
commit 4b598d8ae5

View File

@@ -1,6 +1,6 @@
#!/usr/local/bin/perl -w #!/usr/local/bin/perl -w
# #
# Copyright (C) 1998, 1999, 2000 Internet Software Consortium. # Copyright (C) 1998-2000 Internet Software Consortium.
# #
# Permission to use, copy, modify, and distribute this software for any # Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above # purpose with or without fee is hereby granted, provided that the above
@@ -24,6 +24,7 @@ require 5.002;
my %owner2filename = ( my %owner2filename = (
"" => "util/COPYRIGHT", "" => "util/COPYRIGHT",
"NAI" => "util/COPYRIGHT.NAI", "NAI" => "util/COPYRIGHT.NAI",
"BRIEF" => "util/COPYRIGHT.BRIEF",
"PORTION" => "util/COPYRIGHT.PORTION", "PORTION" => "util/COPYRIGHT.PORTION",
); );
@@ -60,28 +61,55 @@ while (<>) {
next if $type eq "X"; next if $type eq "X";
# XXXTALE lib/isc/commandline.c should probably also have special handling.
$before_copyright = ""; $before_copyright = "";
$c_comment = 0; $c_comment = 0;
$shell_comment = 0; $shell_comment = 0;
$m4_comment = 0; $m4_comment = 0;
$html_comment = 0;
$zone_comment = 0;
$man_comment = 0;
$start_comment = "";
$end_comment = "";
$first = ""; $first = "";
if ($type eq "C") { if ($type =~ /^(C|YACC|CONF-C)/) {
$c_comment = 1; $c_comment = 1;
$start_comment = "/*\n";
$prefix = " * "; $prefix = " * ";
} elsif ($type eq "SH" || $type eq "PERL" || $type eq "MAKE") { $end_comment = " */\n";
} elsif ($type =~ /^(SH|PERL|MAKE|CONF-SH)/) {
$shell_comment = 1; $shell_comment = 1;
$prefix = "# "; $prefix = "# ";
} elsif ($type eq "ZONE") {
$zone_comment = 1;
$prefix = "; ";
} elsif ($type eq "MAN") {
$man_comment = 1;
$prefix = ".\\\" ";
} elsif ($type eq "M4") { } elsif ($type eq "M4") {
$m4_comment = 1; $m4_comment = 1;
$prefix = "dnl "; $prefix = "dnl ";
} elsif ($type eq "HTML") {
$html_comment = 1;
$start_comment = "<!--\n";
$prefix = " - ";
$end_comment = "-->\n";
} elsif ($type eq "TXT") {
$prefix = "";
} else { } else {
print "$file: type '$type' not supported yet; skipping\n"; print "$file: type '$type' not supported yet; skipping\n";
next; next;
} }
open(SOURCE, "<$file") || die "can't open $file: $!"; open(SOURCE, "<$file") || die "can't open $file: $!";
$_ = <SOURCE>; $_ = <SOURCE>;
if ($type eq "YACC") {
unless ($_ eq "%{\n") {
print "$file: unexpected yacc file start (expected \"%{\\n\")\n";
close(SOURCE);
next;
}
$before_copyright = "$_";
$_ = <SOURCE>;
}
if ($c_comment && /^\/\*/) { if ($c_comment && /^\/\*/) {
$_ = <SOURCE>; $_ = <SOURCE>;
if ($_ !~ /[Cc]opyright/) { if ($_ !~ /[Cc]opyright/) {
@@ -100,9 +128,7 @@ while (<>) {
if (/^\#\!/) { if (/^\#\!/) {
$before_copyright = "$_#\n"; $before_copyright = "$_#\n";
$_ = <SOURCE>; $_ = <SOURCE>;
if ($_ eq "#\n") { $_ = <SOURCE> if $_ eq "#\n";
$_ = <SOURCE>;
}
} }
if (/^\#/) { if (/^\#/) {
if ($_ !~ /[Cc]opyright/) { if ($_ !~ /[Cc]opyright/) {
@@ -119,37 +145,97 @@ while (<>) {
} else { } else {
$first = $_; $first = $_;
} }
} elsif ($m4_comment && /^dnl /) { } elsif (($m4_comment || $zone_comment || $man_comment) &&
/^\Q$prefix\E/) {
($nonspaceprefix = $prefix) =~ s/\s+$//;
while (/^\Q$nonspaceprefix\E\s*$/) {
$_ = <SOURCE>;
}
if ($_ !~ /[Cc]opyright/) { if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n"; print "$file: non-copyright comment\n";
close(SOURCE); close(SOURCE);
next; next;
} }
while (<SOURCE>) { while (<SOURCE>) {
if ($_ !~ /^dnl /) { if ($_ !~ /^\Q$prefix\E/) {
$first = $_; $first = $_;
last; last;
} }
} }
} elsif ($html_comment) {
if (/^<!DOCTYPE/) {
$before_copyright = $_;
$_ = <SOURCE>;
}
if (/^<!/) {
$_ = <SOURCE> if $_ eq "<!--\n";
if ($_ !~ /[Cc]opyright/) {
print "$file: non-copyright comment\n";
close(SOURCE);
next;
}
while (defined($_)) {
last if s/.*-->//;
$_ = <SOURCE>;
}
print "$file: unterminated comment\n" unless defined($_);
if ($_ ne "\n") {
$first = $_;
} else {
$first = <SOURCE>;
}
} else {
$first = $_;
}
} elsif ($type eq "TXT") {
if ($_ =~ /[Cc]opyright/) {
$/ = ""; # paragraph at a time
while (<SOURCE>) {
# Not very maintainable, but suitable enough for now.
last unless
/See COPYRIGHT in the source root/ ||
/Permission to use, copy, modify, and distribute / ||
/THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET /;
}
$/ = "\n";
}
$first = $_;
} else { } else {
$first = $_; $first = $_;
} }
$first = "" if ! defined($first);
open(TARGET, ">$file.new") || die "can't open $file.new: $!"; open(TARGET, ">$file.new") || die "can't open $file.new: $!";
if ($before_copyright ne "") { if ($before_copyright ne "") {
print TARGET $before_copyright; print TARGET $before_copyright;
} }
if ($c_comment) { if ($start_comment) {
print TARGET "/*\n"; print TARGET $start_comment;
} }
$years = ""; $years = "";
$first_year = 1; $last_year = 0;
$anchor_year = 0;
foreach $year (@years) { foreach $year (@years) {
if (! $first_year) { if ($last_year != 0 && $year == $last_year + 1) {
$years .= ", "; if ($year > $anchor_year + 1) {
} substr($years, $anchor_end) = "-$year";
$years .= "$year"; } else {
$first_year = 0; $years .= ", $year";
}
} else {
$years .= $last_year == 0 ? "$year" : ", $year";
if ($anchor_year != 0) {
print "$file: noncontiguous year: $year != $last_year + 1\n";
}
$anchor_year = $year;
$anchor_end = length($years);
}
$last_year = $year;
} }
($firstline, @otherlines) = @$textp; ($firstline, @otherlines) = @$textp;
@@ -161,13 +247,13 @@ while (<>) {
foreach $_ (@otherlines) { foreach $_ (@otherlines) {
print TARGET "${prefix}$_"; print TARGET "${prefix}$_";
} }
if ($c_comment) { if ($end_comment) {
print TARGET " */\n"; print TARGET $end_comment;
} }
if ($first eq "") { if ($first eq "") {
$first = <SOURCE>; $first = <SOURCE>;
} }
if ($first ne "") { if (defined($first)) {
if ($first !~ /^\s*$/) { if ($first !~ /^\s*$/) {
print TARGET "\n"; print TARGET "\n";
} }
@@ -180,6 +266,11 @@ while (<>) {
close(SOURCE); close(SOURCE);
$mode = (stat $file)[2]&511; $mode = (stat $file)[2]&511;
chmod $mode, "$file.new"; chmod $mode, "$file.new";
rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
rename("$file.new", "$file") || die "rename($file.new, $file): $!"; if (system("cmp -s $file.new $file") == 0) {
unlink("$file.new");
} else {
rename("$file", "$file.bak") || die "rename($file, $file.bak): $!";
rename("$file.new", "$file") || die "rename($file.new, $file): $!";
}
} }