be defensive about setting {host,group,pass}cat (from Andy Dougherty)
[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#
40# Copyright 1999 by Russ Allbery <rra@stanford.edu>
6055f9d4 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 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;
55use vars qw($ID);
56
57# Take an initial pass through our options, looking for one of the form
58# -<number>. We turn that into -w <number> for compatibility with the
59# original pod2text script.
60for (my $i = 0; $i < @ARGV; $i++) {
61 last if $ARGV[$i] =~ /^--$/;
62 if ($ARGV[$i] =~ /^-(\d+)$/) {
63 splice (@ARGV, $i++, 1, '-w', $1);
64 }
65}
66
9741dab0 67# Parse our options. Use the same names as Pod::Text for simplicity, and
68# default to sentence boundaries turned off for compatibility.
6055f9d4 69my %options;
70$options{termcap} = -t STDOUT;
71$options{sentence} = 0;
72Getopt::Long::config ('bundling');
73GetOptions (\%options, 'alt|a', 'color|c', 'help|h', 'indent|i=i',
74 'loose|l', 'sentence|s', 'termcap|t!', 'width|w=i') or exit 1;
75pod2usage (1) if $options{help};
76
77# Figure out what formatter we're going to use. -c overrides -t.
78my $formatter = 'Pod::Text';
79if ($options{color}) {
80 $formatter = 'Pod::Text::Color';
9741dab0 81 eval { require Term::ANSIColor };
82 if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
6055f9d4 83 require Pod::Text::Color;
84} elsif ($options{termcap}) {
85 $formatter = 'Pod::Text::Termcap';
86 require Pod::Text::Termcap;
cb1a09d0 87}
6055f9d4 88delete @options{'color', 'termcap'};
89
90# Initialize and run the formatter.
91my $parser = $formatter->new (%options);
92$parser->parse_from_file (@ARGV);
93
94__END__
95
96=head1 NAME
97
98pod2text - Convert POD data to formatted ASCII text
99
100=head1 SYNOPSIS
101
102pod2text [B<-aclst>] [B<-i> I<indent>] [B<-w> I<width>] [I<input> [I<output>]]
103
104pod2text B<-h>
105
106=head1 DESCRIPTION
107
9741dab0 108B<pod2text> is a front-end for Pod::Text and its subclasses. It uses them
109to generate formatted ASCII text from POD source. It can optionally use
110either termcap sequences or ANSI color escape sequences to format the text.
6055f9d4 111
112I<input> is the file to read for POD source (the POD can be embedded in
113code). If I<input> isn't given, it defaults to STDIN. I<output>, if given,
114is the file to which to write the formatted output. If I<output> isn't
115given, the formatted output is written to STDOUT.
116
9741dab0 117B<pod2text> defaults to trying to use Pod::Text::Termcap if STDOUT is a tty.
118To explicitly say not to attempt termcap escape sequences, use
119B<--notermcap>.
120
6055f9d4 121=head1 OPTIONS
122
123=over 4
124
125=item B<-a>, B<--alt>
126
127Use an alternate output format that, among other things, uses a different
128heading style and marks C<=item> entries with a colon in the left margin.
129
130=item B<-c>, B<--color>
131
132Format the output with ANSI color escape sequences. Using this option
133requires that Term::ANSIColor be installed on your system.
134
135=item B<-i> I<indent>, B<--indent=>I<indent>
136
137Set the number of spaces to indent regular text, and the default indentation
138for C<=over> blocks. Defaults to 4 spaces if this option isn't given.
139
9741dab0 140=item B<-h>, B<--help>
141
142Print out usage information and exit.
143
6055f9d4 144=item B<-l>, B<--loose>
145
146Print a blank line after a C<=head1> heading. Normally, no blank line is
9741dab0 147printed after C<=head1>, although one is still printed after C<=head2>,
148because this is the expected formatting for manual pages; if you're
149formatting arbitrary text documents, using this option is recommended.
6055f9d4 150
151=item B<-s>, B<--sentence>
152
9741dab0 153Assume each sentence ends with two spaces and try to preserve that spacing.
6055f9d4 154Without this option, all consecutive whitespace in non-verbatim paragraphs
155is compressed into a single space.
156
157=item B<-t>, B<--termcap>
158
159Try to determine the width of the screen and the bold and underline
160sequences for the terminal from termcap, and use that information in
161formatting the output. Output will be wrapped at two columns less than the
162width of your terminal device. Using this option requires that your system
163have a termcap file somewhere where Term::Cap can find it. With this
9741dab0 164option, the output of B<pod2text> will contain terminal control sequences
165for your current terminal type.
6055f9d4 166
167=item B<-w>, B<--width=>I<width>, B<->I<width>
168
169The column at which to wrap text on the right-hand side. Defaults to 76,
170unless B<-t> is given, in which case it's two columns less than the width of
171your terminal device.
172
173=back
174
9741dab0 175=head1 DIAGNOSTICS
176
177If B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Parser> for
178information about what those errors might mean. Internally, it can also
179produce the following diagnostics:
180
181=over 4
182
183=item -c (--color) requires Term::ANSIColor be installed
184
185(F) B<-c> or B<--color> were given, but Term::ANSIColor could not be
186loaded.
187
188=item Unknown option: %s
189
190(F) An unknown command line option was given.
191
192=back
193
194In addition, other L<Getopt::Long|Getopt::Long> error messages may result
195from invalid command-line options.
196
6055f9d4 197=head1 ENVIRONMENT
198
199=over 4
200
201=item COLUMNS
202
203If B<-t> is given, B<pod2text> will take the current width of your screen
204from this environment variable, if available. It overrides terminal width
205information in TERMCAP.
206
207=item TERMCAP
208
209If B<-t> is given, B<pod2text> will use the contents of this environment
210variable if available to determine the correct formatting sequences for your
211current terminal device.
212
213=back
214
6055f9d4 215=head1 SEE ALSO
216
217L<Pod::Text|Pod::Text>, L<Pod::Text::Color|Pod::Text::Color>,
218L<Pod::Text::Termcap|Pod::Text::Termcap>, L<Pod::Parser|Pod::Parser>
219
220=head1 AUTHOR
221
222Russ Allbery E<lt>rra@stanford.eduE<gt>.
cb1a09d0 223
6055f9d4 224=cut
c07a80fd 225!NO!SUBS!
cb1a09d0 226
c07a80fd 227close OUT or die "Can't close $file: $!";
228chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
229exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
3b5ca523 230chdir $origdir;