Admin/page/bin/mkcontents
author wenzelm
Sat, 29 May 2004 15:08:08 +0200
changeset 14839 c994f1c57fc7
parent 14490 7b37aa726d2d
permissions -rwxr-xr-x
handle raw symbols; Output.add_mode; more robust handling of sub/superscript;

#!/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);