#!/usr/bin/perl
# mkcontents.pl
#
# $Id$
#
# simple script to create a html version of the Contents file in the
# Isabelle documentation directory.
#
# Nov/14/1999 Version 1.0 - Gerwin Klein <kleing@in.tum.de>
#
# command line:
# mkcontent [-p <url-path-prefix>] <Content-file> <output-file>
#
use Getopt::Long ;
$opt_p="";
$result = GetOptions ("p=s");
$path=$opt_p;
$infile = $ARGV[0];
$outfile = $ARGV[1];
$listHeader = "<ul>\n";
$lineHeader = " <li>";
$lineEnd = "</li>\n";
$listFooter = "</ul>\n";
$topicStart = "<h2>";
$topicEnd = "</h2>\n";
open(IN, "<$infile") || die "cannot read input file <$infile>";
open(OUT, ">$outfile") || die "cannot write output file <$outfile>";
$first = 1;
while (<IN>) {
if (/^([^ \t].*)\n/) {
if ($first == 1) {
$first = 0;
}
else {
print OUT $listFooter;
}
print OUT $topicStart;
print OUT $1;
print OUT $topicEnd;
print OUT $listHeader;
}
elsif (/^[ \t]+([^ \t]+)[ \t]+(.+)\n/) {
print OUT $lineHeader;
print OUT "<a href=\"$path$1.pdf\">$2</a>";
print OUT $lineEnd;
}
}
print OUT $listFooter;
close(OUT);
close(IN);
exit(0);