simplify
authorRich Salz <rsalz@akamai.com>
Fri, 21 Aug 2015 19:07:22 +0000 (15:07 -0400)
committerRich Salz <rsalz@akamai.com>
Fri, 21 Aug 2015 19:07:22 +0000 (15:07 -0400)
bin/mk-changelog

index 60135c9d3b2a5cc361303e6ebf14233819f11db2..18902d5234730785e7b195d7931a00ee8b8469c9 100755 (executable)
@@ -1,48 +1,34 @@
 #! /usr/bin/perl -w
 use strict;
 
 #! /usr/bin/perl -w
 use strict;
 
-# Read whole input.
-my $page;
-{
-    local $/;
-    $page .= <STDIN>;
-}
-
-# HTML entities.
-$page =~ s|&|&amp;|sg;
-$page =~ s|<|&lt;|sg;
-$page =~ s|>|&gt;|sg;
-
-# Make sub-headings.
-$page =~ s|^.+?(Changes.+?\n+)|$1|s;
-$page =~ s|(Changes between.+?)\n|</pre>\n<h3>$1</h3>\n<pre>\n|sg;
-
-# Wrap it, and remove empty <pre></pre>
-$page = '<pre>' . $page . '</pre>';
-$page =~ s|<pre></pre>||g;
-
-# Make a TOC
 my $ctr = 0;
 my $toc;
 my $out;
 my $top = '  <a href="#toc"><img src="/img/up.gif"/></a>';
 my $ctr = 0;
 my $toc;
 my $out;
 my $top = '  <a href="#toc"><img src="/img/up.gif"/></a>';
-for (split /^/, $page) {
-    if ( /<h3>/ ) {
-       my $name = $_;
-       $name =~ s|<h3>(.*)</h3>|$1|;
-       chop ($name);
-       $out .= '<h3><a name="x' . $ctr . '">' . $name . "</a>$top</h3>\n";
-       $toc .= '<li><a href="#x' . $ctr . '">' . $name . "</a></li>\n";
+my $skipping = 1;
+
+while ( <STDIN> ) {
+    chop;
+    # HTML entities.
+    s|&|&amp;|sg;
+    s|<|&lt;|sg;
+    s|>|&gt;|sg;
+    if ( /^( Changes between.*)/ ) {
+        $out .= "</pre>\n" unless $skipping;
+        $skipping = 0;
+       $out .= "<h3><a name=\"x$ctr\">$1</a>$top</h3>\n<pre>\n";
+       $toc .= "  <li><a href=\"#x$ctr\">$1</a></li>\n";
        $ctr++;
        $ctr++;
-    } else {
-       $out .= $_;
+    } elsif ( ! $skipping ) {
+        $out .= $_ . "\n";
     }
 }
     }
 }
+$out .= "</pre>\n";
 
 print "<h3><a name='toc'>Table of contents</a></h3>\n";
 
 print "<h3><a name='toc'>Table of contents</a></h3>\n";
-print "<ul>";
+print "<ul>\n";
 print $toc;
 print $toc;
-print "</ul>";
+print "</ul>\n";
 print $out;
 
 exit(0);
 print $out;
 
 exit(0);