add build properties
[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 EOF
19
20 print LOG_HTML <<EOF;
21 <html>
22 <head>
23   <link rel="stylesheet" href="build.css">
24 </head>
25 <body>
26 EOF
27 print LOG_HTML "<pre>";
28
29 sub read_vars {
30     my ($file) = @_;
31     my %vars = ();
32     if (open (VARS, "<", $file)) {
33         while (<VARS>) {
34             chomp;
35             my ($key, $value) = /^([^=]+)=(.*)/ or next;
36             $vars{$key} = $value;
37         }
38         close (VARS);
39     }
40     return %vars;
41 }
42
43 my (%vars) = read_vars ('VARS');
44 print INDEX "<h2>Build Properties</h2>\n";
45 print INDEX "<table>\n";
46 print INDEX "<tr><th>Name</th><th>Value</th></tr>\n";
47 foreach my $key (sort (keys (%vars))) {
48     print INDEX "<tr>";
49     print INDEX "<td>", encode_entities ($key), "</td>";
50     print INDEX "<td>", encode_entities ($vars{$key}), "</td>";
51     print INDEX "</tr>\n";
52 }
53 print INDEX "</table>\n";
54
55 print INDEX "<h2>Build Summary</h2>\n";
56 print INDEX "<ol>\n";
57
58 my ($n_products) = 0;
59 my ($n_steps) = 0;
60 my ($new_page) = 0;
61 while (<LOG>) {
62     my $ln = $.;
63     chomp;
64
65     if (/^\f$/) {
66         $new_page = 1;
67         print LOG_HTML "</pre><hr><pre>\n";
68         next;
69     }
70
71     my $log_class;
72     if ($new_page) {
73         $new_page = 0;
74         $log_class = "step";
75         if (my ($product) = /^Saving (.*)$/) {
76             print INDEX "\n  <ul>\n" if !$n_products++;
77             my $href = "$product/index.html";
78             $href = $product if ! -e $href;
79             print INDEX "  <li><a href=\"", encode_entities ($href), "\">";
80             print INDEX encode_entities ($product), "</a>";
81             print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
82             print INDEX "</li>\n";
83         } else {
84             print INDEX "</ul>" if !$n_steps;
85             print INDEX "<li>", encode_entities ($_);
86             print INDEX " <small><a href=\"log.html#$ln\">(log)</a></small>";
87             $n_products = 0;
88         }
89     } else {
90         if (my ($diagnostic) = /(error|warning):/) {
91             if ($n_products) {
92                 print INDEX "  </ul>\n";
93                 $n_products = 0;
94             }
95             print INDEX "<p class=\"$diagnostic\">";
96             print INDEX "<a href=\"log.html#$ln\">";
97             print INDEX encode_entities ($_);
98             print INDEX "</a></p>\n";
99             $log_class = "$diagnostic";
100         }
101     }
102     printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
103     if (defined ($log_class)) {
104         print LOG_HTML "<span class=\"$log_class\">", encode_entities ($_), "</span>\n";
105     } else {
106         print LOG_HTML encode_entities ($_), "\n";
107     }
108 }
109 print INDEX "  </ul>\n" if $n_products;
110 print INDEX "</li>\n" if $n_steps;
111 print INDEX <<EOF;
112 </ol>
113 </body>
114 </html>
115 EOF
116
117 print LOG_HTML <<EOF;
118 </pre>
119 </body>
120 </html>
121 EOF
122
123 open (CSS, '>', "build.css");
124 print CSS <<EOF;
125 body {
126         background: white;
127         color: black;
128         padding: 0em 12em 0em 3em;
129         margin: 0
130 }
131 body>p {
132         margin: 0pt 0pt 0pt 0em
133 }
134 body>p + p {
135         text-indent: 1.5em;
136 }
137 H1 {
138         font-size: 150%;
139         margin-left: -1.33em
140 }
141 H2 {
142         font-size: 125%;
143         font-weight: bold;
144         margin-left: -.8em
145 }
146 H3 {
147         font-size: 100%;
148         font-weight: bold;
149         margin-left: -.5em }
150 H4 {
151         font-size: 100%;
152         margin-left: 0em
153 }
154 H1, H2, H3, H4, H5, H6 {
155         font-family: sans-serif;
156         color: blue
157 }
158 html {
159         margin: 0
160 }
161
162 a:link {
163         color: blue;
164         text-decoration: none;
165 }
166 a:visited {
167         color: gray;
168         text-decoration: none;
169 }
170 a:active {
171         color: black;
172         text-decoration: none;
173 }
174 a:hover {
175         text-decoration: underline
176 }
177
178 .step {
179         font-weight: bold
180 }
181 .warning {
182         background: yellow;
183         margin-top: 0;
184         margin-bottom: 0
185 }
186 .error {
187         background: orange;
188         margin-top: 0;
189         margin-bottom: 0
190 }
191 EOF