On Tue, 4 Aug 2009, Karl Berry wrote: > 5. Inconsistent line prefix. In many cases, it's a C-style comment such > that "/*" appears only on the first line. In some cases, it's just > inconsistent indentation. > > For better or worse, it's very common to have /* or just * preceding the > copyright line ...
Here's a patch that offers some support for C-style comments. >From 071e76b3e8d7890f8c62881539153c0bdcb2487a Mon Sep 17 00:00:00 2001 From: Joel E. Denny <jde...@clemson.edu> Date: Wed, 5 Aug 2009 23:30:14 -0400 Subject: [PATCH] update-copyright: support C-style comments * build-aux/update-copyright: Implement and document. * tests/test-update-copyright.sh: Test. --- ChangeLog | 6 +++ build-aux/update-copyright | 30 ++++++++++---- tests/test-update-copyright.sh | 86 ++++++++++++++++++++++++++++++++++------ 3 files changed, 102 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 602f69d..c5a6a10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-08-05 Joel E. Denny <jde...@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 <jde...@clemson.edu> + update-copyright: support omitted "(C)" * build-aux/update-copyright: Implement and document. Also, allow variable whitespace before "(C)". diff --git a/build-aux/update-copyright b/build-aux/update-copyright index b124bb9..bbd2a04 100755 --- a/build-aux/update-copyright +++ b/build-aux/update-copyright @@ -58,8 +58,8 @@ my $VERSION = '2009-08-06.01:08'; # UTC # 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 @@ my $VERSION = '2009-08-06.01:08'; # UTC # 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 $ws_re; 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 @@ while (/(^|\n)(.{0,$prefix_max})$copyright_re/g) 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 @@ if (defined $stmt_re) || ($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 { diff --git a/tests/test-update-copyright.sh b/tests/test-update-copyright.sh index 69dadbf..9997df4 100755 --- a/tests/test-update-copyright.sh +++ b/tests/test-update-copyright.sh @@ -45,15 +45,15 @@ cat > $TMP.3 <<EOF */ 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 @@ compare - $TMP.3 <<EOF || exit 1 */ 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 @@ compare - $TMP.3 <<EOF || exit 1 */ 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 @@ compare - $TMP <<EOF || exit 1 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 -- 1.5.4.3