]>
gcc.gnu.org Git - gcc.git/blob - contrib/texi2pod.pl
3 # This does trivial (and I mean _trivial_) conversion of Texinfo
4 # markup to Perl POD format. It's intended to be used to extract
5 # something suitable for a manpage from a Texinfo document.
26 die "no flag specified for -D\n"
28 die "flags may only contain letters, digits, hyphens, and underscores\n"
29 unless $flag =~ /^[a-zA-Z0-9_-]+$/;
34 $in = $_, next unless defined $in;
35 $out = $_, next unless defined $out;
41 open(STDIN
, $in) or die "opening \"$in\": $!\n";
44 open(STDOUT, ">$out") or die "opening
\"$out\": $!\n";
50 /^\@c man begin ([A-Z]+)/ and $sect = $1, $output = 1, next;
51 /^\@c man end/ and do {
54 s/\@(?:dfn|var|emph|cite)\{([^\}]*)\}/I<$1>/g;
55 s/\@(?:code|kbd)\{([^\}]*)\}/C<$1>/g;
56 s/\@(?:samp|strong|key)\{([^\}]*)\}/B<$1>/g;
57 s/\@value\{([a-zA-Z0-9_-]+)\}/$defs{$1}/g;
58 s/\@sc\{([^\}]*)\}/\U$1/g;
59 s/\@file\{([^\}]*)\}/F<$1>/g;
60 s/\@(?:url|email)\{([^\}]*)\}/E<lt>C<$1>E<rt>/g;
61 s/\@xref\{(?:[^\}]*)\}[^.]*.//g;
62 s/\s+\(\@p[a-z]?ref\{(?:[^\}]*)\}\)//g;
68 # Turn B<blah I<blah> blah> into B<blah> I<blah> B<blah> to
69 # match Texinfo semantics of @emph inside @samp.
73 1 while (s/B<([^<>]*)I<([^>]+)>/B<$1>I<$2>B</g);
74 1 while (s/I<([^<>]*)B<([^>]+)>/I<$1>B<$2>I</g);
76 s/([BI])<(\s+)([^>]+)>/$2$1<$3>/g;
77 s/([BI])<([^>]+?)(\s+)>/$1<$2>$3/g;
90 /^\@(c|[a-z]+index)\b/ and next;
91 /^\@subsection/ and next;
95 /^\@setfilename\s+([^.]+)/ and $fn = $1, next;
96 /^\@settitle\s+([^.]+)/ and $tl = $1, next;
100 /^\@end\s+([a-z]+)/ and do {
103 die "\@$endw ended by \@end $1 at line $.\n"
106 if($endw =~ /example$/)
111 elsif($endw =~ /^if/)
113 $skipping = pop @skstack;
121 $endw = pop @endwstack;
125 /^\@end ignore/ and $ignore = 0, next;
129 /^\@ignore/ and $ignore = 1, next;
131 /^\@set\s+([a-zA-Z0-9_-]+)\s*(.*)$/ and $defs{$1} = $2, next;
132 /^\@clear\s+([a-zA-Z0-9_-]+)/ and delete $defs{$1}, next;
134 /^\@ifset\s+([a-zA-Z0-9_-]+)/ and do {
135 push @endwstack, $endw;
136 push @skstack, $skipping;
138 $skipping = 1 unless exists $defs{$1};
141 /^\@ifclear\s+([a-zA-Z0-9_-]+)/ and do {
142 push @endwstack, $endw;
143 push @skstack, $skipping;
145 $skipping = 1 if exists $defs{$1};
148 /^\@itemize (\@[a-z]+)/ and do {
149 push @endwstack, $endw;
152 $ic =~ s/\@bullet/*/;
158 /^\@enumerate\s+([A-Z0-9]+)/ and do {
159 push @endwstack, $endw;
166 /^\@table\s+(\@[a-z]+)/ and do {
167 push @endwstack, $endw;
170 $ic =~ s/\@(?:samp|strong|key)/B/;
171 $ic =~ s/\@(?:code|kbd)/C/;
172 $ic =~ s/\@(?:dfn|var|emph|cite)/I/;
173 $ic =~ s/\@(?:file)/F/;
178 /^\@((?:small)?example)/ and do {
179 push @endwstack, $endw;
185 /^\@itemx?\s*(.+)?$/ and do {
188 $_ = "=item $ic\<$1\>\n";
193 $ic =~ y/A-Ya-y1-8/B-Zb-z2-9/;
197 /^\@section\s+(.+)$/ and do {
198 $_ = "\n=head2 $1\n";
201 # POD doesn't interpret E<> inside a verbatim block.
211 $section .= $shift.$_."\n";
214 $sects{NAME
} = "$fn \- $tl\n";
216 for $sect (qw(NAME SYNOPSIS DESCRIPTION OPTIONS ENVIRONMENT FILES
217 BUGS NOTES SEEALSO AUTHOR COPYRIGHT))
219 if(exists $sects{$sect})
222 $head =~ s/SEEALSO/SEE ALSO/;
223 print "=head1 $head\n\n";
231 die "usage: $0 [-D toggle...] [infile [outfile]]\n";
This page took 0.058111 seconds and 6 git commands to generate.