#!/usr/bin/perl # filecheck.plx -*- Perl -*- # # filecheck.plx: A program to update HTML files with dates # # Copyright (C) 2002 Bradley M. Kuhn. # 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 2 of the License, 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 # alongside this program in the file "COPYING"; if not, please check # http://www.ebb.org/bkuhn/code/COPYING, or write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA # Note that there are tons of assumptions that this all is relative to the # top of the web-public. For example, the "filecheck" comments are assumed # to be relative to web-public/ use strict; use warnings; use POSIX qw(strftime); use Cwd; if (@ARGV < 2) { print STDERR "usage: $0 [ ... ]\n"; exit 1; } #my $WEB_PUBLIC_DIR = cwd() . "/web-public/"; my $WEB_PUBLIC_DIR = "./web-public/"; my $EXTENSION = shift @ARGV; foreach my $file (@ARGV) { open(INPUT, "<$file") || die "Unable to open $file for reading: $!"; my $first = 1; my @saveData; while (my $line = ) { push(@saveData, $line); if ($line =~ /^(.*\s*) [^<]*(\s*.*)$/x) { my($beginLine, $checkFileName, $endLine) = ($1, $2, $3); chomp $endLine; if ($first) { print "Writing new version of: $file\n"; rename($file, "$file$EXTENSION") or die "unable to rename $file: $!"; unless (open(OUTPUT, ">$file")) { rename("$file$EXTENSION", $file); die "unable to write to $file: $!"; } $first = 0; pop @saveData; # cut off the filecheck line print OUTPUT @saveData; } $checkFileName = "$WEB_PUBLIC_DIR$checkFileName"; if (! -r "$checkFileName") { warn "$checkFileName is not readable. Will list it as unknown"; print OUTPUT "$beginLine UNKNOWN $endLine\n"; } else { open(LOG, "cvs log -l $checkFileName|") or die "unable to run cvs log -l $checkFileName: $!"; my($year, $month, $day); while (my $logLine = ) { if ($logLine =~ m%^\s*date:\s*(\d+)/(\d+)/(\d+)\s+.*$%) { ($year, $month, $day) = ($1, $2, $3); last; } } close(LOG); print OUTPUT $beginLine, sprintf("%4.4d-%2.2d-%2.2d", $year, $month, $day), # POSIX::strftime("%d %B %Y", localtime((stat($fileName))[9])), # POSIX::strftime("%F", localtime((stat($checkFileName))[9])), $endLine, "\n"; } } elsif (! $first) { print OUTPUT $line; } } close(INPUT); close(OUTPUT); } exit 0; # Local variables: # compile-command: "perl -c filecheck.plx" # End: