update to modern debian/copyright format
[debian/gzip] / build-aux / update-copyright
index 28ff44180e75e8a305c4edee0bf1d9e7755d2370..f2fc97e368f05f062e2616fb3c7d6e2f6a4cd732 100755 (executable)
@@ -1,11 +1,11 @@
-eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" ${1+"$@"}'
+eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" "$@"'
   & eval 'exec perl -wS -0777 -pi "$0" $argv:q'
     if 0;
 # Update an FSF copyright year list to include the current year.
 
-my $VERSION = '2009-12-28.11:09'; # UTC
+my $VERSION = '2018-03-07.03:47'; # UTC
 
-# Copyright (C) 2009-2010 Free Software Foundation, Inc.
+# Copyright (C) 2009-2018 Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -18,16 +18,20 @@ my $VERSION = '2009-12-28.11:09'; # UTC
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 # Written by Jim Meyering and Joel E. Denny
 
-# The arguments to this script should be names of files that contain FSF
-# copyright statements to be updated.  For example, you might wish to
-# use the update-copyright target rule in maint.mk from gnulib's
-# maintainer-makefile module.
+# The arguments to this script should be names of files that contain
+# copyright statements to be updated.  The copyright holder's name
+# defaults to "Free Software Foundation, Inc." but may be changed to
+# any other name by using the "UPDATE_COPYRIGHT_HOLDER" environment
+# variable.
 #
-# Iff an FSF copyright statement is recognized in a file and the final
+# For example, you might wish to use the update-copyright target rule
+# in maint.mk from gnulib's maintainer-makefile module.
+#
+# Iff a copyright statement is recognized in a file and the final
 # year is not the current year, then the statement is updated for the
 # new year and it is reformatted to:
 #
@@ -36,10 +40,10 @@ my $VERSION = '2009-12-28.11:09'; # UTC
 #   3. Expand copyright year intervals.  (See "Environment variables"
 #      below.)
 #
-# A warning is printed for every file for which no FSF copyright
+# A warning is printed for every file for which no copyright
 # statement is recognized.
 #
-# Each file's FSF copyright statement must be formated correctly in
+# Each file's copyright statement must be formatted correctly in
 # order to be recognized.  For example, each of these is fine:
 #
 #   Copyright @copyright{} 1990-2005, 2007-2009 Free Software
@@ -59,23 +63,17 @@ my $VERSION = '2009-12-28.11:09'; # UTC
 #   ## Copyright (C) 1990-2005, 2007-2009 Free Software
 #   #  Foundation, Inc.
 #
-# The following copyright statement is not recognized because the
-# copyright holder is not the FSF:
-#
-#   Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
+# However, any correctly formatted copyright statement following
+# a non-matching copyright statements would be recognized.
 #
-# However, any correctly formatted FSF copyright statement following
-# either of the previous two copyright statements would be recognized.
-#
-# The exact conditions that a file's FSF copyright statement must meet
+# The exact conditions that a file's copyright statement must meet
 # to be recognized are:
 #
-#   1. It is the first FSF copyright statement that meets all of the
-#      following conditions.  Subsequent FSF copyright statements are
+#   1. It is the first copyright statement that meets all of the
+#      following conditions.  Subsequent copyright statements are
 #      ignored.
 #   2. Its format is "Copyright (C)", then a list of copyright years,
-#      and then the name of the copyright holder, which is "Free
-#      Software Foundation, Inc.".
+#      and then the name of the copyright holder.
 #   3. The "(C)" takes one of the following forms or is omitted
 #      entirely:
 #
@@ -83,10 +81,11 @@ my $VERSION = '2009-12-28.11:09'; # UTC
 #        B. (c)
 #        C. @copyright{}
 #        D. &copy;
+#        E. ©
 #
-#   4. The "Copyright" appears at the beginning of a line except that it
+#   4. The "Copyright" appears at the beginning of a line, except that it
 #      may be prefixed by any sequence (e.g., a comment) of no more than
-#      5 characters.
+#      5 characters -- including white space.
 #   5. Iff such a prefix is present, the same prefix appears at the
 #      beginning of each remaining line within the FSF copyright
 #      statement.  There is one exception in order to support C-style
@@ -112,17 +111,23 @@ my $VERSION = '2009-12-28.11:09'; # UTC
 #      interval (such as 1990-2008).  If unset or set to 0, all existing
 #      copyright year intervals in a reformatted FSF copyright statement
 #      are expanded instead.
+#      If UPDATE_COPYRIGHT_USE_INTERVALS=2, convert a sequence with gaps
+#      to the minimal containing range.  For example, convert
+#      2000, 2004-2007, 2009 to 2000-2009.
 #   3. For testing purposes, you can set the assumed current year in
 #      UPDATE_COPYRIGHT_YEAR.
 #   4. The default maximum line length for a copyright line is 72.
 #      Set UPDATE_COPYRIGHT_MAX_LINE_LENGTH to use a different length.
+#   5. Set UPDATE_COPYRIGHT_HOLDER if the copyright holder is other
+#      than "Free Software Foundation, Inc.".
 
 use strict;
 use warnings;
 
 my $copyright_re = 'Copyright';
-my $circle_c_re = '(?:\([cC]\)|@copyright{}|&copy;)';
-my $holder = 'Free Software Foundation, Inc.';
+my $circle_c_re = '(?:\([cC]\)|@copyright\{}|\\\\\(co|&copy;|©)';
+my $holder = $ENV{UPDATE_COPYRIGHT_HOLDER};
+$holder ||= 'Free Software Foundation, Inc.';
 my $prefix_max = 5;
 my $margin = $ENV{UPDATE_COPYRIGHT_MAX_LINE_LENGTH};
 !$margin || $margin !~ m/^\d+$/
@@ -188,7 +193,7 @@ if (defined $stmt_re)
     if ($final_year != $this_year)
       {
         # Update the year.
-        $stmt =~ s/$final_year_orig/$final_year, $this_year/;
+        $stmt =~ s/\b$final_year_orig\b/$final_year, $this_year/;
       }
     if ($final_year != $this_year || $ENV{'UPDATE_COPYRIGHT_FORCE'})
       {
@@ -220,6 +225,10 @@ if (defined $stmt_re)
                   }))
                 )+
               /$1-$3/gx;
+
+            # When it's 2, emit a single range encompassing all year numbers.
+            $ENV{UPDATE_COPYRIGHT_USE_INTERVALS} == 2
+              and $stmt =~ s/\b(\d{4})\b.*\b(\d{4})\b/$1-$2/;
           }
 
         # Format within margin.
@@ -252,15 +261,17 @@ if (defined $stmt_re)
   }
 else
   {
-    print STDERR "$ARGV: warning: FSF copyright statement not found\n";
+    print STDERR "$ARGV: warning: copyright statement not found\n";
   }
 
+# Hey Emacs!
 # Local variables:
+# coding: utf-8
 # mode: perl
 # indent-tabs-mode: nil
-# eval: (add-hook 'write-file-hooks 'time-stamp)
+# eval: (add-hook 'before-save-hook 'time-stamp)
 # time-stamp-start: "my $VERSION = '"
 # time-stamp-format: "%:y-%02m-%02d.%02H:%02M"
-# time-stamp-time-zone: "UTC"
+# time-stamp-time-zone: "UTC0"
 # time-stamp-end: "'; # UTC"
 # End: