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

📄 man.pm

📁 UNIX下perl实现代码
💻 PM
📖 第 1 页 / 共 4 页
字号:
# Pod::Man -- Convert POD data to formatted *roff input.# $Id: Man.pm,v 1.15 2001/02/10 06:50:22 eagle Exp $## Copyright 1999, 2000, 2001 by Russ Allbery <rra@stanford.edu>## This program is free software; you can redistribute it and/or modify it# under the same terms as Perl itself.## This module is intended to be a replacement for the pod2man script# distributed with versions of Perl prior to 5.6, and attempts to match its# output except for some specific circumstances where other decisions seemed# to produce better output.  It uses Pod::Parser and is designed to be easy# to subclass.## Perl core hackers, please note that this module is also separately# maintained outside of the Perl core as part of the podlators.  Please send# me any patches at the address above in addition to sending them to the# standard Perl mailing lists.############################################################################# Modules and declarations############################################################################package Pod::Man;require 5.004;use Carp qw(carp croak);use Pod::Parser ();use strict;use subs qw(makespace);use vars qw(@ISA %ESCAPES $PREAMBLE $VERSION);@ISA = qw(Pod::Parser);# Don't use the CVS revision as the version, since this module is also in# Perl core and too many things could munge CVS magic revision strings.# This number should ideally be the same as the CVS revision in podlators,# however.$VERSION = 1.15;############################################################################# Preamble and *roff output tables############################################################################# The following is the static preamble which starts all *roff output we# generate.  It's completely static except for the font to use as a# fixed-width font, which is designed by @CFONT@, and the left and right# quotes to use for C<> text, designated by @LQOUTE@ and @RQUOTE@.# $PREAMBLE should therefore be run through s/\@CFONT\@/<font>/g before# output.$PREAMBLE = <<'----END OF PREAMBLE----';.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Ip \" List item.br.ie \\n(.$>=3 .ne \\$3.el .ne 3.IP "\\$1" \\$2...de Vb \" Begin verbatim text.ft @CFONT@.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  | will give a.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used.\" to do unbreakable dashes and therefore won't be available.  \*(C` and.\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>.tr \(*W-|\(bv\*(Tr.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` @LQUOTE@.    ds C' @RQUOTE@'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" If the F register is turned on, we'll generate index entries on stderr.\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and.\" index entries marked with X<> in POD.  Of course, you'll have to process.\" the output yourself in some meaningful fashion..if \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.\".\" For nroff, turn off justification.  Always turn off hyphenation; it.\" makes way too many mistakes in technical documents..hy 0.if n .na.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..bd B 3.    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C----END OF PREAMBLE----#`# for cperl-mode# This table is taken nearly verbatim from Tom Christiansen's pod2man.  It# assumes that the standard preamble has already been printed, since that's# what defines all of the accent marks.  Note that some of these are quoted# with double quotes since they contain embedded single quotes, so use \\# uniformly for backslash for readability.%ESCAPES = (    'amp'       =>    '&',      # ampersand    'lt'        =>    '<',      # left chevron, less-than    'gt'        =>    '>',      # right chevron, greater-than    'quot'      =>    '"',      # double quote    'sol'       =>    '/',      # solidus (forward slash)    'verbar'    =>    '|',      # vertical bar    'Aacute'    =>    "A\\*'",  # capital A, acute accent    'aacute'    =>    "a\\*'",  # small a, acute accent    'Acirc'     =>    'A\\*^',  # capital A, circumflex accent    'acirc'     =>    'a\\*^',  # small a, circumflex accent    'AElig'     =>    '\*(AE',  # capital AE diphthong (ligature)    'aelig'     =>    '\*(ae',  # small ae diphthong (ligature)    'Agrave'    =>    "A\\*`",  # capital A, grave accent    'agrave'    =>    "A\\*`",  # small a, grave accent    'Aring'     =>    'A\\*o',  # capital A, ring    'aring'     =>    'a\\*o',  # small a, ring    'Atilde'    =>    'A\\*~',  # capital A, tilde    'atilde'    =>    'a\\*~',  # small a, tilde    'Auml'      =>    'A\\*:',  # capital A, dieresis or umlaut mark    'auml'      =>    'a\\*:',  # small a, dieresis or umlaut mark    'Ccedil'    =>    'C\\*,',  # capital C, cedilla    'ccedil'    =>    'c\\*,',  # small c, cedilla    'Eacute'    =>    "E\\*'",  # capital E, acute accent    'eacute'    =>    "e\\*'",  # small e, acute accent    'Ecirc'     =>    'E\\*^',  # capital E, circumflex accent    'ecirc'     =>    'e\\*^',  # small e, circumflex accent    'Egrave'    =>    'E\\*`',  # capital E, grave accent    'egrave'    =>    'e\\*`',  # small e, grave accent    'ETH'       =>    '\\*(D-', # capital Eth, Icelandic    'eth'       =>    '\\*(d-', # small eth, Icelandic    'Euml'      =>    'E\\*:',  # capital E, dieresis or umlaut mark    'euml'      =>    'e\\*:',  # small e, dieresis or umlaut mark    'Iacute'    =>    "I\\*'",  # capital I, acute accent    'iacute'    =>    "i\\*'",  # small i, acute accent    'Icirc'     =>    'I\\*^',  # capital I, circumflex accent    'icirc'     =>    'i\\*^',  # small i, circumflex accent    'Igrave'    =>    'I\\*`',  # capital I, grave accent    'igrave'    =>    'i\\*`',  # small i, grave accent    'Iuml'      =>    'I\\*:',  # capital I, dieresis or umlaut mark    'iuml'      =>    'i\\*:',  # small i, dieresis or umlaut mark    'Ntilde'    =>    'N\*~',   # capital N, tilde    'ntilde'    =>    'n\*~',   # small n, tilde    'Oacute'    =>    "O\\*'",  # capital O, acute accent    'oacute'    =>    "o\\*'",  # small o, acute accent    'Ocirc'     =>    'O\\*^',  # capital O, circumflex accent    'ocirc'     =>    'o\\*^',  # small o, circumflex accent    'Ograve'    =>    'O\\*`',  # capital O, grave accent    'ograve'    =>    'o\\*`',  # small o, grave accent    'Oslash'    =>    'O\\*/',  # capital O, slash    'oslash'    =>    'o\\*/',  # small o, slash    'Otilde'    =>    'O\\*~',  # capital O, tilde    'otilde'    =>    'o\\*~',  # small o, tilde    'Ouml'      =>    'O\\*:',  # capital O, dieresis or umlaut mark    'ouml'      =>    'o\\*:',  # small o, dieresis or umlaut mark    'szlig'     =>    '\*8',    # small sharp s, German (sz ligature)    'THORN'     =>    '\\*(Th', # capital THORN, Icelandic    'thorn'     =>    '\\*(th', # small thorn, Icelandic    'Uacute'    =>    "U\\*'",  # capital U, acute accent    'uacute'    =>    "u\\*'",  # small u, acute accent    'Ucirc'     =>    'U\\*^',  # capital U, circumflex accent    'ucirc'     =>    'u\\*^',  # small u, circumflex accent    'Ugrave'    =>    'U\\*`',  # capital U, grave accent    'ugrave'    =>    'u\\*`',  # small u, grave accent    'Uuml'      =>    'U\\*:',  # capital U, dieresis or umlaut mark    'uuml'      =>    'u\\*:',  # small u, dieresis or umlaut mark    'Yacute'    =>    "Y\\*'",  # capital Y, acute accent    'yacute'    =>    "y\\*'",  # small y, acute accent    'yuml'      =>    'y\\*:',  # small y, dieresis or umlaut mark);############################################################################# Static helper functions############################################################################# Protect leading quotes and periods against interpretation as commands.# Also protect anything starting with a backslash, since it could expand# or hide something that *roff would interpret as a command.  This is# overkill, but it's much simpler than trying to parse *roff here.sub protect {    local $_ = shift;    s/^([.\'\\])/\\&$1/mg;    $_;}# Translate a font string into an escape.sub toescape { (length ($_[0]) > 1 ? '\f(' : '\f') . $_[0] }############################################################################# Initialization############################################################################# Initialize the object.  Here, we also process any additional options# passed to the constructor or set up defaults if none were given.  center# is the centered title, release is the version number, and date is the date# for the documentation.  Note that we can't know what file name we're# processing due to the architecture of Pod::Parser, so that *has* to either# be passed to the constructor or set separately with Pod::Man::name().sub initialize {    my $self = shift;    # Figure out the fixed-width font.  If user-supplied, make sure that    # they are the right length.    for (qw/fixed fixedbold fixeditalic fixedbolditalic/) {        if (defined $$self{$_}) {            if (length ($$self{$_}) < 1 || length ($$self{$_}) > 2) {                croak qq(roff font should be 1 or 2 chars,)                    . qq( not "$$self{$_}");            }        } else {            $$self{$_} = '';        }    }    # Set the default fonts.  We can't be sure what fixed bold-italic is    # going to be called, so default to just bold.    $$self{fixed}           ||= 'CW';    $$self{fixedbold}       ||= 'CB';    $$self{fixeditalic}     ||= 'CI';    $$self{fixedbolditalic} ||= 'CB';    # Set up a table of font escapes.  First number is fixed-width, second    # is bold, third is italic.    $$self{FONTS} = { '000' => '\fR', '001' => '\fI',                      '010' => '\fB', '011' => '\f(BI',                      '100' => toescape ($$self{fixed}),                      '101' => toescape ($$self{fixeditalic}),                      '110' => toescape ($$self{fixedbold}),                      '111' => toescape ($$self{fixedbolditalic})};    # Extra stuff for page titles.    $$self{center} = 'User Contributed Perl Documentation'        unless defined $$self{center};    $$self{indent}  = 4 unless defined $$self{indent};    # We used to try first to get the version number from a local binary,    # but we shouldn't need that any more.  Get the version from the running    # Perl.  Work a little magic to handle subversions correctly under both    # the pre-5.6 and the post-5.6 version numbering schemes.    if (!defined $$self{release}) {        my @version = ($] =~ /^(\d+)\.(\d{3})(\d{0,3})$/);        $version[2] ||= 0;        $version[2] *= 10 ** (3 - length $version[2]);        for (@version) { $_ += 0 }        $$self{release} = 'perl v' . join ('.', @version);    }    # Double quotes in things that will be quoted.    for (qw/center date release/) {        $$self{$_} =~ s/\"/\"\"/g if $$self{$_};

⌨️ 快捷键说明

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