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