<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

#
# Copyright Andrew M. Bishop 1996-2013.
#
# Usage: FAQ-html.pl &lt; FAQ &gt; FAQ.html
#

$_=&lt;STDIN&gt;;
s/^ *//;
s/ *\n//;
$first=$_;

print "&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"&gt;\n";
print "&lt;HTML&gt;\n";
print "\n";
print "&lt;HEAD&gt;\n";
print "&lt;TITLE&gt;$first&lt;/TITLE&gt;\n";
print "&lt;/HEAD&gt;\n";
print "\n";
print "&lt;BODY&gt;\n";
print "\n";
print "&lt;h1&gt;$first&lt;/h1&gt;\n";
print "\n";
print "&lt;p&gt;\n";

$questions=0;
$answers=0;
$pre=0;
$blank=1;

while(&lt;STDIN&gt;)
  {
   chop;

   s/&amp;/&amp;amp;/g;
   s/&lt;/&amp;lt;/g;
   s/&gt;/&amp;gt;/g;
   s/ä/&amp;auml;/g;
   s/ö/&amp;ouml;/g;
   s/ü/&amp;uuml;/g;
   s/Ä/&amp;Auml;/g;
   s/Ö/&amp;Ouml;/g;
   s/Ü/&amp;Uuml;/g;
   s/ß/&amp;szlig;/g;

   next if(m/^ *=+ *$/);
   next if ($_ eq "--------------------");
   $pre++,$blank=0,next if($pre==1 &amp;&amp; $_ eq "");
   $blank=1,next        if($pre!=1 &amp;&amp; $_ eq "");
   $pre++ if($pre);

   if ($_ eq "--------------------------------------------------------------------------------")
     {
      $pre=0,print "&lt;/pre&gt;\n" if($pre);
      print "&lt;hr&gt;\n";
      $answers++              if( $answers);
      $questions=0,$answers=1 if( $questions);
      $questions=1            if(!$questions &amp;&amp; !$answers);
     }
   elsif (m/^(Section [0-9]+)/)
     {
      $section = $1;
      $section =~ tr/ /-/;

      $pre=0,print "&lt;/pre&gt;\n" if($pre);
      print "&lt;p&gt;&lt;b&gt;&lt;a href=\"#$section\"&gt;$_&lt;/a&gt;&lt;/b&gt;\n" if($questions);
      print "&lt;h2 id=\"$section\"&gt;$_&lt;/h2&gt;\n"   if($answers);
      print "&lt;p&gt;\n";
     }
   elsif (m/^(Q [0-9]+.[0-9]+[a-z]*)/)
     {
      $question = $1;
      $question =~ tr/ /-/;

      $blank=0,$pre=0,print "&lt;/pre&gt;\n" if($pre);
      print "&lt;p&gt;&lt;a href=\"#$question\"&gt;$_&lt;/a&gt;\n"      if($questions);
      print "&lt;h3 id=\"$question\"&gt;$_&lt;/h3&gt;\n" if($answers);
      $pre=1,print "&lt;pre&gt;\n" if($answers);
     }
   elsif (m/\((See Q [0-9]+.[0-9]+[a-z]*)\)/)
     {
      $question = substr($1,4);
      $question =~ tr/ /-/;
      $href=$1;

      s%$1%&lt;a href="#$question"&gt;$href&lt;/a&gt;% if($answers);
      print "$_\n";
     }
   elsif (m%(^|[^\'\"])(http://[A-Za-z0-9-_.]+/[/A-Za-z0-9-_.~]*)% &amp;&amp;
          ($href=$2) &amp;&amp; $href !~ m%http://www\.(foo|bar)/%)
     {
      s%$2%&lt;a href="$href"&gt;$href&lt;/a&gt;%;
      print "$_\n";
     }
   else
     {
      $blank=0,print "\n" if($blank);
      print "$_\n";
     }
  }

print "&lt;/BODY&gt;\n";
print "\n";
print "&lt;/HTML&gt;\n";
</pre></body></html>