This commit was manufactured by cvs2svn to create tag 'r221c1'.
[python/dscho.git] / Doc / perl / python.perl
blobe54015dc5bf7e63041e95e1db83ff1e7833adbcf
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;
11 use File::Basename;
14 sub next_argument{
15 my $param;
16 $param = missing_braces()
17 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
18 ||(s/$next_pair_rx/$param=$2;''/eo));
19 return $param;
22 sub next_optional_argument{
23 my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
24 s/$rx/$param=$2;''/eo;
25 return $param;
28 sub make_icon_filename($){
29 my($myname, $mydir, $myext) = fileparse(@_[0], '\..*');
30 chop $mydir;
31 if ($mydir eq '.') {
32 $mydir = $ICONSERVER;
34 $myext = ".$IMAGE_TYPE"
35 unless $myext;
36 return "$mydir$dd$myname$myext";
39 sub get_link_icon($){
40 my $url = @_[0];
41 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
42 # absolute URL; assume it points off-site
43 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
44 return (" <img src=\"$icon\"\n"
45 . ' border="0" class="offsitelink"'
46 . ($OFF_SITE_LINK_ICON_HEIGHT
47 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
48 : '')
49 . ($OFF_SITE_LINK_ICON_WIDTH
50 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
51 : '')
52 . " alt=\"[off-site link]\"\n"
53 . " >");
55 return '';
58 # This is a fairly simple hack; it supports \let when it is used to create
59 # (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
60 # Many possible uses of \let aren't supported or aren't supported correctly.
62 sub do_cmd_let{
63 local($_) = @_;
64 my $matched = 0;
65 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
66 if ($matched) {
67 my($new, $old) = ($1, $3);
68 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
69 print "\ndefining handler for \\$new using \\$old\n";
71 else {
72 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
73 if ($matched) {
74 my($new, $char) = ($1, $3);
75 eval "sub do_cmd_$new { \"\\$char\" . \@_[0]; }";
76 print "\ndefining handler for \\$new to insert '$char'\n";
78 else {
79 write_warnings("Could not interpret \\let construct...");
82 return $_;
86 # the older version of LaTeX2HTML we use doesn't support this, but we use it:
88 sub do_cmd_textasciitilde{ '&#126;' . @_[0]; }
89 sub do_cmd_textasciicircum{ '^' . @_[0]; }
90 sub do_cmd_textbar{ '|' . @_[0]; }
91 sub do_cmd_infinity{ '&infin;' . @_[0]; }
92 sub do_cmd_plusminus{ '&plusmn;' . @_[0]; }
93 sub do_cmd_menuselection{ @_[0]; }
94 sub do_cmd_sub{ ' > ' . @_[0]; }
97 # words typeset in a special way (not in HTML though)
99 sub do_cmd_ABC{ 'ABC' . @_[0]; }
100 sub do_cmd_UNIX{ 'Unix'. @_[0]; }
101 sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
102 sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
103 sub do_cmd_C{ 'C' . @_[0]; }
104 sub do_cmd_Cpp{ 'C++' . @_[0]; }
105 sub do_cmd_EOF{ 'EOF' . @_[0]; }
106 sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
108 sub do_cmd_e{ '&#92;' . @_[0]; }
110 $DEVELOPER_ADDRESS = '';
111 $SHORT_VERSION = '';
112 $RELEASE_INFO = '';
113 $PACKAGE_VERSION = '';
115 sub do_cmd_version{ $PACKAGE_VERSION . @_[0]; }
116 sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
117 sub do_cmd_release{
118 local($_) = @_;
119 $PACKAGE_VERSION = next_argument();
120 return $_;
123 sub do_cmd_setreleaseinfo{
124 local($_) = @_;
125 $RELEASE_INFO = next_argument();
126 return $_;
129 sub do_cmd_setshortversion{
130 local($_) = @_;
131 $SHORT_VERSION = next_argument();
132 return $_;
135 sub do_cmd_authoraddress{
136 local($_) = @_;
137 $DEVELOPER_ADDRESS = next_argument();
138 return $_;
141 #sub do_cmd_developer{ do_cmd_author(@_[0]); }
142 #sub do_cmd_developers{ do_cmd_author(@_[0]); }
143 #sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
145 sub do_cmd_hackscore{
146 local($_) = @_;
147 next_argument();
148 return '_' . $_;
151 sub use_wrappers{
152 local($_,$before,$after) = @_;
153 my $stuff = next_argument();
154 return $before . $stuff . $after . $_;
157 $IN_DESC_HANDLER = 0;
158 sub do_cmd_optional{
159 if ($IN_DESC_HANDLER) {
160 return use_wrappers(@_[0], "</var><big>\[</big><var>",
161 "</var><big>\]</big><var>");
163 else {
164 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
168 # Logical formatting (some based on texinfo), needs to be converted to
169 # minimalist HTML. The "minimalist" is primarily to reduce the size of
170 # output files for users that read them over the network rather than
171 # from local repositories.
173 # \file and \samp are at the end of this file since they screw up fontlock.
175 sub do_cmd_pytype{ return @_[0]; }
176 sub do_cmd_makevar{
177 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
178 sub do_cmd_code{
179 return use_wrappers(@_[0], '<code>', '</code>'); }
180 sub do_cmd_module{
181 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
182 sub do_cmd_keyword{
183 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
184 sub do_cmd_exception{
185 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
186 sub do_cmd_class{
187 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
188 sub do_cmd_function{
189 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
190 sub do_cmd_constant{
191 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
192 sub do_cmd_member{
193 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
194 sub do_cmd_method{
195 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
196 sub do_cmd_cfunction{
197 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
198 sub do_cmd_cdata{
199 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
200 sub do_cmd_ctype{
201 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
202 sub do_cmd_regexp{
203 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
204 sub do_cmd_character{
205 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
206 sub do_cmd_program{
207 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
208 sub do_cmd_programopt{
209 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
210 sub do_cmd_longprogramopt{
211 # note that the --- will be later converted to -- by LaTeX2HTML
212 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
213 sub do_cmd_email{
214 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
215 sub do_cmd_mailheader{
216 return use_wrappers(@_[0], '<span class="mailheader">', ':</span>'); }
217 sub do_cmd_mimetype{
218 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
219 sub do_cmd_var{
220 return use_wrappers(@_[0], "<var>", "</var>"); }
221 sub do_cmd_dfn{
222 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
223 sub do_cmd_emph{
224 return use_wrappers(@_[0], '<i>', '</i>'); }
225 sub do_cmd_file{
226 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
227 sub do_cmd_filenq{
228 return do_cmd_file(@_[0]); }
229 sub do_cmd_samp{
230 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
231 sub do_cmd_kbd{
232 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
233 sub do_cmd_strong{
234 return use_wrappers(@_[0], '<b>', '</b>'); }
235 sub do_cmd_textbf{
236 return use_wrappers(@_[0], '<b>', '</b>'); }
237 sub do_cmd_textit{
238 return use_wrappers(@_[0], '<i>', '</i>'); }
239 # This can be changed/overridden for translations:
240 %NoticeNames = ('note' => 'Note:',
241 'warning' => 'Warning:',
244 sub do_cmd_note{
245 my $label = $NoticeNames{'note'};
246 return use_wrappers(
247 @_[0],
248 "<span class=\"note\"><b class=\"label\">$label</b>\n",
249 '</span>'); }
250 sub do_cmd_warning{
251 my $label = $NoticeNames{'warning'};
252 return use_wrappers(
253 @_[0],
254 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
255 '</span>'); }
257 sub do_env_notice{
258 local($_) = @_;
259 my $notice = next_optional_argument();
260 if (!$notice) {
261 $notice = 'note';
263 my $label = $NoticeNames{$notice};
264 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
265 . $_
266 . '</div>');
269 sub do_cmd_moreargs{
270 return '...' . @_[0]; }
271 sub do_cmd_unspecified{
272 return '...' . @_[0]; }
275 sub do_cmd_refmodule{
276 # Insert the right magic to jump to the module definition.
277 local($_) = @_;
278 my $key = next_optional_argument();
279 my $module = next_argument();
280 $key = $module
281 unless $key;
282 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
283 . $_;
286 sub do_cmd_newsgroup{
287 local($_) = @_;
288 my $newsgroup = next_argument();
289 my $icon = get_link_icon("news:$newsgroup");
290 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
291 . "$newsgroup$icon</a>");
292 return $stuff . $_;
295 sub do_cmd_envvar{
296 local($_) = @_;
297 my $envvar = next_argument();
298 my($name,$aname,$ahref) = new_link_info();
299 # The <tt> here is really to keep buildindex.py from making
300 # the variable name case-insensitive.
301 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
302 $ahref);
303 add_index_entry("$envvar (environment variable)", $ahref);
304 $aname =~ s/<a/<a class="envvar"/;
305 return "$aname$envvar</a>" . $_;
308 sub do_cmd_url{
309 # use the URL as both text and hyperlink
310 local($_) = @_;
311 my $url = next_argument();
312 my $icon = get_link_icon($url);
313 $url =~ s/~/&#126;/g;
314 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
317 sub do_cmd_manpage{
318 # two parameters: \manpage{name}{section}
319 local($_) = @_;
320 my $page = next_argument();
321 my $section = next_argument();
322 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
325 $PEP_FORMAT = "http://python.sourceforge.net/peps/pep-%04d.html";
326 #$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
327 $RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
329 sub get_rfc_url($$){
330 my($rfcnum, $format) = @_;
331 return sprintf($format, $rfcnum);
334 sub do_cmd_pep{
335 local($_) = @_;
336 my $rfcnumber = next_argument();
337 my $id = "rfcref-" . ++$global{'max_id'};
338 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
339 my $icon = get_link_icon($href);
340 # Save the reference
341 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
342 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
343 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
344 . "$icon</a>" . $_);
347 sub do_cmd_rfc{
348 local($_) = @_;
349 my $rfcnumber = next_argument();
350 my $id = "rfcref-" . ++$global{'max_id'};
351 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
352 my $icon = get_link_icon($href);
353 # Save the reference
354 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
355 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
356 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
357 . "$icon</a>" . $_);
360 sub do_cmd_ulink{
361 local($_) = @_;
362 my $text = next_argument();
363 my $url = next_argument();
364 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
367 sub do_cmd_citetitle{
368 local($_) = @_;
369 my $url = next_optional_argument();
370 my $title = next_argument();
371 my $icon = get_link_icon($url);
372 my $repl = '';
373 if ($url) {
374 $repl = ("<em class=\"citetitle\"><a\n"
375 . " href=\"$url\"\n"
376 . " title=\"$title\"\n"
377 . " >$title$icon</a></em>");
379 else {
380 $repl = "<em class=\"citetitle\"\n >$title</em>";
382 return $repl . $_;
385 sub do_cmd_deprecated{
386 # two parameters: \deprecated{version}{whattodo}
387 local($_) = @_;
388 my $release = next_argument();
389 my $reason = next_argument();
390 return ('<div class="versionnote">'
391 . "<b>Deprecated since release $release.</b>"
392 . "\n$reason</div><p>"
393 . $_);
396 sub versionnote{
397 # one or two parameters: \versionnote[explanation]{version}
398 my $type = @_[0];
399 local $_ = @_[1];
400 my $explanation = next_optional_argument();
401 my $release = next_argument();
402 my $text = "$type in version $release.";
403 if ($explanation) {
404 $text = "$type in version $release:\n$explanation.";
406 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
409 sub do_cmd_versionadded{
410 return versionnote('New', @_);
413 sub do_cmd_versionchanged{
414 return versionnote('Changed', @_);
418 # These function handle platform dependency tracking.
420 sub do_cmd_platform{
421 local($_) = @_;
422 my $platform = next_argument();
423 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
424 $platform = "Macintosh"
425 if $platform eq 'Mac';
426 return "\n<p class=\"availability\">Availability: <span"
427 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
430 $IGNORE_PLATFORM_ANNOTATION = '';
431 sub do_cmd_ignorePlatformAnnotation{
432 local($_) = @_;
433 $IGNORE_PLATFORM_ANNOTATION = next_argument();
434 return $_;
438 # index commands
440 $INDEX_SUBITEM = "";
442 sub get_indexsubitem{
443 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
446 sub do_cmd_setindexsubitem{
447 local($_) = @_;
448 $INDEX_SUBITEM = next_argument();
449 return $_;
452 sub do_cmd_withsubitem{
453 # We can't really do the right thing, because LaTeX2HTML doesn't
454 # do things in the right order, but we need to at least strip this stuff
455 # out, and leave anything that the second argument expanded out to.
457 local($_) = @_;
458 my $oldsubitem = $INDEX_SUBITEM;
459 $INDEX_SUBITEM = next_argument();
460 my $stuff = next_argument();
461 my $br_id = ++$globals{'max_id'};
462 my $marker = "$O$br_id$C";
463 $stuff =~ s/^\s+//;
464 return
465 $stuff
466 . "\\setindexsubitem$marker$oldsubitem$marker"
467 . $_;
470 # This is the prologue macro which is required to start writing the
471 # mod\jobname.idx file; we can just ignore it. (Defining this suppresses
472 # a warning that \makemodindex is unknown.)
474 sub do_cmd_makemodindex{ return @_[0]; }
476 # We're in the document subdirectory when this happens!
478 open(IDXFILE, '>index.dat') || die "\n$!\n";
479 open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
480 print INTLABELS "%internal_labels = ();\n";
481 print INTLABELS "1; # hack in case there are no entries\n\n";
483 # Using \0 for this is bad because we can't use common tools to work with the
484 # resulting files. Things like grep can be useful with this stuff!
486 $IDXFILE_FIELD_SEP = "\1";
488 sub write_idxfile{
489 my ($ahref, $str) = @_;
490 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
494 sub gen_link{
495 my($node,$target) = @_;
496 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
497 return "<a href=\"$node#$target\">";
500 sub add_index_entry{
501 # add an entry to the index structures; ignore the return value
502 my($str,$ahref) = @_;
503 $str = gen_index_id($str, '');
504 $index{$str} .= $ahref;
505 write_idxfile($ahref, $str);
508 sub new_link_info{
509 my $name = "l2h-" . ++$globals{'max_id'};
510 my $aname = "<a name=\"$name\">";
511 my $ahref = gen_link($CURRENT_FILE, $name);
512 return ($name, $aname, $ahref);
515 $IndexMacroPattern = '';
516 sub define_indexing_macro{
517 my $count = @_;
518 my $i = 0;
519 for (; $i < $count; ++$i) {
520 my $name = @_[$i];
521 my $cmd = "idx_cmd_$name";
522 die "\nNo function $cmd() defined!\n"
523 if (!defined &$cmd);
524 eval ("sub do_cmd_$name { return process_index_macros("
525 . "\@_[0], '$name'); }");
526 if (length($IndexMacroPattern) == 0) {
527 $IndexMacroPattern = "$name";
529 else {
530 $IndexMacroPattern .= "|$name";
535 $DEBUG_INDEXING = 0;
536 sub process_index_macros{
537 local($_) = @_;
538 my $cmdname = @_[1]; # This is what triggered us in the first place;
539 # we know it's real, so just process it.
540 my($name,$aname,$ahref) = new_link_info();
541 my $cmd = "idx_cmd_$cmdname";
542 print "\nIndexing: \\$cmdname"
543 if $DEBUG_INDEXING;
544 &$cmd($ahref); # modifies $_ and adds index entries
545 while (/^[\s\n]*\\($IndexMacroPattern)</) {
546 $cmdname = "$1";
547 print " \\$cmdname"
548 if $DEBUG_INDEXING;
549 $cmd = "idx_cmd_$cmdname";
550 if (!defined &$cmd) {
551 last;
553 else {
554 s/^[\s\n]*\\$cmdname//;
555 &$cmd($ahref);
558 if (/^[ \t\r\n]/) {
559 $_ = substr($_, 1);
561 return "$aname$anchor_invisible_mark</a>" . $_;
564 define_indexing_macro('index');
565 sub idx_cmd_index{
566 my $str = next_argument();
567 add_index_entry("$str", @_[0]);
570 define_indexing_macro('kwindex');
571 sub idx_cmd_kwindex{
572 my $str = next_argument();
573 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
574 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
577 define_indexing_macro('indexii');
578 sub idx_cmd_indexii{
579 my $str1 = next_argument();
580 my $str2 = next_argument();
581 add_index_entry("$str1!$str2", @_[0]);
582 add_index_entry("$str2!$str1", @_[0]);
585 define_indexing_macro('indexiii');
586 sub idx_cmd_indexiii{
587 my $str1 = next_argument();
588 my $str2 = next_argument();
589 my $str3 = next_argument();
590 add_index_entry("$str1!$str2 $str3", @_[0]);
591 add_index_entry("$str2!$str3, $str1", @_[0]);
592 add_index_entry("$str3!$str1 $str2", @_[0]);
595 define_indexing_macro('indexiv');
596 sub idx_cmd_indexiv{
597 my $str1 = next_argument();
598 my $str2 = next_argument();
599 my $str3 = next_argument();
600 my $str4 = next_argument();
601 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
602 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
603 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
604 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
607 define_indexing_macro('ttindex');
608 sub idx_cmd_ttindex{
609 my $str = next_argument();
610 my $entry = $str . get_indexsubitem();
611 add_index_entry($entry, @_[0]);
614 sub my_typed_index_helper{
615 my($word,$ahref) = @_;
616 my $str = next_argument();
617 add_index_entry("$str $word", $ahref);
618 add_index_entry("$word!$str", $ahref);
621 define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
622 sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
623 sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
624 sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
625 sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
627 define_indexing_macro('bifuncindex');
628 sub idx_cmd_bifuncindex{
629 my $str = next_argument();
630 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
631 @_[0]);
635 sub make_mod_index_entry{
636 my($str,$define) = @_;
637 my($name,$aname,$ahref) = new_link_info();
638 # equivalent of add_index_entry() using $define instead of ''
639 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
640 if ($define eq 'DEF');
641 $str = gen_index_id($str, $define);
642 $index{$str} .= $ahref;
643 write_idxfile($ahref, $str);
645 if ($define eq 'DEF') {
646 # add to the module index
647 $str =~ /(<tt.*<\/tt>)/;
648 my $nstr = $1;
649 $Modules{$nstr} .= $ahref;
651 return "$aname$anchor_invisible_mark2</a>";
655 $THIS_MODULE = '';
656 $THIS_CLASS = '';
658 sub define_module{
659 my($word,$name) = @_;
660 my $section_tag = join('', @curr_sec_id);
661 if ($word ne "built-in" && $word ne "extension"
662 && $word ne "standard" && $word ne "") {
663 write_warnings("Bad module type '$word'"
664 . " for \\declaremodule (module $name)");
665 $word = "";
667 $word = "$word " if $word;
668 $THIS_MODULE = "$name";
669 $INDEX_SUBITEM = "(in module $name)";
670 print "[$name]";
671 return make_mod_index_entry(
672 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
675 sub my_module_index_helper{
676 local($word, $_) = @_;
677 my $name = next_argument();
678 return define_module($word, $name) . $_;
681 sub do_cmd_modindex{ return my_module_index_helper('', @_); }
682 sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
683 sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
684 sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
686 sub ref_module_index_helper{
687 my($word, $ahref) = @_;
688 my $str = next_argument();
689 $word = "$word " if $word;
690 $str = "<tt class=\"module\">$str</tt> (${word}module)";
691 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
692 # just inline it all here
693 $str = gen_index_id($str, 'REF');
694 $index{$str} .= $ahref;
695 write_idxfile($ahref, $str);
698 # these should be adjusted a bit....
699 define_indexing_macro('refmodindex', 'refbimodindex',
700 'refexmodindex', 'refstmodindex');
701 sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
702 sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
703 sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
704 sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
706 sub do_cmd_nodename{ return do_cmd_label(@_); }
708 sub init_myformat{
709 $anchor_invisible_mark = '&nbsp;';
710 $anchor_invisible_mark2 = '';
711 $anchor_mark = '';
712 $icons{'anchor_mark'} = '';
714 init_myformat();
716 # Create an index entry, but include the string in the target anchor
717 # instead of the dummy filler.
719 sub make_str_index_entry{
720 my($str) = @_;
721 my($name,$aname,$ahref) = new_link_info();
722 add_index_entry($str, $ahref);
723 return "$aname$str</a>";
727 %TokenToTargetMapping = ();
728 %DefinedGrammars = ();
729 %BackpatchGrammarFiles = ();
731 sub do_cmd_token{
732 local($_) = @_;
733 my $token = next_argument();
734 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
735 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
736 # recursive definition or display-only productionlist
737 return "$token";
739 if ($target eq '') {
740 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
741 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
742 print "Adding '$CURRENT_FILE' to back-patch list.\n";
744 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
746 return "<a href=\"$target\">$token</a>" . $_;
749 sub do_cmd_grammartoken{
750 return do_cmd_token(@_);
753 sub do_env_productionlist{
754 local($_) = @_;
755 my $lang = next_optional_argument();
756 my $filename = "grammar-$lang.txt";
757 if ($lang eq '') {
758 $filename = 'grammar.txt';
760 local($CURRENT_GRAMMAR) = $lang;
761 $DefinedGrammars{$lang} .= $_;
762 return ("<dl><dd class=\"grammar\">\n"
763 . "<div class=\"productions\">\n"
764 . "<table cellpadding=\"2\">\n"
765 . translate_commands(translate_environments($_))
766 . "</table>\n"
767 . "</div>\n"
768 . (($lang eq '*')
769 ? ''
770 : ("<a class=\"grammar-footer\"\n"
771 . " href=\"$filename\" type=\"text/plain\"\n"
772 . " >Download entire grammar as text.</a>\n"))
773 . "</dd></dl>");
776 sub do_cmd_production{
777 local($_) = @_;
778 my $token = next_argument();
779 my $defn = next_argument();
780 my $lang = $CURRENT_GRAMMAR;
781 local($CURRENT_TOKEN) = $token;
782 if ($lang eq '*') {
783 return ("<tr valign=\"baseline\">\n"
784 . " <td><code>$token</code></td>\n"
785 . " <td>&nbsp;::=&nbsp;</td>\n"
786 . " <td><code>"
787 . translate_commands($defn)
788 . "</code></td></tr>"
789 . $_);
791 my $target;
792 if ($lang eq '') {
793 $target = "$CURRENT_FILE\#tok-$token";
795 else {
796 $target = "$CURRENT_FILE\#tok-$lang-$token";
798 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
799 return ("<tr valign=\"baseline\">\n"
800 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
801 . " <td>&nbsp;::=&nbsp;</td>\n"
802 . " <td><code>"
803 . translate_commands($defn)
804 . "</code></td></tr>"
805 . $_);
808 sub do_cmd_productioncont{
809 local($_) = @_;
810 my $defn = next_argument();
811 return ("<tr valign=\"baseline\">\n"
812 . " <td>&nbsp;</td>\n"
813 . " <td>&nbsp;</td>\n"
814 . " <td><code>"
815 . translate_commands($defn)
816 . "</code></td></tr>"
817 . $_);
820 sub process_grammar_files{
821 my $lang;
822 my $filename;
823 local($_);
824 print "process_grammar_files()\n";
825 foreach $lang (keys %DefinedGrammars) {
826 $filename = "grammar-$lang.txt";
827 if ($lang eq '*') {
828 next;
830 if ($lang eq '') {
831 $filename = 'grammar.txt';
833 open(GRAMMAR, ">$filename") || die "\n$!\n";
834 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
835 close(GRAMMAR);
836 print "Wrote grammar file $filename\n";
838 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
839 foreach $filename (keys %BackpatchGrammarFiles) {
840 print "\nBack-patching grammar links in $filename\n";
841 my $buffer;
842 open(GRAMMAR, "<$filename") || die "\n$!\n";
843 # read all of the file into the buffer
844 sysread(GRAMMAR, $buffer, 1024*1024);
845 close(GRAMMAR);
846 while ($buffer =~ /$PATTERN/) {
847 my($lang, $token) = ($1, $2);
848 my $target = $TokenToTargetMapping{"$lang:$token"};
849 my $source = "<pyGrammarToken><$lang><$token>";
850 $buffer =~ s/$source/$target/g;
852 open(GRAMMAR, ">$filename") || die "\n$!\n";
853 print GRAMMAR $buffer;
854 close(GRAMMAR);
858 sub strip_grammar_markup{
859 local($_) = @_;
860 s/\\productioncont/ /g;
861 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
862 s/\\token(<<\d+>>)(.+)\1/\2/g;
863 s/\\e([^a-zA-Z])/\\\1/g;
864 s/<<\d+>>//g;
865 s/;SPMgt;/>/g;
866 s/;SPMlt;/</g;
867 s/;SPMquot;/\"/g;
868 return $_;
872 $REFCOUNTS_LOADED = 0;
874 sub load_refcounts{
875 $REFCOUNTS_LOADED = 1;
877 my $myname, $mydir, $myext;
878 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
879 chop $mydir; # remove trailing '/'
880 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
881 chop $mydir; # remove trailing '/'
882 $mydir = getcwd() . "$dd$mydir"
883 unless $mydir =~ s|^/|/|;
884 local $_;
885 my $filename = "$mydir${dd}api${dd}refcounts.dat";
886 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
887 print "[loading API refcount data]";
888 while (<REFCOUNT_FILE>) {
889 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
890 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
891 #print "\n$func($param) --> $count";
892 $REFCOUNTS{"$func:$param"} = $count;
897 sub get_refcount{
898 my ($func, $param) = @_;
899 load_refcounts()
900 unless $REFCOUNTS_LOADED;
901 return $REFCOUNTS{"$func:$param"};
905 $TLSTART = '<span class="typelabel">';
906 $TLEND = '</span>';
908 sub do_env_cfuncdesc{
909 local($_) = @_;
910 my $return_type = next_argument();
911 my $function_name = next_argument();
912 my $arg_list = next_argument();
913 my $idx = make_str_index_entry(
914 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
915 $idx =~ s/ \(.*\)//;
916 $idx =~ s/\(\)//; # ???? - why both of these?
917 my $result_rc = get_refcount($function_name, '');
918 my $rcinfo = '';
919 if ($result_rc eq '+1') {
920 $rcinfo = 'New reference';
922 elsif ($result_rc eq '0') {
923 $rcinfo = 'Borrowed reference';
925 elsif ($result_rc eq 'null') {
926 $rcinfo = 'Always <tt class="constant">NULL</tt>';
928 if ($rcinfo ne '') {
929 $rcinfo = ( "\n<div class=\"refcount-info\">"
930 . "\n <span class=\"label\">Return value:</span>"
931 . "\n <span class=\"value\">$rcinfo.</span>"
932 . "\n</div>");
934 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
935 . $rcinfo
936 . $_
937 . '</dl>';
940 sub do_env_csimplemacrodesc{
941 local($_) = @_;
942 my $name = next_argument();
943 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
944 return "<dl><dt><b>$idx</b>\n<dd>"
945 . $_
946 . '</dl>'
949 sub do_env_ctypedesc{
950 local($_) = @_;
951 my $index_name = next_optional_argument();
952 my $type_name = next_argument();
953 $index_name = $type_name
954 unless $index_name;
955 my($name,$aname,$ahref) = new_link_info();
956 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
957 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
958 . $_
959 . '</dl>'
962 sub do_env_cvardesc{
963 local($_) = @_;
964 my $var_type = next_argument();
965 my $var_name = next_argument();
966 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
967 . get_indexsubitem());
968 $idx =~ s/ \(.*\)//;
969 return "<dl><dt>$var_type <b>$idx</b>\n"
970 . '<dd>'
971 . $_
972 . '</dl>';
975 sub convert_args($){
976 local($IN_DESC_HANDLER) = 1;
977 local($_) = @_;
978 return translate_commands($_);
981 sub do_env_funcdesc{
982 local($_) = @_;
983 my $function_name = next_argument();
984 my $arg_list = convert_args(next_argument());
985 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
986 . '</tt>'
987 . get_indexsubitem());
988 $idx =~ s/ \(.*\)//;
989 $idx =~ s/\(\)<\/tt>/<\/tt>/;
990 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
993 sub do_env_funcdescni{
994 local($_) = @_;
995 my $function_name = next_argument();
996 my $arg_list = convert_args(next_argument());
997 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
998 . "(<var>$arg_list</var>)\n"
999 . '<dd>'
1000 . $_
1001 . '</dl>';
1004 sub do_cmd_funcline{
1005 local($_) = @_;
1006 my $function_name = next_argument();
1007 my $arg_list = convert_args(next_argument());
1008 my $prefix = "<tt class=\"function\">$function_name()</tt>";
1009 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1010 $prefix =~ s/\(\)//;
1012 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
1015 sub do_cmd_funclineni{
1016 local($_) = @_;
1017 my $function_name = next_argument();
1018 my $arg_list = convert_args(next_argument());
1019 my $prefix = "<tt class=\"function\">$function_name</tt>";
1021 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
1024 # Change this flag to index the opcode entries. I don't think it's very
1025 # useful to index them, since they're only presented to describe the dis
1026 # module.
1028 $INDEX_OPCODES = 0;
1030 sub do_env_opcodedesc{
1031 local($_) = @_;
1032 my $opcode_name = next_argument();
1033 my $arg_list = next_argument();
1034 my $idx;
1035 if ($INDEX_OPCODES) {
1036 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1037 . ' (byte code instruction)');
1038 $idx =~ s/ \(byte code instruction\)//;
1040 else {
1041 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
1043 my $stuff = "<dl><dt><b>$idx</b>";
1044 if ($arg_list) {
1045 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1047 return $stuff . "\n<dd>" . $_ . '</dl>';
1050 sub do_env_datadesc{
1051 local($_) = @_;
1052 my $dataname = next_argument();
1053 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
1054 $idx =~ s/ \(.*\)//;
1055 return "<dl><dt><b>$idx</b>\n<dd>"
1056 . $_
1057 . '</dl>';
1060 sub do_env_datadescni{
1061 local($_) = @_;
1062 my $idx = next_argument();
1063 if (! $STRING_INDEX_TT) {
1064 $idx = "<tt>$idx</tt>";
1066 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
1069 sub do_cmd_dataline{
1070 local($_) = @_;
1071 my $data_name = next_argument();
1072 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
1073 $idx =~ s/ \(.*\)//;
1074 return "<dt><b>$idx</b><dd>" . $_;
1077 sub do_cmd_datalineni{
1078 local($_) = @_;
1079 my $data_name = next_argument();
1080 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1083 sub do_env_excdesc{
1084 local($_) = @_;
1085 my $excname = next_argument();
1086 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
1087 return ("<dl><dt><b>${TLSTART}exception$TLEND $idx</b>"
1088 . "\n<dd>"
1089 . $_
1090 . '</dl>');
1093 sub do_env_fulllineitems{ return do_env_itemize(@_); }
1096 sub handle_classlike_descriptor{
1097 local($_, $what) = @_;
1098 $THIS_CLASS = next_argument();
1099 my $arg_list = convert_args(next_argument());
1100 $idx = make_str_index_entry(
1101 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
1102 $idx =~ s/ \(.*\)//;
1103 return ("<dl><dt><b>$TLSTART$what$TLEND $idx</b>"
1104 . "(<var>$arg_list</var>)\n<dd>"
1105 . $_
1106 . '</dl>');
1109 sub do_env_classdesc{
1110 return handle_classlike_descriptor(@_[0], "class");
1113 sub do_env_classdescstar{
1114 local($_) = @_;
1115 $THIS_CLASS = next_argument();
1116 $idx = make_str_index_entry(
1117 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
1118 $idx =~ s/ \(.*\)//;
1119 return ("<dl><dt><b>${TLSTART}class$TLEND $idx</b>\n<dd>"
1120 . $_
1121 . '</dl>');
1124 sub do_env_excclassdesc{
1125 return handle_classlike_descriptor(@_[0], "exception");
1129 sub do_env_methoddesc{
1130 local($_) = @_;
1131 my $class_name = next_optional_argument();
1132 $class_name = $THIS_CLASS
1133 unless $class_name;
1134 my $method = next_argument();
1135 my $arg_list = convert_args(next_argument());
1136 my $extra = '';
1137 if ($class_name) {
1138 $extra = " ($class_name method)";
1140 my $idx = make_str_index_entry(
1141 "<tt class=\"method\">$method()</tt>$extra");
1142 $idx =~ s/ \(.*\)//;
1143 $idx =~ s/\(\)//;
1144 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
1148 sub do_cmd_methodline{
1149 local($_) = @_;
1150 my $class_name = next_optional_argument();
1151 $class_name = $THIS_CLASS
1152 unless $class_name;
1153 my $method = next_argument();
1154 my $arg_list = convert_args(next_argument());
1155 my $extra = '';
1156 if ($class_name) {
1157 $extra = " ($class_name method)";
1159 my $idx = make_str_index_entry(
1160 "<tt class=\"method\">$method()</tt>$extra");
1161 $idx =~ s/ \(.*\)//;
1162 $idx =~ s/\(\)//;
1163 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
1164 . $_;
1168 sub do_cmd_methodlineni{
1169 local($_) = @_;
1170 next_optional_argument();
1171 my $method = next_argument();
1172 my $arg_list = convert_args(next_argument());
1173 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
1174 . $_;
1177 sub do_env_methoddescni{
1178 local($_) = @_;
1179 next_optional_argument();
1180 my $method = next_argument();
1181 my $arg_list = convert_args(next_argument());
1182 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
1183 . $_
1184 . '</dl>';
1188 sub do_env_memberdesc{
1189 local($_) = @_;
1190 my $class = next_optional_argument();
1191 my $member = next_argument();
1192 $class = $THIS_CLASS
1193 unless $class;
1194 my $extra = '';
1195 $extra = " ($class attribute)"
1196 if ($class ne '');
1197 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
1198 $idx =~ s/ \(.*\)//;
1199 $idx =~ s/\(\)//;
1200 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
1204 sub do_cmd_memberline{
1205 local($_) = @_;
1206 my $class = next_optional_argument();
1207 my $member = next_argument();
1208 $class = $THIS_CLASS
1209 unless $class;
1210 my $extra = '';
1211 $extra = " ($class attribute)"
1212 if ($class ne '');
1213 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
1214 $idx =~ s/ \(.*\)//;
1215 $idx =~ s/\(\)//;
1216 return "<dt><b>$idx</b><dd>" . $_;
1220 sub do_env_memberdescni{
1221 local($_) = @_;
1222 next_optional_argument();
1223 my $member = next_argument();
1224 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
1225 . $_
1226 . '</dl>';
1230 sub do_cmd_memberlineni{
1231 local($_) = @_;
1232 next_optional_argument();
1233 my $member = next_argument();
1234 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
1238 @col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
1240 %FontConversions = ('cdata' => 'tt class="cdata"',
1241 'character' => 'tt class="character"',
1242 'class' => 'tt class="class"',
1243 'command' => 'code',
1244 'constant' => 'tt class="constant"',
1245 'exception' => 'tt class="exception"',
1246 'file' => 'tt class="file"',
1247 'filenq' => 'tt class="file"',
1248 'kbd' => 'kbd',
1249 'member' => 'tt class="member"',
1250 'programopt' => 'b',
1251 'textrm' => '',
1254 sub fix_font{
1255 # do a little magic on a font name to get the right behavior in the first
1256 # column of the output table
1257 my $font = @_[0];
1258 if (defined $FontConversions{$font}) {
1259 $font = $FontConversions{$font};
1261 return $font;
1264 sub figure_column_alignment{
1265 my $a = @_[0];
1266 my $mark = substr($a, 0, 1);
1267 my $r = '';
1268 if ($mark eq 'c')
1269 { $r = ' align="center"'; }
1270 elsif ($mark eq 'r')
1271 { $r = ' align="right"'; }
1272 elsif ($mark eq 'l')
1273 { $r = ' align="left"'; }
1274 elsif ($mark eq 'p')
1275 { $r = ' align="left"'; }
1276 return $r;
1279 sub setup_column_alignments{
1280 local($_) = @_;
1281 my($s1,$s2,$s3,$s4,$a5) = split(/[|]/,$_);
1282 my $a1 = figure_column_alignment($s1);
1283 my $a2 = figure_column_alignment($s2);
1284 my $a3 = figure_column_alignment($s3);
1285 my $a4 = figure_column_alignment($s4);
1286 my $a5 = figure_column_alignment($s5);
1287 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1288 $col_aligns[1] = "<td$a2>";
1289 $col_aligns[2] = "<td$a3>";
1290 $col_aligns[3] = "<td$a4>";
1291 $col_aligns[4] = "<td$a5>";
1292 # return the aligned header start tags
1293 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
1296 sub get_table_col1_fonts{
1297 my $font = $globals{'lineifont'};
1298 my ($sfont,$efont) = ('', '');
1299 if ($font) {
1300 $sfont = "<$font>";
1301 $efont = "</$font>";
1302 $efont =~ s/ .*>/>/;
1304 return ($sfont, $efont);
1307 sub do_env_tableii{
1308 local($_) = @_;
1309 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1310 my $font = fix_font(next_argument());
1311 my $h1 = next_argument();
1312 my $h2 = next_argument();
1313 s/[\s\n]+//;
1314 $globals{'lineifont'} = $font;
1315 my $a1 = $col_aligns[0];
1316 my $a2 = $col_aligns[1];
1317 s/\\lineii</\\lineii[$a1|$a2]</g;
1318 return '<table border align="center" style="border-collapse: collapse">'
1319 . "\n <thead>"
1320 . "\n <tr class=\"tableheader\">"
1321 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1322 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1323 . "\n </tr>"
1324 . "\n </thead>"
1325 . "\n <tbody valign=\"baseline\">"
1326 . $_
1327 . "\n </tbody>"
1328 . "\n</table>";
1331 sub do_env_longtableii{
1332 return do_env_tableii(@_);
1335 sub do_cmd_lineii{
1336 local($_) = @_;
1337 my $aligns = next_optional_argument();
1338 my $c1 = next_argument();
1339 my $c2 = next_argument();
1340 s/[\s\n]+//;
1341 my($sfont,$efont) = get_table_col1_fonts();
1342 $c2 = '&nbsp;' if ($c2 eq '');
1343 my($c1align,$c2align) = split('\|', $aligns);
1344 my $padding = '';
1345 if ($c1align =~ /align="right"/ || $c1 eq '') {
1346 $padding = '&nbsp;';
1348 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1349 . " $c2align$c2</td>"
1350 . $_;
1353 sub do_env_tableiii{
1354 local($_) = @_;
1355 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1356 my $font = fix_font(next_argument());
1357 my $h1 = next_argument();
1358 my $h2 = next_argument();
1359 my $h3 = next_argument();
1360 s/[\s\n]+//;
1361 $globals{'lineifont'} = $font;
1362 my $a1 = $col_aligns[0];
1363 my $a2 = $col_aligns[1];
1364 my $a3 = $col_aligns[2];
1365 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1366 return '<table border align="center" style="border-collapse: collapse">'
1367 . "\n <thead>"
1368 . "\n <tr class=\"tableheader\">"
1369 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1370 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1371 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1372 . "\n </tr>"
1373 . "\n </thead>"
1374 . "\n <tbody valign=\"baseline\">"
1375 . $_
1376 . "\n </tbody>"
1377 . "\n</table>";
1380 sub do_env_longtableiii{
1381 return do_env_tableiii(@_);
1384 sub do_cmd_lineiii{
1385 local($_) = @_;
1386 my $aligns = next_optional_argument();
1387 my $c1 = next_argument();
1388 my $c2 = next_argument();
1389 my $c3 = next_argument();
1390 s/[\s\n]+//;
1391 my($sfont,$efont) = get_table_col1_fonts();
1392 $c3 = '&nbsp;' if ($c3 eq '');
1393 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1394 my $padding = '';
1395 if ($c1align =~ /align="right"/ || $c1 eq '') {
1396 $padding = '&nbsp;';
1398 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1399 . " $c2align$c2</td>\n"
1400 . " $c3align$c3</td>"
1401 . $_;
1404 sub do_env_tableiv{
1405 local($_) = @_;
1406 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1407 my $font = fix_font(next_argument());
1408 my $h1 = next_argument();
1409 my $h2 = next_argument();
1410 my $h3 = next_argument();
1411 my $h4 = next_argument();
1412 s/[\s\n]+//;
1413 $globals{'lineifont'} = $font;
1414 my $a1 = $col_aligns[0];
1415 my $a2 = $col_aligns[1];
1416 my $a3 = $col_aligns[2];
1417 my $a4 = $col_aligns[3];
1418 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1419 return '<table border align="center" style="border-collapse: collapse">'
1420 . "\n <thead>"
1421 . "\n <tr class=\"tableheader\">"
1422 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1423 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1424 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1425 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1426 . "\n </tr>"
1427 . "\n </thead>"
1428 . "\n <tbody valign=\"baseline\">"
1429 . $_
1430 . "\n </tbody>"
1431 . "\n</table>";
1434 sub do_env_longtableiv{
1435 return do_env_tableiv(@_);
1438 sub do_cmd_lineiv{
1439 local($_) = @_;
1440 my $aligns = next_optional_argument();
1441 my $c1 = next_argument();
1442 my $c2 = next_argument();
1443 my $c3 = next_argument();
1444 my $c4 = next_argument();
1445 s/[\s\n]+//;
1446 my($sfont,$efont) = get_table_col1_fonts();
1447 $c4 = '&nbsp;' if ($c4 eq '');
1448 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1449 my $padding = '';
1450 if ($c1align =~ /align="right"/ || $c1 eq '') {
1451 $padding = '&nbsp;';
1453 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1454 . " $c2align$c2</td>\n"
1455 . " $c3align$c3</td>\n"
1456 . " $c4align$c4</td>"
1457 . $_;
1460 sub do_env_tablev{
1461 local($_) = @_;
1462 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1463 my $font = fix_font(next_argument());
1464 my $h1 = next_argument();
1465 my $h2 = next_argument();
1466 my $h3 = next_argument();
1467 my $h4 = next_argument();
1468 my $h5 = next_argument();
1469 s/[\s\n]+//;
1470 $globals{'lineifont'} = $font;
1471 my $a1 = $col_aligns[0];
1472 my $a2 = $col_aligns[1];
1473 my $a3 = $col_aligns[2];
1474 my $a4 = $col_aligns[3];
1475 my $a5 = $col_aligns[4];
1476 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1477 return '<table border align="center" style="border-collapse: collapse">'
1478 . "\n <thead>"
1479 . "\n <tr class=\"tableheader\">"
1480 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1481 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1482 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1483 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1484 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1485 . "\n </tr>"
1486 . "\n </thead>"
1487 . "\n <tbody valign=\"baseline\">"
1488 . $_
1489 . "\n </tbody>"
1490 . "\n</table>";
1493 sub do_env_longtablev{
1494 return do_env_tablev(@_);
1497 sub do_cmd_linev{
1498 local($_) = @_;
1499 my $aligns = next_optional_argument();
1500 my $c1 = next_argument();
1501 my $c2 = next_argument();
1502 my $c3 = next_argument();
1503 my $c4 = next_argument();
1504 my $c5 = next_argument();
1505 s/[\s\n]+//;
1506 my($sfont,$efont) = get_table_col1_fonts();
1507 $c5 = '&nbsp;' if ($c5 eq '');
1508 my($c1align,$c2align,$c3align,$c4align,$c5align) = split('\|', $aligns);
1509 my $padding = '';
1510 if ($c1align =~ /align="right"/ || $c1 eq '') {
1511 $padding = '&nbsp;';
1513 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1514 . " $c2align$c2</td>\n"
1515 . " $c3align$c3</td>\n"
1516 . " $c4align$c4</td>\n"
1517 . " $c5align$c5</td>"
1518 . $_;
1522 # These can be used to control the title page appearance;
1523 # they need a little bit of documentation.
1525 # If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1526 # $ICONSERVER directory, or include path information (other than "./"). The
1527 # default image type will be assumed if an extension is not provided.
1529 # If specified, the "title page" will contain two colums: one containing the
1530 # title/author/etc., and the other containing the graphic. Use the other
1531 # four variables listed here to control specific details of the layout; all
1532 # are optional.
1534 # $TITLE_PAGE_GRAPHIC = "my-company-logo";
1535 # $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1536 # $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1537 # $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1538 # $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1540 sub make_my_titlepage() {
1541 my $the_title = "";
1542 if ($t_title) {
1543 $the_title .= "\n<h1>$t_title</h1>";
1545 else {
1546 write_warnings("\nThis document has no title.");
1548 if ($t_author) {
1549 if ($t_authorURL) {
1550 my $href = translate_commands($t_authorURL);
1551 $href = make_named_href('author', $href,
1552 "<b><font size=\"+2\">$t_author"
1553 . '</font></b>');
1554 $the_title .= "\n<p>$href</p>";
1556 else {
1557 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1558 . '</font></b></p>');
1561 else {
1562 write_warnings("\nThere is no author for this document.");
1564 if ($t_institute) {
1565 $the_title .= "\n<p>$t_institute</p>";
1567 if ($DEVELOPER_ADDRESS) {
1568 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1570 if ($t_affil) {
1571 $the_title .= "\n<p><i>$t_affil</i></p>";
1573 if ($t_date) {
1574 $the_title .= "\n<p>";
1575 if ($PACKAGE_VERSION) {
1576 $the_title .= ('<strong>Release '
1577 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
1579 $the_title .= "<strong>$t_date</strong></p>"
1581 if ($t_address) {
1582 $the_title .= "\n<p>$t_address</p>";
1584 else {
1585 $the_title .= "\n<p>";
1587 if ($t_email) {
1588 $the_title .= "\n<p>$t_email</p>";
1590 return $the_title;
1593 sub make_my_titlegraphic() {
1594 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
1595 my $graphic = "<td class=\"titlegraphic\"";
1596 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1597 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1598 $graphic .= "><img";
1599 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1600 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1601 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1602 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
1603 $graphic .= "\n src=\"$filename\"></td>\n";
1604 return $graphic;
1607 sub do_cmd_maketitle {
1608 local($_) = @_;
1609 my $the_title = "\n<div class=\"titlepage\">";
1610 if ($TITLE_PAGE_GRAPHIC) {
1611 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1612 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1613 . "<tr align=\"right\">\n<td>"
1614 . make_my_titlepage()
1615 . "</td>\n"
1616 . make_my_titlegraphic()
1617 . "</tr>\n</table>");
1619 else {
1620 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1621 . make_my_titlegraphic()
1622 . "<td>"
1623 . make_my_titlepage()
1624 . "</td></tr>\n</table>");
1627 else {
1628 $the_title .= ("\n<center>"
1629 . make_my_titlepage()
1630 . "\n</center>");
1632 $the_title .= "\n</div>";
1633 return $the_title . $_;
1634 $the_title .= "\n</center></div>";
1635 return $the_title . $_ ;
1640 # Module synopsis support
1643 require SynopsisTable;
1645 sub get_chapter_id(){
1646 my $id = do_cmd_thechapter('');
1647 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1648 $id =~ s/\.//;
1649 return $id;
1652 # 'chapter' => 'SynopsisTable instance'
1653 %ModuleSynopses = ();
1655 sub get_synopsis_table($){
1656 my($chap) = @_;
1657 my $key;
1658 foreach $key (keys %ModuleSynopses) {
1659 if ($key eq $chap) {
1660 return $ModuleSynopses{$chap};
1663 my $st = SynopsisTable->new();
1664 $ModuleSynopses{$chap} = $st;
1665 return $st;
1668 sub do_cmd_moduleauthor{
1669 local($_) = @_;
1670 next_argument();
1671 next_argument();
1672 return $_;
1675 sub do_cmd_sectionauthor{
1676 local($_) = @_;
1677 next_argument();
1678 next_argument();
1679 return $_;
1682 sub do_cmd_declaremodule{
1683 local($_) = @_;
1684 my $key = next_optional_argument();
1685 my $type = next_argument();
1686 my $name = next_argument();
1687 my $st = get_synopsis_table(get_chapter_id());
1689 $key = $name unless $key;
1690 $type = 'built-in' if $type eq 'builtin';
1691 $st->declare($name, $key, $type);
1692 define_module($type, $name);
1693 return anchor_label("module-$key",$CURRENT_FILE,$_)
1696 sub do_cmd_modulesynopsis{
1697 local($_) = @_;
1698 my $st = get_synopsis_table(get_chapter_id());
1699 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
1700 return $_;
1703 sub do_cmd_localmoduletable{
1704 local($_) = @_;
1705 my $chap = get_chapter_id();
1706 my $st = get_synopsis_table($chap);
1707 $st->set_file("$CURRENT_FILE");
1708 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
1711 sub process_all_localmoduletables{
1712 my $key;
1713 my $st, $file;
1714 foreach $key (keys %ModuleSynopses) {
1715 $st = $ModuleSynopses{$key};
1716 $file = $st->get_file();
1717 if ($file) {
1718 process_localmoduletables_in_file($file);
1720 else {
1721 print "\nsynopsis table $key has no file association\n";
1726 sub process_localmoduletables_in_file{
1727 my $file = @_[0];
1728 open(MYFILE, "<$file");
1729 local($_);
1730 sysread(MYFILE, $_, 1024*1024);
1731 close(MYFILE);
1732 # need to get contents of file in $_
1733 while (/<tex2html-localmoduletable><(\d+)>/) {
1734 my $match = $&;
1735 my $chap = $1;
1736 my $st = get_synopsis_table($chap);
1737 my $data = $st->tohtml();
1738 s/$match/$data/;
1740 open(MYFILE,">$file");
1741 print MYFILE $_;
1742 close(MYFILE);
1744 sub process_python_state{
1745 process_all_localmoduletables();
1746 process_grammar_files();
1751 # "See also:" -- references placed at the end of a \section
1754 sub do_env_seealso{
1755 return ("<div class=\"seealso\">\n "
1756 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1757 . @_[0]
1758 . '</div>');
1761 sub do_env_seealsostar{
1762 return ("<div class=\"seealso-simple\">\n "
1763 . @_[0]
1764 . '</div>');
1767 sub do_cmd_seemodule{
1768 # Insert the right magic to jump to the module definition. This should
1769 # work most of the time, at least for repeat builds....
1770 local($_) = @_;
1771 my $key = next_optional_argument();
1772 my $module = next_argument();
1773 my $text = next_argument();
1774 my $period = '.';
1775 $key = $module
1776 unless $key;
1777 if ($text =~ /\.$/) {
1778 $period = '';
1780 return ('<dl compact class="seemodule">'
1781 . "\n <dt>Module <b><tt class=\"module\">"
1782 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1783 . "\n <dd>$text$period\n </dl>"
1784 . $_);
1787 sub strip_html_markup($){
1788 my $str = @_[0];
1789 my $s = "$str";
1790 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1791 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1792 return $s;
1795 sub handle_rfclike_reference{
1796 local($_, $what, $format) = @_;
1797 my $rfcnum = next_argument();
1798 my $title = next_argument();
1799 my $text = next_argument();
1800 my $url = get_rfc_url($rfcnum, $format);
1801 my $icon = get_link_icon($url);
1802 my $attrtitle = strip_html_markup($title);
1803 return '<dl compact class="seerfc">'
1804 . "\n <dt><a href=\"$url\""
1805 . "\n title=\"$attrtitle\""
1806 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
1807 . "\n <dd>$text\n </dl>"
1808 . $_;
1811 sub do_cmd_seepep{
1812 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
1815 sub do_cmd_seerfc{
1816 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
1819 sub do_cmd_seetitle{
1820 local($_) = @_;
1821 my $url = next_optional_argument();
1822 my $title = next_argument();
1823 my $text = next_argument();
1824 if ($url) {
1825 my $icon = get_link_icon($url);
1826 return '<dl compact class="seetitle">'
1827 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
1828 . "\n >$title$icon</a></em>"
1829 . "\n <dd>$text\n </dl>"
1830 . $_;
1832 return '<dl compact class="seetitle">'
1833 . "\n <dt><em class=\"citetitle\""
1834 . "\n >$title</em>"
1835 . "\n <dd>$text\n </dl>"
1836 . $_;
1839 sub do_cmd_seeurl{
1840 local($_) = @_;
1841 my $url = next_argument();
1842 my $text = next_argument();
1843 my $icon = get_link_icon($url);
1844 return '<dl compact class="seeurl">'
1845 . "\n <dt><a href=\"$url\""
1846 . "\n class=\"url\">$url$icon</a>"
1847 . "\n <dd>$text\n </dl>"
1848 . $_;
1851 sub do_cmd_seetext{
1852 local($_) = @_;
1853 my $content = next_argument();
1854 return '<div class="seetext"><p>' . $content . '</div>' . $_;
1859 # Definition list support.
1862 sub do_env_definitions{
1863 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
1866 sub do_cmd_term{
1867 local($_) = @_;
1868 my $term = next_argument();
1869 my($name,$aname,$ahref) = new_link_info();
1870 # could easily add an index entry here...
1871 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
1875 # I don't recall exactly why this was needed, but it was very much needed.
1876 # We'll see if anything breaks when I move the "code" line out -- some
1877 # things broke with it in.
1879 #code # {}
1880 process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
1881 declaremodule # [] # {} # {}
1882 memberline # [] # {}
1883 methodline # [] # {} # {}
1884 modulesynopsis # {}
1885 platform # {}
1886 samp # {}
1887 setindexsubitem # {}
1888 withsubitem # {} # {}
1889 _RAW_ARG_DEFERRED_CMDS_
1892 $alltt_start = '<dl><dd><pre class="verbatim">';
1893 $alltt_end = '</pre></dl>';
1895 sub do_env_alltt {
1896 local ($_) = @_;
1897 local($closures,$reopens,@open_block_tags);
1899 # get the tag-strings for all open tags
1900 local(@keep_open_tags) = @$open_tags_R;
1901 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1903 # get the tags for text-level tags only
1904 $open_tags_R = [ @keep_open_tags ];
1905 local($local_closures, $local_reopens);
1906 ($local_closures, $local_reopens,@open_block_tags)
1907 = &preserve_open_block_tags
1908 if (@$open_tags_R);
1910 $open_tags_R = [ @open_block_tags ];
1912 do {
1913 local($open_tags_R) = [ @open_block_tags ];
1914 local(@save_open_tags) = ();
1916 local($cnt) = ++$global{'max_id'};
1917 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1918 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1920 $_ = &translate_environments($_);
1921 $_ = &translate_commands($_) if (/\\/);
1923 # preserve space-runs, using &nbsp;
1924 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1925 s/(<BR>) /$1;SPMnbsp;/g;
1927 $_ = join('', $closures, $alltt_start, $local_reopens
1928 , $_
1929 , &balance_tags() #, $local_closures
1930 , $alltt_end, $reopens);
1931 undef $open_tags_R; undef @save_open_tags;
1933 $open_tags_R = [ @keep_open_tags ];
1937 sub do_cmd_verbatiminput{
1938 local($_) = @_;
1939 my $fname = next_argument();
1940 my $file;
1941 my $found = 0;
1942 my $texpath;
1943 # Search TEXINPUTS for the input file, the way we're supposed to:
1944 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1945 $file = "$texpath$dd$fname";
1946 last if ($found = (-f $file));
1948 my $srcname;
1949 my $text;
1950 if ($found) {
1951 open(MYFILE, "<$file") || die "\n$!\n";
1952 read(MYFILE, $text, 1024*1024);
1953 close(MYFILE);
1954 use File::Basename;
1955 my $srcdir, $srcext;
1956 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1957 open(MYFILE, ">$srcname.txt");
1958 print MYFILE $text;
1959 close(MYFILE);
1961 # These rewrites convert the raw text to something that will
1962 # be properly visible as HTML and also will pass through the
1963 # vagaries of conversion through LaTeX2HTML. The order in
1964 # which the specific rewrites are performed is significant.
1966 $text =~ s/\&/\&amp;/g;
1967 # These need to happen before the normal < and > re-writes,
1968 # since we need to avoid LaTeX2HTML's attempt to perform
1969 # ligature processing without regard to context (since it
1970 # doesn't have font information).
1971 $text =~ s/--/-&\#45;/g;
1972 $text =~ s/<</\&lt;\&\#60;/g;
1973 $text =~ s/>>/\&gt;\&\#62;/g;
1974 # Just normal re-writes...
1975 $text =~ s/</\&lt;/g;
1976 $text =~ s/>/\&gt;/g;
1977 # These last isn't needed for the HTML, but is needed to get
1978 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1979 # of &sol; since many browsers don't support that.
1980 $text =~ s/\\/\&\#92;/g;
1982 else {
1983 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1985 return ('<dl><dd><pre class="verbatim">'
1986 . $text
1987 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1988 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1989 . ">Download as text.</a>"
1990 . "\n</div>\n</dd></dl>"
1991 . $_);
1994 1; # This must be the last line