3 # Script to turn the Exim FAQ into HTML.
7 # Function to do text conversions that apply to both displays and non displays
11 $s =~ s/</</g; # Deal with < and >
17 # Function to do text conversions to display paragraphs
22 my($indent) = $s =~ /^(\s+)/;
23 my($remove) = " " x (length($indent) - 3);
25 $s = &process_both($s);
30 # Function to do text conversions to paragraphs not in displays.
32 sub process_non_display {
33 my($s) = &process_both($_[0]);
35 $s =~ s/@\\/@@backslash@@/g; # @\ temporarily hidden
37 $s =~ s/\\#/ /g; # \# is a hard space
39 $s =~ s/\\\*\*([^*]*)\*\*\\/<b>$1<\/b>/g; # \**...**\ => bold
40 $s =~ s/\\\*([^*]*)\*\\/<i>$1<\/i>/g; # \*.....*\ => italic
41 $s =~ s/\\"([^"]*)"\\/<tt>$1<\/tt>/g; # \"....."\ => fixed pitch
42 $s =~ s/\\\$([^\$]*)\$\\/<i>\$$1<\/i>/g; # \$.....$\ => $italic
43 $s =~ s/\\\\([^\\]*)\\\\/<small>$1<\/small>/g; # \\.....\\ => small
44 $s =~ s/\\\(([^)]*)\)\\/<i>$1<\/i>/g; # \(.....)\ => italic
45 $s =~ s/\\-([^\\]*)-\\/<b>-$1<\/b>/g; # \-.....-\ => -bold
46 $s =~ s/\\\[([^]]*)\]\\/&\#60;<i>$1<\/i>&\#62;/gx; # \[.....]\ => <italic>
47 $s =~ s/\\\?(.*?)\?\\/<a href="$1">$1<\/a>/g; # \?.....?\ => URL
48 $s =~ s/\\\^\^([^^]*)\^\^\\/<i>$1<\/i>/g; # \^^...^^\ => italic
49 $s =~ s/\\\^([^^]*)\^\\/<i>$1<\/i>/g; # \^.....^\ => italic
50 $s =~ s/\\%([^%]*)%\\/<b>$1<\/b>/g; # \%.....%\ => bold
51 $s =~ s/\\\/([^\/]*)\/\\/<i>$1<\/i>/g; # \/...../\ => italic
52 $s =~ s/\\([^\\]+)\\/<tt>$1<\/tt>/g; # \.......\ => fixed pitch
54 $s =~ s"//([^/\"]*)//"<i>$1</i>"g; # //.....// => italic
55 $s =~ s/::([^:]*)::/<i>$1:<\/i>/g; # ::.....:: => italic:
57 $s =~ s/``(.*?)''/“$1”/g; # ``.....'' => quoted text
59 $s =~ s/\s*\[\[br\]\]\s*/<br>/g; # [[br]] => <br>
61 $s =~ s/@@backslash@@/\\/g; # Put back single backslash
63 $s =~ s/^(\s*\(\d\)\s)/$1 /; # Extra space after (1), etc.
65 # Cross references within paragraphs
67 $s =~ s/Q(\d{4})(?!:)/<a href="$xref{$1}">$&<\/a>/xg;
69 # References to configuration samples
71 $s =~ s/\b([CFLS]\d\d\d)\b/<a href="$1.txt">$1<\/a>/g;
73 # Remove white space preceding a newline in the middle of paragraphs,
74 # to keep the file smaller (and for human reading when debugging).
84 # We want to read the file paragraph by paragraph; Perl only does this if the
85 # separating lines are truly blank. Having been caught by lines containing
86 # whitespace before, do a detrailing pass first.
88 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (preliminary)\n";
89 open(OUT, ">$ARGV[0]-$$") || die "can't open $ARGV[0]-$$\n";
97 rename("$ARGV[0]-$$", "$ARGV[0]") ||
98 die "can't rename $ARGV[0]-$$ as $ARGV[0]\n";
100 # The second argument is the name of a directory into which to put multiple
101 # HTML files. We start off with FAQ.html.
104 open(OUT, ">$hdir/FAQ.html") || die "can't open $hdir/FAQ.html\n";
111 <title>The Exim FAQ</title>
113 <body bgcolor="#F8F8F8" text="#00005A" link="#0066FF" alink="#0066FF" vlink="#000099">
114 <h1>The Exim FAQ</h1>
119 # First pass to read the titles and questions and create the table of
120 # contents. We save it up in a vector so that it can be written after the
121 # introductory paragraphs.
123 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (first time)\n";
131 $count = s/\n/\n/g - 1; # Number of lines in paragraph
133 if ($count == 1 && /^\d+\./) # Look for headings
136 push @toc, "</ul>" if $inul;
138 push @toc, "<br>\n\n" if $sec++ >= 0;
139 push @toc, "<a name=\"TOC$toc\" href=\"FAQ_$sec.html\">$_</a>\n";
142 ($number,$title) = /^(\d+)\.\s+(.*)$/;
143 if ($title ne "UUCP" && $title ne "IRIX" && $title ne "BSDI" &&
146 ($initial,$rest) = $title =~ /^(.)(.*)$/;
147 $title = "$initial\L$rest";
148 $title =~ s/isdn/ISDN/;
149 $title =~ s/\btls\b/TLS/;
150 $title =~ s/\bssl\b/SSL/;
151 $title =~ s/ os x/ OS X/;
153 push @seclist, "<a href=\"FAQ_$sec.html\">$number. $title</a>";
158 if (/^(Q\d{4})/) # Q initial paragraph
167 $xref{substr($num,1)} = "FAQ_$sec.html#TOC$toc";
168 $rest =~ s/^: /: /;
169 $rest = &process_non_display($rest);
170 push @toc, "<li><a name=\"TOC$toc\" href=\"FAQ_$sec.html#TOC$toc\">$num</a>$rest<br><br></li>\n";
176 push @toc, "</ul>\n" if $inul;
180 # This is the main processing pass. We have to detect the different kinds of
181 # "paragraph" and do appropriate things.
183 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (second time)\n";
185 # Skip the title line
189 # Handle the rest of the file
197 $count = s/\n/\n/g - 1; # Number of lines in paragraph
198 chomp; # Trailing newlines
200 if (/^The FAQ is divided into/)
202 my($count) = scalar(@seclist);
203 my($cols) = ($count + 1)/2;
205 print OUT "<hr><a name=\"TOC\"><h1>Index</h1></a>\n";
206 print OUT "<p>A <i>Keyword-in-context</i> <a href=\"FAQ-KWIC_A.html\">index</a> " .
207 "to the questions is available. This is usually the " .
208 "quickest way to find information in the FAQ.</p>\n";
210 print OUT "<h1>Contents</h1>\n";
211 print OUT "<p>The FAQ is divided into the following sections:<br><br></p>\n";
213 print OUT "<table>\n";
215 for ($i = 0; $i < $cols; $i++)
218 print OUT " <td>", " " x 4, "</td>\n";
219 print OUT " <td> $seclist[$i]</td>\n";
220 print OUT " <td>", " " x8, "$seclist[$cols+$i]</td>\n"
221 if $cols+$i < $count;
224 print OUT "</table><br><p>\n<hr><br>\n";
225 print OUT "<h1>List of questions</h1>\n";
227 $_ = <IN>; # Skip section list
231 if ($count == 1 && /^\d+\./) # Look for headings
233 if (@toc != 0) # TOC when hit first heading
235 while (@toc != 0) { print OUT shift @toc; }
238 # Output links at the bottom of this page
240 print OUT "<hr><br>\n";
241 print OUT "<a href=\"FAQ.html#TOC\">Contents</a> \n";
244 printf OUT ("<a href=\"FAQ_%d.html\">Previous</a> \n", $sec-1);
246 printf OUT ("<a href=\"FAQ_%d.html\">Next</a>\n", $sec+1);
248 # New section goes in new file
250 print OUT "</body>\n</html>\n";
254 open(OUT, ">$hdir/FAQ_$sec.html") ||
255 die "Can't open $hdir/FAQ_$sec.html\n";
257 print OUT "<html>\n<head>\n" .
258 "<title>The Exim FAQ Section $sec</title>\n" .
260 "<body bgcolor=\"#F8F8F8\" text=\"#00005A\" " .
261 "link=\"#FF6600\" alink=\"#FF9933\" vlink=\"#990000\">\n";
263 printf OUT "<h1>The Exim FAQ</h1>\n";
265 print OUT "<a href=\"FAQ.html#TOC\">Contents</a> \n";
268 printf OUT ("<a href=\"FAQ_%d.html\">Previous</a> \n", $sec-1);
272 printf OUT ("<a href=\"FAQ_%d.html\">Next</a>\n", $sec+1);
275 print OUT "<hr><br>\n";
277 print OUT "<h2><a href=\"FAQ.html#TOC$toc\">$_</a></h2>\n";
282 s/^([QA]\d{4}|[CFLS]\d{3}): /$1: /;
284 if (/^(Q\d{4}:)/) # Q initial paragraph
286 print OUT "<p>\n<a name=\"TOC$toc\" href=\"FAQ.html#TOC$toc\">$1</a>";
287 $_ = &process_non_display($');
288 print OUT "$_\n</p>\n";
293 if (/^A\d{4}:/) # A initial paragraph
295 $_ = &process_non_display($_);
296 s/^(A\d{4}:)/<font color="#00BB00">$1<\/font>/;
297 print OUT "<p>\n$_\n</p>\n";
301 # If a paragraph begins ==> it is a display which must remain verbatin
302 # and not be reformatted. The flag gets turned into spaces.
306 $_ = &process_display($_);
308 print OUT "<pre>\n$_</pre>\n";
311 # Non-display paragraph; massage the final line & my sig.
313 elsif (/^\*\*\* End of Exim FAQ \*\*\*/)
319 $_ = &process_non_display($_);
325 print OUT "<p>\n$_\n</p>\n";
331 print OUT "<hr><br>\n";
332 print OUT "<a href=\"FAQ.html#TOC\">Contents</a> \n";
333 printf OUT ("<a href=\"FAQ_%d.html\">Previous</a>\n", $sec-1);
335 print OUT "</body>\n</html>\n";