maint: make update-copyright handle more cases
authorJim Meyering <meyering@redhat.com>
Wed, 29 Jul 2009 08:25:24 +0000 (10:25 +0200)
committerJim Meyering <meyering@redhat.com>
Wed, 29 Jul 2009 08:25:24 +0000 (10:25 +0200)
* build-aux/update-copyright: Handle cases in which the final
year number and copyright holder are on separate lines.
Prompted by a report from Joel E. Denny.
Also, do not invoke localtime for each line we process.

build-aux/update-copyright

index 42579c2..9039b7c 100755 (executable)
@@ -1,7 +1,7 @@
-#!/usr/bin/perl -w -pi
+#!/usr/bin/perl -0777 -pi
 # Update an FSF copyright year list to include the current year.
 
-my $VERSION = '2009-06-04 08:53'; # UTC
+my $VERSION = '2009-07-29.08:18'; # UTC
 
 # Copyright (C) 2009 Free Software Foundation
 #
@@ -21,15 +21,19 @@ my $VERSION = '2009-06-04 08:53'; # UTC
 # Written by Jim Meyering
 
 use strict;
+use warnings;
 
-my ($sec, $min, $hour, $mday, $month, $this_year) = localtime (time());
-$this_year += 1900;
-
+my $this_year;
 my $holder = 'Free Software Foundation';
 
-if (/([- ])((?:\d\d)?\d\d)\s+$holder/)
+BEGIN {
+  my ($sec, $min, $hour, $mday, $month, $year) = localtime (time());
+  $this_year = $year + 1900;
+}
+
+if (/([- ])((?:\d\d)?\d\d)(\s+$holder)/s)
   {
-    my ($sep, $last_c_year) = ($1, $2);
+    my ($sep, $last_c_year, $rest) = ($1, $2, $3);
 
     # Handle two-digit year numbers like "98" and "99".
     $last_c_year <= 99
@@ -39,15 +43,15 @@ if (/([- ])((?:\d\d)?\d\d)\s+$holder/)
       {
         if ($sep eq '-' && $last_c_year + 1 == $this_year)
           {
-            s//-$this_year $holder/;
+            s//-$this_year$rest/;
           }
         elsif ($sep eq ' ' && $last_c_year + 1 == $this_year)
           {
-            s// $last_c_year-$this_year $holder/;
+            s// $last_c_year-$this_year$rest/;
           }
         else
           {
-            s//$sep$last_c_year, $this_year $holder/;
+            s//$sep$last_c_year, $this_year$rest/;
           }
       }
   }
@@ -56,7 +60,7 @@ if (/([- ])((?:\d\d)?\d\d)\s+$holder/)
 # indent-tabs-mode: nil
 # eval: (add-hook 'write-file-hooks 'time-stamp)
 # time-stamp-start: "my $VERSION = '"
-# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-format: "%:y-%02m-%02d.%02H:%02M"
 # time-stamp-time-zone: "UTC"
 # time-stamp-end: "'; # UTC"
 # End: