]> git.donarmstrong.com Git - debbugs.git/blob - scripts/db2html.in
6c4b7c9c1f7f215abe3d27a27ca0e165d87b4703
[debbugs.git] / scripts / db2html.in
1 #!/usr/bin/perl
2 # $Id: db2html.in,v 1.18 2003/05/25 14:43:30 joy Exp $
3 # usage: db2html [-diff] [-stampfile=<stampfile>] [-lastrun=<days>] <wwwbase>
4
5 #load the necessary libraries/configuration
6 $config_path = '/etc/debbugs';
7 $lib_path = '/usr/lib/debbugs';
8
9 require("$config_path/config");
10 require("$config_path/text");
11 require("$lib_path/errorlib");
12 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
13
14 use POSIX qw(strftime tzset);
15 $ENV{"TZ"} = 'UTC';
16 tzset();
17
18 #set current working directory
19 chdir("$gSpoolDir") || die "chdir spool: $!\n";
20
21 #setup variables
22 $diff = 0;
23 $stampfile = 'stamp.html';
24 $tail_html = $gHTMLTail; 
25 $expirynote_html = $gHTMLExpireNote;
26 $shorthead = ' Ref   * Package    Keywords/Subject                    Submitter';
27 $shortindex = ''; 
28 $amonths = -1;
29 $indexunmatched = '';
30 %displayshowpendings = ('pending','outstanding',
31                        'done','resolved',
32                        'forwarded','forwarded to upstream software authors');
33
34 #set timestamp for html files
35 $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
36 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
37
38 #check for commandline switches
39 while (@ARGV && $ARGV[0] =~ m/^-/) 
40 {       if ($ARGV[0] eq '-diff') { $diff=1; }
41     elsif ($ARGV[0] =~ m/^-lastrun\=([0-9.]+)$/) { $lastrun= $1; undef $stampfile; }
42     elsif ($ARGV[0] =~ m/^-full$/) { undef $lastrun; undef $stampfile; }
43     elsif ($ARGV[0] =~ m/^-stampfile\=(\S+)$/) { $stampfile= $1; }
44     else { &quit("bad usage"); }
45     shift;
46 }
47
48 #check for remaing argument, only one...
49 @ARGV==1 or die;
50 $wwwbase= shift(@ARGV);
51
52 #get starting time
53 defined($startdate= time) || &quit("failed to get time: $!");
54
55 $|=1;
56
57 #if stamp file was given, 
58 if (defined($stampfile)) 
59 {       if (open(X,"< $stampfile")) 
60         {       $lastrun= -M X;
61         close(X);
62         printf "progress last run %.7f days\n",$lastrun;
63     } else { print "progress stamp file $stampfile: $! - full\n"; }
64 }
65
66 #only process file if greater than last run...
67 if (defined($lastrun) && -M "db-h" > $lastrun) 
68 {       $_= $gHTMLStamp;
69     s/SUBSTITUTE_DTIME/$dtime/o;
70     s/\<\!\-\-updateupdate\-\-\>.*\<\!\-\-\/updateupdate\-\-\>/check/;
71     &file('ix/zstamp.html','non',$_."</body></html>\n");
72         print "noremoves";
73 #    print "db2html: no changes since last run\n";
74     exit 0;
75 }
76
77 #parse maintainer file
78 open(MM,"$gMaintainerFile") || &quit("open $gMaintainerFile: $!");
79 while(<MM>) 
80 {       m/^(\S+)\s+(\S.*\S)\s*$/ || &quit("$gMaintainerFile: \`$_'");
81     ($a,$b)=($1,$2);
82     $a =~ y/A-Z/a-z/;
83     $maintainer{$a}= $b;
84 }
85 close(MM);
86
87 #load all database files
88 opendir(D,'db-h') || &quit("opendir db-h: $!");
89 @dirs = sort { $a <=> $b } grep(s#^#db-h/#,grep(/^\d+$/,readdir(D)));
90 closedir(D);
91 foreach my $dir (@dirs) {
92     opendir(D,$dir);
93     push @files, sort { $a <=> $b } grep(/^-?\d+\.log$/,readdir(D));
94     closedir(D);
95 }
96
97 for $pending (qw(pending done forwarded)) 
98 {       for $severity (@showseverities) 
99         {       eval "\$index${pending}${severity}= \$iiindex${pending}${severity}= ''; 1;"
100             or &quit("reset \$index${pending}${severity}: $@");
101     }
102 }
103
104 for $f (@files) 
105 {       next unless $f =~ m/^(-?\d+)\.log$/;
106     $ref= $1;
107         #((print STDERR "$ref\n"),
108         #next
109         #)
110         # unless $ref =~ m/^-/ || $ref =~ m/^124/;
111     &filelock("lock/$ref");
112     $preserveonly= defined($lastrun) && -M "db-h/".get_hashname($ref)."/$ref.log" > $lastrun;
113     if ($ref =~ m/^-\d$/) 
114         {       $week= $ref eq '-1' ? 'this week' :
115                $ref eq '-2' ? 'last week' :
116                $ref eq '-3' ? 'two weeks ago' :
117                               ($ref-1)." weeks ago";
118         $linkto= "ju/unmatched$ref";
119         $short= "junk, $week";
120         $descriptivehead=
121             "This includes messages sent to <code>done\@$gEmailDomain</code>\n".
122             "which did not have a $gBug reference number in the Subject line\n".
123             "or which contained an\n".
124             "unknown or out of date $gBug report number (these cause a warning\n".
125             "to be sent to the sender) and details about the messages\n".
126             "sent to <code>request@$gEmailDomain</code> (all of which".
127             "produce replies).\n";
128         $indexlink= "Messages not matched to a specific $gBug report - $week";
129         $data->{subject}= '';
130         $indexentry= '';
131         undef $tpack;
132         undef $tmaint;
133         undef $iiref;
134         $tpackfile= "pnone.html";
135         $indexpart= 'unmatched';
136     } else 
137         {
138         $data=readbug($ref);
139         $_= $data->{package}; y/A-Z/a-z/; $_= $` if m/[^-+._a-z0-9()]/;
140         $tpack= $_;
141         if ($data->{severity} eq '' || $data->{severity} eq 'normal') 
142                 {       $showseverity= '';
143             $addseverity= $gDefaultSeverity;
144         } elsif (grep($data->{severity} eq $_, @strongseverities)) 
145                 {       $showseverity= "<strong>Severity: $data->{severity}</strong>;\n";
146             $addseverity= $data->{severity};
147         } else 
148                 {       $showseverity= "Severity: <em>$data->{severity}</em>;\n";
149             $addseverity= $data->{severity};
150         }
151         $days= int(($startdate - $data->{date})/86400); close(S);
152         $indexlink= "#$ref: ".&sani($data->{subject});
153         $indexentry= '';
154         $packfile= length($tpack) ? "pa/l$tpack.html" : "pa/none.html";
155         $indexentry .= "Package: <A href=\"../$packfile\"><strong>".
156                         &sani($data->{package})."</strong></A>;\n"
157             if length($data->{package});
158         $indexentry .= $showseverity;
159         $indexentry .= "Reported by: ".&sani($data->{originator});
160         $indexentry .= ";\nKeywords: ".&sani($data->{keywords})
161             if length($data->{keywords});
162         $linkto= $ref; $linkto =~ s,^..,$&/$&,;
163         @merged= split(/ /,$data->{mergedwith});
164         if (@merged) 
165                 {       $mseparator= ";\nmerged with ";
166             for $m (@merged) 
167                         {       $mfile= $m; $mfile =~ s,^..,$&/$&,;
168                 $indexentry .= $mseparator."<A href=\"../$mfile.html\">#$m</A>";
169                 $mseparator= ",\n";
170             }
171         }
172         $daysold=$submitted='';
173         if (length($data->{done})) 
174                 {       $indexentry .= ";\n<strong>Done:</strong> ".&sani($data->{done});
175             $indexpart= "done$addseverity";
176         } elsif (length($data->{forwarded})) 
177                 {       $indexentry .= ";\n<strong>Forwarded</strong> to ".&sani($data->{forwarded});
178             $indexpart= "forwarded$addseverity";
179         } else 
180                 {       $cmonths= int($days/30);
181             if ($cmonths != $amonths) 
182                         {       $msg= $cmonths == 0 ? "Submitted in the last month" :
183                         $cmonths == 1 ? "Over one month old" :
184                         $cmonths == 2 ? "Over two months old - attention is required" :
185                         "OVER $cmonths MONTHS OLD - ATTENTION IS REQUIRED";
186                 $shortindex .= "</pre><h2>$msg:</h2><pre>\n$shorthead\n";
187                 $amonths= $cmonths;
188             }
189             $pad= 6-length(sprintf("%d",$f));
190             $thissient=
191                 ($pad>0 ? ' 'x$pad : '').
192                 sprintf("<A href=\"../%s.html\">%d</A>",$linkto,$ref).
193                 &sani(sprintf(" %-1.1s %-10.10s %-35.35s %-.25s\n",
194                                                 $data->{severity},
195                         $data->{package},
196                         (length($data->{keywords}) ? $data->{keywords}.'/' : '').
197                         $data->{subject}, $data->{originator}));
198             $shortindex.= $thissient;
199             $sient{"$ref $data->{package}"}= $thissient;
200             if ($days >= 7) 
201                         {       $font= $days <= 30 ? '' :
202                         $days <= 60 ? 'em' :
203                     'strong';
204                 $efont= length($font) ? "</$font>" : '';
205                 $font= length($font) ? "<$font>" : '';
206                 $daysold= "; $font$days days old$efont";
207             }
208             if ($preserveonly) {
209                 $submitted = 'THIS IS A BUG IN THE BUG PROCESSOR';
210             } else {
211                 $submitted = strftime "%a, %e %b %Y %T %Z", localtime($data->{date});
212             }
213             $submitted= "; dated $submitted";
214             $indexpart= "pending$addseverity";
215         }
216         $iiref= $ref;
217         $short= $ref; $short =~ s/^\d+/#$&/;
218         $tmaint= defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
219         $qpackage= &sani($_);
220         $descriptivehead= $indexentry.$submitted.";\nMaintainer for $qpackage is\n".
221             '<A href="../ma/l'.&maintencoded($tmaint).'.html">'.&sani($tmaint).'</A>.';
222         $indexentry .= $daysold;
223         $indexentry .= ".";
224     }
225     $indexadd='';
226     $indexadd .= "<!--iid $iiref-->" if defined($iiref);
227     $indexadd .= "<li><A href=\"../$linkto.html\">".$indexlink."</A>";
228     $indexadd .=  "<br>\n".$indexentry if length($indexentry);
229     $indexadd .= "<!--/iid-->" if defined($iiref);
230     $indexadd .= "\n";
231     $estr= "\$index$indexpart = \$indexadd.\$index$indexpart; 1;";
232     eval($estr) || &quit("eval add to \$index$indexpart ($estr) failed: $@");
233         #print STDERR ">$estr|$indexadd<\n";
234     $indexadd= "<!--ii $iiref-->\n" if defined($iiref);
235     eval("\$iiindex$indexpart = \$indexadd.\$iiindex$indexpart; 1;") ||
236         &quit("eval add to \$iiindex$indexpart failed: $@");
237     if (defined($tmaint)) 
238         {       $countpermaint{$tmaint} += length($data->{done}) ? 0 : length($data->{forwarded}) ? 0 : 1;
239         eval("\$permaint${indexpart}{\$tmaint} .= \$indexadd; 1;") ||
240             &quit("eval add to \$permaint${indexpart}{\$tmaint} failed: $@");
241     }
242     if (defined($tpack)) 
243         {       $countperpack{$tpack} += length($data->{done}) ? 0 : length($data->{forwarded}) ? 0 : 1;
244         eval("\$perpack${indexpart}{\$tpack} .= \$indexadd; 1;") ||
245             &quit("eval add to \$perpack${indexpart}{\$tpack} failed: $@");
246     }
247     if ($preserveonly) { &preserve("$linkto.html"); &preserve("$linkto-b.html"); &unfilelock; next; }
248     my $hash = get_hashname($ref);
249     open(L,"db-h/$hash/$ref.log") || &quit("open db-h/$hash/$ref.log: $!");
250     $log='';
251     $boring=''; $xmessage= 0;
252     $normstate= 'kill-init';
253     $suppressnext= 0;
254     while(<L>) {
255         if (m/^\07$/) {
256             $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
257                 &quit("$ref ^G in state $normstate");
258             $normstate= 'incoming-recv';
259         } elsif (m/^\01$/) {
260             $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
261                 &quit("$ref ^A in state $normstate");
262             $normstate= 'autocheck';
263         } elsif (m/^\02$/) {
264             $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
265                 &quit("$ref ^B in state $normstate");
266             $normstate= 'recips';
267         } elsif (m/^\03$/) {
268             $normstate eq 'go' || $normstate eq 'go-nox' || $normstate eq 'html' ||
269                 &quit("$ref ^C in state $normstate");
270             $this .= "</pre>\n" if $normstate eq 'go' || $normstate eq 'go-nox';
271             if ($normstate eq 'html') {
272                 $xmessage++;
273                 $this .= "  <em><A href=\"../$linkto-b.html#m$xmessage\">Full text</A>".
274                          " available.</em>";
275             }
276             if ($suppressnext && $normstate ne 'html') {
277                 $ntis= $this; $ntis =~ s:\<pre\>:</A><pre>:i;
278                 $boring .= "<hr><A name=\"m$xmessage\">\n$ntis\n";
279             } else {
280                 $log = $this. "<hr>\n". $log;
281             }
282             $suppressnext= $normstate eq 'html';
283             $normstate= 'kill-end';
284         } elsif (m/^\05$/) {
285             $normstate eq 'kill-body' || &quit("^E in state $normstate");
286             $this .= "<pre>\n";
287             $normstate= 'go';
288         } elsif (m/^\06$/) {
289             $normstate eq 'kill-init' || $normstate eq 'kill-end' ||
290                 &quit("$ref ^F in state $normstate");
291             $normstate= 'html'; $this= '';
292         } elsif ($normstate eq 'incoming-recv') {
293             $pl= $_; $pl =~ s/\n+$//;
294             m/^Received: \(at (\S+)\) by (\S+)\;/ ||
295                 &quit("bad line \`$pl' in state incoming-recv");
296             $this = "<h2>Message received at ".&sani("$1\@$2").":</h2><br>\n".
297                     "<pre>\n".
298                     "$_";
299             $normstate= 'go';
300         } elsif ($normstate eq 'html') {
301             $this .= $_;
302         } elsif ($normstate eq 'go') {
303             s/^\030//;
304             $this .= &sani($_);
305         } elsif ($normstate eq 'go-nox') {
306             next if !s/^X//;
307             $this .= &sani($_);
308         } elsif ($normstate eq 'recips') {
309             if (m/^-t$/) {
310                 $this = "<h2>Message sent:</h2><br>\n";
311             } else {
312                 s/\04/, /g; s/\n$//;
313                 $this = "<h2>Message sent to ".&sani($_).":</h2><br>\n";
314             }
315             $normstate= 'kill-body';
316         } elsif ($normstate eq 'autocheck') {
317             next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
318             $normstate= 'autowait';
319             $this = "<h2>Message received at $2:</h2><br>\n";
320         } elsif ($normstate eq 'autowait') {
321             next if !m/^$/;
322             $normstate= 'go-nox';
323             $this .= "<pre>\n";
324         } else {
325             &quit("$ref state $normstate line \`$_'");
326         }
327     }
328     &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
329     close(L);
330     if (length($boring)) {
331         &file("$linkto-b.html",'non',
332               "<html><head><title>$gProject $gBug report logs - ".
333               "$short, boring messages</title>\n".
334               "<link rev=\"made\" href=\"mailto:$gMaintainerEmail)\">\n".
335               "</head>$gHTMLStart<h1>$gProject $gBugreport logs -".
336               "\n <A href=\"../$linkto.html\">$short</A>,".
337               " boring messages</h1>\n$boring\n<hr>\n".
338               $tail_html."</body></html>\n");
339     }
340     &file("$linkto.html",'non',
341           "<html><head><title>$gProject $gBug report logs - ".
342           "$short</title>\n".
343           "<link rev=\"made\" href=\"mailto:$gMaintainerEmail\">\n".
344           "</head>$gHTMLStart<h1>$gProject $gBug report logs -  $short<br>\n".
345           &sani($data->{subject})."</h1>".
346           "$descriptivehead\n".
347           "\n<hr>\n".
348           $log.
349           $tail_html."</body></html>\n");
350     &unfilelock;
351 }
352
353 sub maintsort {
354     $_= $_[0];
355     s/([^<>()]+) \(([^()<>]+)\)/$2 \<$1\>/;
356     
357     s/\s+/ /g;
358     s/^\s*//;
359     $email= s/ *\<[^<>()]+\>$//g ? $& : '';
360     $_= "$1 $_" if s/ (\S+)$//;
361     $_.= $email;
362     $_;
363 }
364
365 sub maintencoded {
366     return $maintencoded{$_[0]} if defined($maintencoded{$_[0]});
367     local ($input)= @_;
368     local ($todo,$encoded)= ($input);
369     while ($todo =~ m/\W/) {
370         $encoded.=$`.sprintf("-%02x_",unpack("C",$&));
371         $todo= $';
372     }
373     $encoded.= $todo;
374     $encoded =~ s/-2e_/\./g;
375     $encoded =~ s/^([^,]+)-20_-3c_(.*)-40_(.*)-3e_/$1,$2,$3,/;
376     $encoded =~ s/^(.*)-40_(.*)-20_-28_([^,]+)-29_$/,$1,$2,$3/;
377     $encoded =~ s/-20_/_/g;
378     $encoded =~ s/-([^_]+)_-/-$1/g;
379     $maintencoded{$input}= $encoded;
380 }
381
382 for $tmaint (keys %countpermaint) {
383     $_= $tmaint;
384     $after=$before=$sort2d=$sort2s=$sort1d=$sort1s='';
385     $after= "$&$after" if s/\s*\<[^<>()]+\>\s*$//;
386     $after= "$&$after" if s/\s*\)\s*$//;
387     $after= "$&$after" if s/\s*,.*$//;
388     $before.= $& if s/^.*\(\s*//;
389     $sort2d= $& if s/\S+$//;
390     $sort1d= $_;
391     while (s/^([^()<>]+)\. */$1 /) { };
392     s/\s+$//; y/A-Za-z/a-zA-Z/; $sort1s= $_;
393     $sort2s= $sort2d; $sort2s =~ y/A-Za-z/a-zA-Z/;
394     $maintsort{$tmaint}= $sort2s.' '.$sort1s.' '.$before.$sort1d.$sort2d.$after;
395     $maintdisplay{$tmaint}=
396         &sani($before).'<strong>'.&sani($sort1d.$sort2d).'</strong>'.&sani($after);
397 }
398
399 sub heading ($$) {
400     my ($pt,$sv) = @_;
401     return $displayshowseverities{$sv}.' - '.$displayshowpendings{$pt};
402 }
403
404 sub makeindex ($$$) {
405     my ($varprefix,$varsuffix,$tkey) = @_;
406     my ($pending,$severity,$anydone,$text);
407     $anydone= 0;
408     $text= '';
409     for $pending (qw(pending forwarded done)) {
410         for $severity (@showseverities) {
411             $estr= "\$value= \\${varprefix}${pending}${severity}${varsuffix}; 1;";
412 #print STDERR $estr;
413             eval $estr
414                 or &quit("eval get \$${varprefix}${pending}${severity} failed: $@");
415 #print STDERR ">$$value<\n";
416             next unless length($$value);
417             $text.= "<hr>\n<h2>".&heading($pending,$severity).":</h2>\n".
418                     "(List of <A href=\"../si/$pending$severity.html\">all".
419                     " such $gBugs</A> is available.)\n<ul>\n".
420                     $$value.
421                     "</ul>\n";
422             $anydone=1 if $pending eq 'done';
423         }
424     }
425     $text.= $expirynote_html if $anydone;
426     return $text;
427 }        
428
429 &file("ix/full.html",'def',
430       $gFullIndex.
431       makeindex('$index',"",'').
432       "<hr>\n".
433       $tail_html."</body><html>\n");
434
435 &file("ju/junk.html",'non',
436       $gJunkIndex.
437       "<hr>\n<h2>Junk (messages without a specific $gBug report number):</h2>\n".
438       "(\`this week' is everything since last Wednesday.)\n<ul>\n".
439       $indexunmatched.
440       "</ul><hr>\n".
441       $tail_html."</body><html>\n");
442
443 $nobugs_html= "No reports are currently in this state.";
444 $who_html= $gProject;
445 $owner_addr= $gMaintainerEmail;
446 $otherindex_html= "For other kinds of index or for other information about
447 $gProject and the $gBug system, see the <A HREF=\"../../\">$gBug system top-level
448 contents WWW page</A>.
449
450 ";
451
452 for $pending (qw(pending forwarded done)) {
453     for $severity (@showseverities) {
454         eval "\$value= \\\$iiindex${pending}${severity}; 1;"
455             or &quit("eval get \$iiindex${pendingtype}${severity} failed: $@");
456         $value= \$nobugs_html if !length($$value);
457         $headstring= &heading($pending,$severity);
458         &file("si/$pending$severity.html",'ref',
459               "<html><head><title>$who_html $gBug reports: $headstring</title>\n".
460               "<link rev=\"made\" href=\"mailto:".&sani($owner_addr)."\">\n".
461               "</head>$gHTMLStart<h1>$who_html $gBug reports: $headstring</h1>\n".
462               $otherindex_html.
463               ($pending eq 'done' ? "<P>\n$expirynote_html" : '').
464               "<hr>\n<ul>\n".
465               $$value.
466               "</ul>\n<hr>\n".
467               $tail_html."</body></html>\n");
468     }
469 }
470
471 sub individualindexes ($\@&\%&&$$$$$&&) {
472     my ($filename,$keysref,$getfilenameref,$countref,$getdisplayref,
473         $getsimpledisplayref,$what,$caveat,$whatplural,$abbrev,$ihead,
474         $getxinforef,$getxindexref) = @_;
475     my ($itext,$i,$tkey,$sani,$count,$tfilename,$refto,$backnext,$xitext,$bugbugs);
476     $itext='';
477     for ($i=0; $i<=$#$keysref; $i++) {
478         $tkey= $$keysref[$i];
479         $tfilename= &$getfilenameref($tkey);
480         $sani= &$getsimpledisplayref($tkey);
481         $count= $$countref{$tkey};
482         $count= $count >= 1 ? "$count" : "no";
483         $bugbugs= $count == 1 ? "$gBug" : "$gBugs";
484         $xitext= &$getxindexref($tkey);
485         $xitext= length($xitext) ? "$count $bugbugs; $xitext"
486                                  : "$count outstanding $bugbugs";
487         $itext .= "<li><A href=\"../$tfilename\">".&$getdisplayref($tkey)."</A>"."\n".
488                   "  ($xitext)\n";
489         $backnext= '';
490         if ($i>0) {
491             $refto= $$keysref[$i-1];
492             $xitext= &$getxindexref($refto);
493             $xitext= " ($xitext)" if length($xitext);
494             $backnext .= "<br>\nPrevious $what in list, <A href=\"../".
495                          &$getfilenameref($refto)."\">".&$getdisplayref($refto)."</A>".
496                          "$xitext\n";
497         }
498         if ($i<$#$keysref) {
499             $refto= $$keysref[$i+1];
500             $xitext= &$getxindexref($refto);
501             $xitext= " ($xitext)" if length($xitext);
502             $backnext .= "<br>\nNext $what in list, <A href=\"../".
503                          &$getfilenameref($refto)."\">".&$getdisplayref($refto)."</A>".
504                          "$xitext\n";
505         }
506         &file($tfilename,'ref',
507               "<html><head><title>$gProject $gBug reports: $what $sani</title>\n".
508               "<link rev=\"made\" href=\"mailto:$gMaintainerEmail\">\n".
509               "</head>$gHTMLStart<h1>$gProject $gBug reports: $what $sani</h1>\n".
510               &$getxinforef($tkey).
511               $caveat.
512               "See the <A href=\"../$filename\">listing of $whatplural</A>.\n".
513               $backnext.
514               &makeindex("\$per${abbrev}","{\$tkey}",$tkey).
515               "<hr>\n".
516               $tail_html."</body></html>\n");
517     }
518     &file($filename,'non',
519           $ihead.
520           "<hr><ul>\n".
521           $itext.
522           "</ul><hr>\n".
523           $tail_html."</body></html>\n");
524 }
525
526 @maintainers= sort { $maintsort{$a} cmp $maintsort{$b}; } keys %countpermaint;
527 individualindexes('ix/maintainers.html',
528                   @maintainers,
529                   sub { 'ma/l'.&maintencoded($_[0]).'.html'; },
530                   %countpermaint,
531                   sub { $maintdisplay{$_[0]}; },
532                   sub { &sani($_[0]); },
533                   'maintainer',
534                   "Note that there may be other reports filed under different
535                                   variations on the maintainer\'s name and email address.<P>",
536                   'maintainers',
537                   'maint',
538                   $gMaintIndex,
539                   sub { return ''; },
540                   sub { return ''; });
541
542 @packages= sort keys %countperpack;
543 individualindexes('ix/packages.html',
544                   @packages,
545                   sub { length($_[0]) ? "pa/l$_[0].html" : 'pa/none.html'; },
546                   %countperpack,
547                   sub { length($_[0]) ? $_[0] : 'not specified'; },
548                   sub { &sani(length($_[0]) ? $_[0] : 'not specified'); },
549                   'package',
550                   "Note that with multi-binary packages there may be other
551                                   reports filed under the different binary package names.<P>",
552                   'packages',
553                   'pack',
554                   $gPackageIndex,
555                   sub {
556                       return unless defined($maintainer{$_[0]});
557                       $tmaint= $maintainer{$_[0]};
558                       return "Maintainer for $_[0] is <A href=\"../ma/l".
559                              &maintencoded($tmaint).
560                              ".html\">".&sani($tmaint)."</A>.\n<p>\n";
561                   },
562                   sub {
563                       return unless defined($maintainer{$_[0]});
564                       $tmaint= $maintainer{$_[0]};
565                       return "<A href=\"../ma/l".
566                              &maintencoded($tmaint).
567                              ".html\">".&sani($tmaint)."</A>";
568                   });
569
570 &file('ix/summary.html','non',
571       $gSummaryIndex.
572       "<hr><pre>\n".
573       $shortindex.
574       "</pre><hr>\n".
575       $tail_html."</body></html>\n");
576
577 $bypackageindex='';
578 for $k (map {$_->[0] }
579         sort { $a->[2] cmp $b->[2]  ||  $a->[1] <=> $b->[1] }
580         map { [$_, split(' ',$_,2)] } keys %sient)
581     { $bypackageindex.= $sient{$k}; }
582 &file('ix/psummary.html','non',
583       $gPackageLog.
584       "<hr><pre>\n$shorthead\n".
585       $bypackageindex.
586       "</pre><hr>\n".
587       $tail_html."</body></html>\n");
588
589 open(P,"$gPseudoDescFile") ||
590     &quit("$gPseudoDescFile: $!");
591 $ppd=''; while(<P>) { s/\s*\n$//; $ppd.= &sani($_)."\n"; } close(P);
592 &file('ix/pseudopackages.html','non',
593       $gPseudoIndex.
594       "<hr><pre>\n$ppd".
595       "</pre><hr>\n".
596       $tail_html."</body></html>\n");
597
598 $_= $gHTMLStamp; s/SUBSTITUTE_DTIME/$dtime/o;
599
600 &file('ix/zstamp.html','non',$_."</body></html>\n");
601
602 sub notimestamp ($) {
603     $_= $_[0];
604     s/\<\!\-\-timestamp\-\-\>\n.*\n\<\!\-\-\/timestamp\-\-\>\n//;
605     return $_;
606 }
607
608 sub file {
609     local ($name,$ii,$file)= @_;
610     if ($diff) {
611         $cmppath= "$wwwbase/$name".($ii eq 'ref' ? '.ref' : '');
612         if (open(ORIG,"$cmppath")) {
613             undef $/; $orig= <ORIG>; $/= "\n";
614             close(ORIG);
615             if (&notimestamp($orig) eq &notimestamp($file)) {
616                 print "preserve $name\n";
617                 return;
618             }
619             defined($c= open(P,"-|")) or &quit("pipe/fork for diff: $!");
620             if (!$c) {
621                 open(Q,"|diff -e $cmppath -") or die "pipe/fork II for diff: $!\n";
622                 print Q $file or die "write orig to diff: $!\n";
623                 close(Q); $?==0 || $?==256 or die "diff gave $?\n";
624                 exit($?>>8);
625             }
626             undef $/; $difftxt= <P>; $/= "\n";
627             close(P); $?==0 || $?==256 or die "diff fork gave $?\n";
628             if ($?==0) {
629                 print "preserve $name\n";
630                 return;
631             }
632             $v= (split(/\n/,$difftxt));
633             print "diff $v $ii $name\n${difftxt}thatdiff $name\n"
634                 or &quit("stdout (diff): $!");
635             return;
636         }
637     } 
638     $v= (split(/\n/,$file));
639     print "file $v $ii $name\n${file}thatfile $name\n" or &quit("stdout: $!");
640 }
641
642 sub preserve {
643     print "preserve $_[0]\n";
644 }
645
646 print "end\n";
647
648 while ($u= $cleanups[$#cleanups]) { &$u; }
649 exit 0;