Generating TOC.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 16 Dec 2013 22:58:24 +0000 (23:58 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 16 Dec 2013 22:58:24 +0000 (23:58 +0100)
matrixgen.pl
toc.pl [new file with mode: 0755]

index 779e858..95845b1 100755 (executable)
@@ -198,10 +198,42 @@ foreach my $c (sort keys %components) {
                        }
                }
        }
+       `cat /tmp/report-$c-install.part /tmp/report-$c-minor-upgrade.part /tmp/report-$c-major-upgrade.part /tmp/report-$c-double-upgrade.part /tmp/report-$c-update.part >> /tmp/report-body-$c.html 2>/dev/null`;
+       `rm -f /tmp/report-$c-*.part`;
+
+       # TOC
+       #
+       # keep in sync with toc.pl
+       #
+       open TH, ">", "/tmp/toc-$c.html";
+       open FH, "<", "/tmp/report-body-$c.html";
+       if ($? == 0) {
+               my $i;
+
+               printf TH "<H1>Content</H1>\n";
+               while (<FH>) {
+                       chomp;
+
+                       if (/<A NAME="([^"]*)".*<\/A>.*<H(.)>([^<]*)<\/H.*/) {
+                               foreach $i (2..$2) {
+                                       printf TH "&nbsp;&nbsp;&nbsp;&nbsp;";
+                               }
+                               printf TH "<A HREF=\"#$1\">$3</A><BR>\n";
+                       }
+               }
+               printf TH "\n";
+               close FH;
+
+               printf TH "<H1>Reports</H1>\n";
+       }
+       close TH;
+
        `cat ../template.header.html | sed 's/\@TITLE\@/$c/' > /tmp/report-$c.html`;
-       `cat /tmp/report-$c-install.part /tmp/report-$c-minor-upgrade.part /tmp/report-$c-major-upgrade.part /tmp/report-$c-double-upgrade.part /tmp/report-$c-update.part >> /tmp/report-$c.html 2>/dev/null`;
+       `cat /tmp/toc-$c.html >> /tmp/report-$c.html`;
+       `cat /tmp/report-body-$c.html >> /tmp/report-$c.html`;
        `cat ../template.footer.html >> /tmp/report-$c.html`;
-       `rm -f /tmp/report-$c-*.part`;
+
+       `rm -f /tmp/toc-$c.html /tmp/report-body-$c.html`;
 }
 
 
diff --git a/toc.pl b/toc.pl
new file mode 100755 (executable)
index 0000000..bb0f590
--- /dev/null
+++ b/toc.pl
@@ -0,0 +1,45 @@
+#! /usr/bin/perl -w
+
+use strict;
+
+#
+# keep in sync with gluer in matrixgen.pl
+#
+
+#
+# usage:
+#   cat report1.html report2.html... | ./toc.pl lb > reports.html
+#
+
+       # TOC
+               my $i;
+               my $c = 'Title';
+               my $dir = `dirname $0`;
+               my $tmpbody = "/tmp/body.$$.html";
+               chomp $dir;
+
+       if ($#ARGV >= 0) { $c = $ARGV[0]; }
+
+       system("cat $dir/template.header.html | sed 's/\@TITLE\@/$c/'");
+
+               open FH, ">", $tmpbody;
+               print "<H1>Content</H1>\n";
+               while (<>) {
+                       chomp;
+                       printf FH "%s", "$_\n";
+
+                       if (/<A NAME="([^"]*)".*<\/A>.*<H(.)>([^<]*)<\/H.*/) {
+                               foreach $i (2..$2) {
+                                       print "&nbsp;&nbsp;&nbsp;&nbsp;";
+                               }
+                               print "<A HREF=\"#$1\">$3</A><BR>\n";
+                       }
+               }
+               print "\n";
+               close FH;
+
+               print "<H1>Reports</H1>\n";
+
+       system("cat $tmpbody");
+       system("cat $dir/template.footer.html");
+       `rm -f $tmpbody`;