Add utility for HTML results.
[pspp] / results2html
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use HTML::Entities;
7
8 open (LOG, '<', "LOG");
9 open (INDEX, '>','index.html');
10 open (LOG_HTML, '>', "log.html");
11
12 print INDEX <<EOF;
13 <html>
14 <head>
15   <link rel="stylesheet" href="build.css">
16 </head>
17 <body>
18 <ol>
19 EOF
20
21 print LOG_HTML <<EOF;
22 <html>
23 <head>
24   <link rel="stylesheet" href="build.css">
25 </head>
26 <body>
27 EOF
28 print LOG_HTML "<pre>";
29
30 my ($n_products) = 0;
31 my ($n_steps) = 0;
32 my ($new_page) = 0;
33 while (<LOG>) {
34     my $ln = $.;
35     chomp;
36
37     if (/^\f$/) {
38         $new_page = 1;
39         print LOG_HTML "</pre><hr><pre>\n";
40         next;
41     }
42
43     my $log_class;
44     if ($new_page) {
45         $new_page = 0;
46         $log_class = "step";
47         if (my ($product) = /^Saving (.*)$/) {
48             print INDEX "\n  <ul>\n" if !$n_products++;
49             my $href = "$product/index.html";
50             $href = $product if ! -e $href;
51             print INDEX "  <li><a href=\"", encode_entities ($href), "\">";
52             print INDEX encode_entities ($product), "</a>";
53             print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
54             print INDEX "</li>\n";
55         } else {
56             print INDEX "</ul>" if !$n_steps;
57             print INDEX "<li>", encode_entities ($_);
58             print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
59             $n_products = 0;
60         }
61     } else {
62         if (my ($diagnostic) = /(error|warning):/) {
63             if ($n_products) {
64                 print INDEX "  </ul>\n";
65                 $n_products = 0;
66             }
67             print INDEX "<p class=\"$diagnostic\">";
68             print INDEX "<a href=\"log.html#$ln\">";
69             print INDEX encode_entities ($_);
70             print INDEX "</a></p>\n";
71             $log_class = "$diagnostic";
72         }
73     }
74     printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
75     if (defined ($log_class)) {
76         print LOG_HTML "<span class=\"$log_class\">", encode_entities ($_), "</span>\n";
77     } else {
78         print LOG_HTML encode_entities ($_), "\n";
79     }
80 }
81 print INDEX "  </ul>\n" if $n_products;
82 print INDEX "</li>\n" if $n_steps;
83 print INDEX <<EOF;
84 </ol>
85 </body>
86 </html>
87 EOF
88
89 print LOG_HTML <<EOF;
90 </pre>
91 </body>
92 </html>
93 EOF
94
95 open (CSS, '>', "build.css");
96 print CSS <<EOF;
97 body {
98         background: white;
99         color: black;
100         padding: 0em 12em 0em 3em;
101         margin: 0
102 }
103 body>p {
104         margin: 0pt 0pt 0pt 0em
105 }
106 body>p + p {
107         text-indent: 1.5em;
108 }
109 H1 {
110         font-size: 150%;
111         margin-left: -1.33em
112 }
113 H2 {
114         font-size: 125%;
115         font-weight: bold;
116         margin-left: -.8em
117 }
118 H3 {
119         font-size: 100%;
120         font-weight: bold;
121         margin-left: -.5em }
122 H4 {
123         font-size: 100%;
124         margin-left: 0em
125 }
126 H1, H2, H3, H4, H5, H6 {
127         font-family: sans-serif;
128         color: blue
129 }
130 html {
131         margin: 0
132 }
133
134 a:link {
135         color: blue;
136         text-decoration: none;
137 }
138 a:visited {
139         color: gray;
140         text-decoration: none;
141 }
142 a:active {
143         color: black;
144         text-decoration: none;
145 }
146 a:hover {
147         text-decoration: underline
148 }
149
150 .step {
151         font-weight: bold
152 }
153 .warning {
154         background: yellow;
155         margin-top: 0;
156         margin-bottom: 0
157 }
158 .error {
159         background: orange;
160         margin-top: 0;
161         margin-bottom: 0
162 }
163 EOF