summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9b8fb61)
* build-aux/update-copyright: Append "_re" to the name of any
variable holding a regular expression.
Replace "old" and "new" with "stmt" in variable names.
Do not accept 2-digit UPDATE_COPYRIGHT_YEAR, which was not
handled correctly.
Format code more consistently.
+2009-08-05 Joel E. Denny <jdenny@clemson.edu>
+
+ update-copyright: clean up code a little
+ * build-aux/update-copyright: Append "_re" to the name of any
+ variable holding a regular expression.
+ Replace "old" and "new" with "stmt" in variable names.
+ Do not accept 2-digit UPDATE_COPYRIGHT_YEAR, which was not
+ handled correctly.
+ Format code more consistently.
+
2009-08-05 Joel E. Denny <jdenny@clemson.edu>
update-copyright-tests: improve portability
2009-08-05 Joel E. Denny <jdenny@clemson.edu>
update-copyright-tests: improve portability
use strict;
use warnings;
use strict;
use warnings;
-my $this_year = $ENV{UPDATE_COPYRIGHT_YEAR};
-if (!$this_year || $this_year !~ m/^\d\d(\d\d)?$/) {
- my ($sec, $min, $hour, $mday, $month, $year) = localtime (time ());
- $this_year = $year + 1900;
-}
-my $copyright = 'Copyright (?:\([cC]\)|@copyright{}|©)';
+my $copyright_re = 'Copyright (?:\([cC]\)|@copyright{}|©)';
my $holder = 'Free Software Foundation, Inc.';
my $prefix_max = 5;
my $margin = 72;
my $tab_width = 8;
my $holder = 'Free Software Foundation, Inc.';
my $prefix_max = 5;
my $margin = 72;
my $tab_width = 8;
+my $this_year = $ENV{UPDATE_COPYRIGHT_YEAR};
+if (!$this_year || $this_year !~ m/^\d{4}$/)
+ {
+ my ($sec, $min, $hour, $mday, $month, $year) = localtime (time ());
+ $this_year = $year + 1900;
+ }
+
# Unless the file consistently uses "\r\n" as the EOL, use "\n" instead.
my $eol = /(?:^|[^\r])\n/ ? "\n" : "\r\n";
my $leading;
my $prefix;
# 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;
-my $old_re;
-if (/(^|\n)(.{0,$prefix_max})$copyright/)
+my $ws_re;
+my $stmt_re;
+if (/(^|\n)(.{0,$prefix_max})$copyright_re/)
{
$leading = $1;
$prefix = $2;
{
$leading = $1;
$prefix = $2;
- $ws = '[ \t\r\f]'; # \s without \n
- $ws = "(?:$ws*(?:$ws|\\n" . quotemeta($prefix) . ")$ws*)";
- $holder =~ s/\s/$ws/g;
- $old_re =
- quotemeta("$leading$prefix") . "($copyright$ws"
- . "(?:(?:\\d\\d)?\\d\\d(,$ws?|-))*"
- . "((?:\\d\\d)?\\d\\d)$ws$holder)";
+ $ws_re = '[ \t\r\f]'; # \s without \n
+ $ws_re =
+ "(?:$ws_re*(?:$ws_re|\\n" . quotemeta($prefix) . ")$ws_re*)";
+ my $holder_re = $holder;
+ $holder_re =~ s/\s/$ws_re/g;
+ $stmt_re =
+ quotemeta("$leading$prefix") . "($copyright_re$ws_re"
+ . "(?:(?:\\d\\d)?\\d\\d(,$ws_re?|-))*"
+ . "((?:\\d\\d)?\\d\\d)$ws_re$holder_re)";
-if (defined $old_re && /$old_re/)
+if (defined $stmt_re && /$stmt_re/)
my $sep = $2 ? $2 : "";
my $final_year_orig = $3;
my $sep = $2 ? $2 : "";
my $final_year_orig = $3;
# Update the year.
if ($sep eq '-' && $final_year + 1 == $this_year)
{
# Update the year.
if ($sep eq '-' && $final_year + 1 == $this_year)
{
- $new =~ s/$final_year_orig/$this_year/;
+ $stmt =~ s/$final_year_orig/$this_year/;
}
elsif ($sep ne '-' && $final_year + 1 == $this_year)
{
}
elsif ($sep ne '-' && $final_year + 1 == $this_year)
{
- $new =~ s/$final_year_orig/$final_year-$this_year/;
+ $stmt =~ s/$final_year_orig/$final_year-$this_year/;
- $new =~ s/$final_year_orig/$final_year, $this_year/;
+ $stmt =~ s/$final_year_orig/$final_year, $this_year/;
}
# Normalize all whitespace including newline-prefix sequences.
}
# Normalize all whitespace including newline-prefix sequences.
# Put spaces after commas.
# Put spaces after commas.
my $text_margin = $margin - length($prefix);
my $text_margin = $margin - length($prefix);
- if ($prefix =~ /^(\t+)/) {
- $text_margin -= length($1) * ($tab_width - 1);
- }
- while (length $new)
+ if ($prefix =~ /^(\t+)/)
+ {
+ $text_margin -= length($1) * ($tab_width - 1);
+ }
+ while (length $stmt)
- if (($new =~ s/^(.{1,$text_margin})(?: |$)//)
- || ($new =~ s/^([\S]+)(?: |$)//))
+ if (($stmt =~ s/^(.{1,$text_margin})(?: |$)//)
+ || ($stmt =~ s/^([\S]+)(?: |$)//))
- $new_wrapped .= $new_wrapped ? $eol : $leading;
- $new_wrapped .= "$prefix$line";
+ $stmt_wrapped .= $stmt_wrapped ? $eol : $leading;
+ $stmt_wrapped .= "$prefix$line";
}
# Replace the old copyright statement.
}
# Replace the old copyright statement.
- s/$old_re/$new_wrapped/;
+ s/$stmt_re/$stmt_wrapped/;