#!/usr/local/bin/perl

sub makehtml
  {
  local ($file, $title, $desc) = @_;
  print "Working on \"$file\" ($title)\n";
  if (!open (OUT, ">$file"))
    {
    warn "Couldn't open file: $!\n";
    next LINE;
    }
  print OUT "<HTML>\n";
  print OUT "<HEAD>\n";
  print OUT "<TITLE>$title</TITLE>\n";
  print OUT "</HEAD>\n";
  print OUT "<BODY>\n";
  print OUT "<H1>$title</H1>\n";

  $desc =~
    s/(Computer Science|CS)\s*([0-9]+)/<A HREF="Cs$2.html">$1 $2<\/A>/ig;

  $col = 0;
  foreach $word (split('\s+', $desc))
    {
    if ($word =~ /[.!?:]['")]*$/)
      {
      $word .= " ";
      }
    $word .= " ";
    if ($word =~ /:.*  $/)
      {
      print OUT "\n";
      print OUT "<P>\n";
      $col = 0;
      }
    if ($col + length($word) > 75)
      {
      print OUT "\n";
      $col = 0;
      }
    $col += length($word);
    print OUT $word;
    }
  print OUT "\n";
  print OUT "<P>\n";
  print OUT "Return to the Computer Science <A HREF=\"..\">Home Page</A>\n";
  print OUT "</BODY>\n";
  print OUT "</HTML>\n";
  close OUT;
  }

$file = "";
LINE: while (<>)
  {
  if (/^___(.*)___$/)
    {
    if ($file ne "")
      {
      &makehtml($file, $title, $desc);
      }
    $file="$1.html";
    $title=<>;
    chop($title);
    $desc = "";
    next LINE;
    }
  $desc .= $_;
  }
if ($file ne "")
  {
  &makehtml($file, $title, $desc);
  }
