File: FAQ-html.pl

package info (click to toggle)
cxref 1.6e-9
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,332 kB
  • sloc: ansic: 16,598; yacc: 2,091; sh: 945; lex: 470; perl: 452; makefile: 439; lisp: 256; cpp: 188; python: 80
file content (106 lines) | stat: -rwxr-xr-x 2,327 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/perl

#
# Copyright Andrew M. Bishop 1996-2013.
#
# Usage: FAQ-html.pl < FAQ > FAQ.html
#

$_=<STDIN>;
s/^ *//;
s/ *\n//;
$first=$_;

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

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

while(<STDIN>)
  {
   chop;

   s/&/&amp;/g;
   s/</&lt;/g;
   s/>/&gt;/g;
   s//&auml;/g;
   s//&ouml;/g;
   s//&uuml;/g;
   s//&Auml;/g;
   s//&Ouml;/g;
   s//&Uuml;/g;
   s//&szlig;/g;

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

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

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

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

      s%$1%<a href="#$question">$href</a>% if($answers);
      print "$_\n";
     }
   elsif (m%(^|[^\'\"])(http://[A-Za-z0-9-_.]+/[/A-Za-z0-9-_.~]*)%)
     {
      $href=$2;

      s%$2%<a href="$href">$href</a>%;
      print "$_\n";
     }
   else
     {
      $blank=0,print "\n" if($blank);
      print "$_\n";
     }
  }

print "</BODY>\n";
print "\n";
print "</HTML>\n";