home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / pod2text < prev    next >
Encoding:
Text File  |  2003-09-03  |  8.1 KB  |  242 lines

  1. #!perl
  2.  
  3.     eval 'exec C:\Perl\bin\perl.exe -S $0 ${1+"$@"}'
  4.  
  5.         if $running_under_some_shell;
  6.  
  7.  
  8.  
  9. # pod2text -- Convert POD data to formatted ASCII text.
  10.  
  11. #
  12.  
  13. # Copyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>
  14.  
  15. #
  16.  
  17. # This program is free software; you may redistribute it and/or modify it
  18.  
  19. # under the same terms as Perl itself.
  20.  
  21. #
  22.  
  23. # The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
  24.  
  25. # invoked by perldoc -t among other things.
  26.  
  27.  
  28.  
  29. require 5.004;
  30.  
  31.  
  32.  
  33. use Getopt::Long qw(GetOptions);
  34.  
  35. use Pod::Text ();
  36.  
  37. use Pod::Usage qw(pod2usage);
  38.  
  39.  
  40.  
  41. use strict;
  42.  
  43.  
  44.  
  45. # Silence -w warnings.
  46.  
  47. use vars qw($running_under_some_shell);
  48.  
  49.  
  50.  
  51. # Take an initial pass through our options, looking for one of the form
  52.  
  53. # -<number>.  We turn that into -w <number> for compatibility with the
  54.  
  55. # original pod2text script.
  56.  
  57. for (my $i = 0; $i < @ARGV; $i++) {
  58.  
  59.     last if $ARGV[$i] =~ /^--$/;
  60.  
  61.     if ($ARGV[$i] =~ /^-(\d+)$/) {
  62.  
  63.         splice (@ARGV, $i++, 1, '-w', $1);
  64.  
  65.     }
  66.  
  67. }
  68.  
  69.  
  70.  
  71. # Insert -- into @ARGV before any single dash argument to hide it from
  72.  
  73. # Getopt::Long; we want to interpret it as meaning stdin (which Pod::Parser
  74.  
  75. # does correctly).
  76.  
  77. my $stdin;
  78.  
  79. @ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
  80.  
  81.  
  82.  
  83. # Parse our options.  Use the same names as Pod::Text for simplicity, and
  84.  
  85. # default to sentence boundaries turned off for compatibility.
  86.  
  87. my %options;
  88.  
  89. $options{sentence} = 0;
  90.  
  91. Getopt::Long::config ('bundling');
  92.  
  93. GetOptions (\%options, 'alt|a', 'code', 'color|c', 'help|h', 'indent|i=i',
  94.  
  95.             'loose|l', 'margin|left-margin|m=i', 'overstrike|o',
  96.  
  97.             'quotes|q=s', 'sentence|s', 'termcap|t', 'width|w=i') or exit 1;
  98.  
  99. pod2usage (1) if $options{help};
  100.  
  101.  
  102.  
  103. # Figure out what formatter we're going to use.  -c overrides -t.
  104.  
  105. my $formatter = 'Pod::Text';
  106.  
  107. if ($options{color}) {
  108.  
  109.     $formatter = 'Pod::Text::Color';
  110.  
  111.     eval { require Term::ANSIColor };
  112.  
  113.     if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
  114.  
  115.     require Pod::Text::Color;
  116.  
  117. } elsif ($options{termcap}) {
  118.  
  119.     $formatter = 'Pod::Text::Termcap';
  120.  
  121.     require Pod::Text::Termcap;
  122.  
  123. } elsif ($options{overstrike}) {
  124.  
  125.     $formatter = 'Pod::Text::Overstrike';
  126.  
  127.     require Pod::Text::Overstrike;
  128.  
  129. }
  130.  
  131. delete @options{'color', 'termcap', 'overstrike'};
  132.  
  133.  
  134.  
  135. # Initialize and run the formatter.
  136.  
  137. my $parser = $formatter->new (%options);
  138.  
  139. $parser->parse_from_file (@ARGV);
  140.  
  141.  
  142.  
  143. __END__
  144.  
  145.  
  146.  
  147. =head1 NAME
  148.  
  149.  
  150.  
  151. pod2text - Convert POD data to formatted ASCII text
  152.  
  153.  
  154.  
  155. =head1 SYNOPSIS
  156.  
  157.  
  158.  
  159. pod2text [B<-aclost>] [B<--code>] [B<-i> I<indent>] S<[B<-q> I<quotes>]>
  160.  
  161. S<[B<-w> I<width>]> [I<input> [I<output>]]
  162.  
  163.  
  164.  
  165. pod2text B<-h>
  166.  
  167.  
  168.  
  169. =head1 DESCRIPTION
  170.  
  171.  
  172.  
  173. B<pod2text> is a front-end for Pod::Text and its subclasses.  It uses them
  174.  
  175. to generate formatted ASCII text from POD source.  It can optionally use
  176.  
  177. either termcap sequences or ANSI color escape sequences to format the text.
  178.  
  179.  
  180.  
  181. I<input> is the file to read for POD source (the POD can be embedded in
  182.  
  183. code).  If I<input> isn't given, it defaults to STDIN.  I<output>, if given,
  184.  
  185. is the file to which to write the formatted output.  If I<output> isn't
  186.  
  187. given, the formatted output is written to STDOUT.
  188.  
  189.  
  190.  
  191. =head1 OPTIONS
  192.  
  193.  
  194.  
  195. =over 4
  196.  
  197.  
  198.  
  199. =item B<-a>, B<--alt>
  200.  
  201.  
  202.  
  203. Use an alternate output format that, among other things, uses a different
  204.  
  205. heading style and marks C<=item> entries with a colon in the left margin.
  206.  
  207.  
  208.  
  209. =item B<--code>
  210.  
  211.  
  212.  
  213. Include any non-POD text from the input file in the output as well.  Useful
  214.  
  215. for viewing code documented with POD blocks with the POD rendered and the
  216.  
  217. code left intact.
  218.  
  219.  
  220.  
  221. =item B<-c>, B<--color>
  222.  
  223.  
  224.  
  225. Format the output with ANSI color escape sequences.  Using this option
  226.  
  227. requires that Term::ANSIColor be installed on your system.
  228.  
  229.  
  230.  
  231. =item B<-i> I<indent>, B<--indent=>I<indent>
  232.  
  233.  
  234.  
  235. Set the number of spaces to indent regular text, and the default indentation
  236.  
  237. for C<=over> blocks.  Defaults to 4 spaces if this option isn't given.
  238.  
  239.  
  240.  
  241. =item B<-h>, B<--help>
  242.  
  243.  
  244.  
  245. Print out usage information and exit.
  246.  
  247.  
  248.  
  249. =item B<-l>, B<--loose>
  250.  
  251.  
  252.  
  253. Print a blank line after a C<=head1> heading.  Normally, no blank line is
  254.  
  255. printed after C<=head1>, although one is still printed after C<=head2>,
  256.  
  257. because this is the expected formatting for manual pages; if you're
  258.  
  259. formatting arbitrary text documents, using this option is recommended.
  260.  
  261.  
  262.  
  263. =item B<-m> I<width>, B<--left-margin>=I<width>, B<--margin>=I<width>
  264.  
  265.  
  266.  
  267. The width of the left margin in spaces.  Defaults to 0.  This is the margin
  268.  
  269. for all text, including headings, not the amount by which regular text is
  270.  
  271. indented; for the latter, see B<-i> option.
  272.  
  273.  
  274.  
  275. =item B<-o>, B<--overstrike>
  276.  
  277.  
  278.  
  279. Format the output with overstruck printing.  Bold text is rendered as
  280.  
  281. character, backspace, character.  Italics and file names are rendered as
  282.  
  283. underscore, backspace, character.  Many pagers, such as B<less>, know how
  284.  
  285. to convert this to bold or underlined text.
  286.  
  287.  
  288.  
  289. =item B<-q> I<quotes>, B<--quotes>=I<quotes>
  290.  
  291.  
  292.  
  293. Sets the quote marks used to surround CE<lt>> text to I<quotes>.  If
  294.  
  295. I<quotes> is a single character, it is used as both the left and right
  296.  
  297. quote; if I<quotes> is two characters, the first character is used as the
  298.  
  299. left quote and the second as the right quoted; and if I<quotes> is four
  300.  
  301. characters, the first two are used as the left quote and the second two as
  302.  
  303. the right quote.
  304.  
  305.  
  306.  
  307. I<quotes> may also be set to the special value C<none>, in which case no
  308.  
  309. quote marks are added around CE<lt>> text.
  310.  
  311.  
  312.  
  313. =item B<-s>, B<--sentence>
  314.  
  315.  
  316.  
  317. Assume each sentence ends with two spaces and try to preserve that spacing.
  318.  
  319. Without this option, all consecutive whitespace in non-verbatim paragraphs
  320.  
  321. is compressed into a single space.
  322.  
  323.  
  324.  
  325. =item B<-t>, B<--termcap>
  326.  
  327.  
  328.  
  329. Try to determine the width of the screen and the bold and underline
  330.  
  331. sequences for the terminal from termcap, and use that information in
  332.  
  333. formatting the output.  Output will be wrapped at two columns less than the
  334.  
  335. width of your terminal device.  Using this option requires that your system
  336.  
  337. have a termcap file somewhere where Term::Cap can find it and requires that
  338.  
  339. your system support termios.  With this option, the output of B<pod2text>
  340.  
  341. will contain terminal control sequences for your current terminal type.
  342.  
  343.  
  344.  
  345. =item B<-w>, B<--width=>I<width>, B<->I<width>
  346.  
  347.  
  348.  
  349. The column at which to wrap text on the right-hand side.  Defaults to 76,
  350.  
  351. unless B<-t> is given, in which case it's two columns less than the width of
  352.  
  353. your terminal device.
  354.  
  355.  
  356.  
  357. =back
  358.  
  359.  
  360.  
  361. =head1 DIAGNOSTICS
  362.  
  363.  
  364.  
  365. If B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Parser> for
  366.  
  367. information about what those errors might mean.  Internally, it can also
  368.  
  369. produce the following diagnostics:
  370.  
  371.  
  372.  
  373. =over 4
  374.  
  375.  
  376.  
  377. =item -c (--color) requires Term::ANSIColor be installed
  378.  
  379.  
  380.  
  381. (F) B<-c> or B<--color> were given, but Term::ANSIColor could not be
  382.  
  383. loaded.
  384.  
  385.  
  386.  
  387. =item Unknown option: %s
  388.  
  389.  
  390.  
  391. (F) An unknown command line option was given.
  392.  
  393.  
  394.  
  395. =back
  396.  
  397.  
  398.  
  399. In addition, other L<Getopt::Long|Getopt::Long> error messages may result
  400.  
  401. from invalid command-line options.
  402.  
  403.  
  404.  
  405. =head1 ENVIRONMENT
  406.  
  407.  
  408.  
  409. =over 4
  410.  
  411.  
  412.  
  413. =item COLUMNS
  414.  
  415.  
  416.  
  417. If B<-t> is given, B<pod2text> will take the current width of your screen
  418.  
  419. from this environment variable, if available.  It overrides terminal width
  420.  
  421. information in TERMCAP.
  422.  
  423.  
  424.  
  425. =item TERMCAP
  426.  
  427.  
  428.  
  429. If B<-t> is given, B<pod2text> will use the contents of this environment
  430.  
  431. variable if available to determine the correct formatting sequences for your
  432.  
  433. current terminal device.
  434.  
  435.  
  436.  
  437. =back
  438.  
  439.  
  440.  
  441. =head1 SEE ALSO
  442.  
  443.  
  444.  
  445. L<Pod::Text>, L<Pod::Text::Color>, L<Pod::Text::Overstrike>,
  446.  
  447. L<Pod::Text::Termcap>, L<Pod::Parser>
  448.  
  449.  
  450.  
  451. The current version of this script is always available from its web site at
  452.  
  453. L<http://www.eyrie.org/~eagle/software/podlators/>.  It is also part of the
  454.  
  455. Perl core distribution as of 5.6.0.
  456.  
  457.  
  458.  
  459. =head1 AUTHOR
  460.  
  461.  
  462.  
  463. Russ Allbery <rra@stanford.edu>.
  464.  
  465.  
  466.  
  467. =head1 COPYRIGHT AND LICENSE
  468.  
  469.  
  470.  
  471. Copyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>.
  472.  
  473.  
  474.  
  475. This program is free software; you may redistribute it and/or modify it
  476.  
  477. under the same terms as Perl itself.
  478.  
  479.  
  480.  
  481. =cut
  482.  
  483.