Note the task TODO of splitting the linker from the compiler.
[p5sagit/p5-mst-13.2.git] / pod / pod2text.PL
CommitLineData
cb1a09d0 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 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#
0e4e3f6e 40# Copyright 1999, 2000, 2001, 2004, 2006, 2008 Russ Allbery <rra@stanford.edu>
6055f9d4 41#
3c014959 42# This program is free software; you may redistribute it and/or modify it
6055f9d4 43# under the same terms as Perl itself.
44#
9741dab0 45# The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
46# invoked by perldoc -t among other things.
6055f9d4 47
48require 5.004;
49
50use Getopt::Long qw(GetOptions);
51use Pod::Text ();
52use Pod::Usage qw(pod2usage);
53
54use strict;
6055f9d4 55
59548eca 56# Silence -w warnings.
57use vars qw($running_under_some_shell);
58
6055f9d4 59# Take an initial pass through our options, looking for one of the form
60# -<number>. We turn that into -w <number> for compatibility with the
61# original pod2text script.
62for (my $i = 0; $i < @ARGV; $i++) {
63 last if $ARGV[$i] =~ /^--$/;
64 if ($ARGV[$i] =~ /^-(\d+)$/) {
65 splice (@ARGV, $i++, 1, '-w', $1);
66 }
67}
68
46bce7d0 69# Insert -- into @ARGV before any single dash argument to hide it from
b7ae008f 70# Getopt::Long; we want to interpret it as meaning stdin (which Pod::Simple
46bce7d0 71# does correctly).
72my $stdin;
73@ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
74
9741dab0 75# Parse our options. Use the same names as Pod::Text for simplicity, and
76# default to sentence boundaries turned off for compatibility.
6055f9d4 77my %options;
6055f9d4 78$options{sentence} = 0;
79Getopt::Long::config ('bundling');
59548eca 80GetOptions (\%options, 'alt|a', 'code', 'color|c', 'help|h', 'indent|i=i',
11f72409 81 'loose|l', 'margin|left-margin|m=i', 'overstrike|o',
82 'quotes|q=s', 'sentence|s', 'termcap|t', 'width|w=i') or exit 1;
6055f9d4 83pod2usage (1) if $options{help};
84
85# Figure out what formatter we're going to use. -c overrides -t.
86my $formatter = 'Pod::Text';
87if ($options{color}) {
88 $formatter = 'Pod::Text::Color';
9741dab0 89 eval { require Term::ANSIColor };
90 if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
6055f9d4 91 require Pod::Text::Color;
92} elsif ($options{termcap}) {
93 $formatter = 'Pod::Text::Termcap';
94 require Pod::Text::Termcap;
73849855 95} elsif ($options{overstrike}) {
96 $formatter = 'Pod::Text::Overstrike';
97 require Pod::Text::Overstrike;
cb1a09d0 98}
73849855 99delete @options{'color', 'termcap', 'overstrike'};
6055f9d4 100
101# Initialize and run the formatter.
8f202758 102my $parser = $formatter->new (%options);
b7ae008f 103do {
b7ae008f 104 my ($input, $output) = splice (@ARGV, 0, 2);
8f202758 105 $parser->parse_from_file ($input, $output);
b7ae008f 106} while (@ARGV);
6055f9d4 107
108__END__
109
110=head1 NAME
111
112pod2text - Convert POD data to formatted ASCII text
113
0e4e3f6e 114=for stopwords
115-aclost --alt Allbery
116
6055f9d4 117=head1 SYNOPSIS
118
59548eca 119pod2text [B<-aclost>] [B<--code>] [B<-i> I<indent>] S<[B<-q> I<quotes>]>
0e4e3f6e 120 S<[B<-w> I<width>]> [I<input> [I<output> ...]]
6055f9d4 121
122pod2text B<-h>
123
124=head1 DESCRIPTION
125
9741dab0 126B<pod2text> is a front-end for Pod::Text and its subclasses. It uses them
127to generate formatted ASCII text from POD source. It can optionally use
128either termcap sequences or ANSI color escape sequences to format the text.
6055f9d4 129
130I<input> is the file to read for POD source (the POD can be embedded in
0e4e3f6e 131code). If I<input> isn't given, it defaults to C<STDIN>. I<output>, if
132given, is the file to which to write the formatted output. If I<output>
133isn't given, the formatted output is written to C<STDOUT>. Several POD
134files can be processed in the same B<pod2text> invocation (saving module
135load and compile times) by providing multiple pairs of I<input> and
136I<output> files on the command line.
6055f9d4 137
138=head1 OPTIONS
139
140=over 4
141
142=item B<-a>, B<--alt>
143
144Use an alternate output format that, among other things, uses a different
145heading style and marks C<=item> entries with a colon in the left margin.
146
59548eca 147=item B<--code>
148
149Include any non-POD text from the input file in the output as well. Useful
150for viewing code documented with POD blocks with the POD rendered and the
151code left intact.
152
6055f9d4 153=item B<-c>, B<--color>
154
155Format the output with ANSI color escape sequences. Using this option
156requires that Term::ANSIColor be installed on your system.
157
158=item B<-i> I<indent>, B<--indent=>I<indent>
159
160Set the number of spaces to indent regular text, and the default indentation
161for C<=over> blocks. Defaults to 4 spaces if this option isn't given.
162
9741dab0 163=item B<-h>, B<--help>
164
165Print out usage information and exit.
166
6055f9d4 167=item B<-l>, B<--loose>
168
169Print a blank line after a C<=head1> heading. Normally, no blank line is
9741dab0 170printed after C<=head1>, although one is still printed after C<=head2>,
171because this is the expected formatting for manual pages; if you're
172formatting arbitrary text documents, using this option is recommended.
6055f9d4 173
11f72409 174=item B<-m> I<width>, B<--left-margin>=I<width>, B<--margin>=I<width>
175
176The width of the left margin in spaces. Defaults to 0. This is the margin
177for all text, including headings, not the amount by which regular text is
178indented; for the latter, see B<-i> option.
179
73849855 180=item B<-o>, B<--overstrike>
181
0e4e3f6e 182Format the output with overstrike printing. Bold text is rendered as
73849855 183character, backspace, character. Italics and file names are rendered as
184underscore, backspace, character. Many pagers, such as B<less>, know how
185to convert this to bold or underlined text.
186
ab1f1d91 187=item B<-q> I<quotes>, B<--quotes>=I<quotes>
188
189Sets the quote marks used to surround CE<lt>> text to I<quotes>. If
190I<quotes> is a single character, it is used as both the left and right
191quote; if I<quotes> is two characters, the first character is used as the
192left quote and the second as the right quoted; and if I<quotes> is four
193characters, the first two are used as the left quote and the second two as
194the right quote.
195
196I<quotes> may also be set to the special value C<none>, in which case no
197quote marks are added around CE<lt>> text.
198
6055f9d4 199=item B<-s>, B<--sentence>
200
9741dab0 201Assume each sentence ends with two spaces and try to preserve that spacing.
6055f9d4 202Without this option, all consecutive whitespace in non-verbatim paragraphs
203is compressed into a single space.
204
205=item B<-t>, B<--termcap>
206
207Try to determine the width of the screen and the bold and underline
208sequences for the terminal from termcap, and use that information in
209formatting the output. Output will be wrapped at two columns less than the
210width of your terminal device. Using this option requires that your system
46bce7d0 211have a termcap file somewhere where Term::Cap can find it and requires that
212your system support termios. With this option, the output of B<pod2text>
213will contain terminal control sequences for your current terminal type.
6055f9d4 214
215=item B<-w>, B<--width=>I<width>, B<->I<width>
216
217The column at which to wrap text on the right-hand side. Defaults to 76,
218unless B<-t> is given, in which case it's two columns less than the width of
219your terminal device.
220
221=back
222
9741dab0 223=head1 DIAGNOSTICS
224
b7ae008f 225If B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Simple> for
9741dab0 226information about what those errors might mean. Internally, it can also
227produce the following diagnostics:
228
229=over 4
230
231=item -c (--color) requires Term::ANSIColor be installed
232
233(F) B<-c> or B<--color> were given, but Term::ANSIColor could not be
234loaded.
235
236=item Unknown option: %s
237
238(F) An unknown command line option was given.
239
240=back
241
b7ae008f 242In addition, other L<Getopt::Long> error messages may result from invalid
243command-line options.
9741dab0 244
6055f9d4 245=head1 ENVIRONMENT
246
247=over 4
248
249=item COLUMNS
250
251If B<-t> is given, B<pod2text> will take the current width of your screen
252from this environment variable, if available. It overrides terminal width
253information in TERMCAP.
254
255=item TERMCAP
256
257If B<-t> is given, B<pod2text> will use the contents of this environment
258variable if available to determine the correct formatting sequences for your
259current terminal device.
260
261=back
262
6055f9d4 263=head1 SEE ALSO
264
fd20da51 265L<Pod::Text>, L<Pod::Text::Color>, L<Pod::Text::Overstrike>,
b7ae008f 266L<Pod::Text::Termcap>, L<Pod::Simple>
fd20da51 267
268The current version of this script is always available from its web site at
269L<http://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
270Perl core distribution as of 5.6.0.
6055f9d4 271
272=head1 AUTHOR
273
3c014959 274Russ Allbery <rra@stanford.edu>.
275
276=head1 COPYRIGHT AND LICENSE
277
0e4e3f6e 278Copyright 1999, 2000, 2001, 2004, 2006, 2008 Russ Allbery
279<rra@stanford.edu>.
3c014959 280
281This program is free software; you may redistribute it and/or modify it
282under the same terms as Perl itself.
cb1a09d0 283
6055f9d4 284=cut
c07a80fd 285!NO!SUBS!
cb1a09d0 286
c07a80fd 287close OUT or die "Can't close $file: $!";
288chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
289exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
3b5ca523 290chdir $origdir;