Folks,

I noticed that src/tools/copyright looks like it can only be run on
Bruce's machine, so this translation to Perl is intended:

1.  To make the script idempotent, which allows its safe use in
automated tools that might run it many times.

2.  To get the script to run on any machine a PostgreSQL developer
would be using, as Perl is already required.

3.  To make the script more efficient.  As the copyright notice we
need to munge only appears once per file, it stops once it has made a
substitution.

Please find attached a patch implementing same.

Cheers,
David.
-- 
David Fetter <da...@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fet...@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
diff --git a/src/tools/copyright b/src/tools/copyright
deleted file mode 100755
index b0d61e1..0000000
--- a/src/tools/copyright
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# src/tools/copyright
-
-echo "Using current year:  `date '+%Y'`"
-
-rgrep -l 'Copyright.*PostgreSQL Global Development Group' | while read FILE
-do
-       pipe sed 's/^\(.*Copyright (c) [12][0-9][0-9][0-9]\) \?- 
\?[12][0-9][0-9][0-9] \?,\?\( PostgreSQL Global Development 
Group.*\)$/\1-'`date '+%Y'`',\2/' $FILE
-       # handle cases where only one year appears
-       pipe sed 's/^\(.*Copyright (c) [12][0-9][0-9][0-9]\) \?,\?\( PostgreSQL 
Global Development Group.*\)$/\1-'`date '+%Y'`',\2/' $FILE
-done
-
-echo "Manually update doc/src/sgml/legal.sgml and 
src/interfaces/libpq/libpq.rc.in too" 1>&2
diff --git a/src/tools/copyright.pl b/src/tools/copyright.pl
new file mode 100755
index 0000000..d981911
--- /dev/null
+++ b/src/tools/copyright.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/perl 
+#################################################################
+# copyright.pl -- update copyright notices throughout the source tree, 
idempotently.
+#
+# Copyright (c) 2011, PostgreSQL Global Development Group
+#
+# src/tools/copyright.pl
+#################################################################
+
+use strict;
+use warnings;
+
+use File::Find;
+
+my $pgdg = 'PostgreSQL Global Development Group';
+my $cc = 'Copyright (c) ';
+# year-1900 is what localtime(time) puts in element 5
+my $year = 1900+${[localtime(time)]}[5];
+
+print "Using current year:  $year\n";
+
+find({wanted => \&wanted, no_chdir => 1}, '.');
+
+sub wanted {
+    return unless -f $File::Find::name;
+
+    my @lines;
+    tie @lines, Tie::File, $File::Find::name;
+
+    foreach my $line (@lines) {
+        # We only care about lines with a copyright notice.
+        next unless $line =~ m/$cc.*$pgdg/;
+        # We stop when we've done one substitution.  This is both for
+        # efficiency and, at least in the case of this program, for
+        # correctness.
+        last if $line =~ m/$cc.*$year.*$pgdg/;
+        last if $line =~ s/($cc\d{4})(, $pgdg)/$1-$year$2/;
+        last if $line =~ s/($cc\d{4})-\d{4}(, $pgdg)/$1-$year$2/;
+    }
+    untie @lines;
+}
+print "Manually update doc/src/sgml/legal.sgml and 
src/interfaces/libpq/libpq.rc.in too\n";
+
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to