]>
Commit | Line | Data |
---|---|---|
6251188c ZW |
1 | #! /usr/bin/perl -w |
2 | ||
386c4027 | 3 | # Copyright (C) 1999-2014 Free Software Foundation, Inc. |
6e26f4aa | 4 | |
487a9427 | 5 | # This file is part of GCC. |
6e26f4aa | 6 | |
487a9427 | 7 | # GCC is free software; you can redistribute it and/or modify |
6e26f4aa | 8 | # it under the terms of the GNU General Public License as published by |
3dfb41c5 | 9 | # the Free Software Foundation; either version 3, or (at your option) |
6e26f4aa JM |
10 | # any later version. |
11 | ||
487a9427 | 12 | # GCC is distributed in the hope that it will be useful, |
6e26f4aa JM |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | ||
17 | # You should have received a copy of the GNU General Public License | |
487a9427 | 18 | # along with GCC; see the file COPYING. If not, write to |
89ee9c70 KC |
19 | # the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
20 | # Boston MA 02110-1301, USA. | |
6e26f4aa | 21 | |
6251188c ZW |
22 | # This does trivial (and I mean _trivial_) conversion of Texinfo |
23 | # markup to Perl POD format. It's intended to be used to extract | |
24 | # something suitable for a manpage from a Texinfo document. | |
25 | ||
6251188c | 26 | $output = 0; |
3d6f4d76 | 27 | $skipping = 0; |
6251188c ZW |
28 | %sects = (); |
29 | $section = ""; | |
30 | @icstack = (); | |
31 | @endwstack = (); | |
3d6f4d76 | 32 | @skstack = (); |
049b03f4 | 33 | @instack = (); |
6251188c | 34 | $shift = ""; |
3d6f4d76 | 35 | %defs = (); |
b75d998f | 36 | $fnno = 1; |
049b03f4 ZW |
37 | $inf = ""; |
38 | $ibase = ""; | |
84309a32 | 39 | @ipath = (); |
6251188c | 40 | |
b75d998f | 41 | while ($_ = shift) { |
3d6f4d76 ZW |
42 | if (/^-D(.*)$/) { |
43 | if ($1 ne "") { | |
44 | $flag = $1; | |
45 | } else { | |
46 | $flag = shift; | |
47 | } | |
3da33af3 MK |
48 | $value = ""; |
49 | ($flag, $value) = ($flag =~ /^([^=]+)(?:=(.+))?/); | |
3d6f4d76 ZW |
50 | die "no flag specified for -D\n" |
51 | unless $flag ne ""; | |
3da33af3 | 52 | die "flags may only contain letters, digits, hyphens, dashes and underscores\n" |
3d6f4d76 | 53 | unless $flag =~ /^[a-zA-Z0-9_-]+$/; |
3da33af3 | 54 | $defs{$flag} = $value; |
84309a32 DJ |
55 | } elsif (/^-I(.*)$/) { |
56 | if ($1 ne "") { | |
57 | $flag = $1; | |
58 | } else { | |
59 | $flag = shift; | |
60 | } | |
61 | push (@ipath, $flag); | |
3d6f4d76 ZW |
62 | } elsif (/^-/) { |
63 | usage(); | |
64 | } else { | |
65 | $in = $_, next unless defined $in; | |
66 | $out = $_, next unless defined $out; | |
67 | usage(); | |
68 | } | |
69 | } | |
70 | ||
71 | if (defined $in) { | |
049b03f4 ZW |
72 | $inf = gensym(); |
73 | open($inf, "<$in") or die "opening \"$in\": $!\n"; | |
74 | $ibase = $1 if $in =~ m|^(.+)/[^/]+$|; | |
75 | } else { | |
76 | $inf = \*STDIN; | |
3d6f4d76 | 77 | } |
049b03f4 | 78 | |
3d6f4d76 ZW |
79 | if (defined $out) { |
80 | open(STDOUT, ">$out") or die "opening \"$out\": $!\n"; | |
81 | } | |
82 | ||
049b03f4 ZW |
83 | while(defined $inf) { |
84 | while(<$inf>) { | |
b75d998f ZW |
85 | # Certain commands are discarded without further processing. |
86 | /^\@(?: | |
87 | [a-z]+index # @*index: useful only in complete manual | |
88 | |need # @need: useful only in printed manual | |
89 | |(?:end\s+)?group # @group .. @end group: ditto | |
90 | |page # @page: ditto | |
91 | |node # @node: useful only in .info file | |
77bd67cb | 92 | |(?:end\s+)?ifnottex # @ifnottex .. @end ifnottex: use contents |
b75d998f | 93 | )\b/x and next; |
3da33af3 | 94 | |
6251188c | 95 | chomp; |
b75d998f ZW |
96 | |
97 | # Look for filename and title markers. | |
98 | /^\@setfilename\s+([^.]+)/ and $fn = $1, next; | |
3da33af3 MK |
99 | /^\@settitle\s+([^.]+)/ and $tl = postprocess($1), next; |
100 | ||
101 | # Identify a man title but keep only the one we are interested in. | |
102 | /^\@c\s+man\s+title\s+([A-Za-z0-9-]+)\s+(.+)/ and do { | |
103 | if (exists $defs{$1}) { | |
104 | $fn = $1; | |
105 | $tl = postprocess($2); | |
106 | } | |
107 | next; | |
108 | }; | |
b75d998f ZW |
109 | |
110 | # Look for blocks surrounded by @c man begin SECTION ... @c man end. | |
111 | # This really oughta be @ifman ... @end ifman and the like, but such | |
112 | # would require rev'ing all other Texinfo translators. | |
3da33af3 MK |
113 | /^\@c\s+man\s+begin\s+([A-Z]+)\s+([A-Za-z0-9-]+)/ and do { |
114 | $output = 1 if exists $defs{$2}; | |
115 | $sect = $1; | |
116 | next; | |
117 | }; | |
118 | /^\@c\s+man\s+begin\s+([A-Z]+)/ and $sect = $1, $output = 1, next; | |
119 | /^\@c\s+man\s+end/ and do { | |
f4e8dec6 ZW |
120 | $sects{$sect} = "" unless exists $sects{$sect}; |
121 | $sects{$sect} .= postprocess($section); | |
6251188c ZW |
122 | $section = ""; |
123 | $output = 0; | |
124 | next; | |
125 | }; | |
3da33af3 MK |
126 | |
127 | # handle variables | |
049b03f4 ZW |
128 | /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and do { |
129 | $defs{$1} = $2; | |
130 | next; | |
131 | }; | |
132 | /^\@clear\s+([a-zA-Z0-9_-]+)/ and do { | |
133 | delete $defs{$1}; | |
134 | next; | |
135 | }; | |
3da33af3 | 136 | |
b75d998f | 137 | next unless $output; |
3d6f4d76 | 138 | |
b75d998f ZW |
139 | # Discard comments. (Can't do it above, because then we'd never see |
140 | # @c man lines.) | |
141 | /^\@c\b/ and next; | |
6251188c | 142 | |
b75d998f ZW |
143 | # End-block handler goes up here because it needs to operate even |
144 | # if we are skipping. | |
145 | /^\@end\s+([a-z]+)/ and do { | |
f4e8dec6 ZW |
146 | # Ignore @end foo, where foo is not an operation which may |
147 | # cause us to skip, if we are presently skipping. | |
148 | my $ended = $1; | |
d6bef02d | 149 | next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/; |
f4e8dec6 ZW |
150 | |
151 | die "\@end $ended without \@$ended at line $.\n" unless defined $endw; | |
152 | die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw; | |
6251188c | 153 | |
b75d998f | 154 | $endw = pop @endwstack; |
6251188c | 155 | |
77bd67cb | 156 | if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) { |
b75d998f ZW |
157 | $skipping = pop @skstack; |
158 | next; | |
77bd67cb | 159 | } elsif ($ended =~ /^(?:example|smallexample|display)$/) { |
f4e8dec6 ZW |
160 | $shift = ""; |
161 | $_ = ""; # need a paragraph break | |
28852cc6 | 162 | } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) { |
b75d998f ZW |
163 | $_ = "\n=back\n"; |
164 | $ic = pop @icstack; | |
427e84f7 RS |
165 | } elsif ($ended eq "multitable") { |
166 | $_ = "\n=back\n"; | |
b01d215d | 167 | $ic = pop @icstack; |
f4e8dec6 ZW |
168 | } else { |
169 | die "unknown command \@end $ended at line $.\n"; | |
3d6f4d76 ZW |
170 | } |
171 | }; | |
f4e8dec6 ZW |
172 | |
173 | # We must handle commands which can cause skipping even while we | |
174 | # are skipping, otherwise we will not process nested conditionals | |
175 | # correctly. | |
176 | /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do { | |
177 | push @endwstack, $endw; | |
178 | push @skstack, $skipping; | |
179 | $endw = "ifset"; | |
180 | $skipping = 1 unless exists $defs{$1}; | |
181 | next; | |
182 | }; | |
183 | ||
184 | /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do { | |
185 | push @endwstack, $endw; | |
186 | push @skstack, $skipping; | |
187 | $endw = "ifclear"; | |
188 | $skipping = 1 if exists $defs{$1}; | |
189 | next; | |
190 | }; | |
191 | ||
d6bef02d | 192 | /^\@(ignore|menu|iftex|copying)\b/ and do { |
f4e8dec6 ZW |
193 | push @endwstack, $endw; |
194 | push @skstack, $skipping; | |
195 | $endw = $1; | |
196 | $skipping = 1; | |
197 | next; | |
198 | }; | |
199 | ||
3d6f4d76 ZW |
200 | next if $skipping; |
201 | ||
b75d998f ZW |
202 | # Character entities. First the ones that can be replaced by raw text |
203 | # or discarded outright: | |
204 | s/\@copyright\{\}/(c)/g; | |
205 | s/\@dots\{\}/.../g; | |
206 | s/\@enddots\{\}/..../g; | |
207 | s/\@([.!? ])/$1/g; | |
208 | s/\@[:-]//g; | |
209 | s/\@bullet(?:\{\})?/*/g; | |
210 | s/\@TeX\{\}/TeX/g; | |
211 | s/\@pounds\{\}/\#/g; | |
212 | s/\@minus(?:\{\})?/-/g; | |
3b015530 | 213 | s/\@tie\{\}/ /g; |
445c435a | 214 | s/\\,/,/g; |
6251188c | 215 | |
b75d998f ZW |
216 | # Now the ones that have to be replaced by special escapes |
217 | # (which will be turned back into text by unmunge()) | |
ab940b73 | 218 | # Replace @@ before @{ and @} in order to parse @samp{@@} correctly. |
b75d998f | 219 | s/&/&/g; |
ab940b73 | 220 | s/\@\@/&at;/g; |
b75d998f ZW |
221 | s/\@\{/{/g; |
222 | s/\@\}/}/g; | |
ab940b73 | 223 | s/\@`\{(.)\}/&$1grave;/g; |
77bd67cb | 224 | |
7f9766e4 | 225 | # Inside a verbatim block, handle @var, @samp and @url specially. |
77bd67cb JM |
226 | if ($shift ne "") { |
227 | s/\@var\{([^\}]*)\}/<$1>/g; | |
7f9766e4 JM |
228 | s/\@samp\{([^\}]*)\}/"$1"/g; |
229 | s/\@url\{([^\}]*)\}/<$1>/g; | |
77bd67cb JM |
230 | } |
231 | ||
b75d998f ZW |
232 | # POD doesn't interpret E<> inside a verbatim block. |
233 | if ($shift eq "") { | |
234 | s/</</g; | |
235 | s/>/>/g; | |
236 | } else { | |
237 | s/</</g; | |
238 | s/>/>/g; | |
239 | } | |
240 | ||
241 | # Single line command handlers. | |
3d6f4d76 | 242 | |
049b03f4 ZW |
243 | /^\@include\s+(.+)$/ and do { |
244 | push @instack, $inf; | |
245 | $inf = gensym(); | |
901097db | 246 | $file = postprocess($1); |
049b03f4 | 247 | |
84309a32 DJ |
248 | # Try cwd and $ibase, then explicit -I paths. |
249 | $done = 0; | |
5dd59f65 DJ |
250 | foreach $path ("", $ibase, @ipath) { |
251 | $mypath = $file; | |
252 | $mypath = $path . "/" . $mypath if ($path ne ""); | |
253 | open($inf, "<" . $mypath) and ($done = 1, last); | |
84309a32 DJ |
254 | } |
255 | die "cannot find $file" if !$done; | |
049b03f4 ZW |
256 | next; |
257 | }; | |
258 | ||
7f9766e4 | 259 | /^\@(?:section|unnumbered|unnumberedsec|center|heading)\s+(.+)$/ |
049b03f4 ZW |
260 | and $_ = "\n=head2 $1\n"; |
261 | /^\@subsection\s+(.+)$/ | |
262 | and $_ = "\n=head3 $1\n"; | |
d0fc3f06 MK |
263 | /^\@subsubsection\s+(.+)$/ |
264 | and $_ = "\n=head4 $1\n"; | |
b75d998f ZW |
265 | |
266 | # Block command handlers: | |
9fa09038 | 267 | /^\@itemize(?:\s+(\@[a-z]+|\*|-))?/ and do { |
6251188c ZW |
268 | push @endwstack, $endw; |
269 | push @icstack, $ic; | |
9fa09038 MK |
270 | if (defined $1) { |
271 | $ic = $1; | |
272 | } else { | |
3caecafa | 273 | $ic = '*'; |
9fa09038 | 274 | } |
6251188c ZW |
275 | $_ = "\n=over 4\n"; |
276 | $endw = "itemize"; | |
277 | }; | |
278 | ||
77bd67cb | 279 | /^\@enumerate(?:\s+([a-zA-Z0-9]+))?/ and do { |
6251188c ZW |
280 | push @endwstack, $endw; |
281 | push @icstack, $ic; | |
b75d998f ZW |
282 | if (defined $1) { |
283 | $ic = $1 . "."; | |
284 | } else { | |
285 | $ic = "1."; | |
286 | } | |
6251188c ZW |
287 | $_ = "\n=over 4\n"; |
288 | $endw = "enumerate"; | |
289 | }; | |
290 | ||
427e84f7 RS |
291 | /^\@multitable\s.*/ and do { |
292 | push @endwstack, $endw; | |
b01d215d | 293 | push @icstack, $ic; |
427e84f7 | 294 | $endw = "multitable"; |
b01d215d | 295 | $ic = ""; |
427e84f7 RS |
296 | $_ = "\n=over 4\n"; |
297 | }; | |
298 | ||
049b03f4 | 299 | /^\@([fv]?table)\s+(\@[a-z]+)/ and do { |
6251188c ZW |
300 | push @endwstack, $endw; |
301 | push @icstack, $ic; | |
049b03f4 ZW |
302 | $endw = $1; |
303 | $ic = $2; | |
2642624b | 304 | $ic =~ s/\@(?:samp|strong|key|gcctabopt|env)/B/; |
6251188c | 305 | $ic =~ s/\@(?:code|kbd)/C/; |
b75d998f | 306 | $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/; |
6251188c | 307 | $ic =~ s/\@(?:file)/F/; |
7b6cb843 | 308 | $ic =~ s/\@(?:asis)//; |
6251188c | 309 | $_ = "\n=over 4\n"; |
6251188c ZW |
310 | }; |
311 | ||
77bd67cb | 312 | /^\@((?:small)?example|display)/ and do { |
6251188c ZW |
313 | push @endwstack, $endw; |
314 | $endw = $1; | |
315 | $shift = "\t"; | |
f4e8dec6 | 316 | $_ = ""; # need a paragraph break |
6251188c ZW |
317 | }; |
318 | ||
b01d215d | 319 | /^\@(headitem|item)\s+(.*\S)\s*$/ and $endw eq "multitable" and do { |
427e84f7 | 320 | @columns = (); |
b01d215d RS |
321 | $item = $1; |
322 | for $column (split (/\s*\@tab\s*/, $2)) { | |
427e84f7 | 323 | # @strong{...} is used a @headitem work-alike |
4b5ed6cf | 324 | $column =~ s/^\@strong\{(.*)\}$/$1/; |
b01d215d | 325 | $column = "I<$column>" if $item eq "headitem"; |
427e84f7 RS |
326 | push @columns, $column; |
327 | } | |
328 | $_ = "\n=item ".join (" : ", @columns)."\n"; | |
329 | }; | |
330 | ||
6251188c | 331 | /^\@itemx?\s*(.+)?$/ and do { |
b75d998f | 332 | if (defined $1) { |
7b6cb843 | 333 | if ($ic) { |
7f9766e4 JM |
334 | if ($endw eq "enumerate") { |
335 | $_ = "\n=item $ic $1\n"; | |
336 | $ic =~ s/(\d+)/$1 + 1/eg; | |
337 | } else { | |
338 | # Entity escapes prevent munging by the <> | |
339 | # processing below. | |
340 | $_ = "\n=item $ic\<$1\>\n"; | |
341 | } | |
7b6cb843 MLI |
342 | } else { |
343 | $_ = "\n=item $1\n"; | |
344 | } | |
b75d998f | 345 | } else { |
386c4027 | 346 | $_ = "\n=item Z\<\>$ic\n"; |
77bd67cb JM |
347 | $ic =~ y/A-Ya-y/B-Zb-z/; |
348 | $ic =~ s/(\d+)/$1 + 1/eg; | |
6251188c ZW |
349 | } |
350 | }; | |
3d6f4d76 | 351 | |
6251188c ZW |
352 | $section .= $shift.$_."\n"; |
353 | } | |
049b03f4 ZW |
354 | # End of current file. |
355 | close($inf); | |
356 | $inf = pop @instack; | |
357 | } | |
6251188c | 358 | |
b75d998f ZW |
359 | die "No filename or title\n" unless defined $fn && defined $tl; |
360 | ||
6251188c | 361 | $sects{NAME} = "$fn \- $tl\n"; |
b75d998f | 362 | $sects{FOOTNOTES} .= "=back\n" if exists $sects{FOOTNOTES}; |
6251188c ZW |
363 | |
364 | for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES | |
b75d998f ZW |
365 | BUGS NOTES FOOTNOTES SEEALSO AUTHOR COPYRIGHT)) { |
366 | if(exists $sects{$sect}) { | |
6251188c ZW |
367 | $head = $sect; |
368 | $head =~ s/SEEALSO/SEE ALSO/; | |
369 | print "=head1 $head\n\n"; | |
b75d998f | 370 | print scalar unmunge ($sects{$sect}); |
6251188c ZW |
371 | print "\n"; |
372 | } | |
373 | } | |
3d6f4d76 ZW |
374 | |
375 | sub usage | |
376 | { | |
377 | die "usage: $0 [-D toggle...] [infile [outfile]]\n"; | |
378 | } | |
b75d998f ZW |
379 | |
380 | sub postprocess | |
381 | { | |
382 | local $_ = $_[0]; | |
383 | ||
384 | # @value{foo} is replaced by whatever 'foo' is defined as. | |
3da33af3 MK |
385 | while (m/(\@value\{([a-zA-Z0-9_-]+)\})/g) { |
386 | if (! exists $defs{$2}) { | |
387 | print STDERR "Option $2 not defined\n"; | |
388 | s/\Q$1\E//; | |
389 | } else { | |
390 | $value = $defs{$2}; | |
391 | s/\Q$1\E/$value/; | |
392 | } | |
393 | } | |
b75d998f ZW |
394 | |
395 | # Formatting commands. | |
4bc1997b JM |
396 | # Temporary escape for @r. |
397 | s/\@r\{([^\}]*)\}/R<$1>/g; | |
6f853fd4 | 398 | s/\@sc\{([^\}]*)\}/\U$1/g; |
b75d998f ZW |
399 | s/\@(?:dfn|var|emph|cite|i)\{([^\}]*)\}/I<$1>/g; |
400 | s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g; | |
7b6cb843 | 401 | s/\@(?:samp|strong|key|option|env|command|b)\{([^\}]*)\}/B<$1>/g; |
ab940b73 | 402 | s/\@acronym\{([^\}]*)\}/\U$1/g; |
b75d998f ZW |
403 | s/\@file\{([^\}]*)\}/F<$1>/g; |
404 | s/\@w\{([^\}]*)\}/S<$1>/g; | |
405 | s/\@(?:dmn|math)\{([^\}]*)\}/$1/g; | |
ab940b73 | 406 | s/\@\///g; |
6f853fd4 | 407 | s/\@t\{([^\}]*)\}/$1/g; |
b75d998f | 408 | |
df6e87bf MK |
409 | # keep references of the form @ref{...}, print them bold |
410 | s/\@(?:ref)\{([^\}]*)\}/B<$1>/g; | |
411 | ||
0928f405 BW |
412 | # Change double single quotes to double quotes. |
413 | s/''/"/g; | |
414 | s/``/"/g; | |
415 | ||
b75d998f ZW |
416 | # Cross references are thrown away, as are @noindent and @refill. |
417 | # (@noindent is impossible in .pod, and @refill is unnecessary.) | |
418 | # @* is also impossible in .pod; we discard it and any newline that | |
4bc1997b | 419 | # follows it. Similarly, our macro @gol must be discarded. |
b75d998f | 420 | |
4bc1997b | 421 | s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g; |
b75d998f ZW |
422 | s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g; |
423 | s/;\s+\@pxref\{(?:[^\}]*)\}//g; | |
424 | s/\@noindent\s*//g; | |
425 | s/\@refill//g; | |
4bc1997b | 426 | s/\@gol//g; |
b75d998f ZW |
427 | s/\@\*\s*\n?//g; |
428 | ||
d0fc3f06 MK |
429 | # Anchors are thrown away |
430 | s/\@anchor\{(?:[^\}]*)\}//g; | |
431 | ||
b75d998f ZW |
432 | # @uref can take one, two, or three arguments, with different |
433 | # semantics each time. @url and @email are just like @uref with | |
434 | # one argument, for our purposes. | |
2642624b | 435 | s/\@(?:uref|url|email)\{([^\},]*)\}/<B<$1>>/g; |
b75d998f ZW |
436 | s/\@uref\{([^\},]*),([^\},]*)\}/$2 (C<$1>)/g; |
437 | s/\@uref\{([^\},]*),([^\},]*),([^\},]*)\}/$3/g; | |
438 | ||
7b6cb843 MLI |
439 | # Handle gccoptlist here, so it can contain the above formatting |
440 | # commands. | |
441 | s/\@gccoptlist\{([^\}]*)\}/B<$1>/g; | |
442 | ||
dd6773cd | 443 | # Un-escape <> at this point. |
b75d998f ZW |
444 | s/</</g; |
445 | s/>/>/g; | |
dd6773cd ZW |
446 | |
447 | # Now un-nest all B<>, I<>, R<>. Theoretically we could have | |
448 | # indefinitely deep nesting; in practice, one level suffices. | |
449 | 1 while s/([BIR])<([^<>]*)([BIR])<([^<>]*)>/$1<$2>$3<$4>$1</g; | |
450 | ||
451 | # Replace R<...> with bare ...; eliminate empty markup, B<>; | |
452 | # shift white space at the ends of [BI]<...> expressions outside | |
453 | # the expression. | |
454 | s/R<([^<>]*)>/$1/g; | |
b75d998f ZW |
455 | s/[BI]<>//g; |
456 | s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g; | |
457 | s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g; | |
458 | ||
459 | # Extract footnotes. This has to be done after all other | |
460 | # processing because otherwise the regexp will choke on formatting | |
461 | # inside @footnote. | |
462 | while (/\@footnote/g) { | |
463 | s/\@footnote\{([^\}]+)\}/[$fnno]/; | |
464 | add_footnote($1, $fnno); | |
465 | $fnno++; | |
466 | } | |
467 | ||
468 | return $_; | |
469 | } | |
470 | ||
471 | sub unmunge | |
472 | { | |
473 | # Replace escaped symbols with their equivalents. | |
474 | local $_ = $_[0]; | |
475 | ||
ab940b73 | 476 | s/&(.)grave;/E<$1grave>/g; |
b75d998f ZW |
477 | s/</E<lt>/g; |
478 | s/>/E<gt>/g; | |
479 | s/{/\{/g; | |
480 | s/}/\}/g; | |
481 | s/&at;/\@/g; | |
482 | s/&/&/g; | |
483 | return $_; | |
484 | } | |
485 | ||
486 | sub add_footnote | |
487 | { | |
488 | unless (exists $sects{FOOTNOTES}) { | |
489 | $sects{FOOTNOTES} = "\n=over 4\n\n"; | |
490 | } | |
491 | ||
492 | $sects{FOOTNOTES} .= "=item $fnno.\n\n"; $fnno++; | |
493 | $sects{FOOTNOTES} .= $_[0]; | |
494 | $sects{FOOTNOTES} .= "\n\n"; | |
495 | } | |
049b03f4 ZW |
496 | |
497 | # stolen from Symbol.pm | |
498 | { | |
499 | my $genseq = 0; | |
500 | sub gensym | |
501 | { | |
502 | my $name = "GEN" . $genseq++; | |
503 | my $ref = \*{$name}; | |
504 | delete $::{$name}; | |
505 | return $ref; | |
506 | } | |
507 | } |