summaryrefslogtreecommitdiff
path: root/build-aux/update-copyright
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux/update-copyright')
-rwxr-xr-xbuild-aux/update-copyright159
1 files changed, 80 insertions, 79 deletions
diff --git a/build-aux/update-copyright b/build-aux/update-copyright
index 6d56e48fdb1..ea3e46fe60f 100755
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -138,7 +138,7 @@
eval 'exec perl -wSx -0777 -pi "$0" "$@"'
if 0;
-my $VERSION = '2023-06-18.01:14'; # UTC
+my $VERSION = '2024-01-15.18:30'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
@@ -146,6 +146,7 @@ my $VERSION = '2023-06-18.01:14'; # UTC
use strict;
use warnings;
+use re 'eval';
my $copyright_re = 'Copyright';
my $circle_c_re = '(?:\([cC]\)|@copyright\{}|\\\\\(co|©|©)';
@@ -169,14 +170,13 @@ if (!$this_year || $this_year !~ m/^\d{4}$/)
# Unless the file consistently uses "\r\n" as the EOL, use "\n" instead.
my $eol = /(?:^|[^\r])\n/ ? "\n" : "\r\n";
-my $leading;
-my $prefix;
-my $ws_re;
my $stmt_re;
-while (/(^|\n)(.{0,$prefix_max})$copyright_re/g)
+my $found;
+while (/(^|\n)(.{0,$prefix_max})$copyright_re/cg)
{
- $leading = "$1$2";
- $prefix = $2;
+ my $pos=pos();
+ my $leading = "$1$2";
+ my $prefix = $2;
if ($prefix =~ /^(\s*\/)\*(\s*)$/)
{
$prefix =~ s,/, ,;
@@ -187,7 +187,7 @@ while (/(^|\n)(.{0,$prefix_max})$copyright_re/g)
$prefix = $prefix_ws;
}
}
- $ws_re = '[ \t\r\f]'; # \s without \n
+ my $ws_re = '[ \t\r\f]'; # \s without \n
$ws_re =
"(?:$ws_re*(?:$ws_re|\\n" . quotemeta($prefix) . ")$ws_re*)";
my $holder_re = $holder;
@@ -198,96 +198,97 @@ while (/(^|\n)(.{0,$prefix_max})$copyright_re/g)
. "((?:\\d\\d)?\\d\\d)$ws_re$holder_re";
if (/\G$stmt_remainder_re/)
{
+ $found = 1;
$stmt_re =
quotemeta($leading) . "($copyright_re$stmt_remainder_re)";
- last;
- }
- }
-if (defined $stmt_re)
- {
- /$stmt_re/ or die; # Should never die.
- my $stmt = $1;
- my $final_year_orig = $2;
- # Handle two-digit year numbers like "98" and "99".
- my $final_year = $final_year_orig;
- $final_year <= 99
- and $final_year += 1900;
+ /$stmt_re/ or die; # Should never die.
+ my $stmt = $1;
+ my $final_year_orig = $2;
- if ($final_year != $this_year)
- {
- # Update the year.
- $stmt =~ s/(^|[^\d])$final_year_orig\b/$1$final_year, $this_year/;
- }
- if ($final_year != $this_year || $ENV{'UPDATE_COPYRIGHT_FORCE'})
- {
- # Normalize all whitespace including newline-prefix sequences.
- $stmt =~ s/$ws_re/ /g;
+ # Handle two-digit year numbers like "98" and "99".
+ my $final_year = $final_year_orig;
+ $final_year <= 99
+ and $final_year += 1900;
- # Put spaces after commas.
- $stmt =~ s/, ?/, /g;
-
- # Convert 2-digit to 4-digit years.
- $stmt =~ s/(\b\d\d\b)/19$1/g;
-
- # Make the use of intervals consistent.
- if (!$ENV{UPDATE_COPYRIGHT_USE_INTERVALS})
+ if ($final_year != $this_year)
{
- $stmt =~ s/(\d{4})$ndash_re(\d{4})/join(', ', $1..$2)/eg;
+ # Update the year.
+ $stmt =~ s/(^|[^\d])$final_year_orig\b/$1$final_year, $this_year/;
}
- else
+ if ($final_year != $this_year || $ENV{'UPDATE_COPYRIGHT_FORCE'})
{
- my $ndash = ($ARGV =~ /\.tex(i(nfo)?)?$/ ? "--"
- : $ARGV =~ /\.(\d[a-z]*|man)$/ ? "\\(en"
- : "-");
+ # Normalize all whitespace including newline-prefix sequences.
+ $stmt =~ s/$ws_re/ /g;
- $stmt =~
- s/
- (\d{4})
- (?:
- (,\ |$ndash_re)
- ((??{
- if ($2 ne ', ') { '\d{4}'; }
- elsif (!$3) { $1 + 1; }
- else { $3 + 1; }
- }))
- )+
- /$1$ndash$3/gx;
+ # Put spaces after commas.
+ $stmt =~ s/, ?/, /g;
- # When it's 2, emit a single range encompassing all year numbers.
- $ENV{UPDATE_COPYRIGHT_USE_INTERVALS} == 2
- and $stmt =~ s/(^|[^\d])(\d{4})\b.*(?:[^\d])(\d{4})\b/$1$2$ndash$3/;
- }
+ # Convert 2-digit to 4-digit years.
+ $stmt =~ s/(\b\d\d\b)/19$1/g;
- # Format within margin.
- my $stmt_wrapped;
- my $text_margin = $margin - length($prefix);
- if ($prefix =~ /^(\t+)/)
- {
- $text_margin -= length($1) * ($tab_width - 1);
- }
- while (length $stmt)
- {
- if (($stmt =~ s/^(.{1,$text_margin})(?: |$)//)
- || ($stmt =~ s/^([\S]+)(?: |$)//))
+ # Make the use of intervals consistent.
+ if (!$ENV{UPDATE_COPYRIGHT_USE_INTERVALS})
{
- my $line = $1;
- $stmt_wrapped .= $stmt_wrapped ? "$eol$prefix" : $leading;
- $stmt_wrapped .= $line;
+ $stmt =~ s/(\d{4})$ndash_re(\d{4})/join(', ', $1..$2)/eg;
}
else
{
- # Should be unreachable, but we don't want an infinite
- # loop if it can be reached.
- die;
+ my $ndash = ($ARGV =~ /\.tex(i(nfo)?)?$/ ? "--"
+ : $ARGV =~ /\.(\d[a-z]*|man)$/ ? "\\(en"
+ : "-");
+
+ $stmt =~
+ s/
+ (\d{4})
+ (?:
+ (,\ |$ndash_re)
+ ((??{
+ if ($2 ne ', ') { '\d{4}'; }
+ elsif (!$3) { $1 + 1; }
+ else { $3 + 1; }
+ }))
+ )+
+ /$1$ndash$3/gx;
+
+ # When it's 2, emit a single range encompassing all year numbers.
+ $ENV{UPDATE_COPYRIGHT_USE_INTERVALS} == 2
+ and $stmt =~ s/(^|[^\d])(\d{4})\b.*(?:[^\d])(\d{4})\b/$1$2$ndash$3/;
}
- }
- # Replace the old copyright statement.
- s/$stmt_re/$stmt_wrapped/g;
+ # Format within margin.
+ my $stmt_wrapped;
+ my $text_margin = $margin - length($prefix);
+ if ($prefix =~ /^(\t+)/)
+ {
+ $text_margin -= length($1) * ($tab_width - 1);
+ }
+ while (length $stmt)
+ {
+ if (($stmt =~ s/^(.{1,$text_margin})(?: |$)//)
+ || ($stmt =~ s/^([\S]+)(?: |$)//))
+ {
+ my $line = $1;
+ $stmt_wrapped .= $stmt_wrapped ? "$eol$prefix" : $leading;
+ $stmt_wrapped .= $line;
+ }
+ else
+ {
+ # Should be unreachable, but we don't want an infinite
+ # loop if it can be reached.
+ die;
+ }
+ }
+
+ # Replace the old copyright statement.
+ my $p = pos();
+ s/$stmt_re/$stmt_wrapped/g;
+ pos() = $p;
+ }
}
}
-else
+
+if (!$found)
{
print STDERR "$ARGV: warning: copyright statement not found\n";
}