Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1387 lines
50 KiB

  1. # Pod::Man -- Convert POD data to formatted *roff input.
  2. # $Id: Man.pm,v 1.15 2001/02/10 06:50:22 eagle Exp $
  3. #
  4. # Copyright 1999, 2000, 2001 by Russ Allbery <[email protected]>
  5. #
  6. # This program is free software; you can redistribute it and/or modify it
  7. # under the same terms as Perl itself.
  8. #
  9. # This module is intended to be a replacement for the pod2man script
  10. # distributed with versions of Perl prior to 5.6, and attempts to match its
  11. # output except for some specific circumstances where other decisions seemed
  12. # to produce better output. It uses Pod::Parser and is designed to be easy
  13. # to subclass.
  14. #
  15. # Perl core hackers, please note that this module is also separately
  16. # maintained outside of the Perl core as part of the podlators. Please send
  17. # me any patches at the address above in addition to sending them to the
  18. # standard Perl mailing lists.
  19. ############################################################################
  20. # Modules and declarations
  21. ############################################################################
  22. package Pod::Man;
  23. require 5.004;
  24. use Carp qw(carp croak);
  25. use Pod::Parser ();
  26. use strict;
  27. use subs qw(makespace);
  28. use vars qw(@ISA %ESCAPES $PREAMBLE $VERSION);
  29. @ISA = qw(Pod::Parser);
  30. # Don't use the CVS revision as the version, since this module is also in
  31. # Perl core and too many things could munge CVS magic revision strings.
  32. # This number should ideally be the same as the CVS revision in podlators,
  33. # however.
  34. $VERSION = 1.15;
  35. ############################################################################
  36. # Preamble and *roff output tables
  37. ############################################################################
  38. # The following is the static preamble which starts all *roff output we
  39. # generate. It's completely static except for the font to use as a
  40. # fixed-width font, which is designed by @CFONT@, and the left and right
  41. # quotes to use for C<> text, designated by @LQOUTE@ and @RQUOTE@.
  42. # $PREAMBLE should therefore be run through s/\@CFONT\@/<font>/g before
  43. # output.
  44. $PREAMBLE = <<'----END OF PREAMBLE----';
  45. .de Sh \" Subsection heading
  46. .br
  47. .if t .Sp
  48. .ne 5
  49. .PP
  50. \fB\\$1\fR
  51. .PP
  52. ..
  53. .de Sp \" Vertical space (when we can't use .PP)
  54. .if t .sp .5v
  55. .if n .sp
  56. ..
  57. .de Ip \" List item
  58. .br
  59. .ie \\n(.$>=3 .ne \\$3
  60. .el .ne 3
  61. .IP "\\$1" \\$2
  62. ..
  63. .de Vb \" Begin verbatim text
  64. .ft @CFONT@
  65. .nf
  66. .ne \\$1
  67. ..
  68. .de Ve \" End verbatim text
  69. .ft R
  70. .fi
  71. ..
  72. .\" Set up some character translations and predefined strings. \*(-- will
  73. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  74. .\" double quote, and \*(R" will give a right double quote. | will give a
  75. .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used
  76. .\" to do unbreakable dashes and therefore won't be available. \*(C` and
  77. .\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
  78. .tr \(*W-|\(bv\*(Tr
  79. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  80. .ie n \{\
  81. . ds -- \(*W-
  82. . ds PI pi
  83. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  84. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  85. . ds L" ""
  86. . ds R" ""
  87. . ds C` @LQUOTE@
  88. . ds C' @RQUOTE@
  89. 'br\}
  90. .el\{\
  91. . ds -- \|\(em\|
  92. . ds PI \(*p
  93. . ds L" ``
  94. . ds R" ''
  95. 'br\}
  96. .\"
  97. .\" If the F register is turned on, we'll generate index entries on stderr
  98. .\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
  99. .\" index entries marked with X<> in POD. Of course, you'll have to process
  100. .\" the output yourself in some meaningful fashion.
  101. .if \nF \{\
  102. . de IX
  103. . tm Index:\\$1\t\\n%\t"\\$2"
  104. ..
  105. . nr % 0
  106. . rr F
  107. .\}
  108. .\"
  109. .\" For nroff, turn off justification. Always turn off hyphenation; it
  110. .\" makes way too many mistakes in technical documents.
  111. .hy 0
  112. .if n .na
  113. .\"
  114. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  115. .\" Fear. Run. Save yourself. No user-serviceable parts.
  116. .bd B 3
  117. . \" fudge factors for nroff and troff
  118. .if n \{\
  119. . ds #H 0
  120. . ds #V .8m
  121. . ds #F .3m
  122. . ds #[ \f1
  123. . ds #] \fP
  124. .\}
  125. .if t \{\
  126. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  127. . ds #V .6m
  128. . ds #F 0
  129. . ds #[ \&
  130. . ds #] \&
  131. .\}
  132. . \" simple accents for nroff and troff
  133. .if n \{\
  134. . ds ' \&
  135. . ds ` \&
  136. . ds ^ \&
  137. . ds , \&
  138. . ds ~ ~
  139. . ds /
  140. .\}
  141. .if t \{\
  142. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  143. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  144. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  145. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  146. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  147. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  148. .\}
  149. . \" troff and (daisy-wheel) nroff accents
  150. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  151. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  152. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  153. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  154. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  155. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  156. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  157. .ds ae a\h'-(\w'a'u*4/10)'e
  158. .ds Ae A\h'-(\w'A'u*4/10)'E
  159. . \" corrections for vroff
  160. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  161. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  162. . \" for low resolution devices (crt and lpr)
  163. .if \n(.H>23 .if \n(.V>19 \
  164. \{\
  165. . ds : e
  166. . ds 8 ss
  167. . ds o a
  168. . ds d- d\h'-1'\(ga
  169. . ds D- D\h'-1'\(hy
  170. . ds th \o'bp'
  171. . ds Th \o'LP'
  172. . ds ae ae
  173. . ds Ae AE
  174. .\}
  175. .rm #[ #] #H #V #F C
  176. ----END OF PREAMBLE----
  177. #`# for cperl-mode
  178. # This table is taken nearly verbatim from Tom Christiansen's pod2man. It
  179. # assumes that the standard preamble has already been printed, since that's
  180. # what defines all of the accent marks. Note that some of these are quoted
  181. # with double quotes since they contain embedded single quotes, so use \\
  182. # uniformly for backslash for readability.
  183. %ESCAPES = (
  184. 'amp' => '&', # ampersand
  185. 'lt' => '<', # left chevron, less-than
  186. 'gt' => '>', # right chevron, greater-than
  187. 'quot' => '"', # double quote
  188. 'sol' => '/', # solidus (forward slash)
  189. 'verbar' => '|', # vertical bar
  190. 'Aacute' => "A\\*'", # capital A, acute accent
  191. 'aacute' => "a\\*'", # small a, acute accent
  192. 'Acirc' => 'A\\*^', # capital A, circumflex accent
  193. 'acirc' => 'a\\*^', # small a, circumflex accent
  194. 'AElig' => '\*(AE', # capital AE diphthong (ligature)
  195. 'aelig' => '\*(ae', # small ae diphthong (ligature)
  196. 'Agrave' => "A\\*`", # capital A, grave accent
  197. 'agrave' => "A\\*`", # small a, grave accent
  198. 'Aring' => 'A\\*o', # capital A, ring
  199. 'aring' => 'a\\*o', # small a, ring
  200. 'Atilde' => 'A\\*~', # capital A, tilde
  201. 'atilde' => 'a\\*~', # small a, tilde
  202. 'Auml' => 'A\\*:', # capital A, dieresis or umlaut mark
  203. 'auml' => 'a\\*:', # small a, dieresis or umlaut mark
  204. 'Ccedil' => 'C\\*,', # capital C, cedilla
  205. 'ccedil' => 'c\\*,', # small c, cedilla
  206. 'Eacute' => "E\\*'", # capital E, acute accent
  207. 'eacute' => "e\\*'", # small e, acute accent
  208. 'Ecirc' => 'E\\*^', # capital E, circumflex accent
  209. 'ecirc' => 'e\\*^', # small e, circumflex accent
  210. 'Egrave' => 'E\\*`', # capital E, grave accent
  211. 'egrave' => 'e\\*`', # small e, grave accent
  212. 'ETH' => '\\*(D-', # capital Eth, Icelandic
  213. 'eth' => '\\*(d-', # small eth, Icelandic
  214. 'Euml' => 'E\\*:', # capital E, dieresis or umlaut mark
  215. 'euml' => 'e\\*:', # small e, dieresis or umlaut mark
  216. 'Iacute' => "I\\*'", # capital I, acute accent
  217. 'iacute' => "i\\*'", # small i, acute accent
  218. 'Icirc' => 'I\\*^', # capital I, circumflex accent
  219. 'icirc' => 'i\\*^', # small i, circumflex accent
  220. 'Igrave' => 'I\\*`', # capital I, grave accent
  221. 'igrave' => 'i\\*`', # small i, grave accent
  222. 'Iuml' => 'I\\*:', # capital I, dieresis or umlaut mark
  223. 'iuml' => 'i\\*:', # small i, dieresis or umlaut mark
  224. 'Ntilde' => 'N\*~', # capital N, tilde
  225. 'ntilde' => 'n\*~', # small n, tilde
  226. 'Oacute' => "O\\*'", # capital O, acute accent
  227. 'oacute' => "o\\*'", # small o, acute accent
  228. 'Ocirc' => 'O\\*^', # capital O, circumflex accent
  229. 'ocirc' => 'o\\*^', # small o, circumflex accent
  230. 'Ograve' => 'O\\*`', # capital O, grave accent
  231. 'ograve' => 'o\\*`', # small o, grave accent
  232. 'Oslash' => 'O\\*/', # capital O, slash
  233. 'oslash' => 'o\\*/', # small o, slash
  234. 'Otilde' => 'O\\*~', # capital O, tilde
  235. 'otilde' => 'o\\*~', # small o, tilde
  236. 'Ouml' => 'O\\*:', # capital O, dieresis or umlaut mark
  237. 'ouml' => 'o\\*:', # small o, dieresis or umlaut mark
  238. 'szlig' => '\*8', # small sharp s, German (sz ligature)
  239. 'THORN' => '\\*(Th', # capital THORN, Icelandic
  240. 'thorn' => '\\*(th', # small thorn, Icelandic
  241. 'Uacute' => "U\\*'", # capital U, acute accent
  242. 'uacute' => "u\\*'", # small u, acute accent
  243. 'Ucirc' => 'U\\*^', # capital U, circumflex accent
  244. 'ucirc' => 'u\\*^', # small u, circumflex accent
  245. 'Ugrave' => 'U\\*`', # capital U, grave accent
  246. 'ugrave' => 'u\\*`', # small u, grave accent
  247. 'Uuml' => 'U\\*:', # capital U, dieresis or umlaut mark
  248. 'uuml' => 'u\\*:', # small u, dieresis or umlaut mark
  249. 'Yacute' => "Y\\*'", # capital Y, acute accent
  250. 'yacute' => "y\\*'", # small y, acute accent
  251. 'yuml' => 'y\\*:', # small y, dieresis or umlaut mark
  252. );
  253. ############################################################################
  254. # Static helper functions
  255. ############################################################################
  256. # Protect leading quotes and periods against interpretation as commands.
  257. # Also protect anything starting with a backslash, since it could expand
  258. # or hide something that *roff would interpret as a command. This is
  259. # overkill, but it's much simpler than trying to parse *roff here.
  260. sub protect {
  261. local $_ = shift;
  262. s/^([.\'\\])/\\&$1/mg;
  263. $_;
  264. }
  265. # Translate a font string into an escape.
  266. sub toescape { (length ($_[0]) > 1 ? '\f(' : '\f') . $_[0] }
  267. ############################################################################
  268. # Initialization
  269. ############################################################################
  270. # Initialize the object. Here, we also process any additional options
  271. # passed to the constructor or set up defaults if none were given. center
  272. # is the centered title, release is the version number, and date is the date
  273. # for the documentation. Note that we can't know what file name we're
  274. # processing due to the architecture of Pod::Parser, so that *has* to either
  275. # be passed to the constructor or set separately with Pod::Man::name().
  276. sub initialize {
  277. my $self = shift;
  278. # Figure out the fixed-width font. If user-supplied, make sure that
  279. # they are the right length.
  280. for (qw/fixed fixedbold fixeditalic fixedbolditalic/) {
  281. if (defined $$self{$_}) {
  282. if (length ($$self{$_}) < 1 || length ($$self{$_}) > 2) {
  283. croak qq(roff font should be 1 or 2 chars,)
  284. . qq( not "$$self{$_}");
  285. }
  286. } else {
  287. $$self{$_} = '';
  288. }
  289. }
  290. # Set the default fonts. We can't be sure what fixed bold-italic is
  291. # going to be called, so default to just bold.
  292. $$self{fixed} ||= 'CW';
  293. $$self{fixedbold} ||= 'CB';
  294. $$self{fixeditalic} ||= 'CI';
  295. $$self{fixedbolditalic} ||= 'CB';
  296. # Set up a table of font escapes. First number is fixed-width, second
  297. # is bold, third is italic.
  298. $$self{FONTS} = { '000' => '\fR', '001' => '\fI',
  299. '010' => '\fB', '011' => '\f(BI',
  300. '100' => toescape ($$self{fixed}),
  301. '101' => toescape ($$self{fixeditalic}),
  302. '110' => toescape ($$self{fixedbold}),
  303. '111' => toescape ($$self{fixedbolditalic})};
  304. # Extra stuff for page titles.
  305. $$self{center} = 'User Contributed Perl Documentation'
  306. unless defined $$self{center};
  307. $$self{indent} = 4 unless defined $$self{indent};
  308. # We used to try first to get the version number from a local binary,
  309. # but we shouldn't need that any more. Get the version from the running
  310. # Perl. Work a little magic to handle subversions correctly under both
  311. # the pre-5.6 and the post-5.6 version numbering schemes.
  312. if (!defined $$self{release}) {
  313. my @version = ($] =~ /^(\d+)\.(\d{3})(\d{0,3})$/);
  314. $version[2] ||= 0;
  315. $version[2] *= 10 ** (3 - length $version[2]);
  316. for (@version) { $_ += 0 }
  317. $$self{release} = 'perl v' . join ('.', @version);
  318. }
  319. # Double quotes in things that will be quoted.
  320. for (qw/center date release/) {
  321. $$self{$_} =~ s/\"/\"\"/g if $$self{$_};
  322. }
  323. # Figure out what quotes we'll be using for C<> text.
  324. $$self{quotes} ||= '"';
  325. if ($$self{quotes} eq 'none') {
  326. $$self{LQUOTE} = $$self{RQUOTE} = '';
  327. } elsif (length ($$self{quotes}) == 1) {
  328. $$self{LQUOTE} = $$self{RQUOTE} = $$self{quotes};
  329. } elsif ($$self{quotes} =~ /^(.)(.)$/
  330. || $$self{quotes} =~ /^(..)(..)$/) {
  331. $$self{LQUOTE} = $1;
  332. $$self{RQUOTE} = $2;
  333. } else {
  334. croak qq(Invalid quote specification "$$self{quotes}");
  335. }
  336. # Double the first quote; note that this should not be s///g as two
  337. # double quotes is represented in *roff as three double quotes, not
  338. # four. Weird, I know.
  339. $$self{LQUOTE} =~ s/\"/\"\"/;
  340. $$self{RQUOTE} =~ s/\"/\"\"/;
  341. $$self{INDENT} = 0; # Current indentation level.
  342. $$self{INDENTS} = []; # Stack of indentations.
  343. $$self{INDEX} = []; # Index keys waiting to be printed.
  344. $$self{ITEMS} = 0; # The number of consecutive =items.
  345. $self->SUPER::initialize;
  346. }
  347. # For each document we process, output the preamble first.
  348. sub begin_pod {
  349. my $self = shift;
  350. # Try to figure out the name and section from the file name.
  351. my $section = $$self{section} || 1;
  352. my $name = $$self{name};
  353. if (!defined $name) {
  354. $name = $self->input_file;
  355. $section = 3 if (!$$self{section} && $name =~ /\.pm\z/i);
  356. $name =~ s/\.p(od|[lm])\z//i;
  357. if ($section =~ /^1/) {
  358. require File::Basename;
  359. $name = uc File::Basename::basename ($name);
  360. } else {
  361. # Lose everything up to the first of
  362. # */lib/*perl* standard or site_perl module
  363. # */*perl*/lib from -D prefix=/opt/perl
  364. # */*perl*/ random module hierarchy
  365. # which works. Should be fixed to use File::Spec. Also handle
  366. # a leading lib/ since that's what ExtUtils::MakeMaker creates.
  367. for ($name) {
  368. s%//+%/%g;
  369. if ( s%^.*?/lib/[^/]*perl[^/]*/%%si
  370. or s%^.*?/[^/]*perl[^/]*/(?:lib/)?%%si) {
  371. s%^site(_perl)?/%%s; # site and site_perl
  372. s%^(.*-$^O|$^O-.*)/%%so; # arch
  373. s%^\d+\.\d+%%s; # version
  374. }
  375. s%^lib/%%;
  376. s%/%::%g;
  377. }
  378. }
  379. }
  380. # If $name contains spaces, quote it; this mostly comes up in the case
  381. # of input from stdin.
  382. $name = '"' . $name . '"' if ($name =~ /\s/);
  383. # Modification date header. Try to use the modification time of our
  384. # input.
  385. if (!defined $$self{date}) {
  386. my $time = (stat $self->input_file)[9] || time;
  387. my ($day, $month, $year) = (localtime $time)[3,4,5];
  388. $month++;
  389. $year += 1900;
  390. $$self{date} = sprintf ('%4d-%02d-%02d', $year, $month, $day);
  391. }
  392. # Now, print out the preamble and the title.
  393. local $_ = $PREAMBLE;
  394. s/\@CFONT\@/$$self{fixed}/;
  395. s/\@LQUOTE\@/$$self{LQUOTE}/;
  396. s/\@RQUOTE\@/$$self{RQUOTE}/;
  397. chomp $_;
  398. print { $self->output_handle } <<"----END OF HEADER----";
  399. .\\" Automatically generated by Pod::Man version $VERSION
  400. .\\" @{[ scalar localtime ]}
  401. .\\"
  402. .\\" Standard preamble:
  403. .\\" ======================================================================
  404. $_
  405. .\\" ======================================================================
  406. .\\"
  407. .IX Title "$name $section"
  408. .TH $name $section "$$self{release}" "$$self{date}" "$$self{center}"
  409. .UC
  410. ----END OF HEADER----
  411. #"# for cperl-mode
  412. # Initialize a few per-file variables.
  413. $$self{INDENT} = 0;
  414. $$self{NEEDSPACE} = 0;
  415. }
  416. ############################################################################
  417. # Core overrides
  418. ############################################################################
  419. # Called for each command paragraph. Gets the command, the associated
  420. # paragraph, the line number, and a Pod::Paragraph object. Just dispatches
  421. # the command to a method named the same as the command. =cut is handled
  422. # internally by Pod::Parser.
  423. sub command {
  424. my $self = shift;
  425. my $command = shift;
  426. return if $command eq 'pod';
  427. return if ($$self{EXCLUDE} && $command ne 'end');
  428. if ($self->can ('cmd_' . $command)) {
  429. $command = 'cmd_' . $command;
  430. $self->$command (@_);
  431. } else {
  432. my ($text, $line, $paragraph) = @_;
  433. my $file;
  434. ($file, $line) = $paragraph->file_line;
  435. $text =~ s/\n+\z//;
  436. $text = " $text" if ($text =~ /^\S/);
  437. warn qq($file:$line: Unknown command paragraph "=$command$text"\n);
  438. return;
  439. }
  440. }
  441. # Called for a verbatim paragraph. Gets the paragraph, the line number, and
  442. # a Pod::Paragraph object. Rofficate backslashes, untabify, put a
  443. # zero-width character at the beginning of each line to protect against
  444. # commands, and wrap in .Vb/.Ve.
  445. sub verbatim {
  446. my $self = shift;
  447. return if $$self{EXCLUDE};
  448. local $_ = shift;
  449. return if /^\s+$/;
  450. s/\s+$/\n/;
  451. my $lines = tr/\n/\n/;
  452. 1 while s/^(.*?)(\t+)/$1 . ' ' x (length ($2) * 8 - length ($1) % 8)/me;
  453. s/\\/\\e/g;
  454. s/^(\s*\S)/'\&' . $1/gme;
  455. $self->makespace;
  456. $self->output (".Vb $lines\n$_.Ve\n");
  457. $$self{NEEDSPACE} = 0;
  458. }
  459. # Called for a regular text block. Gets the paragraph, the line number, and
  460. # a Pod::Paragraph object. Perform interpolation and output the results.
  461. sub textblock {
  462. my $self = shift;
  463. return if $$self{EXCLUDE};
  464. $self->output ($_[0]), return if $$self{VERBATIM};
  465. # Perform a little magic to collapse multiple L<> references. We'll
  466. # just rewrite the whole thing into actual text at this part, bypassing
  467. # the whole internal sequence parsing thing.
  468. my $text = shift;
  469. $text =~ s{
  470. (L< # A link of the form L</something>.
  471. /
  472. (
  473. [:\w]+ # The item has to be a simple word...
  474. (\(\))? # ...or simple function.
  475. )
  476. >
  477. (
  478. ,?\s+(and\s+)? # Allow lots of them, conjuncted.
  479. L<
  480. /
  481. ( [:\w]+ ( \(\) )? )
  482. >
  483. )+
  484. )
  485. } {
  486. local $_ = $1;
  487. s{ L< / ( [^>]+ ) > } {$1}xg;
  488. my @items = split /(?:,?\s+(?:and\s+)?)/;
  489. my $string = 'the ';
  490. my $i;
  491. for ($i = 0; $i < @items; $i++) {
  492. $string .= $items[$i];
  493. $string .= ', ' if @items > 2 && $i != $#items;
  494. $string .= ' ' if @items == 2 && $i == 2;
  495. $string .= 'and ' if ($i == $#items - 1);
  496. }
  497. $string .= ' entries elsewhere in this document';
  498. $string;
  499. }gex;
  500. # Parse the tree and output it. collapse knows about references to
  501. # scalars as well as scalars and does the right thing with them.
  502. $text = $self->parse ($text, @_);
  503. $text =~ s/\n\s*$/\n/;
  504. $self->makespace;
  505. $self->output (protect $self->textmapfonts ($text));
  506. $self->outindex;
  507. $$self{NEEDSPACE} = 1;
  508. }
  509. # Called for an interior sequence. Takes a Pod::InteriorSequence object and
  510. # returns a reference to a scalar. This scalar is the final formatted text.
  511. # It's returned as a reference so that other interior sequences above us
  512. # know that the text has already been processed.
  513. sub sequence {
  514. my ($self, $seq) = @_;
  515. my $command = $seq->cmd_name;
  516. # Zero-width characters.
  517. if ($command eq 'Z') {
  518. # Workaround to generate a blessable reference, needed by 5.005.
  519. my $tmp = '\&';
  520. return bless \ "$tmp", 'Pod::Man::String';
  521. }
  522. # C<>, L<>, X<>, and E<> don't apply guesswork to their contents. C<>
  523. # needs some additional special handling.
  524. my $literal = ($command =~ /^[CELX]$/);
  525. $literal++ if $command eq 'C';
  526. local $_ = $self->collapse ($seq->parse_tree, $literal);
  527. # Handle E<> escapes.
  528. if ($command eq 'E') {
  529. if (/^\d+$/) {
  530. return bless \ chr ($_), 'Pod::Man::String';
  531. } elsif (exists $ESCAPES{$_}) {
  532. return bless \ "$ESCAPES{$_}", 'Pod::Man::String';
  533. } else {
  534. carp "Unknown escape E<$1>";
  535. return bless \ "E<$_>", 'Pod::Man::String';
  536. }
  537. }
  538. # For all the other sequences, empty content produces no output.
  539. return '' if $_ eq '';
  540. # Handle formatting sequences.
  541. if ($command eq 'B') {
  542. return bless \ ('\f(BS' . $_ . '\f(BE'), 'Pod::Man::String';
  543. } elsif ($command eq 'F') {
  544. return bless \ ('\f(IS' . $_ . '\f(IE'), 'Pod::Man::String';
  545. } elsif ($command eq 'I') {
  546. return bless \ ('\f(IS' . $_ . '\f(IE'), 'Pod::Man::String';
  547. } elsif ($command eq 'C') {
  548. return bless \ ('\f(FS\*(C`' . $_ . "\\*(C'\\f(FE"),
  549. 'Pod::Man::String';
  550. }
  551. # Handle links.
  552. if ($command eq 'L') {
  553. # A bug in lvalue subs in 5.6 requires the temporary variable.
  554. my $tmp = $self->buildlink ($_);
  555. return bless \ "$tmp", 'Pod::Man::String';
  556. }
  557. # Whitespace protection replaces whitespace with "\ ".
  558. if ($command eq 'S') {
  559. s/\s+/\\ /g;
  560. return bless \ "$_", 'Pod::Man::String';
  561. }
  562. # Add an index entry to the list of ones waiting to be output.
  563. if ($command eq 'X') { push (@{ $$self{INDEX} }, $_); return '' }
  564. # Anything else is unknown.
  565. carp "Unknown sequence $command<$_>";
  566. }
  567. ############################################################################
  568. # Command paragraphs
  569. ############################################################################
  570. # All command paragraphs take the paragraph and the line number.
  571. # First level heading. We can't output .IX in the NAME section due to a bug
  572. # in some versions of catman, so don't output a .IX for that section. .SH
  573. # already uses small caps, so remove any E<> sequences that would cause
  574. # them.
  575. sub cmd_head1 {
  576. my $self = shift;
  577. local $_ = $self->parse (@_);
  578. s/\s+$//;
  579. s/\\s-?\d//g;
  580. s/\s*\n\s*/ /g;
  581. if ($$self{ITEMS} > 1) {
  582. $$self{ITEMS} = 0;
  583. $self->output (".PD\n");
  584. }
  585. $self->output ($self->switchquotes ('.SH', $self->mapfonts ($_)));
  586. $self->outindex (($_ eq 'NAME') ? () : ('Header', $_));
  587. $$self{NEEDSPACE} = 0;
  588. }
  589. # Second level heading.
  590. sub cmd_head2 {
  591. my $self = shift;
  592. local $_ = $self->parse (@_);
  593. s/\s+$//;
  594. s/\s*\n\s*/ /g;
  595. if ($$self{ITEMS} > 1) {
  596. $$self{ITEMS} = 0;
  597. $self->output (".PD\n");
  598. }
  599. $self->output ($self->switchquotes ('.Sh', $self->mapfonts ($_)));
  600. $self->outindex ('Subsection', $_);
  601. $$self{NEEDSPACE} = 0;
  602. }
  603. # Third level heading.
  604. sub cmd_head3 {
  605. my $self = shift;
  606. local $_ = $self->parse (@_);
  607. s/\s+$//;
  608. s/\s*\n\s*/ /g;
  609. if ($$self{ITEMS} > 1) {
  610. $$self{ITEMS} = 0;
  611. $self->output (".PD\n");
  612. }
  613. $self->makespace;
  614. $self->output ($self->switchquotes ('.I', $self->mapfonts ($_)));
  615. $self->outindex ('Subsection', $_);
  616. $$self{NEEDSPACE} = 1;
  617. }
  618. # Fourth level heading.
  619. sub cmd_head4 {
  620. my $self = shift;
  621. local $_ = $self->parse (@_);
  622. s/\s+$//;
  623. s/\s*\n\s*/ /g;
  624. if ($$self{ITEMS} > 1) {
  625. $$self{ITEMS} = 0;
  626. $self->output (".PD\n");
  627. }
  628. $self->makespace;
  629. $self->output ($self->textmapfonts ($_) . "\n");
  630. $self->outindex ('Subsection', $_);
  631. $$self{NEEDSPACE} = 1;
  632. }
  633. # Start a list. For indents after the first, wrap the outside indent in .RS
  634. # so that hanging paragraph tags will be correct.
  635. sub cmd_over {
  636. my $self = shift;
  637. local $_ = shift;
  638. unless (/^[-+]?\d+\s+$/) { $_ = $$self{indent} }
  639. if (@{ $$self{INDENTS} } > 0) {
  640. $self->output (".RS $$self{INDENT}\n");
  641. }
  642. push (@{ $$self{INDENTS} }, $$self{INDENT});
  643. $$self{INDENT} = ($_ + 0);
  644. }
  645. # End a list. If we've closed an embedded indent, we've mangled the hanging
  646. # paragraph indent, so temporarily replace it with .RS and set WEIRDINDENT.
  647. # We'll close that .RS at the next =back or =item.
  648. sub cmd_back {
  649. my $self = shift;
  650. $$self{INDENT} = pop @{ $$self{INDENTS} };
  651. unless (defined $$self{INDENT}) {
  652. carp "Unmatched =back";
  653. $$self{INDENT} = 0;
  654. }
  655. if ($$self{WEIRDINDENT}) {
  656. $self->output (".RE\n");
  657. $$self{WEIRDINDENT} = 0;
  658. }
  659. if (@{ $$self{INDENTS} } > 0) {
  660. $self->output (".RE\n");
  661. $self->output (".RS $$self{INDENT}\n");
  662. $$self{WEIRDINDENT} = 1;
  663. }
  664. $$self{NEEDSPACE} = 1;
  665. }
  666. # An individual list item. Emit an index entry for anything that's
  667. # interesting, but don't emit index entries for things like bullets and
  668. # numbers. rofficate bullets too while we're at it (so for nice output, use
  669. # * for your lists rather than o or . or - or some other thing). Newlines
  670. # in an item title are turned into spaces since *roff can't handle them
  671. # embedded.
  672. sub cmd_item {
  673. my $self = shift;
  674. local $_ = $self->parse (@_);
  675. s/\s+$//;
  676. s/\s*\n\s*/ /g;
  677. my $index;
  678. if (/\w/ && !/^\w[.\)]\s*$/) {
  679. $index = $_;
  680. $index =~ s/^\s*[-*+o.]?(?:\s+|\Z)//;
  681. }
  682. s/^\*(\s|\Z)/\\\(bu$1/;
  683. if ($$self{WEIRDINDENT}) {
  684. $self->output (".RE\n");
  685. $$self{WEIRDINDENT} = 0;
  686. }
  687. $_ = $self->textmapfonts ($_);
  688. $self->output (".PD 0\n") if ($$self{ITEMS} == 1);
  689. $self->output ($self->switchquotes ('.Ip', $_, $$self{INDENT}));
  690. $self->outindex ($index ? ('Item', $index) : ());
  691. $$self{NEEDSPACE} = 0;
  692. $$self{ITEMS}++;
  693. }
  694. # Begin a block for a particular translator. Setting VERBATIM triggers
  695. # special handling in textblock().
  696. sub cmd_begin {
  697. my $self = shift;
  698. local $_ = shift;
  699. my ($kind) = /^(\S+)/ or return;
  700. if ($kind eq 'man' || $kind eq 'roff') {
  701. $$self{VERBATIM} = 1;
  702. } else {
  703. $$self{EXCLUDE} = 1;
  704. }
  705. }
  706. # End a block for a particular translator. We assume that all =begin/=end
  707. # pairs are properly closed.
  708. sub cmd_end {
  709. my $self = shift;
  710. $$self{EXCLUDE} = 0;
  711. $$self{VERBATIM} = 0;
  712. }
  713. # One paragraph for a particular translator. Ignore it unless it's intended
  714. # for man or roff, in which case we output it verbatim.
  715. sub cmd_for {
  716. my $self = shift;
  717. local $_ = shift;
  718. return unless s/^(?:man|roff)\b[ \t]*\n?//;
  719. $self->output ($_);
  720. }
  721. ############################################################################
  722. # Link handling
  723. ############################################################################
  724. # Handle links. We can't actually make real hyperlinks, so this is all to
  725. # figure out what text and formatting we print out.
  726. sub buildlink {
  727. my $self = shift;
  728. local $_ = shift;
  729. # Smash whitespace in case we were split across multiple lines.
  730. s/\s+/ /g;
  731. # If we were given any explicit text, just output it.
  732. if (m{ ^ ([^|]+) \| }x) { return $1 }
  733. # Okay, leading and trailing whitespace isn't important.
  734. s/^\s+//;
  735. s/\s+$//;
  736. # If the argument looks like a URL, return it verbatim. This only
  737. # handles URLs that use the server syntax.
  738. if (m%^[a-z]+://\S+$%) { return $_ }
  739. # Default to using the whole content of the link entry as a section
  740. # name. Note that L<manpage/> forces a manpage interpretation, as does
  741. # something looking like L<manpage(section)>. Do the same thing to
  742. # L<manpage(section)> as we would to manpage(section) without the L<>;
  743. # see guesswork(). If we've added italics, don't add the "manpage"
  744. # text; markup is sufficient.
  745. my ($manpage, $section) = ('', $_);
  746. if (/^"\s*(.*?)\s*"$/) {
  747. $section = '"' . $1 . '"';
  748. } elsif (m{ ^ [-:.\w]+ (?: \( \S+ \) )? $ }x) {
  749. ($manpage, $section) = ($_, '');
  750. $manpage =~ s/^([^\(]+)\(/'\f(IS' . $1 . '\f(IE\|('/e;
  751. } elsif (m%/%) {
  752. ($manpage, $section) = split (/\s*\/\s*/, $_, 2);
  753. if ($manpage =~ /^[-:.\w]+(?:\(\S+\))?$/) {
  754. $manpage =~ s/^([^\(]+)\(/'\f(IS' . $1 . '\f(IE\|'/e;
  755. }
  756. $section =~ s/^\"\s*//;
  757. $section =~ s/\s*\"$//;
  758. }
  759. if ($manpage && $manpage !~ /\\f\(IS/) {
  760. $manpage = "the $manpage manpage";
  761. }
  762. # Now build the actual output text.
  763. my $text = '';
  764. if (!length ($section) && !length ($manpage)) {
  765. carp "Invalid link $_";
  766. } elsif (!length ($section)) {
  767. $text = $manpage;
  768. } elsif ($section =~ /^[:\w]+(?:\(\))?/) {
  769. $text .= 'the ' . $section . ' entry';
  770. $text .= (length $manpage) ? " in $manpage"
  771. : " elsewhere in this document";
  772. } else {
  773. if ($section !~ /^".*"$/) { $section = '"' . $section . '"' }
  774. $text .= 'the section on ' . $section;
  775. $text .= " in $manpage" if length $manpage;
  776. }
  777. $text;
  778. }
  779. ############################################################################
  780. # Escaping and fontification
  781. ############################################################################
  782. # At this point, we'll have embedded font codes of the form \f(<font>[SE]
  783. # where <font> is one of B, I, or F. Turn those into the right font start
  784. # or end codes. The old pod2man didn't get B<someI<thing> else> right;
  785. # after I<> it switched back to normal text rather than bold. We take care
  786. # of this by using variables as a combined pointer to our current font
  787. # sequence, and set each to the number of current nestings of start tags for
  788. # that font. Use them as a vector to look up what font sequence to use.
  789. #
  790. # \fP changes to the previous font, but only one previous font is kept. We
  791. # don't know what the outside level font is; normally it's R, but if we're
  792. # inside a heading it could be something else. So arrange things so that
  793. # the outside font is always the "previous" font and end with \fP instead of
  794. # \fR. Idea from Zack Weinberg.
  795. sub mapfonts {
  796. my $self = shift;
  797. local $_ = shift;
  798. my ($fixed, $bold, $italic) = (0, 0, 0);
  799. my %magic = (F => \$fixed, B => \$bold, I => \$italic);
  800. my $last = '\fR';
  801. s { \\f\((.)(.) } {
  802. my $sequence = '';
  803. my $f;
  804. if ($last ne '\fR') { $sequence = '\fP' }
  805. ${ $magic{$1} } += ($2 eq 'S') ? 1 : -1;
  806. $f = $$self{FONTS}{($fixed && 1) . ($bold && 1) . ($italic && 1)};
  807. if ($f eq $last) {
  808. '';
  809. } else {
  810. if ($f ne '\fR') { $sequence .= $f }
  811. $last = $f;
  812. $sequence;
  813. }
  814. }gxe;
  815. $_;
  816. }
  817. # Unfortunately, there is a bug in Solaris 2.6 nroff (not present in GNU
  818. # groff) where the sequence \fB\fP\f(CW\fP leaves the font set to B rather
  819. # than R, presumably because \f(CW doesn't actually do a font change. To
  820. # work around this, use a separate textmapfonts for text blocks where the
  821. # default font is always R and only use the smart mapfonts for headings.
  822. sub textmapfonts {
  823. my $self = shift;
  824. local $_ = shift;
  825. my ($fixed, $bold, $italic) = (0, 0, 0);
  826. my %magic = (F => \$fixed, B => \$bold, I => \$italic);
  827. s { \\f\((.)(.) } {
  828. ${ $magic{$1} } += ($2 eq 'S') ? 1 : -1;
  829. $$self{FONTS}{($fixed && 1) . ($bold && 1) . ($italic && 1)};
  830. }gxe;
  831. $_;
  832. }
  833. ############################################################################
  834. # *roff-specific parsing
  835. ############################################################################
  836. # Called instead of parse_text, calls parse_text with the right flags.
  837. sub parse {
  838. my $self = shift;
  839. $self->parse_text ({ -expand_seq => 'sequence',
  840. -expand_ptree => 'collapse' }, @_);
  841. }
  842. # Takes a parse tree and a flag saying whether or not to treat it as literal
  843. # text (not call guesswork on it), and returns the concatenation of all of
  844. # the text strings in that parse tree. If the literal flag isn't true,
  845. # guesswork() will be called on all plain scalars in the parse tree.
  846. # Otherwise, just escape backslashes in the normal case. If collapse is
  847. # being called on a C<> sequence, literal is set to 2, and we do some
  848. # additional cleanup. Assumes that everything in the parse tree is either a
  849. # scalar or a reference to a scalar.
  850. sub collapse {
  851. my ($self, $ptree, $literal) = @_;
  852. if ($literal) {
  853. return join ('', map {
  854. if (ref $_) {
  855. $$_;
  856. } else {
  857. s/\\/\\e/g;
  858. s/-/\\-/g if $literal > 1;
  859. s/__/_\\|_/g if $literal > 1;
  860. $_;
  861. }
  862. } $ptree->children);
  863. } else {
  864. return join ('', map {
  865. ref ($_) ? $$_ : $self->guesswork ($_)
  866. } $ptree->children);
  867. }
  868. }
  869. # Takes a text block to perform guesswork on; this is guaranteed not to
  870. # contain any interior sequences. Returns the text block with remapping
  871. # done.
  872. sub guesswork {
  873. my $self = shift;
  874. local $_ = shift;
  875. # rofficate backslashes.
  876. s/\\/\\e/g;
  877. # Ensure double underbars have a tiny space between them.
  878. s/__/_\\|_/g;
  879. # Make all caps a little smaller. Be careful here, since we don't want
  880. # to make @ARGV into small caps, nor do we want to fix the MIME in
  881. # MIME-Version, since it looks weird with the full-height V.
  882. s{
  883. ( ^ | [\s\(\"\'\`\[\{<>] )
  884. ( [A-Z] [A-Z] [/A-Z+:\d_\$&-]* )
  885. (?: (?= [\s>\}\]\)\'\".?!,;:] | -- ) | $ )
  886. } { $1 . '\s-1' . $2 . '\s0' }egx;
  887. # Turn PI into a pretty pi.
  888. s{ (?: \\s-1 | \b ) PI (?: \\s0 | \b ) } {\\*\(PI}gx;
  889. # Italize functions in the form func().
  890. s{
  891. \b
  892. (
  893. [:\w]+ (?:\\s-1)? \(\)
  894. )
  895. } { '\f(IS' . $1 . '\f(IE' }egx;
  896. # func(n) is a reference to a manual page. Make it \fIfunc\fR\|(n).
  897. s{
  898. \b
  899. (\w[-:.\w]+ (?:\\s-1)?)
  900. (
  901. \( [^\)] \)
  902. )
  903. } { '\f(IS' . $1 . '\f(IE\|' . $2 }egx;
  904. # Convert simple Perl variable references to a fixed-width font.
  905. s{
  906. ( \s+ )
  907. ( [\$\@%] [\w:]+ )
  908. (?! \( )
  909. } { $1 . '\f(FS' . $2 . '\f(FE'}egx;
  910. # Translate -- into a real em dash if it's used like one and fix up
  911. # dashes, but keep hyphens hyphens.
  912. s{ (\G|^|.) (-+) (\b|.) } {
  913. my ($pre, $dash, $post) = ($1, $2, $3);
  914. if (length ($dash) == 1) {
  915. ($pre =~ /[a-zA-Z]/) ? "$pre-$post" : "$pre\\-$post";
  916. } elsif (length ($dash) == 2
  917. && ((!$pre && !$post)
  918. || ($pre =~ /\w/ && !$post)
  919. || ($pre eq ' ' && $post eq ' ')
  920. || ($pre eq '=' && $post ne '=')
  921. || ($pre ne '=' && $post eq '='))) {
  922. "$pre\\*(--$post";
  923. } else {
  924. $pre . ('\-' x length $dash) . $post;
  925. }
  926. }egxs;
  927. # Fix up double quotes.
  928. s{ \" ([^\"]+) \" } { '\*(L"' . $1 . '\*(R"' }egx;
  929. # Make C++ into \*(C+, which is a squinched version.
  930. s{ \b C\+\+ } {\\*\(C+}gx;
  931. # All done.
  932. $_;
  933. }
  934. ############################################################################
  935. # Output formatting
  936. ############################################################################
  937. # Make vertical whitespace.
  938. sub makespace {
  939. my $self = shift;
  940. $self->output (".PD\n") if ($$self{ITEMS} > 1);
  941. $$self{ITEMS} = 0;
  942. $self->output ($$self{INDENT} > 0 ? ".Sp\n" : ".PP\n")
  943. if $$self{NEEDSPACE};
  944. }
  945. # Output any pending index entries, and optionally an index entry given as
  946. # an argument. Support multiple index entries in X<> separated by slashes,
  947. # and strip special escapes from index entries.
  948. sub outindex {
  949. my ($self, $section, $index) = @_;
  950. my @entries = map { split m%\s*/\s*% } @{ $$self{INDEX} };
  951. return unless ($section || @entries);
  952. $$self{INDEX} = [];
  953. my $output;
  954. if (@entries) {
  955. my $output = '.IX Xref "'
  956. . join (' ', map { s/\"/\"\"/; $_ } @entries)
  957. . '"' . "\n";
  958. }
  959. if ($section) {
  960. $index =~ s/\"/\"\"/;
  961. $index =~ s/\\-/-/g;
  962. $index =~ s/\\(?:s-?\d|.\(..|.)//g;
  963. $output .= ".IX $section " . '"' . $index . '"' . "\n";
  964. }
  965. $self->output ($output);
  966. }
  967. # Output text to the output device.
  968. sub output { print { $_[0]->output_handle } $_[1] }
  969. # Given a command and a single argument that may or may not contain double
  970. # quotes, handle double-quote formatting for it. If there are no double
  971. # quotes, just return the command followed by the argument in double quotes.
  972. # If there are double quotes, use an if statement to test for nroff, and for
  973. # nroff output the command followed by the argument in double quotes with
  974. # embedded double quotes doubled. For other formatters, remap paired double
  975. # quotes to LQUOTE and RQUOTE.
  976. sub switchquotes {
  977. my $self = shift;
  978. my $command = shift;
  979. local $_ = shift;
  980. my $extra = shift;
  981. s/\\\*\([LR]\"/\"/g;
  982. # We also have to deal with \*C` and \*C', which are used to add the
  983. # quotes around C<> text, since they may expand to " and if they do this
  984. # confuses the .SH macros and the like no end. Expand them ourselves.
  985. # If $extra is set, we're dealing with =item, which in most nroff macro
  986. # sets requires an extra level of quoting of double quotes.
  987. my $c_is_quote = ($$self{LQUOTE} =~ /\"/) || ($$self{RQUOTE} =~ /\"/);
  988. if (/\"/ || ($c_is_quote && /\\\*\(C[\'\`]/)) {
  989. s/\"/\"\"/g;
  990. my $troff = $_;
  991. $troff =~ s/\"\"([^\"]*)\"\"/\`\`$1\'\'/g;
  992. s/\\\*\(C\`/$$self{LQUOTE}/g;
  993. s/\\\*\(C\'/$$self{RQUOTE}/g;
  994. $troff =~ s/\\\*\(C[\'\`]//g;
  995. s/\"/\"\"/g if $extra;
  996. $troff =~ s/\"/\"\"/g if $extra;
  997. $_ = qq("$_") . ($extra ? " $extra" : '');
  998. $troff = qq("$troff") . ($extra ? " $extra" : '');
  999. return ".if n $command $_\n.el $command $troff\n";
  1000. } else {
  1001. $_ = qq("$_") . ($extra ? " $extra" : '');
  1002. return "$command $_\n";
  1003. }
  1004. }
  1005. __END__
  1006. .\" These are some extra bits of roff that I don't want to lose track of
  1007. .\" but that have been removed from the preamble to make it a bit shorter
  1008. .\" since they're not currently being used. They're accents and special
  1009. .\" characters we don't currently have escapes for.
  1010. .if n \{\
  1011. . ds ? ?
  1012. . ds ! !
  1013. . ds q
  1014. .\}
  1015. .if t \{\
  1016. . ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
  1017. . ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
  1018. . ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
  1019. .\}
  1020. .ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
  1021. .ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
  1022. .ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
  1023. .ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
  1024. .ds oe o\h'-(\w'o'u*4/10)'e
  1025. .ds Oe O\h'-(\w'O'u*4/10)'E
  1026. .if \n(.H>23 .if \n(.V>19 \
  1027. \{\
  1028. . ds v \h'-1'\o'\(aa\(ga'
  1029. . ds _ \h'-1'^
  1030. . ds . \h'-1'.
  1031. . ds 3 3
  1032. . ds oe oe
  1033. . ds Oe OE
  1034. .\}
  1035. ############################################################################
  1036. # Documentation
  1037. ############################################################################
  1038. =head1 NAME
  1039. Pod::Man - Convert POD data to formatted *roff input
  1040. =head1 SYNOPSIS
  1041. use Pod::Man;
  1042. my $parser = Pod::Man->new (release => $VERSION, section => 8);
  1043. # Read POD from STDIN and write to STDOUT.
  1044. $parser->parse_from_filehandle;
  1045. # Read POD from file.pod and write to file.1.
  1046. $parser->parse_from_file ('file.pod', 'file.1');
  1047. =head1 DESCRIPTION
  1048. Pod::Man is a module to convert documentation in the POD format (the
  1049. preferred language for documenting Perl) into *roff input using the man
  1050. macro set. The resulting *roff code is suitable for display on a terminal
  1051. using nroff(1), normally via man(1), or printing using troff(1). It is
  1052. conventionally invoked using the driver script B<pod2man>, but it can also
  1053. be used directly.
  1054. As a derived class from Pod::Parser, Pod::Man supports the same methods and
  1055. interfaces. See L<Pod::Parser> for all the details; briefly, one creates a
  1056. new parser with C<Pod::Man-E<gt>new()> and then calls either
  1057. parse_from_filehandle() or parse_from_file().
  1058. new() can take options, in the form of key/value pairs that control the
  1059. behavior of the parser. See below for details.
  1060. If no options are given, Pod::Man uses the name of the input file with any
  1061. trailing C<.pod>, C<.pm>, or C<.pl> stripped as the man page title, to
  1062. section 1 unless the file ended in C<.pm> in which case it defaults to
  1063. section 3, to a centered title of "User Contributed Perl Documentation", to
  1064. a centered footer of the Perl version it is run with, and to a left-hand
  1065. footer of the modification date of its input (or the current date if given
  1066. STDIN for input).
  1067. Pod::Man assumes that your *roff formatters have a fixed-width font named
  1068. CW. If yours is called something else (like CR), use the C<fixed> option to
  1069. specify it. This generally only matters for troff output for printing.
  1070. Similarly, you can set the fonts used for bold, italic, and bold italic
  1071. fixed-width output.
  1072. Besides the obvious pod conversions, Pod::Man also takes care of formatting
  1073. func(), func(n), and simple variable references like $foo or @bar so you
  1074. don't have to use code escapes for them; complex expressions like
  1075. C<$fred{'stuff'}> will still need to be escaped, though. It also translates
  1076. dashes that aren't used as hyphens into en dashes, makes long dashes--like
  1077. this--into proper em dashes, fixes "paired quotes," makes C++ and PI look
  1078. right, puts a little space between double underbars, makes ALLCAPS a teeny
  1079. bit smaller in troff(1), and escapes stuff that *roff treats as special so
  1080. that you don't have to.
  1081. The recognized options to new() are as follows. All options take a single
  1082. argument.
  1083. =over 4
  1084. =item center
  1085. Sets the centered page header to use instead of "User Contributed Perl
  1086. Documentation".
  1087. =item date
  1088. Sets the left-hand footer. By default, the modification date of the input
  1089. file will be used, or the current date if stat() can't find that file (the
  1090. case if the input is from STDIN), and the date will be formatted as
  1091. YYYY-MM-DD.
  1092. =item fixed
  1093. The fixed-width font to use for vertabim text and code. Defaults to CW.
  1094. Some systems may want CR instead. Only matters for troff(1) output.
  1095. =item fixedbold
  1096. Bold version of the fixed-width font. Defaults to CB. Only matters for
  1097. troff(1) output.
  1098. =item fixeditalic
  1099. Italic version of the fixed-width font (actually, something of a misnomer,
  1100. since most fixed-width fonts only have an oblique version, not an italic
  1101. version). Defaults to CI. Only matters for troff(1) output.
  1102. =item fixedbolditalic
  1103. Bold italic (probably actually oblique) version of the fixed-width font.
  1104. Pod::Man doesn't assume you have this, and defaults to CB. Some systems
  1105. (such as Solaris) have this font available as CX. Only matters for troff(1)
  1106. output.
  1107. =item quotes
  1108. Sets the quote marks used to surround CE<lt>> text. If the value is a
  1109. single character, it is used as both the left and right quote; if it is two
  1110. characters, the first character is used as the left quote and the second as
  1111. the right quoted; and if it is four characters, the first two are used as
  1112. the left quote and the second two as the right quote.
  1113. This may also be set to the special value C<none>, in which case no quote
  1114. marks are added around CE<lt>> text (but the font is still changed for troff
  1115. output).
  1116. =item release
  1117. Set the centered footer. By default, this is the version of Perl you run
  1118. Pod::Man under. Note that some system an macro sets assume that the
  1119. centered footer will be a modification date and will prepend something like
  1120. "Last modified: "; if this is the case, you may want to set C<release> to
  1121. the last modified date and C<date> to the version number.
  1122. =item section
  1123. Set the section for the C<.TH> macro. The standard section numbering
  1124. convention is to use 1 for user commands, 2 for system calls, 3 for
  1125. functions, 4 for devices, 5 for file formats, 6 for games, 7 for
  1126. miscellaneous information, and 8 for administrator commands. There is a lot
  1127. of variation here, however; some systems (like Solaris) use 4 for file
  1128. formats, 5 for miscellaneous information, and 7 for devices. Still others
  1129. use 1m instead of 8, or some mix of both. About the only section numbers
  1130. that are reliably consistent are 1, 2, and 3.
  1131. By default, section 1 will be used unless the file ends in .pm in which case
  1132. section 3 will be selected.
  1133. =back
  1134. The standard Pod::Parser method parse_from_filehandle() takes up to two
  1135. arguments, the first being the file handle to read POD from and the second
  1136. being the file handle to write the formatted output to. The first defaults
  1137. to STDIN if not given, and the second defaults to STDOUT. The method
  1138. parse_from_file() is almost identical, except that its two arguments are the
  1139. input and output disk files instead. See L<Pod::Parser> for the specific
  1140. details.
  1141. =head1 DIAGNOSTICS
  1142. =over 4
  1143. =item roff font should be 1 or 2 chars, not "%s"
  1144. (F) You specified a *roff font (using C<fixed>, C<fixedbold>, etc.) that
  1145. wasn't either one or two characters. Pod::Man doesn't support *roff fonts
  1146. longer than two characters, although some *roff extensions do (the canonical
  1147. versions of nroff(1) and troff(1) don't either).
  1148. =item Invalid link %s
  1149. (W) The POD source contained a C<LE<lt>E<gt>> sequence that Pod::Man was
  1150. unable to parse. You should never see this error message; it probably
  1151. indicates a bug in Pod::Man.
  1152. =item Invalid quote specification "%s"
  1153. (F) The quote specification given (the quotes option to the constructor) was
  1154. invalid. A quote specification must be one, two, or four characters long.
  1155. =item %s:%d: Unknown command paragraph "%s".
  1156. (W) The POD source contained a non-standard command paragraph (something of
  1157. the form C<=command args>) that Pod::Man didn't know about. It was ignored.
  1158. =item Unknown escape EE<lt>%sE<gt>
  1159. (W) The POD source contained an C<EE<lt>E<gt>> escape that Pod::Man didn't
  1160. know about. C<EE<lt>%sE<gt>> was printed verbatim in the output.
  1161. =item Unknown sequence %s
  1162. (W) The POD source contained a non-standard interior sequence (something of
  1163. the form C<XE<lt>E<gt>>) that Pod::Man didn't know about. It was ignored.
  1164. =item %s: Unknown command paragraph "%s" on line %d.
  1165. (W) The POD source contained a non-standard command paragraph (something of
  1166. the form C<=command args>) that Pod::Man didn't know about. It was ignored.
  1167. =item Unmatched =back
  1168. (W) Pod::Man encountered a C<=back> command that didn't correspond to an
  1169. C<=over> command.
  1170. =back
  1171. =head1 BUGS
  1172. The lint-like features and strict POD format checking done by B<pod2man> are
  1173. not yet implemented and should be, along with the corresponding C<lax>
  1174. option.
  1175. The NAME section should be recognized specially and index entries emitted
  1176. for everything in that section. This would have to be deferred until the
  1177. next section, since extraneous things in NAME tends to confuse various man
  1178. page processors.
  1179. The handling of hyphens, en dashes, and em dashes is somewhat fragile, and
  1180. one may get the wrong one under some circumstances. This should only matter
  1181. for troff(1) output.
  1182. When and whether to use small caps is somewhat tricky, and Pod::Man doesn't
  1183. necessarily get it right.
  1184. Pod::Man doesn't handle font names longer than two characters. Neither do
  1185. most troff(1) implementations, but GNU troff does as an extension. It would
  1186. be nice to support as an option for those who want to use it.
  1187. The preamble added to each output file is rather verbose, and most of it is
  1188. only necessary in the presence of EE<lt>E<gt> escapes for non-ASCII
  1189. characters. It would ideally be nice if all of those definitions were only
  1190. output if needed, perhaps on the fly as the characters are used.
  1191. Some of the automagic applied to file names assumes Unix directory
  1192. separators.
  1193. Pod::Man is excessively slow.
  1194. =head1 SEE ALSO
  1195. L<Pod::Parser|Pod::Parser>, perlpod(1), pod2man(1), nroff(1), troff(1),
  1196. man(1), man(7)
  1197. Ossanna, Joseph F., and Brian W. Kernighan. "Troff User's Manual,"
  1198. Computing Science Technical Report No. 54, AT&T Bell Laboratories. This is
  1199. the best documentation of standard nroff(1) and troff(1). At the time of
  1200. this writing, it's available at http://www.cs.bell-labs.com/cm/cs/cstr.html.
  1201. The man page documenting the man macro set may be man(5) instead of man(7)
  1202. on your system. Also, please see pod2man(1) for extensive documentation on
  1203. writing manual pages if you've not done it before and aren't familiar with
  1204. the conventions.
  1205. =head1 AUTHOR
  1206. Russ Allbery E<lt>rra@stanford.eduE<gt>, based I<very> heavily on the
  1207. original B<pod2man> by Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>.
  1208. =cut