blob: 476ef662a9a4a7998dd642be0602cd6f90d95a2f [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
2#
3# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
4#
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.
8
9package main;
10
Fred Drake7a40c072000-10-02 14:43:38 +000011use File::Basename;
12
Fred Drake6659c301998-03-03 22:02:19 +000013
Fred Drake08932051998-04-17 02:15:42 +000014sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000015 my $param;
16 $param = missing_braces()
17 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
18 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000019 return $param;
Fred Drake08932051998-04-17 02:15:42 +000020}
21
22sub next_optional_argument{
23 my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000024 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000025 return $param;
Fred Drake08932051998-04-17 02:15:42 +000026}
27
Fred Drake7a40c072000-10-02 14:43:38 +000028sub make_icon_filename($){
29 my($myname, $mydir, $myext) = fileparse(@_[0], '\..*');
30 chop $mydir;
31 if ($mydir eq '.') {
32 $mydir = $ICONSERVER;
33 }
34 $myext = ".$IMAGE_TYPE"
35 unless $myext;
36 return "$mydir$dd$myname$myext";
37}
38
Fred Drake7a40c072000-10-02 14:43:38 +000039sub 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"
Fred Drake5f84c9b2000-10-03 06:05:25 +000045 . " 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"
Fred Drake7a40c072000-10-02 14:43:38 +000053 . " >");
54 }
55 return '';
56}
Fred Drakee16f6791998-05-15 04:28:37 +000057
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.
Fred Drake5b73cdf1998-05-15 16:59:38 +000060# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000061#
62sub do_cmd_let{
63 local($_) = @_;
64 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000065 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000066 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";
70 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000071 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";
77 }
78 else {
79 write_warnings("Could not interpret \\let construct...");
80 }
81 }
Fred Drake62e43691998-08-10 19:40:44 +000082 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000083}
84
85
Fred Drakec3fd45f2000-06-15 22:41:48 +000086# the older version of LaTeX2HTML we use doesn't support this, but we use it:
87
88sub do_cmd_textasciitilde{ '~' . @_[0]; }
89
90
Fred Drake6659c301998-03-03 22:02:19 +000091# words typeset in a special way (not in HTML though)
92
93sub do_cmd_ABC{ 'ABC' . @_[0]; }
94sub do_cmd_UNIX{ 'Unix'. @_[0]; }
95sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
96sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
97sub do_cmd_C{ 'C' . @_[0]; }
98sub do_cmd_Cpp{ 'C++' . @_[0]; }
99sub do_cmd_EOF{ 'EOF' . @_[0]; }
Fred Drakee15956b2000-04-03 04:51:13 +0000100sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000101
102sub do_cmd_e{ '&#92;' . @_[0]; }
103
Fred Draked07868a1998-05-14 21:00:28 +0000104$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000105$SHORT_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000106$PYTHON_VERSION = '';
107
108sub do_cmd_version{ $PYTHON_VERSION . @_[0]; }
Fred Drake3cdb89d2000-09-14 20:17:23 +0000109sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000110sub do_cmd_release{
111 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000112 $PYTHON_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000113 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000114}
115
Fred Drake3cdb89d2000-09-14 20:17:23 +0000116sub do_cmd_setshortversion{
117 local($_) = @_;
118 $SHORT_VERSION = next_argument();
119 return $_;
120}
121
Fred Drake6659c301998-03-03 22:02:19 +0000122sub do_cmd_authoraddress{
123 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000124 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000125 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000126}
127
Fred Drakee16f6791998-05-15 04:28:37 +0000128#sub do_cmd_developer{ do_cmd_author(@_[0]); }
129#sub do_cmd_developers{ do_cmd_author(@_[0]); }
130#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000131
Fred Drake6659c301998-03-03 22:02:19 +0000132sub do_cmd_hackscore{
133 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000134 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000135 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000136}
137
Fred Drake08932051998-04-17 02:15:42 +0000138sub use_wrappers{
139 local($_,$before,$after) = @_;
140 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000141 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000142}
143
Fred Drake3cdb89d2000-09-14 20:17:23 +0000144$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000145sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000146 if ($IN_DESC_HANDLER) {
147 return use_wrappers(@_[0], "</var><big>\[</big><var>",
148 "</var><big>\]</big><var>");
149 }
150 else {
151 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
152 }
Fred Drake6659c301998-03-03 22:02:19 +0000153}
154
Fred Drakec9a44381998-03-17 06:29:13 +0000155# Logical formatting (some based on texinfo), needs to be converted to
156# minimalist HTML. The "minimalist" is primarily to reduce the size of
157# output files for users that read them over the network rather than
158# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000159
Fred Drake2cafcbb1999-03-25 16:57:04 +0000160# \file and \samp are at the end of this file since they screw up fontlock.
161
Fred Drake2ff880e1999-02-05 18:31:29 +0000162sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000163sub do_cmd_makevar{
164 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000165sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000166 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000167sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000168 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000169sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000170 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000171sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000172 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000173sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000174 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000175sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000176 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000177sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000178 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000179sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000180 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000181sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000182 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000183sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000184 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000185sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000186 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000187sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000188 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000189sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000190 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000191sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000192 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000193sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000194 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000195sub do_cmd_programopt{
196 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000197sub do_cmd_longprogramopt{
198 # note that the --- will be later converted to -- by LaTeX2HTML
199 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000201 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000203 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_var{
205 return use_wrappers(@_[0], "<var>", "</var>"); }
206sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000207 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000208sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000209 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000210sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000211 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000212sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000213 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000214sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000215 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000216sub do_cmd_kbd{
217 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
218sub do_cmd_strong{
219 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000220sub do_cmd_textbf{
221 return use_wrappers(@_[0], '<b>', '</b>'); }
222sub do_cmd_textit{
223 return use_wrappers(@_[0], '<i>', '</i>'); }
224
Fred Drake3d5a04a2000-08-03 17:25:44 +0000225sub do_cmd_moreargs{
226 return '...' . @_[0]; }
227sub do_cmd_unspecified{
228 return '...' . @_[0]; }
229
Fred Drakec9a44381998-03-17 06:29:13 +0000230
Fred Drake25817041999-01-13 17:06:34 +0000231sub do_cmd_refmodule{
232 # Insert the right magic to jump to the module definition.
233 local($_) = @_;
234 my $key = next_optional_argument();
235 my $module = next_argument();
236 $key = $module
237 unless $key;
Fred Drakee15956b2000-04-03 04:51:13 +0000238 return "<tt class='module'><a href='module-$key.html'>$module</a></tt>"
239 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000240}
241
Fred Drake1a7af391998-04-01 22:44:56 +0000242sub do_cmd_newsgroup{
243 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000244 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000245 my $icon = get_link_icon("news:$newsgroup");
Fred Drakee15956b2000-04-03 04:51:13 +0000246 my $stuff = "<span class='newsgroup'><a href='news:$newsgroup'>"
Fred Drake7a40c072000-10-02 14:43:38 +0000247 . "$newsgroup$icon</a></span>";
Fred Drake62e43691998-08-10 19:40:44 +0000248 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000249}
Fred Drakefc16e781998-03-12 21:03:26 +0000250
251sub do_cmd_envvar{
252 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000253 my $envvar = next_argument();
254 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000255 # The <tt> here is really to keep buildindex.py from making
256 # the variable name case-insensitive.
257 add_index_entry("environment variables!$envvar@<tt>\$$envvar</tt>",
258 $ahref);
Fred Drake42b31a51998-03-27 05:16:10 +0000259 add_index_entry("$envvar@\$$envvar", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000260 $aname =~ s/<a/<a class="envvar"/;
Fred Draked37cecf1999-09-23 16:45:08 +0000261 return "$aname\$$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000262}
263
Fred Drake6659c301998-03-03 22:02:19 +0000264sub do_cmd_url{
265 # use the URL as both text and hyperlink
266 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000267 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000268 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000269 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000270 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000271}
272
273sub do_cmd_manpage{
274 # two parameters: \manpage{name}{section}
275 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000276 my $page = next_argument();
277 my $section = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000278 return "<span class='manpage'><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000279}
280
Fred Drake643d76d2000-09-09 06:07:37 +0000281sub get_pep_url{
282 my $rfcnum = sprintf("%04d", @_[0]);
283 return "http://python.sourceforge.net/peps/pep-$rfcnum.html";
284}
285
286sub do_cmd_pep{
287 local($_) = @_;
288 my $rfcnumber = next_argument();
289 my $id = "rfcref-" . ++$global{'max_id'};
290 my $href = get_pep_url($rfcnumber);
Fred Drake7a40c072000-10-02 14:43:38 +0000291 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000292 # Save the reference
293 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
294 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000295 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
296 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000297}
298
Fred Drake37cc0c02000-04-26 18:05:24 +0000299sub get_rfc_url{
300 my $rfcnum = sprintf("%04d", @_[0]);
301 return "http://www.ietf.org/rfc/rfc$rfcnum.txt";
302}
303
Fred Drake6659c301998-03-03 22:02:19 +0000304sub do_cmd_rfc{
305 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000306 my $rfcnumber = next_argument();
307 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drake37cc0c02000-04-26 18:05:24 +0000308 my $href = get_rfc_url($rfcnumber);
Fred Drake7a40c072000-10-02 14:43:38 +0000309 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000310 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000311 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000312 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000313 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
314 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000315}
316
Fred Drakec9f5fe01999-11-09 16:59:42 +0000317sub do_cmd_citetitle{
318 local($_) = @_;
319 my $url = next_optional_argument();
320 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000321 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000322 my $repl = '';
323 if ($url) {
324 $repl = ("<em class='citetitle'><a\n"
325 . " href='$url'\n"
326 . " title='$title'\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000327 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000328 }
329 else {
330 $repl = "<em class='citetitle'\n >$title</em>";
331 }
332 return $repl . $_;
333}
334
Fred Drake6659c301998-03-03 22:02:19 +0000335sub do_cmd_deprecated{
336 # two parameters: \deprecated{version}{whattodo}
337 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000338 my $release = next_argument();
339 my $reason = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000340 return "<b>Deprecated since release $release.</b>\n$reason<p>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000341}
342
Fred Drake897d12b1998-07-27 20:33:17 +0000343sub do_cmd_versionadded{
344 # one parameter: \versionadded{version}
345 local($_) = @_;
346 my $release = next_argument();
Fred Drake2116d981999-02-02 18:02:48 +0000347 return "\nNew in version $release.\n" . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000348}
349
350sub do_cmd_versionchanged{
351 # one parameter: \versionchanged{version}
352 local($_) = @_;
Fred Drake52e76842000-05-02 17:37:42 +0000353 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000354 my $release = next_argument();
Fred Drake52e76842000-05-02 17:37:42 +0000355 my $text = "\nChanged in version $release.\n";
356 if ($release) {
357 $text = "\nChanged in version $release:\n$explanation.\n";
358 }
359 return $text . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000360}
361
Fred Drake557460c1999-03-02 16:05:35 +0000362#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000363# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000364#
365sub do_cmd_platform{
366 local($_) = @_;
367 my $platform = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000368 $ModulePlatforms{"<tt class='module'>$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000369 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000370 if $platform eq 'Mac';
Fred Drakee15956b2000-04-03 04:51:13 +0000371 return "\n<p class='availability'>Availability: <span"
372 . "\n class='platform'>$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000373}
374
Fred Drake557460c1999-03-02 16:05:35 +0000375$IGNORE_PLATFORM_ANNOTATION = '';
376sub do_cmd_ignorePlatformAnnotation{
377 local($_) = @_;
378 $IGNORE_PLATFORM_ANNOTATION = next_argument();
379 return $_;
380}
381
Fred Drake6659c301998-03-03 22:02:19 +0000382
383# index commands
384
385$INDEX_SUBITEM = "";
386
387sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000388 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000389}
390
391sub do_cmd_setindexsubitem{
392 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000393 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000394 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000395}
396
Fred Drakefc16e781998-03-12 21:03:26 +0000397sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000398 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000399 # do things in the right order, but we need to at least strip this stuff
400 # out, and leave anything that the second argument expanded out to.
401 #
402 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000403 my $oldsubitem = $INDEX_SUBITEM;
404 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000405 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000406 my $br_id = ++$globals{'max_id'};
407 my $marker = "$O$br_id$C";
Fred Drake7d45f6d1999-01-05 14:39:27 +0000408 return
409 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000410 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000411 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000412}
413
Fred Drake08932051998-04-17 02:15:42 +0000414# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000415# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
416# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000417#
Fred Drake62e43691998-08-10 19:40:44 +0000418sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000419
Fred Drake42b31a51998-03-27 05:16:10 +0000420# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000421#
Fred Drake08932051998-04-17 02:15:42 +0000422open(IDXFILE, '>index.dat') || die "\n$!\n";
423open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000424print INTLABELS "%internal_labels = ();\n";
425print INTLABELS "1; # hack in case there are no entries\n\n";
426
427# Using \0 for this is bad because we can't use common tools to work with the
428# resulting files. Things like grep can be useful with this stuff!
429#
430$IDXFILE_FIELD_SEP = "\1";
431
Fred Drakeccc62721999-01-05 22:16:29 +0000432sub write_idxfile{
433 my ($ahref, $str) = @_;
434 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000435}
436
Fred Drake42b31a51998-03-27 05:16:10 +0000437
438sub gen_link{
439 my($node,$target) = @_;
440 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakee15956b2000-04-03 04:51:13 +0000441 return "<a href='$node#$target'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000442}
443
Fred Drake42b31a51998-03-27 05:16:10 +0000444sub add_index_entry{
445 # add an entry to the index structures; ignore the return value
446 my($str,$ahref) = @_;
447 $str = gen_index_id($str, '');
448 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000449 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000450}
451
Fred Drakeccc62721999-01-05 22:16:29 +0000452sub new_link_info{
453 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakee15956b2000-04-03 04:51:13 +0000454 my $aname = "<a name='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000455 my $ahref = gen_link($CURRENT_FILE, $name);
456 return ($name, $aname, $ahref);
457}
458
Fred Drakeab032151999-05-13 18:36:54 +0000459$IndexMacroPattern = '';
460sub define_indexing_macro{
461 my $count = @_;
462 my $i = 0;
463 for (; $i < $count; ++$i) {
464 my $name = @_[$i];
465 my $cmd = "idx_cmd_$name";
466 die "\nNo function $cmd() defined!\n"
467 if (!defined &$cmd);
468 eval ("sub do_cmd_$name { return process_index_macros("
469 . "\@_[0], '$name'); }");
470 if (length($IndexMacroPattern) == 0) {
471 $IndexMacroPattern = "$name";
472 }
473 else {
474 $IndexMacroPattern .= "|$name";
475 }
476 }
477}
478
479$DEBUG_INDEXING = 0;
480sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000481 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000482 my $cmdname = @_[1]; # This is what triggered us in the first place;
483 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000484 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000485 my $cmd = "idx_cmd_$cmdname";
486 print "\nIndexing: \\$cmdname"
487 if $DEBUG_INDEXING;
488 &$cmd($ahref); # modifies $_ and adds index entries
489 while (/^[\s\n]*\\($IndexMacroPattern)</) {
490 $cmdname = "$1";
491 print " \\$cmdname"
492 if $DEBUG_INDEXING;
493 $cmd = "idx_cmd_$cmdname";
494 if (!defined &$cmd) {
495 last;
496 }
497 else {
498 s/^[\s\n]*\\$cmdname//;
499 &$cmd($ahref);
500 }
501 }
Fred Drake62e43691998-08-10 19:40:44 +0000502 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000503}
504
Fred Drakeab032151999-05-13 18:36:54 +0000505define_indexing_macro('index');
506sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000507 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000508 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000509}
510
Fred Drakeab032151999-05-13 18:36:54 +0000511define_indexing_macro('kwindex');
512sub idx_cmd_kwindex{
513 my $str = next_argument();
514 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
515 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
516}
517
518define_indexing_macro('indexii');
519sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000520 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000521 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000522 add_index_entry("$str1!$str2", @_[0]);
523 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000524}
525
Fred Drakeab032151999-05-13 18:36:54 +0000526define_indexing_macro('indexiii');
527sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000528 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000529 my $str2 = next_argument();
530 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000531 add_index_entry("$str1!$str2 $str3", @_[0]);
532 add_index_entry("$str2!$str3, $str1", @_[0]);
533 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000534}
535
Fred Drakeab032151999-05-13 18:36:54 +0000536define_indexing_macro('indexiv');
537sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000538 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000539 my $str2 = next_argument();
540 my $str3 = next_argument();
541 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000542 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
543 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
544 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
545 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000546}
547
Fred Drakeab032151999-05-13 18:36:54 +0000548define_indexing_macro('ttindex');
549sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000550 my $str = next_argument();
551 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000552 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000553}
Fred Drake6659c301998-03-03 22:02:19 +0000554
555sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000556 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000557 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000558 add_index_entry("$str $word", $ahref);
559 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000560}
561
Fred Drakeab032151999-05-13 18:36:54 +0000562define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
563sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
564sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
565sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
566sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000567
Fred Drakeab032151999-05-13 18:36:54 +0000568define_indexing_macro('bifuncindex');
569sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000570 my $str = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000571 add_index_entry("<tt class='function'>$str()</tt> (built-in function)",
572 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000573}
574
575
Fred Drake6659c301998-03-03 22:02:19 +0000576sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000577 my($str,$define) = @_;
578 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000579 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000580 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
581 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000582 $str = gen_index_id($str, $define);
583 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000584 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000585
Fred Drakec9a44381998-03-17 06:29:13 +0000586 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000587 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000588 $str =~ /(<tt.*<\/tt>)/;
589 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000590 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000591 }
Fred Drake62e43691998-08-10 19:40:44 +0000592 return "$aname$anchor_invisible_mark</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000593}
594
Fred Drake557460c1999-03-02 16:05:35 +0000595
Fred Drakec9a44381998-03-17 06:29:13 +0000596$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000597$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000598
Fred Drakea0f4c941998-07-24 22:16:04 +0000599sub define_module{
600 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000601 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000602 if ($word ne "built-in" && $word ne "extension"
603 && $word ne "standard" && $word ne "") {
604 write_warnings("Bad module type '$word'"
605 . " for \\declaremodule (module $name)");
606 $word = "";
607 }
Fred Drake6659c301998-03-03 22:02:19 +0000608 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000609 $THIS_MODULE = "$name";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000610 $INDEX_SUBITEM = "(in $name)";
611 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000612 return make_mod_index_entry(
613 "<tt class='module'>$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000614}
615
616sub my_module_index_helper{
617 local($word, $_) = @_;
618 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000619 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000620}
621
Fred Drake62e43691998-08-10 19:40:44 +0000622sub do_cmd_modindex{ return my_module_index_helper('', @_); }
623sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
624sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
625sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000626
Fred Drakeab032151999-05-13 18:36:54 +0000627sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000628 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000629 my $str = next_argument();
630 $word = "$word " if $word;
Fred Drakee15956b2000-04-03 04:51:13 +0000631 $str = "<tt class='module'>$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000632 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
633 # just inline it all here
634 $str = gen_index_id($str, 'REF');
635 $index{$str} .= $ahref;
636 write_idxfile($ahref, $str);
637}
638
Fred Drake6659c301998-03-03 22:02:19 +0000639# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000640define_indexing_macro('refmodindex', 'refbimodindex',
641 'refexmodindex', 'refstmodindex');
642sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
643sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
644sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
645sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000646
Fred Drake62e43691998-08-10 19:40:44 +0000647sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000648
649sub init_myformat{
Fred Drake38178fd2000-09-22 17:05:04 +0000650 $anchor_invisible_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000651 $anchor_mark = '';
652 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000653}
Fred Drake42b31a51998-03-27 05:16:10 +0000654init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000655
Fred Drakeab032151999-05-13 18:36:54 +0000656# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000657# instead of the dummy filler.
658#
659sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000660 my($str) = @_;
661 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000662 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000663 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000664}
665
Fred Drakee15956b2000-04-03 04:51:13 +0000666$REFCOUNTS_LOADED = 0;
667
668sub load_refcounts{
669 $REFCOUNTS_LOADED = 1;
670
Fred Drakee15956b2000-04-03 04:51:13 +0000671 my $myname, $mydir, $myext;
672 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
673 chop $mydir; # remove trailing '/'
674 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
675 chop $mydir; # remove trailing '/'
676 $mydir = getcwd() . "$dd$mydir"
677 unless $mydir =~ s|^/|/|;
678 local $_;
679 my $filename = "$mydir${dd}api${dd}refcounts.dat";
680 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
681 print "[loading API refcount data]";
682 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000683 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000684 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
685 #print "\n$func($param) --> $count";
686 $REFCOUNTS{"$func:$param"} = $count;
687 }
688 }
689}
690
691sub get_refcount{
692 my ($func, $param) = @_;
693 load_refcounts()
694 unless $REFCOUNTS_LOADED;
695 return $REFCOUNTS{"$func:$param"};
696}
697
Fred Drake6659c301998-03-03 22:02:19 +0000698sub do_env_cfuncdesc{
699 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000700 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000701 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000702 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000703 my $idx = make_str_index_entry(
704 "<tt class='cfunction'>$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000705 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000706 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000707 my $result_rc = get_refcount($function_name, '');
708 my $rcinfo = '';
709 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000710 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000711 }
712 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000713 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000714 }
Fred Drakec2578c52000-04-10 18:26:45 +0000715 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000716 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000717 }
Fred Drakee15956b2000-04-03 04:51:13 +0000718 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000719 $rcinfo = ( "\n<div class=\"refcount-info\">"
720 . "\n <span class=\"label\">Return value:</span>"
721 . "\n <span class=\"value\">$rcinfo.</span>"
722 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000723 }
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000724 return "<dl><dt>$return_type <b>$idx</b> (<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000725 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000726 . $_
727 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000728}
729
Fred Drakee15956b2000-04-03 04:51:13 +0000730sub do_env_csimplemacrodesc{
731 local($_) = @_;
732 my $name = next_argument();
733 my $idx = make_str_index_entry("<tt class='macro'>$name</tt>");
734 return "<dl><dt><b>$idx</b>\n<dd>"
735 . $_
736 . '</dl>'
737}
738
Fred Drake6659c301998-03-03 22:02:19 +0000739sub do_env_ctypedesc{
740 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000741 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000742 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000743 $index_name = $type_name
744 unless $index_name;
745 my($name,$aname,$ahref) = new_link_info();
746 add_index_entry("<tt class='ctype'>$index_name</tt> (C type)", $ahref);
747 return "<dl><dt><b><tt class='ctype'>$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000748 . $_
749 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000750}
751
752sub do_env_cvardesc{
753 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000754 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000755 my $var_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000756 my $idx = make_str_index_entry("<tt class='cdata'>$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000757 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000758 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000759 return "<dl><dt>$var_type <b>$idx</b>\n"
760 . '<dd>'
761 . $_
762 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000763}
764
Fred Drake3cdb89d2000-09-14 20:17:23 +0000765sub convert_args($){
766 local($IN_DESC_HANDLER) = 1;
767 local($_) = @_;
768 return translate_commands($_);
769}
770
Fred Drake6659c301998-03-03 22:02:19 +0000771sub do_env_funcdesc{
772 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000773 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000774 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000775 my $idx = make_str_index_entry("<tt class='function'>$function_name()</tt>"
Fred Drake08932051998-04-17 02:15:42 +0000776 . get_indexsubitem());
777 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000778 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drake62e43691998-08-10 19:40:44 +0000779 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000780}
781
782sub do_env_funcdescni{
783 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000784 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000785 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000786 return "<dl><dt><b><tt class='function'>$function_name</tt></b>"
Fred Drake90fdda51999-02-16 20:27:42 +0000787 . " (<var>$arg_list</var>)\n"
788 . '<dd>'
789 . $_
790 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000791}
792
793sub do_cmd_funcline{
794 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000795 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000796 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000797 my $prefix = "<tt class='function'>$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000798 my $idx = make_str_index_entry($prefix . get_indexsubitem());
799 $prefix =~ s/\(\)//;
800
801 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000802}
803
Fred Drake6b3fb781999-07-12 16:50:09 +0000804sub do_cmd_funclineni{
805 local($_) = @_;
806 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000807 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000808 my $prefix = "<tt class='function'>$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000809
810 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
811}
812
Fred Drake6659c301998-03-03 22:02:19 +0000813# Change this flag to index the opcode entries. I don't think it's very
814# useful to index them, since they're only presented to describe the dis
815# module.
816#
817$INDEX_OPCODES = 0;
818
819sub do_env_opcodedesc{
820 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000821 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000822 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000823 my $idx;
824 if ($INDEX_OPCODES) {
Fred Drakee15956b2000-04-03 04:51:13 +0000825 $idx = make_str_index_entry("<tt class='opcode'>$opcode_name</tt>"
826 . " (byte code instruction)");
Fred Drake08932051998-04-17 02:15:42 +0000827 $idx =~ s/ \(byte code instruction\)//;
828 }
829 else {
Fred Drakee15956b2000-04-03 04:51:13 +0000830 $idx = "<tt class='opcode'>$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +0000831 }
832 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +0000833 if ($arg_list) {
834 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
835 }
Fred Drake62e43691998-08-10 19:40:44 +0000836 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000837}
838
839sub do_env_datadesc{
840 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000841 my $dataname = next_argument();
842 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000843 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000844 return "<dl><dt><b>$idx</b>\n<dd>"
845 . $_
846 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000847}
848
849sub do_env_datadescni{
850 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000851 my $idx = next_argument();
852 if (! $STRING_INDEX_TT) {
853 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +0000854 }
Fred Drake62e43691998-08-10 19:40:44 +0000855 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000856}
857
858sub do_cmd_dataline{
859 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000860 my $data_name = next_argument();
861 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +0000862 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000863 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000864}
865
Fred Drakeadb272c2000-04-10 17:47:14 +0000866sub do_cmd_datalineni{
867 local($_) = @_;
868 my $data_name = next_argument();
869 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
870}
871
Fred Drake42b31a51998-03-27 05:16:10 +0000872sub do_env_excdesc{
873 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000874 my $excname = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000875 my $idx = make_str_index_entry("<tt class='exception'>$excname</tt>");
Fred Drake62e43691998-08-10 19:40:44 +0000876 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>'
Fred Drake42b31a51998-03-27 05:16:10 +0000877}
878
Fred Drake62e43691998-08-10 19:40:44 +0000879sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000880
881
Fred Drake643d76d2000-09-09 06:07:37 +0000882sub handle_classlike_descriptor{
883 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000884 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000885 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000886 $idx = make_str_index_entry(
Fred Drake643d76d2000-09-09 06:07:37 +0000887 "<tt class='$what'>$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +0000888 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000889 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +0000890}
891
Fred Drake643d76d2000-09-09 06:07:37 +0000892sub do_env_classdesc{
893 return handle_classlike_descriptor(@_[0], "class");
894}
895
896sub do_env_excclassdesc{
897 return handle_classlike_descriptor(@_[0], "exception");
898}
899
Fred Drake42b31a51998-03-27 05:16:10 +0000900
901sub do_env_methoddesc{
902 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000903 my $class_name = next_optional_argument();
904 $class_name = $THIS_CLASS
905 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +0000906 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000907 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +0000908 my $extra = '';
909 if ($class_name) {
910 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +0000911 }
Fred Drakee15956b2000-04-03 04:51:13 +0000912 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +0000913 $idx =~ s/ \(.*\)//;
914 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000915 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000916}
917
918
Fred Drake7d45f6d1999-01-05 14:39:27 +0000919sub do_cmd_methodline{
920 local($_) = @_;
921 my $class_name = next_optional_argument();
922 $class_name = $THIS_CLASS
923 unless $class_name;
924 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000925 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +0000926 my $extra = '';
927 if ($class_name) {
928 $extra = " ($class_name method)";
929 }
Fred Drakee15956b2000-04-03 04:51:13 +0000930 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +0000931 $idx =~ s/ \(.*\)//;
932 $idx =~ s/\(\)//;
933 return "<dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>"
934 . $_;
935}
936
937
Fred Draked64a40d1998-09-10 18:59:13 +0000938sub do_cmd_methodlineni{
939 local($_) = @_;
940 next_optional_argument();
941 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000942 my $arg_list = convert_args(next_argument());
Fred Draked64a40d1998-09-10 18:59:13 +0000943 return "<dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
944 . $_;
945}
946
Fred Drake42b31a51998-03-27 05:16:10 +0000947sub do_env_methoddescni{
948 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000949 next_optional_argument();
950 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000951 my $arg_list = convert_args(next_argument());
Fred Drake62e43691998-08-10 19:40:44 +0000952 return "<dl><dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
953 . $_
954 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000955}
956
957
958sub do_env_memberdesc{
959 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000960 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000961 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000962 $class = $THIS_CLASS
963 unless $class;
Fred Drake08932051998-04-17 02:15:42 +0000964 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000965 $extra = " ($class attribute)"
966 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000967 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +0000968 $idx =~ s/ \(.*\)//;
969 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000970 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000971}
972
973
Fred Drake5ccf3301998-04-17 20:04:09 +0000974sub do_cmd_memberline{
975 local($_) = @_;
976 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000977 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +0000978 $class = $THIS_CLASS
979 unless $class;
980 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000981 $extra = " ($class attribute)"
982 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000983 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +0000984 $idx =~ s/ \(.*\)//;
985 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000986 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000987}
988
Fred Drake42b31a51998-03-27 05:16:10 +0000989sub do_env_memberdescni{
990 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000991 next_optional_argument();
992 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000993 return "<dl><dt><b><tt class='member'>$member</tt></b>\n<dd>"
994 . $_
995 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000996}
997
998
Fred Drake5ccf3301998-04-17 20:04:09 +0000999sub do_cmd_memberlineni{
1000 local($_) = @_;
1001 next_optional_argument();
1002 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001003 return "<dt><b><tt class='member'>$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001004}
1005
Fred Drakee15956b2000-04-03 04:51:13 +00001006@col_aligns = ('<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001007
Fred Drakef74e5b71999-04-28 14:58:49 +00001008sub fix_font{
1009 # do a little magic on a font name to get the right behavior in the first
1010 # column of the output table
1011 my $font = @_[0];
1012 if ($font eq 'textrm') {
1013 $font = '';
1014 }
1015 elsif ($font eq 'file' || $font eq 'filenq') {
Fred Drakee15956b2000-04-03 04:51:13 +00001016 $font = 'tt class="file"';
1017 }
1018 elsif ($font eq 'member') {
1019 $font = 'tt class="member"';
Fred Drakef74e5b71999-04-28 14:58:49 +00001020 }
Fred Drake7388f732000-06-28 21:06:08 +00001021 elsif ($font eq 'constant') {
1022 $font = 'tt class="constant"';
1023 }
Fred Drakecb0fc9c2000-08-09 13:45:04 +00001024 elsif ($font eq 'kbd') {
1025 $font = 'kbd';
1026 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001027 return $font;
1028}
1029
Fred Drakee15956b2000-04-03 04:51:13 +00001030sub figure_column_alignment{
1031 my $a = @_[0];
1032 my $mark = substr($a, 0, 1);
1033 my $r = '';
1034 if ($mark eq 'c')
1035 { $r = ' align="center"'; }
1036 elsif ($mark eq 'r')
1037 { $r = ' align="right"'; }
1038 elsif ($mark eq 'l')
1039 { $r = ' align="left"'; }
1040 elsif ($mark eq 'p')
1041 { $r = ' align="left"'; }
1042 return $r;
1043}
1044
Fred Drake6659c301998-03-03 22:02:19 +00001045sub setup_column_alignments{
1046 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001047 my($s1,$s2,$s3,$s4) = split(/[|]/,$_);
1048 my $a1 = figure_column_alignment($s1);
1049 my $a2 = figure_column_alignment($s2);
1050 my $a3 = figure_column_alignment($s3);
1051 my $a4 = figure_column_alignment($s4);
1052 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1053 $col_aligns[1] = "<td$a2>";
1054 $col_aligns[2] = "<td$a3>";
1055 $col_aligns[3] = "<td$a4>";
Fred Drake79189b51999-04-28 13:54:30 +00001056 # return the aligned header start tags
Fred Drakee15956b2000-04-03 04:51:13 +00001057 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>");
1058}
1059
1060sub get_table_col1_fonts{
1061 my $font = $globals{'lineifont'};
1062 my ($sfont,$efont) = ('', '');
1063 if ($font) {
1064 $sfont = "<$font>";
1065 $efont = "</$font>";
1066 $efont =~ s/ .*>/>/;
1067 }
1068 return ($font, $sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001069}
1070
1071sub do_env_tableii{
1072 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001073 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001074 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001075 my $h1 = next_argument();
1076 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001077 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001078 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001079 my $a1 = $col_aligns[0];
1080 my $a2 = $col_aligns[1];
1081 s/\\lineii</\\lineii[$a1|$a2]</g;
1082 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001083 . "\n <thead>"
Fred Drake3be20742000-08-31 06:22:54 +00001084 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001085 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1086 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001087 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001088 . "\n <tbody valign='baseline'>"
1089 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001090 . "\n </tbody>"
1091 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001092}
1093
Fred Drakeda72b932000-09-21 15:58:02 +00001094sub do_env_longtableii{
1095 return do_env_tableii(@_);
1096}
1097
Fred Drake6659c301998-03-03 22:02:19 +00001098sub do_cmd_lineii{
1099 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001100 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001101 my $c1 = next_argument();
1102 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001103 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001104 my($font,$sfont,$efont) = get_table_col1_fonts();
1105 $c2 = '&nbsp;' if ($c2 eq '');
1106 my($c1align,$c2align) = split('\|', $aligns);
1107 my $padding = '';
1108 if ($c1align =~ /align="right"/) {
1109 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001110 }
Fred Drakee15956b2000-04-03 04:51:13 +00001111 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1112 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001113 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001114}
1115
1116sub do_env_tableiii{
1117 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001118 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001119 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001120 my $h1 = next_argument();
1121 my $h2 = next_argument();
1122 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001123 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001124 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001125 my $a1 = $col_aligns[0];
1126 my $a2 = $col_aligns[1];
1127 my $a3 = $col_aligns[2];
1128 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1129 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001130 . "\n <thead>"
1131 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001132 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1133 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1134 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001135 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001136 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001137 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001138 . "\n </tbody>"
1139 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001140}
1141
Fred Drakeda72b932000-09-21 15:58:02 +00001142sub do_env_longtableiii{
1143 return do_env_tableiii(@_);
1144}
1145
Fred Drake6659c301998-03-03 22:02:19 +00001146sub do_cmd_lineiii{
1147 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001148 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001149 my $c1 = next_argument();
1150 my $c2 = next_argument();
1151 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001152 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001153 my($font,$sfont,$efont) = get_table_col1_fonts();
1154 $c3 = '&nbsp;' if ($c3 eq '');
1155 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1156 my $padding = '';
1157 if ($c1align =~ /align="right"/) {
1158 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001159 }
Fred Drakee15956b2000-04-03 04:51:13 +00001160 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001161 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001162 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001163 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001164}
1165
Fred Drakea0f4c941998-07-24 22:16:04 +00001166sub do_env_tableiv{
1167 local($_) = @_;
1168 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001169 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001170 my $h1 = next_argument();
1171 my $h2 = next_argument();
1172 my $h3 = next_argument();
1173 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001174 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001175 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001176 my $a1 = $col_aligns[0];
1177 my $a2 = $col_aligns[1];
1178 my $a3 = $col_aligns[2];
1179 my $a4 = $col_aligns[3];
1180 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1181 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001182 . "\n <thead>"
1183 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001184 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1185 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1186 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1187 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001188 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001189 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001190 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001191 . "\n </tbody>"
1192 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001193}
1194
Fred Drakeda72b932000-09-21 15:58:02 +00001195sub do_env_longtableiv{
1196 return do_env_tableiv(@_);
1197}
1198
Fred Drakea0f4c941998-07-24 22:16:04 +00001199sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001200 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001201 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001202 my $c1 = next_argument();
1203 my $c2 = next_argument();
1204 my $c3 = next_argument();
1205 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001206 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001207 my($font,$sfont,$efont) = get_table_col1_fonts();
1208 $c4 = '&nbsp;' if ($c4 eq '');
1209 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1210 my $padding = '';
1211 if ($c1align =~ /align="right"/) {
1212 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001213 }
Fred Drakee15956b2000-04-03 04:51:13 +00001214 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001215 . " $c2align$c2</td>\n"
1216 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001217 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001218 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001219}
1220
Fred Drake3be20742000-08-31 06:22:54 +00001221
1222# These can be used to control the title page appearance;
1223# they need a little bit of documentation.
1224#
1225# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1226# $ICONSERVER directory, or include path information (other than "./"). The
1227# default image type will be assumed if an extension is not provided.
1228#
1229# If specified, the "title page" will contain two colums: one containing the
1230# title/author/etc., and the other containing the graphic. Use the other
1231# four variables listed here to control specific details of the layout; all
1232# are optional.
1233#
1234# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1235# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1236# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1237# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1238# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1239
1240sub make_my_titlepage() {
1241 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001242 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001243 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001244 }
1245 else {
1246 write_warnings("\nThis document has no title.");
1247 }
Fred Drake6659c301998-03-03 22:02:19 +00001248 if ($t_author) {
1249 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001250 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001251 $href = make_named_href('author', $href,
1252 "<b><font size='+2'>$t_author</font></b>");
Fred Drakec9a44381998-03-17 06:29:13 +00001253 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001254 }
1255 else {
Fred Drake2d1f81e1999-02-09 16:03:31 +00001256 $the_title .= ("\n<p><b><font size='+2'>$t_author</font></b></p>");
Fred Drake6659c301998-03-03 22:02:19 +00001257 }
Fred Drake3be20742000-08-31 06:22:54 +00001258 }
1259 else {
1260 write_warnings("\nThere is no author for this document.");
1261 }
Fred Drake6659c301998-03-03 22:02:19 +00001262 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001263 $the_title .= "\n<p>$t_institute</p>";
1264 }
Fred Draked07868a1998-05-14 21:00:28 +00001265 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001266 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1267 }
Fred Drake6659c301998-03-03 22:02:19 +00001268 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001269 $the_title .= "\n<p><i>$t_affil</i></p>";
1270 }
Fred Drake6659c301998-03-03 22:02:19 +00001271 if ($t_date) {
Fred Drakec9a44381998-03-17 06:29:13 +00001272 $the_title .= "\n<p><strong>$t_date</strong>";
Fred Drake6659c301998-03-03 22:02:19 +00001273 if ($PYTHON_VERSION) {
Fred Drake3be20742000-08-31 06:22:54 +00001274 $the_title .= "<br><strong>Release $PYTHON_VERSION</strong>";
1275 }
Fred Drake6659c301998-03-03 22:02:19 +00001276 $the_title .= "</p>"
1277 }
1278 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001279 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001280 }
1281 else {
1282 $the_title .= "\n<p>";
1283 }
Fred Drake6659c301998-03-03 22:02:19 +00001284 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001285 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001286 }
1287 return $the_title;
1288}
1289
Fred Drake3be20742000-08-31 06:22:54 +00001290sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001291 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001292 my $graphic = "<td class=\"titlegraphic\"";
1293 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1294 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1295 $graphic .= "><img";
1296 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1297 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1298 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1299 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001300 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001301 return $graphic;
1302}
1303
1304sub do_cmd_maketitle {
1305 local($_) = @_;
1306 my $the_title = "\n<div class=\"titlepage\">";
1307 if ($TITLE_PAGE_GRAPHIC) {
1308 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1309 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1310 . "<tr align=\"right\">\n<td>"
1311 . make_my_titlepage()
1312 . "</td>\n"
1313 . make_my_titlegraphic()
1314 . "</tr>\n</table>");
1315 }
1316 else {
1317 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1318 . make_my_titlegraphic()
1319 . "<td>"
1320 . make_my_titlepage()
1321 . "</td></tr>\n</table>");
1322 }
1323 }
1324 else {
1325 $the_title .= ("\n<center>"
1326 . make_my_titlepage()
1327 . "\n</center>");
1328 }
1329 $the_title .= "\n</div>";
1330 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001331 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001332 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001333}
1334
1335
Fred Drake885215c1998-05-20 21:32:09 +00001336#
Fred Drakea0f4c941998-07-24 22:16:04 +00001337# Module synopsis support
1338#
1339
1340require SynopsisTable;
1341
Fred Drakef7685d71998-07-25 03:31:46 +00001342sub get_chapter_id(){
1343 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001344 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1345 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001346 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001347}
1348
Fred Drake643d76d2000-09-09 06:07:37 +00001349# 'chapter' => 'SynopsisTable instance'
1350%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001351
1352sub get_synopsis_table($){
1353 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001354 my $key;
1355 foreach $key (keys %ModuleSynopses) {
1356 if ($key eq $chap) {
1357 return $ModuleSynopses{$chap};
1358 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001359 }
Fred Drake643d76d2000-09-09 06:07:37 +00001360 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001361 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001362 return $st;
1363}
1364
Fred Drake62e43691998-08-10 19:40:44 +00001365sub do_cmd_moduleauthor{
1366 local($_) = @_;
1367 next_argument();
1368 next_argument();
1369 return $_;
1370}
1371
1372sub do_cmd_sectionauthor{
1373 local($_) = @_;
1374 next_argument();
1375 next_argument();
1376 return $_;
1377}
1378
Fred Drakea0f4c941998-07-24 22:16:04 +00001379sub do_cmd_declaremodule{
1380 local($_) = @_;
1381 my $key = next_optional_argument();
1382 my $type = next_argument();
1383 my $name = next_argument();
1384 my $st = get_synopsis_table(get_chapter_id());
1385 #
1386 $key = $name unless $key;
1387 $type = 'built-in' if $type eq 'builtin';
1388 $st->declare($name, $key, $type);
1389 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001390 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001391}
1392
1393sub do_cmd_modulesynopsis{
1394 local($_) = @_;
1395 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001396 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001397 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001398}
1399
1400sub do_cmd_localmoduletable{
1401 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001402 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001403 my $st = get_synopsis_table($chap);
1404 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001405 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001406}
1407
1408sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001409 my $key;
1410 my $st, $file;
1411 foreach $key (keys %ModuleSynopses) {
1412 $st = $ModuleSynopses{$key};
1413 $file = $st->get_file();
1414 if ($file) {
1415 process_localmoduletables_in_file($file);
1416 }
1417 else {
1418 print "\nsynopsis table $key has no file association";
1419 }
1420 }
1421}
1422
1423sub process_localmoduletables_in_file{
1424 my $file = @_[0];
1425 open(MYFILE, "<$file");
1426 local($_);
1427 sysread(MYFILE, $_, 1024*1024);
1428 close(MYFILE);
1429 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001430 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001431 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001432 my $chap = $1;
1433 my $st = get_synopsis_table($chap);
1434 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001435 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001436 }
Fred Drake643d76d2000-09-09 06:07:37 +00001437 open(MYFILE,">$file");
1438 print MYFILE $_;
1439 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001440}
Fred Drake557460c1999-03-02 16:05:35 +00001441sub process_python_state{
1442 process_all_localmoduletables();
Fred Drake557460c1999-03-02 16:05:35 +00001443}
Fred Drakea0f4c941998-07-24 22:16:04 +00001444
1445
1446#
1447# "See also:" -- references placed at the end of a \section
1448#
1449
1450sub do_env_seealso{
Fred Drakee15956b2000-04-03 04:51:13 +00001451 return "<div class='seealso'>\n "
1452 . "<p class='heading'><b>See Also:</b></p>\n"
Fred Drake90fdda51999-02-16 20:27:42 +00001453 . @_[0]
1454 . '</div>';
Fred Drakea0f4c941998-07-24 22:16:04 +00001455}
1456
1457sub do_cmd_seemodule{
1458 # Insert the right magic to jump to the module definition. This should
1459 # work most of the time, at least for repeat builds....
1460 local($_) = @_;
1461 my $key = next_optional_argument();
1462 my $module = next_argument();
1463 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001464 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001465 $key = $module
1466 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001467 if ($text =~ /\.$/) {
1468 $period = '';
1469 }
Fred Drakee15956b2000-04-03 04:51:13 +00001470 return '<dl compact class="seemodule">'
1471 . "\n <dt>Module <b><tt class='module'><a href='module-$key.html'>"
Fred Drake84bd6f31999-05-11 15:42:51 +00001472 . "$module</a></tt>:</b>"
1473 . "\n <dd>$text$period\n </dl>"
Fred Drake90fdda51999-02-16 20:27:42 +00001474 . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001475}
1476
Fred Drake643d76d2000-09-09 06:07:37 +00001477sub handle_rfclike_reference{
1478 local($_, $what) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001479 my $rfcnum = next_argument();
1480 my $title = next_argument();
1481 my $text = next_argument();
1482 my $url = get_rfc_url($rfcnum);
Fred Drake7a40c072000-10-02 14:43:38 +00001483 my $icon = get_link_icon($url);
Fred Drake37cc0c02000-04-26 18:05:24 +00001484 return '<dl compact class="seerfc">'
1485 . "\n <dt><a href=\"$url\""
1486 . "\n title=\"$title\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001487 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001488 . "\n <dd>$text\n </dl>"
1489 . $_;
1490}
1491
Fred Drake643d76d2000-09-09 06:07:37 +00001492sub do_cmd_seepep{
1493 return handle_rfclike_reference(@_[0], "PEP");
1494}
1495
1496sub do_cmd_seerfc{
1497 return handle_rfclike_reference(@_[0], "RFC");
1498}
1499
Fred Drake48449982000-09-12 17:52:33 +00001500sub do_cmd_seetitle{
1501 local($_) = @_;
1502 my $url = next_optional_argument();
1503 my $title = next_argument();
1504 my $text = next_argument();
1505 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001506 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001507 return '<dl compact class="seetitle">'
1508 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001509 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001510 . "\n <dd>$text\n </dl>"
1511 . $_;
1512 }
1513 return '<dl compact class="seetitle">'
1514 . "\n <dt><em class=\"citetitle\""
1515 . "\n >$title</em>"
1516 . "\n <dd>$text\n </dl>"
1517 . $_;
1518}
1519
Fred Drakeef4d1112000-05-09 16:17:51 +00001520sub do_cmd_seeurl{
1521 local($_) = @_;
1522 my $url = next_argument();
1523 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001524 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001525 return '<dl compact class="seeurl">'
1526 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001527 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001528 . "\n <dd>$text\n </dl>"
1529 . $_;
1530}
1531
Fred Drakea0f4c941998-07-24 22:16:04 +00001532sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001533 local($_) = @_;
1534 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001535 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001536}
1537
1538
1539#
Fred Drake885215c1998-05-20 21:32:09 +00001540# Definition list support.
1541#
1542
1543sub do_env_definitions{
Fred Drake37cc0c02000-04-26 18:05:24 +00001544 return "<dl class='definitions'>" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001545}
1546
1547sub do_cmd_term{
1548 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001549 my $term = next_argument();
1550 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001551 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001552 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001553}
1554
1555
Fred Drake38178fd2000-09-22 17:05:04 +00001556# I don't recall exactly why this was needed, but it was very much needed.
1557# We'll see if anything breaks when I move the "code" line out -- some
1558# things broke with it in.
1559
1560#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001561process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001562declaremodule # [] # {} # {}
1563memberline # [] # {}
1564methodline # [] # {} # {}
1565modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001566platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001567samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001568setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001569withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001570_RAW_ARG_DEFERRED_CMDS_
1571
1572
Fred Drake6659c301998-03-03 22:02:19 +000015731; # This must be the last line