⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 man.pm

📁 UNIX下perl实现代码
💻 PM
📖 第 1 页 / 共 4 页
字号:
    $self->output ($$self{INDENT} > 0 ? ".Sp\n" : ".PP\n")        if $$self{NEEDSPACE};}# Output any pending index entries, and optionally an index entry given as# an argument.  Support multiple index entries in X<> separated by slashes,# and strip special escapes from index entries.sub outindex {    my ($self, $section, $index) = @_;    my @entries = map { split m%\s*/\s*% } @{ $$self{INDEX} };    return unless ($section || @entries);    $$self{INDEX} = [];    my $output;    if (@entries) {        my $output = '.IX Xref "'            . join (' ', map { s/\"/\"\"/; $_ } @entries)            . '"' . "\n";    }    if ($section) {        $index =~ s/\"/\"\"/;        $index =~ s/\\-/-/g;        $index =~ s/\\(?:s-?\d|.\(..|.)//g;        $output .= ".IX $section " . '"' . $index . '"' . "\n";    }    $self->output ($output);}# Output text to the output device.sub output { print { $_[0]->output_handle } $_[1] }# Given a command and a single argument that may or may not contain double# quotes, handle double-quote formatting for it.  If there are no double# quotes, just return the command followed by the argument in double quotes.# If there are double quotes, use an if statement to test for nroff, and for# nroff output the command followed by the argument in double quotes with# embedded double quotes doubled.  For other formatters, remap paired double# quotes to LQUOTE and RQUOTE.sub switchquotes {    my $self = shift;    my $command = shift;    local $_ = shift;    my $extra = shift;    s/\\\*\([LR]\"/\"/g;    # We also have to deal with \*C` and \*C', which are used to add the    # quotes around C<> text, since they may expand to " and if they do this    # confuses the .SH macros and the like no end.  Expand them ourselves.    # If $extra is set, we're dealing with =item, which in most nroff macro    # sets requires an extra level of quoting of double quotes.    my $c_is_quote = ($$self{LQUOTE} =~ /\"/) || ($$self{RQUOTE} =~ /\"/);    if (/\"/ || ($c_is_quote && /\\\*\(C[\'\`]/)) {        s/\"/\"\"/g;        my $troff = $_;        $troff =~ s/\"\"([^\"]*)\"\"/\`\`$1\'\'/g;        s/\\\*\(C\`/$$self{LQUOTE}/g;        s/\\\*\(C\'/$$self{RQUOTE}/g;        $troff =~ s/\\\*\(C[\'\`]//g;        s/\"/\"\"/g if $extra;        $troff =~ s/\"/\"\"/g if $extra;        $_ = qq("$_") . ($extra ? " $extra" : '');        $troff = qq("$troff") . ($extra ? " $extra" : '');        return ".if n $command $_\n.el $command $troff\n";    } else {        $_ = qq("$_") . ($extra ? " $extra" : '');        return "$command $_\n";    }}__END__.\" These are some extra bits of roff that I don't want to lose track of.\" but that have been removed from the preamble to make it a bit shorter.\" since they're not currently being used.  They're accents and special.\" characters we don't currently have escapes for..if n \{\.    ds ? ?.    ds ! !.    ds q.\}.if t \{\.    ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'.    ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'.    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'.\}.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#].ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#].ds oe o\h'-(\w'o'u*4/10)'e.ds Oe O\h'-(\w'O'u*4/10)'E.if \n(.H>23 .if \n(.V>19 \\{\.    ds v \h'-1'\o'\(aa\(ga'.    ds _ \h'-1'^.    ds . \h'-1'..    ds 3 3.    ds oe oe.    ds Oe OE.\}############################################################################# Documentation############################################################################=head1 NAMEPod::Man - Convert POD data to formatted *roff input=head1 SYNOPSIS    use Pod::Man;    my $parser = Pod::Man->new (release => $VERSION, section => 8);    # Read POD from STDIN and write to STDOUT.    $parser->parse_from_filehandle;    # Read POD from file.pod and write to file.1.    $parser->parse_from_file ('file.pod', 'file.1');=head1 DESCRIPTIONPod::Man is a module to convert documentation in the POD format (thepreferred language for documenting Perl) into *roff input using the manmacro set.  The resulting *roff code is suitable for display on a terminalusing nroff(1), normally via man(1), or printing using troff(1).  It isconventionally invoked using the driver script B<pod2man>, but it can alsobe used directly.As a derived class from Pod::Parser, Pod::Man supports the same methods andinterfaces.  See L<Pod::Parser> for all the details; briefly, one creates anew parser with C<Pod::Man-E<gt>new()> and then calls eitherparse_from_filehandle() or parse_from_file().new() can take options, in the form of key/value pairs that control thebehavior of the parser.  See below for details.If no options are given, Pod::Man uses the name of the input file with anytrailing C<.pod>, C<.pm>, or C<.pl> stripped as the man page title, tosection 1 unless the file ended in C<.pm> in which case it defaults tosection 3, to a centered title of "User Contributed Perl Documentation", toa centered footer of the Perl version it is run with, and to a left-handfooter of the modification date of its input (or the current date if givenSTDIN for input).Pod::Man assumes that your *roff formatters have a fixed-width font namedCW.  If yours is called something else (like CR), use the C<fixed> option tospecify it.  This generally only matters for troff output for printing.Similarly, you can set the fonts used for bold, italic, and bold italicfixed-width output.Besides the obvious pod conversions, Pod::Man also takes care of formattingfunc(), func(n), and simple variable references like $foo or @bar so youdon't have to use code escapes for them; complex expressions likeC<$fred{'stuff'}> will still need to be escaped, though.  It also translatesdashes that aren't used as hyphens into en dashes, makes long dashes--likethis--into proper em dashes, fixes "paired quotes," makes C++ and PI lookright, puts a little space between double underbars, makes ALLCAPS a teenybit smaller in troff(1), and escapes stuff that *roff treats as special sothat you don't have to.The recognized options to new() are as follows.  All options take a singleargument.=over 4=item centerSets the centered page header to use instead of "User Contributed PerlDocumentation".=item dateSets the left-hand footer.  By default, the modification date of the inputfile will be used, or the current date if stat() can't find that file (thecase if the input is from STDIN), and the date will be formatted asYYYY-MM-DD.=item fixedThe fixed-width font to use for vertabim text and code.  Defaults to CW.Some systems may want CR instead.  Only matters for troff(1) output.=item fixedboldBold version of the fixed-width font.  Defaults to CB.  Only matters fortroff(1) output.=item fixeditalicItalic version of the fixed-width font (actually, something of a misnomer,since most fixed-width fonts only have an oblique version, not an italicversion).  Defaults to CI.  Only matters for troff(1) output.=item fixedbolditalicBold italic (probably actually oblique) version of the fixed-width font.Pod::Man doesn't assume you have this, and defaults to CB.  Some systems(such as Solaris) have this font available as CX.  Only matters for troff(1)output.=item quotesSets the quote marks used to surround CE<lt>> text.  If the value is asingle character, it is used as both the left and right quote; if it is twocharacters, the first character is used as the left quote and the second asthe right quoted; and if it is four characters, the first two are used asthe left quote and the second two as the right quote.This may also be set to the special value C<none>, in which case no quotemarks are added around CE<lt>> text (but the font is still changed for troffoutput).=item releaseSet the centered footer.  By default, this is the version of Perl you runPod::Man under.  Note that some system an macro sets assume that thecentered footer will be a modification date and will prepend something like"Last modified: "; if this is the case, you may want to set C<release> tothe last modified date and C<date> to the version number.=item sectionSet the section for the C<.TH> macro.  The standard section numberingconvention is to use 1 for user commands, 2 for system calls, 3 forfunctions, 4 for devices, 5 for file formats, 6 for games, 7 formiscellaneous information, and 8 for administrator commands.  There is a lotof variation here, however; some systems (like Solaris) use 4 for fileformats, 5 for miscellaneous information, and 7 for devices.  Still othersuse 1m instead of 8, or some mix of both.  About the only section numbersthat are reliably consistent are 1, 2, and 3.By default, section 1 will be used unless the file ends in .pm in which casesection 3 will be selected.=backThe standard Pod::Parser method parse_from_filehandle() takes up to twoarguments, the first being the file handle to read POD from and the secondbeing the file handle to write the formatted output to.  The first defaultsto STDIN if not given, and the second defaults to STDOUT.  The methodparse_from_file() is almost identical, except that its two arguments are theinput and output disk files instead.  See L<Pod::Parser> for the specificdetails.=head1 DIAGNOSTICS=over 4=item roff font should be 1 or 2 chars, not "%s"(F) You specified a *roff font (using C<fixed>, C<fixedbold>, etc.) thatwasn't either one or two characters.  Pod::Man doesn't support *roff fontslonger than two characters, although some *roff extensions do (the canonicalversions of nroff(1) and troff(1) don't either).=item Invalid link %s(W) The POD source contained a C<LE<lt>E<gt>> sequence that Pod::Man wasunable to parse.  You should never see this error message; it probablyindicates a bug in Pod::Man.=item Invalid quote specification "%s"(F) The quote specification given (the quotes option to the constructor) wasinvalid.  A quote specification must be one, two, or four characters long.=item %s:%d: Unknown command paragraph "%s".(W) The POD source contained a non-standard command paragraph (something ofthe form C<=command args>) that Pod::Man didn't know about.  It was ignored.=item Unknown escape EE<lt>%sE<gt>(W) The POD source contained an C<EE<lt>E<gt>> escape that Pod::Man didn'tknow about.  C<EE<lt>%sE<gt>> was printed verbatim in the output.=item Unknown sequence %s(W) The POD source contained a non-standard interior sequence (something ofthe form C<XE<lt>E<gt>>) that Pod::Man didn't know about.  It was ignored.=item %s: Unknown command paragraph "%s" on line %d.(W) The POD source contained a non-standard command paragraph (something ofthe form C<=command args>) that Pod::Man didn't know about. It was ignored.=item Unmatched =back(W) Pod::Man encountered a C<=back> command that didn't correspond to anC<=over> command.=back=head1 BUGSThe lint-like features and strict POD format checking done by B<pod2man> arenot yet implemented and should be, along with the corresponding C<lax>option.The NAME section should be recognized specially and index entries emittedfor everything in that section.  This would have to be deferred until thenext section, since extraneous things in NAME tends to confuse various manpage processors.The handling of hyphens, en dashes, and em dashes is somewhat fragile, andone may get the wrong one under some circumstances.  This should only matterfor troff(1) output.When and whether to use small caps is somewhat tricky, and Pod::Man doesn'tnecessarily get it right.Pod::Man doesn't handle font names longer than two characters.  Neither domost troff(1) implementations, but GNU troff does as an extension.  It wouldbe nice to support as an option for those who want to use it.The preamble added to each output file is rather verbose, and most of it isonly necessary in the presence of EE<lt>E<gt> escapes for non-ASCIIcharacters.  It would ideally be nice if all of those definitions were onlyoutput if needed, perhaps on the fly as the characters are used.Some of the automagic applied to file names assumes Unix directoryseparators.Pod::Man is excessively slow.=head1 SEE ALSOL<Pod::Parser|Pod::Parser>, perlpod(1), pod2man(1), nroff(1), troff(1),man(1), man(7)Ossanna, Joseph F., and Brian W. Kernighan.  "Troff User's Manual,"Computing Science Technical Report No. 54, AT&T Bell Laboratories.  This isthe best documentation of standard nroff(1) and troff(1).  At the time ofthis writing, it's available at http://www.cs.bell-labs.com/cm/cs/cstr.html.The man page documenting the man macro set may be man(5) instead of man(7)on your system.  Also, please see pod2man(1) for extensive documentation onwriting manual pages if you've not done it before and aren't familiar withthe conventions.=head1 AUTHORRuss Allbery E<lt>rra@stanford.eduE<gt>, based I<very> heavily on theoriginal B<pod2man> by Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -