update-copyright: much ado about intervals
authorJoel E. Denny <jdenny@clemson.edu>
Fri, 14 Aug 2009 05:10:08 +0000 (01:10 -0400)
committerJim Meyering <meyering@redhat.com>
Fri, 14 Aug 2009 07:47:36 +0000 (09:47 +0200)
* build-aux/update-copyright: Implement and document
UPDATE_COPYRIGHT_USE_INTERVALS to control expansion and collapse
of copyright year intervals.
Also, document UPDATE_COPYRIGHT_YEAR.
* tests/test-update-copyright.sh: Test it.

ChangeLog
build-aux/update-copyright
tests/test-update-copyright.sh

index 9d5187a..0f65202 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-08-14  Joel E. Denny  <jdenny@clemson.edu>
 
+       update-copyright: much ado about intervals
+       * build-aux/update-copyright: Implement and document
+       UPDATE_COPYRIGHT_USE_INTERVALS to control expansion and collapse
+       of copyright year intervals.
+       Also, document UPDATE_COPYRIGHT_YEAR.
+       * tests/test-update-copyright.sh: Test it.
+
        update-copyright: convert 2-digit to 4-digit years
        * build-aux/update-copyright: Implement and document.
        * tests/test-update-copyright.sh: Update.
index fb1c7d2..d8445fe 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -0777 -pi
 # Update an FSF copyright year list to include the current year.
 
-my $VERSION = '2009-08-14.02:23'; # UTC
+my $VERSION = '2009-08-14.05:03'; # UTC
 
 # Copyright (C) 2009 Free Software Foundation, Inc.
 #
@@ -92,6 +92,16 @@ my $VERSION = '2009-08-14.02:23'; # UTC
 #      within the FSF copyright statement.
 #   7. Each copyright year is 2 or 4 digits, and years are separated by
 #      commas or dashes.  Whitespace may occur after commas.
+#
+# Environment variables:
+#
+#   1. If UPDATE_COPYRIGHT_USE_INTERVALS=1, every series of consecutive
+#      copyright years (such as 90, 1991, 1992-2007, 2008) in an updated
+#      FSF copyright statement is collapsed to a single interval (such
+#      as 1990-2008).  If unset or set to 0, all existing copyright year
+#      intervals are expanded.
+#   2. For testing purposes, you can set the assumed current year in
+#      UPDATE_COPYRIGHT_YEAR.
 
 use strict;
 use warnings;
@@ -138,7 +148,7 @@ while (/(^|\n)(.{0,$prefix_max})$copyright_re/g)
     $holder_re =~ s/\s/$ws_re/g;
     my $stmt_remainder_re =
       "(?:$ws_re$circle_c_re)?"
