3 # htmlify-cystic-l-faq: turn text version of cystic-l faq into html
4 # run like this: htmlify-cystic-l-faq < cystic-l-faq-all
6 # Ron Trueworthy should put the date on the FAQ.
18 my $new_tag = "[NEW]";
21 { die "Can't find faq directory"; }
29 my $this_file_toc = "";
32 my @output_files = ();
38 while (defined($line = <>))
41 if ($line =~ /^From /)
42 { while ($line ne "\n")
45 if ($line =~ /^See PART ONE of this FAQ for/)
46 { while (defined($line = <>) && ($line ne "\n"))
50 if ($line =~ /^\s*[-+]+$/)
54 if ($line =~ /^\s*CYSTIC-L Frequently Asked Questions - PART (.*)\n$/)
55 { # print "part $1\n";
59 { die "output_file shouldn't have been set yet: $output_file"; }
60 $output_file = "faq/index.html";
61 open(OUTPUT, ">$output_file") || die "Couldn't open $output_file";
64 <TITLE>CYSTIC-L FAQ Table of Contents
68 <H1>CYSTIC-L Frequently Asked Questions</H1>
69 <h2>Knowledge Is Power</h2>
73 if ($line =~ /^\s*~ Knowledge Is Power ~$/)
77 if ($line =~ /^\s*~ FAQ Table of Contents ~$/)
79 print "<hr><a href=\"../\">Info-Zone</a> <a href=\"../../\">CF-WEB</a>\n";
84 if ($line =~ /^PART /)
87 if ($line =~ s/^>?APPENDIX ([A-Z])\.\s*//)
88 { if (!defined($appendix))
90 { die "First appendix is $1"; } }
91 elsif ($1 ne chr(ord($appendix)+1))
92 { die "Appendix $1 follows Appendix $appendix"; }
99 $subsubsection = undef;
100 $output_file = section_url_base();
101 open(OUTPUT, "> faq/$output_file") || die "Can't open faq/$output_file";
105 print "<title>$line</title>\n<h1>$line</h1>\n";
106 if (defined($file_tocs{$output_file}) && $file_tocs{$output_file})
107 { print "Contents: $file_tocs{$output_file}\n"; }
110 if (($line =~ /^>?([0-9]+)\.\s+/) && (!defined($section) || ($1 == $section+1)))
111 { $line =~ s/^>?([0-9]+)\.\s+//;
112 if (!defined($appendix))
113 { # should do some more here
114 if (defined($section))
119 $subsubsection = undef;
120 $output_file = section_url_base();
121 if (!defined($appendix))
122 { open(OUTPUT, "> faq/$output_file") || die "Can't open faq/$output_file";
125 print "<title>$line</title>\n<h1>$line</h1>\n";
126 if (defined($file_tocs{$output_file}) && $file_tocs{$output_file})
127 { print "Contents: $file_tocs{$output_file}\n"; }
131 if ($line =~ s/^>?o\s+//)
132 { $line =~ s/^>//; # sometimes the > follows the itemization
133 if (!defined($subsection))
137 $subsubsection = undef;
138 print "<h2>", section_name($line), "</h2>\n";
141 if ($line =~ s/^>?-\s+//)
142 { $line =~ s/^>//; # sometimes the > follows the itemization
143 if (!defined($subsubsection))
144 { $subsubsection = 1; }
146 { $subsubsection++; }
147 print "<h3>", section_name($line), "</h3>\n";
150 ### A paragraph of ordinary text
151 if ($line !~ /^\s*$/)
153 while (defined($line = <>) && ($line ne "\n"))
161 my $subsection_marker;
166 { # These variables are initially undefined
167 if (defined($appendix)
169 || defined($subsection)
170 || defined($subsubsection))
171 { die "some value should have been undefined when calling read_toc: `$appendix' `$section' `$subsection' `$subsubsection'"; }
173 while (defined($line = <>) && $line)
174 { if ($line =~ /^\s*$/)
176 if ($line =~ /^\s*\((Portions updated since.*)>\)\n/)
177 { print "$1$new_tag<p>\n";
179 if ($line =~ /^PART (.*)$/)
180 # { if ($MATCH eq "ONE")
183 if ($line eq "APPENDICES\n")
185 if ($line =~ /^\s*INDEX/)
188 if ($line =~ /^\s*[-+]+$/)
189 { finish_appendices();
190 if (defined($appendix)
192 || defined($subsection)
193 || defined($subsubsection))
194 { die "some value should have been undefined when exiting read_toc: `$appendix' `$section' `$subsection' `$subsubsection'"; }
197 $new = ($line =~ s/>//);
199 # # Not sure if this is the right place to do this.
200 # if (($line !~ /^\s*([-o]|[0-9A-Z]+\.|APPENDIX [A-Z]\.)/)
201 # && ($line !~ /[ .]*[0-9]+$/))
202 # { die "What line? $line"; }
203 while (!($line =~ s/[ .]*[0-9]+$//))
207 if ($line =~ s/^\s*APPENDIX ([A-Z])\.\s*//)
209 if (!defined($appendix))
211 { die "First appendix is $1"; }
212 print "Appendices\n";
213 print "<ol type=\"A\" start=\"$1\">\n"; }
214 elsif ($1 ne chr(ord($appendix)+1))
215 { die "Appendix $1 follows Appendix $appendix"; }
217 $appendix_name[ord($appendix)-ord('A')+1] = $line;
218 my $entry = toc_line($line);
220 push(@output_files,section_url_base());
223 if ($line =~ s/^\s*([0-9]+)\.\s*//)
224 { finish_subsections();
225 if (!defined($section))
226 { my $entry = "<ol start=$1>\n";
228 if (defined($appendix))
229 { $this_file_toc .= $entry; } }
230 elsif ($1 != $section+1)
231 { die "Section $1 follows section $section"; }
233 $section_name[$section] = $line;
234 my $entry = " " . toc_line($line);
236 if (defined($appendix))
237 { $this_file_toc .= $entry; }
239 { push(@output_files,section_url_base()); }
242 if ($line =~ s/^\s*o\s+//)
243 { if (!defined($subsection))
245 my $entry = " <ul>\n";
247 $this_file_toc .= $entry;
248 $subsection_marker = "ul"; }
250 { finish_subsubsections();
252 my $entry = " " . toc_line($line);
254 $this_file_toc .= $entry;
257 if ($line =~ s/^\s*([A-Z])\.\s+//)
258 { finish_subsubsections();
259 if (!defined($subsection))
260 { my $entry = " <ol type=\"A\" start=\"$1\">\n";
262 $this_file_toc .= $entry;
263 $subsection_marker = "ol"; }
265 { if ($1 ne chr(ord($subsection)+1))
266 { die "Subsection $1 follows subsection $subsection"; } }
268 my $entry = " " . toc_line($line);
270 $this_file_toc .= $entry;
273 if ($line =~ s/^\s*-\s+//)
274 { if (!defined($subsubsection))
275 { $subsubsection = 1;
276 my $entry = " <ul>\n";
278 $this_file_toc .= $entry; }
280 { $subsubsection++; }
281 my $entry = " " . toc_line($line);
283 $this_file_toc .= $entry;
286 # Itemized line without leading "o" (grrr).
287 if (!defined($subsection))
288 { my $entry = " <ul>\n";
290 $this_file_toc .= $entry;
292 $subsection_marker = "ul"; }
296 my $entry = " " . toc_line($line);
297 $this_file_toc .= $entry;
302 sub finish_subsubsections ()
303 { if (defined($subsubsection))
304 { my $entry = " </ul>\n";
306 $this_file_toc .= $entry;
307 $subsubsection = undef; } }
309 sub finish_subsections ()
310 { finish_subsubsections();
311 if (defined($subsection))
312 { my $entry = " </$subsection_marker>\n";
314 $this_file_toc .= $entry;
316 if (!defined($appendix))
317 { $file_tocs{section_url_base()} = $this_file_toc;
318 $this_file_toc = ""; } } }
320 sub finish_sections ()
321 { finish_subsections();
322 if (defined($section))
323 { my $entry = " </ol>\n";
325 if (defined($appendix))
326 { $this_file_toc .= $entry;
327 $file_tocs{section_url_base()} = $this_file_toc;
328 $this_file_toc = ""; }
329 $section = undef; } }
331 sub finish_appendices ()
333 if (defined($appendix))
335 $appendix = undef; } }
337 sub section_url_base ()
338 { if (!defined($appendix) && !defined($section))
339 { die "undefined appendix and section"; }
340 return (defined($appendix) ? "app-$appendix.html" : "sec-$section.html"); }
342 sub section_url_name ()
343 { my $sans_subsubsection
344 = (defined($appendix)
346 ? "sec-$section" . (defined($subsection)
347 ? "-$subsection" : "")
349 : (defined($subsection) ? "ssec-$subsection" : ""));
350 if (defined($subsubsection))
351 { $sans_subsubsection . "-$subsubsection"; }
353 { $sans_subsubsection; } }
356 { my $base = section_url_base();
357 my $name = section_url_name();
359 { return $base . "\#" . $name; }
366 return "<a href=\"" . section_url() . "\">$text</a>"; }
370 return "<a name=\"" . section_url_name() . "\">$text</a>"; }
373 { return " <LI>" . section_href($line) . ($new ? " $new_tag" : "") . "\n"; }
377 . (($file_index < $#output_files)
378 ? "<a href=\"$output_files[$file_index+1]\">Next</a> " : "")
380 ? "<a href=\"$output_files[$file_index-1]\">Previous</a> " : "")
381 . "<a href=\"./\">FAQ</a> <a href=\"../\">Info-Zone</a> <a href=\"../../\">CF-WEB</a>\n";