#!/usr/bin/perl -w

use strict;

my $rcs2log = "rcs2log ".join(" ",@ARGV);
my $have_ul = 0;

sub encode {
	my $foo = shift;
	$foo =~ s/</&lt;/g;
	$foo =~ s/>/&gt;/g;
	$foo =~ s/"/&quot;/g;
	return $foo;
}
	

open(RCS2LOG, "$rcs2log |") || die "$rcs2log: $!";
while(<RCS2LOG>) {
	chomp;
	next if (/^$/);
	if (/^(\d\d\d\d-\d+-\d+)\s+(.+)\s(<.+>)$/) {
		my ($date,$who,$email) = ($1,$2,$3);
		if ($have_ul) {
			print "</ul>\n";
			$have_ul = 0;
		}
		$email = encode($email);
		$email =~ s/@/(at)/g;
		$email =~ s/\./(dot)/g;
		print "<tt>$date</tt> $who <tt>$email</tt>\n";
	} elsif (/^\t\* ([^:]+):(\s*.*)$/) {
		if (! $have_ul) {
			print "<ul>\n";
			$have_ul = 1;
		}
		print "<li> <tt>$1</tt>:".encode($2)."\n";
	} elsif (/^\t([-]\s.*)$/) {
		print "<br>".encode($1)."\n";
	} else {
		print encode($_)."\n";
	}
}

