#!/usr/local/bin/perl
eval "exec perl -S  $0 $*"
                         if $running_under_some_shell;

# Joel Schroeder April 1996
#
# keywords web html report tex redoc

$usage = "Usage: $0 -";
$selfdoc = "\n
Convert a report (not a thesis) to html format using book2html.
$0 is called from the Adm directory.
The resulting page is at http://sepwww/docs/title.html

Any flag is passed on to book2html

WARNING: run $0 in the foreground (otherwise it may stop unexpectedly)

See also: book2web, paper2html\n";

if (@ARGV < 1) {
    die "$usage$selfdoc";
}

$args = join(" ",@ARGV);
$args =~ s/$0//;

&getbookname(*reportname);
chop($reportname);
@tmp = split(/\W*\s+\W*/, $reportname);
$reportdir = @tmp[0];
$reportdir =~ tr/A-Z/a-z/;

$machmadewarning =  "<! WARNING: machine-made html file (with [book|report]2web).  Remove this line before hand-editing>";
$htmlname = "/public/docs/$reportdir.html";
if (-f $htmlname) {
   open(HTMLFILE, "<$htmlname");
   while (<HTMLFILE>) { last; }
   chop($_);
   if ($_ ne $machmadewarning) {
      die "Machine Made file already exists: $htmlname\n";
   }
   `rm $htmlname`;
}   

open(HTMLFILE, ">$htmlname");
   print HTMLFILE "$machmadewarning\n";
close(HTMLFILE);

`book2html /private/docs /private/docs/$reportdir $args >> $htmlname`;

print "Look for the report at http://sepwww/public/docs/$reportdir.html\n";

exit;

# get the name of the report or book based on document.name
sub getbookname {
   local(*name) = @_;
   open(NAMEFILE, "<document.name");
   $not_found = 1;
   while (<NAMEFILE>) {
       if ((s/^#define\s*BOOK\s*//) ||
	   (s/^\s*BOOKn\s*:?=\s*//))
       {
	   $name = $_;
	   $not_found = 0;
	   last;
       }
   }
   if ($not_found) { # no name found, use the directory name
       $name = `cd ..; pwd`;
       $name =~ s#(/.*)*/##;
   }
}
