xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/pod/pod2text.PL (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/local/bin/perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse Config;
4*0Sstevel@tonic-gateuse File::Basename qw(&basename &dirname);
5*0Sstevel@tonic-gateuse Cwd;
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gate# List explicitly here the variables you want Configure to
8*0Sstevel@tonic-gate# generate.  Metaconfig only looks for shell variables, so you
9*0Sstevel@tonic-gate# have to mention them as if they were shell variables, not
10*0Sstevel@tonic-gate# %Config entries.  Thus you write
11*0Sstevel@tonic-gate#  $startperl
12*0Sstevel@tonic-gate# to ensure Configure will look for $Config{startperl}.
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate# This forces PL files to create target in same directory as PL file.
15*0Sstevel@tonic-gate# This is so that make depend always knows where to find PL derivatives.
16*0Sstevel@tonic-gate$origdir = cwd;
17*0Sstevel@tonic-gatechdir dirname($0);
18*0Sstevel@tonic-gate$file = basename($0, '.PL');
19*0Sstevel@tonic-gate$file .= '.com' if $^O eq 'VMS';
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gateopen OUT,">$file" or die "Can't create $file: $!";
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gateprint "Extracting $file (with variable substitutions)\n";
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate# In this section, perl variables will be expanded during extraction.
26*0Sstevel@tonic-gate# You can use $Config{...} to use Configure variables.
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gateprint OUT <<"!GROK!THIS!";
29*0Sstevel@tonic-gate$Config{startperl}
30*0Sstevel@tonic-gate    eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
31*0Sstevel@tonic-gate        if \$running_under_some_shell;
32*0Sstevel@tonic-gate!GROK!THIS!
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate# In the following, perl variables are not expanded during extraction.
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gateprint OUT <<'!NO!SUBS!';
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate# pod2text -- Convert POD data to formatted ASCII text.
39*0Sstevel@tonic-gate#
40*0Sstevel@tonic-gate# Copyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>
41*0Sstevel@tonic-gate#
42*0Sstevel@tonic-gate# This program is free software; you may redistribute it and/or modify it
43*0Sstevel@tonic-gate# under the same terms as Perl itself.
44*0Sstevel@tonic-gate#
45*0Sstevel@tonic-gate# The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
46*0Sstevel@tonic-gate# invoked by perldoc -t among other things.
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gaterequire 5.004;
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gateuse Getopt::Long qw(GetOptions);
51*0Sstevel@tonic-gateuse Pod::Text ();
52*0Sstevel@tonic-gateuse Pod::Usage qw(pod2usage);
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gateuse strict;
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate# Silence -w warnings.
57*0Sstevel@tonic-gateuse vars qw($running_under_some_shell);
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate# Take an initial pass through our options, looking for one of the form
60*0Sstevel@tonic-gate# -<number>.  We turn that into -w <number> for compatibility with the
61*0Sstevel@tonic-gate# original pod2text script.
62*0Sstevel@tonic-gatefor (my $i = 0; $i < @ARGV; $i++) {
63*0Sstevel@tonic-gate    last if $ARGV[$i] =~ /^--$/;
64*0Sstevel@tonic-gate    if ($ARGV[$i] =~ /^-(\d+)$/) {
65*0Sstevel@tonic-gate        splice (@ARGV, $i++, 1, '-w', $1);
66*0Sstevel@tonic-gate    }
67*0Sstevel@tonic-gate}
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate# Insert -- into @ARGV before any single dash argument to hide it from
70*0Sstevel@tonic-gate# Getopt::Long; we want to interpret it as meaning stdin (which Pod::Parser
71*0Sstevel@tonic-gate# does correctly).
72*0Sstevel@tonic-gatemy $stdin;
73*0Sstevel@tonic-gate@ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate# Parse our options.  Use the same names as Pod::Text for simplicity, and
76*0Sstevel@tonic-gate# default to sentence boundaries turned off for compatibility.
77*0Sstevel@tonic-gatemy %options;
78*0Sstevel@tonic-gate$options{sentence} = 0;
79*0Sstevel@tonic-gateGetopt::Long::config ('bundling');
80*0Sstevel@tonic-gateGetOptions (\%options, 'alt|a', 'code', 'color|c', 'help|h', 'indent|i=i',
81*0Sstevel@tonic-gate            'loose|l', 'margin|left-margin|m=i', 'overstrike|o',
82*0Sstevel@tonic-gate            'quotes|q=s', 'sentence|s', 'termcap|t', 'width|w=i') or exit 1;
83*0Sstevel@tonic-gatepod2usage (1) if $options{help};
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate# Figure out what formatter we're going to use.  -c overrides -t.
86*0Sstevel@tonic-gatemy $formatter = 'Pod::Text';
87*0Sstevel@tonic-gateif ($options{color}) {
88*0Sstevel@tonic-gate    $formatter = 'Pod::Text::Color';
89*0Sstevel@tonic-gate    eval { require Term::ANSIColor };
90*0Sstevel@tonic-gate    if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
91*0Sstevel@tonic-gate    require Pod::Text::Color;
92*0Sstevel@tonic-gate} elsif ($options{termcap}) {
93*0Sstevel@tonic-gate    $formatter = 'Pod::Text::Termcap';
94*0Sstevel@tonic-gate    require Pod::Text::Termcap;
95*0Sstevel@tonic-gate} elsif ($options{overstrike}) {
96*0Sstevel@tonic-gate    $formatter = 'Pod::Text::Overstrike';
97*0Sstevel@tonic-gate    require Pod::Text::Overstrike;
98*0Sstevel@tonic-gate}
99*0Sstevel@tonic-gatedelete @options{'color', 'termcap', 'overstrike'};
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate# Initialize and run the formatter.
102*0Sstevel@tonic-gatemy $parser = $formatter->new (%options);
103*0Sstevel@tonic-gate$parser->parse_from_file (@ARGV);
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate__END__
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate=head1 NAME
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gatepod2text - Convert POD data to formatted ASCII text
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate=head1 SYNOPSIS
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gatepod2text [B<-aclost>] [B<--code>] [B<-i> I<indent>] S<[B<-q> I<quotes>]>
114*0Sstevel@tonic-gateS<[B<-w> I<width>]> [I<input> [I<output>]]
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gatepod2text B<-h>
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate=head1 DESCRIPTION
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gateB<pod2text> is a front-end for Pod::Text and its subclasses.  It uses them
121*0Sstevel@tonic-gateto generate formatted ASCII text from POD source.  It can optionally use
122*0Sstevel@tonic-gateeither termcap sequences or ANSI color escape sequences to format the text.
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gateI<input> is the file to read for POD source (the POD can be embedded in
125*0Sstevel@tonic-gatecode).  If I<input> isn't given, it defaults to STDIN.  I<output>, if given,
126*0Sstevel@tonic-gateis the file to which to write the formatted output.  If I<output> isn't
127*0Sstevel@tonic-gategiven, the formatted output is written to STDOUT.
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate=head1 OPTIONS
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate=over 4
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate=item B<-a>, B<--alt>
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gateUse an alternate output format that, among other things, uses a different
136*0Sstevel@tonic-gateheading style and marks C<=item> entries with a colon in the left margin.
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate=item B<--code>
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gateInclude any non-POD text from the input file in the output as well.  Useful
141*0Sstevel@tonic-gatefor viewing code documented with POD blocks with the POD rendered and the
142*0Sstevel@tonic-gatecode left intact.
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate=item B<-c>, B<--color>
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gateFormat the output with ANSI color escape sequences.  Using this option
147*0Sstevel@tonic-gaterequires that Term::ANSIColor be installed on your system.
148*0Sstevel@tonic-gate
149*0Sstevel@tonic-gate=item B<-i> I<indent>, B<--indent=>I<indent>
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gateSet the number of spaces to indent regular text, and the default indentation
152*0Sstevel@tonic-gatefor C<=over> blocks.  Defaults to 4 spaces if this option isn't given.
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate=item B<-h>, B<--help>
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gatePrint out usage information and exit.
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate=item B<-l>, B<--loose>
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gatePrint a blank line after a C<=head1> heading.  Normally, no blank line is
161*0Sstevel@tonic-gateprinted after C<=head1>, although one is still printed after C<=head2>,
162*0Sstevel@tonic-gatebecause this is the expected formatting for manual pages; if you're
163*0Sstevel@tonic-gateformatting arbitrary text documents, using this option is recommended.
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate=item B<-m> I<width>, B<--left-margin>=I<width>, B<--margin>=I<width>
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gateThe width of the left margin in spaces.  Defaults to 0.  This is the margin
168*0Sstevel@tonic-gatefor all text, including headings, not the amount by which regular text is
169*0Sstevel@tonic-gateindented; for the latter, see B<-i> option.
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate=item B<-o>, B<--overstrike>
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gateFormat the output with overstruck printing.  Bold text is rendered as
174*0Sstevel@tonic-gatecharacter, backspace, character.  Italics and file names are rendered as
175*0Sstevel@tonic-gateunderscore, backspace, character.  Many pagers, such as B<less>, know how
176*0Sstevel@tonic-gateto convert this to bold or underlined text.
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate=item B<-q> I<quotes>, B<--quotes>=I<quotes>
179*0Sstevel@tonic-gate
180*0Sstevel@tonic-gateSets the quote marks used to surround CE<lt>> text to I<quotes>.  If
181*0Sstevel@tonic-gateI<quotes> is a single character, it is used as both the left and right
182*0Sstevel@tonic-gatequote; if I<quotes> is two characters, the first character is used as the
183*0Sstevel@tonic-gateleft quote and the second as the right quoted; and if I<quotes> is four
184*0Sstevel@tonic-gatecharacters, the first two are used as the left quote and the second two as
185*0Sstevel@tonic-gatethe right quote.
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gateI<quotes> may also be set to the special value C<none>, in which case no
188*0Sstevel@tonic-gatequote marks are added around CE<lt>> text.
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate=item B<-s>, B<--sentence>
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gateAssume each sentence ends with two spaces and try to preserve that spacing.
193*0Sstevel@tonic-gateWithout this option, all consecutive whitespace in non-verbatim paragraphs
194*0Sstevel@tonic-gateis compressed into a single space.
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate=item B<-t>, B<--termcap>
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gateTry to determine the width of the screen and the bold and underline
199*0Sstevel@tonic-gatesequences for the terminal from termcap, and use that information in
200*0Sstevel@tonic-gateformatting the output.  Output will be wrapped at two columns less than the
201*0Sstevel@tonic-gatewidth of your terminal device.  Using this option requires that your system
202*0Sstevel@tonic-gatehave a termcap file somewhere where Term::Cap can find it and requires that
203*0Sstevel@tonic-gateyour system support termios.  With this option, the output of B<pod2text>
204*0Sstevel@tonic-gatewill contain terminal control sequences for your current terminal type.
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate=item B<-w>, B<--width=>I<width>, B<->I<width>
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gateThe column at which to wrap text on the right-hand side.  Defaults to 76,
209*0Sstevel@tonic-gateunless B<-t> is given, in which case it's two columns less than the width of
210*0Sstevel@tonic-gateyour terminal device.
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate=back
213*0Sstevel@tonic-gate
214*0Sstevel@tonic-gate=head1 DIAGNOSTICS
215*0Sstevel@tonic-gate
216*0Sstevel@tonic-gateIf B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Parser> for
217*0Sstevel@tonic-gateinformation about what those errors might mean.  Internally, it can also
218*0Sstevel@tonic-gateproduce the following diagnostics:
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate=over 4
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate=item -c (--color) requires Term::ANSIColor be installed
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gate(F) B<-c> or B<--color> were given, but Term::ANSIColor could not be
225*0Sstevel@tonic-gateloaded.
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate=item Unknown option: %s
228*0Sstevel@tonic-gate
229*0Sstevel@tonic-gate(F) An unknown command line option was given.
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gate=back
232*0Sstevel@tonic-gate
233*0Sstevel@tonic-gateIn addition, other L<Getopt::Long|Getopt::Long> error messages may result
234*0Sstevel@tonic-gatefrom invalid command-line options.
235*0Sstevel@tonic-gate
236*0Sstevel@tonic-gate=head1 ENVIRONMENT
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate=over 4
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate=item COLUMNS
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gateIf B<-t> is given, B<pod2text> will take the current width of your screen
243*0Sstevel@tonic-gatefrom this environment variable, if available.  It overrides terminal width
244*0Sstevel@tonic-gateinformation in TERMCAP.
245*0Sstevel@tonic-gate
246*0Sstevel@tonic-gate=item TERMCAP
247*0Sstevel@tonic-gate
248*0Sstevel@tonic-gateIf B<-t> is given, B<pod2text> will use the contents of this environment
249*0Sstevel@tonic-gatevariable if available to determine the correct formatting sequences for your
250*0Sstevel@tonic-gatecurrent terminal device.
251*0Sstevel@tonic-gate
252*0Sstevel@tonic-gate=back
253*0Sstevel@tonic-gate
254*0Sstevel@tonic-gate=head1 SEE ALSO
255*0Sstevel@tonic-gate
256*0Sstevel@tonic-gateL<Pod::Text>, L<Pod::Text::Color>, L<Pod::Text::Overstrike>,
257*0Sstevel@tonic-gateL<Pod::Text::Termcap>, L<Pod::Parser>
258*0Sstevel@tonic-gate
259*0Sstevel@tonic-gateThe current version of this script is always available from its web site at
260*0Sstevel@tonic-gateL<http://www.eyrie.org/~eagle/software/podlators/>.  It is also part of the
261*0Sstevel@tonic-gatePerl core distribution as of 5.6.0.
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate=head1 AUTHOR
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gateRuss Allbery <rra@stanford.edu>.
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate=head1 COPYRIGHT AND LICENSE
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gateCopyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>.
270*0Sstevel@tonic-gate
271*0Sstevel@tonic-gateThis program is free software; you may redistribute it and/or modify it
272*0Sstevel@tonic-gateunder the same terms as Perl itself.
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate=cut
275*0Sstevel@tonic-gate!NO!SUBS!
276*0Sstevel@tonic-gate
277*0Sstevel@tonic-gateclose OUT or die "Can't close $file: $!";
278*0Sstevel@tonic-gatechmod 0755, $file or die "Can't reset permissions for $file: $!\n";
279*0Sstevel@tonic-gateexec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
280*0Sstevel@tonic-gatechdir $origdir;
281