#!/usr/bin/perl
#
# MakeIndex
#
# Build HTML index of a set of html files.
# Extracts "<title>" segment from each file.
#

# 1) print header
# 2) process files to produce items
#    Ie extract title component, and build cross-ref to actual file.
# 3) print trailer

$outputfile = "Index.html";
$includefile = "Intro.include";

if (!open(OUTPUT, ">".$outputfile)) {
  die "Can't open output file $outputfile: $!\n";
}

select(OUTPUT);

# Print header
print "<html>","\n";
print "<BODY BGCOLOR=\"#ffffff\">","\n";
print "<body>","\n";
print "<h1>$heading</h1>","\n";
print "<p>","\n";
print "<ul>","\n";


# Print include file 

open(INCLUDEFILE, $includefile);
while (<INCLUDEFILE>) { print; }

# Process the files

# HTML versions:

print "<b>For on-line browsing (HTML):</b>\n";
print "<ul>","\n";

while (<Ex*/Ex*.html>) {
  $TheFile = $_ ;
  warn "Debug: PROCESSING $TheFile\n";
  if (!open(TheFD,$TheFile)) {
    warn "Can't open $foo: $!\n"; 
    break; 
  }
  reset;
  while(<TheFD>) {
    if (?<title>?io) {
      s/<title>/<li><a href="$TheFile">/io;
      if (?<\/title>?io) {
        s/<\/title>/<\/a><p>/io;
        print;
      }
      else {
        print;
        while(<TheFD>) {
          s/<\/title>/<\/a><p>/io;
          print;
          if (?<\/title>?io) {
            break;
          }
        }
      }
    }
  }
}
print "</ul>\n";

# Postscript versions:

print "<b>For printing (postscript):</b>\n";
print "<ul>","\n";

while (<Postscript/Ex*.ps.gz>) {
  $TheFile = $_ ;
  warn "Debug: PROCESSING $TheFile\n";
  print "<li>";
  print "<a href=\"$TheFile\"> $TheFile</a>\n";
}
print "</ul>\n";

#Print trailer
print "</ul>","\n";
print "</p>","\n";
print "</body>","\n";
print "</html>","\n";

