]>
git.saurik.com Git - bison.git/blob - build-aux/update-b4-copyright
1 #!/usr/bin/perl -0777 -pi
2 # Update an b4_copyright invocation to include the current year.
4 # Copyright (C) 2009 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 my $this_year = $ENV{UPDATE_COPYRIGHT_YEAR
};
23 if (!$this_year || $this_year !~ m/^\d\d(\d\d)?$/)
25 my ($sec, $min, $hour, $mday, $month, $year) = localtime (time ());
26 $this_year = $year + 1900;
33 b4_copyright\(\[[^]]*]
34 | m4_(?:push|pop)def\(\[b4_copyright_years]
40 \[\s* (?:\d{4}(,\s*|-))* (\d{4}) \s*]
49 my $b4_copyright_line = $1;
51 my $sep = $3 ? $3 : "";
56 $b4_copyright_line =~ s/b4_/b4*/g;
58 # If there was a second argument, it contains years, so update them.
61 $b4_copyright_line .= ',';
62 if ($final_year != $this_year)
65 if ($sep eq '-' && $final_year + 1 == $this_year)
67 $year_lines =~ s/$final_year/$this_year/;
69 elsif ($sep ne '-' && $final_year + 1 == $this_year)
71 $year_lines =~ s/$final_year/$final_year-$this_year/;
75 $year_lines =~ s/$final_year/$final_year, $this_year/;
79 # Normalize all whitespace.
80 $year_lines =~ s/\s+/ /g;
82 # Put spaces after commas.
83 $year_lines =~ s/, ?/, /g;
85 # Format within margin.
87 my $indent = index ($b4_copyright_line, '[');
88 --$indent if ($b4_copyright_line =~ m/^\n/);
89 while (length $year_lines)
91 my $text_margin = $margin - $indent;
92 if (($year_lines =~ s/^(.{1,$text_margin})(?: |$)//)
93 || ($year_lines =~ s/^([\S]+)(?: |$)//))
95 my $line = "\n" . (' 'x
$indent) . $1;
96 ++$indent if (!$year_lines_new);
97 $year_lines_new .= $line;
101 # Should be unreachable, but we don't want an infinite
102 # loop if it can be reached.
106 $year_lines = $year_lines_new;
109 # Replace the old invocation.
110 s/$old_re/$b4_copyright_line$year_lines/x;
113 if (/\bb4_copyright\(/)
116 "$ARGV: warning: failed to update a b4_copyright invocation\n";
118 if (/\[b4_copyright_years]/)
121 "$ARGV: warning: failed to update a b4_copyright_years use\n";
124 s/b4\*copyright/b4_copyright/g;