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

📄 python.perl

📁 python s60 1.4.5版本的源代码
💻 PERL
📖 第 1 页 / 共 4 页
字号:
# python.perl by Fred L. Drake, Jr. <fdrake@acm.org>		-*- perl -*-
#
# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
#
# Extension to LaTeX2HTML for documents using myformat.sty.
# Subroutines of the form do_cmd_<name> here define translations
# for LaTeX commands \<name> defined in the corresponding .sty file.

package main;

use File::Basename;


sub next_argument{
    my $param;
    $param = missing_braces()
      unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
	      ||(s/$next_pair_rx/$param=$2;''/eo));
    return $param;
}

sub next_optional_argument{
    my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
    s/$rx/$param=$2;''/eo;
    return $param;
}

sub make_icon_filename($){
    my($myname, $mydir, $myext) = fileparse(@_[0], '\..*');
    chop $mydir;
    if ($mydir eq '.') {
        $mydir = $ICONSERVER;
    }
    $myext = ".$IMAGE_TYPE"
      unless $myext;
    return "$mydir$dd$myname$myext";
}

sub get_link_icon($){
    my $url = @_[0];
    if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
        # absolute URL; assume it points off-site
        my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
        return (" <img src=\"$icon\"\n"
                . '  border="0" class="offsitelink"'
                . ($OFF_SITE_LINK_ICON_HEIGHT
                   ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
                   : '')
                . ($OFF_SITE_LINK_ICON_WIDTH
                   ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
                   : '')
                . " alt=\"[off-site link]\"\n"
                . "  >");
    }
    return '';
}

# This is a fairly simple hack; it supports \let when it is used to create
# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
# Many possible uses of \let aren't supported or aren't supported correctly.
#
sub do_cmd_let{
    local($_) = @_;
    my $matched = 0;
    s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
    if ($matched) {
	my($new, $old) = ($1, $3);
	eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
	print "\ndefining handler for \\$new using \\$old\n";
    }
    else {
	s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
	if ($matched) {
	    my($new, $char) = ($1, $3);
	    eval "sub do_cmd_$new { \"\\$char\" . \@_[0]; }";
	    print "\ndefining handler for \\$new to insert '$char'\n";
	}
	else {
	    write_warnings("Could not interpret \\let construct...");
	}
    }
    return $_;
}


# the older version of LaTeX2HTML we use doesn't support this, but we use it:

sub do_cmd_textasciitilde{ '&#126;' . @_[0]; }
sub do_cmd_textasciicircum{ '^' . @_[0]; }
sub do_cmd_textbar{ '|' . @_[0]; }
sub do_cmd_infinity{ '&infin;' . @_[0]; }
sub do_cmd_plusminus{ '&plusmn;' . @_[0]; }
sub do_cmd_menuselection{ @_[0]; }
sub do_cmd_sub{ ' > ' . @_[0]; }


# words typeset in a special way (not in HTML though)

sub do_cmd_ABC{ 'ABC' . @_[0]; }
sub do_cmd_UNIX{ 'Unix'. @_[0]; }
sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
sub do_cmd_C{ 'C' . @_[0]; }
sub do_cmd_Cpp{ 'C++' . @_[0]; }
sub do_cmd_EOF{ 'EOF' . @_[0]; }
sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }

sub do_cmd_e{ '&#92;' . @_[0]; }

$DEVELOPER_ADDRESS = '';
$SHORT_VERSION = '';
$RELEASE_INFO = '';
$PACKAGE_VERSION = '';

sub do_cmd_version{ $PACKAGE_VERSION . @_[0]; }
sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
sub do_cmd_release{
    local($_) = @_;
    $PACKAGE_VERSION = next_argument();
    return $_;
}

sub do_cmd_setreleaseinfo{
    local($_) = @_;
    $RELEASE_INFO = next_argument();
    return $_;
}

sub do_cmd_setshortversion{
    local($_) = @_;
    $SHORT_VERSION = next_argument();
    return $_;
}

sub do_cmd_authoraddress{
    local($_) = @_;
    $DEVELOPER_ADDRESS = next_argument();
    return $_;
}

#sub do_cmd_developer{ do_cmd_author(@_[0]); }
#sub do_cmd_developers{ do_cmd_author(@_[0]); }
#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }

sub do_cmd_hackscore{
    local($_) = @_;
    next_argument();
    return '_' . $_;
}

sub use_wrappers{
    local($_,$before,$after) = @_;
    my $stuff = next_argument();
    return $before . $stuff . $after . $_;
}

$IN_DESC_HANDLER = 0;
sub do_cmd_optional{
    if ($IN_DESC_HANDLER) {
        return use_wrappers(@_[0], "</var><big>\[</big><var>",
                            "</var><big>\]</big><var>");
    }
    else {
        return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
    }
}

