add build products list
[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 my (@products);
56 my (@steps);
57 my ($new_page) = 0;
58 while (<LOG>) {
59     my $ln = $.;
60     chomp;
61
62     if (/^\f$/) {
63         $new_page = 1;
64         print LOG_HTML "</pre><hr><pre>\n";
65         next;
66     }
67
68     my $log_class;
69     if ($new_page) {
70         $new_page = 0;
71         $log_class = "step";
72         if (my ($product) = /^Saving (.*)$/) {
73             my $href = "$product/index.html";
74             $href = $product if ! -e $href;
75
76             my (%p);
77             $p{PRODUCT} = $product;
78             $p{HREF} = $href;
79             $p{LN} = $ln;
80             push (@products, \%p);
81             push (@{$steps[$#steps]{CHILDREN}}, \%p);
82         } else {
83             my (%s);
84             $s{TITLE} = $_;
85             $s{LN} = $ln;
86             push (@steps, \%s);
87         }
88     } else {
89         if (my ($diagnostic) = /(error|warning):/) {
90             my (%d);
91             $d{DIAGNOSTIC} = $diagnostic;
92             $d{MESSAGE} = $_;
93             $d{LN} = $ln;
94             push (@{$steps[$#steps]{CHILDREN}}, \%d);
95
96             $log_class = "$diagnostic";
97         }
98     }
99     printf LOG_HTML "<a name=\"%d\"><tt>%4d</tt></a>  ", $ln, $ln;
100     if (defined ($log_class)) {
101         print LOG_HTML "<span class=\"$log_class\">", encode_entities ($_), "</span>\n";
102     } else {
103         print LOG_HTML encode_entities ($_), "\n";
104     }
105 }
106
107 print INDEX "<h2>Build Products</h2>\n";
108 print INDEX "<ul>\n";
109 foreach my $p (@products) {
110     print INDEX "<li><a href=\"", encode_entities ($p->{HREF}), "\">";
111     print INDEX encode_entities ($p->{PRODUCT});
112     print INDEX "</a></li>\n";
113 }
114 print INDEX "</ul>\n";
115
116 sub log_link {
117     my ($ln) = @_;
118     return "<small><a href=\"log.html#$ln\">(log)</a></small>";
119 }
120
121 print INDEX "<h2>Build Summary</h2>\n";
122 print INDEX "<ol>\n";
123 foreach my $s (@steps) {
124     print INDEX "<li>", encode_entities ($s->{TITLE});
125     print INDEX " ", log_link ($s->{LN});
126     foreach my $c (@{$s->{CHILDREN}}) {
127         if (defined ($c->{DIAGNOSTIC})) {
128             print INDEX "<p class=\"$c->{DIAGNOSTIC}\">";
129             print INDEX "<a href=\"log.html#$c->{LN}\">";
130             print INDEX encode_entities ($c->{MESSAGE});
131             print INDEX "</a></p>\n";
132         } else {
133             print INDEX "<p>&rarr; <a href=\"", encode_entities ($c->{HREF}), "\">";
134             print INDEX encode_entities ($c->{PRODUCT});
135             print INDEX "</a></p>\n";
136         }
137     }
138     print INDEX "</li>\n";
139 }
140 print INDEX "</ol>\n";
141
142 print INDEX <<EOF;
143 </body>
144 </html>
145 EOF
146
147 print LOG_HTML <<EOF;
148 </pre>
149 </body>
150 </html>
151 EOF
152
153 open (CSS, '>', "build.css");
154 print CSS <<EOF;
155 body {
156         background: white;
157         color: black;
158         padding: 0em 3em 0em 3em;
159         margin: 0
160 }
161 body>p {
162         margin: 0pt 0pt 0pt 0em
163 }
164 body>p + p {
165         text-indent: 1.5em;
166 }
167 H1 {
168         font-size: 150%;
169         margin-left: -1.33em
170 }
171 H2 {
172         font-size: 125%;
173         font-weight: bold;
174         margin-left: -.8em
175 }
176 H3 {
177         font-size: 100%;
178         font-weight: bold;
179         margin-left: -.5em }
180 H4 {
181         font-size: 100%;
182         margin-left: 0em
183 }
184 H1, H2, H3, H4, H5, H6 {
185         font-family: sans-serif;
186         color: blue
187 }
188 html {
189         margin: 0
190 }
191
192 a:link {
193         color: blue;
194         text-decoration: none;
195 }
196 a:visited {
197         color: gray;
198         text-decoration: none;
199 }
200 a:active {
201         color: black;
202         text-decoration: none;
203 }
204 a:hover {
205         text-decoration: underline
206 }
207
208 ol>li>p {
209         margin-top: 0;
210         margin-bottom: 0
211 }
212 .step {
213         font-weight: bold
214 }
215 .warning {
216         background: yellow
217 }
218 .error {
219         background: orange
220 }
221 EOF