blob: e6555d78dd492382c5c6443b268ce71fa5a5a282 [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
11
Fred Drake08932051998-04-17 02:15:42 +000012sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000013 my $param;
14 $param = missing_braces()
15 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
16 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000017 return $param;
Fred Drake08932051998-04-17 02:15:42 +000018}
19
20sub next_optional_argument{
21 my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000022 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000023 return $param;
Fred Drake08932051998-04-17 02:15:42 +000024}
25
Fred Drakee16f6791998-05-15 04:28:37 +000026
27# This is a fairly simple hack; it supports \let when it is used to create
28# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000029# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000030#
31sub do_cmd_let{
32 local($_) = @_;
33 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000034 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000035 if ($matched) {
36 my($new, $old) = ($1, $3);
37 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
38 print "\ndefining handler for \\$new using \\$old\n";
39 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000040 else {
41 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
42 if ($matched) {
43 my($new, $char) = ($1, $3);
44 eval "sub do_cmd_$new { \"\\$char\" . \@_[0]; }";
45 print "\ndefining handler for \\$new to insert '$char'\n";
46 }
47 else {
48 write_warnings("Could not interpret \\let construct...");
49 }
50 }
Fred Drake62e43691998-08-10 19:40:44 +000051 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000052}
53
54
Fred Drakec3fd45f2000-06-15 22:41:48 +000055# the older version of LaTeX2HTML we use doesn't support this, but we use it:
56
57sub do_cmd_textasciitilde{ '~' . @_[0]; }
58
59
Fred Drake6659c301998-03-03 22:02:19 +000060# words typeset in a special way (not in HTML though)
61
62sub do_cmd_ABC{ 'ABC' . @_[0]; }
63sub do_cmd_UNIX{ 'Unix'. @_[0]; }
64sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
65sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
66sub do_cmd_C{ 'C' . @_[0]; }
67sub do_cmd_Cpp{ 'C++' . @_[0]; }
68sub do_cmd_EOF{ 'EOF' . @_[0]; }
Fred Drakee15956b2000-04-03 04:51:13 +000069sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +000070
71sub do_cmd_e{ '&#92;' . @_[0]; }
72
Fred Draked07868a1998-05-14 21:00:28 +000073$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +000074$SHORT_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +000075$PYTHON_VERSION = '';
76
77sub do_cmd_version{ $PYTHON_VERSION . @_[0]; }
Fred Drake3cdb89d2000-09-14 20:17:23 +000078sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +000079sub do_cmd_release{
80 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +000081 $PYTHON_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +000082 return $_;
Fred Drake6659c301998-03-03 22:02:19 +000083}
84
Fred Drake3cdb89d2000-09-14 20:17:23 +000085sub do_cmd_setshortversion{
86 local($_) = @_;
87 $SHORT_VERSION = next_argument();
88 return $_;
89}
90
Fred Drake6659c301998-03-03 22:02:19 +000091sub do_cmd_authoraddress{
92 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +000093 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +000094 return $_;
Fred Drake6659c301998-03-03 22:02:19 +000095}
96
Fred Drakee16f6791998-05-15 04:28:37 +000097#sub do_cmd_developer{ do_cmd_author(@_[0]); }
98#sub do_cmd_developers{ do_cmd_author(@_[0]); }
99#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000100
Fred Drake6659c301998-03-03 22:02:19 +0000101sub do_cmd_hackscore{
102 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000103 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000104 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000105}
106
Fred Drake08932051998-04-17 02:15:42 +0000107sub use_wrappers{
108 local($_,$before,$after) = @_;
109 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000110 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000111}
112
Fred Drake62e43691998-08-10 19:40:44 +0000113sub use_sans_serif{
Fred Drakeccc62721999-01-05 22:16:29 +0000114 return use_wrappers(@_[0], '<font face="sans-serif">', '</font>');
Fred Drake62e43691998-08-10 19:40:44 +0000115}
116sub use_italics{
117 return use_wrappers(@_[0], '<i>', '</i>');
118}
Fred Drake08932051998-04-17 02:15:42 +0000119
Fred Drake3cdb89d2000-09-14 20:17:23 +0000120$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000121sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000122 if ($IN_DESC_HANDLER) {
123 return use_wrappers(@_[0], "</var><big>\[</big><var>",
124 "</var><big>\]</big><var>");
125 }
126 else {
127 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
128 }
Fred Drake6659c301998-03-03 22:02:19 +0000129}
130
Fred Drakec9a44381998-03-17 06:29:13 +0000131# Logical formatting (some based on texinfo), needs to be converted to
132# minimalist HTML. The "minimalist" is primarily to reduce the size of
133# output files for users that read them over the network rather than
134# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000135
Fred Drake2cafcbb1999-03-25 16:57:04 +0000136# \file and \samp are at the end of this file since they screw up fontlock.
137
Fred Drake2ff880e1999-02-05 18:31:29 +0000138sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000139sub do_cmd_makevar{
140 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000141sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000142 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000143sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000144 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000145sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000146 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000147sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000148 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000149sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000150 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000151sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000152 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000153sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000154 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000155sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000156 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000157sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000158 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000159sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000160 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000161sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000162 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000163sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000164 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000165sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000166 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000167sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000168 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000169sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000170 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000171sub do_cmd_programopt{
172 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000173sub do_cmd_longprogramopt{
174 # note that the --- will be later converted to -- by LaTeX2HTML
175 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000176sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000177 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000178sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000179 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000180sub do_cmd_var{
181 return use_wrappers(@_[0], "<var>", "</var>"); }
182sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000183 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_emph{
185 return use_italics(@_); }
186sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000187 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000188sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000189 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000191 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_kbd{
193 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
194sub do_cmd_strong{
195 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000196sub do_cmd_textbf{
197 return use_wrappers(@_[0], '<b>', '</b>'); }
198sub do_cmd_textit{
199 return use_wrappers(@_[0], '<i>', '</i>'); }
200
Fred Drake3d5a04a2000-08-03 17:25:44 +0000201sub do_cmd_moreargs{
202 return '...' . @_[0]; }
203sub do_cmd_unspecified{
204 return '...' . @_[0]; }
205
Fred Drakec9a44381998-03-17 06:29:13 +0000206
Fred Drake25817041999-01-13 17:06:34 +0000207sub do_cmd_refmodule{
208 # Insert the right magic to jump to the module definition.
209 local($_) = @_;
210 my $key = next_optional_argument();
211 my $module = next_argument();
212 $key = $module
213 unless $key;
Fred Drakee15956b2000-04-03 04:51:13 +0000214 return "<tt class='module'><a href='module-$key.html'>$module</a></tt>"
215 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000216}
217
Fred Drake1a7af391998-04-01 22:44:56 +0000218sub do_cmd_newsgroup{
219 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000220 my $newsgroup = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000221 my $stuff = "<span class='newsgroup'><a href='news:$newsgroup'>"
222 . "$newsgroup</a></span>";
Fred Drake62e43691998-08-10 19:40:44 +0000223 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000224}
Fred Drakefc16e781998-03-12 21:03:26 +0000225
226sub do_cmd_envvar{
227 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000228 my $envvar = next_argument();
229 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000230 # The <tt> here is really to keep buildindex.py from making
231 # the variable name case-insensitive.
232 add_index_entry("environment variables!$envvar@<tt>\$$envvar</tt>",
233 $ahref);
Fred Drake42b31a51998-03-27 05:16:10 +0000234 add_index_entry("$envvar@\$$envvar", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000235 $aname =~ s/<a/<a class="envvar"/;
Fred Draked37cecf1999-09-23 16:45:08 +0000236 return "$aname\$$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000237}
238
Fred Drake6659c301998-03-03 22:02:19 +0000239sub do_cmd_url{
240 # use the URL as both text and hyperlink
241 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000242 my $url = next_argument();
Fred Drake6659c301998-03-03 22:02:19 +0000243 $url =~ s/~/&#126;/g;
Fred Drakee15956b2000-04-03 04:51:13 +0000244 return "<a class=\"url\" href=\"$url\">$url</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000245}
246
247sub do_cmd_manpage{
248 # two parameters: \manpage{name}{section}
249 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000250 my $page = next_argument();
251 my $section = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000252 return "<span class='manpage'><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000253}
254
Fred Drake643d76d2000-09-09 06:07:37 +0000255sub get_pep_url{
256 my $rfcnum = sprintf("%04d", @_[0]);
257 return "http://python.sourceforge.net/peps/pep-$rfcnum.html";
258}
259
260sub do_cmd_pep{
261 local($_) = @_;
262 my $rfcnumber = next_argument();
263 my $id = "rfcref-" . ++$global{'max_id'};
264 my $href = get_pep_url($rfcnumber);
265 # Save the reference
266 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
267 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
268 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber</a>"
269 . $_);
270}
271
Fred Drake37cc0c02000-04-26 18:05:24 +0000272sub get_rfc_url{
273 my $rfcnum = sprintf("%04d", @_[0]);
274 return "http://www.ietf.org/rfc/rfc$rfcnum.txt";
275}
276
Fred Drake6659c301998-03-03 22:02:19 +0000277sub do_cmd_rfc{
278 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000279 my $rfcnumber = next_argument();
280 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drake37cc0c02000-04-26 18:05:24 +0000281 my $href = get_rfc_url($rfcnumber);
Fred Drake6659c301998-03-03 22:02:19 +0000282 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000283 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000284 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drakee15956b2000-04-03 04:51:13 +0000285 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber</a>"
Fred Draked52879c1999-09-22 19:58:51 +0000286 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000287}
288
Fred Drakec9f5fe01999-11-09 16:59:42 +0000289sub do_cmd_citetitle{
290 local($_) = @_;
291 my $url = next_optional_argument();
292 my $title = next_argument();
293 my $repl = '';
294 if ($url) {
295 $repl = ("<em class='citetitle'><a\n"
296 . " href='$url'\n"
297 . " title='$title'\n"
298 . " >$title</a></em>");
299 }
300 else {
301 $repl = "<em class='citetitle'\n >$title</em>";
302 }
303 return $repl . $_;
304}
305
Fred Drake6659c301998-03-03 22:02:19 +0000306sub do_cmd_deprecated{
307 # two parameters: \deprecated{version}{whattodo}
308 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000309 my $release = next_argument();
310 my $reason = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000311 return "<b>Deprecated since release $release.</b>\n$reason<p>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000312}
313
Fred Drake897d12b1998-07-27 20:33:17 +0000314sub do_cmd_versionadded{
315 # one parameter: \versionadded{version}
316 local($_) = @_;
317 my $release = next_argument();
Fred Drake2116d981999-02-02 18:02:48 +0000318 return "\nNew in version $release.\n" . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000319}
320
321sub do_cmd_versionchanged{
322 # one parameter: \versionchanged{version}
323 local($_) = @_;
Fred Drake52e76842000-05-02 17:37:42 +0000324 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000325 my $release = next_argument();
Fred Drake52e76842000-05-02 17:37:42 +0000326 my $text = "\nChanged in version $release.\n";
327 if ($release) {
328 $text = "\nChanged in version $release:\n$explanation.\n";
329 }
330 return $text . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000331}
332
Fred Drake557460c1999-03-02 16:05:35 +0000333#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000334# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000335#
336sub do_cmd_platform{
337 local($_) = @_;
338 my $platform = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000339 $ModulePlatforms{"<tt class='module'>$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000340 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000341 if $platform eq 'Mac';
Fred Drakee15956b2000-04-03 04:51:13 +0000342 return "\n<p class='availability'>Availability: <span"
343 . "\n class='platform'>$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000344}
345
Fred Drake557460c1999-03-02 16:05:35 +0000346$IGNORE_PLATFORM_ANNOTATION = '';
347sub do_cmd_ignorePlatformAnnotation{
348 local($_) = @_;
349 $IGNORE_PLATFORM_ANNOTATION = next_argument();
350 return $_;
351}
352
Fred Drake6659c301998-03-03 22:02:19 +0000353
354# index commands
355
356$INDEX_SUBITEM = "";
357
358sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000359 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000360}
361
362sub do_cmd_setindexsubitem{
363 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000364 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000365 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000366}
367
Fred Drakefc16e781998-03-12 21:03:26 +0000368sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000369 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000370 # do things in the right order, but we need to at least strip this stuff
371 # out, and leave anything that the second argument expanded out to.
372 #
373 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000374 my $oldsubitem = $INDEX_SUBITEM;
375 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000376 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000377 my $br_id = ++$globals{'max_id'};
378 my $marker = "$O$br_id$C";
Fred Drake7d45f6d1999-01-05 14:39:27 +0000379 return
380 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000381 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000382 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000383}
384
Fred Drake08932051998-04-17 02:15:42 +0000385# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000386# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
387# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000388#
Fred Drake62e43691998-08-10 19:40:44 +0000389sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000390
Fred Drake42b31a51998-03-27 05:16:10 +0000391# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000392#
Fred Drake08932051998-04-17 02:15:42 +0000393open(IDXFILE, '>index.dat') || die "\n$!\n";
394open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000395print INTLABELS "%internal_labels = ();\n";
396print INTLABELS "1; # hack in case there are no entries\n\n";
397
398# Using \0 for this is bad because we can't use common tools to work with the
399# resulting files. Things like grep can be useful with this stuff!
400#
401$IDXFILE_FIELD_SEP = "\1";
402
Fred Drakeccc62721999-01-05 22:16:29 +0000403sub write_idxfile{
404 my ($ahref, $str) = @_;
405 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000406}
407
Fred Drake42b31a51998-03-27 05:16:10 +0000408
409sub gen_link{
410 my($node,$target) = @_;
411 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakee15956b2000-04-03 04:51:13 +0000412 return "<a href='$node#$target'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000413}
414
Fred Drake42b31a51998-03-27 05:16:10 +0000415sub add_index_entry{
416 # add an entry to the index structures; ignore the return value
417 my($str,$ahref) = @_;
418 $str = gen_index_id($str, '');
419 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000420 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000421}
422
Fred Drakeccc62721999-01-05 22:16:29 +0000423sub new_link_info{
424 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakee15956b2000-04-03 04:51:13 +0000425 my $aname = "<a name='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000426 my $ahref = gen_link($CURRENT_FILE, $name);
427 return ($name, $aname, $ahref);
428}
429
Fred Drakeab032151999-05-13 18:36:54 +0000430$IndexMacroPattern = '';
431sub define_indexing_macro{
432 my $count = @_;
433 my $i = 0;
434 for (; $i < $count; ++$i) {
435 my $name = @_[$i];
436 my $cmd = "idx_cmd_$name";
437 die "\nNo function $cmd() defined!\n"
438 if (!defined &$cmd);
439 eval ("sub do_cmd_$name { return process_index_macros("
440 . "\@_[0], '$name'); }");
441 if (length($IndexMacroPattern) == 0) {
442 $IndexMacroPattern = "$name";
443 }
444 else {
445 $IndexMacroPattern .= "|$name";
446 }
447 }
448}
449
450$DEBUG_INDEXING = 0;
451sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000452 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000453 my $cmdname = @_[1]; # This is what triggered us in the first place;
454 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000455 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000456 my $cmd = "idx_cmd_$cmdname";
457 print "\nIndexing: \\$cmdname"
458 if $DEBUG_INDEXING;
459 &$cmd($ahref); # modifies $_ and adds index entries
460 while (/^[\s\n]*\\($IndexMacroPattern)</) {
461 $cmdname = "$1";
462 print " \\$cmdname"
463 if $DEBUG_INDEXING;
464 $cmd = "idx_cmd_$cmdname";
465 if (!defined &$cmd) {
466 last;
467 }
468 else {
469 s/^[\s\n]*\\$cmdname//;
470 &$cmd($ahref);
471 }
472 }
Fred Drake62e43691998-08-10 19:40:44 +0000473 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000474}
475
Fred Drakeab032151999-05-13 18:36:54 +0000476define_indexing_macro('index');
477sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000478 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000479 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000480}
481
Fred Drakeab032151999-05-13 18:36:54 +0000482define_indexing_macro('kwindex');
483sub idx_cmd_kwindex{
484 my $str = next_argument();
485 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
486 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
487}
488
489define_indexing_macro('indexii');
490sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000491 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000492 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000493 add_index_entry("$str1!$str2", @_[0]);
494 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000495}
496
Fred Drakeab032151999-05-13 18:36:54 +0000497define_indexing_macro('indexiii');
498sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000499 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000500 my $str2 = next_argument();
501 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000502 add_index_entry("$str1!$str2 $str3", @_[0]);
503 add_index_entry("$str2!$str3, $str1", @_[0]);
504 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000505}
506
Fred Drakeab032151999-05-13 18:36:54 +0000507define_indexing_macro('indexiv');
508sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000509 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000510 my $str2 = next_argument();
511 my $str3 = next_argument();
512 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000513 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
514 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
515 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
516 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000517}
518
Fred Drakeab032151999-05-13 18:36:54 +0000519define_indexing_macro('ttindex');
520sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000521 my $str = next_argument();
522 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000523 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000524}
Fred Drake6659c301998-03-03 22:02:19 +0000525
526sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000527 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000528 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000529 add_index_entry("$str $word", $ahref);
530 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000531}
532
Fred Drakeab032151999-05-13 18:36:54 +0000533define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
534sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
535sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
536sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
537sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000538
Fred Drakeab032151999-05-13 18:36:54 +0000539define_indexing_macro('bifuncindex');
540sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000541 my $str = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000542 add_index_entry("<tt class='function'>$str()</tt> (built-in function)",
543 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000544}
545
546
Fred Drake6659c301998-03-03 22:02:19 +0000547sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000548 my($str,$define) = @_;
549 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000550 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000551 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
552 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000553 $str = gen_index_id($str, $define);
554 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000555 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000556
Fred Drakec9a44381998-03-17 06:29:13 +0000557 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000558 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000559 $str =~ /(<tt.*<\/tt>)/;
560 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000561 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000562 }
Fred Drake62e43691998-08-10 19:40:44 +0000563 return "$aname$anchor_invisible_mark</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000564}
565
Fred Drake557460c1999-03-02 16:05:35 +0000566
Fred Drakec9a44381998-03-17 06:29:13 +0000567$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000568$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000569
Fred Drakea0f4c941998-07-24 22:16:04 +0000570sub define_module{
571 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000572 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000573 if ($word ne "built-in" && $word ne "extension"
574 && $word ne "standard" && $word ne "") {
575 write_warnings("Bad module type '$word'"
576 . " for \\declaremodule (module $name)");
577 $word = "";
578 }
Fred Drake6659c301998-03-03 22:02:19 +0000579 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000580 $THIS_MODULE = "$name";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000581 $INDEX_SUBITEM = "(in $name)";
582 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000583 return make_mod_index_entry(
584 "<tt class='module'>$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000585}
586
587sub my_module_index_helper{
588 local($word, $_) = @_;
589 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000590 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000591}
592
Fred Drake62e43691998-08-10 19:40:44 +0000593sub do_cmd_modindex{ return my_module_index_helper('', @_); }
594sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
595sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
596sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000597
Fred Drakeab032151999-05-13 18:36:54 +0000598sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000599 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000600 my $str = next_argument();
601 $word = "$word " if $word;
Fred Drakee15956b2000-04-03 04:51:13 +0000602 $str = "<tt class='module'>$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000603 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
604 # just inline it all here
605 $str = gen_index_id($str, 'REF');
606 $index{$str} .= $ahref;
607 write_idxfile($ahref, $str);
608}
609
Fred Drake6659c301998-03-03 22:02:19 +0000610# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000611define_indexing_macro('refmodindex', 'refbimodindex',
612 'refexmodindex', 'refstmodindex');
613sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
614sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
615sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
616sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000617
Fred Drake62e43691998-08-10 19:40:44 +0000618sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000619
620sub init_myformat{
Fred Drake08932051998-04-17 02:15:42 +0000621# $anchor_invisible_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000622 $anchor_mark = '';
623 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000624}
Fred Drake42b31a51998-03-27 05:16:10 +0000625init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000626
Fred Drakeab032151999-05-13 18:36:54 +0000627# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000628# instead of the dummy filler.
629#
630sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000631 my($str) = @_;
632 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000633 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000634 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000635}
636
Fred Drakee15956b2000-04-03 04:51:13 +0000637$REFCOUNTS_LOADED = 0;
638
639sub load_refcounts{
640 $REFCOUNTS_LOADED = 1;
641
642 use File::Basename;
643 my $myname, $mydir, $myext;
644 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
645 chop $mydir; # remove trailing '/'
646 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
647 chop $mydir; # remove trailing '/'
648 $mydir = getcwd() . "$dd$mydir"
649 unless $mydir =~ s|^/|/|;
650 local $_;
651 my $filename = "$mydir${dd}api${dd}refcounts.dat";
652 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
653 print "[loading API refcount data]";
654 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000655 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000656 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
657 #print "\n$func($param) --> $count";
658 $REFCOUNTS{"$func:$param"} = $count;
659 }
660 }
661}
662
663sub get_refcount{
664 my ($func, $param) = @_;
665 load_refcounts()
666 unless $REFCOUNTS_LOADED;
667 return $REFCOUNTS{"$func:$param"};
668}
669
Fred Drake6659c301998-03-03 22:02:19 +0000670sub do_env_cfuncdesc{
671 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000672 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000673 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000674 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000675 my $idx = make_str_index_entry(
676 "<tt class='cfunction'>$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000677 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000678 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000679 my $result_rc = get_refcount($function_name, '');
680 my $rcinfo = '';
681 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000682 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000683 }
684 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000685 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000686 }
Fred Drakec2578c52000-04-10 18:26:45 +0000687 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000688 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000689 }
Fred Drakee15956b2000-04-03 04:51:13 +0000690 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000691 $rcinfo = ( "\n<div class=\"refcount-info\">"
692 . "\n <span class=\"label\">Return value:</span>"
693 . "\n <span class=\"value\">$rcinfo.</span>"
694 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000695 }
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000696 return "<dl><dt>$return_type <b>$idx</b> (<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000697 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000698 . $_
699 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000700}
701
Fred Drakee15956b2000-04-03 04:51:13 +0000702sub do_env_csimplemacrodesc{
703 local($_) = @_;
704 my $name = next_argument();
705 my $idx = make_str_index_entry("<tt class='macro'>$name</tt>");
706 return "<dl><dt><b>$idx</b>\n<dd>"
707 . $_
708 . '</dl>'
709}
710
Fred Drake6659c301998-03-03 22:02:19 +0000711sub do_env_ctypedesc{
712 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000713 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000714 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000715 $index_name = $type_name
716 unless $index_name;
717 my($name,$aname,$ahref) = new_link_info();
718 add_index_entry("<tt class='ctype'>$index_name</tt> (C type)", $ahref);
719 return "<dl><dt><b><tt class='ctype'>$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000720 . $_
721 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000722}
723
724sub do_env_cvardesc{
725 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000726 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000727 my $var_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000728 my $idx = make_str_index_entry("<tt class='cdata'>$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000729 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000730 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000731 return "<dl><dt>$var_type <b>$idx</b>\n"
732 . '<dd>'
733 . $_
734 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000735}
736
Fred Drake3cdb89d2000-09-14 20:17:23 +0000737sub convert_args($){
738 local($IN_DESC_HANDLER) = 1;
739 local($_) = @_;
740 return translate_commands($_);
741}
742
Fred Drake6659c301998-03-03 22:02:19 +0000743sub do_env_funcdesc{
744 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000745 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000746 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000747 my $idx = make_str_index_entry("<tt class='function'>$function_name()</tt>"
Fred Drake08932051998-04-17 02:15:42 +0000748 . get_indexsubitem());
Fred Drake3cdb89d2000-09-14 20:17:23 +0000749 print "\n--- funcdesc arg_list:\n$arg_list\n===";
Fred Drake08932051998-04-17 02:15:42 +0000750 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000751 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drake62e43691998-08-10 19:40:44 +0000752 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000753}
754
755sub do_env_funcdescni{
756 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000757 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000758 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000759 return "<dl><dt><b><tt class='function'>$function_name</tt></b>"
Fred Drake90fdda51999-02-16 20:27:42 +0000760 . " (<var>$arg_list</var>)\n"
761 . '<dd>'
762 . $_
763 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000764}
765
766sub do_cmd_funcline{
767 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000768 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000769 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000770 my $prefix = "<tt class='function'>$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000771 my $idx = make_str_index_entry($prefix . get_indexsubitem());
772 $prefix =~ s/\(\)//;
773
774 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000775}
776
Fred Drake6b3fb781999-07-12 16:50:09 +0000777sub do_cmd_funclineni{
778 local($_) = @_;
779 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000780 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000781 my $prefix = "<tt class='function'>$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000782
783 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
784}
785
Fred Drake6659c301998-03-03 22:02:19 +0000786# Change this flag to index the opcode entries. I don't think it's very
787# useful to index them, since they're only presented to describe the dis
788# module.
789#
790$INDEX_OPCODES = 0;
791
792sub do_env_opcodedesc{
793 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000794 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000795 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000796 my $idx;
797 if ($INDEX_OPCODES) {
Fred Drakee15956b2000-04-03 04:51:13 +0000798 $idx = make_str_index_entry("<tt class='opcode'>$opcode_name</tt>"
799 . " (byte code instruction)");
Fred Drake08932051998-04-17 02:15:42 +0000800 $idx =~ s/ \(byte code instruction\)//;
801 }
802 else {
Fred Drakee15956b2000-04-03 04:51:13 +0000803 $idx = "<tt class='opcode'>$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +0000804 }
805 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +0000806 if ($arg_list) {
807 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
808 }
Fred Drake62e43691998-08-10 19:40:44 +0000809 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000810}
811
812sub do_env_datadesc{
813 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000814 my $dataname = next_argument();
815 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000816 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000817 return "<dl><dt><b>$idx</b>\n<dd>"
818 . $_
819 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000820}
821
822sub do_env_datadescni{
823 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000824 my $idx = next_argument();
825 if (! $STRING_INDEX_TT) {
826 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +0000827 }
Fred Drake62e43691998-08-10 19:40:44 +0000828 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000829}
830
831sub do_cmd_dataline{
832 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000833 my $data_name = next_argument();
834 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +0000835 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000836 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000837}
838
Fred Drakeadb272c2000-04-10 17:47:14 +0000839sub do_cmd_datalineni{
840 local($_) = @_;
841 my $data_name = next_argument();
842 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
843}
844
Fred Drake42b31a51998-03-27 05:16:10 +0000845sub do_env_excdesc{
846 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000847 my $excname = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000848 my $idx = make_str_index_entry("<tt class='exception'>$excname</tt>");
Fred Drake62e43691998-08-10 19:40:44 +0000849 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>'
Fred Drake42b31a51998-03-27 05:16:10 +0000850}
851
Fred Drake62e43691998-08-10 19:40:44 +0000852sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000853
854
Fred Drake643d76d2000-09-09 06:07:37 +0000855sub handle_classlike_descriptor{
856 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000857 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000858 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000859 $idx = make_str_index_entry(
Fred Drake643d76d2000-09-09 06:07:37 +0000860 "<tt class='$what'>$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +0000861 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000862 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +0000863}
864
Fred Drake643d76d2000-09-09 06:07:37 +0000865sub do_env_classdesc{
866 return handle_classlike_descriptor(@_[0], "class");
867}
868
869sub do_env_excclassdesc{
870 return handle_classlike_descriptor(@_[0], "exception");
871}
872
Fred Drake42b31a51998-03-27 05:16:10 +0000873
874sub do_env_methoddesc{
875 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000876 my $class_name = next_optional_argument();
877 $class_name = $THIS_CLASS
878 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +0000879 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000880 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +0000881 my $extra = '';
882 if ($class_name) {
883 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +0000884 }
Fred Drakee15956b2000-04-03 04:51:13 +0000885 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +0000886 $idx =~ s/ \(.*\)//;
887 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000888 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000889}
890
891
Fred Drake7d45f6d1999-01-05 14:39:27 +0000892sub do_cmd_methodline{
893 local($_) = @_;
894 my $class_name = next_optional_argument();
895 $class_name = $THIS_CLASS
896 unless $class_name;
897 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000898 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +0000899 my $extra = '';
900 if ($class_name) {
901 $extra = " ($class_name method)";
902 }
Fred Drakee15956b2000-04-03 04:51:13 +0000903 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +0000904 $idx =~ s/ \(.*\)//;
905 $idx =~ s/\(\)//;
906 return "<dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>"
907 . $_;
908}
909
910
Fred Draked64a40d1998-09-10 18:59:13 +0000911sub do_cmd_methodlineni{
912 local($_) = @_;
913 next_optional_argument();
914 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000915 my $arg_list = convert_args(next_argument());
Fred Draked64a40d1998-09-10 18:59:13 +0000916 return "<dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
917 . $_;
918}
919
Fred Drake42b31a51998-03-27 05:16:10 +0000920sub do_env_methoddescni{
921 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000922 next_optional_argument();
923 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000924 my $arg_list = convert_args(next_argument());
Fred Drake62e43691998-08-10 19:40:44 +0000925 return "<dl><dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
926 . $_
927 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000928}
929
930
931sub do_env_memberdesc{
932 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000933 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000934 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000935 $class = $THIS_CLASS
936 unless $class;
Fred Drake08932051998-04-17 02:15:42 +0000937 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000938 $extra = " ($class attribute)"
939 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000940 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +0000941 $idx =~ s/ \(.*\)//;
942 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000943 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000944}
945
946
Fred Drake5ccf3301998-04-17 20:04:09 +0000947sub do_cmd_memberline{
948 local($_) = @_;
949 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000950 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +0000951 $class = $THIS_CLASS
952 unless $class;
953 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000954 $extra = " ($class attribute)"
955 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000956 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +0000957 $idx =~ s/ \(.*\)//;
958 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000959 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000960}
961
Fred Drake42b31a51998-03-27 05:16:10 +0000962sub do_env_memberdescni{
963 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000964 next_optional_argument();
965 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000966 return "<dl><dt><b><tt class='member'>$member</tt></b>\n<dd>"
967 . $_
968 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000969}
970
971
Fred Drake5ccf3301998-04-17 20:04:09 +0000972sub do_cmd_memberlineni{
973 local($_) = @_;
974 next_optional_argument();
975 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000976 return "<dt><b><tt class='member'>$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000977}
978
Fred Drakee15956b2000-04-03 04:51:13 +0000979@col_aligns = ('<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +0000980
Fred Drakef74e5b71999-04-28 14:58:49 +0000981sub fix_font{
982 # do a little magic on a font name to get the right behavior in the first
983 # column of the output table
984 my $font = @_[0];
985 if ($font eq 'textrm') {
986 $font = '';
987 }
988 elsif ($font eq 'file' || $font eq 'filenq') {
Fred Drakee15956b2000-04-03 04:51:13 +0000989 $font = 'tt class="file"';
990 }
991 elsif ($font eq 'member') {
992 $font = 'tt class="member"';
Fred Drakef74e5b71999-04-28 14:58:49 +0000993 }
Fred Drake7388f732000-06-28 21:06:08 +0000994 elsif ($font eq 'constant') {
995 $font = 'tt class="constant"';
996 }
Fred Drakecb0fc9c2000-08-09 13:45:04 +0000997 elsif ($font eq 'kbd') {
998 $font = 'kbd';
999 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001000 return $font;
1001}
1002
Fred Drakee15956b2000-04-03 04:51:13 +00001003sub figure_column_alignment{
1004 my $a = @_[0];
1005 my $mark = substr($a, 0, 1);
1006 my $r = '';
1007 if ($mark eq 'c')
1008 { $r = ' align="center"'; }
1009 elsif ($mark eq 'r')
1010 { $r = ' align="right"'; }
1011 elsif ($mark eq 'l')
1012 { $r = ' align="left"'; }
1013 elsif ($mark eq 'p')
1014 { $r = ' align="left"'; }
1015 return $r;
1016}
1017
Fred Drake6659c301998-03-03 22:02:19 +00001018sub setup_column_alignments{
1019 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001020 my($s1,$s2,$s3,$s4) = split(/[|]/,$_);
1021 my $a1 = figure_column_alignment($s1);
1022 my $a2 = figure_column_alignment($s2);
1023 my $a3 = figure_column_alignment($s3);
1024 my $a4 = figure_column_alignment($s4);
1025 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1026 $col_aligns[1] = "<td$a2>";
1027 $col_aligns[2] = "<td$a3>";
1028 $col_aligns[3] = "<td$a4>";
Fred Drake79189b51999-04-28 13:54:30 +00001029 # return the aligned header start tags
Fred Drakee15956b2000-04-03 04:51:13 +00001030 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>");
1031}
1032
1033sub get_table_col1_fonts{
1034 my $font = $globals{'lineifont'};
1035 my ($sfont,$efont) = ('', '');
1036 if ($font) {
1037 $sfont = "<$font>";
1038 $efont = "</$font>";
1039 $efont =~ s/ .*>/>/;
1040 }
1041 return ($font, $sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001042}
1043
1044sub do_env_tableii{
1045 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001046 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001047 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001048 my $h1 = next_argument();
1049 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001050 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001051 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001052 my $a1 = $col_aligns[0];
1053 my $a2 = $col_aligns[1];
1054 s/\\lineii</\\lineii[$a1|$a2]</g;
1055 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001056 . "\n <thead>"
Fred Drake3be20742000-08-31 06:22:54 +00001057 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001058 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1059 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001060 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001061 . "\n <tbody valign='baseline'>"
1062 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001063 . "\n </tbody>"
1064 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001065}
1066
1067sub do_cmd_lineii{
1068 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001069 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001070 my $c1 = next_argument();
1071 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001072 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001073 my($font,$sfont,$efont) = get_table_col1_fonts();
1074 $c2 = '&nbsp;' if ($c2 eq '');
1075 my($c1align,$c2align) = split('\|', $aligns);
1076 my $padding = '';
1077 if ($c1align =~ /align="right"/) {
1078 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001079 }
Fred Drakee15956b2000-04-03 04:51:13 +00001080 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1081 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001082 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001083}
1084
1085sub do_env_tableiii{
1086 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001087 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001088 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001089 my $h1 = next_argument();
1090 my $h2 = next_argument();
1091 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001092 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001093 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001094 my $a1 = $col_aligns[0];
1095 my $a2 = $col_aligns[1];
1096 my $a3 = $col_aligns[2];
1097 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1098 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001099 . "\n <thead>"
1100 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001101 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1102 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1103 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001104 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001105 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001106 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001107 . "\n </tbody>"
1108 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001109}
1110
1111sub do_cmd_lineiii{
1112 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001113 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001114 my $c1 = next_argument();
1115 my $c2 = next_argument();
1116 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001117 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001118 my($font,$sfont,$efont) = get_table_col1_fonts();
1119 $c3 = '&nbsp;' if ($c3 eq '');
1120 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1121 my $padding = '';
1122 if ($c1align =~ /align="right"/) {
1123 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001124 }
Fred Drakee15956b2000-04-03 04:51:13 +00001125 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001126 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001127 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001128 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001129}
1130
Fred Drakea0f4c941998-07-24 22:16:04 +00001131sub do_env_tableiv{
1132 local($_) = @_;
1133 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001134 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001135 my $h1 = next_argument();
1136 my $h2 = next_argument();
1137 my $h3 = next_argument();
1138 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001139 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001140 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001141 my $a1 = $col_aligns[0];
1142 my $a2 = $col_aligns[1];
1143 my $a3 = $col_aligns[2];
1144 my $a4 = $col_aligns[3];
1145 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1146 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001147 . "\n <thead>"
1148 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001149 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1150 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1151 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1152 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001153 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001154 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001155 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001156 . "\n </tbody>"
1157 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001158}
1159
Fred Drakea0f4c941998-07-24 22:16:04 +00001160sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001161 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001162 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001163 my $c1 = next_argument();
1164 my $c2 = next_argument();
1165 my $c3 = next_argument();
1166 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001167 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001168 my($font,$sfont,$efont) = get_table_col1_fonts();
1169 $c4 = '&nbsp;' if ($c4 eq '');
1170 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1171 my $padding = '';
1172 if ($c1align =~ /align="right"/) {
1173 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001174 }
Fred Drakee15956b2000-04-03 04:51:13 +00001175 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001176 . " $c2align$c2</td>\n"
1177 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001178 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001179 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001180}
1181
Fred Drake3be20742000-08-31 06:22:54 +00001182
1183# These can be used to control the title page appearance;
1184# they need a little bit of documentation.
1185#
1186# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1187# $ICONSERVER directory, or include path information (other than "./"). The
1188# default image type will be assumed if an extension is not provided.
1189#
1190# If specified, the "title page" will contain two colums: one containing the
1191# title/author/etc., and the other containing the graphic. Use the other
1192# four variables listed here to control specific details of the layout; all
1193# are optional.
1194#
1195# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1196# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1197# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1198# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1199# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1200
1201sub make_my_titlepage() {
1202 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001203 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001204 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001205 }
1206 else {
1207 write_warnings("\nThis document has no title.");
1208 }
Fred Drake6659c301998-03-03 22:02:19 +00001209 if ($t_author) {
1210 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001211 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001212 $href = make_named_href('author', $href,
1213 "<b><font size='+2'>$t_author</font></b>");
Fred Drakec9a44381998-03-17 06:29:13 +00001214 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001215 }
1216 else {
Fred Drake2d1f81e1999-02-09 16:03:31 +00001217 $the_title .= ("\n<p><b><font size='+2'>$t_author</font></b></p>");
Fred Drake6659c301998-03-03 22:02:19 +00001218 }
Fred Drake3be20742000-08-31 06:22:54 +00001219 }
1220 else {
1221 write_warnings("\nThere is no author for this document.");
1222 }
Fred Drake6659c301998-03-03 22:02:19 +00001223 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001224 $the_title .= "\n<p>$t_institute</p>";
1225 }
Fred Draked07868a1998-05-14 21:00:28 +00001226 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001227 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1228 }
Fred Drake6659c301998-03-03 22:02:19 +00001229 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001230 $the_title .= "\n<p><i>$t_affil</i></p>";
1231 }
Fred Drake6659c301998-03-03 22:02:19 +00001232 if ($t_date) {
Fred Drakec9a44381998-03-17 06:29:13 +00001233 $the_title .= "\n<p><strong>$t_date</strong>";
Fred Drake6659c301998-03-03 22:02:19 +00001234 if ($PYTHON_VERSION) {
Fred Drake3be20742000-08-31 06:22:54 +00001235 $the_title .= "<br><strong>Release $PYTHON_VERSION</strong>";
1236 }
Fred Drake6659c301998-03-03 22:02:19 +00001237 $the_title .= "</p>"
1238 }
1239 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001240 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001241 }
1242 else {
1243 $the_title .= "\n<p>";
1244 }
Fred Drake6659c301998-03-03 22:02:19 +00001245 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001246 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001247 }
1248 return $the_title;
1249}
1250
1251use File::Basename;
1252
1253sub make_my_titlegraphic() {
1254 my($myname, $mydir, $myext) = fileparse($TITLE_PAGE_GRAPHIC, '\..*');
1255 chop $mydir;
1256 if ($mydir eq '.') {
1257 $mydir = $ICONSERVER;
1258 }
1259 $myext = ".$IMAGE_TYPE"
1260 unless $myext;
1261 my $graphic = "<td class=\"titlegraphic\"";
1262 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1263 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1264 $graphic .= "><img";
1265 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1266 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1267 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1268 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
1269 $graphic .= "\n src=\"$mydir/$myname$myext\"></td>\n";
1270 return $graphic;
1271}
1272
1273sub do_cmd_maketitle {
1274 local($_) = @_;
1275 my $the_title = "\n<div class=\"titlepage\">";
1276 if ($TITLE_PAGE_GRAPHIC) {
1277 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1278 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1279 . "<tr align=\"right\">\n<td>"
1280 . make_my_titlepage()
1281 . "</td>\n"
1282 . make_my_titlegraphic()
1283 . "</tr>\n</table>");
1284 }
1285 else {
1286 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1287 . make_my_titlegraphic()
1288 . "<td>"
1289 . make_my_titlepage()
1290 . "</td></tr>\n</table>");
1291 }
1292 }
1293 else {
1294 $the_title .= ("\n<center>"
1295 . make_my_titlepage()
1296 . "\n</center>");
1297 }
1298 $the_title .= "\n</div>";
1299 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001300 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001301 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001302}
1303
1304
Fred Drake885215c1998-05-20 21:32:09 +00001305#
Fred Drakea0f4c941998-07-24 22:16:04 +00001306# Module synopsis support
1307#
1308
1309require SynopsisTable;
1310
Fred Drakef7685d71998-07-25 03:31:46 +00001311sub get_chapter_id(){
1312 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001313 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1314 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001315 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001316}
1317
Fred Drake643d76d2000-09-09 06:07:37 +00001318# 'chapter' => 'SynopsisTable instance'
1319%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001320
1321sub get_synopsis_table($){
1322 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001323 my $key;
1324 foreach $key (keys %ModuleSynopses) {
1325 if ($key eq $chap) {
1326 return $ModuleSynopses{$chap};
1327 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001328 }
Fred Drake643d76d2000-09-09 06:07:37 +00001329 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001330 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001331 return $st;
1332}
1333
Fred Drake62e43691998-08-10 19:40:44 +00001334sub do_cmd_moduleauthor{
1335 local($_) = @_;
1336 next_argument();
1337 next_argument();
1338 return $_;
1339}
1340
1341sub do_cmd_sectionauthor{
1342 local($_) = @_;
1343 next_argument();
1344 next_argument();
1345 return $_;
1346}
1347
Fred Drakea0f4c941998-07-24 22:16:04 +00001348sub do_cmd_declaremodule{
1349 local($_) = @_;
1350 my $key = next_optional_argument();
1351 my $type = next_argument();
1352 my $name = next_argument();
1353 my $st = get_synopsis_table(get_chapter_id());
1354 #
1355 $key = $name unless $key;
1356 $type = 'built-in' if $type eq 'builtin';
1357 $st->declare($name, $key, $type);
1358 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001359 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001360}
1361
1362sub do_cmd_modulesynopsis{
1363 local($_) = @_;
1364 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001365 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001366 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001367}
1368
1369sub do_cmd_localmoduletable{
1370 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001371 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001372 my $st = get_synopsis_table($chap);
1373 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001374 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001375}
1376
1377sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001378 my $key;
1379 my $st, $file;
1380 foreach $key (keys %ModuleSynopses) {
1381 $st = $ModuleSynopses{$key};
1382 $file = $st->get_file();
1383 if ($file) {
1384 process_localmoduletables_in_file($file);
1385 }
1386 else {
1387 print "\nsynopsis table $key has no file association";
1388 }
1389 }
1390}
1391
1392sub process_localmoduletables_in_file{
1393 my $file = @_[0];
1394 open(MYFILE, "<$file");
1395 local($_);
1396 sysread(MYFILE, $_, 1024*1024);
1397 close(MYFILE);
1398 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001399 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001400 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001401 my $chap = $1;
1402 my $st = get_synopsis_table($chap);
1403 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001404 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001405 }
Fred Drake643d76d2000-09-09 06:07:37 +00001406 open(MYFILE,">$file");
1407 print MYFILE $_;
1408 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001409}
Fred Drake557460c1999-03-02 16:05:35 +00001410sub process_python_state{
1411 process_all_localmoduletables();
Fred Drake557460c1999-03-02 16:05:35 +00001412}
Fred Drakea0f4c941998-07-24 22:16:04 +00001413
1414
1415#
1416# "See also:" -- references placed at the end of a \section
1417#
1418
1419sub do_env_seealso{
Fred Drakee15956b2000-04-03 04:51:13 +00001420 return "<div class='seealso'>\n "
1421 . "<p class='heading'><b>See Also:</b></p>\n"
Fred Drake90fdda51999-02-16 20:27:42 +00001422 . @_[0]
1423 . '</div>';
Fred Drakea0f4c941998-07-24 22:16:04 +00001424}
1425
1426sub do_cmd_seemodule{
1427 # Insert the right magic to jump to the module definition. This should
1428 # work most of the time, at least for repeat builds....
1429 local($_) = @_;
1430 my $key = next_optional_argument();
1431 my $module = next_argument();
1432 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001433 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001434 $key = $module
1435 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001436 if ($text =~ /\.$/) {
1437 $period = '';
1438 }
Fred Drakee15956b2000-04-03 04:51:13 +00001439 return '<dl compact class="seemodule">'
1440 . "\n <dt>Module <b><tt class='module'><a href='module-$key.html'>"
Fred Drake84bd6f31999-05-11 15:42:51 +00001441 . "$module</a></tt>:</b>"
1442 . "\n <dd>$text$period\n </dl>"
Fred Drake90fdda51999-02-16 20:27:42 +00001443 . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001444}
1445
Fred Drake643d76d2000-09-09 06:07:37 +00001446sub handle_rfclike_reference{
1447 local($_, $what) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001448 my $rfcnum = next_argument();
1449 my $title = next_argument();
1450 my $text = next_argument();
1451 my $url = get_rfc_url($rfcnum);
1452 return '<dl compact class="seerfc">'
1453 . "\n <dt><a href=\"$url\""
1454 . "\n title=\"$title\""
Fred Drake643d76d2000-09-09 06:07:37 +00001455 . "\n >$what $rfcnum, <em>$title</em></a>:"
Fred Drake37cc0c02000-04-26 18:05:24 +00001456 . "\n <dd>$text\n </dl>"
1457 . $_;
1458}
1459
Fred Drake643d76d2000-09-09 06:07:37 +00001460sub do_cmd_seepep{
1461 return handle_rfclike_reference(@_[0], "PEP");
1462}
1463
1464sub do_cmd_seerfc{
1465 return handle_rfclike_reference(@_[0], "RFC");
1466}
1467
Fred Drake48449982000-09-12 17:52:33 +00001468sub do_cmd_seetitle{
1469 local($_) = @_;
1470 my $url = next_optional_argument();
1471 my $title = next_argument();
1472 my $text = next_argument();
1473 if ($url) {
1474 return '<dl compact class="seetitle">'
1475 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
1476 . "\n class=\"url\">$title</a></em>"
1477 . "\n <dd>$text\n </dl>"
1478 . $_;
1479 }
1480 return '<dl compact class="seetitle">'
1481 . "\n <dt><em class=\"citetitle\""
1482 . "\n >$title</em>"
1483 . "\n <dd>$text\n </dl>"
1484 . $_;
1485}
1486
Fred Drakeef4d1112000-05-09 16:17:51 +00001487sub do_cmd_seeurl{
1488 local($_) = @_;
1489 my $url = next_argument();
1490 my $text = next_argument();
1491 return '<dl compact class="seeurl">'
1492 . "\n <dt><a href=\"$url\""
1493 . "\n class=\"url\">$url</a>"
1494 . "\n <dd>$text\n </dl>"
1495 . $_;
1496}
1497
Fred Drakea0f4c941998-07-24 22:16:04 +00001498sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001499 local($_) = @_;
1500 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001501 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001502}
1503
1504
1505#
Fred Drake885215c1998-05-20 21:32:09 +00001506# Definition list support.
1507#
1508
1509sub do_env_definitions{
Fred Drake37cc0c02000-04-26 18:05:24 +00001510 return "<dl class='definitions'>" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001511}
1512
1513sub do_cmd_term{
1514 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001515 my $term = next_argument();
1516 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001517 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001518 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001519}
1520
1521
Fred Drake2ff880e1999-02-05 18:31:29 +00001522process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
1523code # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001524declaremodule # [] # {} # {}
1525memberline # [] # {}
1526methodline # [] # {} # {}
1527modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001528platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001529samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001530setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001531withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001532_RAW_ARG_DEFERRED_CMDS_
1533
1534
Fred Drake6659c301998-03-03 22:02:19 +000015351; # This must be the last line