# Logical formatting (some based on texinfo), needs to be converted to
# minimalist HTML.  The "minimalist" is primarily to reduce the size of
# output files for users that read them over the network rather than
# from local repositories.

# \file and \samp are at the end of this file since they screw up fontlock.

sub do_cmd_pytype{ return @_[0]; }
sub do_cmd_makevar{
    return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
sub do_cmd_code{
    return use_wrappers(@_[0], '<code>', '</code>'); }
sub do_cmd_module{
    return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
sub do_cmd_keyword{
    return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
sub do_cmd_exception{
    return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
sub do_cmd_class{
    return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
sub do_cmd_function{
    return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
sub do_cmd_constant{
    return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
sub do_cmd_member{
    return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
sub do_cmd_method{
    return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
sub do_cmd_cfunction{
    return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
sub do_cmd_cdata{
    return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
sub do_cmd_ctype{
    return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
sub do_cmd_regexp{
    return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
sub do_cmd_character{
    return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
sub do_cmd_program{
    return use_wrappers(@_[0], '<b class="program">', '</b>'); }
sub do_cmd_programopt{
    return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
sub do_cmd_longprogramopt{
    # note that the --- will be later converted to -- by LaTeX2HTML
    return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
sub do_cmd_email{
    return use_wrappers(@_[0], '<span class="email">', '</span>'); }
sub do_cmd_mailheader{
    return use_wrappers(@_[0], '<span class="mailheader">', ':</span>'); }
sub do_cmd_mimetype{
    return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
sub do_cmd_var{
    return use_wrappers(@_[0], "<var>", "</var>"); }
sub do_cmd_dfn{
    return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
sub do_cmd_emph{
    return use_wrappers(@_[0], '<i>', '</i>'); }
sub do_cmd_file{
    return use_wrappers(@_[0], '<span class="file">', '</span>'); }
sub do_cmd_filenq{
    return do_cmd_file(@_[0]); }
sub do_cmd_samp{
    return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
sub do_cmd_kbd{
    return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
sub do_cmd_strong{
    return use_wrappers(@_[0], '<b>', '</b>'); }
sub do_cmd_textbf{
    return use_wrappers(@_[0], '<b>', '</b>'); }
sub do_cmd_textit{
    return use_wrappers(@_[0], '<i>', '</i>'); }
# This can be changed/overridden for translations:
%NoticeNames = ('note' => 'Note:',
                'warning' => 'Warning:',
                );

sub do_cmd_note{
    my $label = $NoticeNames{'note'};
    return use_wrappers(
        @_[0],
        "<span class=\"note\"><b class=\"label\">$label</b>\n",
        '</span>'); }
sub do_cmd_warning{
    my $label = $NoticeNames{'warning'};
    return use_wrappers(
        @_[0],
        "<span class=\"warning\"><b class=\"label\">$label</b>\n",
        '</span>'); }

sub do_env_notice{
    local($_) = @_;
    my $notice = next_optional_argument();
    if (!$notice) {
        $notice = 'note';
    }
    my $label = $NoticeNames{$notice};
    return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
            . $_
            . '</div>');
}

sub do_cmd_moreargs{
    return '...' . @_[0]; }
sub do_cmd_unspecified{
    return '...' . @_[0]; }


sub do_cmd_refmodule{
    # Insert the right magic to jump to the module definition.
    local($_) = @_;
    my $key = next_optional_argument();
    my $module = next_argument();
    $key = $module
        unless $key;
    return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
      . $_;
}

sub do_cmd_newsgroup{
    local($_) = @_;
    my $newsgroup = next_argument();
    my $icon = get_link_icon("news:$newsgroup");
    my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
                 . "$newsgroup$icon</a>");
    return $stuff . $_;
}

sub do_cmd_envvar{
    local($_) = @_;
    my $envvar = next_argument();
    my($name,$aname,$ahref) = new_link_info();
    # The <tt> here is really to keep buildindex.py from making
    # the variable name case-insensitive.
    add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
		    $ahref);
    add_index_entry("$envvar (environment variable)", $ahref);
    $aname =~ s/<a/<a class="envvar"/;
    return "$aname$envvar</a>" . $_;
}

sub do_cmd_url{
    # use the URL as both text and hyperlink
    local($_) = @_;
    my $url = next_argument();
    my $icon = get_link_icon($url);
    $url =~ s/~/&#126;/g;
    return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
}

sub do_cmd_manpage{
    # two parameters:  \manpage{name}{section}
    local($_) = @_;
    my $page = next_argument();
    my $section = next_argument();
    return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
}

$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";

sub get_rfc_url($$){
    my($rfcnum, $format) = @_;
    return sprintf($format, $rfcnum);
}

sub do_cmd_pep{
    local($_) = @_;
    my $rfcnumber = next_argument();
    my $id = "rfcref-" . ++$global{'max_id'};
    my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
    my $icon = get_link_icon($href);
    # Save the reference
    my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
    $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
    return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
            . "$icon</a>" . $_);
}

sub do_cmd_rfc{
    local($_) = @_;
    my $rfcnumber = next_argument();
    my $id = "rfcref-" . ++$global{'max_id'};
    my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
    my $icon = get_link_icon($href);
    # Save the reference
    my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
    $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
    return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
            . "$icon</a>" . $_);
}

sub do_cmd_ulink{
    local($_) = @_;
    my $text = next_argument();
    my $url = next_argument();
    return "<a class=\"ulink\" href=\"$url\"\n  >$text</a>" . $_;
}

sub do_cmd_citetitle{
    local($_) = @_;
    my $url = next_optional_argument();
    my $title = next_argument();
    my $icon = get_link_icon($url);
    my $repl = '';
    if ($url) {
        $repl = ("<em class=\"citetitle\"><a\n"
                 . " href=\"$url\"\n"
                 . " title=\"$title\"\n"
                 . " >$title$icon</a></em>");
    }
    else {
        $repl = "<em class=\"citetitle\"\n >$title</em>";
    }
    return $repl . $_;
}

sub do_cmd_deprecated{
    # two parameters:  \deprecated{version}{whattodo}
    local($_) = @_;
    my $release = next_argument();
    my $reason = next_argument();
    return ('<div class="versionnote">'
            . "<b>Deprecated since release $release.</b>"
            . "\n$reason</div><p>"
            . $_);
}

sub versionnote{
    # one or two parameters:  \versionnote[explanation]{version}
    my $type = @_[0];
    local $_ = @_[1];
    my $explanation = next_optional_argument();
    my $release = next_argument();
    my $text = "$type in version $release.";
    if ($explanation) {
        $text = "$type in version $release:\n$explanation.";
    }
    return "\n<span class=\"versionnote\">$text</span>\n" . $_;
}

sub do_cmd_versionadded{
    return versionnote('New', @_);
}

sub do_cmd_versionchanged{
    return versionnote('Changed', @_);
}

#
# These function handle platform dependency tracking.
#
sub do_cmd_platform{
    local($_) = @_;
    my $platform = next_argument();
    $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
    $platform = "Macintosh"
      if $platform eq 'Mac';
    return "\n<p class=\"availability\">Availability: <span"
      . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
}

$IGNORE_PLATFORM_ANNOTATION = '';
sub do_cmd_ignorePlatformAnnotation{
    local($_) = @_;
    $IGNORE_PLATFORM_ANNOTATION = next_argument();
    return $_;
}


# index commands

$INDEX_SUBITEM = "";

sub get_indexsubitem{
    return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
}

sub do_cmd_setindexsubitem{
    local($_) = @_;
    $INDEX_SUBITEM = next_argument();
    return $_;
}

sub do_cmd_withsubitem{
    # We can't really do the right thing, because LaTeX2HTML doesn't
    # do things in the right order, but we need to at least strip this stuff
    # out, and leave anything that the second argument expanded out to.
    #
    local($_) = @_;
    my $oldsubitem = $INDEX_SUBITEM;
    $INDEX_SUBITEM = next_argument();
    my $stuff = next_argument();
    my $br_id = ++$globals{'max_id'};
    my $marker = "$O$br_id$C";
    $stuff =~ s/^\s+//;
    return
      $stuff
      . "\\setindexsubitem$marker$oldsubitem$marker"
      . $_;
}

# This is the prologue macro which is required to start writing the
# mod\jobname.idx file; we can just ignore it.  (Defining this suppresses
# a warning that \makemodindex is unknown.)
#
sub do_cmd_makemodindex{ return @_[0]; }

# We're in the document subdirectory when this happens!
#
open(IDXFILE, '>index.dat') || die "\n$!\n";
open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
print INTLABELS "%internal_labels = ();\n";
print INTLABELS "1;		# hack in case there are no entries\n\n";

# Using \0 for this is bad because we can't use common tools to work with the
# resulting files.  Things like grep can be useful with this stuff!
#
$IDXFILE_FIELD_SEP = "\1";

sub write_idxfile{
    my ($ahref, $str) = @_;
    print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
}


sub gen_link{
    my($node,$target) = @_;
    print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
    return "<a href=\"$node#$target\">";
}

⌨️ 快捷键说明

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