4 This is a silly little program for generating the libc FAQ.
9 ? section name (one line)
15 {ID} name <email@address>
35 Answers were provided by:
40 # We slurp the whole file into a pair of assoc arrays indexed by
41 # the 'section.question' number.
46 # These arrays and counter keep track of the sections.
51 # Cross reference list.
55 $sepmaj = "\f\n" . ('~ ' x
36) . "\n\n";
56 $sepmin = "\f\n" . ('. ' x
36) . "\n\n";
58 # Pass through the top boilerplate.
70 $sectcount[$section] = $question;
77 $sectcount[$section] = $question if $section > 0;
79 $sections[$section] = $_;
83 s/^\?\?(\w*?)\s+// && do
87 $questions{$section,$question} = $_;
88 $refs{$1} = "$section.$question" if $1 ne "";
94 $answers{$section,$question} .= $_;
98 ${$cur}{$section,$question} .= $_;
101 # Now we have to clean up the newlines and deal with cross references.
102 foreach(keys %questions) { $questions{$_} =~ s/\n+$//; }
103 foreach(keys %answers)
105 $answers{$_} =~ s/\n+$//;
106 $answers{$_} =~ s/(\s)\?(\w+)\b/$1 . "question " . ($refs{$2} or badref($2,$_), "!!$2")/eg;
109 # Now output the formatted FAQ.
111 for($i = 1; $i <= $section; $i++)
113 print "$i. $sections[$i]\n\n";
114 for($j = 1; $j <= $sectcount[$i]; $j++)
116 print "$i.$j.\t$questions{$i,$j}\n";
122 for($i = 1; $i <= $section; $i++)
124 print "$i. $sections[$i]\n\n";
125 for($j = 1; $j <= $sectcount[$i]; $j++)
127 print "$i.$j.\t$questions{$i,$j}\n\n";
128 print $answers{$i,$j}, "\n\n";
129 print "\n" if $j < $sectcount[$i];
131 print $sepmin if $i < $section;
136 # Pass through the trailer.
141 my($ref,$quest) = @_;
143 print STDERR
"Undefined reference to $ref in answer to Q$quest\n";