This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
diff -se shows these as different
[perl5.git] / pod / pod2text.PL
CommitLineData
cb1a09d0
AD
1#!/usr/local/bin/perl
2
c07a80fd 3use Config;
4use File::Basename qw(&basename &dirname);
3b5ca523 5use Cwd;
cb1a09d0 6
c07a80fd 7# List explicitly here the variables you want Configure to
8# generate. Metaconfig only looks for shell variables, so you
9# have to mention them as if they were shell variables, not
10# %Config entries. Thus you write
11# $startperl
12# to ensure Configure will look for $Config{startperl}.
cb1a09d0 13
3b5ca523
GS
14# This forces PL files to create target in same directory as PL file.
15# This is so that make depend always knows where to find PL derivatives.
16$origdir = cwd;
17chdir dirname($0);
44a8e56a 18$file = basename($0, '.PL');
774d564b 19$file .= '.com' if $^O eq 'VMS';
cb1a09d0 20
c07a80fd 21open OUT,">$file" or die "Can't create $file: $!";
cb1a09d0 22
c07a80fd 23print "Extracting $file (with variable substitutions)\n";
cb1a09d0 24
c07a80fd 25# In this section, perl variables will be expanded during extraction.
26# You can use $Config{...} to use Configure variables.
cb1a09d0 27
c07a80fd 28print OUT <<"!GROK!THIS!";
5f05dabc 29$Config{startperl}
30 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
9741dab0 31 if \$running_under_some_shell;
c07a80fd 32!GROK!THIS!
cb1a09d0 33
c07a80fd 34# In the following, perl variables are not expanded during extraction.
cb1a09d0 35
c07a80fd 36print OUT <<'!NO!SUBS!';
cb1a09d0 37
6055f9d4 38# pod2text -- Convert POD data to formatted ASCII text.
9741dab0 39#
46bce7d0 40# Copyright 1999, 2000 by Russ Allbery <rra@stanford.edu>
6055f9d4
GS
41#
42# This program is free software; you can redistribute it and/or modify it
43# under the same terms as Perl itself.
44#
9741dab0
GS
45# The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
46# invoked by perldoc -t among other things.
6055f9d4
GS
47
48require 5.004;
49
50use Getopt::Long qw(GetOptions);
51use Pod::Text ();
52use Pod::Usage qw(pod2usage);
53
54use strict;
6055f9d4
GS
55
56# Take an initial pass through our options, looking for one of the form
57# -<number>. We turn that into -w <number> for compatibility with the
58# original pod2text script.
59for (my $i = 0; $i < @ARGV; $i++) {
60 last if $ARGV[$i] =~ /^--$/;
61 if ($ARGV[$i] =~ /^-(\d+)$/) {
62 splice (@ARGV, $i++, 1, '-w', $1);
63 }
64}
65
46bce7d0
GS
66# Insert -- into @ARGV before any single dash argument to hide it from
67# Getopt::Long; we want to interpret it as meaning stdin (which Pod::Parser
68# does correctly).
69my $stdin;
70@ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
71
9741dab0
GS
72# Parse our options. Use the same names as Pod::Text for simplicity, and
73# default to sentence boundaries turned off for compatibility.
6055f9d4 74my %options;
6055f9d4
GS
75$options{sentence} = 0;
76Getopt::Long::config ('bundling');
77GetOptions (\%options, 'alt|a', 'color|c', 'help|h', 'indent|i=i',
ab1f1d91
JH
78 'loose|l', 'quotes|q=s', 'sentence|s', 'termcap|t',
79 'width|w=i') or exit 1;
6055f9d4
GS
80pod2usage (1) if $options{help};
81
82# Figure out what formatter we're going to use. -c overrides -t.
83my $formatter = 'Pod::Text';
84if ($options{color}) {
85 $formatter = 'Pod::Text::Color';
9741dab0
GS
86 eval { require Term::ANSIColor };
87 if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
6055f9d4
GS
88 require Pod::Text::Color;
89} elsif ($options{termcap}) {
90 $formatter = 'Pod::Text::Termcap';
91 require Pod::Text::Termcap;
cb1a09d0 92}
6055f9d4
GS
93delete @options{'color', 'termcap'};
94
95# Initialize and run the formatter.
96my $parser = $formatter->new (%options);
97$parser->parse_from_file (@ARGV);
98
99__END__
100
101=head1 NAME
102
103pod2text - Convert POD data to formatted ASCII text
104
105=head1 SYNOPSIS
106
ab1f1d91
JH
107pod2text [B<-aclst>] [B<-i> I<indent>] [B<-q> I<quotes>] [B<-w> I<width>]
108[I<input> [I<output>]]
6055f9d4
GS
109
110pod2text B<-h>
111
112=head1 DESCRIPTION
113
9741dab0
GS
114B<pod2text> is a front-end for Pod::Text and its subclasses. It uses them
115to generate formatted ASCII text from POD source. It can optionally use
116either termcap sequences or ANSI color escape sequences to format the text.
6055f9d4
GS
117
118I<input> is the file to read for POD source (the POD can be embedded in
119code). If I<input> isn't given, it defaults to STDIN. I<output>, if given,
120is the file to which to write the formatted output. If I<output> isn't
121given, the formatted output is written to STDOUT.
122
123=head1 OPTIONS
124
125=over 4
126
127=item B<-a>, B<--alt>
128
129Use an alternate output format that, among other things, uses a different
130heading style and marks C<=item> entries with a colon in the left margin.
131
132=item B<-c>, B<--color>
133
134Format the output with ANSI color escape sequences. Using this option
135requires that Term::ANSIColor be installed on your system.
136
137=item B<-i> I<indent>, B<--indent=>I<indent>
138
139Set the number of spaces to indent regular text, and the default indentation
140for C<=over> blocks. Defaults to 4 spaces if this option isn't given.
141
9741dab0
GS
142=item B<-h>, B<--help>
143
144Print out usage information and exit.
145
6055f9d4
GS
146=item B<-l>, B<--loose>
147
148Print a blank line after a C<=head1> heading. Normally, no blank line is
9741dab0
GS
149printed after C<=head1>, although one is still printed after C<=head2>,
150because this is the expected formatting for manual pages; if you're
151formatting arbitrary text documents, using this option is recommended.
6055f9d4 152
ab1f1d91
JH
153=item B<-q> I<quotes>, B<--quotes>=I<quotes>
154
155Sets the quote marks used to surround CE<lt>> text to I<quotes>. If
156I<quotes> is a single character, it is used as both the left and right
157quote; if I<quotes> is two characters, the first character is used as the
158left quote and the second as the right quoted; and if I<quotes> is four
159characters, the first two are used as the left quote and the second two as
160the right quote.
161
162I<quotes> may also be set to the special value C<none>, in which case no
163quote marks are added around CE<lt>> text.
164
6055f9d4
GS
165=item B<-s>, B<--sentence>
166
9741dab0 167Assume each sentence ends with two spaces and try to preserve that spacing.
6055f9d4
GS
168Without this option, all consecutive whitespace in non-verbatim paragraphs
169is compressed into a single space.
170
171=item B<-t>, B<--termcap>
172
173Try to determine the width of the screen and the bold and underline
174sequences for the terminal from termcap, and use that information in
175formatting the output. Output will be wrapped at two columns less than the
176width of your terminal device. Using this option requires that your system
46bce7d0
GS
177have a termcap file somewhere where Term::Cap can find it and requires that
178your system support termios. With this option, the output of B<pod2text>
179will contain terminal control sequences for your current terminal type.
6055f9d4
GS
180
181=item B<-w>, B<--width=>I<width>, B<->I<width>
182
183The column at which to wrap text on the right-hand side. Defaults to 76,
184unless B<-t> is given, in which case it's two columns less than the width of
185your terminal device.
186
187=back
188
9741dab0
GS
189=head1 DIAGNOSTICS
190
191If B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Parser> for
192information about what those errors might mean. Internally, it can also
193produce the following diagnostics:
194
195=over 4
196
197=item -c (--color) requires Term::ANSIColor be installed
198
199(F) B<-c> or B<--color> were given, but Term::ANSIColor could not be
200loaded.
201
202=item Unknown option: %s
203
204(F) An unknown command line option was given.
205
206=back
207
208In addition, other L<Getopt::Long|Getopt::Long> error messages may result
209from invalid command-line options.
210
6055f9d4
GS
211=head1 ENVIRONMENT
212
213=over 4
214
215=item COLUMNS
216
217If B<-t> is given, B<pod2text> will take the current width of your screen
218from this environment variable, if available. It overrides terminal width
219information in TERMCAP.
220
221=item TERMCAP
222
223If B<-t> is given, B<pod2text> will use the contents of this environment
224variable if available to determine the correct formatting sequences for your
225current terminal device.
226
227=back
228
6055f9d4
GS
229=head1 SEE ALSO
230
231L<Pod::Text|Pod::Text>, L<Pod::Text::Color|Pod::Text::Color>,
232L<Pod::Text::Termcap|Pod::Text::Termcap>, L<Pod::Parser|Pod::Parser>
233
234=head1 AUTHOR
235
236Russ Allbery E<lt>rra@stanford.eduE<gt>.
cb1a09d0 237
6055f9d4 238=cut
c07a80fd 239!NO!SUBS!
cb1a09d0 240
c07a80fd 241close OUT or die "Can't close $file: $!";
242chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
243exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
3b5ca523 244chdir $origdir;