From 1978084a56315dc7563f99b4315564be1843ecae Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Fri, 14 Aug 2009 01:10:08 -0400 Subject: [PATCH] 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. --- ChangeLog | 7 ++++ build-aux/update-copyright | 51 +++++++++++++++-------- tests/test-update-copyright.sh | 93 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 127 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d5187a0d..0f652025c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-08-14 Joel E. Denny + 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. diff --git a/build-aux/update-copyright b/build-aux/update-copyright index fb1c7d2b7..d8445fee0 100755 --- a/build-aux/update-copyright +++ b/build-aux/update-copyright @@ -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); diff --git a/tests/test-update-copyright.sh b/tests/test-update-copyright.sh index d0e30833d..ac47b9be9 100755 --- a/tests/test-update-copyright.sh +++ b/tests/test-update-copyright.sh @@ -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 < $TMP-stdout 2> $TMP-stderr +compare /dev/null $TMP-stdout || exit 1 +compare - $TMP-stderr < $TMP-stdout 2> $TMP-stderr +compare /dev/null $TMP-stdout || exit 1 +compare /dev/null $TMP-stderr || exit 1 +compare - $TMP < $TMP-stdout 2> $TMP-stderr +compare /dev/null $TMP-stdout || exit 1 +compare /dev/null $TMP-stderr || exit 1 +compare - $TMP < $TMP-stdout 2> $TMP-stderr +compare /dev/null $TMP-stdout || exit 1 +compare /dev/null $TMP-stderr || exit 1 +compare - $TMP < $TMP < $TMP-stdout 2> $TMP-stderr +compare /dev/null $TMP-stdout || exit 1 +compare /dev/null $TMP-stderr || exit 1 +compare - $TMP < $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 2009, 2010 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 <