X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/0b61a8ec1842bfbd6130714d06b758165b32ead4..ec6dc4375eaeb5ef358fb2a0e9082a53dcc54d87:/build-aux/update-b4-copyright?ds=sidebyside diff --git a/build-aux/update-b4-copyright b/build-aux/update-b4-copyright index 06d3cb76..5ba7dd66 100755 --- a/build-aux/update-b4-copyright +++ b/build-aux/update-b4-copyright @@ -3,8 +3,8 @@ # Update b4_copyright invocations or b4_copyright_years definitions to # include the current year. -# Copyright (C) 2009 Free Software Foundation, Inc. -# +# Copyright (C) 2009-2013 Free Software Foundation, Inc. + # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3, or (at your option) @@ -42,7 +42,7 @@ my $old_re = <<'EOF' (?: ,\s* ( - \[\s* (?:\d{4}(,\s*|-))* (\d{4}) \s*] + \[\s* (?:\d{4}(?:,\s*|-))* (\d{4}) \s*] ) )? \) @@ -54,8 +54,7 @@ while (/($old_re)/gx) my $start = pos() - length ($1); my $b4_copyright_line = $2; my $year_lines = $3; - my $sep = $4 ? $4 : ""; - my $final_year = $5; + my $final_year = $4; $year_lines .= ')'; # If there was a second argument, it contains years, so update them. @@ -65,18 +64,7 @@ while (/($old_re)/gx) if ($final_year != $this_year) { # Update the year. - if ($sep eq '-' && $final_year + 1 == $this_year) - { - $year_lines =~ s/$final_year/$this_year/; - } - elsif ($sep ne '-' && $final_year + 1 == $this_year) - { - $year_lines =~ s/$final_year/$final_year-$this_year/; - } - else - { - $year_lines =~ s/$final_year/$final_year, $this_year/; - } + $year_lines =~ s/$final_year/$final_year, $this_year/; } # Normalize all whitespace. @@ -85,6 +73,20 @@ while (/($old_re)/gx) # Put spaces after commas. $year_lines =~ s/, ?/, /g; + # Compress to intervals. + $year_lines =~ + s/ + (\d{4}) + (?: + (,\ |-) + ((??{ + if ($2 eq '-') { '\d{4}'; } + elsif (!$3) { $1 + 1; } + else { $3 + 1; } + })) + )+ + /$1-$3/gx; + # Format within margin. my $year_lines_new; my $indent = index ($b4_copyright_line, '['); @@ -117,29 +119,34 @@ while (/($old_re)/gx) while (/(\bb4_copyright\()/g) { - my $pos = pos (); - pos () -= length ($1); + my $start = pos () - length ($1); + my $end = pos (); my $re = $old_re; + pos () = $start; $re =~ s/\#BEFORE/\\G/; if (!/$re/x) { + my $line = (substr ($_, 0, $start) =~ s/\n/\n/g) + 1; print STDERR - "$ARGV: warning: failed to update a b4_copyright before char" - . " $pos\n"; + "$ARGV:$line: warning: failed to update a b4_copyright\n"; } - pos () = $pos; + pos () = $end; } -while (/\[b4_copyright_years]/g) +while (/(\[b4_copyright_years])/g) { - my $pos = pos (); + my $start = pos () - length ($1); + my $end = pos (); my $re = $old_re; $re =~ s/\#AFTER/\\G/; if (!/$re/x) { + # The substr operation blows away pos (), so restoring pos () + # at the end is necessary. + my $line = (substr ($_, 0, $start) =~ s/\n/\n/g) + 1; print STDERR - "$ARGV: warning: failed to update a b4_copyright_years before" - . " char $pos\n"; + "$ARGV:$line: warning: failed to update a" + . " b4_copyright_years\n"; } - pos () = $pos; + pos () = $end; }