#! /usr/local/bin/perl
#
# @(#)update_vldocs David Groep 20010515.1
#
$cvsroot=":pserver:davidg\@vlabwww.nikhef.nl:/global/ices/vlab/cvs";
$ENV{"CVSROOT"}=$cvsroot;
$cvs="/usr/local/bin/cvs";

%modules = ( 
	vlam => '/global/ices/www/site/vlabwww/VLAM-G/10_Abstract_Machine' 
);


foreach $mod ( keys %modules ) {
	$htroot=$modules{$mod};
	open HTML,">$htroot/80_Documents_Live_-_$mod.html" or 
		die "Opening file for $mod for writing: $!\n";

	open CVS,"$cvs checkout -p $mod 2>&1 1>/dev/null |" or
		die "Starting cvs checkout for $mod: $!\n";
	$descs=();
	while (<CVS>) {
		chop($_); split;
		# look for confirming document directories
		/^Checking out.*\.desc$/ and do {
			$fn=$_[2];
			push @descs,$fn;
		}
	}
	close CVS;

	&write_header(\*HTML,$mod);
	foreach $fn ( @descs ) {
		open CVS,"$cvs checkout -p $fn 2>&1 |" or die "cvs $fn: $!\n";
		$desc="";
		while (<CVS>) {
			chop($_);
			split;
			/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/ and do {
			 while (<CVS>) { $desc.=$_; }
			};
			/^VERS: / and $docvers=$_[1];
		}
		close CVS;

		($docroot=$fn)=~s/[^\/]*$//;
		chop($docroot);
		($docname=$fn)=~s/^.*\/(.*)\.desc$/$1/;
		&write_doc(\*HTML,$docroot,$docname,$docvers,$desc);
	}
	&write_footer(\*HTML,$mod);
	close HTML;
}






exit 0;



sub write_doc {
	my ($fh,$docroot,$docname,$docvers,$docdesc) = @_;
	print $fh <<EOF;
<hr>
<a href="http://vlabwww.nikhef.nl/cgi-bin/getdoc.pl?cvs=vl;docroot=$docroot;docname=$docname">$docname</a><br>
$docdesc
<br>
<b>Version: $docvers</b>
<p>
EOF
	return 0;
}


sub write_header {
	my ($fh,$mod) = @_;
	print $fh <<EOF;

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Description" content="Document live tree for $mod">
  <meta name="Author" content="David Groep <davidg\@nikhef.nl>">
  <title>Documents from $mod</title>
</head>

<body 
	text="#000000" bgcolor="#FFFFFF" 
	link="#0000EF" vlink="#51188E" alink="#FF0000">

<h1>Document live tree for $mod</h1>
EOF
	return 0;
}

sub write_footer {
	my ($fh,$mod) = @_;
	print $fh <<EOF;
<hr WIDTH="100%">
<small><a href="mailto:davidg\@nikhef.nl">David Groep</a></small>
</body>
</html>
EOF
	return 0;
}
