2 # $Cambridge: exim/doc/doc-scripts/f2h,v 1.1 2004/10/07 15:04:35 ph10 Exp $
4 # Script to turn the Exim FAQ into HTML.
8 # Function to do text conversions that apply to both displays and non displays
12 $s =~ s/</</g; # Deal with < and >
18 # Function to do text conversions to display paragraphs
23 my($indent) = $s =~ /^(\s+)/;
24 my($remove) = " " x (length($indent) - 3);
26 $s = &process_both($s);
31 # Function to do text conversions to paragraphs not in displays.
33 sub process_non_display {
34 my($s) = &process_both($_[0]);
36 $s =~ s/@\\/@@backslash@@/g; # @\ temporarily hidden
38 $s =~ s/\\#/ /g; # \# is a hard space
40 $s =~ s/\\\*\*([^*]*)\*\*\\/<b>$1<\/b>/g; # \**...**\ => bold
41 $s =~ s/\\\*([^*]*)\*\\/<i>$1<\/i>/g; # \*.....*\ => italic
42 $s =~ s/\\"([^"]*)"\\/<tt>$1<\/tt>/g; # \"....."\ => fixed pitch
43 $s =~ s/\\\$([^\$]*)\$\\/<i>\$$1<\/i>/g; # \$.....$\ => $italic
44 $s =~ s/\\\\([^\\]*)\\\\/<small>$1<\/small>/g; # \\.....\\ => small
45 $s =~ s/\\\(([^)]*)\)\\/<i>$1<\/i>/g; # \(.....)\ => italic
46 $s =~ s/\\-([^\\]*)-\\/<b>-$1<\/b>/g; # \-.....-\ => -bold
47 $s =~ s/\\\[([^]]*)\]\\/&\#60;<i>$1<\/i>&\#62;/gx; # \[.....]\ => <italic>
48 $s =~ s/\\\?(.*?)\?\\/<a href="$1">$1<\/a>/g; # \?.....?\ => URL
49 $s =~ s/\\\^\^([^^]*)\^\^\\/<i>$1<\/i>/g; # \^^...^^\ => italic
50 $s =~ s/\\\^([^^]*)\^\\/<i>$1<\/i>/g; # \^.....^\ => italic
51 $s =~ s/\\%([^%]*)%\\/<b>$1<\/b>/g; # \%.....%\ => bold
52 $s =~ s/\\\/([^\/]*)\/\\/<i>$1<\/i>/g; # \/...../\ => italic
53 $s =~ s/\\([^\\]+)\\/<tt>$1<\/tt>/g; # \.......\ => fixed pitch
55 $s =~ s"//([^/\"]*)//"<i>$1</i>"g; # //.....// => italic
56 $s =~ s/::([^:]*)::/<i>$1:<\/i>/g; # ::.....:: => italic:
58 $s =~ s/``(.*?)''/“$1”/g; # ``.....'' => quoted text
60 $s =~ s/\s*\[\[br\]\]\s*/<br>/g; # [[br]] => <br>
62 $s =~ s/@@backslash@@/\\/g; # Put back single backslash
64 $s =~ s/^(\s*\(\d\)\s)/$1 /; # Extra space after (1), etc.
66 # Cross references within paragraphs
68 $s =~ s/Q(\d{4})(?!:)/<a href="$xref{$1}">$&<\/a>/xg;
70 # References to configuration samples
72 $s =~ s/\b([CFLS]\d\d\d)\b/<a href="$1.txt">$1<\/a>/g;
74 # Remove white space preceding a newline in the middle of paragraphs,
75 # to keep the file smaller (and for human reading when debugging).
85 # We want to read the file paragraph by paragraph; Perl only does this if the
86 # separating lines are truly blank. Having been caught by lines containing
87 # whitespace before, do a detrailing pass first.
89 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (preliminary)\n";
90 open(OUT, ">$ARGV[0]-$$") || die "can't open $ARGV[0]-$$\n";
98 rename("$ARGV[0]-$$", "$ARGV[0]") ||
99 die "can't rename $ARGV[0]-$$ as $ARGV[0]\n";
101 # The second argument is the name of a directory into which to put multiple
102 # HTML files. We start off with FAQ.html.
105 open(OUT, ">$hdir/FAQ.html") || die "can't open $hdir/FAQ.html\n";
112 <title>The Exim FAQ</title>
114 <body bgcolor="#F8F8F8" text="#00005A" link="#0066FF" alink="#0066FF" vlink="#000099">
115 <h1>The Exim FAQ</h1>
120 # First pass to read the titles and questions and create the table of
121 # contents. We save it up in a vector so that it can be written after the
122 # introductory paragraphs.
124 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (first time)\n";
132 $count = s/\n/\n/g - 1; # Number of lines in paragraph
134 if ($count == 1 && /^\d+\./) # Look for headings
137 push @toc, "</ul>" if $inul;
139 push @toc, "<br>\n\n" if $sec++ >= 0;
140 push @toc, "<a name=\"TOC$toc\" href=\"FAQ_$sec.html\">$_</a>\n";
143 ($number,$title) = /^(\d+)\.\s+(.*)$/;
144 if ($title ne "UUCP" && $title ne "IRIX" && $title ne "BSDI" &&
147 ($initial,$rest) = $title =~ /^(.)(.*)$/;
148 $title = "$initial\L$rest";
149 $title =~ s/isdn/ISDN/;
150 $title =~ s/\btls\b/TLS/;
151 $title =~ s/\bssl\b/SSL/;
152 $title =~ s/ os x/ OS X/;
154 push @seclist, "<a href=\"FAQ_$sec.html\">$number. $title</a>";
159 if (/^(Q\d{4})/) # Q initial paragraph
168 $xref{substr($num,1)} = "FAQ_$sec.html#TOC$toc";
169 $rest =~ s/^: /: /;
170 $rest = &process_non_display($rest);
171 push @toc, "<li><a name=\"TOC$toc\" href=\"FAQ_$sec.html#TOC$toc\">$num</a>$rest<br><br></li>\n";
177 push @toc, "</ul>\n" if $inul;
181 # This is the main processing pass. We have to detect the different kinds of
182 # "paragraph" and do appropriate things.
184 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (second time)\n";
186 # Skip the title line
190 # Handle the rest of the file
198 $count = s/\n/\n/g - 1; # Number of lines in paragraph
199 chomp; # Trailing newlines
201 if (/^The FAQ is divided into/)
203 my($count) = scalar(@seclist);
204 my($cols) = ($count + 1)/2;
206 print OUT "<hr><a name=\"TOC\"><h1>Index</h1></a>\n";
207 print OUT "<p>A <i>Keyword-in-context</i> <a href=\"FAQ-KWIC_A.html\">index</a> " .
208 "to the questions is available. This is usually the " .
209 "quickest way to find information in the FAQ.</p>\n";
211 print OUT "<h1>Contents</h1>\n";
212 print OUT "<p>The FAQ is divided into the following sections:<br><br></p>\n";
214 print OUT "<table>\n";
216 for ($i = 0; $i < $cols; $i++)
219 print OUT " <td>", " " x 4, "</td>\n";
220 print OUT " <td> $seclist[$i]</td>\n";
221 print OUT " <td>", " " x8, "$seclist[$cols+$i]</td>\n"
222 if $cols+$i < $count;
225 print OUT "</table><br><p>\n<hr><br>\n";
226 print OUT "<h1>List of questions</h1>\n";
228 $_ = <IN>; # Skip section list
232 if ($count == 1 && /^\d+\./) # Look for headings
234 if (@toc != 0) # TOC when hit first heading
236 while (@toc != 0) { print OUT shift @toc; }
239 # Output links at the bottom of this page
241 print OUT "<hr><br>\n";
242 print OUT "<a href=\"FAQ.html#TOC\">Contents</a> \n";
245 printf OUT ("<a href=\"FAQ_%d.html\">Previous</a> \n", $sec-1);
247 printf OUT ("<a href=\"FAQ_%d.html\">Next</a>\n", $sec+1);
249 # New section goes in new file
251 print OUT "</body>\n</html>\n";
255 open(OUT, ">$hdir/FAQ_$sec.html") ||
256 die "Can't open $hdir/FAQ_$sec.html\n";
258 print OUT "<html>\n<head>\n" .
259 "<title>The Exim FAQ Section $sec</title>\n" .
261 "<body bgcolor=\"#F8F8F8\" text=\"#00005A\" " .
262 "link=\"#FF6600\" alink=\"#FF9933\" vlink=\"#990000\">\n";
264 printf OUT "<h1>The Exim FAQ</h1>\n";
266 print OUT "<a href=\"FAQ.html#TOC\">Contents</a> \n";
269 printf OUT ("<a href=\"FAQ_%d.html\">Previous</a> \n", $sec-1);
273 printf OUT ("<a href=\"FAQ_%d.html\">Next</a>\n", $sec+1);
276 print OUT "<hr><br>\n";
278 print OUT "<h2><a href=\"FAQ.html#TOC$toc\">$_</a></h2>\n";
283 s/^([QA]\d{4}|[CFLS]\d{3}): /$1: /;
285 if (/^(Q\d{4}:)/) # Q initial paragraph
287 print OUT "<p>\n<a name=\"TOC$toc\" href=\"FAQ.html#TOC$toc\">$1</a>";
288 $_ = &process_non_display($');
289 print OUT "$_\n</p>\n";
294 if (/^A\d{4}:/) # A initial paragraph
296 $_ = &process_non_display($_);
297 s/^(A\d{4}:)/<font color="#00BB00">$1<\/font>/;
298 print OUT "<p>\n$_\n</p>\n";
302 # If a paragraph begins ==> it is a display which must remain verbatin
303 # and not be reformatted. The flag gets turned into spaces.
307 $_ = &process_display($_);
309 print OUT "<pre>\n$_</pre>\n";
312 # Non-display paragraph; massage the final line & my sig.
314 elsif (/^\*\*\* End of Exim FAQ \*\*\*/)
320 $_ = &process_non_display($_);
326 print OUT "<p>\n$_\n</p>\n";
332 print OUT "<hr><br>\n";
333 print OUT "<a href=\"FAQ.html#TOC\">Contents</a> \n";
334 printf OUT ("<a href=\"FAQ_%d.html\">Previous</a>\n", $sec-1);
336 print OUT "</body>\n</html>\n";