X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fpod2text.PL;h=92b26feceb8b2661bee0e69a0b445a6f05e28397;hb=140cb37ed79835bf0c0cde1ebe5ce5eceaa7b04b;hp=94516c3997821e8b1da685311566fe3c339424ab;hpb=92c28edd459d810e3c841dc07d7846c462b368a9;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/pod2text.PL b/pod/pod2text.PL index 94516c3..92b26fe 100644 --- a/pod/pod2text.PL +++ b/pod/pod2text.PL @@ -35,14 +35,169 @@ $Config{startperl} print OUT <<'!NO!SUBS!'; -use Pod::Text; +$ID = q$Id: pod2text,v 0.1 1999/06/13 02:42:18 eagle Exp $; -if(@ARGV) { - pod2text($ARGV[0]); -} else { - pod2text("<&STDIN"); +# pod2text -- Convert POD data to formatted ASCII text. +# Copyright 1999 by Russ Allbery +# +# This program is free software; you can redistribute it and/or modify it +# under the same terms as Perl itself. +# +# The driver script for Pod::Text, Pod::Text::Termcap, and +# Pod::Text::Color, invoked by perldoc -t among other things. + +require 5.004; + +use Getopt::Long qw(GetOptions); +use Pod::Text (); +use Pod::Usage qw(pod2usage); + +use strict; +use vars qw($ID); + +# Take an initial pass through our options, looking for one of the form +# -. We turn that into -w for compatibility with the +# original pod2text script. +for (my $i = 0; $i < @ARGV; $i++) { + last if $ARGV[$i] =~ /^--$/; + if ($ARGV[$i] =~ /^-(\d+)$/) { + splice (@ARGV, $i++, 1, '-w', $1); + } +} + +# Parse our options. Use the same names as Pod::Text for simplicity, +# and default to sentence boundaries turned off for compatibility. +my %options; +$options{termcap} = -t STDOUT; +$options{sentence} = 0; +Getopt::Long::config ('bundling'); +GetOptions (\%options, 'alt|a', 'color|c', 'help|h', 'indent|i=i', + 'loose|l', 'sentence|s', 'termcap|t!', 'width|w=i') or exit 1; +pod2usage (1) if $options{help}; + +# Figure out what formatter we're going to use. -c overrides -t. +my $formatter = 'Pod::Text'; +if ($options{color}) { + $formatter = 'Pod::Text::Color'; + require Pod::Text::Color; +} elsif ($options{termcap}) { + $formatter = 'Pod::Text::Termcap'; + require Pod::Text::Termcap; } +delete @options{'color', 'termcap'}; + +# Initialize and run the formatter. +my $parser = $formatter->new (%options); +$parser->parse_from_file (@ARGV); + +__END__ + +=head1 NAME + +pod2text - Convert POD data to formatted ASCII text + +=head1 SYNOPSIS + +pod2text [B<-aclst>] [B<-i> I] [B<-w> I] [I [I]] + +pod2text B<-h> + +=head1 DESCRIPTION + +B is a front-end for Pod::Text and its subclasses. It uses +them to generate formatted ASCII text from POD source. It can optionally +use either termcap sequences or ANSI color escape sequences to format the +text. + +I is the file to read for POD source (the POD can be embedded in +code). If I isn't given, it defaults to STDIN. I, if given, +is the file to which to write the formatted output. If I isn't +given, the formatted output is written to STDOUT. + +=head1 OPTIONS + +=over 4 + +=item B<-a>, B<--alt> + +Use an alternate output format that, among other things, uses a different +heading style and marks C<=item> entries with a colon in the left margin. + +=item B<-c>, B<--color> + +Format the output with ANSI color escape sequences. Using this option +requires that Term::ANSIColor be installed on your system. + +=item B<-i> I, B<--indent=>I + +Set the number of spaces to indent regular text, and the default indentation +for C<=over> blocks. Defaults to 4 spaces if this option isn't given. + +=item B<-l>, B<--loose> + +Print a blank line after a C<=head1> heading. Normally, no blank line is +printed after C<=head1>, although one is still printed after C<=head2>. +This is the default because it's the expected formatting for manual pages; +if you're formatting arbitrary text documents, using this option is +recommended. + +=item B<-s>, B<--sentence> + +Assume each sentence ends in two spaces and try to preserve that spacing. +Without this option, all consecutive whitespace in non-verbatim paragraphs +is compressed into a single space. + +=item B<-t>, B<--termcap> + +Try to determine the width of the screen and the bold and underline +sequences for the terminal from termcap, and use that information in +formatting the output. Output will be wrapped at two columns less than the +width of your terminal device. Using this option requires that your system +have a termcap file somewhere where Term::Cap can find it. With this +option, the output of B will contain terminal control sequences for +your current terminal type. + +=item B<-w>, B<--width=>I, B<->I + +The column at which to wrap text on the right-hand side. Defaults to 76, +unless B<-t> is given, in which case it's two columns less than the width of +your terminal device. + +=back + +=head1 ENVIRONMENT + +=over 4 + +=item COLUMNS + +If B<-t> is given, B will take the current width of your screen +from this environment variable, if available. It overrides terminal width +information in TERMCAP. + +=item TERMCAP + +If B<-t> is given, B will use the contents of this environment +variable if available to determine the correct formatting sequences for your +current terminal device. + +=back + +=head1 DIAGNOSTICS + +If B fails with POD errors, see L and +L for information about what those errors might mean. + +=head1 SEE ALSO + +L, L, +L, L + +=head1 AUTHOR + +Russ Allbery Erra@stanford.eduE. +=cut !NO!SUBS! close OUT or die "Can't close $file: $!";