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