1 # python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
3 # Heavily based on Guido van Rossum's myformat.perl (now obsolete).
5 # Extension to LaTeX2HTML for documents using myformat.sty.
6 # Subroutines of the form do_cmd_<name> here define translations
7 # for LaTeX commands \<name> defined in the corresponding .sty file.
17 $param = missing_braces
()
18 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
19 ||(s/$next_pair_rx/$param=$2;''/eo));
23 sub next_optional_argument
{
24 my($param, $rx) = ('', "^\\s*(\\[([^]]*)\\])?");
25 s/$rx/$param=$2;''/eo;
29 sub make_icon_filename
($){
30 my($myname, $mydir, $myext) = fileparse
($_[0], '\..*');
35 $myext = ".$IMAGE_TYPE"
37 return "$mydir$dd$myname$myext";
42 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
43 # absolute URL; assume it points off-site
44 my $icon = make_icon_filename
($OFF_SITE_LINK_ICON);
45 return (" <img src=\"$icon\"\n"
46 . ' border="0" class="offsitelink"'
47 . ($OFF_SITE_LINK_ICON_HEIGHT
48 ?
" height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
50 . ($OFF_SITE_LINK_ICON_WIDTH
51 ?
" width=\"$OFF_SITE_LINK_ICON_WIDTH\""
53 . " alt=\"[off-site link]\"\n"
59 # This is a fairly simple hack; it supports \let when it is used to create
60 # (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
61 # Many possible uses of \let aren't supported or aren't supported correctly.
66 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
68 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
73 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
75 my($new, $char) = ($1, $3);
76 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
77 print "\ndefining handler for \\$new to insert '$char'\n";
80 write_warnings
("Could not interpret \\let construct...");
87 # the older version of LaTeX2HTML we use doesn't support this, but we use it:
89 sub do_cmd_textasciitilde
{ '~' . $_[0]; }
90 sub do_cmd_textasciicircum
{ '^' . $_[0]; }
91 sub do_cmd_textbar
{ '|' . $_[0]; }
92 sub do_cmd_texteuro
{ '€' . $_[0]; }
93 sub do_cmd_textgreater
{ '>' . $_[0]; }
94 sub do_cmd_textless
{ '<' . $_[0]; }
95 sub do_cmd_textunderscore
{ '_' . $_[0]; }
96 sub do_cmd_infinity
{ '∞' . $_[0]; }
97 sub do_cmd_plusminus
{ '±' . $_[0]; }
98 sub do_cmd_menuselection
{
99 return use_wrappers
($_[0], '<span class="menuselection">', '</span>'); }
100 sub do_cmd_sub
{ ' > ' . $_[0]; }
103 # words typeset in a special way (not in HTML though)
105 sub do_cmd_ABC
{ 'ABC' . $_[0]; }
106 sub do_cmd_UNIX
{ '<font style="font-variant: small-caps;">Unix</font>'
108 sub do_cmd_ASCII
{ 'ASCII' . $_[0]; }
109 sub do_cmd_POSIX
{ 'POSIX' . $_[0]; }
110 sub do_cmd_C
{ 'C' . $_[0]; }
111 sub do_cmd_Cpp
{ 'C++' . $_[0]; }
112 sub do_cmd_EOF
{ 'EOF' . $_[0]; }
113 sub do_cmd_NULL
{ '<tt class="constant">NULL</tt>' . $_[0]; }
115 sub do_cmd_e
{ '\' . $_[0]; }
117 $DEVELOPER_ADDRESS = '';
120 $PACKAGE_VERSION = '';
122 sub do_cmd_version
{ $PACKAGE_VERSION . $_[0]; }
123 sub do_cmd_shortversion
{ $SHORT_VERSION . $_[0]; }
126 $PACKAGE_VERSION = next_argument
();
130 sub do_cmd_setreleaseinfo
{
132 $RELEASE_INFO = next_argument
();
136 sub do_cmd_setshortversion
{
138 $SHORT_VERSION = next_argument
();
142 sub do_cmd_authoraddress
{
144 $DEVELOPER_ADDRESS = next_argument
();
148 #sub do_cmd_developer{ do_cmd_author($_[0]); }
149 #sub do_cmd_developers{ do_cmd_author($_[0]); }
150 #sub do_cmd_developersaddress{ do_cmd_authoraddress($_[0]); }
152 sub do_cmd_hackscore
{
158 # Helper used in many places that arbitrary code-like text appears:
162 $text =~ s/--/-\-/go;
166 sub use_wrappers
($$$){
167 local($_,$before,$after) = @_;
168 my $stuff = next_argument
();
169 return $before . $stuff . $after . $_;
172 sub use_code_wrappers
($$$){
173 local($_,$before,$after) = @_;
174 my $stuff = codetext
(next_argument
());
175 return $before . $stuff . $after . $_;
178 $IN_DESC_HANDLER = 0;
180 if ($IN_DESC_HANDLER) {
181 return use_wrappers
($_[0], "</var><big>\[</big><var>",
182 "</var><big>\]</big><var>");
185 return use_wrappers
($_[0], "<big>\[</big>", "<big>\]</big>");
189 # Logical formatting (some based on texinfo), needs to be converted to
190 # minimalist HTML. The "minimalist" is primarily to reduce the size of
191 # output files for users that read them over the network rather than
192 # from local repositories.
194 sub do_cmd_pytype
{ return $_[0]; }
196 return use_wrappers
($_[0], '<span class="makevar">', '</span>'); }
198 return use_code_wrappers
($_[0], '<code>', '</code>'); }
200 return use_wrappers
($_[0], '<tt class="module">', '</tt>'); }
202 return use_wrappers
($_[0], '<tt class="keyword">', '</tt>'); }
203 sub do_cmd_exception
{
204 return use_wrappers
($_[0], '<tt class="exception">', '</tt>'); }
206 return use_wrappers
($_[0], '<tt class="class">', '</tt>'); }
208 return use_wrappers
($_[0], '<tt class="function">', '</tt>'); }
210 return use_wrappers
($_[0], '<tt class="constant">', '</tt>'); }
212 return use_wrappers
($_[0], '<tt class="member">', '</tt>'); }
214 return use_wrappers
($_[0], '<tt class="method">', '</tt>'); }
215 sub do_cmd_cfunction
{
216 return use_wrappers
($_[0], '<tt class="cfunction">', '</tt>'); }
218 return use_wrappers
($_[0], '<tt class="cdata">', '</tt>'); }
220 return use_wrappers
($_[0], '<tt class="ctype">', '</tt>'); }
222 return use_code_wrappers
($_[0], '<tt class="regexp">', '</tt>'); }
223 sub do_cmd_character
{
224 return use_code_wrappers
($_[0], '"<tt class="character">', '</tt>"'); }
226 return use_wrappers
($_[0], '<b class="program">', '</b>'); }
227 sub do_cmd_programopt
{
228 return use_wrappers
($_[0], '<b class="programopt">', '</b>'); }
229 sub do_cmd_longprogramopt
{
230 # note that the --- will be later converted to -- by LaTeX2HTML
231 return use_wrappers
($_[0], '<b class="programopt">---', '</b>'); }
233 return use_wrappers
($_[0], '<span class="email">', '</span>'); }
234 sub do_cmd_mailheader
{
235 return use_wrappers
($_[0], '<span class="mailheader">', ':</span>'); }
237 return use_wrappers
($_[0], '<span class="mimetype">', '</span>'); }
239 return use_wrappers
($_[0], "<var>", "</var>"); }
241 return use_wrappers
($_[0], '<i class="dfn">', '</i>'); }
243 return use_wrappers
($_[0], '<i>', '</i>'); }
245 return use_wrappers
($_[0], '<span class="file">', '</span>'); }
247 return do_cmd_file
($_[0]); }
249 return use_code_wrappers
($_[0], '"<tt class="samp">', '</tt>"'); }
251 return use_wrappers
($_[0], '<kbd>', '</kbd>'); }
253 return use_wrappers
($_[0], '<b>', '</b>'); }
255 return use_wrappers
($_[0], '<b>', '</b>'); }
257 return use_wrappers
($_[0], '<i>', '</i>'); }
258 # This can be changed/overridden for translations:
259 %NoticeNames = ('note' => 'Note:',
260 'warning' => 'Warning:',
264 my $label = $NoticeNames{'note'};
267 "<span class=\"note\"><b class=\"label\">$label</b>\n",
270 my $label = $NoticeNames{'warning'};
273 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
278 my $notice = next_optional_argument
();
282 my $label = $NoticeNames{$notice};
283 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
289 return '...' . $_[0]; }
290 sub do_cmd_unspecified
{
291 return '...' . $_[0]; }
294 sub do_cmd_refmodule
{
295 # Insert the right magic to jump to the module definition.
297 my $key = next_optional_argument
();
298 my $module = next_argument
();
301 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
305 sub do_cmd_newsgroup
{
307 my $newsgroup = next_argument
();
308 my $icon = get_link_icon
("news:$newsgroup");
309 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
310 . "$newsgroup$icon</a>");
316 my $envvar = next_argument
();
317 my($name, $aname, $ahref) = new_link_info
();
318 # The <tt> here is really to keep buildindex.py from making
319 # the variable name case-insensitive.
320 add_index_entry
("environment variables!$envvar@<tt>$envvar</tt>",
322 add_index_entry
("$envvar (environment variable)", $ahref);
323 $aname =~ s/<a/<a class="envvar"/;
324 return "$aname$envvar</a>" . $_;
328 # use the URL as both text and hyperlink
330 my $url = next_argument
();
331 my $icon = get_link_icon
($url);
332 $url =~ s/~/~/g;
333 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
337 # two parameters: \manpage{name}{section}
339 my $page = next_argument
();
340 my $section = next_argument
();
341 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
344 $PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
345 #$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
346 $RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
349 my($rfcnum, $format) = @_;
350 return sprintf($format, $rfcnum);
355 my $rfcnumber = next_argument
();
356 my $id = "rfcref-" . ++$global{'max_id'};
357 my $href = get_rfc_url
($rfcnumber, $PEP_FORMAT);
358 my $icon = get_link_icon
($href);
360 my $nstr = gen_index_id
("Python Enhancement Proposals!PEP $rfcnumber", '');
361 $index{$nstr} .= make_half_href
("$CURRENT_FILE#$id");
362 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
368 my $rfcnumber = next_argument
();
369 my $id = "rfcref-" . ++$global{'max_id'};
370 my $href = get_rfc_url
($rfcnumber, $RFC_FORMAT);
371 my $icon = get_link_icon
($href);
373 my $nstr = gen_index_id
("RFC!RFC $rfcnumber", '');
374 $index{$nstr} .= make_half_href
("$CURRENT_FILE#$id");
375 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
381 my $text = next_argument
();
382 my $url = next_argument
();
383 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
386 sub do_cmd_citetitle
{
388 my $url = next_optional_argument
();
389 my $title = next_argument
();
390 my $icon = get_link_icon
($url);
393 $repl = ("<em class=\"citetitle\"><a\n"
395 . " title=\"$title\"\n"
396 . " >$title$icon</a></em>");
399 $repl = "<em class=\"citetitle\"\n >$title</em>";
404 sub do_cmd_deprecated
{
405 # two parameters: \deprecated{version}{whattodo}
407 my $release = next_argument
();
408 my $reason = next_argument
();
409 return ('<div class="versionnote">'
410 . "<b>Deprecated since release $release.</b>"
411 . "\n$reason</div><p>"
416 # one or two parameters: \versionnote[explanation]{version}
419 my $explanation = next_optional_argument
();
420 my $release = next_argument
();
421 my $text = "$type in version $release.";
423 $text = "$type in version $release:\n$explanation.";
425 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
428 sub do_cmd_versionadded
{
429 return versionnote
('New', $_[0]);
432 sub do_cmd_versionchanged
{
433 return versionnote
('Changed', $_[0]);
437 # These function handle platform dependency tracking.
441 my $platform = next_argument
();
442 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
443 $platform = "Macintosh"
444 if $platform eq 'Mac';
445 return "\n<p class=\"availability\">Availability: <span"
446 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
449 $IGNORE_PLATFORM_ANNOTATION = '';
450 sub do_cmd_ignorePlatformAnnotation
{
452 $IGNORE_PLATFORM_ANNOTATION = next_argument
();
461 sub get_indexsubitem
(){
462 return $INDEX_SUBITEM ?
" $INDEX_SUBITEM" : '';
465 sub do_cmd_setindexsubitem
{
467 $INDEX_SUBITEM = next_argument
();
471 sub do_cmd_withsubitem
{
472 # We can't really do the right thing, because LaTeX2HTML doesn't
473 # do things in the right order, but we need to at least strip this stuff
474 # out, and leave anything that the second argument expanded out to.
477 my $oldsubitem = $INDEX_SUBITEM;
478 $INDEX_SUBITEM = next_argument
();
479 my $stuff = next_argument
();
480 my $br_id = ++$globals{'max_id'};
481 my $marker = "$O$br_id$C";
485 . "\\setindexsubitem$marker$oldsubitem$marker"
489 # This is the prologue macro which is required to start writing the
490 # mod\jobname.idx file; we can just ignore it. (Defining this suppresses
491 # a warning that \makemodindex is unknown.)
493 sub do_cmd_makemodindex
{ return $_[0]; }
495 # We're in the document subdirectory when this happens!
497 open(IDXFILE
, '>index.dat') || die "\n$!\n";
498 open(INTLABELS
, '>intlabels.pl') || die "\n$!\n";
499 print INTLABELS
"%internal_labels = ();\n";
500 print INTLABELS
"1; # hack in case there are no entries\n\n";
502 # Using \0 for this is bad because we can't use common tools to work with the
503 # resulting files. Things like grep can be useful with this stuff!
505 $IDXFILE_FIELD_SEP = "\1";
507 sub write_idxfile
($$){
508 my($ahref, $str) = @_;
509 print IDXFILE
$ahref, $IDXFILE_FIELD_SEP, $str, "\n";
514 my($node, $target) = @_;
515 print INTLABELS
"\$internal_labels{\"$target\"} = \"/$node\";\n";
516 return "<a href=\"$node#$target\">";
519 sub add_index_entry
($$){
520 # add an entry to the index structures; ignore the return value
521 my($str, $ahref) = @_;
522 $str = gen_index_id
($str, '');
523 $index{$str} .= $ahref;
524 write_idxfile
($ahref, $str);
528 my $name = "l2h-" . ++$globals{'max_id'};
529 my $aname = "<a name=\"$name\">";
530 my $ahref = gen_link
($CURRENT_FILE, $name);
531 return ($name, $aname, $ahref);
534 $IndexMacroPattern = '';
535 sub define_indexing_macro
(@
){
538 for (; $i < $count; ++$i) {
540 my $cmd = "idx_cmd_$name";
541 die "\nNo function $cmd() defined!\n"
543 eval ("sub do_cmd_$name { return process_index_macros("
544 . "\$_[0], '$name'); }");
545 if (length($IndexMacroPattern) == 0) {
546 $IndexMacroPattern = "$name";
549 $IndexMacroPattern .= "|$name";
555 sub process_index_macros
($$){
557 my $cmdname = $_[1]; # This is what triggered us in the first place;
558 # we know it's real, so just process it.
559 my($name, $aname, $ahref) = new_link_info
();
560 my $cmd = "idx_cmd_$cmdname";
561 print "\nIndexing: \\$cmdname"
563 &$cmd($ahref); # modifies $_ and adds index entries
564 while (/^[\s\n]*\\($IndexMacroPattern)</) {
568 $cmd = "idx_cmd_$cmdname";
569 if (!defined &$cmd) {
573 s/^[\s\n]*\\$cmdname//;
577 # XXX I don't remember why I added this to begin with.
578 # if (/^[ \t\r\n]/) {
579 # $_ = substr($_, 1);
581 return "$aname$anchor_invisible_mark</a>" . $_;
584 define_indexing_macro
('index');
585 sub idx_cmd_index
($){
586 my $str = next_argument
();
587 add_index_entry
("$str", $_[0]);
590 define_indexing_macro
('kwindex');
591 sub idx_cmd_kwindex
($){
592 my $str = next_argument
();
593 add_index_entry
("<tt>$str</tt>!keyword", $_[0]);
594 add_index_entry
("keyword!<tt>$str</tt>", $_[0]);
597 define_indexing_macro
('indexii');
598 sub idx_cmd_indexii
($){
599 my $str1 = next_argument
();
600 my $str2 = next_argument
();
601 add_index_entry
("$str1!$str2", $_[0]);
602 add_index_entry
("$str2!$str1", $_[0]);
605 define_indexing_macro
('indexiii');
606 sub idx_cmd_indexiii
($){
607 my $str1 = next_argument
();
608 my $str2 = next_argument
();
609 my $str3 = next_argument
();
610 add_index_entry
("$str1!$str2 $str3", $_[0]);
611 add_index_entry
("$str2!$str3, $str1", $_[0]);
612 add_index_entry
("$str3!$str1 $str2", $_[0]);
615 define_indexing_macro
('indexiv');
616 sub idx_cmd_indexiv
($){
617 my $str1 = next_argument
();
618 my $str2 = next_argument
();
619 my $str3 = next_argument
();
620 my $str4 = next_argument
();
621 add_index_entry
("$str1!$str2 $str3 $str4", $_[0]);
622 add_index_entry
("$str2!$str3 $str4, $str1", $_[0]);
623 add_index_entry
("$str3!$str4, $str1 $str2", $_[0]);
624 add_index_entry
("$str4!$str1 $str2 $str3", $_[0]);
627 define_indexing_macro
('ttindex');
628 sub idx_cmd_ttindex
($){
629 my $str = codetext
(next_argument
());
630 my $entry = $str . get_indexsubitem
();
631 add_index_entry
($entry, $_[0]);
634 sub my_typed_index_helper
($$){
635 my($word, $ahref) = @_;
636 my $str = next_argument
();
637 add_index_entry
("$str $word", $ahref);
638 add_index_entry
("$word!$str", $ahref);
641 define_indexing_macro
('stindex', 'opindex', 'exindex', 'obindex');
642 sub idx_cmd_stindex
($){ my_typed_index_helper
('statement', $_[0]); }
643 sub idx_cmd_opindex
($){ my_typed_index_helper
('operator', $_[0]); }
644 sub idx_cmd_exindex
($){ my_typed_index_helper
('exception', $_[0]); }
645 sub idx_cmd_obindex
($){ my_typed_index_helper
('object', $_[0]); }
647 define_indexing_macro
('bifuncindex');
648 sub idx_cmd_bifuncindex
($){
649 my $str = next_argument
();
650 add_index_entry
("<tt class=\"function\">$str()</tt> (built-in function)",
655 sub make_mod_index_entry
($$){
656 my($str, $define) = @_;
657 my($name, $aname, $ahref) = new_link_info
();
658 # equivalent of add_index_entry() using $define instead of ''
659 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
660 if ($define eq 'DEF');
661 $str = gen_index_id
($str, $define);
662 $index{$str} .= $ahref;
663 write_idxfile
($ahref, $str);
665 if ($define eq 'DEF') {
666 # add to the module index
667 $str =~ /(<tt.*<\/tt
>)/;
669 $Modules{$nstr} .= $ahref;
671 return "$aname$anchor_invisible_mark2</a>";
678 sub define_module
($$){
679 my($word, $name) = @_;
680 my $section_tag = join('', @curr_sec_id);
681 if ($word ne "built-in" && $word ne "extension"
682 && $word ne "standard" && $word ne "") {
683 write_warnings
("Bad module type '$word'"
684 . " for \\declaremodule (module $name)");
687 $word = "$word " if $word;
688 $THIS_MODULE = "$name";
689 $INDEX_SUBITEM = "(in module $name)";
691 return make_mod_index_entry
(
692 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
695 sub my_module_index_helper
($$){
696 local($word, $_) = @_;
697 my $name = next_argument
();
698 return define_module
($word, $name) . $_;
701 sub do_cmd_modindex
{ return my_module_index_helper
('', $_[0]); }
702 sub do_cmd_bimodindex
{ return my_module_index_helper
('built-in', $_[0]); }
703 sub do_cmd_exmodindex
{ return my_module_index_helper
('extension', $_[0]); }
704 sub do_cmd_stmodindex
{ return my_module_index_helper
('standard', $_[0]); }
706 # my $name = next_argument();
707 # return define_module('standard', $name) . $_;
710 sub ref_module_index_helper
($$){
711 my($word, $ahref) = @_;
712 my $str = next_argument
();
713 $word = "$word " if $word;
714 $str = "<tt class=\"module\">$str</tt> (${word}module)";
715 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
716 # just inline it all here
717 $str = gen_index_id
($str, 'REF');
718 $index{$str} .= $ahref;
719 write_idxfile
($ahref, $str);
722 # these should be adjusted a bit....
723 define_indexing_macro
('refmodindex', 'refbimodindex',
724 'refexmodindex', 'refstmodindex');
725 sub idx_cmd_refmodindex
($){
726 return ref_module_index_helper
('', $_[0]); }
727 sub idx_cmd_refbimodindex
($){
728 return ref_module_index_helper
('built-in', $_[0]); }
729 sub idx_cmd_refexmodindex
($){
730 return ref_module_index_helper
('extension', $_[0]);}
731 sub idx_cmd_refstmodindex
($){
732 return ref_module_index_helper
('standard', $_[0]); }
734 sub do_cmd_nodename
{ return do_cmd_label
($_[0]); }
737 $anchor_invisible_mark = ' ';
738 $anchor_invisible_mark2 = '';
740 $icons{'anchor_mark'} = '';
744 # Create an index entry, but include the string in the target anchor
745 # instead of the dummy filler.
747 sub make_str_index_entry
($){
749 my($name, $aname, $ahref) = new_link_info
();
750 add_index_entry
($str, $ahref);
751 return "$aname$str</a>";
755 %TokenToTargetMapping = (); # language:token -> link target
756 %DefinedGrammars = (); # language -> full grammar text
757 %BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
761 my $token = next_argument
();
762 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
763 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
764 # recursive definition or display-only productionlist
768 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
769 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
770 print "Adding '$CURRENT_FILE' to back-patch list.\n";
772 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
774 return "<a href=\"$target\">$token</a>" . $_;
777 sub do_cmd_grammartoken
{
778 return do_cmd_token
(@_);
781 sub do_env_productionlist
{
783 my $lang = next_optional_argument
();
784 my $filename = "grammar-$lang.txt";
786 $filename = 'grammar.txt';
788 local($CURRENT_GRAMMAR) = $lang;
789 $DefinedGrammars{$lang} .= $_;
790 return ("<dl><dd class=\"grammar\">\n"
791 . "<div class=\"productions\">\n"
792 . "<table cellpadding=\"2\">\n"
793 . translate_commands
(translate_environments
($_))
798 : ("<a class=\"grammar-footer\"\n"
799 . " href=\"$filename\" type=\"text/plain\"\n"
800 . " >Download entire grammar as text.</a>\n"))
804 sub do_cmd_production
{
806 my $token = next_argument
();
807 my $defn = next_argument
();
808 my $lang = $CURRENT_GRAMMAR;
809 local($CURRENT_TOKEN) = $token;
811 return ("<tr valign=\"baseline\">\n"
812 . " <td><code>$token</code></td>\n"
813 . " <td> ::= </td>\n"
815 . translate_commands
($defn)
816 . "</code></td></tr>"
821 $target = "$CURRENT_FILE\#tok-$token";
824 $target = "$CURRENT_FILE\#tok-$lang-$token";
826 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
827 return ("<tr valign=\"baseline\">\n"
828 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
829 . " <td> ::= </td>\n"
831 . translate_commands
($defn)
832 . "</code></td></tr>"
836 sub do_cmd_productioncont
{
838 my $defn = next_argument
();
839 $defn =~ s/^( +)/' ' x length $1/e;
840 return ("<tr valign=\"baseline\">\n"
841 . " <td> </td>\n"
842 . " <td> </td>\n"
844 . translate_commands
($defn)
845 . "</code></td></tr>"
849 sub process_grammar_files
(){
853 print "process_grammar_files()\n";
854 foreach $lang (keys %DefinedGrammars) {
855 $filename = "grammar-$lang.txt";
860 $filename = 'grammar.txt';
862 open(GRAMMAR
, ">$filename") || die "\n$!\n";
863 print GRAMMAR strip_grammar_markup
($DefinedGrammars{$lang});
865 print "Wrote grammar file $filename\n";
867 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
868 foreach $filename (keys %BackpatchGrammarFiles) {
869 print "\nBack-patching grammar links in $filename\n";
871 open(GRAMMAR
, "<$filename") || die "\n$!\n";
872 # read all of the file into the buffer
873 sysread(GRAMMAR
, $buffer, 1024*1024);
875 while ($buffer =~ /$PATTERN/) {
876 my($lang, $token) = ($1, $2);
877 my $target = $TokenToTargetMapping{"$lang:$token"};
878 my $source = "<pyGrammarToken><$lang><$token>";
879 $buffer =~ s/$source/$target/g;
881 open(GRAMMAR
, ">$filename") || die "\n$!\n";
882 print GRAMMAR
$buffer;
887 sub strip_grammar_markup
($){
889 s/\\productioncont/ /g;
890 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
891 s/\\token(<<\d+>>)(.+)\1/$2/g;
892 s/\\e([^a-zA-Z])/\\$1/g;
901 $REFCOUNTS_LOADED = 0;
903 sub load_refcounts
(){
904 $REFCOUNTS_LOADED = 1;
906 my($myname, $mydir, $myext) = fileparse
(__FILE__
, '\..*');
907 chop $mydir; # remove trailing '/'
908 ($myname, $mydir, $myext) = fileparse
($mydir, '\..*');
909 chop $mydir; # remove trailing '/'
910 $mydir = getcwd
() . "$dd$mydir"
911 unless $mydir =~ s
|^/|/|;
913 my $filename = "$mydir${dd}api${dd}refcounts.dat";
914 open(REFCOUNT_FILE
, "<$filename") || die "\n$!\n";
915 print "[loading API refcount data]";
916 while (<REFCOUNT_FILE
>) {
917 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
918 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
919 #print "\n$func($param) --> $count";
920 $REFCOUNTS{"$func:$param"} = $count;
925 sub get_refcount
($$){
926 my($func, $param) = @_;
928 unless $REFCOUNTS_LOADED;
929 return $REFCOUNTS{"$func:$param"};
933 $TLSTART = '<span class="typelabel">';
934 $TLEND = '</span> ';
936 sub cfuncline_helper
($$$){
937 my($type, $name, $args) = @_;
938 my $idx = make_str_index_entry
(
939 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem
());
941 $idx =~ s/\(\)//; # ???? - why both of these?
942 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var
>,/g
;
943 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var
>/s
;
944 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
945 . "<td><nobr>$type\ <b>$idx</b>(</nobr></td>"
949 sub do_cmd_cfuncline
{
951 my $type = next_argument
();
952 my $name = next_argument
();
953 my $args = next_argument
();
954 my $siginfo = cfuncline_helper
($type, $name, $args);
955 return "<dt>$siginfo\n<dd>" . $_;
957 sub do_env_cfuncdesc
{
959 my $type = next_argument
();
960 my $name = next_argument
();
961 my $args = next_argument
();
962 my $siginfo = cfuncline_helper
($type, $name, $args);
963 my $result_rc = get_refcount
($name, '');
965 if ($result_rc eq '+1') {
966 $rcinfo = 'New reference';
968 elsif ($result_rc eq '0') {
969 $rcinfo = 'Borrowed reference';
971 elsif ($result_rc eq 'null') {
972 $rcinfo = 'Always <tt class="constant">NULL</tt>';
975 $rcinfo = ( "\n<div class=\"refcount-info\">"
976 . "\n <span class=\"label\">Return value:</span>"
977 . "\n <span class=\"value\">$rcinfo.</span>"
980 return "<dl><dt>$siginfo\n<dd>"
986 sub do_cmd_cmemberline
{
988 my $container = next_argument
();
989 my $type = next_argument
();
990 my $name = next_argument
();
991 my $idx = make_str_index_entry
("<tt class=\"cmember\">$name</tt>"
992 . " ($container member)");
994 return "<dt>$type <b>$idx</b>\n<dd>"
997 sub do_env_cmemberdesc
{
999 my $container = next_argument
();
1000 my $type = next_argument
();
1001 my $name = next_argument
();
1002 my $idx = make_str_index_entry
("<tt class=\"cmember\">$name</tt>"
1003 . " ($container member)");
1004 $idx =~ s/ \(.*\)//;
1005 return "<dl><dt>$type <b>$idx</b>\n<dd>"
1010 sub do_env_csimplemacrodesc
{
1012 my $name = next_argument
();
1013 my $idx = make_str_index_entry
("<tt class=\"macro\">$name</tt>");
1014 return "<dl><dt><b>$idx</b>\n<dd>"
1019 sub do_env_ctypedesc
{
1021 my $index_name = next_optional_argument
();
1022 my $type_name = next_argument
();
1023 $index_name = $type_name
1025 my($name, $aname, $ahref) = new_link_info
();
1026 add_index_entry
("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1027 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
1032 sub do_env_cvardesc
{
1034 my $var_type = next_argument
();
1035 my $var_name = next_argument
();
1036 my $idx = make_str_index_entry
("<tt class=\"cdata\">$var_name</tt>"
1037 . get_indexsubitem
());
1038 $idx =~ s/ \(.*\)//;
1039 return "<dl><dt>$var_type <b>$idx</b>\n"
1045 sub convert_args
($){
1046 local($IN_DESC_HANDLER) = 1;
1048 return translate_commands
($_);
1051 sub funcline_helper
($$$){
1052 my($first, $idxitem, $arglist) = @_;
1053 return (($first ?
'<dl>' : '')
1054 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1055 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1056 . "\n <td><var>$arglist</var>)</td></tr></table>\n<dd>");
1059 sub do_env_funcdesc
{
1061 my $function_name = next_argument
();
1062 my $arg_list = convert_args
(next_argument
());
1063 my $idx = make_str_index_entry
("<tt class=\"function\">$function_name()"
1065 . get_indexsubitem
());
1066 $idx =~ s/ \(.*\)//;
1067 $idx =~ s/\(\)<\/tt>/<\
/tt>/;
1068 return funcline_helper
(1, $idx, $arg_list) . $_ . '</dl>';
1071 sub do_env_funcdescni
{
1073 my $function_name = next_argument
();
1074 my $arg_list = convert_args
(next_argument
());
1075 my $prefix = "<tt class=\"function\">$function_name</tt>";
1076 return funcline_helper
(1, $prefix, $arg_list) . $_ . '</dl>';
1079 sub do_cmd_funcline
{
1081 my $function_name = next_argument
();
1082 my $arg_list = convert_args
(next_argument
());
1083 my $prefix = "<tt class=\"function\">$function_name()</tt>";
1084 my $idx = make_str_index_entry
($prefix . get_indexsubitem
());
1085 $prefix =~ s/\(\)//;
1087 return funcline_helper
(0, $prefix, $arg_list) . $_;
1090 sub do_cmd_funclineni
{
1092 my $function_name = next_argument
();
1093 my $arg_list = convert_args
(next_argument
());
1094 my $prefix = "<tt class=\"function\">$function_name</tt>";
1096 return funcline_helper
(0, $prefix, $arg_list) . $_;
1099 # Change this flag to index the opcode entries. I don't think it's very
1100 # useful to index them, since they're only presented to describe the dis
1105 sub do_env_opcodedesc
{
1107 my $opcode_name = next_argument
();
1108 my $arg_list = next_argument
();
1110 if ($INDEX_OPCODES) {
1111 $idx = make_str_index_entry
("<tt class=\"opcode\">$opcode_name</tt>"
1112 . ' (byte code instruction)');
1113 $idx =~ s/ \(byte code instruction\)//;
1116 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
1118 my $stuff = "<dl><dt><b>$idx</b>";
1120 $stuff .= " <var>$arg_list</var>";
1122 return $stuff . "\n<dd>" . $_ . '</dl>';
1125 sub do_env_datadesc
{
1127 my $dataname = next_argument
();
1128 my $idx = make_str_index_entry
("<tt>$dataname</tt>" . get_indexsubitem
());
1129 $idx =~ s/ \(.*\)//;
1130 return "<dl><dt><b>$idx</b>\n<dd>"
1135 sub do_env_datadescni
{
1137 my $idx = next_argument
();
1138 if (! $STRING_INDEX_TT) {
1139 $idx = "<tt>$idx</tt>";
1141 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
1144 sub do_cmd_dataline
{
1146 my $data_name = next_argument
();
1147 my $idx = make_str_index_entry
("<tt>$data_name</tt>" . get_indexsubitem
());
1148 $idx =~ s/ \(.*\)//;
1149 return "<dt><b>$idx</b><dd>" . $_;
1152 sub do_cmd_datalineni
{
1154 my $data_name = next_argument
();
1155 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1160 my $excname = next_argument
();
1161 my $idx = make_str_index_entry
("<tt class=\"exception\">$excname</tt>");
1162 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
1168 sub do_env_fulllineitems
{ return do_env_itemize
(@_); }
1171 sub handle_classlike_descriptor
($$){
1172 local($_, $what) = @_;
1173 $THIS_CLASS = next_argument
();
1174 my $arg_list = convert_args
(next_argument
());
1175 $idx = make_str_index_entry
(
1176 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
1177 $idx =~ s/ \(.*\)//;
1178 my $prefix = "$TLSTART$what$TLEND$idx";
1179 return funcline_helper
(1, $prefix, $arg_list) . $_ . '</dl>';
1182 sub do_env_classdesc
{
1183 return handle_classlike_descriptor
($_[0], "class");
1186 sub do_env_classdescstar
{
1188 $THIS_CLASS = next_argument
();
1189 $idx = make_str_index_entry
(
1190 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
1191 $idx =~ s/ \(.*\)//;
1192 my $prefix = "${TLSTART}class$TLEND$idx";
1193 # Can't use funcline_helper() since there is no args list.
1194 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
1197 sub do_env_excclassdesc
{
1198 return handle_classlike_descriptor
($_[0], "exception");
1202 sub do_env_methoddesc
{
1204 my $class_name = next_optional_argument
();
1205 $class_name = $THIS_CLASS
1207 my $method = next_argument
();
1208 my $arg_list = convert_args
(next_argument
());
1211 $extra = " ($class_name method)";
1213 my $idx = make_str_index_entry
(
1214 "<tt class=\"method\">$method()</tt>$extra");
1215 $idx =~ s/ \(.*\)//;
1217 return funcline_helper
(1, $idx, $arg_list) . $_ . '</dl>';
1221 sub do_cmd_methodline
{
1223 my $class_name = next_optional_argument
();
1224 $class_name = $THIS_CLASS
1226 my $method = next_argument
();
1227 my $arg_list = convert_args
(next_argument
());
1230 $extra = " ($class_name method)";
1232 my $idx = make_str_index_entry
(
1233 "<tt class=\"method\">$method()</tt>$extra");
1234 $idx =~ s/ \(.*\)//;
1236 return funcline_helper
(0, $idx, $arg_list) . $_;
1240 sub do_cmd_methodlineni
{
1242 next_optional_argument
();
1243 my $method = next_argument
();
1244 my $arg_list = convert_args
(next_argument
());
1245 return funcline_helper
(0, $method, $arg_list) . $_;
1248 sub do_env_methoddescni
{
1250 next_optional_argument
();
1251 my $method = next_argument
();
1252 my $arg_list = convert_args
(next_argument
());
1253 return funcline_helper
(1, $method, $arg_list) . $_ . '</dl>';
1257 sub do_env_memberdesc
{
1259 my $class = next_optional_argument
();
1260 my $member = next_argument
();
1261 $class = $THIS_CLASS
1264 $extra = " ($class attribute)"
1266 my $idx = make_str_index_entry
("<tt class=\"member\">$member</tt>$extra");
1267 $idx =~ s/ \(.*\)//;
1269 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
1273 sub do_cmd_memberline
{
1275 my $class = next_optional_argument
();
1276 my $member = next_argument
();
1277 $class = $THIS_CLASS
1280 $extra = " ($class attribute)"
1282 my $idx = make_str_index_entry
("<tt class=\"member\">$member</tt>$extra");
1283 $idx =~ s/ \(.*\)//;
1285 return "<dt><b>$idx</b><dd>" . $_;
1289 sub do_env_memberdescni
{
1291 next_optional_argument
();
1292 my $member = next_argument
();
1293 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
1299 sub do_cmd_memberlineni
{
1301 next_optional_argument
();
1302 my $member = next_argument
();
1303 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
1307 @col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
1309 %FontConversions = ('cdata' => 'tt class="cdata"',
1310 'character' => 'tt class="character"',
1311 'class' => 'tt class="class"',
1312 'command' => 'code',
1313 'constant' => 'tt class="constant"',
1314 'exception' => 'tt class="exception"',
1315 'file' => 'tt class="file"',
1316 'filenq' => 'tt class="file"',
1318 'member' => 'tt class="member"',
1319 'programopt' => 'b',
1324 # do a little magic on a font name to get the right behavior in the first
1325 # column of the output table
1327 if (defined $FontConversions{$font}) {
1328 $font = $FontConversions{$font};
1333 sub figure_column_alignment
($){
1338 my $mark = substr($a, 0, 1);
1341 { $r = ' align="center"'; }
1342 elsif ($mark eq 'r')
1343 { $r = ' align="right"'; }
1344 elsif ($mark eq 'l')
1345 { $r = ' align="left"'; }
1346 elsif ($mark eq 'p')
1347 { $r = ' align="left"'; }
1351 sub setup_column_alignments
($){
1353 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
1354 my $a1 = figure_column_alignment
($s1);
1355 my $a2 = figure_column_alignment
($s2);
1356 my $a3 = figure_column_alignment
($s3);
1357 my $a4 = figure_column_alignment
($s4);
1358 my $a5 = figure_column_alignment
($s5);
1359 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1360 $col_aligns[1] = "<td$a2>";
1361 $col_aligns[2] = "<td$a3>";
1362 $col_aligns[3] = "<td$a4>";
1363 $col_aligns[4] = "<td$a5>";
1364 # return the aligned header start tags
1365 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
1368 sub get_table_col1_fonts
(){
1369 my $font = $globals{'lineifont'};
1370 my($sfont, $efont) = ('', '');
1373 $efont = "</$font>";
1374 $efont =~ s/ .*>/>/;
1376 return ($sfont, $efont);
1381 my $arg = next_argument
();
1382 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1383 my $font = fix_font
(next_argument
());
1384 my $h1 = next_argument
();
1385 my $h2 = next_argument
();
1387 $globals{'lineifont'} = $font;
1388 my $a1 = $col_aligns[0];
1389 my $a2 = $col_aligns[1];
1390 s/\\lineii</\\lineii[$a1|$a2]</g;
1391 return '<table border align="center" style="border-collapse: collapse">'
1393 . "\n <tr class=\"tableheader\">"
1394 . "\n $th1<b>$h1</b>\ </th>"
1395 . "\n $th2<b>$h2</b>\ </th>"
1398 . "\n <tbody valign=\"baseline\">"
1404 sub do_env_longtableii
{
1405 return do_env_tableii
(@_);
1410 my $aligns = next_optional_argument
();
1411 my $c1 = next_argument
();
1412 my $c2 = next_argument
();
1414 my($sfont, $efont) = get_table_col1_fonts
();
1415 $c2 = ' ' if ($c2 eq '');
1416 my($c1align, $c2align) = split('\|', $aligns);
1418 if ($c1align =~ /align="right"/ || $c1 eq '') {
1419 $padding = ' ';
1421 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1422 . " $c2align$c2</td>"
1426 sub do_env_tableiii
{
1428 my $arg = next_argument
();
1429 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1430 my $font = fix_font
(next_argument
());
1431 my $h1 = next_argument
();
1432 my $h2 = next_argument
();
1433 my $h3 = next_argument
();
1435 $globals{'lineifont'} = $font;
1436 my $a1 = $col_aligns[0];
1437 my $a2 = $col_aligns[1];
1438 my $a3 = $col_aligns[2];
1439 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1440 return '<table border align="center" style="border-collapse: collapse">'
1442 . "\n <tr class=\"tableheader\">"
1443 . "\n $th1<b>$h1</b>\ </th>"
1444 . "\n $th2<b>$h2</b>\ </th>"
1445 . "\n $th3<b>$h3</b>\ </th>"
1448 . "\n <tbody valign=\"baseline\">"
1454 sub do_env_longtableiii
{
1455 return do_env_tableiii
(@_);
1460 my $aligns = next_optional_argument
();
1461 my $c1 = next_argument
();
1462 my $c2 = next_argument
();
1463 my $c3 = next_argument
();
1465 my($sfont, $efont) = get_table_col1_fonts
();
1466 $c3 = ' ' if ($c3 eq '');
1467 my($c1align, $c2align, $c3align) = split('\|', $aligns);
1469 if ($c1align =~ /align="right"/ || $c1 eq '') {
1470 $padding = ' ';
1472 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1473 . " $c2align$c2</td>\n"
1474 . " $c3align$c3</td>"
1480 my $arg = next_argument
();
1481 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1482 my $font = fix_font
(next_argument
());
1483 my $h1 = next_argument
();
1484 my $h2 = next_argument
();
1485 my $h3 = next_argument
();
1486 my $h4 = next_argument
();
1488 $globals{'lineifont'} = $font;
1489 my $a1 = $col_aligns[0];
1490 my $a2 = $col_aligns[1];
1491 my $a3 = $col_aligns[2];
1492 my $a4 = $col_aligns[3];
1493 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1494 return '<table border align="center" style="border-collapse: collapse">'
1496 . "\n <tr class=\"tableheader\">"
1497 . "\n $th1<b>$h1</b>\ </th>"
1498 . "\n $th2<b>$h2</b>\ </th>"
1499 . "\n $th3<b>$h3</b>\ </th>"
1500 . "\n $th4<b>$h4</b>\ </th>"
1503 . "\n <tbody valign=\"baseline\">"
1509 sub do_env_longtableiv
{
1510 return do_env_tableiv
(@_);
1515 my $aligns = next_optional_argument
();
1516 my $c1 = next_argument
();
1517 my $c2 = next_argument
();
1518 my $c3 = next_argument
();
1519 my $c4 = next_argument
();
1521 my($sfont, $efont) = get_table_col1_fonts
();
1522 $c4 = ' ' if ($c4 eq '');
1523 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
1525 if ($c1align =~ /align="right"/ || $c1 eq '') {
1526 $padding = ' ';
1528 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1529 . " $c2align$c2</td>\n"
1530 . " $c3align$c3</td>\n"
1531 . " $c4align$c4</td>"
1537 my $arg = next_argument
();
1538 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1539 my $font = fix_font
(next_argument
());
1540 my $h1 = next_argument
();
1541 my $h2 = next_argument
();
1542 my $h3 = next_argument
();
1543 my $h4 = next_argument
();
1544 my $h5 = next_argument
();
1546 $globals{'lineifont'} = $font;
1547 my $a1 = $col_aligns[0];
1548 my $a2 = $col_aligns[1];
1549 my $a3 = $col_aligns[2];
1550 my $a4 = $col_aligns[3];
1551 my $a5 = $col_aligns[4];
1552 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1553 return '<table border align="center" style="border-collapse: collapse">'
1555 . "\n <tr class=\"tableheader\">"
1556 . "\n $th1<b>$h1</b>\ </th>"
1557 . "\n $th2<b>$h2</b>\ </th>"
1558 . "\n $th3<b>$h3</b>\ </th>"
1559 . "\n $th4<b>$h4</b>\ </th>"
1560 . "\n $th5<b>$h5</b>\ </th>"
1563 . "\n <tbody valign=\"baseline\">"
1569 sub do_env_longtablev
{
1570 return do_env_tablev
(@_);
1575 my $aligns = next_optional_argument
();
1576 my $c1 = next_argument
();
1577 my $c2 = next_argument
();
1578 my $c3 = next_argument
();
1579 my $c4 = next_argument
();
1580 my $c5 = next_argument
();
1582 my($sfont, $efont) = get_table_col1_fonts
();
1583 $c5 = ' ' if ($c5 eq '');
1584 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
1586 if ($c1align =~ /align="right"/ || $c1 eq '') {
1587 $padding = ' ';
1589 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1590 . " $c2align$c2</td>\n"
1591 . " $c3align$c3</td>\n"
1592 . " $c4align$c4</td>\n"
1593 . " $c5align$c5</td>"
1598 # These can be used to control the title page appearance;
1599 # they need a little bit of documentation.
1601 # If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1602 # $ICONSERVER directory, or include path information (other than "./"). The
1603 # default image type will be assumed if an extension is not provided.
1605 # If specified, the "title page" will contain two colums: one containing the
1606 # title/author/etc., and the other containing the graphic. Use the other
1607 # four variables listed here to control specific details of the layout; all
1610 # $TITLE_PAGE_GRAPHIC = "my-company-logo";
1611 # $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1612 # $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1613 # $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1614 # $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1616 sub make_my_titlepage
(){
1619 $the_title .= "\n<h1>$t_title</h1>";
1622 write_warnings
("\nThis document has no title.");
1626 my $href = translate_commands
($t_authorURL);
1627 $href = make_named_href
('author', $href,
1628 "<b><font size=\"+2\">$t_author"
1630 $the_title .= "\n<p>$href</p>";
1633 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1634 . '</font></b></p>');
1638 write_warnings
("\nThere is no author for this document.");
1641 $the_title .= "\n<p>$t_institute</p>";
1643 if ($DEVELOPER_ADDRESS) {
1644 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1647 $the_title .= "\n<p><i>$t_affil</i></p>";
1650 $the_title .= "\n<p>";
1651 if ($PACKAGE_VERSION) {
1652 $the_title .= ('<strong>Release '
1653 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
1655 $the_title .= "<strong>$t_date</strong></p>"
1658 $the_title .= "\n<p>$t_address</p>";
1661 $the_title .= "\n<p>";
1664 $the_title .= "\n<p>$t_email</p>";
1669 sub make_my_titlegraphic
(){
1670 my $filename = make_icon_filename
($TITLE_PAGE_GRAPHIC);
1671 my $graphic = "<td class=\"titlegraphic\"";
1672 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1673 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1674 $graphic .= "><img";
1675 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1676 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1677 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1678 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
1679 $graphic .= "\n src=\"$filename\"></td>\n";
1683 sub do_cmd_maketitle
{
1685 my $the_title = "\n";
1686 if ($EXTERNAL_UP_LINK) {
1687 # This generates a <LINK> element in the wrong place (the
1688 # body), but I don't see any other way to get this generated
1689 # at all. Browsers like Mozilla, that support navigation
1690 # links, can make use of this.
1691 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1692 . ($EXTERNAL_UP_TITLE
1693 ?
" title='$EXTERNAL_UP_TITLE'" : '')
1696 $the_title .= '<div class="titlepage">';
1697 if ($TITLE_PAGE_GRAPHIC) {
1698 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1699 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1700 . "<tr align=\"right\">\n<td>"
1701 . make_my_titlepage
()
1703 . make_my_titlegraphic
()
1704 . "</tr>\n</table>");
1707 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1708 . make_my_titlegraphic
()
1710 . make_my_titlepage
()
1711 . "</td></tr>\n</table>");
1715 $the_title .= ("\n<center>"
1716 . make_my_titlepage
()
1719 $the_title .= "\n</div>";
1720 return $the_title . $_;
1721 $the_title .= "\n</center></div>";
1722 return $the_title . $_ ;
1727 # Module synopsis support
1730 require SynopsisTable
;
1732 sub get_chapter_id
(){
1733 my $id = do_cmd_thechapter
('');
1734 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
1739 # 'chapter' => 'SynopsisTable instance'
1740 %ModuleSynopses = ();
1742 sub get_synopsis_table
($){
1745 foreach $key (keys %ModuleSynopses) {
1746 if ($key eq $chap) {
1747 return $ModuleSynopses{$chap};
1750 my $st = SynopsisTable
->new();
1751 $ModuleSynopses{$chap} = $st;
1755 sub do_cmd_moduleauthor
{
1762 sub do_cmd_sectionauthor
{
1769 sub do_cmd_declaremodule
{
1771 my $key = next_optional_argument
();
1772 my $type = next_argument
();
1773 my $name = next_argument
();
1774 my $st = get_synopsis_table
(get_chapter_id
());
1776 $key = $name unless $key;
1777 $type = 'built-in' if $type eq 'builtin';
1778 $st->declare($name, $key, $type);
1779 define_module
($type, $name);
1780 return anchor_label
("module-$key",$CURRENT_FILE,$_)
1783 sub do_cmd_modulesynopsis
{
1785 my $st = get_synopsis_table
(get_chapter_id
());
1786 $st->set_synopsis($THIS_MODULE, translate_commands
(next_argument
()));
1790 sub do_cmd_localmoduletable
{
1792 my $chap = get_chapter_id
();
1793 my $st = get_synopsis_table
($chap);
1794 $st->set_file("$CURRENT_FILE");
1795 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
1798 sub process_all_localmoduletables
(){
1800 foreach $key (keys %ModuleSynopses) {
1801 my $st = $ModuleSynopses{$key};
1802 my $file = $st->get_file();
1804 process_localmoduletables_in_file
($file);
1807 print "\nsynopsis table $key has no file association\n";
1812 sub process_localmoduletables_in_file
($){
1814 open(MYFILE
, "<$file");
1816 sysread(MYFILE
, $_, 1024*1024);
1818 # need to get contents of file in $_
1819 while (/<tex2html-localmoduletable><(\d+)>/) {
1822 my $st = get_synopsis_table
($chap);
1823 my $data = $st->tohtml();
1826 open(MYFILE
,">$file");
1830 sub process_python_state
(){
1831 process_all_localmoduletables
();
1832 process_grammar_files
();
1837 # "See also:" -- references placed at the end of a \section
1841 return ("<div class=\"seealso\">\n "
1842 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1847 sub do_env_seealsostar
{
1848 return ("<div class=\"seealso-simple\">\n "
1853 sub do_cmd_seemodule
{
1854 # Insert the right magic to jump to the module definition. This should
1855 # work most of the time, at least for repeat builds....
1857 my $key = next_optional_argument
();
1858 my $module = next_argument
();
1859 my $text = next_argument
();
1863 if ($text =~ /\.$/) {
1866 return ('<dl compact class="seemodule">'
1867 . "\n <dt>Module <b><tt class=\"module\">"
1868 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1869 . "\n <dd>$text$period\n </dl>"
1873 sub strip_html_markup
($){
1876 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1877 $s =~ s/<\/[a-zA-Z0-9]+>//g
;
1881 sub handle_rfclike_reference
($$$){
1882 local($_, $what, $format) = @_;
1883 my $rfcnum = next_argument
();
1884 my $title = next_argument
();
1885 my $text = next_argument
();
1886 my $url = get_rfc_url
($rfcnum, $format);
1887 my $icon = get_link_icon
($url);
1888 my $attrtitle = strip_html_markup
($title);
1889 return '<dl compact class="seerfc">'
1890 . "\n <dt><a href=\"$url\""
1891 . "\n title=\"$attrtitle\""
1892 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
1893 . "\n <dd>$text\n </dl>"
1898 return handle_rfclike_reference
($_[0], "PEP", $PEP_FORMAT);
1902 # XXX Would be nice to add links to the text/plain and PDF versions.
1903 return handle_rfclike_reference
($_[0], "RFC", $RFC_FORMAT);
1906 sub do_cmd_seetitle
{
1908 my $url = next_optional_argument
();
1909 my $title = next_argument
();
1910 my $text = next_argument
();
1912 my $icon = get_link_icon
($url);
1913 return '<dl compact class="seetitle">'
1914 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
1915 . "\n >$title$icon</a></em>"
1916 . "\n <dd>$text\n </dl>"
1919 return '<dl compact class="seetitle">'
1920 . "\n <dt><em class=\"citetitle\""
1922 . "\n <dd>$text\n </dl>"
1928 my $url = next_argument
();
1929 my $linktext = next_argument
();
1930 my $text = next_argument
();
1931 my $icon = get_link_icon
($url);
1932 return '<dl compact class="seeurl">'
1933 . "\n <dt><a href='$url'"
1934 . "\n >$linktext$icon</a></dt>"
1935 . "\n <dd>$text</dd>\n </dl>"
1941 my $url = next_argument
();
1942 my $text = next_argument
();
1943 my $icon = get_link_icon
($url);
1944 return '<dl compact class="seeurl">'
1945 . "\n <dt><a href=\"$url\""
1946 . "\n class=\"url\">$url$icon</a>"
1947 . "\n <dd>$text\n </dl>"
1953 my $content = next_argument
();
1954 return '<div class="seetext"><p>' . $content . '</div>' . $_;
1959 # Definition list support.
1962 sub do_env_definitions
{
1963 return "<dl class=\"definitions\">" . $_[0] . "</dl>\n";
1968 my $term = next_argument
();
1969 my($name, $aname, $ahref) = new_link_info
();
1970 # could easily add an index entry here...
1971 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
1975 # Commands listed here have process-order dependencies; these often
1976 # are related to indexing operations.
1977 # XXX Not sure why funclineni, methodlineni, and samp are here.
1979 process_commands_wrap_deferred
(<<_RAW_ARG_DEFERRED_CMDS_
);
1980 declaremodule
# [] # {} # {}
1982 funclineni
# {} # {}
1983 memberline
# [] # {}
1984 methodline
# [] # {} # {}
1985 methodlineni
# [] # {} # {}
1990 indexiii
# {} # {} # {}
1991 indexiv
# {} # {} # {} # {}
1998 setindexsubitem
# {}
1999 withsubitem
# {} # {}
2000 _RAW_ARG_DEFERRED_CMDS_
2003 $alltt_start = '<div class="verbatim"><pre>';
2004 $alltt_end = '</pre></div>';
2008 local($closures,$reopens,@open_block_tags);
2010 # get the tag-strings for all open tags
2011 local(@keep_open_tags) = @
$open_tags_R;
2012 ($closures,$reopens) = &preserve_open_tags
() if (@
$open_tags_R);
2014 # get the tags for text-level tags only
2015 $open_tags_R = [ @keep_open_tags ];
2016 local($local_closures, $local_reopens);
2017 ($local_closures, $local_reopens,@open_block_tags)
2018 = &preserve_open_block_tags
2021 $open_tags_R = [ @open_block_tags ];
2024 local($open_tags_R) = [ @open_block_tags ];
2025 local(@save_open_tags) = ();
2027 local($cnt) = ++$global{'max_id'};
2028 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2029 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
2031 $_ = &translate_environments
($_);
2032 $_ = &translate_commands
($_) if (/\\/);
2034 # preserve space-runs, using
2035 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
2036 s/(<BR>) /$1;SPMnbsp;/g;
2038 $_ = join('', $closures, $alltt_start, $local_reopens
2040 , &balance_tags
() #, $local_closures
2041 , $alltt_end, $reopens);
2042 undef $open_tags_R; undef @save_open_tags;
2044 $open_tags_R = [ @keep_open_tags ];
2045 return codetext
($_);
2048 # List of all filenames produced by do_cmd_verbatiminput()
2049 %VerbatimFiles = ();
2050 @VerbatimOutputs = ();
2052 sub get_verbatim_output_name
($){
2055 # Re-write the source filename to always use a .txt extension
2056 # so that Web servers will present it as text/plain. This is
2057 # needed since there is no other even moderately reliable way
2058 # to get the right Content-Type header on text files for
2059 # servers which we can't configure (like python.org mirrors).
2061 if (defined $VerbatimFiles{$file}) {
2062 # We've seen this one before; re-use the same output file.
2063 return $VerbatimFiles{$file};
2065 my($srcname, $srcdir, $srcext) = fileparse
($file, '\..*');
2066 $filename = "$srcname.txt";
2068 # We need to determine if our default filename is already
2069 # being used, and find a new one it it is. If the name is in
2070 # used, this algorithm will first attempt to include the
2071 # source extension as part of the name, and if that is also in
2072 # use (if the same file is included multiple times, or if
2073 # another source file has that as the base name), a counter is
2079 foreach $fn (@VerbatimOutputs) {
2080 if ($fn eq $filename) {
2082 $srcext =~ s/^[.]//; # Remove '.' from extension
2083 $filename = "$srcname-$srcext.txt";
2086 $filename = "$srcname-$found.txt";
2094 push @VerbatimOutputs, $filename;
2095 $VerbatimFiles{$file} = $filename;
2099 sub do_cmd_verbatiminput
{
2101 my $fname = next_argument
();
2105 # Search TEXINPUTS for the input file, the way we're supposed to:
2106 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2107 $file = "$texpath$dd$fname";
2108 last if ($found = (-f
$file));
2113 open(MYFILE
, "<$file") || die "\n$!\n";
2114 read(MYFILE
, $text, 1024*1024);
2116 $filename = get_verbatim_output_name
($file);
2117 # Now that we have a filename, write it out.
2118 open(MYFILE
, ">$filename");
2122 # These rewrites convert the raw text to something that will
2123 # be properly visible as HTML and also will pass through the
2124 # vagaries of conversion through LaTeX2HTML. The order in
2125 # which the specific rewrites are performed is significant.
2127 $text =~ s/\&/\&/g;
2128 # These need to happen before the normal < and > re-writes,
2129 # since we need to avoid LaTeX2HTML's attempt to perform
2130 # ligature processing without regard to context (since it
2131 # doesn't have font information).
2132 $text =~ s/--/-&\#45;/g;
2133 $text =~ s/<</\<\&\#60;/g;
2134 $text =~ s/>>/\>\&\#62;/g;
2135 # Just normal re-writes...
2136 $text =~ s/</\</g;
2137 $text =~ s/>/\>/g;
2138 # These last isn't needed for the HTML, but is needed to get
2139 # past LaTeX2HTML processing TeX macros. We use \ instead
2140 # of / since many browsers don't support that.
2141 $text =~ s/\\/\&\#92;/g;
2144 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2146 my $note = 'Download as text.';
2147 if ($file ne $filename) {
2148 $note = ('Download as text (original file name: <span class="file">'
2152 return ("<div class=\"verbatim\">\n<pre>"
2154 . "</pre>\n<div class=\"footer\">\n"
2155 . "<a href=\"$filename\" type=\"text/plain\""
2161 1; # This must be the last line