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]; }
99 return use_wrappers
($_[0]. '<span class="guilabel">', '</span>'); }
100 sub do_cmd_menuselection
{
101 return use_wrappers
($_[0], '<span class="guilabel">', '</span>'); }
103 return '</span> > <span class="guilabel">' . $_[0]; }
106 # words typeset in a special way (not in HTML though)
108 sub do_cmd_ABC
{ 'ABC' . $_[0]; }
109 sub do_cmd_UNIX
{ '<span class="Unix">Unix</span>' . $_[0]; }
110 sub do_cmd_LaTeX
{ '<span class="LaTeX">LaTeX</span>' . $_[0]; }
111 sub do_cmd_TeX
{ '<span class="TeX">TeX</span>' . $_[0]; }
112 sub do_cmd_ASCII
{ 'ASCII' . $_[0]; }
113 sub do_cmd_POSIX
{ 'POSIX' . $_[0]; }
114 sub do_cmd_C
{ 'C' . $_[0]; }
115 sub do_cmd_Cpp
{ 'C++' . $_[0]; }
116 sub do_cmd_EOF
{ 'EOF' . $_[0]; }
117 sub do_cmd_NULL
{ '<tt class="constant">NULL</tt>' . $_[0]; }
119 sub do_cmd_e
{ '\' . $_[0]; }
121 $DEVELOPER_ADDRESS = '';
124 $PACKAGE_VERSION = '';
126 sub do_cmd_version
{ $PACKAGE_VERSION . $_[0]; }
127 sub do_cmd_shortversion
{ $SHORT_VERSION . $_[0]; }
130 $PACKAGE_VERSION = next_argument
();
134 sub do_cmd_setreleaseinfo
{
136 $RELEASE_INFO = next_argument
();
140 sub do_cmd_setshortversion
{
142 $SHORT_VERSION = next_argument
();
146 sub do_cmd_authoraddress
{
148 $DEVELOPER_ADDRESS = next_argument
();
152 sub do_cmd_hackscore
{
158 # Helper used in many places that arbitrary code-like text appears:
162 # Make sure that "---" is not converted to "--" later when
163 # LaTeX2HTML tries converting em-dashes based on the conventional
164 # TeX font ligatures:
165 $text =~ s/--/-\-/go;
169 sub use_wrappers
($$$){
170 local($_,$before,$after) = @_;
171 my $stuff = next_argument
();
172 return $before . $stuff . $after . $_;
175 sub use_code_wrappers
($$$){
176 local($_,$before,$after) = @_;
177 my $stuff = codetext
(next_argument
());
178 return $before . $stuff . $after . $_;
181 $IN_DESC_HANDLER = 0;
183 if ($IN_DESC_HANDLER) {
184 return use_wrappers
($_[0], "</var><big>\[</big><var>",
185 "</var><big>\]</big><var>");
188 return use_wrappers
($_[0], "<big>\[</big>", "<big>\]</big>");
192 # Logical formatting (some based on texinfo), needs to be converted to
193 # minimalist HTML. The "minimalist" is primarily to reduce the size of
194 # output files for users that read them over the network rather than
195 # from local repositories.
197 sub do_cmd_pytype
{ return $_[0]; }
199 return use_wrappers
($_[0], '<span class="makevar">', '</span>'); }
201 return use_code_wrappers
($_[0], '<code>', '</code>'); }
203 return use_wrappers
($_[0], '<tt class="module">', '</tt>'); }
205 return use_wrappers
($_[0], '<tt class="keyword">', '</tt>'); }
206 sub do_cmd_exception
{
207 return use_wrappers
($_[0], '<tt class="exception">', '</tt>'); }
209 return use_wrappers
($_[0], '<tt class="class">', '</tt>'); }
211 return use_wrappers
($_[0], '<tt class="function">', '</tt>'); }
213 return use_wrappers
($_[0], '<tt class="constant">', '</tt>'); }
215 return use_wrappers
($_[0], '<tt class="member">', '</tt>'); }
217 return use_wrappers
($_[0], '<tt class="method">', '</tt>'); }
218 sub do_cmd_cfunction
{
219 return use_wrappers
($_[0], '<tt class="cfunction">', '</tt>'); }
221 return use_wrappers
($_[0], '<tt class="cdata">', '</tt>'); }
223 return use_wrappers
($_[0], '<tt class="ctype">', '</tt>'); }
225 return use_code_wrappers
($_[0], '<tt class="regexp">', '</tt>'); }
226 sub do_cmd_character
{
227 return use_code_wrappers
($_[0], '"<tt class="character">', '</tt>"'); }
229 return use_wrappers
($_[0], '<b class="program">', '</b>'); }
230 sub do_cmd_programopt
{
231 return use_wrappers
($_[0], '<b class="programopt">', '</b>'); }
232 sub do_cmd_longprogramopt
{
233 # note that the --- will be later converted to -- by LaTeX2HTML
234 return use_wrappers
($_[0], '<b class="programopt">---', '</b>'); }
236 return use_wrappers
($_[0], '<span class="email">', '</span>'); }
237 sub do_cmd_mailheader
{
238 return use_wrappers
($_[0], '<span class="mailheader">', ':</span>'); }
240 return use_wrappers
($_[0], '<span class="mimetype">', '</span>'); }
242 return use_wrappers
($_[0], "<var>", "</var>"); }
244 return use_wrappers
($_[0], '<i class="dfn">', '</i>'); }
246 return use_wrappers
($_[0], '<em>', '</em>'); }
248 return use_wrappers
($_[0], '<span class="file">', '</span>'); }
250 return do_cmd_file
($_[0]); }
252 return use_code_wrappers
($_[0], '"<tt class="samp">', '</tt>"'); }
254 return use_wrappers
($_[0], '<kbd>', '</kbd>'); }
256 return use_wrappers
($_[0], '<strong>', '</strong>'); }
258 return use_wrappers
($_[0], '<b>', '</b>'); }
260 return use_wrappers
($_[0], '<i>', '</i>'); }
261 # This can be changed/overridden for translations:
262 %NoticeNames = ('note' => 'Note:',
263 'warning' => 'Warning:',
267 my $label = $NoticeNames{'note'};
270 "<span class=\"note\"><b class=\"label\">$label</b>\n",
273 my $label = $NoticeNames{'warning'};
276 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
281 my $notice = next_optional_argument
();
285 my $label = $NoticeNames{$notice};
286 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
292 return '...' . $_[0]; }
293 sub do_cmd_unspecified
{
294 return '...' . $_[0]; }
297 sub do_cmd_refmodule
{
298 # Insert the right magic to jump to the module definition.
300 my $key = next_optional_argument
();
301 my $module = next_argument
();
304 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
308 sub do_cmd_newsgroup
{
310 my $newsgroup = next_argument
();
311 my $icon = get_link_icon
("news:$newsgroup");
312 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
313 . "$newsgroup$icon</a>");
319 my $envvar = next_argument
();
320 my($name, $aname, $ahref) = new_link_info
();
321 # The <tt> here is really to keep buildindex.py from making
322 # the variable name case-insensitive.
323 add_index_entry
("environment variables!$envvar@<tt>$envvar</tt>",
325 add_index_entry
("$envvar (environment variable)", $ahref);
326 $aname =~ s/<a/<a class="envvar"/;
327 return "$aname$envvar</a>" . $_;
331 # use the URL as both text and hyperlink
333 my $url = next_argument
();
334 my $icon = get_link_icon
($url);
335 $url =~ s/~/~/g;
336 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
340 # two parameters: \manpage{name}{section}
342 my $page = next_argument
();
343 my $section = next_argument
();
344 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
347 $PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
348 #$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
349 $RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
352 my($rfcnum, $format) = @_;
353 return sprintf($format, $rfcnum);
358 my $rfcnumber = next_argument
();
359 my $id = "rfcref-" . ++$global{'max_id'};
360 my $href = get_rfc_url
($rfcnumber, $PEP_FORMAT);
361 my $icon = get_link_icon
($href);
363 my $nstr = gen_index_id
("Python Enhancement Proposals!PEP $rfcnumber", '');
364 $index{$nstr} .= make_half_href
("$CURRENT_FILE#$id");
365 return ("<a class=\"rfc\" id='$id' xml:id='$id'\n"
366 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
371 my $rfcnumber = next_argument
();
372 my $id = "rfcref-" . ++$global{'max_id'};
373 my $href = get_rfc_url
($rfcnumber, $RFC_FORMAT);
374 my $icon = get_link_icon
($href);
376 my $nstr = gen_index_id
("RFC!RFC $rfcnumber", '');
377 $index{$nstr} .= make_half_href
("$CURRENT_FILE#$id");
378 return ("<a class=\"rfc\" id='$id' xml:id='$id'\nhref=\"$href\">"
379 . "RFC $rfcnumber$icon</a>" . $_);
384 my $text = next_argument
();
385 my $url = next_argument
();
386 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
389 sub do_cmd_citetitle
{
391 my $url = next_optional_argument
();
392 my $title = next_argument
();
393 my $icon = get_link_icon
($url);
396 my $titletext = strip_html_markup
("$title");
397 $repl = ("<em class=\"citetitle\"><a\n"
399 . " title=\"$titletext\"\n"
400 . " >$title$icon</a></em>");
403 $repl = "<em class=\"citetitle\"\n >$title</em>";
408 sub do_cmd_deprecated
{
409 # two parameters: \deprecated{version}{whattodo}
411 my $release = next_argument
();
412 my $reason = next_argument
();
413 return ('<div class="versionnote">'
414 . "<b>Deprecated since release $release.</b>"
415 . "\n$reason</div><p></p>"
420 # one or two parameters: \versionnote[explanation]{version}
423 my $explanation = next_optional_argument
();
424 my $release = next_argument
();
425 my $text = "$type in version $release.";
427 $text = "$type in version $release:\n$explanation.";
429 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
432 sub do_cmd_versionadded
{
433 return versionnote
('New', $_[0]);
436 sub do_cmd_versionchanged
{
437 return versionnote
('Changed', $_[0]);
441 # These function handle platform dependency tracking.
445 my $platform = next_argument
();
446 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
447 $platform = "Macintosh"
448 if $platform eq 'Mac';
449 return "\n<p class=\"availability\">Availability: <span"
450 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
453 $IGNORE_PLATFORM_ANNOTATION = '';
454 sub do_cmd_ignorePlatformAnnotation
{
456 $IGNORE_PLATFORM_ANNOTATION = next_argument
();
465 sub get_indexsubitem
(){
466 return $INDEX_SUBITEM ?
" $INDEX_SUBITEM" : '';
469 sub do_cmd_setindexsubitem
{
471 $INDEX_SUBITEM = next_argument
();
475 sub do_cmd_withsubitem
{
476 # We can't really do the right thing, because LaTeX2HTML doesn't
477 # do things in the right order, but we need to at least strip this stuff
478 # out, and leave anything that the second argument expanded out to.
481 my $oldsubitem = $INDEX_SUBITEM;
482 $INDEX_SUBITEM = next_argument
();
483 my $stuff = next_argument
();
484 my $br_id = ++$globals{'max_id'};
485 my $marker = "$O$br_id$C";
489 . "\\setindexsubitem$marker$oldsubitem$marker"
493 # This is the prologue macro which is required to start writing the
494 # mod\jobname.idx file; we can just ignore it. (Defining this suppresses
495 # a warning that \makemodindex is unknown.)
497 sub do_cmd_makemodindex
{ return $_[0]; }
499 # We're in the document subdirectory when this happens!
501 open(IDXFILE
, '>index.dat') || die "\n$!\n";
502 open(INTLABELS
, '>intlabels.pl') || die "\n$!\n";
503 print INTLABELS
"%internal_labels = ();\n";
504 print INTLABELS
"1; # hack in case there are no entries\n\n";
506 # Using \0 for this is bad because we can't use common tools to work with the
507 # resulting files. Things like grep can be useful with this stuff!
509 $IDXFILE_FIELD_SEP = "\1";
511 sub write_idxfile
($$){
512 my($ahref, $str) = @_;
513 print IDXFILE
$ahref, $IDXFILE_FIELD_SEP, $str, "\n";
518 my($node, $target) = @_;
519 print INTLABELS
"\$internal_labels{\"$target\"} = \"/$node\";\n";
520 return "<a href=\"$node#$target\">";
523 sub add_index_entry
($$){
524 # add an entry to the index structures; ignore the return value
525 my($str, $ahref) = @_;
526 $str = gen_index_id
($str, '');
527 $index{$str} .= $ahref;
528 write_idxfile
($ahref, $str);
531 sub new_link_name_info
(){
532 my $name = "l2h-" . ++$globals{'max_id'};
533 my $ahref = gen_link
($CURRENT_FILE, $name);
534 return ($name, $ahref);
538 my($name, $ahref) = new_link_name_info
();
539 my $aname = "<a id='$name' xml:id='$name'>";
540 return ($name, $aname, $ahref);
543 $IndexMacroPattern = '';
544 sub define_indexing_macro
(@
){
547 for (; $i < $count; ++$i) {
549 my $cmd = "idx_cmd_$name";
550 die "\nNo function $cmd() defined!\n"
552 eval ("sub do_cmd_$name { return process_index_macros("
553 . "\$_[0], '$name'); }");
554 if (length($IndexMacroPattern) == 0) {
555 $IndexMacroPattern = "$name";
558 $IndexMacroPattern .= "|$name";
564 sub process_index_macros
($$){
566 my $cmdname = $_[1]; # This is what triggered us in the first place;
567 # we know it's real, so just process it.
568 my($name, $aname, $ahref) = new_link_info
();
569 my $cmd = "idx_cmd_$cmdname";
570 print "\nIndexing: \\$cmdname"
572 &$cmd($ahref); # modifies $_ and adds index entries
573 while (/^[\s\n]*\\($IndexMacroPattern)</) {
577 $cmd = "idx_cmd_$cmdname";
578 if (!defined &$cmd) {
582 s/^[\s\n]*\\$cmdname//;
586 # XXX I don't remember why I added this to begin with.
587 # if (/^[ \t\r\n]/) {
588 # $_ = substr($_, 1);
590 return "$aname$anchor_invisible_mark</a>" . $_;
593 define_indexing_macro
('index');
594 sub idx_cmd_index
($){
595 my $str = next_argument
();
596 add_index_entry
("$str", $_[0]);
599 define_indexing_macro
('kwindex');
600 sub idx_cmd_kwindex
($){
601 my $str = next_argument
();
602 add_index_entry
("<tt>$str</tt>!keyword", $_[0]);
603 add_index_entry
("keyword!<tt>$str</tt>", $_[0]);
606 define_indexing_macro
('indexii');
607 sub idx_cmd_indexii
($){
608 my $str1 = next_argument
();
609 my $str2 = next_argument
();
610 add_index_entry
("$str1!$str2", $_[0]);
611 add_index_entry
("$str2!$str1", $_[0]);
614 define_indexing_macro
('indexiii');
615 sub idx_cmd_indexiii
($){
616 my $str1 = next_argument
();
617 my $str2 = next_argument
();
618 my $str3 = next_argument
();
619 add_index_entry
("$str1!$str2 $str3", $_[0]);
620 add_index_entry
("$str2!$str3, $str1", $_[0]);
621 add_index_entry
("$str3!$str1 $str2", $_[0]);
624 define_indexing_macro
('indexiv');
625 sub idx_cmd_indexiv
($){
626 my $str1 = next_argument
();
627 my $str2 = next_argument
();
628 my $str3 = next_argument
();
629 my $str4 = next_argument
();
630 add_index_entry
("$str1!$str2 $str3 $str4", $_[0]);
631 add_index_entry
("$str2!$str3 $str4, $str1", $_[0]);
632 add_index_entry
("$str3!$str4, $str1 $str2", $_[0]);
633 add_index_entry
("$str4!$str1 $str2 $str3", $_[0]);
636 define_indexing_macro
('ttindex');
637 sub idx_cmd_ttindex
($){
638 my $str = codetext
(next_argument
());
639 my $entry = $str . get_indexsubitem
();
640 add_index_entry
($entry, $_[0]);
643 sub my_typed_index_helper
($$){
644 my($word, $ahref) = @_;
645 my $str = next_argument
();
646 add_index_entry
("$str $word", $ahref);
647 add_index_entry
("$word!$str", $ahref);
650 define_indexing_macro
('stindex', 'opindex', 'exindex', 'obindex');
651 sub idx_cmd_stindex
($){ my_typed_index_helper
('statement', $_[0]); }
652 sub idx_cmd_opindex
($){ my_typed_index_helper
('operator', $_[0]); }
653 sub idx_cmd_exindex
($){ my_typed_index_helper
('exception', $_[0]); }
654 sub idx_cmd_obindex
($){ my_typed_index_helper
('object', $_[0]); }
656 define_indexing_macro
('bifuncindex');
657 sub idx_cmd_bifuncindex
($){
658 my $str = next_argument
();
659 add_index_entry
("<tt class=\"function\">$str()</tt> (built-in function)",
664 sub make_mod_index_entry
($$){
665 my($str, $define) = @_;
666 my($name, $aname, $ahref) = new_link_info
();
667 # equivalent of add_index_entry() using $define instead of ''
668 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
669 if ($define eq 'DEF');
670 $str = gen_index_id
($str, $define);
671 $index{$str} .= $ahref;
672 write_idxfile
($ahref, $str);
674 if ($define eq 'DEF') {
675 # add to the module index
676 $str =~ /(<tt.*<\/tt
>)/;
678 $Modules{$nstr} .= $ahref;
680 return "$aname$anchor_invisible_mark2</a>";
687 sub define_module
($$){
688 my($word, $name) = @_;
689 my $section_tag = join('', @curr_sec_id);
690 if ($word ne "built-in" && $word ne "extension"
691 && $word ne "standard" && $word ne "") {
692 write_warnings
("Bad module type '$word'"
693 . " for \\declaremodule (module $name)");
696 $word = "$word " if $word;
697 $THIS_MODULE = "$name";
698 $INDEX_SUBITEM = "(in module $name)";
700 return make_mod_index_entry
(
701 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
704 sub my_module_index_helper
($$){
705 local($word, $_) = @_;
706 my $name = next_argument
();
707 return define_module
($word, $name) . $_;
710 sub do_cmd_modindex
{ return my_module_index_helper
('', $_[0]); }
711 sub do_cmd_bimodindex
{ return my_module_index_helper
('built-in', $_[0]); }
712 sub do_cmd_exmodindex
{ return my_module_index_helper
('extension', $_[0]); }
713 sub do_cmd_stmodindex
{ return my_module_index_helper
('standard', $_[0]); }
715 # my $name = next_argument();
716 # return define_module('standard', $name) . $_;
719 sub ref_module_index_helper
($$){
720 my($word, $ahref) = @_;
721 my $str = next_argument
();
722 $word = "$word " if $word;
723 $str = "<tt class=\"module\">$str</tt> (${word}module)";
724 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
725 # just inline it all here
726 $str = gen_index_id
($str, 'REF');
727 $index{$str} .= $ahref;
728 write_idxfile
($ahref, $str);
731 # these should be adjusted a bit....
732 define_indexing_macro
('refmodindex', 'refbimodindex',
733 'refexmodindex', 'refstmodindex');
734 sub idx_cmd_refmodindex
($){
735 return ref_module_index_helper
('', $_[0]); }
736 sub idx_cmd_refbimodindex
($){
737 return ref_module_index_helper
('built-in', $_[0]); }
738 sub idx_cmd_refexmodindex
($){
739 return ref_module_index_helper
('extension', $_[0]);}
740 sub idx_cmd_refstmodindex
($){
741 return ref_module_index_helper
('standard', $_[0]); }
743 sub do_cmd_nodename
{ return do_cmd_label
($_[0]); }
746 # This depends on the override of text_cleanup() in l2hinit.perl;
747 # if that function cleans out empty tags, the first three of these
748 # variables must be set to comments.
750 # Thanks to Dave Kuhlman for figuring why some named anchors were
752 $anchor_invisible_mark = '';
753 $anchor_invisible_mark2 = '';
755 $icons{'anchor_mark'} = '';
759 # Create an index entry, but include the string in the target anchor
760 # instead of the dummy filler.
762 sub make_str_index_entry
($){
764 my($name, $ahref) = new_link_name_info
();
765 add_index_entry
($str, $ahref);
766 if ($str =~ /^<[a-z]+\b/) {
768 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
772 return "<a id='$name' xml:id='$name'>$str</a>";
777 %TokenToTargetMapping = (); # language:token -> link target
778 %DefinedGrammars = (); # language -> full grammar text
779 %BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
783 my $token = next_argument
();
784 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
785 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
786 # recursive definition or display-only productionlist
790 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
791 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
792 print "Adding '$CURRENT_FILE' to back-patch list.\n";
794 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
796 return "<a class='grammartoken' href=\"$target\">$token</a>" . $_;
799 sub do_cmd_grammartoken
{
800 return do_cmd_token
(@_);
803 sub do_env_productionlist
{
805 my $lang = next_optional_argument
();
806 my $filename = "grammar-$lang.txt";
808 $filename = 'grammar.txt';
810 local($CURRENT_GRAMMAR) = $lang;
811 $DefinedGrammars{$lang} .= $_;
812 return ("<dl><dd class=\"grammar\">\n"
813 . "<div class=\"productions\">\n"
815 . translate_commands
(translate_environments
($_))
820 : ("<a class=\"grammar-footer\"\n"
821 . " href=\"$filename\" type=\"text/plain\"\n"
822 . " >Download entire grammar as text.</a>\n"))
826 sub do_cmd_production
{
828 my $token = next_argument
();
829 my $defn = next_argument
();
830 my $lang = $CURRENT_GRAMMAR;
831 local($CURRENT_TOKEN) = $token;
834 . " <td>$token</td>\n"
837 . translate_commands
($defn)
843 $target = "$CURRENT_FILE\#tok-$token";
846 $target = "$CURRENT_FILE\#tok-$lang-$token";
848 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
850 . " <td><a id='tok-$token' xml:id='tok-$token'>"
851 . "$token</a></td>\n"
854 . translate_commands
($defn)
859 sub do_cmd_productioncont
{
861 my $defn = next_argument
();
862 $defn =~ s/^( +)/' ' x length $1/e;
867 . translate_commands
($defn)
868 . "</code></td></tr>"
872 sub process_grammar_files
(){
876 print "process_grammar_files()\n";
877 foreach $lang (keys %DefinedGrammars) {
878 $filename = "grammar-$lang.txt";
883 $filename = 'grammar.txt';
885 open(GRAMMAR
, ">$filename") || die "\n$!\n";
886 print GRAMMAR strip_grammar_markup
($DefinedGrammars{$lang});
888 print "Wrote grammar file $filename\n";
890 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
891 foreach $filename (keys %BackpatchGrammarFiles) {
892 print "\nBack-patching grammar links in $filename\n";
894 open(GRAMMAR
, "<$filename") || die "\n$!\n";
895 # read all of the file into the buffer
896 sysread(GRAMMAR
, $buffer, 1024*1024);
898 while ($buffer =~ /$PATTERN/) {
899 my($lang, $token) = ($1, $2);
900 my $target = $TokenToTargetMapping{"$lang:$token"};
901 my $source = "<pyGrammarToken><$lang><$token>";
902 $buffer =~ s/$source/$target/g;
904 open(GRAMMAR
, ">$filename") || die "\n$!\n";
905 print GRAMMAR
$buffer;
910 sub strip_grammar_markup
($){
912 s/\\productioncont/ /g;
913 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
914 s/\\token(<<\d+>>)(.+)\1/$2/g;
915 s/\\e([^a-zA-Z])/\\$1/g;
924 $REFCOUNTS_LOADED = 0;
926 sub load_refcounts
(){
927 $REFCOUNTS_LOADED = 1;
929 my($myname, $mydir, $myext) = fileparse
(__FILE__
, '\..*');
930 chop $mydir; # remove trailing '/'
931 ($myname, $mydir, $myext) = fileparse
($mydir, '\..*');
932 chop $mydir; # remove trailing '/'
933 $mydir = getcwd
() . "$dd$mydir"
934 unless $mydir =~ s
|^/|/|;
936 my $filename = "$mydir${dd}api${dd}refcounts.dat";
937 open(REFCOUNT_FILE
, "<$filename") || die "\n$!\n";
938 print "[loading API refcount data]";
939 while (<REFCOUNT_FILE
>) {
940 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
941 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
942 #print "\n$func($param) --> $count";
943 $REFCOUNTS{"$func:$param"} = $count;
948 sub get_refcount
($$){
949 my($func, $param) = @_;
951 unless $REFCOUNTS_LOADED;
952 return $REFCOUNTS{"$func:$param"};
956 $TLSTART = '<span class="typelabel">';
957 $TLEND = '</span> ';
959 sub cfuncline_helper
($$$){
960 my($type, $name, $args) = @_;
961 my $idx = make_str_index_entry
(
962 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem
());
964 $idx =~ s/\(\)//; # ???? - why both of these?
965 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var
>,/g
;
966 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var
>/s
;
967 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
968 . "<td><nobr>$type\ <b>$idx</b>(</nobr></td>"
972 sub do_cmd_cfuncline
{
974 my $type = next_argument
();
975 my $name = next_argument
();
976 my $args = next_argument
();
977 my $siginfo = cfuncline_helper
($type, $name, $args);
978 return "<dt>$siginfo\n<dd>" . $_;
980 sub do_env_cfuncdesc
{
982 my $type = next_argument
();
983 my $name = next_argument
();
984 my $args = next_argument
();
985 my $siginfo = cfuncline_helper
($type, $name, $args);
986 my $result_rc = get_refcount
($name, '');
988 if ($result_rc eq '+1') {
989 $rcinfo = 'New reference';
991 elsif ($result_rc eq '0') {
992 $rcinfo = 'Borrowed reference';
994 elsif ($result_rc eq 'null') {
995 $rcinfo = 'Always <tt class="constant">NULL</tt>';
998 $rcinfo = ( "\n<div class=\"refcount-info\">"
999 . "\n <span class=\"label\">Return value:</span>"
1000 . "\n <span class=\"value\">$rcinfo.</span>"
1003 return "<dl><dt>$siginfo</dt>\n<dd>"
1009 sub do_cmd_cmemberline
{
1011 my $container = next_argument
();
1012 my $type = next_argument
();
1013 my $name = next_argument
();
1014 my $idx = make_str_index_entry
("<tt class=\"cmember\">$name</tt>"
1015 . " ($container member)");
1016 $idx =~ s/ \(.*\)//;
1017 return "<dt>$type <b>$idx</b></dt>\n<dd>"
1020 sub do_env_cmemberdesc
{
1022 my $container = next_argument
();
1023 my $type = next_argument
();
1024 my $name = next_argument
();
1025 my $idx = make_str_index_entry
("<tt class=\"cmember\">$name</tt>"
1026 . " ($container member)");
1027 $idx =~ s/ \(.*\)//;
1028 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
1033 sub do_env_csimplemacrodesc
{
1035 my $name = next_argument
();
1036 my $idx = make_str_index_entry
("<tt class=\"macro\">$name</tt>");
1037 return "<dl><dt><b>$idx</b></dt>\n<dd>"
1042 sub do_env_ctypedesc
{
1044 my $index_name = next_optional_argument
();
1045 my $type_name = next_argument
();
1046 $index_name = $type_name
1048 my($name, $aname, $ahref) = new_link_info
();
1049 add_index_entry
("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1050 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1056 sub do_env_cvardesc
{
1058 my $var_type = next_argument
();
1059 my $var_name = next_argument
();
1060 my $idx = make_str_index_entry
("<tt class=\"cdata\">$var_name</tt>"
1061 . get_indexsubitem
());
1062 $idx =~ s/ \(.*\)//;
1063 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
1069 sub convert_args
($){
1070 local($IN_DESC_HANDLER) = 1;
1072 return translate_commands
($_);
1075 sub funcline_helper
($$$){
1076 my($first, $idxitem, $arglist) = @_;
1077 return (($first ?
'<dl>' : '')
1078 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1079 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1080 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
1083 sub do_env_funcdesc
{
1085 my $function_name = next_argument
();
1086 my $arg_list = convert_args
(next_argument
());
1087 my $idx = make_str_index_entry
("<tt class=\"function\">$function_name()"
1089 . get_indexsubitem
());
1090 $idx =~ s/ \(.*\)//;
1091 $idx =~ s/\(\)<\/tt>/<\
/tt>/;
1092 return funcline_helper
(1, $idx, $arg_list) . $_ . '</dl>';
1095 sub do_env_funcdescni
{
1097 my $function_name = next_argument
();
1098 my $arg_list = convert_args
(next_argument
());
1099 my $prefix = "<tt class=\"function\">$function_name</tt>";
1100 return funcline_helper
(1, $prefix, $arg_list) . $_ . '</dl>';
1103 sub do_cmd_funcline
{
1105 my $function_name = next_argument
();
1106 my $arg_list = convert_args
(next_argument
());
1107 my $prefix = "<tt class=\"function\">$function_name()</tt>";
1108 my $idx = make_str_index_entry
($prefix . get_indexsubitem
());
1109 $prefix =~ s/\(\)//;
1111 return funcline_helper
(0, $prefix, $arg_list) . $_;
1114 sub do_cmd_funclineni
{
1116 my $function_name = next_argument
();
1117 my $arg_list = convert_args
(next_argument
());
1118 my $prefix = "<tt class=\"function\">$function_name</tt>";
1120 return funcline_helper
(0, $prefix, $arg_list) . $_;
1123 # Change this flag to index the opcode entries. I don't think it's very
1124 # useful to index them, since they're only presented to describe the dis
1129 sub do_env_opcodedesc
{
1131 my $opcode_name = next_argument
();
1132 my $arg_list = next_argument
();
1134 if ($INDEX_OPCODES) {
1135 $idx = make_str_index_entry
("<tt class=\"opcode\">$opcode_name</tt>"
1136 . ' (byte code instruction)');
1137 $idx =~ s/ \(byte code instruction\)//;
1140 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
1142 my $stuff = "<dl><dt><b>$idx</b>";
1144 $stuff .= " <var>$arg_list</var>";
1146 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
1149 sub do_env_datadesc
{
1151 my $dataname = next_argument
();
1152 my $idx = make_str_index_entry
("<tt>$dataname</tt>" . get_indexsubitem
());
1153 $idx =~ s/ \(.*\)//;
1154 return "<dl><dt><b>$idx</b></dt>\n<dd>"
1159 sub do_env_datadescni
{
1161 my $idx = next_argument
();
1162 if (! $STRING_INDEX_TT) {
1163 $idx = "<tt>$idx</tt>";
1165 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
1168 sub do_cmd_dataline
{
1170 my $data_name = next_argument
();
1171 my $idx = make_str_index_entry
("<tt>$data_name</tt>" . get_indexsubitem
());
1172 $idx =~ s/ \(.*\)//;
1173 return "<dt><b>$idx</b></dt><dd>" . $_;
1176 sub do_cmd_datalineni
{
1178 my $data_name = next_argument
();
1179 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
1184 my $excname = next_argument
();
1185 my $idx = make_str_index_entry
("<tt class=\"exception\">$excname</tt>");
1186 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
1192 sub do_env_fulllineitems
{ return do_env_itemize
(@_); }
1195 sub handle_classlike_descriptor
($$){
1196 local($_, $what) = @_;
1197 $THIS_CLASS = next_argument
();
1198 my $arg_list = convert_args
(next_argument
());
1199 $idx = make_str_index_entry
(
1200 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
1201 $idx =~ s/ \(.*\)//;
1202 my $prefix = "$TLSTART$what$TLEND$idx";
1203 return funcline_helper
(1, $prefix, $arg_list) . $_ . '</dl>';
1206 sub do_env_classdesc
{
1207 return handle_classlike_descriptor
($_[0], "class");
1210 sub do_env_classdescstar
{
1212 $THIS_CLASS = next_argument
();
1213 $idx = make_str_index_entry
(
1214 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
1215 $idx =~ s/ \(.*\)//;
1216 my $prefix = "${TLSTART}class$TLEND$idx";
1217 # Can't use funcline_helper() since there is no args list.
1218 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
1221 sub do_env_excclassdesc
{
1222 return handle_classlike_descriptor
($_[0], "exception");
1226 sub do_env_methoddesc
{
1228 my $class_name = next_optional_argument
();
1229 $class_name = $THIS_CLASS
1231 my $method = next_argument
();
1232 my $arg_list = convert_args
(next_argument
());
1235 $extra = " ($class_name method)";
1237 my $idx = make_str_index_entry
(
1238 "<tt class=\"method\">$method()</tt>$extra");
1239 $idx =~ s/ \(.*\)//;
1241 return funcline_helper
(1, $idx, $arg_list) . $_ . '</dl>';
1245 sub do_cmd_methodline
{
1247 my $class_name = next_optional_argument
();
1248 $class_name = $THIS_CLASS
1250 my $method = next_argument
();
1251 my $arg_list = convert_args
(next_argument
());
1254 $extra = " ($class_name method)";
1256 my $idx = make_str_index_entry
(
1257 "<tt class=\"method\">$method()</tt>$extra");
1258 $idx =~ s/ \(.*\)//;
1260 return funcline_helper
(0, $idx, $arg_list) . $_;
1264 sub do_cmd_methodlineni
{
1266 next_optional_argument
();
1267 my $method = next_argument
();
1268 my $arg_list = convert_args
(next_argument
());
1269 return funcline_helper
(0, $method, $arg_list) . $_;
1272 sub do_env_methoddescni
{
1274 next_optional_argument
();
1275 my $method = next_argument
();
1276 my $arg_list = convert_args
(next_argument
());
1277 return funcline_helper
(1, $method, $arg_list) . $_ . '</dl>';
1281 sub do_env_memberdesc
{
1283 my $class = next_optional_argument
();
1284 my $member = next_argument
();
1285 $class = $THIS_CLASS
1288 $extra = " ($class attribute)"
1290 my $idx = make_str_index_entry
("<tt class=\"member\">$member</tt>$extra");
1291 $idx =~ s/ \(.*\)//;
1293 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
1297 sub do_cmd_memberline
{
1299 my $class = next_optional_argument
();
1300 my $member = next_argument
();
1301 $class = $THIS_CLASS
1304 $extra = " ($class attribute)"
1306 my $idx = make_str_index_entry
("<tt class=\"member\">$member</tt>$extra");
1307 $idx =~ s/ \(.*\)//;
1309 return "<dt><b>$idx</b></dt><dd>" . $_;
1313 sub do_env_memberdescni
{
1315 next_optional_argument
();
1316 my $member = next_argument
();
1317 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
1323 sub do_cmd_memberlineni
{
1325 next_optional_argument
();
1326 my $member = next_argument
();
1327 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
1331 # For tables, we include a class on every cell to allow the CSS to set
1332 # the text-align property; this is because support for styling columns
1333 # via the <col> element appears nearly non-existant on even the latest
1334 # browsers (Mozilla 1.7 is stable at the time of this writing).
1335 # Hopefully this can be improved as browsers evolve.
1337 @col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
1339 %FontConversions = ('cdata' => 'tt class="cdata"',
1340 'character' => 'tt class="character"',
1341 'class' => 'tt class="class"',
1342 'command' => 'code',
1343 'constant' => 'tt class="constant"',
1344 'exception' => 'tt class="exception"',
1345 'file' => 'tt class="file"',
1346 'filenq' => 'tt class="file"',
1348 'member' => 'tt class="member"',
1349 'programopt' => 'b',
1354 # do a little magic on a font name to get the right behavior in the first
1355 # column of the output table
1357 if (defined $FontConversions{$font}) {
1358 $font = $FontConversions{$font};
1363 sub figure_column_alignment
($){
1368 my $mark = substr($a, 0, 1);
1371 { $r = ' class="center"'; }
1372 elsif ($mark eq 'r')
1373 { $r = ' class="right" '; }
1374 elsif ($mark eq 'l')
1375 { $r = ' class="left" '; }
1376 elsif ($mark eq 'p')
1377 { $r = ' class="left" '; }
1381 sub setup_column_alignments
($){
1383 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
1384 my $a1 = figure_column_alignment
($s1);
1385 my $a2 = figure_column_alignment
($s2);
1386 my $a3 = figure_column_alignment
($s3);
1387 my $a4 = figure_column_alignment
($s4);
1388 my $a5 = figure_column_alignment
($s5);
1389 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1390 $col_aligns[1] = "<td$a2>";
1391 $col_aligns[2] = "<td$a3>";
1392 $col_aligns[3] = "<td$a4>";
1393 $col_aligns[4] = "<td$a5>";
1394 # return the aligned header start tags
1395 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
1398 sub get_table_col1_fonts
(){
1399 my $font = $globals{'lineifont'};
1400 my($sfont, $efont) = ('', '');
1403 $efont = "</$font>";
1404 $efont =~ s/ .*>/>/;
1406 return ($sfont, $efont);
1411 my $arg = next_argument
();
1412 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1413 my $font = fix_font
(next_argument
());
1414 my $h1 = next_argument
();
1415 my $h2 = next_argument
();
1417 $globals{'lineifont'} = $font;
1418 my $a1 = $col_aligns[0];
1419 my $a2 = $col_aligns[1];
1420 s/\\lineii</\\lineii[$a1|$a2]</g;
1421 return '<div class="center"><table class="realtable">'
1431 . "\n</table></div>";
1434 sub do_env_longtableii
{
1435 return do_env_tableii
(@_);
1440 my $aligns = next_optional_argument
();
1441 my $c1 = next_argument
();
1442 my $c2 = next_argument
();
1444 my($sfont, $efont) = get_table_col1_fonts
();
1445 my($c1align, $c2align) = split('\|', $aligns);
1446 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1447 . " $c2align$c2</td></tr>"
1451 sub do_env_tableiii
{
1453 my $arg = next_argument
();
1454 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1455 my $font = fix_font
(next_argument
());
1456 my $h1 = next_argument
();
1457 my $h2 = next_argument
();
1458 my $h3 = next_argument
();
1460 $globals{'lineifont'} = $font;
1461 my $a1 = $col_aligns[0];
1462 my $a2 = $col_aligns[1];
1463 my $a3 = $col_aligns[2];
1464 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1465 return '<div class="center"><table class="realtable">'
1476 . "\n</table></div>";
1479 sub do_env_longtableiii
{
1480 return do_env_tableiii
(@_);
1485 my $aligns = next_optional_argument
();
1486 my $c1 = next_argument
();
1487 my $c2 = next_argument
();
1488 my $c3 = next_argument
();
1490 my($sfont, $efont) = get_table_col1_fonts
();
1491 my($c1align, $c2align, $c3align) = split('\|', $aligns);
1492 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1493 . " $c2align$c2</td>\n"
1494 . " $c3align$c3</td></tr>"
1500 my $arg = next_argument
();
1501 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1502 my $font = fix_font
(next_argument
());
1503 my $h1 = next_argument
();
1504 my $h2 = next_argument
();
1505 my $h3 = next_argument
();
1506 my $h4 = next_argument
();
1508 $globals{'lineifont'} = $font;
1509 my $a1 = $col_aligns[0];
1510 my $a2 = $col_aligns[1];
1511 my $a3 = $col_aligns[2];
1512 my $a4 = $col_aligns[3];
1513 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1514 return '<div class="center"><table class="realtable">'
1526 . "\n</table></div>";
1529 sub do_env_longtableiv
{
1530 return do_env_tableiv
(@_);
1535 my $aligns = next_optional_argument
();
1536 my $c1 = next_argument
();
1537 my $c2 = next_argument
();
1538 my $c3 = next_argument
();
1539 my $c4 = next_argument
();
1541 my($sfont, $efont) = get_table_col1_fonts
();
1542 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
1543 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1544 . " $c2align$c2</td>\n"
1545 . " $c3align$c3</td>\n"
1546 . " $c4align$c4</td></tr>"
1552 my $arg = next_argument
();
1553 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments
($arg);
1554 my $font = fix_font
(next_argument
());
1555 my $h1 = next_argument
();
1556 my $h2 = next_argument
();
1557 my $h3 = next_argument
();
1558 my $h4 = next_argument
();
1559 my $h5 = next_argument
();
1561 $globals{'lineifont'} = $font;
1562 my $a1 = $col_aligns[0];
1563 my $a2 = $col_aligns[1];
1564 my $a3 = $col_aligns[2];
1565 my $a4 = $col_aligns[3];
1566 my $a5 = $col_aligns[4];
1567 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1568 return '<div class="center"><table class="realtable">'
1581 . "\n</table></div>";
1584 sub do_env_longtablev
{
1585 return do_env_tablev
(@_);
1590 my $aligns = next_optional_argument
();
1591 my $c1 = next_argument
();
1592 my $c2 = next_argument
();
1593 my $c3 = next_argument
();
1594 my $c4 = next_argument
();
1595 my $c5 = next_argument
();
1597 my($sfont, $efont) = get_table_col1_fonts
();
1598 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
1599 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1600 . " $c2align$c2</td>\n"
1601 . " $c3align$c3</td>\n"
1602 . " $c4align$c4</td>\n"
1603 . " $c5align$c5</td></tr>"
1608 # These can be used to control the title page appearance;
1609 # they need a little bit of documentation.
1611 # If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1612 # $ICONSERVER directory, or include path information (other than "./"). The
1613 # default image type will be assumed if an extension is not provided.
1615 # If specified, the "title page" will contain two colums: one containing the
1616 # title/author/etc., and the other containing the graphic. Use the other
1617 # four variables listed here to control specific details of the layout; all
1620 # $TITLE_PAGE_GRAPHIC = "my-company-logo";
1621 # $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1622 # $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1623 # $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1624 # $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1626 sub make_my_titlepage
(){
1629 $the_title .= "\n<h1>$t_title</h1>";
1632 write_warnings
("\nThis document has no title.");
1636 my $href = translate_commands
($t_authorURL);
1637 $href = make_named_href
('author', $href,
1638 "<b><font size=\"+2\">$t_author"
1640 $the_title .= "\n<p>$href</p>";
1643 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1644 . '</font></b></p>');
1648 write_warnings
("\nThere is no author for this document.");
1651 $the_title .= "\n<p>$t_institute</p>";
1653 if ($DEVELOPER_ADDRESS) {
1654 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1657 $the_title .= "\n<p><i>$t_affil</i></p>";
1660 $the_title .= "\n<p>";
1661 if ($PACKAGE_VERSION) {
1662 $the_title .= ('<strong>Release '
1663 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
1665 $the_title .= "<strong>$t_date</strong></p>"
1668 $the_title .= "\n<p>$t_address</p>";
1671 $the_title .= "\n<p></p>";
1674 $the_title .= "\n<p>$t_email</p>";
1679 sub make_my_titlegraphic
(){
1680 my $filename = make_icon_filename
($TITLE_PAGE_GRAPHIC);
1681 my $graphic = "<td class=\"titlegraphic\"";
1682 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1683 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1684 $graphic .= "><img";
1685 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1686 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1687 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1688 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
1689 $graphic .= "\n src=\"$filename\" /></td>\n";
1693 sub do_cmd_maketitle
{
1695 my $the_title = "\n";
1696 if ($EXTERNAL_UP_LINK) {
1697 # This generates a <link> element in the wrong place (the
1698 # body), but I don't see any other way to get this generated
1699 # at all. Browsers like Mozilla, that support navigation
1700 # links, can make use of this.
1701 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1702 . ($EXTERNAL_UP_TITLE
1703 ?
" title='$EXTERNAL_UP_TITLE'" : '')
1706 $the_title .= '<div class="titlepage">';
1707 if ($TITLE_PAGE_GRAPHIC) {
1708 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1709 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1710 . "<tr align=\"right\">\n<td>"
1711 . make_my_titlepage
()
1713 . make_my_titlegraphic
()
1714 . "</tr>\n</table>");
1717 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1718 . make_my_titlegraphic
()
1720 . make_my_titlepage
()
1721 . "</td></tr>\n</table>");
1725 $the_title .= ("\n<div class='center'>"
1726 . make_my_titlepage
()
1729 $the_title .= "\n</div>";
1730 return $the_title . $_;
1735 # Module synopsis support
1738 require SynopsisTable
;
1740 sub get_chapter_id
(){
1741 my $id = do_cmd_thechapter
('');
1742 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
1747 # 'chapter' => 'SynopsisTable instance'
1748 %ModuleSynopses = ();
1750 sub get_synopsis_table
($){
1753 foreach $key (keys %ModuleSynopses) {
1754 if ($key eq $chap) {
1755 return $ModuleSynopses{$chap};
1758 my $st = SynopsisTable
->new();
1759 $ModuleSynopses{$chap} = $st;
1763 sub do_cmd_moduleauthor
{
1770 sub do_cmd_sectionauthor
{
1777 sub do_cmd_declaremodule
{
1779 my $key = next_optional_argument
();
1780 my $type = next_argument
();
1781 my $name = next_argument
();
1782 my $st = get_synopsis_table
(get_chapter_id
());
1784 $key = $name unless $key;
1785 $type = 'built-in' if $type eq 'builtin';
1786 $st->declare($name, $key, $type);
1787 define_module
($type, $name);
1788 return anchor_label
("module-$key",$CURRENT_FILE,$_)
1791 sub do_cmd_modulesynopsis
{
1793 my $st = get_synopsis_table
(get_chapter_id
());
1794 $st->set_synopsis($THIS_MODULE, translate_commands
(next_argument
()));
1798 sub do_cmd_localmoduletable
{
1800 my $chap = get_chapter_id
();
1801 my $st = get_synopsis_table
($chap);
1802 $st->set_file("$CURRENT_FILE");
1803 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
1806 sub process_all_localmoduletables
(){
1808 foreach $key (keys %ModuleSynopses) {
1809 my $st = $ModuleSynopses{$key};
1810 my $file = $st->get_file();
1812 process_localmoduletables_in_file
($file);
1815 print "\nsynopsis table $key has no file association\n";
1820 sub process_localmoduletables_in_file
($){
1822 open(MYFILE
, "<$file");
1824 sysread(MYFILE
, $_, 1024*1024);
1826 # need to get contents of file in $_
1827 while (/<tex2html-localmoduletable><(\d+)>/) {
1830 my $st = get_synopsis_table
($chap);
1831 my $data = $st->tohtml();
1834 open(MYFILE
,">$file");
1838 sub process_python_state
(){
1839 process_all_localmoduletables
();
1840 process_grammar_files
();
1845 # "See also:" -- references placed at the end of a \section
1849 return ("<div class=\"seealso\">\n "
1850 . "<p class=\"heading\">See Also:</p>\n"
1855 sub do_env_seealsostar
{
1856 return ("<div class=\"seealso-simple\">\n "
1861 sub do_cmd_seemodule
{
1862 # Insert the right magic to jump to the module definition. This should
1863 # work most of the time, at least for repeat builds....
1865 my $key = next_optional_argument
();
1866 my $module = next_argument
();
1867 my $text = next_argument
();
1871 if ($text =~ /\.$/) {
1874 return ('<dl compact="compact" class="seemodule">'
1875 . "\n <dt>Module <b><tt class=\"module\">"
1876 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1877 . "\n <dd>$text$period\n </dl>"
1881 sub strip_html_markup
($){
1884 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1885 $s =~ s/<\/[a-zA-Z0-9]+>//g
;
1889 sub handle_rfclike_reference
($$$){
1890 local($_, $what, $format) = @_;
1891 my $rfcnum = next_argument
();
1892 my $title = next_argument
();
1893 my $text = next_argument
();
1894 my $url = get_rfc_url
($rfcnum, $format);
1895 my $icon = get_link_icon
($url);
1896 my $attrtitle = strip_html_markup
($title);
1897 return '<dl compact="compact" class="seerfc">'
1898 . "\n <dt><a href=\"$url\""
1899 . "\n title=\"$attrtitle\""
1900 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
1901 . "\n <dd>$text\n </dl>"
1906 return handle_rfclike_reference
($_[0], "PEP", $PEP_FORMAT);
1910 # XXX Would be nice to add links to the text/plain and PDF versions.
1911 return handle_rfclike_reference
($_[0], "RFC", $RFC_FORMAT);
1914 sub do_cmd_seetitle
{
1916 my $url = next_optional_argument
();
1917 my $title = next_argument
();
1918 my $text = next_argument
();
1920 my $icon = get_link_icon
($url);
1921 return '<dl compact="compact" class="seetitle">'
1922 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
1923 . "\n >$title$icon</a></em></dt>"
1924 . "\n <dd>$text</dd>\n </dl>"
1927 return '<dl compact="compact" class="seetitle">'
1928 . "\n <dt><em class=\"citetitle\""
1929 . "\n >$title</em></dt>"
1930 . "\n <dd>$text</dd>\n </dl>"
1936 my $url = next_argument
();
1937 my $linktext = next_argument
();
1938 my $text = next_argument
();
1939 my $icon = get_link_icon
($url);
1940 return '<dl compact="compact" class="seeurl">'
1941 . "\n <dt><a href='$url'"
1942 . "\n >$linktext$icon</a></dt>"
1943 . "\n <dd>$text</dd>\n </dl>"
1949 my $url = next_argument
();
1950 my $text = next_argument
();
1951 my $icon = get_link_icon
($url);
1952 return '<dl compact="compact" class="seeurl">'
1953 . "\n <dt><a href=\"$url\""
1954 . "\n class=\"url\">$url$icon</a></dt>"
1955 . "\n <dd>$text</dd>\n </dl>"
1961 my $content = next_argument
();
1962 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
1967 # Definition list support.
1970 sub do_env_definitions
{
1971 return '<dl class="definitions">' . $_[0] . "</dl>\n";
1976 my $term = next_argument
();
1977 my($name, $aname, $ahref) = new_link_info
();
1978 # could easily add an index entry here...
1979 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
1983 # Commands listed here have process-order dependencies; these often
1984 # are related to indexing operations.
1985 # XXX Not sure why funclineni, methodlineni, and samp are here.
1987 process_commands_wrap_deferred
(<<_RAW_ARG_DEFERRED_CMDS_
);
1988 declaremodule
# [] # {} # {}
1990 funclineni
# {} # {}
1991 memberline
# [] # {}
1992 methodline
# [] # {} # {}
1993 methodlineni
# [] # {} # {}
1998 indexiii
# {} # {} # {}
1999 indexiv
# {} # {} # {} # {}
2006 setindexsubitem
# {}
2007 withsubitem
# {} # {}
2008 _RAW_ARG_DEFERRED_CMDS_
2011 $alltt_start = '<div class="verbatim"><pre>';
2012 $alltt_end = '</pre></div>';
2016 local($closures,$reopens,@open_block_tags);
2018 # get the tag-strings for all open tags
2019 local(@keep_open_tags) = @
$open_tags_R;
2020 ($closures,$reopens) = &preserve_open_tags
() if (@
$open_tags_R);
2022 # get the tags for text-level tags only
2023 $open_tags_R = [ @keep_open_tags ];
2024 local($local_closures, $local_reopens);
2025 ($local_closures, $local_reopens,@open_block_tags)
2026 = &preserve_open_block_tags
2029 $open_tags_R = [ @open_block_tags ];
2032 local($open_tags_R) = [ @open_block_tags ];
2033 local(@save_open_tags) = ();
2035 local($cnt) = ++$global{'max_id'};
2036 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2037 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
2039 $_ = &translate_environments
($_);
2040 $_ = &translate_commands
($_) if (/\\/);
2042 # remove spurious <BR> someone sticks in; not sure where they
2043 # actually come from
2044 # XXX the replacement space is there to accomodate something
2045 # broken that inserts a space in front of the first line of
2049 $_ = join('', $closures, $alltt_start, $local_reopens
2051 , &balance_tags
() #, $local_closures
2052 , $alltt_end, $reopens);
2053 undef $open_tags_R; undef @save_open_tags;
2055 $open_tags_R = [ @keep_open_tags ];
2056 return codetext
($_);
2059 # List of all filenames produced by do_cmd_verbatiminput()
2060 %VerbatimFiles = ();
2061 @VerbatimOutputs = ();
2063 sub get_verbatim_output_name
($){
2066 # Re-write the source filename to always use a .txt extension
2067 # so that Web servers will present it as text/plain. This is
2068 # needed since there is no other even moderately reliable way
2069 # to get the right Content-Type header on text files for
2070 # servers which we can't configure (like python.org mirrors).
2072 if (defined $VerbatimFiles{$file}) {
2073 # We've seen this one before; re-use the same output file.
2074 return $VerbatimFiles{$file};
2076 my($srcname, $srcdir, $srcext) = fileparse
($file, '\..*');
2077 $filename = "$srcname.txt";
2079 # We need to determine if our default filename is already
2080 # being used, and find a new one it it is. If the name is in
2081 # used, this algorithm will first attempt to include the
2082 # source extension as part of the name, and if that is also in
2083 # use (if the same file is included multiple times, or if
2084 # another source file has that as the base name), a counter is
2090 foreach $fn (@VerbatimOutputs) {
2091 if ($fn eq $filename) {
2093 $srcext =~ s/^[.]//; # Remove '.' from extension
2094 $filename = "$srcname-$srcext.txt";
2097 $filename = "$srcname-$found.txt";
2105 push @VerbatimOutputs, $filename;
2106 $VerbatimFiles{$file} = $filename;
2110 sub do_cmd_verbatiminput
{
2112 my $fname = next_argument
();
2116 # Search TEXINPUTS for the input file, the way we're supposed to:
2117 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2118 $file = "$texpath$dd$fname";
2119 last if ($found = (-f
$file));
2124 open(MYFILE
, "<$file") || die "\n$!\n";
2125 read(MYFILE
, $text, 1024*1024);
2127 $filename = get_verbatim_output_name
($file);
2128 # Now that we have a filename, write it out.
2129 open(MYFILE
, ">$filename");
2133 # These rewrites convert the raw text to something that will
2134 # be properly visible as HTML and also will pass through the
2135 # vagaries of conversion through LaTeX2HTML. The order in
2136 # which the specific rewrites are performed is significant.
2138 $text =~ s/\&/\&/g;
2139 # These need to happen before the normal < and > re-writes,
2140 # since we need to avoid LaTeX2HTML's attempt to perform
2141 # ligature processing without regard to context (since it
2142 # doesn't have font information).
2143 $text =~ s/--/-&\#45;/g;
2144 $text =~ s/<</\<\&\#60;/g;
2145 $text =~ s/>>/\>\&\#62;/g;
2146 # Just normal re-writes...
2147 $text =~ s/</\</g;
2148 $text =~ s/>/\>/g;
2149 # These last isn't needed for the HTML, but is needed to get
2150 # past LaTeX2HTML processing TeX macros. We use \ instead
2151 # of / since many browsers don't support that.
2152 $text =~ s/\\/\&\#92;/g;
2155 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2157 my $note = 'Download as text.';
2158 if ($file ne $filename) {
2159 $note = ('Download as text (original file name: <span class="file">'
2163 return ("<div class=\"verbatim\">\n<pre>"
2165 . "</pre>\n<div class=\"footer\">\n"
2166 . "<a href=\"$filename\" type=\"text/plain\""
2172 1; # This must be the last line