cinap_lenrekadd hg and python4bb9e2215 years agoHistory
2172 lines · 63.8 KB · Text
RawDownload
# 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 warnings;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_texteuro { '&#8364;' . $_[0]; }sub do_cmd_textgreater{ '&gt;' . $_[0]; }sub do_cmd_textless{ '&lt;' . $_[0]; }sub do_cmd_textunderscore{ '_' . $_[0]; }sub do_cmd_infinity{ '&infin;' . $_[0]; }sub do_cmd_plusminus{ '&plusmn;' . $_[0]; }sub do_cmd_guilabel{    return use_wrappers($_[0]. '<span class="guilabel">', '</span>'); }sub do_cmd_menuselection{    return use_wrappers($_[0], '<span class="guilabel">', '</span>'); }sub do_cmd_sub{    return '</span> &gt; <span class="guilabel">' . $_[0]; }  # words typeset in a special way (not in HTML though) sub do_cmd_ABC{ 'ABC' . $_[0]; }sub do_cmd_UNIX{ '<span class="Unix">Unix</span>' . $_[0]; }sub do_cmd_LaTeX{ '<span class="LaTeX">LaTeX</span>' . $_[0]; }sub do_cmd_TeX{ '<span class="TeX">TeX</span>' . $_[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_hackscore{    local($_) = @_;    next_argument();    return '_' . $_;} # Helper used in many places that arbitrary code-like text appears: sub codetext($){    my $text = "$_[0]";    # Make sure that "---" is not converted to "--" later when    # LaTeX2HTML tries converting em-dashes based on the conventional    # TeX font ligatures:    $text =~ s/--/-\&#45;/go;    return $text;} sub use_wrappers($$$){    local($_,$before,$after) = @_;    my $stuff = next_argument();    return $before . $stuff . $after . $_;} sub use_code_wrappers($$$){    local($_,$before,$after) = @_;    my $stuff = codetext(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. sub do_cmd_pytype{ return $_[0]; }sub do_cmd_makevar{    return use_wrappers($_[0], '<span class="makevar">', '</span>'); }sub do_cmd_code{    return use_code_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_code_wrappers($_[0], '<tt class="regexp">', '</tt>'); }sub do_cmd_character{    return use_code_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], '<em>', '</em>'); }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_code_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }sub do_cmd_kbd{    return use_wrappers($_[0], '<kbd>', '</kbd>'); }sub do_cmd_strong{    return use_wrappers($_[0], '<strong>', '</strong>'); }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\" id='$id' xml:id='$id'\n"            . "href=\"$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\" id='$id' xml:id='$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) {        my $titletext = strip_html_markup("$title");        $repl = ("<em class=\"citetitle\"><a\n"                 . " href=\"$url\"\n"                 . " title=\"$titletext\"\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></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', $_[0]);} sub do_cmd_versionchanged{    return versionnote('Changed', $_[0]);} ## 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!#

Lines 1–500 of 2172.