# -*- Perl -*- # $Id: cvshtmlwdiff,v 1.10 2005/10/06 01:34:06 sra Exp $ # Do Fenner's htmlwdiff thing using a CVS repository. This knows way # more than it should about how I use CVS tags, because the # alternative would be parsing cvs log output. my @tmpfile = do { my $me = ($0 =~ (m=^(.+/)*([^/]+)\.pl$=))[1]; ("$me.1.$$", "$me.2.$$"); }; $SIG{$_} = sub { unlink @tmpfile } foreach (qw(__DIE__ HUP INT QUIT PIPE TERM)); sub pipe_open { my $pid = open(IN, "-|"); return if ($pid); die("Couldn't fork(", join(" ", @_), "): $!") unless (defined($pid)); exec(@_); die("Couldn't exec(", join(" ", @_), "): $!"); } sub draft_quote { my $in = shift; my $out = shift; if ( -r $in) { open(IN, $in) or die("Couldn't open $in: $!"); } else { $_ = $in; s/\.txt$//; print("cvs..."); pipe_open(qw(cvs -q update -p -r), $_, $in); } open(OUT, "> $out") or die("Couldn't open $out: $!"); while () { s/&/&/g; s//\>/g; print(OUT) or die("Couldn't write $out: $!"); } close(IN) or die("Couldn't close input: $!"); close(OUT) or die("Couldn't close $out: $!"); } $| = 1; while (@ARGV) { $_ = shift(@ARGV); my ($base, $vers) = /^(draft-.+-)0*([1-9][0-9]?)\.txt$/; next unless ($base && $vers > 0); my $out = sprintf("changes-%s%02d-%02d.html", $base, $vers -1, $vers); print("Generating $out..."); draft_quote(sprintf("%s%02d.txt", $base, $vers - 1), $tmpfile[0]); draft_quote(sprintf("%s%02d.txt", $base, $vers), $tmpfile[1]); print("wdiff..."); pipe_open("wdiff", "-w", "", "-x", "", "-y", "", "-z", "", $tmpfile[0], $tmpfile[1]); open(OUT, "> $out") or die("Couldn't open $out: $!"); print(OUT "
\n") or die("Couldn't write $out: $!");
    print(OUT $_) or die("Couldn't write $out: $!") while ();
    print(OUT "
\n") or die("Couldn't write $out: $!"); die("Couldn't close wdiff: $!") unless (close(IN) or $! == 0); close(OUT) or die("Couldn't close $out: $!"); print("done.\n"); } cleanup();