changeset 11785:4b93f30470cf

update-copyright: support C-style comments * build-aux/update-copyright: Implement and document. * tests/test-update-copyright.sh: Test.
author Joel E. Denny <jdenny@clemson.edu>
date Wed, 05 Aug 2009 23:30:14 -0400
parents 72e645655421
children 51e19b43ff65
files ChangeLog build-aux/update-copyright tests/test-update-copyright.sh
diffstat 3 files changed, 102 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-08-05  Joel E. Denny  <jdenny@clemson.edu>
+
+	update-copyright: support C-style comments
+	* build-aux/update-copyright: Implement and document.
+	* tests/test-update-copyright.sh: Test.
+
 2009-08-05  Joel E. Denny  <jdenny@clemson.edu>
 
 	update-copyright: support omitted "(C)"
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -58,8 +58,8 @@
 # However, the following format is not recognized because the line
 # prefix changes after the first line:
 #
-#   /* Copyright (C) 1990-2005, 2007-2009 Free Software
-#    * Foundation, Inc.  */
+#   ## 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:
@@ -91,7 +91,12 @@
 #      5 characters.
 #   5. Iff such a prefix is present, the same prefix appears at the
 #      beginning of each remaining line within the FSF copyright
-#      statement.
+#      statement.  There is one exception in order to support C-style
+#      comments: if the first line's prefix contains nothing but
+#      whitespace surrounding a "/*", then the prefix for all subsequent
+#      lines is the same as the first line's prefix except with each of
+#      "/" and possibly "*" replaced by a " ".  The replacement of "*"
+#      by " " is consistent throughout all subsequent lines.
 #   6. Blank lines, even if preceded by the prefix, do not appear
 #      within the FSF copyright statement.
 #   7. Each copyright year is 2 or 4 digits, and years are separated by
@@ -123,8 +128,18 @@
 my $stmt_re;
 while (/(^|\n)(.{0,$prefix_max})$copyright_re/g)
   {
-    $leading = $1;
+    $leading = "$1$2";
     $prefix = $2;
+    if ($prefix =~ /^(\s*\/)\*(\s*)$/)
+      {
+        $prefix =~ s,/, ,;
+        my $prefix_ws = $prefix;
+        $prefix_ws =~ s/\*/ /; # Only whitespace.
+        if (/\G(?:[^*\n]|\*[^\/\n])*\*?\n$prefix_ws/)
+          {
+            $prefix = $prefix_ws;
+          }
+      }
     $ws_re = '[ \t\r\f]'; # \s without \n
     $ws_re =
       "(?:$ws_re*(?:$ws_re|\\n" . quotemeta($prefix) . ")$ws_re*)";
@@ -137,8 +152,7 @@
     if (/\G$stmt_remainder_re/)
       {
         $stmt_re =
-          quotemeta("$leading$prefix")
-          . "($copyright_re$stmt_remainder_re)";
+          quotemeta($leading) . "($copyright_re$stmt_remainder_re)";
         last;
       }
   }
@@ -189,8 +203,8 @@
                 || ($stmt =~ s/^([\S]+)(?: |$)//))
               {
                 my $line = $1;
-                $stmt_wrapped .= $stmt_wrapped ? $eol : $leading;
-                $stmt_wrapped .= "$prefix$line";
+                $stmt_wrapped .= $stmt_wrapped ? "$eol$prefix" : $leading;
+                $stmt_wrapped .= $line;
               }
             else
               {
--- a/tests/test-update-copyright.sh
+++ b/tests/test-update-copyright.sh
@@ -45,15 +45,15 @@
  */
 EOF
 cat > $TMP.4 <<EOF
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 EOF
 cat > $TMP.5 <<EOF
 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 EOF
 cat > $TMP.6 <<EOF
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 
 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
 Inc.
@@ -87,15 +87,15 @@
  */
 EOF
 compare - $TMP.4 <<EOF || exit 1
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## 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-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 
 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
 Inc.
@@ -127,15 +127,15 @@
  */
 EOF
 compare - $TMP.4 <<EOF || exit 1
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## 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-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 
 Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc.
 EOF
@@ -355,4 +355,66 @@
 EOF
 rm $TMP*
 
+## ------------------ ##
+## C-style comments.  ##
+## ------------------ ##
+
+TMP=$TMP_BASE-c-style-comments
+cat > $TMP.star <<EOF
+/*  Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+ *  98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ *  2009 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.space <<EOF
+  /*Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+    98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+    2009 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.single-line <<EOF
+/* Copyright 87, 88, 1991, 1992 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.single-line-wrapped <<EOF
+ /* Copyright 1988, 1991, 1992, 1993 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.extra-text-star <<EOF
+ /* Copyright 1987, 1988, 1991, 1992 Free Software Foundation, Inc.  End
+  * More comments.  */
+EOF
+cat > $TMP.extra-text-space <<EOF
+ /* Copyright 1987, 1988, 1991, 1992 Free Software Foundation, Inc. ***
+    * End of comments. */
+EOF
+UPDATE_COPYRIGHT_YEAR=2010 \
+  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.star <<EOF || exit 1
+/*  Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 98,
+ *  1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ *  2009-2010 Free Software Foundation, Inc.  */
+EOF
+compare - $TMP.space <<EOF || exit 1
+  /*Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 98,
+    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+    2009-2010 Free Software Foundation, Inc.  */
+EOF
+compare - $TMP.single-line <<EOF || exit 1
+/* Copyright 87, 88, 1991, 1992, 2010 Free Software Foundation, Inc.  */
+EOF
+compare - $TMP.single-line-wrapped <<EOF || exit 1
+ /* Copyright 1988, 1991, 1992, 1993, 2010 Free Software Foundation,
+  * Inc.  */
+EOF
+compare - $TMP.extra-text-star <<EOF || exit 1
+ /* Copyright 1987, 1988, 1991, 1992, 2010 Free Software Foundation,
+  * Inc.  End
+  * More comments.  */
+EOF
+compare - $TMP.extra-text-space <<EOF || exit 1
+ /* Copyright 1987, 1988, 1991, 1992, 2010 Free Software Foundation,
+    Inc. ***
+    * End of comments. */
+EOF
+rm $TMP*
+
 exit 0