update-copyright: generalize comment handling
authorJoel E. Denny <jdenny@clemson.edu>
Wed, 29 Jul 2009 19:17:53 +0000 (15:17 -0400)
committerJim Meyering <meyering@redhat.com>
Thu, 30 Jul 2009 14:35:17 +0000 (16:35 +0200)
* build-aux/update-copyright: Handle copyright statements
within more comment styles.
Document usage.
Report any file with an external copyright holder or parse failure.

ChangeLog
build-aux/update-copyright

index 9c386f5..5f1c812 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-07-29  Joel E. Denny  <jdenny@clemson.edu>
+
+       update-copyright: generalize comment handling
+       * build-aux/update-copyright: Handle copyright statements
+       within more comment styles.
+       Document usage.
+       Report any file with an external copyright holder or parse failure.
+
 2009-07-29  Jim Meyering  <meyering@redhat.com>
 
        mktime: correct setting of REPLACE_MKTIME
index 1ceaf8a..e35d51b 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-07-29.13:34'; # UTC
+my $VERSION = '2009-07-30.13:24'; # UTC
 
 # Copyright (C) 2009 Free Software Foundation
 #
@@ -20,6 +20,46 @@ my $VERSION = '2009-07-29.13:34'; # UTC
 
 # Written by Jim Meyering
 
+# In the copyright statement in each file, "Copyright (C)" must appear
+# at the beginning of the line except that it may be preceded by any
+# sequence (e.g., a comment) of no more than 5 characters.  Iff that
+# prefix is present, the same prefix should appear at the beginning
+# of each remaining line within the copyright statement so that it
+# can be parsed correctly.
+#
+# For example, these are fine:
+#
+#   # Copyright (C) 1990-2005, 2007-2009 Free Software
+#   # Foundation, Inc.
+#
+#   /*
+#    * Copyright (C) 1990-2005, 2007-2009 Free Software
+#    * Foundation, Inc.
+#    */
+#
+# The following format is not recognized:
+#
+#   /* Copyright (C) 1990-2005, 2007-2009 Free Software
+#    * Foundation, Inc.  */
+#
+# A warning is printed for every file for which the copyright format is
+# not recognized.  The culprit may be that the above preconditions are
+# not obeyed as in the previous example, or it may simply be that the
+# stated copyright holder is not the Free Software Foundation.
+#
+# You may wish to place a target like the following in your top-level
+# makefile in your project:
+#
+#   .PHONY: update-copyright
+#   update-copyright:
+#       if test -d .git; then                                   \
+#         git grep -l -w Copyright                              \
+#           | grep -v -E '(^|/)(COPYING|ChangeLog)'             \
+#           | xargs $(srcdir)/build-aux/$@;                     \
+#       fi
+#
+# You can build a list of files to skip in the second grep.
+
 use strict;
 use warnings;
 
@@ -27,7 +67,14 @@ my ($sec, $min, $hour, $mday, $month, $year) = localtime (time());
 my $this_year = $year + 1900;
 my $holder = 'Free Software Foundation';
 
-if (/([- ])((?:\d\d)?\d\d)((?:\n\#)?\s+$holder)/s)
+my $prefix = '';
+if (/(?:^|\n)(.{0,5})Copyright \([cC]\)/) {
+  $prefix = quotemeta $1;
+}
+$holder = " $holder";
+$holder =~ s/\s/\\s*(?:\\s|\\n$prefix)\\s*/g;
+
+if (/([- ])((?:\d\d)?\d\d)($holder)/s)
   {
     my ($sep, $last_c_year, $rest) = ($1, $2, $3);
 
@@ -51,6 +98,11 @@ if (/([- ])((?:\d\d)?\d\d)((?:\n\#)?\s+$holder)/s)
           }
       }
   }
+else
+  {
+    print STDERR
+      "$ARGV: warning: external copyright holder or parse failure\n";
+  }
 
 # Local variables:
 # indent-tabs-mode: nil