Last set of CW Pro 5 projects (probably)
[python/dscho.git] / Doc / perl / python.perl
blobbacc8cc708ab1cfe72eabba1b0ba834dbff03d78
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 # the older version of LaTeX2HTML we use doesn't support this, but we use it:
57 sub do_cmd_textasciitilde{ '~' . @_[0]; }
60 # words typeset in a special way (not in HTML though)
62 sub do_cmd_ABC{ 'ABC' . @_[0]; }
63 sub do_cmd_UNIX{ 'Unix'. @_[0]; }
64 sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
65 sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
66 sub do_cmd_C{ 'C' . @_[0]; }
67 sub do_cmd_Cpp{ 'C++' . @_[0]; }
68 sub do_cmd_EOF{ 'EOF' . @_[0]; }
69 sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
71 sub do_cmd_e{ '&#92;' . @_[0]; }
73 $DEVELOPER_ADDRESS = '';
74 $PYTHON_VERSION = '';
76 sub do_cmd_version{ $PYTHON_VERSION . @_[0]; }
77 sub do_cmd_release{
78 local($_) = @_;
79 $PYTHON_VERSION = next_argument();
80 return $_;
83 sub do_cmd_authoraddress{
84 local($_) = @_;
85 $DEVELOPER_ADDRESS = next_argument();
86 return $_;
89 #sub do_cmd_developer{ do_cmd_author(@_[0]); }
90 #sub do_cmd_developers{ do_cmd_author(@_[0]); }
91 #sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
93 sub do_cmd_hackscore{
94 local($_) = @_;
95 next_argument();
96 return '_' . $_;
99 sub use_wrappers{
100 local($_,$before,$after) = @_;
101 my $stuff = next_argument();
102 return $before . $stuff . $after . $_;
105 sub use_sans_serif{
106 return use_wrappers(@_[0], '<font face="sans-serif">', '</font>');
108 sub use_italics{
109 return use_wrappers(@_[0], '<i>', '</i>');
112 sub do_cmd_optional{
113 return use_wrappers(@_[0], "</var><big>\[</big><var>",
114 "</var><big>\]</big><var>");
117 # Logical formatting (some based on texinfo), needs to be converted to
118 # minimalist HTML. The "minimalist" is primarily to reduce the size of
119 # output files for users that read them over the network rather than
120 # from local repositories.
122 # \file and \samp are at the end of this file since they screw up fontlock.
124 sub do_cmd_pytype{ return @_[0]; }
125 sub do_cmd_makevar{
126 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
127 sub do_cmd_code{
128 return use_wrappers(@_[0], '<code>', '</code>'); }
129 sub do_cmd_module{
130 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
131 sub do_cmd_keyword{
132 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
133 sub do_cmd_exception{
134 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
135 sub do_cmd_class{
136 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
137 sub do_cmd_function{
138 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
139 sub do_cmd_constant{
140 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
141 sub do_cmd_member{
142 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
143 sub do_cmd_method{
144 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
145 sub do_cmd_cfunction{
146 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
147 sub do_cmd_cdata{
148 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
149 sub do_cmd_ctype{
150 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
151 sub do_cmd_regexp{
152 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
153 sub do_cmd_character{
154 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
155 sub do_cmd_program{
156 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
157 sub do_cmd_programopt{
158 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
159 sub do_cmd_longprogramopt{
160 # note that the --- will be later converted to -- by LaTeX2HTML
161 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
162 sub do_cmd_email{
163 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
164 sub do_cmd_mimetype{
165 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
166 sub do_cmd_var{
167 return use_wrappers(@_[0], "<var>", "</var>"); }
168 sub do_cmd_dfn{
169 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
170 sub do_cmd_emph{
171 return use_italics(@_); }
172 sub do_cmd_file{
173 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
174 sub do_cmd_filenq{
175 return do_cmd_file(@_[0]); }
176 sub do_cmd_samp{
177 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
178 sub do_cmd_kbd{
179 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
180 sub do_cmd_strong{
181 return use_wrappers(@_[0], '<b>', '</b>'); }
182 sub do_cmd_textbf{
183 return use_wrappers(@_[0], '<b>', '</b>'); }
184 sub do_cmd_textit{
185 return use_wrappers(@_[0], '<i>', '</i>'); }
187 sub do_cmd_moreargs{
188 return '...' . @_[0]; }
189 sub do_cmd_unspecified{
190 return '...' . @_[0]; }
193 sub do_cmd_refmodule{
194 # Insert the right magic to jump to the module definition.
195 local($_) = @_;
196 my $key = next_optional_argument();
197 my $module = next_argument();
198 $key = $module
199 unless $key;
200 return "<tt class='module'><a href='module-$key.html'>$module</a></tt>"
201 . $_;
204 sub do_cmd_newsgroup{
205 local($_) = @_;
206 my $newsgroup = next_argument();
207 my $stuff = "<span class='newsgroup'><a href='news:$newsgroup'>"
208 . "$newsgroup</a></span>";
209 return $stuff . $_;
212 sub do_cmd_envvar{
213 local($_) = @_;
214 my $envvar = next_argument();
215 my($name,$aname,$ahref) = new_link_info();
216 # The <tt> here is really to keep buildindex.py from making
217 # the variable name case-insensitive.
218 add_index_entry("environment variables!$envvar@<tt>\$$envvar</tt>",
219 $ahref);
220 add_index_entry("$envvar@\$$envvar", $ahref);
221 $aname =~ s/<a/<a class="envvar"/;
222 return "$aname\$$envvar</a>" . $_;
225 sub do_cmd_url{
226 # use the URL as both text and hyperlink
227 local($_) = @_;
228 my $url = next_argument();
229 $url =~ s/~/&#126;/g;
230 return "<a class=\"url\" href=\"$url\">$url</a>" . $_;
233 sub do_cmd_manpage{
234 # two parameters: \manpage{name}{section}
235 local($_) = @_;
236 my $page = next_argument();
237 my $section = next_argument();
238 return "<span class='manpage'><i>$page</i>($section)</span>" . $_;
241 sub get_rfc_url{
242 my $rfcnum = sprintf("%04d", @_[0]);
243 return "http://www.ietf.org/rfc/rfc$rfcnum.txt";
246 sub do_cmd_rfc{
247 local($_) = @_;
248 my $rfcnumber = next_argument();
249 my $id = "rfcref-" . ++$global{'max_id'};
250 my $href = get_rfc_url($rfcnumber);
251 # Save the reference
252 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
253 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
254 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber</a>"
255 . $_);
258 sub do_cmd_citetitle{
259 local($_) = @_;
260 my $url = next_optional_argument();
261 my $title = next_argument();
262 my $repl = '';
263 if ($url) {
264 $repl = ("<em class='citetitle'><a\n"
265 . " href='$url'\n"
266 . " title='$title'\n"
267 . " >$title</a></em>");
269 else {
270 $repl = "<em class='citetitle'\n >$title</em>";
272 return $repl . $_;
275 sub do_cmd_deprecated{
276 # two parameters: \deprecated{version}{whattodo}
277 local($_) = @_;
278 my $release = next_argument();
279 my $reason = next_argument();
280 return "<b>Deprecated since release $release.</b>\n$reason<p>" . $_;
283 sub do_cmd_versionadded{
284 # one parameter: \versionadded{version}
285 local($_) = @_;
286 my $release = next_argument();
287 return "\nNew in version $release.\n" . $_;
290 sub do_cmd_versionchanged{
291 # one parameter: \versionchanged{version}
292 local($_) = @_;
293 my $explanation = next_optional_argument();
294 my $release = next_argument();
295 my $text = "\nChanged in version $release.\n";
296 if ($release) {
297 $text = "\nChanged in version $release:\n$explanation.\n";
299 return $text . $_;
303 # These function handle platform dependency tracking.
305 sub do_cmd_platform{
306 local($_) = @_;
307 my $platform = next_argument();
308 $ModulePlatforms{"<tt class='module'>$THIS_MODULE</tt>"} = $platform;
309 $platform = "Macintosh"
310 if $platform eq 'Mac';
311 return "\n<p class='availability'>Availability: <span"
312 . "\n class='platform'>$platform</span>.</p>\n" . $_;
315 $IGNORE_PLATFORM_ANNOTATION = '';
316 sub do_cmd_ignorePlatformAnnotation{
317 local($_) = @_;
318 $IGNORE_PLATFORM_ANNOTATION = next_argument();
319 return $_;
323 # index commands
325 $INDEX_SUBITEM = "";
327 sub get_indexsubitem{
328 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
331 sub do_cmd_setindexsubitem{
332 local($_) = @_;
333 $INDEX_SUBITEM = next_argument();
334 return $_;
337 sub do_cmd_withsubitem{
338 # We can't really do the right thing, because LaTeX2HTML doesn't
339 # do things in the right order, but we need to at least strip this stuff
340 # out, and leave anything that the second argument expanded out to.
342 local($_) = @_;
343 my $oldsubitem = $INDEX_SUBITEM;
344 $INDEX_SUBITEM = next_argument();
345 my $stuff = next_argument();
346 my $br_id = ++$globals{'max_id'};
347 my $marker = "$O$br_id$C";
348 return
349 $stuff
350 . "\\setindexsubitem$marker$oldsubitem$marker"
351 . $_;
354 # This is the prologue macro which is required to start writing the
355 # mod\jobname.idx file; we can just ignore it. (Defining this suppresses
356 # a warning that \makemodindex is unknown.)
358 sub do_cmd_makemodindex{ return @_[0]; }
360 # We're in the document subdirectory when this happens!
362 open(IDXFILE, '>index.dat') || die "\n$!\n";
363 open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
364 print INTLABELS "%internal_labels = ();\n";
365 print INTLABELS "1; # hack in case there are no entries\n\n";
367 # Using \0 for this is bad because we can't use common tools to work with the
368 # resulting files. Things like grep can be useful with this stuff!
370 $IDXFILE_FIELD_SEP = "\1";
372 sub write_idxfile{
373 my ($ahref, $str) = @_;
374 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
378 sub gen_link{
379 my($node,$target) = @_;
380 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
381 return "<a href='$node#$target'>";
384 sub add_index_entry{
385 # add an entry to the index structures; ignore the return value
386 my($str,$ahref) = @_;
387 $str = gen_index_id($str, '');
388 $index{$str} .= $ahref;
389 write_idxfile($ahref, $str);
392 sub new_link_info{
393 my $name = "l2h-" . ++$globals{'max_id'};
394 my $aname = "<a name='$name'>";
395 my $ahref = gen_link($CURRENT_FILE, $name);
396 return ($name, $aname, $ahref);
399 $IndexMacroPattern = '';
400 sub define_indexing_macro{
401 my $count = @_;
402 my $i = 0;
403 for (; $i < $count; ++$i) {
404 my $name = @_[$i];
405 my $cmd = "idx_cmd_$name";
406 die "\nNo function $cmd() defined!\n"
407 if (!defined &$cmd);
408 eval ("sub do_cmd_$name { return process_index_macros("
409 . "\@_[0], '$name'); }");
410 if (length($IndexMacroPattern) == 0) {
411 $IndexMacroPattern = "$name";
413 else {
414 $IndexMacroPattern .= "|$name";
419 $DEBUG_INDEXING = 0;
420 sub process_index_macros{
421 local($_) = @_;
422 my $cmdname = @_[1]; # This is what triggered us in the first place;
423 # we know it's real, so just process it.
424 my($name,$aname,$ahref) = new_link_info();
425 my $cmd = "idx_cmd_$cmdname";
426 print "\nIndexing: \\$cmdname"
427 if $DEBUG_INDEXING;
428 &$cmd($ahref); # modifies $_ and adds index entries
429 while (/^[\s\n]*\\($IndexMacroPattern)</) {
430 $cmdname = "$1";
431 print " \\$cmdname"
432 if $DEBUG_INDEXING;
433 $cmd = "idx_cmd_$cmdname";
434 if (!defined &$cmd) {
435 last;
437 else {
438 s/^[\s\n]*\\$cmdname//;
439 &$cmd($ahref);
442 return "$aname$anchor_invisible_mark</a>" . $_;
445 define_indexing_macro('index');
446 sub idx_cmd_index{
447 my $str = next_argument();
448 add_index_entry("$str", @_[0]);
451 define_indexing_macro('kwindex');
452 sub idx_cmd_kwindex{
453 my $str = next_argument();
454 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
455 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
458 define_indexing_macro('indexii');
459 sub idx_cmd_indexii{
460 my $str1 = next_argument();
461 my $str2 = next_argument();
462 add_index_entry("$str1!$str2", @_[0]);
463 add_index_entry("$str2!$str1", @_[0]);
466 define_indexing_macro('indexiii');
467 sub idx_cmd_indexiii{
468 my $str1 = next_argument();
469 my $str2 = next_argument();
470 my $str3 = next_argument();
471 add_index_entry("$str1!$str2 $str3", @_[0]);
472 add_index_entry("$str2!$str3, $str1", @_[0]);
473 add_index_entry("$str3!$str1 $str2", @_[0]);
476 define_indexing_macro('indexiv');
477 sub idx_cmd_indexiv{
478 my $str1 = next_argument();
479 my $str2 = next_argument();
480 my $str3 = next_argument();
481 my $str4 = next_argument();
482 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
483 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
484 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
485 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
488 define_indexing_macro('ttindex');
489 sub idx_cmd_ttindex{
490 my $str = next_argument();
491 my $entry = $str . get_indexsubitem();
492 add_index_entry($entry, @_[0]);
495 sub my_typed_index_helper{
496 my($word,$ahref) = @_;
497 my $str = next_argument();
498 add_index_entry("$str $word", $ahref);
499 add_index_entry("$word!$str", $ahref);
502 define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
503 sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
504 sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
505 sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
506 sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
508 define_indexing_macro('bifuncindex');
509 sub idx_cmd_bifuncindex{
510 my $str = next_argument();
511 add_index_entry("<tt class='function'>$str()</tt> (built-in function)",
512 @_[0]);
516 sub make_mod_index_entry{
517 my($str,$define) = @_;
518 my($name,$aname,$ahref) = new_link_info();
519 # equivalent of add_index_entry() using $define instead of ''
520 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
521 if ($define eq 'DEF');
522 $str = gen_index_id($str, $define);
523 $index{$str} .= $ahref;
524 write_idxfile($ahref, $str);
526 if ($define eq 'DEF') {
527 # add to the module index
528 $str =~ /(<tt.*<\/tt>)/;
529 my $nstr = $1;
530 $Modules{$nstr} .= $ahref;
532 return "$aname$anchor_invisible_mark</a>";
536 $THIS_MODULE = '';
537 $THIS_CLASS = '';
539 sub define_module{
540 my($word,$name) = @_;
541 my $section_tag = join('', @curr_sec_id);
542 if ($word ne "built-in" && $word ne "extension"
543 && $word ne "standard" && $word ne "") {
544 write_warnings("Bad module type '$word'"
545 . " for \\declaremodule (module $name)");
546 $word = "";
548 $word = "$word " if $word;
549 $THIS_MODULE = "$name";
550 $INDEX_SUBITEM = "(in $name)";
551 print "[$name]";
552 return make_mod_index_entry(
553 "<tt class='module'>$name</tt> (${word}module)", 'DEF');
556 sub my_module_index_helper{
557 local($word, $_) = @_;
558 my $name = next_argument();
559 return define_module($word, $name) . $_;
562 sub do_cmd_modindex{ return my_module_index_helper('', @_); }
563 sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
564 sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
565 sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
567 sub ref_module_index_helper{
568 my($word, $ahref) = @_;
569 my $str = next_argument();
570 $word = "$word " if $word;
571 $str = "<tt class='module'>$str</tt> (${word}module)";
572 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
573 # just inline it all here
574 $str = gen_index_id($str, 'REF');
575 $index{$str} .= $ahref;
576 write_idxfile($ahref, $str);
579 # these should be adjusted a bit....
580 define_indexing_macro('refmodindex', 'refbimodindex',
581 'refexmodindex', 'refstmodindex');
582 sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
583 sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
584 sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
585 sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
587 sub do_cmd_nodename{ return do_cmd_label(@_); }
589 sub init_myformat{
590 # $anchor_invisible_mark = '';
591 $anchor_mark = '';
592 $icons{'anchor_mark'} = '';
594 init_myformat();
596 # Create an index entry, but include the string in the target anchor
597 # instead of the dummy filler.
599 sub make_str_index_entry{
600 my($str) = @_;
601 my($name,$aname,$ahref) = new_link_info();
602 add_index_entry($str, $ahref);
603 return "$aname$str</a>";
606 $REFCOUNTS_LOADED = 0;
608 sub load_refcounts{
609 $REFCOUNTS_LOADED = 1;
611 use File::Basename;
612 my $myname, $mydir, $myext;
613 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
614 chop $mydir; # remove trailing '/'
615 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
616 chop $mydir; # remove trailing '/'
617 $mydir = getcwd() . "$dd$mydir"
618 unless $mydir =~ s|^/|/|;
619 local $_;
620 my $filename = "$mydir${dd}api${dd}refcounts.dat";
621 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
622 print "[loading API refcount data]";
623 while (<REFCOUNT_FILE>) {
624 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
625 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
626 #print "\n$func($param) --> $count";
627 $REFCOUNTS{"$func:$param"} = $count;
632 sub get_refcount{
633 my ($func, $param) = @_;
634 load_refcounts()
635 unless $REFCOUNTS_LOADED;
636 return $REFCOUNTS{"$func:$param"};
639 sub do_env_cfuncdesc{
640 local($_) = @_;
641 my $return_type = next_argument();
642 my $function_name = next_argument();
643 my $arg_list = next_argument();
644 my $idx = make_str_index_entry(
645 "<tt class='cfunction'>$function_name()</tt>" . get_indexsubitem());
646 $idx =~ s/ \(.*\)//;
647 $idx =~ s/\(\)//; # ???? - why both of these?
648 my $result_rc = get_refcount($function_name, '');
649 my $rcinfo = '';
650 if ($result_rc eq '+1') {
651 $rcinfo = 'New reference';
653 elsif ($result_rc eq '0') {
654 $rcinfo = 'Borrowed reference';
656 elsif ($result_rc eq 'null') {
657 $rcinfo = 'Always <tt class="constant">NULL</tt>';
659 if ($rcinfo ne '') {
660 $rcinfo = ( "\n<div class=\"refcount-info\">"
661 . "\n <span class=\"label\">Return value:</span>"
662 . "\n <span class=\"value\">$rcinfo.</span>"
663 . "\n</div>");
665 return "<dl><dt>$return_type <b>$idx</b> (<var>$arg_list</var>)\n<dd>"
666 . $rcinfo
667 . $_
668 . '</dl>';
671 sub do_env_csimplemacrodesc{
672 local($_) = @_;
673 my $name = next_argument();
674 my $idx = make_str_index_entry("<tt class='macro'>$name</tt>");
675 return "<dl><dt><b>$idx</b>\n<dd>"
676 . $_
677 . '</dl>'
680 sub do_env_ctypedesc{
681 local($_) = @_;
682 my $index_name = next_optional_argument();
683 my $type_name = next_argument();
684 $index_name = $type_name
685 unless $index_name;
686 my($name,$aname,$ahref) = new_link_info();
687 add_index_entry("<tt class='ctype'>$index_name</tt> (C type)", $ahref);
688 return "<dl><dt><b><tt class='ctype'>$aname$type_name</a></tt></b>\n<dd>"
689 . $_
690 . '</dl>'
693 sub do_env_cvardesc{
694 local($_) = @_;
695 my $var_type = next_argument();
696 my $var_name = next_argument();
697 my $idx = make_str_index_entry("<tt class='cdata'>$var_name</tt>"
698 . get_indexsubitem());
699 $idx =~ s/ \(.*\)//;
700 return "<dl><dt>$var_type <b>$idx</b>\n"
701 . '<dd>'
702 . $_
703 . '</dl>';
706 sub do_env_funcdesc{
707 local($_) = @_;
708 my $function_name = next_argument();
709 my $arg_list = next_argument();
710 my $idx = make_str_index_entry("<tt class='function'>$function_name()</tt>"
711 . get_indexsubitem());
712 $idx =~ s/ \(.*\)//;
713 $idx =~ s/\(\)<\/tt>/<\/tt>/;
714 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
717 sub do_env_funcdescni{
718 local($_) = @_;
719 my $function_name = next_argument();
720 my $arg_list = next_argument();
721 return "<dl><dt><b><tt class='function'>$function_name</tt></b>"
722 . " (<var>$arg_list</var>)\n"
723 . '<dd>'
724 . $_
725 . '</dl>';
728 sub do_cmd_funcline{
729 local($_) = @_;
730 my $function_name = next_argument();
731 my $arg_list = next_argument();
732 my $prefix = "<tt class='function'>$function_name()</tt>";
733 my $idx = make_str_index_entry($prefix . get_indexsubitem());
734 $prefix =~ s/\(\)//;
736 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
739 sub do_cmd_funclineni{
740 local($_) = @_;
741 my $function_name = next_argument();
742 my $arg_list = next_argument();
743 my $prefix = "<tt class='function'>$function_name</tt>";
745 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
748 # Change this flag to index the opcode entries. I don't think it's very
749 # useful to index them, since they're only presented to describe the dis
750 # module.
752 $INDEX_OPCODES = 0;
754 sub do_env_opcodedesc{
755 local($_) = @_;
756 my $opcode_name = next_argument();
757 my $arg_list = next_argument();
758 my $idx;
759 if ($INDEX_OPCODES) {
760 $idx = make_str_index_entry("<tt class='opcode'>$opcode_name</tt>"
761 . " (byte code instruction)");
762 $idx =~ s/ \(byte code instruction\)//;
764 else {
765 $idx = "<tt class='opcode'>$opcode_name</tt>";
767 my $stuff = "<dl><dt><b>$idx</b>";
768 if ($arg_list) {
769 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
771 return $stuff . "\n<dd>" . $_ . '</dl>';
774 sub do_env_datadesc{
775 local($_) = @_;
776 my $dataname = next_argument();
777 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
778 $idx =~ s/ \(.*\)//;
779 return "<dl><dt><b>$idx</b>\n<dd>"
780 . $_
781 . '</dl>';
784 sub do_env_datadescni{
785 local($_) = @_;
786 my $idx = next_argument();
787 if (! $STRING_INDEX_TT) {
788 $idx = "<tt>$idx</tt>";
790 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
793 sub do_cmd_dataline{
794 local($_) = @_;
795 my $data_name = next_argument();
796 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
797 $idx =~ s/ \(.*\)//;
798 return "<dt><b>$idx</b><dd>" . $_;
801 sub do_cmd_datalineni{
802 local($_) = @_;
803 my $data_name = next_argument();
804 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
807 sub do_env_excdesc{
808 local($_) = @_;
809 my $excname = next_argument();
810 my $idx = make_str_index_entry("<tt class='exception'>$excname</tt>");
811 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>'
814 sub do_env_fulllineitems{ return do_env_itemize(@_); }
817 sub do_env_classdesc{
818 local($_) = @_;
819 $THIS_CLASS = next_argument();
820 my $arg_list = next_argument();
821 $idx = make_str_index_entry(
822 "<tt class='class'>$THIS_CLASS</tt> (class in $THIS_MODULE)" );
823 $idx =~ s/ \(.*\)//;
824 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
828 sub do_env_methoddesc{
829 local($_) = @_;
830 my $class_name = next_optional_argument();
831 $class_name = $THIS_CLASS
832 unless $class_name;
833 my $method = next_argument();
834 my $arg_list = next_argument();
835 my $extra = '';
836 if ($class_name) {
837 $extra = " ($class_name method)";
839 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
840 $idx =~ s/ \(.*\)//;
841 $idx =~ s/\(\)//;
842 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
846 sub do_cmd_methodline{
847 local($_) = @_;
848 my $class_name = next_optional_argument();
849 $class_name = $THIS_CLASS
850 unless $class_name;
851 my $method = next_argument();
852 my $arg_list = next_argument();
853 my $extra = '';
854 if ($class_name) {
855 $extra = " ($class_name method)";
857 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
858 $idx =~ s/ \(.*\)//;
859 $idx =~ s/\(\)//;
860 return "<dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>"
861 . $_;
865 sub do_cmd_methodlineni{
866 local($_) = @_;
867 next_optional_argument();
868 my $method = next_argument();
869 my $arg_list = next_argument();
870 return "<dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
871 . $_;
874 sub do_env_methoddescni{
875 local($_) = @_;
876 next_optional_argument();
877 my $method = next_argument();
878 my $arg_list = next_argument();
879 return "<dl><dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
880 . $_
881 . '</dl>';
885 sub do_env_memberdesc{
886 local($_) = @_;
887 my $class = next_optional_argument();
888 my $member = next_argument();
889 $class = $THIS_CLASS
890 unless $class;
891 my $extra = '';
892 $extra = " ($class attribute)"
893 if ($class ne '');
894 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
895 $idx =~ s/ \(.*\)//;
896 $idx =~ s/\(\)//;
897 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
901 sub do_cmd_memberline{
902 local($_) = @_;
903 my $class = next_optional_argument();
904 my $member = next_argument();
905 $class = $THIS_CLASS
906 unless $class;
907 my $extra = '';
908 $extra = " ($class attribute)"
909 if ($class ne '');
910 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
911 $idx =~ s/ \(.*\)//;
912 $idx =~ s/\(\)//;
913 return "<dt><b>$idx</b><dd>" . $_;
916 sub do_env_memberdescni{
917 local($_) = @_;
918 next_optional_argument();
919 my $member = next_argument();
920 return "<dl><dt><b><tt class='member'>$member</tt></b>\n<dd>"
921 . $_
922 . '</dl>';
926 sub do_cmd_memberlineni{
927 local($_) = @_;
928 next_optional_argument();
929 my $member = next_argument();
930 return "<dt><b><tt class='member'>$member</tt></b><dd>" . $_;
933 @col_aligns = ('<td>', '<td>', '<td>', '<td>');
935 $TABLE_HEADER_BGCOLOR = $NAV_BGCOLOR;
937 sub fix_font{
938 # do a little magic on a font name to get the right behavior in the first
939 # column of the output table
940 my $font = @_[0];
941 if ($font eq 'textrm') {
942 $font = '';
944 elsif ($font eq 'file' || $font eq 'filenq') {
945 $font = 'tt class="file"';
947 elsif ($font eq 'member') {
948 $font = 'tt class="member"';
950 elsif ($font eq 'constant') {
951 $font = 'tt class="constant"';
953 elsif ($font eq 'kbd') {
954 $font = 'kbd';
956 return $font;
959 sub figure_column_alignment{
960 my $a = @_[0];
961 my $mark = substr($a, 0, 1);
962 my $r = '';
963 if ($mark eq 'c')
964 { $r = ' align="center"'; }
965 elsif ($mark eq 'r')
966 { $r = ' align="right"'; }
967 elsif ($mark eq 'l')
968 { $r = ' align="left"'; }
969 elsif ($mark eq 'p')
970 { $r = ' align="left"'; }
971 return $r;
974 sub setup_column_alignments{
975 local($_) = @_;
976 my($s1,$s2,$s3,$s4) = split(/[|]/,$_);
977 my $a1 = figure_column_alignment($s1);
978 my $a2 = figure_column_alignment($s2);
979 my $a3 = figure_column_alignment($s3);
980 my $a4 = figure_column_alignment($s4);
981 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
982 $col_aligns[1] = "<td$a2>";
983 $col_aligns[2] = "<td$a3>";
984 $col_aligns[3] = "<td$a4>";
985 # return the aligned header start tags
986 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>");
989 sub get_table_col1_fonts{
990 my $font = $globals{'lineifont'};
991 my ($sfont,$efont) = ('', '');
992 if ($font) {
993 $sfont = "<$font>";
994 $efont = "</$font>";
995 $efont =~ s/ .*>/>/;
997 return ($font, $sfont, $efont);
1000 sub do_env_tableii{
1001 local($_) = @_;
1002 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
1003 my $font = fix_font(next_argument());
1004 my $h1 = next_argument();
1005 my $h2 = next_argument();
1006 s/[\s\n]+//;
1007 $globals{'lineifont'} = $font;
1008 my $a1 = $col_aligns[0];
1009 my $a2 = $col_aligns[1];
1010 s/\\lineii</\\lineii[$a1|$a2]</g;
1011 return '<table border align="center" style="border-collapse: collapse">'
1012 . "\n <thead>"
1013 . "\n <tr$TABLE_HEADER_BGCOLOR>"
1014 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1015 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1016 . "\n </thead>"
1017 . "\n <tbody valign='baseline'>"
1018 . $_
1019 . "\n </tbody>"
1020 . "\n</table>";
1023 sub do_cmd_lineii{
1024 local($_) = @_;
1025 my $aligns = next_optional_argument();
1026 my $c1 = next_argument();
1027 my $c2 = next_argument();
1028 s/[\s\n]+//;
1029 my($font,$sfont,$efont) = get_table_col1_fonts();
1030 $c2 = '&nbsp;' if ($c2 eq '');
1031 my($c1align,$c2align) = split('\|', $aligns);
1032 my $padding = '';
1033 if ($c1align =~ /align="right"/) {
1034 $padding = '&nbsp;';
1036 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1037 . " $c2align$c2</td>"
1038 . $_;
1041 sub do_env_tableiii{
1042 local($_) = @_;
1043 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
1044 my $font = fix_font(next_argument());
1045 my $h1 = next_argument();
1046 my $h2 = next_argument();
1047 my $h3 = next_argument();
1048 s/[\s\n]+//;
1049 $globals{'lineifont'} = $font;
1050 my $a1 = $col_aligns[0];
1051 my $a2 = $col_aligns[1];
1052 my $a3 = $col_aligns[2];
1053 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1054 return '<table border align="center" style="border-collapse: collapse">'
1055 . "\n <thead>"
1056 . "\n <tr$TABLE_HEADER_BGCOLOR>"
1057 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1058 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1059 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1060 . "\n </thead>"
1061 . "\n <tbody valign='baseline'>"
1062 . $_
1063 . "\n </tbody>"
1064 . "\n</table>";
1067 sub do_cmd_lineiii{
1068 local($_) = @_;
1069 my $aligns = next_optional_argument();
1070 my $c1 = next_argument();
1071 my $c2 = next_argument();
1072 my $c3 = next_argument();
1073 s/[\s\n]+//;
1074 my($font,$sfont,$efont) = get_table_col1_fonts();
1075 $c3 = '&nbsp;' if ($c3 eq '');
1076 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1077 my $padding = '';
1078 if ($c1align =~ /align="right"/) {
1079 $padding = '&nbsp;';
1081 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1082 . " $c2align$c2</td>\n"
1083 . " $c3align$c3</td>"
1084 . $_;
1087 sub do_env_tableiv{
1088 local($_) = @_;
1089 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
1090 my $font = fix_font(next_argument());
1091 my $h1 = next_argument();
1092 my $h2 = next_argument();
1093 my $h3 = next_argument();
1094 my $h4 = next_argument();
1095 s/[\s\n]+//;
1096 $globals{'lineifont'} = $font;
1097 my $a1 = $col_aligns[0];
1098 my $a2 = $col_aligns[1];
1099 my $a3 = $col_aligns[2];
1100 my $a4 = $col_aligns[3];
1101 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1102 return '<table border align="center" style="border-collapse: collapse">'
1103 . "\n <thead>"
1104 . "\n <tr$TABLE_HEADER_BGCOLOR>"
1105 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1106 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1107 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1108 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1109 . "\n </thead>"
1110 . "\n <tbody valign='baseline'>"
1111 . $_
1112 . "\n </tbody>"
1113 . "\n</table>";
1116 sub do_cmd_lineiv{
1117 local($_) = @_;
1118 my $aligns = next_optional_argument();
1119 my $c1 = next_argument();
1120 my $c2 = next_argument();
1121 my $c3 = next_argument();
1122 my $c4 = next_argument();
1123 s/[\s\n]+//;
1124 my($font,$sfont,$efont) = get_table_col1_fonts();
1125 $c4 = '&nbsp;' if ($c4 eq '');
1126 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1127 my $padding = '';
1128 if ($c1align =~ /align="right"/) {
1129 $padding = '&nbsp;';
1131 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1132 . " $c2align$c2</td>\n"
1133 . " $c3align$c3</td>\n"
1134 . " $c4align$c4</td>"
1135 . $_;
1138 sub do_cmd_maketitle {
1139 local($_) = @_;
1140 my $the_title = "\n<div class='titlepage'><center>";
1141 if ($t_title) {
1142 $the_title .= "\n<h1>$t_title</h1>";
1143 } else { write_warnings("\nThis document has no title."); }
1144 if ($t_author) {
1145 if ($t_authorURL) {
1146 my $href = translate_commands($t_authorURL);
1147 $href = make_named_href('author', $href,
1148 "<b><font size='+2'>$t_author</font></b>");
1149 $the_title .= "\n<p>$href</p>";
1150 } else {
1151 $the_title .= ("\n<p><b><font size='+2'>$t_author</font></b></p>");
1153 } else { write_warnings("\nThere is no author for this document."); }
1154 if ($t_institute) {
1155 $the_title .= "\n<p>$t_institute</p>";}
1156 if ($DEVELOPER_ADDRESS) {
1157 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";}
1158 if ($t_affil) {
1159 $the_title .= "\n<p><i>$t_affil</i></p>";}
1160 if ($t_date) {
1161 $the_title .= "\n<p><strong>$t_date</strong>";
1162 if ($PYTHON_VERSION) {
1163 $the_title .= "<br><strong>Release $PYTHON_VERSION</strong>";}
1164 $the_title .= "</p>"
1166 if ($t_address) {
1167 $the_title .= "\n<p>$t_address</p>";
1168 } else { $the_title .= "\n<p>"}
1169 if ($t_email) {
1170 $the_title .= "\n<p>$t_email</p>";
1171 }# else { $the_title .= "</p>" }
1172 $the_title .= "\n</center></div>";
1173 return $the_title . $_ ;
1178 # Module synopsis support
1181 require SynopsisTable;
1183 sub get_chapter_id(){
1184 my $id = do_cmd_thechapter('');
1185 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1186 $id =~ s/\.//;
1187 return $id;
1190 %ModuleSynopses = ('chapter' => 'SynopsisTable instance');
1192 sub get_synopsis_table($){
1193 my($chap) = @_;
1194 my $st = $ModuleSynopses{$chap};
1195 my $key;
1196 foreach $key (keys %ModuleSynopses) {
1197 if ($key eq $chap) {
1198 return $ModuleSynopses{$chap};
1201 $st = SynopsisTable->new();
1202 $ModuleSynopses{$chap} = $st;
1203 return $st;
1206 sub do_cmd_moduleauthor{
1207 local($_) = @_;
1208 next_argument();
1209 next_argument();
1210 return $_;
1213 sub do_cmd_sectionauthor{
1214 local($_) = @_;
1215 next_argument();
1216 next_argument();
1217 return $_;
1220 sub do_cmd_declaremodule{
1221 local($_) = @_;
1222 my $key = next_optional_argument();
1223 my $type = next_argument();
1224 my $name = next_argument();
1225 my $st = get_synopsis_table(get_chapter_id());
1227 $key = $name unless $key;
1228 $type = 'built-in' if $type eq 'builtin';
1229 $st->declare($name, $key, $type);
1230 define_module($type, $name);
1231 return anchor_label("module-$key",$CURRENT_FILE,$_)
1234 sub do_cmd_modulesynopsis{
1235 local($_) = @_;
1236 my $st = get_synopsis_table(get_chapter_id());
1237 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
1238 return $_;
1241 sub do_cmd_localmoduletable{
1242 local($_) = @_;
1243 my $chap = get_chapter_id();
1244 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
1247 sub process_all_localmoduletables{
1248 while (/<tex2html-localmoduletable><(\d+)>/) {
1249 my $match = $&;
1250 my $chap = $1;
1251 my $st = get_synopsis_table($chap);
1252 my $data = $st->tohtml();
1253 s/$match/$data/;
1256 sub process_python_state{
1257 process_all_localmoduletables();
1262 # "See also:" -- references placed at the end of a \section
1265 sub do_env_seealso{
1266 return "<div class='seealso'>\n "
1267 . "<p class='heading'><b>See Also:</b></p>\n"
1268 . @_[0]
1269 . '</div>';
1272 sub do_cmd_seemodule{
1273 # Insert the right magic to jump to the module definition. This should
1274 # work most of the time, at least for repeat builds....
1275 local($_) = @_;
1276 my $key = next_optional_argument();
1277 my $module = next_argument();
1278 my $text = next_argument();
1279 my $period = '.';
1280 $key = $module
1281 unless $key;
1282 if ($text =~ /\.$/) {
1283 $period = '';
1285 return '<dl compact class="seemodule">'
1286 . "\n <dt>Module <b><tt class='module'><a href='module-$key.html'>"
1287 . "$module</a></tt>:</b>"
1288 . "\n <dd>$text$period\n </dl>"
1289 . $_;
1292 sub do_cmd_seerfc{
1293 local($_) = @_;
1294 my $rfcnum = next_argument();
1295 my $title = next_argument();
1296 my $text = next_argument();
1297 my $url = get_rfc_url($rfcnum);
1298 return '<dl compact class="seerfc">'
1299 . "\n <dt><a href=\"$url\""
1300 . "\n title=\"$title\""
1301 . "\n >RFC $rfcnum, <em>$title</em></a>:"
1302 . "\n <dd>$text\n </dl>"
1303 . $_;
1306 sub do_cmd_seeurl{
1307 local($_) = @_;
1308 my $url = next_argument();
1309 my $text = next_argument();
1310 return '<dl compact class="seeurl">'
1311 . "\n <dt><a href=\"$url\""
1312 . "\n class=\"url\">$url</a>"
1313 . "\n <dd>$text\n </dl>"
1314 . $_;
1317 sub do_cmd_seetext{
1318 local($_) = @_;
1319 my $content = next_argument();
1320 return '<div class="seetext"><p>' . $content . '</div>' . $_;
1325 # Definition list support.
1328 sub do_env_definitions{
1329 return "<dl class='definitions'>" . @_[0] . "</dl>\n";
1332 sub do_cmd_term{
1333 local($_) = @_;
1334 my $term = next_argument();
1335 my($name,$aname,$ahref) = new_link_info();
1336 # could easily add an index entry here...
1337 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
1341 process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
1342 code # {}
1343 declaremodule # [] # {} # {}
1344 memberline # [] # {}
1345 methodline # [] # {} # {}
1346 modulesynopsis # {}
1347 platform # {}
1348 samp # {}
1349 setindexsubitem # {}
1350 withsubitem # {} # {}
1351 _RAW_ARG_DEFERRED_CMDS_
1354 1; # This must be the last line