#!/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.
#
# 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;
$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/)
{
{
/$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;
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;
# 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);
# 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
# 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 © 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*
## -------------- ##
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*
## ------------------ ##
#### 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*
## ------------------- ##
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*
TMP=$TMP_BASE-unusual-ws
cat > $TMP <<EOF
- # Copyright (C) 87, 88, 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
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*
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 2009, 2010 Free Software Foundation, Inc.@
EOF
compare $TMP-exp $TMP || exit 1
rm $TMP*
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, 2009, 2010
Free Software Foundation, Inc.
EOF
rm $TMP*
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. */
+ * 2009, 2010 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. */
+ 2009, 2010 Free Software Foundation, Inc. */
EOF
compare - $TMP.single-line <<EOF || exit 1
/* Copyright 1987, 1991, 1992, 2010 Free Software Foundation, Inc. */