Re: new module: update-copyright [Re: copyright years: mass-update every January 1

2009-08-12 Thread Akim Demaille


Le 31 juil. 09 à 15:52, Joel E. Denny a écrit :

Hi Joel,


+# Format within margin.
+my $new_wrapped;
+my $text_margin = $margin - length($prefix);
+while (length($new))
+  {
+if (($new =~ s/^(.{1,$text_margin})(?: |$)//)
+|| ($new =~ s/^([\S]+)(?: |$)//))
+  {
+my $line = $1;
+$new_wrapped .= $new_wrapped ? "\n" : $leading;
+$new_wrapped .= "$prefix$line";
+  }
+else
+  {
+# Should be unreachable, but we don't want an  
infinite

+# loop if it can be reached.
+die;
+  }
+  }


You might want to have a look at Text::Wrap.



Re: new module: update-copyright [Re: copyright years: mass-update every January 1

2009-07-31 Thread Joel E. Denny
On Thu, 30 Jul 2009, Joel E. Denny wrote:

> On Thu, 30 Jul 2009, Jim Meyering wrote:

> > There remains at least one infelicity: if someone discusses
> > the Copyright (C) notation (e.g., as on this line), and later
> > has the copyright-with-dates line, the prefixes may not match.
> > We could require that the Copyright...holder (and hence prefix)
> > are all in proximity, but that may not be worth the trouble.

In the first patch below, I ended up documenting that limitation instead 
of fixing it.  It should be very straightforward to add a proximity check 
in the initial search for the copyright.  However, I haven't yet found a 
real-world test case, so I'm waiting.  For now, the worst case is that an 
affected file just won't be updated, and we'll be warned.

> The current behavior is a little unintuitive in other similar ways as 
> well.  For example, if "Copyright (C)" isn't recognized anywhere and thus 
> no comment sequence is recognized, the script still looks for an 
> occurrence of the copyright year and holder to adjust.  Thus, the script 
> handles "Copyright @copyright{}" only when it's not in comments.  I'd 
> rather it be consistent by not handling it at all or handling it 
> completely.

Also, it bothered me that 2009 might be added to the phrase " 98 Free 
Software Foundation", for example, even if it had nothing to do with a 
copyright statement.  I've fixed this in the first patch below.

> I'm working on a patch to fix all of the above and to automatically format 
> the result to 72 columns.  I'll try to post a patch soon.

I've also implemented reformatting in the first patch.

In the next two patches below, I've added handling for DOS EOLs and for 
leading tabs in, for example, ChangeLogs.  These are helpful in Bison, at 
least.

>From 2727188acb1f45b83f5072bfdac740715c78444c Mon Sep 17 00:00:00 2001
From: Joel E. Denny 
Date: Fri, 31 Jul 2009 09:11:53 -0400
Subject: [PATCH] update-copyright: automatically format copyright statements

* build-aux/update-copyright: Implement that.
Also, be a little more predictable and safer by always failing
when the full copyright format is not perfectly recognized as an
unbroken whole.  Discussed at
.
Rewrite documentation.
---
 ChangeLog  |   10 +++
 build-aux/update-copyright |  160 +---
 2 files changed, 130 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 239faa6..a9e8cfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-07-31  Joel E. Denny  
+
+   update-copyright: automatically format copyright statements
+   * build-aux/update-copyright: Implement that.
+   Also, be a little more predictable and safer by always failing
+   when the full copyright format is not perfectly recognized as an
+   unbroken whole.  Discussed at
+   .
+   Rewrite documentation.
+
 2009-07-29  Matt Kraai  
 
getloadavg: check whether n_name is a pointer, for QNX 6.4.1
diff --git a/build-aux/update-copyright b/build-aux/update-copyright
index e35d51b..59ce6b6 100755
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -0777 -pi
 # Update an FSF copyright year list to include the current year.
 
-my $VERSION = '2009-07-30.13:24'; # UTC
+my $VERSION = '2009-07-31.12:44'; # UTC
 
 # Copyright (C) 2009 Free Software Foundation
 #
@@ -20,63 +20,114 @@ my $VERSION = '2009-07-30.13:24'; # 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.
+# The arguments to this script should be names of files that contain FSF
+# copyright statements to be updated.  For example, you may wish to
+# place a target like the following in your top-level makefile in your
+# project:
 #
-# For example, these are fine:
+#   .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
+#
+# In the second grep, you can build a list of files to skip within your
+# project.
+#
+# Iff an FSF copyright statement is discovered in a file and the final
+# year is not the current year, the statement is updated for the new
+# year and reformatted to fit within 72 columns.  A warning is printed
+# for every file for which no FSF copyright statement is discovered.
+#
+# Each file's FSF copy

Re: new module: update-copyright [Re: copyright years: mass-update every January 1

2009-07-30 Thread Joel E. Denny
On Thu, 30 Jul 2009, Jim Meyering wrote:

> Thank you!

Thank you.  :)

> Here's an incremental change I'm about to fold into yours.
> It changes "comment" to "prefix" and adjusts syntax.

Makes sense.

> There remains at least one infelicity: if someone discusses
> the Copyright (C) notation (e.g., as on this line), and later
> has the copyright-with-dates line, the prefixes may not match.
> We could require that the Copyright...holder (and hence prefix)
> are all in proximity, but that may not be worth the trouble.

The current behavior is a little unintuitive in other similar ways as 
well.  For example, if "Copyright (C)" isn't recognized anywhere and thus 
no comment sequence is recognized, the script still looks for an 
occurrence of the copyright year and holder to adjust.  Thus, the script 
handles "Copyright @copyright{}" only when it's not in comments.  I'd 
rather it be consistent by not handling it at all or handling it 
completely.

I'm working on a patch to fix all of the above and to automatically format 
the result to 72 columns.  I'll try to post a patch soon.



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: new module: update-copyright [Re: copyright years: mass-update every January 1

2009-07-30 Thread Jim Meyering
Joel E. Denny wrote:

> On Wed, 29 Jul 2009, Jim Meyering wrote:
>
>> Joel E. Denny wrote:
>>
>> > On Wed, 29 Jul 2009, Jim Meyering wrote:
>> >
>> >> Joel E. Denny wrote:
>> >
>> >> > I'd like to use this in Bison.  Would you consider contributing
>> >> > build-aux/update-copyright to gnulib so we don't maintain separate 
>> >> > copies?
>> >>
>> >> Sure.
>> >
>> > Thanks.  I'll watch for that.  In the meantime, I'll probably import a
>> > copy into Bison.
>>
>> I've just pushed it to gnulib:
>
> Thanks.  I didn't notice this before I posted that last patch to
> bug-coreutils:
>
>   http://lists.gnu.org/archive/html/bug-coreutils/2009-07/msg00213.html
>
> Here it is again, rewritten for gnulib.  I've also made some improvements
> to the documentation.

Thank you!

Here's an incremental change I'm about to fold into yours.
It changes "comment" to "prefix" and adjusts syntax.

There remains at least one infelicity: if someone discusses
the Copyright (C) notation (e.g., as on this line), and later
has the copyright-with-dates line, the prefixes may not match.
We could require that the Copyright...holder (and hence prefix)
are all in proximity, but that may not be worth the trouble.

diff --git a/build-aux/update-copyright b/build-aux/update-copyright
index c4419b5..e35d51b 100755
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -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.19:13'; # UTC
+my $VERSION = '2009-07-30.13:24'; # UTC

 # Copyright (C) 2009 Free Software Foundation
 #
@@ -22,10 +22,10 @@ my $VERSION = '2009-07-29.19:13'; # UTC

 # 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
-# comment sequence of no more than 5 characters.  Iff that comment
-# sequence is present, the same comment sequence should appear at the
-# beginning of each remaining line within the copyright statement so
-# that it can be parsed correctly.
+# 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:
 #
@@ -52,11 +52,11 @@ my $VERSION = '2009-07-29.19:13'; # UTC
 #
 #   .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
+#   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.

@@ -67,12 +67,12 @@ my ($sec, $min, $hour, $mday, $month, $year) = localtime 
(time());
 my $this_year = $year + 1900;
 my $holder = 'Free Software Foundation';

-my $comment = "";
+my $prefix = '';
 if (/(?:^|\n)(.{0,5})Copyright \([cC]\)/) {
-  $comment = quotemeta($1);
+  $prefix = quotemeta $1;
 }
 $holder = " $holder";
-$holder =~ s/\s/\\s*(?:\\s|\\n$comment)\\s*/g;
+$holder =~ s/\s/\\s*(?:\\s|\\n$prefix)\\s*/g;

 if (/([- ])((?:\d\d)?\d\d)($holder)/s)
   {


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: new module: update-copyright [Re: copyright years: mass-update every January 1

2009-07-29 Thread Joel E. Denny
On Wed, 29 Jul 2009, Jim Meyering wrote:

> Joel E. Denny wrote:
> 
> > On Wed, 29 Jul 2009, Jim Meyering wrote:
> >
> >> Joel E. Denny wrote:
> >
> >> > I'd like to use this in Bison.  Would you consider contributing
> >> > build-aux/update-copyright to gnulib so we don't maintain separate 
> >> > copies?
> >>
> >> Sure.
> >
> > Thanks.  I'll watch for that.  In the meantime, I'll probably import a
> > copy into Bison.
> 
> I've just pushed it to gnulib:

Thanks.  I didn't notice this before I posted that last patch to 
bug-coreutils:

  http://lists.gnu.org/archive/html/bug-coreutils/2009-07/msg00213.html

Here it is again, rewritten for gnulib.  I've also made some improvements 
to the documentation.

>From 009b660dd28dfbb2b289b367d243d08d7ef01588 Mon Sep 17 00:00:00 2001
From: Joel E. Denny 
Date: Wed, 29 Jul 2009 15:17:53 -0400
Subject: [PATCH] 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.
---
 ChangeLog  |8 ++
 build-aux/update-copyright |   56 ++-
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9c386f5..5f1c812 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-07-29  Joel E. Denny  
+
+   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  
 
mktime: correct setting of REPLACE_MKTIME
diff --git a/build-aux/update-copyright b/build-aux/update-copyright
index 1ceaf8a..c4419b5 100755
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -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-29.19:13'; # 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
+# comment sequence of no more than 5 characters.  Iff that comment
+# sequence is present, the same comment sequence 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 $comment = "";
+if (/(?:^|\n)(.{0,5})Copyright \([cC]\)/) {
+  $comment = quotemeta($1);
+}
+$holder = " $holder";
+$holder =~ s/\s/\\s*(?:\\s|\\n$comment)\\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
-- 
1.5.4.3



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


new module: update-copyright [Re: copyright years: mass-update every January 1

2009-07-29 Thread Jim Meyering
Joel E. Denny wrote:

> On Wed, 29 Jul 2009, Jim Meyering wrote:
>
>> Joel E. Denny wrote:
>
>> > I'd like to use this in Bison.  Would you consider contributing
>> > build-aux/update-copyright to gnulib so we don't maintain separate copies?
>>
>> Sure.
>
> Thanks.  I'll watch for that.  In the meantime, I'll probably import a
> copy into Bison.

I've just pushed it to gnulib:

>From 8dc0e5d63e272095754e3144e64dc6b1c8791d9e Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Wed, 29 Jul 2009 16:22:21 +0200
Subject: [PATCH] update-copyright: new module

* modules/update-copyright: New file.
* build-aux/update-copyright: New file.
* MODULES.html.sh (maint+release support): Add update-copyright.
---
 ChangeLog  |7 +
 MODULES.html.sh|1 +
 build-aux/update-copyright |   62 
 modules/update-copyright   |   19 +
 4 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100755 build-aux/update-copyright
 create mode 100644 modules/update-copyright

diff --git a/ChangeLog b/ChangeLog
index fa9a76b..2be276a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-29  Jim Meyering  
+
+   update-copyright: new module
+   * modules/update-copyright: New file.
+   * build-aux/update-copyright: New file.
+   * MODULES.html.sh (maint+release support): Add update-copyright.
+
 2009-07-27  Bruno Haible  

Fix compilation error when  is used and mktime is replaced.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 6adef20..ef48ec5 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -3179,6 +3179,7 @@ func_all_modules ()
   func_module gnupload
   func_module maintainer-makefile
   func_module mktempd
+  func_module update-copyright
   func_module useless-if-before-free
   func_module vc-list-files
   func_end_table
diff --git a/build-aux/update-copyright b/build-aux/update-copyright
new file mode 100755
index 000..1ceaf8a
--- /dev/null
+++ b/build-aux/update-copyright
@@ -0,0 +1,62 @@
+#!/usr/bin/perl -0777 -pi
+# Update an FSF copyright year list to include the current year.
+
+my $VERSION = '2009-07-29.13:34'; # UTC
+
+# Copyright (C) 2009 Free Software Foundation
+#
+# 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
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# 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 .
+
+# Written by Jim Meyering
+
+use strict;
+use warnings;
+
+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 ($sep, $last_c_year, $rest) = ($1, $2, $3);
+
+# Handle two-digit year numbers like "98" and "99".
+$last_c_year <= 99
+  and $last_c_year += 1900;
+
+if ($last_c_year != $this_year)
+  {
+if ($sep eq '-' && $last_c_year + 1 == $this_year)
+  {
+s//-$this_year$rest/;
+  }
+elsif ($sep eq ' ' && $last_c_year + 1 == $this_year)
+  {
+s// $last_c_year-$this_year$rest/;
+  }
+else
+  {
+s//$sep$last_c_year, $this_year$rest/;
+  }
+  }
+  }
+
+# Local variables:
+# indent-tabs-mode: nil
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "my $VERSION = '"
+# time-stamp-format: "%:y-%02m-%02d.%02H:%02M"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "'; # UTC"
+# End:
diff --git a/modules/update-copyright b/modules/update-copyright
new file mode 100644
index 000..c703c68
--- /dev/null
+++ b/modules/update-copyright
@@ -0,0 +1,19 @@
+Description:
+Update an FSF copyright year list to include the current year.
+
+Files:
+build-aux/update-copyright
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+
+License:
+GPLed build tool
+
+Maintainer:
+Jim Meyering
--
1.6.4.rc3.201.gd9d59


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils