#!/usr/bin/perl

$HOME   = (getpwuid( $< ))[7];

$SRC="/home/web/ranulf.net/docs/britdisc/britdisc";
$DST="/home/web/ranulf.net/docs/britdisc/old";

$art=0000;

open (fSRC,$SRC);
open (fDST,">/dev/null");
open (fIDX,">$DST/index.html");

print fIDX "<html><head><title>BritDisc Archive</title></head>".
	"<body><center><h1>BritDisc Archive</h1></center>".
	"Please choose one of the following articles:<p><ul>\n";

$gotblank=1;
$gotsubject=0;

@indexList=();

while (<fSRC>) {
#	if (/^From britdisc-owner\@csv.warwick.ac.uk/) {
	if (/^From\s*(\S*)\s*(.*)/) {
		if ($gotblank) {
			print fDST "</pre></body></html>\n";
			close(fDST);
			$art++;
			open(fDST,">$DST/$art.html");
			$gotsubject=0;
			print fDST "<html><head><title>BritDisc article #$art".
				"</title></head><body><pre>\n";
			$date=$2;
		}
	}
	if (/^$/) {
		$gotblank=1;
	} else {
		$gotblank=0;
	}
	if (/^Subject:[ \t]*(.*)/) {
		$subj=$1;
		$subj=~s/</&lt;/g;
		$subj=~s/>/&gt;/g;
		push @indexList,"<li>#$art - <a href=\"$art.html\">$subj</a> $date\n" if ($gotsubject==0);
#		print fIDX "<li>#$art - <a href=\"$art.html\">$1</a> $date\n" if ($gotsubject==0);
		$gotsubject=1;
	}
	s/</&lt;/g;
	s/>/&gt;/g;
	print fDST $_;
}

while ($_=pop @indexList) {
	print fIDX $_;
}

print fIDX "</ul><hr>\n";

print fIDX <<EOF;
<ul>
<li><a href="../BritDiscOld/britdisc-0001-1000">31/8/96 - 11/11/97</a></li>
<li><a href="../BritDiscOld/britdisc-1001-2000">11/11/97 - 3/7/98</a></li>
<li><a href="../BritDiscOld/britdisc-2001-3000">3/7/98 - 3/3/99</a></li>
<li><a href="../BritDiscOld/britdisc-3001-4000">3/3/99 - 6/10/99</a></li>
<li><a href="../BritDiscOld/britdisc-4001-5000">6/10/99 - 13/6/00</a></li>
<li><a href="../BritDiscOld/britdisc-5001-6000">13/6/00 - 27/3/01</a></li>
<li><a href="../BritDiscOld/britdisc-6001-end">27/3/01 - end of old list</a></li>
</ul>
EOF

print fIDX "<center>BritDisc archive<br>(c) 1996 Ranulf Doswell".
	"</center></body></html>\n";

print fDST "</pre></body></html>\n";

close(fSRC);
close(fDST);
close(fIDX);


