home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / bin / pod2text.bat < prev    next >
Encoding:
DOS Batch File  |  2002-12-01  |  8.0 KB  |  252 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.     eval 'exec D:\p4\Apps\Gecko\MSI\data\ActivePerl\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  16.         if $running_under_some_shell;
  17.  
  18. # pod2text -- Convert POD data to formatted ASCII text.
  19. #
  20. # Copyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>
  21. #
  22. # This program is free software; you may redistribute it and/or modify it
  23. # under the same terms as Perl itself.
  24. #
  25. # The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
  26. # invoked by perldoc -t among other things.
  27.  
  28. require 5.004;
  29.  
  30. use Getopt::Long qw(GetOptions);
  31. use Pod::Text ();
  32. use Pod::Usage qw(pod2usage);
  33.  
  34. use strict;
  35.  
  36. # Silence -w warnings.
  37. use vars qw($running_under_some_shell);
  38.  
  39. # Take an initial pass through our options, looking for one of the form
  40. # -<number>.  We turn that into -w <number> for compatibility with the
  41. # original pod2text script.
  42. for (my $i = 0; $i < @ARGV; $i++) {
  43.     last if $ARGV[$i] =~ /^--$/;
  44.     if ($ARGV[$i] =~ /^-(\d+)$/) {
  45.         splice (@ARGV, $i++, 1, '-w', $1);
  46.     }
  47. }
  48.  
  49. # Insert -- into @ARGV before any single dash argument to hide it from
  50. # Getopt::Long; we want to interpret it as meaning stdin (which Pod::Parser
  51. # does correctly).
  52. my $stdin;
  53. @ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
  54.  
  55. # Parse our options.  Use the same names as Pod::Text for simplicity, and
  56. # default to sentence boundaries turned off for compatibility.
  57. my %options;
  58. $options{sentence} = 0;
  59. Getopt::Long::config ('bundling');
  60. GetOptions (\%options, 'alt|a', 'code', 'color|c', 'help|h', 'indent|i=i',
  61.             'loose|l', 'overstrike|o', 'quotes|q=s', 'sentence|s',
  62.             'termcap|t', 'width|w=i') or exit 1;
  63. pod2usage (1) if $options{help};
  64.  
  65. # Figure out what formatter we're going to use.  -c overrides -t.
  66. my $formatter = 'Pod::Text';
  67. if ($options{color}) {
  68.     $formatter = 'Pod::Text::Color';
  69.     eval { require Term::ANSIColor };
  70.     if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
  71.     require Pod::Text::Color;
  72. } elsif ($options{termcap}) {
  73.     $formatter = 'Pod::Text::Termcap';
  74.     require Pod::Text::Termcap;
  75. } elsif ($options{overstrike}) {
  76.     $formatter = 'Pod::Text::Overstrike';
  77.     require Pod::Text::Overstrike;
  78. }
  79. delete @options{'color', 'termcap', 'overstrike'};
  80.  
  81. # Initialize and run the formatter.
  82. my $parser = $formatter->new (%options);
  83. $parser->parse_from_file (@ARGV);
  84.  
  85. __END__
  86.  
  87. =head1 NAME
  88.  
  89. pod2text - Convert POD data to formatted ASCII text
  90.  
  91. =head1 SYNOPSIS
  92.  
  93. pod2text [B<-aclost>] [B<--code>] [B<-i> I<indent>] S<[B<-q> I<quotes>]>
  94. S<[B<-w> I<width>]> [I<input> [I<output>]]
  95.  
  96. pod2text B<-h>
  97.  
  98. =head1 DESCRIPTION
  99.  
  100. B<pod2text> is a front-end for Pod::Text and its subclasses.  It uses them
  101. to generate formatted ASCII text from POD source.  It can optionally use
  102. either termcap sequences or ANSI color escape sequences to format the text.
  103.  
  104. I<input> is the file to read for POD source (the POD can be embedded in
  105. code).  If I<input> isn't given, it defaults to STDIN.  I<output>, if given,
  106. is the file to which to write the formatted output.  If I<output> isn't
  107. given, the formatted output is written to STDOUT.
  108.  
  109. =head1 OPTIONS
  110.  
  111. =over 4
  112.  
  113. =item B<-a>, B<--alt>
  114.  
  115. Use an alternate output format that, among other things, uses a different
  116. heading style and marks C<=item> entries with a colon in the left margin.
  117.  
  118. =item B<--code>
  119.  
  120. Include any non-POD text from the input file in the output as well.  Useful
  121. for viewing code documented with POD blocks with the POD rendered and the
  122. code left intact.
  123.  
  124. =item B<-c>, B<--color>
  125.  
  126. Format the output with ANSI color escape sequences.  Using this option
  127. requires that Term::ANSIColor be installed on your system.
  128.  
  129. =item B<-i> I<indent>, B<--indent=>I<indent>
  130.  
  131. Set the number of spaces to indent regular text, and the default indentation
  132. for C<=over> blocks.  Defaults to 4 spaces if this option isn't given.
  133.  
  134. =item B<-h>, B<--help>
  135.  
  136. Print out usage information and exit.
  137.  
  138. =item B<-l>, B<--loose>
  139.  
  140. Print a blank line after a C<=head1> heading.  Normally, no blank line is
  141. printed after C<=head1>, although one is still printed after C<=head2>,
  142. because this is the expected formatting for manual pages; if you're
  143. formatting arbitrary text documents, using this option is recommended.
  144.  
  145. =item B<-o>, B<--overstrike>
  146.  
  147. Format the output with overstruck printing.  Bold text is rendered as
  148. character, backspace, character.  Italics and file names are rendered as
  149. underscore, backspace, character.  Many pagers, such as B<less>, know how
  150. to convert this to bold or underlined text.
  151.  
  152. =item B<-q> I<quotes>, B<--quotes>=I<quotes>
  153.  
  154. Sets the quote marks used to surround CE<lt>> text to I<quotes>.  If
  155. I<quotes> is a single character, it is used as both the left and right
  156. quote; if I<quotes> is two characters, the first character is used as the
  157. left quote and the second as the right quoted; and if I<quotes> is four
  158. characters, the first two are used as the left quote and the second two as
  159. the right quote.
  160.  
  161. I<quotes> may also be set to the special value C<none>, in which case no
  162. quote marks are added around CE<lt>> text.
  163.  
  164. =item B<-s>, B<--sentence>
  165.  
  166. Assume each sentence ends with two spaces and try to preserve that spacing.
  167. Without this option, all consecutive whitespace in non-verbatim paragraphs
  168. is compressed into a single space.
  169.  
  170. =item B<-t>, B<--termcap>
  171.  
  172. Try to determine the width of the screen and the bold and underline
  173. sequences for the terminal from termcap, and use that information in
  174. formatting the output.  Output will be wrapped at two columns less than the
  175. width of your terminal device.  Using this option requires that your system
  176. have a termcap file somewhere where Term::Cap can find it and requires that
  177. your system support termios.  With this option, the output of B<pod2text>
  178. will contain terminal control sequences for your current terminal type.
  179.  
  180. =item B<-w>, B<--width=>I<width>, B<->I<width>
  181.  
  182. The column at which to wrap text on the right-hand side.  Defaults to 76,
  183. unless B<-t> is given, in which case it's two columns less than the width of
  184. your terminal device.
  185.  
  186. =back
  187.  
  188. =head1 DIAGNOSTICS
  189.  
  190. If B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Parser> for
  191. information about what those errors might mean.  Internally, it can also
  192. produce the following diagnostics:
  193.  
  194. =over 4
  195.  
  196. =item -c (--color) requires Term::ANSIColor be installed
  197.  
  198. (F) B<-c> or B<--color> were given, but Term::ANSIColor could not be
  199. loaded.
  200.  
  201. =item Unknown option: %s
  202.  
  203. (F) An unknown command line option was given.
  204.  
  205. =back
  206.  
  207. In addition, other L<Getopt::Long|Getopt::Long> error messages may result
  208. from invalid command-line options.
  209.  
  210. =head1 ENVIRONMENT
  211.  
  212. =over 4
  213.  
  214. =item COLUMNS
  215.  
  216. If B<-t> is given, B<pod2text> will take the current width of your screen
  217. from this environment variable, if available.  It overrides terminal width
  218. information in TERMCAP.
  219.  
  220. =item TERMCAP
  221.  
  222. If B<-t> is given, B<pod2text> will use the contents of this environment
  223. variable if available to determine the correct formatting sequences for your
  224. current terminal device.
  225.  
  226. =back
  227.  
  228. =head1 SEE ALSO
  229.  
  230. L<Pod::Text>, L<Pod::Text::Color>, L<Pod::Text::Overstrike>,
  231. L<Pod::Text::Termcap>, L<Pod::Parser>
  232.  
  233. The current version of this script is always available from its web site at
  234. L<http://www.eyrie.org/~eagle/software/podlators/>.  It is also part of the
  235. Perl core distribution as of 5.6.0.
  236.  
  237. =head1 AUTHOR
  238.  
  239. Russ Allbery <rra@stanford.edu>.
  240.  
  241. =head1 COPYRIGHT AND LICENSE
  242.  
  243. Copyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>.
  244.  
  245. This program is free software; you may redistribute it and/or modify it
  246. under the same terms as Perl itself.
  247.  
  248. =cut
  249.  
  250. __END__
  251. :endofperl
  252.