Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Doc / perl / python.perl
blob57a19eda1808029e7507d17424d82bfe04129b98
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.
9 package main;
12 sub next_argument{
13 my $param;
14 $param = missing_braces()
15 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
16 ||(s/$next_pair_rx/$param=$2;''/eo));
17 return $param;
20 sub next_optional_argument{
21 my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
22 s/$rx/$param=$2;''/eo;
23 return $param;
27 # This is a fairly simple hack; it supports \let when it is used to create
28 # (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
29 # Many possible uses of \let aren't supported or aren't supported correctly.
31 sub do_cmd_let{
32 local($_) = @_;
33 my $matched = 0;
34 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
35 if ($matched) {
36 my($new, $old) = ($1, $3);
37 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
38 print "\ndefining handler for \\$new using \\$old\n";
40 else {
41 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
42 if ($matched) {
43 my($new, $char) = ($1, $3);
44 eval "sub do_cmd_$new { \"\\$char\" . \@_[0]; }";
45 print "\ndefining handler for \\$new to insert '$char'\n";
47 else {
48 write_warnings("Could not interpret \\let construct...");
51 return $_;
55 # words typeset in a special way (not in HTML though)
57 sub do_cmd_ABC{ 'ABC' . @_[0]; }
58 sub do_cmd_UNIX{ 'Unix'. @_[0]; }
59 sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
60 sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
61 sub do_cmd_C{ 'C' . @_[0]; }
62 sub do_cmd_Cpp{ 'C++' . @_[0]; }
63 sub do_cmd_EOF{ 'EOF' . @_[0]; }
64 sub do_cmd_NULL{ '<tt>NULL</tt>' . @_[0]; }
66 sub do_cmd_e{ '&#92;' . @_[0]; }
68 $DEVELOPER_ADDRESS = '';
69 $PYTHON_VERSION = '';
71 sub do_cmd_version{ $PYTHON_VERSION . @_[0]; }
72 sub do_cmd_release{
73 local($_) = @_;
74 $PYTHON_VERSION = next_argument();
75 return $_;
78 sub do_cmd_authoraddress{
79 local($_) = @_;
80 $DEVELOPER_ADDRESS = next_argument();
81 return $_;
84 #sub do_cmd_developer{ do_cmd_author(@_[0]); }
85 #sub do_cmd_developers{ do_cmd_author(@_[0]); }
86 #sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
88 sub do_cmd_hackscore{
89 local($_) = @_;
90 next_argument();
91 return '_' . $_;
94 sub use_wrappers{
95 local($_,$before,$after) = @_;
96 my $stuff = next_argument();
97 return $before . $stuff . $after . $_;
100 sub use_sans_serif{
101 return use_wrappers(@_[0], '<font face="sans-serif">', '</font>');
103 sub use_italics{
104 return use_wrappers(@_[0], '<i>', '</i>');
107 sub do_cmd_optional{
108 return use_wrappers(@_[0], "</var><big>\[</big><var>",
109 "</var><big>\]</big><var>");
112 # Logical formatting (some based on texinfo), needs to be converted to
113 # minimalist HTML. The "minimalist" is primarily to reduce the size of
114 # output files for users that read them over the network rather than
115 # from local repositories.
117 # \file and \samp are at the end of this file since they screw up fontlock.
119 sub do_cmd_pytype{ return @_[0]; }
120 sub do_cmd_makevar{ return @_[0]; }
121 sub do_cmd_code{
122 return use_wrappers(@_[0], '<tt>', '</tt>'); }
123 sub do_cmd_module{
124 return use_wrappers(@_[0], '<tt class=module>', '</tt>'); }
125 sub do_cmd_keyword{
126 return use_wrappers(@_[0], '<tt class=keyword>', '</tt>'); }
127 sub do_cmd_exception{
128 return use_wrappers(@_[0], '<tt class=exception>', '</tt>'); }
129 sub do_cmd_class{
130 return use_wrappers(@_[0], '<tt class=class>', '</tt>'); }
131 sub do_cmd_function{
132 return use_wrappers(@_[0], '<tt class=function>', '</tt>'); }
133 sub do_cmd_constant{
134 return use_wrappers(@_[0], '<tt class=constant>', '</tt>'); }
135 sub do_cmd_member{
136 return use_wrappers(@_[0], '<tt class=member>', '</tt>'); }
137 sub do_cmd_method{
138 return use_wrappers(@_[0], '<tt class=method>', '</tt>'); }
139 sub do_cmd_cfunction{
140 return use_wrappers(@_[0], '<tt class=cfunction>', '</tt>'); }
141 sub do_cmd_cdata{
142 return use_wrappers(@_[0], '<tt class=cdata>', '</tt>'); }
143 sub do_cmd_ctype{
144 return use_wrappers(@_[0], '<tt class=ctype>', '</tt>'); }
145 sub do_cmd_regexp{
146 return use_wrappers(@_[0], '<tt class=regexp>', '</tt>'); }
147 sub do_cmd_character{
148 return use_wrappers(@_[0], '"<tt class=character>', '</tt>"'); }
149 sub do_cmd_program{
150 return use_wrappers(@_[0], '<b class=program>', '</b>'); }
151 sub do_cmd_programopt{
152 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
153 sub do_cmd_email{
154 return use_wrappers(@_[0], '<span class=email>', '</span>'); }
155 sub do_cmd_mimetype{
156 return use_wrappers(@_[0], '<span class=mimetype>', '</span>'); }
157 sub do_cmd_var{
158 return use_wrappers(@_[0], "<var>", "</var>"); }
159 sub do_cmd_dfn{
160 return use_wrappers(@_[0], '<i class=dfn>', '</i>'); }
161 sub do_cmd_emph{
162 return use_italics(@_); }
163 sub do_cmd_file{
164 return use_wrappers(@_[0], '<tt class=file>', '</tt>'); }
165 sub do_cmd_filenq{
166 return use_wrappers(@_[0], '<tt class=file>', '</tt>'); }
167 sub do_cmd_samp{
168 return use_wrappers(@_[0], '"<tt class=samp>', '</tt>"'); }
169 sub do_cmd_kbd{
170 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
171 sub do_cmd_strong{
172 return use_wrappers(@_[0], '<b>', '</b>'); }
173 sub do_cmd_textbf{
174 return use_wrappers(@_[0], '<b>', '</b>'); }
175 sub do_cmd_textit{
176 return use_wrappers(@_[0], '<i>', '</i>'); }
179 sub do_cmd_refmodule{
180 # Insert the right magic to jump to the module definition.
181 local($_) = @_;
182 my $key = next_optional_argument();
183 my $module = next_argument();
184 $key = $module
185 unless $key;
186 return "<tt class=module><a href=\"module-$key.html\">$module</a></tt>" . $_;
189 sub do_cmd_newsgroup{
190 local($_) = @_;
191 my $newsgroup = next_argument();
192 my $stuff = "<a class=newsgroup href=\"news:$newsgroup\">$newsgroup</a>";
193 return $stuff . $_;
196 sub do_cmd_envvar{
197 local($_) = @_;
198 my $envvar = next_argument();
199 my($name,$aname,$ahref) = new_link_info();
200 # The <tt> here is really to keep buildindex.py from making
201 # the variable name case-insensitive.
202 add_index_entry("environment variables!$envvar@<tt>\$$envvar</tt>",
203 $ahref);
204 add_index_entry("$envvar@\$$envvar", $ahref);
205 $aname =~ s/<a/<a class=envvar/;
206 return "$aname\$$envvar</a>" . $_;
209 sub do_cmd_url{
210 # use the URL as both text and hyperlink
211 local($_) = @_;
212 my $url = next_argument();
213 $url =~ s/~/&#126;/g;
214 return "<a class=url href=\"$url\">$url</a>" . $_;
217 sub do_cmd_manpage{
218 # two parameters: \manpage{name}{section}
219 local($_) = @_;
220 my $page = next_argument();
221 my $section = next_argument();
222 return "<span class=manpage><i>$page</i>($section)</span>" . $_;
225 sub do_cmd_rfc{
226 local($_) = @_;
227 my $rfcnumber = next_argument();
228 my $id = "rfcref-" . ++$global{'max_id'};
229 my $href =
230 "http://info.internet.isi.edu/in-notes/rfc/files/rfc$rfcnumber.txt";
231 # Save the reference
232 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
233 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
234 return ("<a class=rfc name=\"$id\"\nhref=\"$href\">RFC $rfcnumber</a>"
235 . $_);
238 sub do_cmd_citetitle{
239 local($_) = @_;
240 my $url = next_optional_argument();
241 my $title = next_argument();
242 my $repl = '';
243 if ($url) {
244 $repl = ("<em class='citetitle'><a\n"
245 . " href='$url'\n"
246 . " title='$title'\n"
247 . " >$title</a></em>");
249 else {
250 $repl = "<em class='citetitle'\n >$title</em>";
252 return $repl . $_;
255 sub do_cmd_deprecated{
256 # two parameters: \deprecated{version}{whattodo}
257 local($_) = @_;
258 my $release = next_argument();
259 my $reason = next_argument();
260 return "<b>Deprecated since release $release.</b>\n$reason<p>" . $_;
263 sub do_cmd_versionadded{
264 # one parameter: \versionadded{version}
265 local($_) = @_;
266 my $release = next_argument();
267 return "\nNew in version $release.\n" . $_;
270 sub do_cmd_versionchanged{
271 # one parameter: \versionchanged{version}
272 local($_) = @_;
273 my $release = next_argument();
274 return "\nChanged in version $release.\n" . $_;
278 # These function handle platform dependency tracking.
280 sub do_cmd_platform{
281 local($_) = @_;
282 my $platform = next_argument();
283 $ModulePlatforms{$THIS_MODULE} = $platform;
284 $platform = "Macintosh"
285 if $platform eq 'Mac';
286 return "\n<p class=availability>Availability: <span"
287 . "\n class=platform>$platform</span>.</p>\n" . $_;
290 $IGNORE_PLATFORM_ANNOTATION = '';
291 sub do_cmd_ignorePlatformAnnotation{
292 local($_) = @_;
293 $IGNORE_PLATFORM_ANNOTATION = next_argument();
294 return $_;
298 # index commands
300 $INDEX_SUBITEM = "";
302 sub get_indexsubitem{
303 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
306 sub do_cmd_setindexsubitem{
307 local($_) = @_;
308 $INDEX_SUBITEM = next_argument();
309 return $_;
312 sub do_cmd_withsubitem{
313 # We can't really do the right thing, because LaTeX2HTML doesn't
314 # do things in the right order, but we need to at least strip this stuff
315 # out, and leave anything that the second argument expanded out to.
317 local($_) = @_;
318 my $oldsubitem = $INDEX_SUBITEM;
319 $INDEX_SUBITEM = next_argument();
320 my $stuff = next_argument();
321 my $br_id = ++$globals{'max_id'};
322 my $marker = "$O$br_id$C";
323 return
324 $stuff
325 . "\\setindexsubitem$marker$oldsubitem$marker"
326 . $_;
329 # This is the prologue macro which is required to start writing the
330 # mod\jobname.idx file; we can just ignore it. (Defining this suppresses
331 # a warning that \makemodindex is unknown.)
333 sub do_cmd_makemodindex{ return @_[0]; }
335 # We're in the document subdirectory when this happens!
337 open(IDXFILE, '>index.dat') || die "\n$!\n";
338 open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
339 print INTLABELS "%internal_labels = ();\n";
340 print INTLABELS "1; # hack in case there are no entries\n\n";
342 # Using \0 for this is bad because we can't use common tools to work with the
343 # resulting files. Things like grep can be useful with this stuff!
345 $IDXFILE_FIELD_SEP = "\1";
347 sub write_idxfile{
348 my ($ahref, $str) = @_;
349 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
353 sub gen_link{
354 my($node,$target) = @_;
355 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
356 return "<a href=\"$node#$target\">";
359 sub add_index_entry{
360 # add an entry to the index structures; ignore the return value
361 my($str,$ahref) = @_;
362 $str = gen_index_id($str, '');
363 $index{$str} .= $ahref;
364 write_idxfile($ahref, $str);
367 sub new_link_info{
368 my $name = "l2h-" . ++$globals{'max_id'};
369 my $aname = '<a name="' . $name . '">';
370 my $ahref = gen_link($CURRENT_FILE, $name);
371 return ($name, $aname, $ahref);
374 $IndexMacroPattern = '';
375 sub define_indexing_macro{
376 my $count = @_;
377 my $i = 0;
378 for (; $i < $count; ++$i) {
379 my $name = @_[$i];
380 my $cmd = "idx_cmd_$name";
381 die "\nNo function $cmd() defined!\n"
382 if (!defined &$cmd);
383 eval ("sub do_cmd_$name { return process_index_macros("
384 . "\@_[0], '$name'); }");
385 if (length($IndexMacroPattern) == 0) {
386 $IndexMacroPattern = "$name";
388 else {
389 $IndexMacroPattern .= "|$name";
394 $DEBUG_INDEXING = 0;
395 sub process_index_macros{
396 local($_) = @_;
397 my $cmdname = @_[1]; # This is what triggered us in the first place;
398 # we know it's real, so just process it.
399 my($name,$aname,$ahref) = new_link_info();
400 my $cmd = "idx_cmd_$cmdname";
401 print "\nIndexing: \\$cmdname"
402 if $DEBUG_INDEXING;
403 &$cmd($ahref); # modifies $_ and adds index entries
404 while (/^[\s\n]*\\($IndexMacroPattern)</) {
405 $cmdname = "$1";
406 print " \\$cmdname"
407 if $DEBUG_INDEXING;
408 $cmd = "idx_cmd_$cmdname";
409 if (!defined &$cmd) {
410 last;
412 else {
413 s/^[\s\n]*\\$cmdname//;
414 &$cmd($ahref);
417 return "$aname$anchor_invisible_mark</a>" . $_;
420 define_indexing_macro('index');
421 sub idx_cmd_index{
422 my $str = next_argument();
423 add_index_entry("$str", @_[0]);
426 define_indexing_macro('kwindex');
427 sub idx_cmd_kwindex{
428 my $str = next_argument();
429 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
430 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
433 define_indexing_macro('indexii');
434 sub idx_cmd_indexii{
435 my $str1 = next_argument();
436 my $str2 = next_argument();
437 add_index_entry("$str1!$str2", @_[0]);
438 add_index_entry("$str2!$str1", @_[0]);
441 define_indexing_macro('indexiii');
442 sub idx_cmd_indexiii{
443 my $str1 = next_argument();
444 my $str2 = next_argument();
445 my $str3 = next_argument();
446 add_index_entry("$str1!$str2 $str3", @_[0]);
447 add_index_entry("$str2!$str3, $str1", @_[0]);
448 add_index_entry("$str3!$str1 $str2", @_[0]);
451 define_indexing_macro('indexiv');
452 sub idx_cmd_indexiv{
453 my $str1 = next_argument();
454 my $str2 = next_argument();
455 my $str3 = next_argument();
456 my $str4 = next_argument();
457 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
458 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
459 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
460 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
463 define_indexing_macro('ttindex');
464 sub idx_cmd_ttindex{
465 my $str = next_argument();
466 my $entry = $str . get_indexsubitem();
467 add_index_entry($entry, @_[0]);
470 sub my_typed_index_helper{
471 my($word,$ahref) = @_;
472 my $str = next_argument();
473 add_index_entry("$str $word", $ahref);
474 add_index_entry("$word!$str", $ahref);
477 define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
478 sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
479 sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
480 sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
481 sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
483 define_indexing_macro('bifuncindex');
484 sub idx_cmd_bifuncindex{
485 my $str = next_argument();
486 add_index_entry("<tt>$str()</tt> (built-in function)", @_[0]);
490 sub make_mod_index_entry{
491 my($str,$define) = @_;
492 my($name,$aname,$ahref) = new_link_info();
493 # equivalent of add_index_entry() using $define instead of ''
494 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
495 if ($define eq 'DEF');
496 $str = gen_index_id($str, $define);
497 $index{$str} .= $ahref;
498 write_idxfile($ahref, $str);
500 if ($define eq 'DEF') {
501 # add to the module index
502 my($nstr,$garbage) = split / /, $str, 2;
503 $Modules{$nstr} .= $ahref;
505 return "$aname$anchor_invisible_mark</a>";
509 $THIS_MODULE = '';
510 $THIS_CLASS = '';
512 sub define_module{
513 my($word,$name) = @_;
514 my $section_tag = join('', @curr_sec_id);
515 if ($word ne "built-in" && $word ne "extension"
516 && $word ne "standard" && $word ne "") {
517 write_warnings("Bad module type '$word'"
518 . " for \\declaremodule (module $name)");
519 $word = "";
521 $word = "$word " if $word;
522 $THIS_MODULE = "$name";
523 $INDEX_SUBITEM = "(in $name)";
524 print "[$name]";
525 return make_mod_index_entry("<tt>$name</tt> (${word}module)", 'DEF');
528 sub my_module_index_helper{
529 local($word, $_) = @_;
530 my $name = next_argument();
531 return define_module($word, $name) . $_;
534 sub do_cmd_modindex{ return my_module_index_helper('', @_); }
535 sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
536 sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
537 sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
539 sub ref_module_index_helper{
540 local($word, $ahref) = @_;
541 my $str = next_argument();
542 $word = "$word " if $word;
543 $str = "<tt>$str</tt> (${word}module)";
544 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
545 # just inline it all here
546 $str = gen_index_id($str, 'REF');
547 $index{$str} .= $ahref;
548 write_idxfile($ahref, $str);
551 # these should be adjusted a bit....
552 define_indexing_macro('refmodindex', 'refbimodindex',
553 'refexmodindex', 'refstmodindex');
554 sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
555 sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
556 sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
557 sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
559 sub do_cmd_nodename{ return do_cmd_label(@_); }
561 sub init_myformat{
562 # $anchor_invisible_mark = '';
563 $anchor_mark = '';
564 $icons{'anchor_mark'} = '';
566 init_myformat();
568 # Create an index entry, but include the string in the target anchor
569 # instead of the dummy filler.
571 sub make_str_index_entry{
572 my($str) = @_;
573 my($name,$aname,$ahref) = new_link_info();
574 add_index_entry($str, $ahref);
575 return "$aname$str</a>";
578 sub do_env_cfuncdesc{
579 local($_) = @_;
580 my $return_type = next_argument();
581 my $function_name = next_argument();
582 my $arg_list = next_argument();
583 my $idx = make_str_index_entry("<tt class=cfunction>$function_name()</tt>"
584 . get_indexsubitem());
585 $idx =~ s/ \(.*\)//;
586 $idx =~ s/\(\)//; # ????
587 return "<dl><dt>$return_type <b>$idx</b> (<var>$arg_list</var>)\n<dd>"
588 . $_
589 . '</dl>';
592 sub do_env_ctypedesc{
593 local($_) = @_;
594 my $type_name = next_argument();
595 my $idx = make_str_index_entry("<tt class=ctype>$type_name</tt>"
596 . get_indexsubitem());
597 $idx =~ s/ \(.*\)//;
598 return "<dl><dt><b>$idx</b>\n<dd>"
599 . $_
600 . '</dl>'
603 sub do_env_cvardesc{
604 local($_) = @_;
605 my $var_type = next_argument();
606 my $var_name = next_argument();
607 my $idx = make_str_index_entry("<tt class=cdata>$var_name</tt>"
608 . get_indexsubitem());
609 $idx =~ s/ \(.*\)//;
610 return "<dl><dt>$var_type <b>$idx</b>\n"
611 . '<dd>'
612 . $_
613 . '</dl>';
616 sub do_env_funcdesc{
617 local($_) = @_;
618 my $function_name = next_argument();
619 my $arg_list = next_argument();
620 my $idx = make_str_index_entry("<tt class=function>$function_name()</tt>"
621 . get_indexsubitem());
622 $idx =~ s/ \(.*\)//;
623 $idx =~ s/\(\)<\/tt>/<\/tt>/;
624 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
627 sub do_env_funcdescni{
628 local($_) = @_;
629 my $function_name = next_argument();
630 my $arg_list = next_argument();
631 return "<dl><dt><b><tt class=function>$function_name</tt></b>"
632 . " (<var>$arg_list</var>)\n"
633 . '<dd>'
634 . $_
635 . '</dl>';
638 sub do_cmd_funcline{
639 local($_) = @_;
640 my $function_name = next_argument();
641 my $arg_list = next_argument();
642 my $prefix = "<tt class=function>$function_name()</tt>";
643 my $idx = make_str_index_entry($prefix . get_indexsubitem());
644 $prefix =~ s/\(\)//;
646 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
649 sub do_cmd_funclineni{
650 local($_) = @_;
651 my $function_name = next_argument();
652 my $arg_list = next_argument();
653 my $prefix = "<tt class=function>$function_name</tt>";
655 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
658 # Change this flag to index the opcode entries. I don't think it's very
659 # useful to index them, since they're only presented to describe the dis
660 # module.
662 $INDEX_OPCODES = 0;
664 sub do_env_opcodedesc{
665 local($_) = @_;
666 my $opcode_name = next_argument();
667 my $arg_list = next_argument();
668 my $idx;
669 if ($INDEX_OPCODES) {
670 $idx = make_str_index_entry(
671 "<tt class=opcode>$opcode_name</tt> (byte code instruction)");
672 $idx =~ s/ \(byte code instruction\)//;
674 else {
675 $idx = "<tt class=opcode>$opcode_name</tt>";
677 my $stuff = "<dl><dt><b>$idx</b>";
678 if ($arg_list) {
679 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
681 return $stuff . "\n<dd>" . $_ . '</dl>';
684 sub do_env_datadesc{
685 local($_) = @_;
686 my $dataname = next_argument();
687 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
688 $idx =~ s/ \(.*\)//;
689 return "<dl><dt><b>$idx</b>\n<dd>"
690 . $_
691 . '</dl>';
694 sub do_env_datadescni{
695 local($_) = @_;
696 my $idx = next_argument();
697 if (! $STRING_INDEX_TT) {
698 $idx = "<tt>$idx</tt>";
700 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
703 sub do_cmd_dataline{
704 local($_) = @_;
705 my $data_name = next_argument();
706 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
707 $idx =~ s/ \(.*\)//;
708 return "<dt><b>$idx</b><dd>" . $_;
711 sub do_env_excdesc{
712 local($_) = @_;
713 my $excname = next_argument();
714 my $idx = make_str_index_entry("<tt class=exception>$excname</tt>");
715 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>'
718 sub do_env_fulllineitems{ return do_env_itemize(@_); }
721 sub do_env_classdesc{
722 local($_) = @_;
723 $THIS_CLASS = next_argument();
724 my $arg_list = next_argument();
725 $idx = make_str_index_entry(
726 "<tt class=class>$THIS_CLASS</tt> (class in $THIS_MODULE)" );
727 $idx =~ s/ \(.*\)//;
728 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
732 sub do_env_methoddesc{
733 local($_) = @_;
734 my $class_name = next_optional_argument();
735 $class_name = $THIS_CLASS
736 unless $class_name;
737 my $method = next_argument();
738 my $arg_list = next_argument();
739 my $extra = '';
740 if ($class_name) {
741 $extra = " ($class_name method)";
743 my $idx = make_str_index_entry("<tt class=method>$method()</tt>$extra");
744 $idx =~ s/ \(.*\)//;
745 $idx =~ s/\(\)//;
746 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
750 sub do_cmd_methodline{
751 local($_) = @_;
752 my $class_name = next_optional_argument();
753 $class_name = $THIS_CLASS
754 unless $class_name;
755 my $method = next_argument();
756 my $arg_list = next_argument();
757 my $extra = '';
758 if ($class_name) {
759 $extra = " ($class_name method)";
761 my $idx = make_str_index_entry("<tt class=method>$method()</tt>$extra");
762 $idx =~ s/ \(.*\)//;
763 $idx =~ s/\(\)//;
764 return "<dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>"
765 . $_;
769 sub do_cmd_methodlineni{
770 local($_) = @_;
771 next_optional_argument();
772 my $method = next_argument();
773 my $arg_list = next_argument();
774 return "<dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
775 . $_;
778 sub do_env_methoddescni{
779 local($_) = @_;
780 next_optional_argument();
781 my $method = next_argument();
782 my $arg_list = next_argument();
783 return "<dl><dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
784 . $_
785 . '</dl>';
789 sub do_env_memberdesc{
790 local($_) = @_;
791 my $class = next_optional_argument();
792 my $member = next_argument();
793 $class = $THIS_CLASS
794 unless $class;
795 my $extra = '';
796 $extra = " ($class attribute)"
797 if ($class ne '');
798 my $idx = make_str_index_entry("<tt class=member>$member</tt>$extra");
799 $idx =~ s/ \(.*\)//;
800 $idx =~ s/\(\)//;
801 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
805 sub do_cmd_memberline{
806 local($_) = @_;
807 my $class = next_optional_argument();
808 my $member = next_argument();
809 $class = $THIS_CLASS
810 unless $class;
811 my $extra = '';
812 $extra = " ($class attribute)"
813 if ($class ne '');
814 my $idx = make_str_index_entry("<tt class=member>$member</tt>$extra");
815 $idx =~ s/ \(.*\)//;
816 $idx =~ s/\(\)//;
817 return "<dt><b>$idx</b><dd>" . $_;
820 sub do_env_memberdescni{
821 local($_) = @_;
822 next_optional_argument();
823 my $member = next_argument();
824 return "<dl><dt><b><tt class=member>$member</tt></b>\n<dd>" . $_ . '</dl>';
828 sub do_cmd_memberlineni{
829 local($_) = @_;
830 next_optional_argument();
831 my $member = next_argument();
832 return "<dt><b><tt class=member>$member</tt></b><dd>" . $_;
835 @col_aligns = ("<td>", "<td>", "<td>", "<td>");
837 $TABLE_HEADER_BGCOLOR = $NAV_BGCOLOR;
839 sub get_th{
840 my $a = @_[0];
841 my $r = '<th>';
842 if ($a eq 'l')
843 { $r = '<th align=left>'; }
844 elsif (substr($a, 0, 1) eq 'p')
845 { $r = '<th align=left>'; }
846 elsif ($a eq 'r')
847 { $r = '<th align=right>'; }
848 return $r;
851 sub fix_font{
852 # do a little magic on a font name to get the right behavior in the first
853 # column of the output table
854 my $font = @_[0];
855 if ($font eq 'textrm') {
856 $font = '';
858 elsif ($font eq 'file' || $font eq 'filenq') {
859 $font = 'tt class=file';
861 return $font;
864 sub setup_column_alignments{
865 local($_) = @_;
866 my($a1,$a2,$a3,$a4) = split(/[|]/,$_);
867 my($th1,$th2,$th3,$th4) = ('<th>', '<th>', '<th>', '<th>');
868 $col_aligns[0] = (($a1 eq 'c') ? '<td align=center valign=baseline>'
869 : '<td valign=baseline>');
870 $col_aligns[1] = (($a2 eq 'c') ? '<td align=center>' : '<td>');
871 $col_aligns[2] = (($a3 eq 'c') ? '<td align=center>' : '<td>');
872 $col_aligns[3] = (($a4 eq 'c') ? '<td align=center>' : '<td>');
873 # return the aligned header start tags
874 return (get_th($a1), get_th($a2), get_th($a3), get_th($a4));
877 sub do_env_tableii{
878 local($_) = @_;
879 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
880 my $font = fix_font(next_argument());
881 my $h1 = next_argument();
882 my $h2 = next_argument();
883 s/[\s\n]+//;
884 $globals{'lineifont'} = $font;
885 return '<table border align=center style="border-collapse: collapse">'
886 . "\n <thead>"
887 . "\n <tr$TABLE_HEADER_BGCOLOR>"
888 . "\n $th1<b>$h1</b>\&nbsp;\&nbsp;</th>"
889 . "\n $th2<b>$h2</b>\&nbsp;\&nbsp;</th>"
890 . "\n </thead>"
891 . "\n <tbody valign=baseline>"
892 . $_
893 . "\n </tbody>"
894 . "\n</table>";
897 sub do_cmd_lineii{
898 local($_) = @_;
899 my $c1 = next_argument();
900 my $c2 = next_argument();
901 s/[\s\n]+//;
902 my($font,$sfont,$efont) = ($globals{'lineifont'}, '', '');
903 if ($font) {
904 $sfont = "<$font>";
905 $efont = "</$font>";
906 $efont =~ s/ .*>/>/;
908 my($c1align,$c2align) = @col_aligns[0,1];
909 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
910 . " $c2align$c2\&nbsp;</td>"
911 . $_;
914 sub do_env_tableiii{
915 local($_) = @_;
916 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
917 my $font = fix_font(next_argument());
918 my $h1 = next_argument();
919 my $h2 = next_argument();
920 my $h3 = next_argument();
921 s/[\s\n]+//;
922 $globals{'lineifont'} = $font;
923 return '<table border align=center style="border-collapse: collapse">'
924 . "\n <thead>"
925 . "\n <tr$TABLE_HEADER_BGCOLOR>"
926 . "\n $th1<b>$h1</b>\&nbsp;\&nbsp;</th>"
927 . "\n $th2<b>$h2</b>\&nbsp;\&nbsp;</th>"
928 . "\n $th3<b>$h3</b>\&nbsp;\&nbsp;</th>"
929 . "\n </thead>"
930 . "\n <tbody valign=baseline>"
931 . $_
932 . "\n </tbody>"
933 . "\n</table>";
936 sub do_cmd_lineiii{
937 local($_) = @_;
938 my $c1 = next_argument();
939 my $c2 = next_argument();
940 my $c3 = next_argument();
941 s/[\s\n]+//;
942 my($font,$sfont,$efont) = ($globals{'lineifont'}, '', '');
943 if ($font) {
944 $sfont = "<$font>";
945 $efont = "</$font>";
946 $efont =~ s/ .*>/>/;
948 my($c1align,$c2align,$c3align) = @col_aligns[0,1,2];
949 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
950 . " $c2align$c2</td>\n"
951 . " $c3align$c3\&nbsp;</td>"
952 . $_;
955 sub do_env_tableiv{
956 local($_) = @_;
957 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
958 my $font = fix_font(next_argument());
959 my $h1 = next_argument();
960 my $h2 = next_argument();
961 my $h3 = next_argument();
962 my $h4 = next_argument();
963 s/[\s\n]+//;
964 $globals{'lineifont'} = $font;
965 return '<table border align=center style="border-collapse: collapse">'
966 . "\n <thead>"
967 . "\n <tr$TABLE_HEADER_BGCOLOR>"
968 . "\n $th1<b>$h1</b>\&nbsp;\&nbsp;</th>"
969 . "\n $th2<b>$h2</b>\&nbsp;\&nbsp;</th>"
970 . "\n $th3<b>$h3</b>\&nbsp;\&nbsp;</th>"
971 . "\n $th4<b>$h4</b>\&nbsp;\&nbsp;</th>"
972 . "\n </thead>"
973 . "\n <tbody valign=baseline>"
974 . $_
975 . "\n </tbody>"
976 . "\n</table>";
979 sub do_cmd_lineiv{
980 local($_) = @_;
981 my $c1 = next_argument();
982 my $c2 = next_argument();
983 my $c3 = next_argument();
984 my $c4 = next_argument();
985 s/[\s\n]+//;
986 my($font,$sfont,$efont) = ($globals{'lineifont'}, '', '');
987 if ($font) {
988 $sfont = "<$font>";
989 $efont = "</$font>";
990 $efont =~ s/ .*>/>/;
992 my($c1align,$c2align,$c3align,$c4align) = @col_aligns;
993 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
994 . " $c2align$c2</td>\n"
995 . " $c3align$c3</td>\n"
996 . " $c4align$c4\&nbsp;</td>"
997 . $_;
1000 sub do_cmd_maketitle {
1001 local($_) = @_;
1002 my $the_title = "\n<div class=titlepage><center>";
1003 if ($t_title) {
1004 $the_title .= "\n<h1>$t_title</h1>";
1005 } else { write_warnings("\nThis document has no title."); }
1006 if ($t_author) {
1007 if ($t_authorURL) {
1008 my $href = translate_commands($t_authorURL);
1009 $href = make_named_href('author', $href,
1010 "<b><font size='+2'>$t_author</font></b>");
1011 $the_title .= "\n<p>$href</p>";
1012 } else {
1013 $the_title .= ("\n<p><b><font size='+2'>$t_author</font></b></p>");
1015 } else { write_warnings("\nThere is no author for this document."); }
1016 if ($t_institute) {
1017 $the_title .= "\n<p>$t_institute</p>";}
1018 if ($DEVELOPER_ADDRESS) {
1019 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";}
1020 if ($t_affil) {
1021 $the_title .= "\n<p><i>$t_affil</i></p>";}
1022 if ($t_date) {
1023 $the_title .= "\n<p><strong>$t_date</strong>";
1024 if ($PYTHON_VERSION) {
1025 $the_title .= "<br><strong>Release $PYTHON_VERSION</strong>";}
1026 $the_title .= "</p>"
1028 if ($t_address) {
1029 $the_title .= "\n<p>$t_address</p>";
1030 } else { $the_title .= "\n<p>"}
1031 if ($t_email) {
1032 $the_title .= "\n<p>$t_email</p>";
1033 }# else { $the_title .= "</p>" }
1034 $the_title .= "\n</center></div>";
1035 return $the_title . $_ ;
1040 # Module synopsis support
1043 require SynopsisTable;
1045 sub get_chapter_id(){
1046 my $id = do_cmd_thechapter('');
1047 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1048 $id =~ s/\.//;
1049 return $id;
1052 %ModuleSynopses = ('chapter' => 'SynopsisTable instance');
1054 sub get_synopsis_table($){
1055 my($chap) = @_;
1056 my $st = $ModuleSynopses{$chap};
1057 my $key;
1058 foreach $key (keys %ModuleSynopses) {
1059 if ($key eq $chap) {
1060 return $ModuleSynopses{$chap};
1063 $st = SynopsisTable->new();
1064 $ModuleSynopses{$chap} = $st;
1065 return $st;
1068 sub do_cmd_moduleauthor{
1069 local($_) = @_;
1070 next_argument();
1071 next_argument();
1072 return $_;
1075 sub do_cmd_sectionauthor{
1076 local($_) = @_;
1077 next_argument();
1078 next_argument();
1079 return $_;
1082 sub do_cmd_declaremodule{
1083 local($_) = @_;
1084 my $key = next_optional_argument();
1085 my $type = next_argument();
1086 my $name = next_argument();
1087 my $st = get_synopsis_table(get_chapter_id());
1089 $key = $name unless $key;
1090 $type = 'built-in' if $type eq 'builtin';
1091 $st->declare($name, $key, $type);
1092 define_module($type, $name);
1093 return anchor_label("module-$key",$CURRENT_FILE,$_)
1096 sub do_cmd_modulesynopsis{
1097 local($_) = @_;
1098 my $st = get_synopsis_table(get_chapter_id());
1099 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
1100 return $_;
1103 sub do_cmd_localmoduletable{
1104 local($_) = @_;
1105 my $chap = get_chapter_id();
1106 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
1109 sub process_all_localmoduletables{
1110 while (/<tex2html-localmoduletable><(\d+)>/) {
1111 my $match = $&;
1112 my $chap = $1;
1113 my $st = get_synopsis_table($chap);
1114 my $data = $st->tohtml();
1115 s/$match/$data/;
1118 sub process_python_state{
1119 process_all_localmoduletables();
1124 # "See also:" -- references placed at the end of a \section
1127 sub do_env_seealso{
1128 return "<div class=seealso>\n "
1129 . "<p class=heading><b>See Also:</b></p>\n"
1130 . @_[0]
1131 . '</div>';
1134 sub do_cmd_seemodule{
1135 # Insert the right magic to jump to the module definition. This should
1136 # work most of the time, at least for repeat builds....
1137 local($_) = @_;
1138 my $key = next_optional_argument();
1139 my $module = next_argument();
1140 my $text = next_argument();
1141 my $period = '.';
1142 $key = $module
1143 unless $key;
1144 if ($text =~ /\.$/) {
1145 $period = '';
1147 return '<dl compact class=seemodule>'
1148 . "\n <dt>Module <b><tt class=module><a href=\"module-$key.html\">"
1149 . "$module</a></tt>:</b>"
1150 . "\n <dd>$text$period\n </dl>"
1151 . $_;
1154 sub do_cmd_seetext{
1155 local($_) = @_;
1156 my $content = next_argument();
1157 return '<div class=seetext><p>' . $content . '</div>' . $_;
1162 # Definition list support.
1165 sub do_env_definitions{
1166 local($_) = @_;
1167 return "<dl class=definitions>$_</dl>\n";
1170 sub do_cmd_term{
1171 local($_) = @_;
1172 my $term = next_argument();
1173 my($name,$aname,$ahref) = new_link_info();
1174 # could easily add an index entry here...
1175 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
1179 process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
1180 code # {}
1181 declaremodule # [] # {} # {}
1182 memberline # [] # {}
1183 methodline # [] # {} # {}
1184 modulesynopsis # {}
1185 platform # {}
1186 samp # {}
1187 setindexsubitem # {}
1188 withsubitem # {} # {}
1189 _RAW_ARG_DEFERRED_CMDS_
1192 1; # This must be the last line