-      . "$ws_re(?:(?:\\d\\d)?\\d\\d(,$ws_re?|-))*"
+      . "$ws_re(?:(?:\\d\\d)?\\d\\d(?:,$ws_re?|-))*"
       . "((?:\\d\\d)?\\d\\d)$ws_re$holder_re";
     if (/\G$stmt_remainder_re/)
       {
@@ -151,8 +161,7 @@ if (defined $stmt_re)
   {
     /$stmt_re/ or die; # Should never die.
     my $stmt = $1;
-    my $sep = $2 ? $2 : "";
-    my $final_year_orig = $3;
+    my $final_year_orig = $2;
 
     # Handle two-digit year numbers like "98" and "99".
     my $final_year = $final_year_orig;
@@ -162,18 +171,7 @@ if (defined $stmt_re)
     if ($final_year != $this_year)
       {
         # Update the year.
-        if ($sep eq '-' && $final_year + 1 == $this_year)
-          {
-            $stmt =~ s/$final_year_orig/$this_year/;
-          }
-        elsif ($sep ne '-' && $final_year + 1 == $this_year)
-          {
-            $stmt =~ s/$final_year_orig/$final_year-$this_year/;
-          }
-        else
-          {
-            $stmt =~ s/$final_year_orig/$final_year, $this_year/;
-          }
+        $stmt =~ s/$final_year_orig/$final_year, $this_year/;
 
         # Normalize all whitespace including newline-prefix sequences.
         $stmt =~ s/$ws_re/ /g;
@@ -184,6 +182,27 @@ if (defined $stmt_re)
         # 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})
+          {
+            $stmt =~ s/(\d{4})-(\d{4})/join(', ', $1..$2)/eg;
+          }
+        else
+          {
+            $stmt =~
+              s/
+                (\d{4})
+                (?:
+                  (,\ |-)
+                  ((??{
+                    if    ($2 eq '-') { '\d{4}'; }
+                    elsif (!$3)       { $1 + 1;  }
+                    else              { $3 + 1;  }
+                  }))
+                )+
+              /$1-$3/gx;
+          }
+
         # Format within margin.
         my $stmt_wrapped;
         my $text_margin = $margin - length($prefix);
index d0e3083..ac47b9b 100755 (executable)
@@ -107,7 +107,7 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Foundation, Inc.
 EOF
 
-UPDATE_COPYRIGHT_YEAR=2010 \
+UPDATE_COPYRIGHT_YEAR=2010 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
   update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
 compare - $TMP-stderr <<EOF || exit 1
@@ -145,6 +145,52 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc.
 EOF
 
+UPDATE_COPYRIGHT_YEAR=2011 \
+  update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare - $TMP-stderr <<EOF || exit 1
+$TMP.4: warning: FSF copyright statement not found
+$TMP.5: warning: FSF copyright statement not found
+EOF
+compare - $TMP.1 <<EOF || exit 1
+Copyright @copyright{} 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
+2011 Free Software Foundation, Inc.
+EOF
+compare - $TMP.2 <<EOF || exit 1
+# Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+# 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+# Free Software Foundation, Inc.
+EOF
+compare - $TMP.3 <<EOF || exit 1
+/*
+ * Copyright &copy; 1990, 2005, 2007, 2008, 2009, 2010, 2011 Free
+ * Software Foundation, Inc.
+ */
+EOF
+compare - $TMP.4 <<EOF || exit 1
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
+EOF
+compare - $TMP.5 <<EOF || exit 1
+Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
+EOF
+compare - $TMP.6 <<EOF || exit 1
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
+
+Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+Free Software Foundation, Inc.
+EOF
+compare - $TMP.7 <<EOF || exit 1
+Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
+
+# Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+# 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+# Free Software Foundation, Inc.
+EOF
+
 rm $TMP*
 
 ## -------------- ##
@@ -164,6 +210,13 @@ compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
 '\" Copyright (C) 2006, $YEAR Free Software Foundation, Inc.
 EOF
+UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+'\" Copyright (C) 2006, $YEAR Free Software Foundation, Inc.
+EOF
 rm $TMP*
 
 ## ------------------ ##
@@ -209,6 +262,14 @@ compare - $TMP <<EOF || exit 1
 #### 1985, 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
 #### 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
 EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+#### Copyright (C) 1976-1988, 1999-2008, 2010-2011 Free Software
+#### Foundation, Inc.
+EOF
 rm $TMP*
 
 ## ------------------- ##
@@ -286,7 +347,15 @@ compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
        Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996,
        1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-       2007, 2008, 2009-2010 Free Software Foundation, Inc.
+       2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+       Copyright (C) 1987-1988, 1991-2011 Free Software Foundation,
+       Inc.
 EOF
 rm $TMP*
 
@@ -296,7 +365,7 @@ rm $TMP*
 
 TMP=$TMP_BASE-unusual-ws
 cat > $TMP <<EOF
-               # Copyright (C) 8788, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+               # Copyright (C) 87-88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
                # 98, 1999, 2000, 2001, 2002, 2003,             \f         2004, 2005, 2006, 2007, 2008,
                # 2009 Free Software Foundation, Inc.
 EOF
@@ -307,7 +376,15 @@ compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
                # Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994,
                # 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-               # 2004, 2005, 2006, 2007, 2008, 2009-2010 Free Software
+               # 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+               # Foundation, Inc.
+EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+               # Copyright (C) 1987-1988, 1991-2011 Free Software
                # Foundation, Inc.
 EOF
 rm $TMP*
@@ -329,7 +406,7 @@ compare /dev/null $TMP-stderr || exit 1
 tr @ '\015' > $TMP-exp <<\EOF
 Rem Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,@
 Rem 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,@
-Rem 2009-2010 Free Software Foundation, Inc.@
+Rem 20092010 Free Software Foundation, Inc.@
 EOF
 compare $TMP-exp $TMP || exit 1
 rm $TMP*
@@ -350,7 +427,7 @@ compare /dev/null $TMP-stdout || exit 1
 compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
   Copyright 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-  1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009-2010
+  1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 20092010
   Free Software Foundation, Inc.
 EOF
 rm $TMP*
@@ -391,12 +468,12 @@ compare /dev/null $TMP-stderr || exit 1
 compare - $TMP.star <<EOF || exit 1
 /*  Copyright 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
  *  1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
- *  2009-2010 Free Software Foundation, Inc.  */
+ *  20092010 Free Software Foundation, Inc.  */
 EOF
 compare - $TMP.space <<EOF || exit 1
   /*Copyright 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-    2009-2010 Free Software Foundation, Inc.  */
+    20092010 Free Software Foundation, Inc.  */
 EOF
 compare - $TMP.single-line <<EOF || exit 1
 /*   Copyright 1987, 1991, 1992, 2010 Free Software Foundation, Inc.  */