Add utility for HTML results.
[pspp] / results2html
diff --git a/results2html b/results2html
new file mode 100755 (executable)
index 0000000..1b46221
--- /dev/null
@@ -0,0 +1,163 @@
+#! /usr/bin/env perl
+
+use strict;
+use warnings;
+
+use HTML::Entities;
+
+open (LOG, '<', "LOG");
+open (INDEX, '>','index.html');
+open (LOG_HTML, '>', "log.html");
+
+print INDEX <<EOF;
+<html>
+<head>
+  <link rel="stylesheet" href="build.css">
+</head>
+<body>
+<ol>
+EOF
+
+print LOG_HTML <<EOF;
+<html>
+<head>
+  <link rel="stylesheet" href="build.css">
+</head>
+<body>
+EOF
+print LOG_HTML "<pre>";
+
+my ($n_products) = 0;
+my ($n_steps) = 0;
+my ($new_page) = 0;
+while (<LOG>) {
+    my $ln = $.;
+    chomp;
+
+    if (/^\f$/) {
+       $new_page = 1;
+       print LOG_HTML "</pre><hr><pre>\n";
+       next;
+    }
+
+    my $log_class;
+    if ($new_page) {
+       $new_page = 0;
+       $log_class = "step";
+       if (my ($product) = /^Saving (.*)$/) {
+           print INDEX "\n  <ul>\n" if !$n_products++;
+           my $href = "$product/index.html";
+           $href = $product if ! -e $href;
+           print INDEX "  <li><a href=\"", encode_entities ($href), "\">";
+           print INDEX encode_entities ($product), "</a>";
+           print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
+           print INDEX "</li>\n";
+       } else {
+           print INDEX "</ul>" if !$n_steps;
+           print INDEX "<li>", encode_entities ($_);
+           print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
+            $n_products = 0;
+       }
+    } else {
+       if (my ($diagnostic) = /(error|warning):/) {
+           if ($n_products) {
+               print INDEX "  </ul>\n";
+               $n_products = 0;
+           }
+           print INDEX "<p class=\"$diagnostic\">";
+           print INDEX "<a href=\"log.html#$ln\">";
+           print INDEX encode_entities ($_);
+           print INDEX "</a></p>\n";
+           $log_class = "$diagnostic";
+       }
+    }
+    printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
+    if (defined ($log_class)) {
+       print LOG_HTML "<span class=\"$log_class\">", encode_entities ($_), "</span>\n";
+    } else {
+       print LOG_HTML encode_entities ($_), "\n";
+    }
+}
+print INDEX "  </ul>\n" if $n_products;
+print INDEX "</li>\n" if $n_steps;
+print INDEX <<EOF;
+</ol>
+</body>
+</html>
+EOF
+
+print LOG_HTML <<EOF;
+</pre>
+</body>
+</html>
+EOF
+
+open (CSS, '>', "build.css");
+print CSS <<EOF;
+body {
+       background: white;
+       color: black;
+       padding: 0em 12em 0em 3em;
+       margin: 0
+}
+body>p {
+       margin: 0pt 0pt 0pt 0em
+}
+body>p + p {
+       text-indent: 1.5em;
+}
+H1 {
+       font-size: 150%;
+       margin-left: -1.33em
+}
+H2 {
+       font-size: 125%;
+       font-weight: bold;
+       margin-left: -.8em
+}
+H3 {
+       font-size: 100%;
+       font-weight: bold;
+       margin-left: -.5em }
+H4 {
+       font-size: 100%;
+       margin-left: 0em
+}
+H1, H2, H3, H4, H5, H6 {
+       font-family: sans-serif;
+       color: blue
+}
+html {
+       margin: 0
+}
+
+a:link {
+       color: blue;
+        text-decoration: none;
+}
+a:visited {
+       color: gray;
+       text-decoration: none;
+}
+a:active {
+       color: black;
+       text-decoration: none;
+}
+a:hover {
+        text-decoration: underline
+}
+
+.step {
+       font-weight: bold
+}
+.warning {
+       background: yellow;
+       margin-top: 0;
+       margin-bottom: 0
+}
+.error {
+       background: orange;
+       margin-top: 0;
+       margin-bottom: 0
+}
+EOF