diff: CVSROOT/check.pl: check copyright dates

Fergus Henderson fjh at cs.mu.oz.au
Sun Jul 27 20:08:56 AEST 1997


Hi,

Here's a partial solution to the problem of copyright messages becoming
out-of-date.

CVSROOT/check.pl:
	Check that files in the `mercury' sub-hierarchy
	have copyright notices which specify the current year.

Comments?

Index: check.pl
===================================================================
RCS file: /home/staff/zs/imp/CVSROOT/check.pl,v
retrieving revision 1.3
diff -u -r1.3 check.pl
--- check.pl	1997/07/11 09:10:51	1.3
+++ check.pl	1997/07/27 10:07:15
@@ -1,4 +1,4 @@
-#!/usr/local/bin/perl
+#!/usr/local/bin/perl -w
 
 # check.pl does a simple check of group-id of the files, and the group
 # read bit. If all is okay, it succeeds, otherwise it fails.
@@ -7,25 +7,39 @@
 
 # we want the files to have group mercury, which has group_id 62
 
-$wanted_group = mercury;
+$wanted_group = 'mercury';
 $wanted_group_id = 62;
 
+# we want them to have a copyright message that specifies the current year
+
+($_sec,$_min,$_hour,$_mday,$_mon,$year,$_wday,$_yday,$_isdst) = localtime;
+if ($year < 100) {
+	# sheesh, how come the year doesn't include a century?
+	if ($year < 97) {
+		# assume 21st century
+		$year = 2000 + $year;
+	} else {
+		# assume 20th century
+		$year = 1900 + $year;
+	}
+}
+
 #-----------------------------------------------------------------------------#
 
 $retval = 0;
 
 # the first argument is the CVS directory
-$directory = @ARGV[0];
+$directory = $ARGV[0];
 shift @ARGV;
 
 # the remaining arguments are files being committed
+FILE:
 foreach $arg (@ARGV) {
-	if (-e "$directory/$arg,v") {
-		# file already exists, we need not do any checks
-	} elsif (-e $arg) {
+	if (-e $arg) {
 		# stat the file, so we can check the permissions
-		($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
-			$ctime,$blksize,$blocks) = stat($arg);
+		($_dev,$_ino,$mode,$_nlink,$_uid,$gid,$_rdev,$_size,
+				$_atime,$_mtime,$_ctime,$_blksize,$_blocks)
+			= stat($arg);
 
 		# check the group id
 		if ($gid != $wanted_group_id) {
@@ -44,6 +58,45 @@
 		}
 	} else {
 		# file not in workspace, so permission problems cannot happen
+		next FILE;
+	}
+
+	#
+	# Check that the copyright message has been updated
+	# to include the current year.  But only for files within
+	# the `mercury' hierarchy.
+	#
+	next FILE unless ($directory =~ m^$ENV{CVSROOT}/mercury^);
+	# print "checking copyright for `$arg' (from `$directory')\n";
+
+	open 'arg' or die "Error opening $arg: $!\n";
+	$found = 0;
+	$copyright = "";
+	LINE:
+	while (<arg>) {
+		if (/Copyright \(C\).*$year/) {
+			$found = 1;
+			last LINE;
+		} elsif (/Copyright/i) {
+			$copyright .= "> $_";
+		}
+	}
+	close 'arg';
+	if (! $found) {
+		if ($copyright ne "") {
+			print "Copyright message for `$arg' appears to be "
+				. "out of date\n";
+			print "$copyright";
+		} else {
+			print "File `$arg' appears to have no "
+				. "copyright message\n";
+		}
+		print "Commit anyway? [n] ";
+		if (open TTY, "/dev/tty" and <TTY> =~ /^y/i) {
+			print "OK, if you insist!\n";
+		} else {
+			$retval = 1;
+		}
 	}
 }
 exit($retval);

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list