#!/usr/bin/perl

$adapterpath="../adapters";
$docpath=".";

&gen_preamble;
&gen_page_heading;
&gen_aqt_content;
foreach $item (@ARGV) {   
    print  "<div id=\"contentitem\">\n";
    print "<h2>Adapter::$item</h2>";     
    print "<h3>ReadMe</h3>";     
    &escape_and_print_file("$adapterpath/$item/ReadMe");
    print "<h3>ReleaseNotes</h3>";     
    &escape_and_print_file("$adapterpath/$item/ReleaseNotes");
    print "</div>\n";
}

&gen_postamble;

sub escape_and_print_file {
   local($file)=@_;
#   print $file;
   open (filedata, $file);
   while (<filedata>){
      $data=$_;
      $data =~ s/</&lt;/g;
      $data =~ s/>/&gt;/g;
      $data =~ s/\n/<br>/g;
      $data =~ s/---/<pre>/g;
      $data =~ s/===/<\/pre>/g;
      print $data;
   }   
   close(filedata);
}

sub gen_preamble {
    print <<END;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
   <title>AquaTerm 1.1.1 help</title>
   <style type="text/css">
   body{background: #FFFFFF; color: #000000; font-family:verdana, arial, sans-serif;}
   #hdr{border:solid #FFFFFF; border-width:1px 0px 0px 0px; margin:1px 0 0 0; padding:16px;}
   #contentitem{border:solid #000000; border-width:1px 0px 0px 0px; margin:1px 0 0 0; padding:16px;}
   h1, h2, h3 {font-family:verdana, arial, sans-serif;}
   h1 {font-size:20px;}
   h2 {font-size:14px;}
   h3 {font-size:12px;}
</style>
</head>
<body>
END
}

sub gen_page_heading {
    print <<END;
<!-- Header -->
<div id="hdr">
<h1>AquaTerm.app, your friendly plotting front-end</h1>
This is the help file for AquaTerm 1.1.1. It is simply a collection of info files from the release.<br>
For questions, please use the mailing lists at <a href="http://aquaterm.sf.net">the AquaTerm website</a>.
<br>
</div>
END
}


sub gen_aqt_content {
foreach $item ('ReadMe', 'INSTALL', 'ReleaseNotes') {   
    print  "<div id=\"contentitem\">\n";
    print "<h2>AquaTerm::$item</h2>";     
    &escape_and_print_file("$docpath/$item");
    print "\n</div>\n";
    }
}

sub gen_postamble {
    print <<END;
</body>
</html>
END
}
