blob: ae0d7b1a24621059144bd34326653dcd0266febb [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 Drake3cdb89d2000-09-14 20:17:23 +0000113$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000114sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000115 if ($IN_DESC_HANDLER) {
116 return use_wrappers(@_[0], "</var><big>\[</big><var>",
117 "</var><big>\]</big><var>");
118 }
119 else {
120 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
121 }
Fred Drake6659c301998-03-03 22:02:19 +0000122}
123
Fred Drakec9a44381998-03-17 06:29:13 +0000124# Logical formatting (some based on texinfo), needs to be converted to
125# minimalist HTML. The "minimalist" is primarily to reduce the size of
126# output files for users that read them over the network rather than
127# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000128
Fred Drake2cafcbb1999-03-25 16:57:04 +0000129# \file and \samp are at the end of this file since they screw up fontlock.
130
Fred Drake2ff880e1999-02-05 18:31:29 +0000131sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000132sub do_cmd_makevar{
133 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000134sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000135 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000136sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000137 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000138sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000139 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000140sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000141 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000142sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000143 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000144sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000145 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000146sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000147 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000148sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000149 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000150sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000151 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000152sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000153 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000154sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000155 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000156sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000157 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000158sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000159 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000160sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000161 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000162sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000163 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000164sub do_cmd_programopt{
165 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000166sub do_cmd_longprogramopt{
167 # note that the --- will be later converted to -- by LaTeX2HTML
168 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000169sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000170 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000171sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000172 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000173sub do_cmd_var{
174 return use_wrappers(@_[0], "<var>", "</var>"); }
175sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000176 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000177sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000178 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000179sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000180 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000181sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000182 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000183sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000184 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000185sub do_cmd_kbd{
186 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
187sub do_cmd_strong{
188 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000189sub do_cmd_textbf{
190 return use_wrappers(@_[0], '<b>', '</b>'); }
191sub do_cmd_textit{
192 return use_wrappers(@_[0], '<i>', '</i>'); }
193
Fred Drake3d5a04a2000-08-03 17:25:44 +0000194sub do_cmd_moreargs{
195 return '...' . @_[0]; }
196sub do_cmd_unspecified{
197 return '...' . @_[0]; }
198
Fred Drakec9a44381998-03-17 06:29:13 +0000199
Fred Drake25817041999-01-13 17:06:34 +0000200sub do_cmd_refmodule{
201 # Insert the right magic to jump to the module definition.
202 local($_) = @_;
203 my $key = next_optional_argument();
204 my $module = next_argument();
205 $key = $module
206 unless $key;
Fred Drakee15956b2000-04-03 04:51:13 +0000207 return "<tt class='module'><a href='module-$key.html'>$module</a></tt>"
208 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000209}
210
Fred Drake1a7af391998-04-01 22:44:56 +0000211sub do_cmd_newsgroup{
212 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000213 my $newsgroup = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000214 my $stuff = "<span class='newsgroup'><a href='news:$newsgroup'>"
215 . "$newsgroup</a></span>";
Fred Drake62e43691998-08-10 19:40:44 +0000216 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000217}
Fred Drakefc16e781998-03-12 21:03:26 +0000218
219sub do_cmd_envvar{
220 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000221 my $envvar = next_argument();
222 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000223 # The <tt> here is really to keep buildindex.py from making
224 # the variable name case-insensitive.
225 add_index_entry("environment variables!$envvar@<tt>\$$envvar</tt>",
226 $ahref);
Fred Drake42b31a51998-03-27 05:16:10 +0000227 add_index_entry("$envvar@\$$envvar", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000228 $aname =~ s/<a/<a class="envvar"/;
Fred Draked37cecf1999-09-23 16:45:08 +0000229 return "$aname\$$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000230}
231
Fred Drake6659c301998-03-03 22:02:19 +0000232sub do_cmd_url{
233 # use the URL as both text and hyperlink
234 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000235 my $url = next_argument();
Fred Drake6659c301998-03-03 22:02:19 +0000236 $url =~ s/~/&#126;/g;
Fred Drakee15956b2000-04-03 04:51:13 +0000237 return "<a class=\"url\" href=\"$url\">$url</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000238}
239
240sub do_cmd_manpage{
241 # two parameters: \manpage{name}{section}
242 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000243 my $page = next_argument();
244 my $section = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000245 return "<span class='manpage'><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000246}
247
Fred Drake643d76d2000-09-09 06:07:37 +0000248sub get_pep_url{
249 my $rfcnum = sprintf("%04d", @_[0]);
250 return "http://python.sourceforge.net/peps/pep-$rfcnum.html";
251}
252
253sub do_cmd_pep{
254 local($_) = @_;
255 my $rfcnumber = next_argument();
256 my $id = "rfcref-" . ++$global{'max_id'};
257 my $href = get_pep_url($rfcnumber);
258 # Save the reference
259 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
260 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
261 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber</a>"
262 . $_);
263}
264
Fred Drake37cc0c02000-04-26 18:05:24 +0000265sub get_rfc_url{
266 my $rfcnum = sprintf("%04d", @_[0]);
267 return "http://www.ietf.org/rfc/rfc$rfcnum.txt";
268}
269
Fred Drake6659c301998-03-03 22:02:19 +0000270sub do_cmd_rfc{
271 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000272 my $rfcnumber = next_argument();
273 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drake37cc0c02000-04-26 18:05:24 +0000274 my $href = get_rfc_url($rfcnumber);
Fred Drake6659c301998-03-03 22:02:19 +0000275 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000276 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000277 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drakee15956b2000-04-03 04:51:13 +0000278 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber</a>"
Fred Draked52879c1999-09-22 19:58:51 +0000279 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000280}
281
Fred Drakec9f5fe01999-11-09 16:59:42 +0000282sub do_cmd_citetitle{
283 local($_) = @_;
284 my $url = next_optional_argument();
285 my $title = next_argument();
286 my $repl = '';
287 if ($url) {
288 $repl = ("<em class='citetitle'><a\n"
289 . " href='$url'\n"
290 . " title='$title'\n"
291 . " >$title</a></em>");
292 }
293 else {
294 $repl = "<em class='citetitle'\n >$title</em>";
295 }
296 return $repl . $_;
297}
298
Fred Drake6659c301998-03-03 22:02:19 +0000299sub do_cmd_deprecated{
300 # two parameters: \deprecated{version}{whattodo}
301 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000302 my $release = next_argument();
303 my $reason = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000304 return "<b>Deprecated since release $release.</b>\n$reason<p>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000305}
306
Fred Drake897d12b1998-07-27 20:33:17 +0000307sub do_cmd_versionadded{
308 # one parameter: \versionadded{version}
309 local($_) = @_;
310 my $release = next_argument();
Fred Drake2116d981999-02-02 18:02:48 +0000311 return "\nNew in version $release.\n" . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000312}
313
314sub do_cmd_versionchanged{
315 # one parameter: \versionchanged{version}
316 local($_) = @_;
Fred Drake52e76842000-05-02 17:37:42 +0000317 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000318 my $release = next_argument();
Fred Drake52e76842000-05-02 17:37:42 +0000319 my $text = "\nChanged in version $release.\n";
320 if ($release) {
321 $text = "\nChanged in version $release:\n$explanation.\n";
322 }
323 return $text . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000324}
325
Fred Drake557460c1999-03-02 16:05:35 +0000326#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000327# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000328#
329sub do_cmd_platform{
330 local($_) = @_;
331 my $platform = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000332 $ModulePlatforms{"<tt class='module'>$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000333 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000334 if $platform eq 'Mac';
Fred Drakee15956b2000-04-03 04:51:13 +0000335 return "\n<p class='availability'>Availability: <span"
336 . "\n class='platform'>$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000337}
338
Fred Drake557460c1999-03-02 16:05:35 +0000339$IGNORE_PLATFORM_ANNOTATION = '';
340sub do_cmd_ignorePlatformAnnotation{
341 local($_) = @_;
342 $IGNORE_PLATFORM_ANNOTATION = next_argument();
343 return $_;
344}
345
Fred Drake6659c301998-03-03 22:02:19 +0000346
347# index commands
348
349$INDEX_SUBITEM = "";
350
351sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000352 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000353}
354
355sub do_cmd_setindexsubitem{
356 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000357 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000358 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000359}
360
Fred Drakefc16e781998-03-12 21:03:26 +0000361sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000362 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000363 # do things in the right order, but we need to at least strip this stuff
364 # out, and leave anything that the second argument expanded out to.
365 #
366 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000367 my $oldsubitem = $INDEX_SUBITEM;
368 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000369 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000370 my $br_id = ++$globals{'max_id'};
371 my $marker = "$O$br_id$C";
Fred Drake7d45f6d1999-01-05 14:39:27 +0000372 return
373 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000374 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000375 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000376}
377
Fred Drake08932051998-04-17 02:15:42 +0000378# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000379# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
380# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000381#
Fred Drake62e43691998-08-10 19:40:44 +0000382sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000383
Fred Drake42b31a51998-03-27 05:16:10 +0000384# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000385#
Fred Drake08932051998-04-17 02:15:42 +0000386open(IDXFILE, '>index.dat') || die "\n$!\n";
387open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000388print INTLABELS "%internal_labels = ();\n";
389print INTLABELS "1; # hack in case there are no entries\n\n";
390
391# Using \0 for this is bad because we can't use common tools to work with the
392# resulting files. Things like grep can be useful with this stuff!
393#
394$IDXFILE_FIELD_SEP = "\1";
395
Fred Drakeccc62721999-01-05 22:16:29 +0000396sub write_idxfile{
397 my ($ahref, $str) = @_;
398 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000399}
400
Fred Drake42b31a51998-03-27 05:16:10 +0000401
402sub gen_link{
403 my($node,$target) = @_;
404 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakee15956b2000-04-03 04:51:13 +0000405 return "<a href='$node#$target'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000406}
407
Fred Drake42b31a51998-03-27 05:16:10 +0000408sub add_index_entry{
409 # add an entry to the index structures; ignore the return value
410 my($str,$ahref) = @_;
411 $str = gen_index_id($str, '');
412 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000413 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000414}
415
Fred Drakeccc62721999-01-05 22:16:29 +0000416sub new_link_info{
417 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakee15956b2000-04-03 04:51:13 +0000418 my $aname = "<a name='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000419 my $ahref = gen_link($CURRENT_FILE, $name);
420 return ($name, $aname, $ahref);
421}
422
Fred Drakeab032151999-05-13 18:36:54 +0000423$IndexMacroPattern = '';
424sub define_indexing_macro{
425 my $count = @_;
426 my $i = 0;
427 for (; $i < $count; ++$i) {
428 my $name = @_[$i];
429 my $cmd = "idx_cmd_$name";
430 die "\nNo function $cmd() defined!\n"
431 if (!defined &$cmd);
432 eval ("sub do_cmd_$name { return process_index_macros("
433 . "\@_[0], '$name'); }");
434 if (length($IndexMacroPattern) == 0) {
435 $IndexMacroPattern = "$name";
436 }
437 else {
438 $IndexMacroPattern .= "|$name";
439 }
440 }
441}
442
443$DEBUG_INDEXING = 0;
444sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000445 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000446 my $cmdname = @_[1]; # This is what triggered us in the first place;
447 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000448 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000449 my $cmd = "idx_cmd_$cmdname";
450 print "\nIndexing: \\$cmdname"
451 if $DEBUG_INDEXING;
452 &$cmd($ahref); # modifies $_ and adds index entries
453 while (/^[\s\n]*\\($IndexMacroPattern)</) {
454 $cmdname = "$1";
455 print " \\$cmdname"
456 if $DEBUG_INDEXING;
457 $cmd = "idx_cmd_$cmdname";
458 if (!defined &$cmd) {
459 last;
460 }
461 else {
462 s/^[\s\n]*\\$cmdname//;
463 &$cmd($ahref);
464 }
465 }
Fred Drake62e43691998-08-10 19:40:44 +0000466 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000467}
468
Fred Drakeab032151999-05-13 18:36:54 +0000469define_indexing_macro('index');
470sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000471 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000472 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000473}
474
Fred Drakeab032151999-05-13 18:36:54 +0000475define_indexing_macro('kwindex');
476sub idx_cmd_kwindex{
477 my $str = next_argument();
478 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
479 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
480}
481
482define_indexing_macro('indexii');
483sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000484 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000485 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000486 add_index_entry("$str1!$str2", @_[0]);
487 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000488}
489
Fred Drakeab032151999-05-13 18:36:54 +0000490define_indexing_macro('indexiii');
491sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000492 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000493 my $str2 = next_argument();
494 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000495 add_index_entry("$str1!$str2 $str3", @_[0]);
496 add_index_entry("$str2!$str3, $str1", @_[0]);
497 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000498}
499
Fred Drakeab032151999-05-13 18:36:54 +0000500define_indexing_macro('indexiv');
501sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000502 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000503 my $str2 = next_argument();
504 my $str3 = next_argument();
505 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000506 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
507 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
508 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
509 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000510}
511
Fred Drakeab032151999-05-13 18:36:54 +0000512define_indexing_macro('ttindex');
513sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000514 my $str = next_argument();
515 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000516 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000517}
Fred Drake6659c301998-03-03 22:02:19 +0000518
519sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000520 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000521 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000522 add_index_entry("$str $word", $ahref);
523 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000524}
525
Fred Drakeab032151999-05-13 18:36:54 +0000526define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
527sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
528sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
529sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
530sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000531
Fred Drakeab032151999-05-13 18:36:54 +0000532define_indexing_macro('bifuncindex');
533sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000534 my $str = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000535 add_index_entry("<tt class='function'>$str()</tt> (built-in function)",
536 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000537}
538
539
Fred Drake6659c301998-03-03 22:02:19 +0000540sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000541 my($str,$define) = @_;
542 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000543 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000544 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
545 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000546 $str = gen_index_id($str, $define);
547 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000548 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000549
Fred Drakec9a44381998-03-17 06:29:13 +0000550 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000551 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000552 $str =~ /(<tt.*<\/tt>)/;
553 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000554 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000555 }
Fred Drake62e43691998-08-10 19:40:44 +0000556 return "$aname$anchor_invisible_mark</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000557}
558
Fred Drake557460c1999-03-02 16:05:35 +0000559
Fred Drakec9a44381998-03-17 06:29:13 +0000560$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000561$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000562
Fred Drakea0f4c941998-07-24 22:16:04 +0000563sub define_module{
564 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000565 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000566 if ($word ne "built-in" && $word ne "extension"
567 && $word ne "standard" && $word ne "") {
568 write_warnings("Bad module type '$word'"
569 . " for \\declaremodule (module $name)");
570 $word = "";
571 }
Fred Drake6659c301998-03-03 22:02:19 +0000572 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000573 $THIS_MODULE = "$name";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000574 $INDEX_SUBITEM = "(in $name)";
575 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000576 return make_mod_index_entry(
577 "<tt class='module'>$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000578}
579
580sub my_module_index_helper{
581 local($word, $_) = @_;
582 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000583 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000584}
585
Fred Drake62e43691998-08-10 19:40:44 +0000586sub do_cmd_modindex{ return my_module_index_helper('', @_); }
587sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
588sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
589sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000590
Fred Drakeab032151999-05-13 18:36:54 +0000591sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000592 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000593 my $str = next_argument();
594 $word = "$word " if $word;
Fred Drakee15956b2000-04-03 04:51:13 +0000595 $str = "<tt class='module'>$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000596 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
597 # just inline it all here
598 $str = gen_index_id($str, 'REF');
599 $index{$str} .= $ahref;
600 write_idxfile($ahref, $str);
601}
602
Fred Drake6659c301998-03-03 22:02:19 +0000603# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000604define_indexing_macro('refmodindex', 'refbimodindex',
605 'refexmodindex', 'refstmodindex');
606sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
607sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
608sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
609sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000610
Fred Drake62e43691998-08-10 19:40:44 +0000611sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000612
613sub init_myformat{
Fred Drake38178fd2000-09-22 17:05:04 +0000614 $anchor_invisible_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000615 $anchor_mark = '';
616 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000617}
Fred Drake42b31a51998-03-27 05:16:10 +0000618init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000619
Fred Drakeab032151999-05-13 18:36:54 +0000620# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000621# instead of the dummy filler.
622#
623sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000624 my($str) = @_;
625 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000626 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000627 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000628}
629
Fred Drakee15956b2000-04-03 04:51:13 +0000630$REFCOUNTS_LOADED = 0;
631
632sub load_refcounts{
633 $REFCOUNTS_LOADED = 1;
634
635 use File::Basename;
636 my $myname, $mydir, $myext;
637 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
638 chop $mydir; # remove trailing '/'
639 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
640 chop $mydir; # remove trailing '/'
641 $mydir = getcwd() . "$dd$mydir"
642 unless $mydir =~ s|^/|/|;
643 local $_;
644 my $filename = "$mydir${dd}api${dd}refcounts.dat";
645 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
646 print "[loading API refcount data]";
647 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000648 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000649 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
650 #print "\n$func($param) --> $count";
651 $REFCOUNTS{"$func:$param"} = $count;
652 }
653 }
654}
655
656sub get_refcount{
657 my ($func, $param) = @_;
658 load_refcounts()
659 unless $REFCOUNTS_LOADED;
660 return $REFCOUNTS{"$func:$param"};
661}
662
Fred Drake6659c301998-03-03 22:02:19 +0000663sub do_env_cfuncdesc{
664 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000665 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000666 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000667 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000668 my $idx = make_str_index_entry(
669 "<tt class='cfunction'>$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000670 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000671 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000672 my $result_rc = get_refcount($function_name, '');
673 my $rcinfo = '';
674 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000675 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000676 }
677 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000678 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000679 }
Fred Drakec2578c52000-04-10 18:26:45 +0000680 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000681 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000682 }
Fred Drakee15956b2000-04-03 04:51:13 +0000683 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000684 $rcinfo = ( "\n<div class=\"refcount-info\">"
685 . "\n <span class=\"label\">Return value:</span>"
686 . "\n <span class=\"value\">$rcinfo.</span>"
687 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000688 }
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000689 return "<dl><dt>$return_type <b>$idx</b> (<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000690 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000691 . $_
692 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000693}
694
Fred Drakee15956b2000-04-03 04:51:13 +0000695sub do_env_csimplemacrodesc{
696 local($_) = @_;
697 my $name = next_argument();
698 my $idx = make_str_index_entry("<tt class='macro'>$name</tt>");
699 return "<dl><dt><b>$idx</b>\n<dd>"
700 . $_
701 . '</dl>'
702}
703
Fred Drake6659c301998-03-03 22:02:19 +0000704sub do_env_ctypedesc{
705 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000706 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000707 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000708 $index_name = $type_name
709 unless $index_name;
710 my($name,$aname,$ahref) = new_link_info();
711 add_index_entry("<tt class='ctype'>$index_name</tt> (C type)", $ahref);
712 return "<dl><dt><b><tt class='ctype'>$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000713 . $_
714 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000715}
716
717sub do_env_cvardesc{
718 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000719 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000720 my $var_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000721 my $idx = make_str_index_entry("<tt class='cdata'>$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000722 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000723 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000724 return "<dl><dt>$var_type <b>$idx</b>\n"
725 . '<dd>'
726 . $_
727 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000728}
729
Fred Drake3cdb89d2000-09-14 20:17:23 +0000730sub convert_args($){
731 local($IN_DESC_HANDLER) = 1;
732 local($_) = @_;
733 return translate_commands($_);
734}
735
Fred Drake6659c301998-03-03 22:02:19 +0000736sub do_env_funcdesc{
737 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000738 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000739 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000740 my $idx = make_str_index_entry("<tt class='function'>$function_name()</tt>"
Fred Drake08932051998-04-17 02:15:42 +0000741 . get_indexsubitem());
Fred Drake3cdb89d2000-09-14 20:17:23 +0000742 print "\n--- funcdesc arg_list:\n$arg_list\n===";
Fred Drake08932051998-04-17 02:15:42 +0000743 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000744 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drake62e43691998-08-10 19:40:44 +0000745 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000746}
747
748sub do_env_funcdescni{
749 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000750 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000751 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000752 return "<dl><dt><b><tt class='function'>$function_name</tt></b>"
Fred Drake90fdda51999-02-16 20:27:42 +0000753 . " (<var>$arg_list</var>)\n"
754 . '<dd>'
755 . $_
756 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000757}
758
759sub do_cmd_funcline{
760 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000761 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000762 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000763 my $prefix = "<tt class='function'>$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000764 my $idx = make_str_index_entry($prefix . get_indexsubitem());
765 $prefix =~ s/\(\)//;
766
767 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000768}
769
Fred Drake6b3fb781999-07-12 16:50:09 +0000770sub do_cmd_funclineni{
771 local($_) = @_;
772 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000773 my $arg_list = convert_args(next_argument());
Fred Drakee15956b2000-04-03 04:51:13 +0000774 my $prefix = "<tt class='function'>$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000775
776 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
777}
778
Fred Drake6659c301998-03-03 22:02:19 +0000779# Change this flag to index the opcode entries. I don't think it's very
780# useful to index them, since they're only presented to describe the dis
781# module.
782#
783$INDEX_OPCODES = 0;
784
785sub do_env_opcodedesc{
786 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000787 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000788 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000789 my $idx;
790 if ($INDEX_OPCODES) {
Fred Drakee15956b2000-04-03 04:51:13 +0000791 $idx = make_str_index_entry("<tt class='opcode'>$opcode_name</tt>"
792 . " (byte code instruction)");
Fred Drake08932051998-04-17 02:15:42 +0000793 $idx =~ s/ \(byte code instruction\)//;
794 }
795 else {
Fred Drakee15956b2000-04-03 04:51:13 +0000796 $idx = "<tt class='opcode'>$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +0000797 }
798 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +0000799 if ($arg_list) {
800 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
801 }
Fred Drake62e43691998-08-10 19:40:44 +0000802 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000803}
804
805sub do_env_datadesc{
806 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000807 my $dataname = next_argument();
808 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000809 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000810 return "<dl><dt><b>$idx</b>\n<dd>"
811 . $_
812 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000813}
814
815sub do_env_datadescni{
816 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000817 my $idx = next_argument();
818 if (! $STRING_INDEX_TT) {
819 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +0000820 }
Fred Drake62e43691998-08-10 19:40:44 +0000821 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000822}
823
824sub do_cmd_dataline{
825 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000826 my $data_name = next_argument();
827 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +0000828 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000829 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000830}
831
Fred Drakeadb272c2000-04-10 17:47:14 +0000832sub do_cmd_datalineni{
833 local($_) = @_;
834 my $data_name = next_argument();
835 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
836}
837
Fred Drake42b31a51998-03-27 05:16:10 +0000838sub do_env_excdesc{
839 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000840 my $excname = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000841 my $idx = make_str_index_entry("<tt class='exception'>$excname</tt>");
Fred Drake62e43691998-08-10 19:40:44 +0000842 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>'
Fred Drake42b31a51998-03-27 05:16:10 +0000843}
844
Fred Drake62e43691998-08-10 19:40:44 +0000845sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000846
847
Fred Drake643d76d2000-09-09 06:07:37 +0000848sub handle_classlike_descriptor{
849 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000850 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000851 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000852 $idx = make_str_index_entry(
Fred Drake643d76d2000-09-09 06:07:37 +0000853 "<tt class='$what'>$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +0000854 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000855 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +0000856}
857
Fred Drake643d76d2000-09-09 06:07:37 +0000858sub do_env_classdesc{
859 return handle_classlike_descriptor(@_[0], "class");
860}
861
862sub do_env_excclassdesc{
863 return handle_classlike_descriptor(@_[0], "exception");
864}
865
Fred Drake42b31a51998-03-27 05:16:10 +0000866
867sub do_env_methoddesc{
868 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000869 my $class_name = next_optional_argument();
870 $class_name = $THIS_CLASS
871 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +0000872 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000873 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +0000874 my $extra = '';
875 if ($class_name) {
876 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +0000877 }
Fred Drakee15956b2000-04-03 04:51:13 +0000878 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +0000879 $idx =~ s/ \(.*\)//;
880 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000881 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000882}
883
884
Fred Drake7d45f6d1999-01-05 14:39:27 +0000885sub do_cmd_methodline{
886 local($_) = @_;
887 my $class_name = next_optional_argument();
888 $class_name = $THIS_CLASS
889 unless $class_name;
890 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000891 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +0000892 my $extra = '';
893 if ($class_name) {
894 $extra = " ($class_name method)";
895 }
Fred Drakee15956b2000-04-03 04:51:13 +0000896 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +0000897 $idx =~ s/ \(.*\)//;
898 $idx =~ s/\(\)//;
899 return "<dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>"
900 . $_;
901}
902
903
Fred Draked64a40d1998-09-10 18:59:13 +0000904sub do_cmd_methodlineni{
905 local($_) = @_;
906 next_optional_argument();
907 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000908 my $arg_list = convert_args(next_argument());
Fred Draked64a40d1998-09-10 18:59:13 +0000909 return "<dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
910 . $_;
911}
912
Fred Drake42b31a51998-03-27 05:16:10 +0000913sub do_env_methoddescni{
914 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000915 next_optional_argument();
916 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000917 my $arg_list = convert_args(next_argument());
Fred Drake62e43691998-08-10 19:40:44 +0000918 return "<dl><dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
919 . $_
920 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000921}
922
923
924sub do_env_memberdesc{
925 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000926 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000927 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000928 $class = $THIS_CLASS
929 unless $class;
Fred Drake08932051998-04-17 02:15:42 +0000930 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000931 $extra = " ($class attribute)"
932 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000933 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +0000934 $idx =~ s/ \(.*\)//;
935 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000936 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000937}
938
939
Fred Drake5ccf3301998-04-17 20:04:09 +0000940sub do_cmd_memberline{
941 local($_) = @_;
942 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000943 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +0000944 $class = $THIS_CLASS
945 unless $class;
946 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000947 $extra = " ($class attribute)"
948 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000949 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +0000950 $idx =~ s/ \(.*\)//;
951 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000952 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000953}
954
Fred Drake42b31a51998-03-27 05:16:10 +0000955sub do_env_memberdescni{
956 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000957 next_optional_argument();
958 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000959 return "<dl><dt><b><tt class='member'>$member</tt></b>\n<dd>"
960 . $_
961 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000962}
963
964
Fred Drake5ccf3301998-04-17 20:04:09 +0000965sub do_cmd_memberlineni{
966 local($_) = @_;
967 next_optional_argument();
968 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000969 return "<dt><b><tt class='member'>$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000970}
971
Fred Drakee15956b2000-04-03 04:51:13 +0000972@col_aligns = ('<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +0000973
Fred Drakef74e5b71999-04-28 14:58:49 +0000974sub fix_font{
975 # do a little magic on a font name to get the right behavior in the first
976 # column of the output table
977 my $font = @_[0];
978 if ($font eq 'textrm') {
979 $font = '';
980 }
981 elsif ($font eq 'file' || $font eq 'filenq') {
Fred Drakee15956b2000-04-03 04:51:13 +0000982 $font = 'tt class="file"';
983 }
984 elsif ($font eq 'member') {
985 $font = 'tt class="member"';
Fred Drakef74e5b71999-04-28 14:58:49 +0000986 }
Fred Drake7388f732000-06-28 21:06:08 +0000987 elsif ($font eq 'constant') {
988 $font = 'tt class="constant"';
989 }
Fred Drakecb0fc9c2000-08-09 13:45:04 +0000990 elsif ($font eq 'kbd') {
991 $font = 'kbd';
992 }
Fred Drakef74e5b71999-04-28 14:58:49 +0000993 return $font;
994}
995
Fred Drakee15956b2000-04-03 04:51:13 +0000996sub figure_column_alignment{
997 my $a = @_[0];
998 my $mark = substr($a, 0, 1);
999 my $r = '';
1000 if ($mark eq 'c')
1001 { $r = ' align="center"'; }
1002 elsif ($mark eq 'r')
1003 { $r = ' align="right"'; }
1004 elsif ($mark eq 'l')
1005 { $r = ' align="left"'; }
1006 elsif ($mark eq 'p')
1007 { $r = ' align="left"'; }
1008 return $r;
1009}
1010
Fred Drake6659c301998-03-03 22:02:19 +00001011sub setup_column_alignments{
1012 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001013 my($s1,$s2,$s3,$s4) = split(/[|]/,$_);
1014 my $a1 = figure_column_alignment($s1);
1015 my $a2 = figure_column_alignment($s2);
1016 my $a3 = figure_column_alignment($s3);
1017 my $a4 = figure_column_alignment($s4);
1018 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1019 $col_aligns[1] = "<td$a2>";
1020 $col_aligns[2] = "<td$a3>";
1021 $col_aligns[3] = "<td$a4>";
Fred Drake79189b51999-04-28 13:54:30 +00001022 # return the aligned header start tags
Fred Drakee15956b2000-04-03 04:51:13 +00001023 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>");
1024}
1025
1026sub get_table_col1_fonts{
1027 my $font = $globals{'lineifont'};
1028 my ($sfont,$efont) = ('', '');
1029 if ($font) {
1030 $sfont = "<$font>";
1031 $efont = "</$font>";
1032 $efont =~ s/ .*>/>/;
1033 }
1034 return ($font, $sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001035}
1036
1037sub do_env_tableii{
1038 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001039 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001040 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001041 my $h1 = next_argument();
1042 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001043 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001044 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001045 my $a1 = $col_aligns[0];
1046 my $a2 = $col_aligns[1];
1047 s/\\lineii</\\lineii[$a1|$a2]</g;
1048 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001049 . "\n <thead>"
Fred Drake3be20742000-08-31 06:22:54 +00001050 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001051 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1052 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001053 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001054 . "\n <tbody valign='baseline'>"
1055 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001056 . "\n </tbody>"
1057 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001058}
1059
Fred Drakeda72b932000-09-21 15:58:02 +00001060sub do_env_longtableii{
1061 return do_env_tableii(@_);
1062}
1063
Fred Drake6659c301998-03-03 22:02:19 +00001064sub do_cmd_lineii{
1065 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001066 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001067 my $c1 = next_argument();
1068 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001069 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001070 my($font,$sfont,$efont) = get_table_col1_fonts();
1071 $c2 = '&nbsp;' if ($c2 eq '');
1072 my($c1align,$c2align) = split('\|', $aligns);
1073 my $padding = '';
1074 if ($c1align =~ /align="right"/) {
1075 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001076 }
Fred Drakee15956b2000-04-03 04:51:13 +00001077 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1078 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001079 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001080}
1081
1082sub do_env_tableiii{
1083 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001084 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001085 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001086 my $h1 = next_argument();
1087 my $h2 = next_argument();
1088 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001089 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001090 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001091 my $a1 = $col_aligns[0];
1092 my $a2 = $col_aligns[1];
1093 my $a3 = $col_aligns[2];
1094 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1095 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001096 . "\n <thead>"
1097 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001098 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1099 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1100 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001101 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001102 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001103 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001104 . "\n </tbody>"
1105 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001106}
1107
Fred Drakeda72b932000-09-21 15:58:02 +00001108sub do_env_longtableiii{
1109 return do_env_tableiii(@_);
1110}
1111
Fred Drake6659c301998-03-03 22:02:19 +00001112sub do_cmd_lineiii{
1113 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001114 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001115 my $c1 = next_argument();
1116 my $c2 = next_argument();
1117 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001118 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001119 my($font,$sfont,$efont) = get_table_col1_fonts();
1120 $c3 = '&nbsp;' if ($c3 eq '');
1121 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1122 my $padding = '';
1123 if ($c1align =~ /align="right"/) {
1124 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001125 }
Fred Drakee15956b2000-04-03 04:51:13 +00001126 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001127 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001128 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001129 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001130}
1131
Fred Drakea0f4c941998-07-24 22:16:04 +00001132sub do_env_tableiv{
1133 local($_) = @_;
1134 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001135 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001136 my $h1 = next_argument();
1137 my $h2 = next_argument();
1138 my $h3 = next_argument();
1139 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001140 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001141 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001142 my $a1 = $col_aligns[0];
1143 my $a2 = $col_aligns[1];
1144 my $a3 = $col_aligns[2];
1145 my $a4 = $col_aligns[3];
1146 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1147 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001148 . "\n <thead>"
1149 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001150 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1151 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1152 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1153 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001154 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001155 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001156 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001157 . "\n </tbody>"
1158 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001159}
1160
Fred Drakeda72b932000-09-21 15:58:02 +00001161sub do_env_longtableiv{
1162 return do_env_tableiv(@_);
1163}
1164
Fred Drakea0f4c941998-07-24 22:16:04 +00001165sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001166 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001167 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001168 my $c1 = next_argument();
1169 my $c2 = next_argument();
1170 my $c3 = next_argument();
1171 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001172 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001173 my($font,$sfont,$efont) = get_table_col1_fonts();
1174 $c4 = '&nbsp;' if ($c4 eq '');
1175 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1176 my $padding = '';
1177 if ($c1align =~ /align="right"/) {
1178 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001179 }
Fred Drakee15956b2000-04-03 04:51:13 +00001180 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001181 . " $c2align$c2</td>\n"
1182 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001183 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001184 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001185}
1186
Fred Drake3be20742000-08-31 06:22:54 +00001187
1188# These can be used to control the title page appearance;
1189# they need a little bit of documentation.
1190#
1191# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1192# $ICONSERVER directory, or include path information (other than "./"). The
1193# default image type will be assumed if an extension is not provided.
1194#
1195# If specified, the "title page" will contain two colums: one containing the
1196# title/author/etc., and the other containing the graphic. Use the other
1197# four variables listed here to control specific details of the layout; all
1198# are optional.
1199#
1200# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1201# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1202# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1203# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1204# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1205
1206sub make_my_titlepage() {
1207 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001208 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001209 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001210 }
1211 else {
1212 write_warnings("\nThis document has no title.");
1213 }
Fred Drake6659c301998-03-03 22:02:19 +00001214 if ($t_author) {
1215 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001216 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001217 $href = make_named_href('author', $href,
1218 "<b><font size='+2'>$t_author</font></b>");
Fred Drakec9a44381998-03-17 06:29:13 +00001219 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001220 }
1221 else {
Fred Drake2d1f81e1999-02-09 16:03:31 +00001222 $the_title .= ("\n<p><b><font size='+2'>$t_author</font></b></p>");
Fred Drake6659c301998-03-03 22:02:19 +00001223 }
Fred Drake3be20742000-08-31 06:22:54 +00001224 }
1225 else {
1226 write_warnings("\nThere is no author for this document.");
1227 }
Fred Drake6659c301998-03-03 22:02:19 +00001228 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001229 $the_title .= "\n<p>$t_institute</p>";
1230 }
Fred Draked07868a1998-05-14 21:00:28 +00001231 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001232 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1233 }
Fred Drake6659c301998-03-03 22:02:19 +00001234 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001235 $the_title .= "\n<p><i>$t_affil</i></p>";
1236 }
Fred Drake6659c301998-03-03 22:02:19 +00001237 if ($t_date) {
Fred Drakec9a44381998-03-17 06:29:13 +00001238 $the_title .= "\n<p><strong>$t_date</strong>";
Fred Drake6659c301998-03-03 22:02:19 +00001239 if ($PYTHON_VERSION) {
Fred Drake3be20742000-08-31 06:22:54 +00001240 $the_title .= "<br><strong>Release $PYTHON_VERSION</strong>";
1241 }
Fred Drake6659c301998-03-03 22:02:19 +00001242 $the_title .= "</p>"
1243 }
1244 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001245 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001246 }
1247 else {
1248 $the_title .= "\n<p>";
1249 }
Fred Drake6659c301998-03-03 22:02:19 +00001250 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001251 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001252 }
1253 return $the_title;
1254}
1255
1256use File::Basename;
1257
1258sub make_my_titlegraphic() {
1259 my($myname, $mydir, $myext) = fileparse($TITLE_PAGE_GRAPHIC, '\..*');
1260 chop $mydir;
1261 if ($mydir eq '.') {
1262 $mydir = $ICONSERVER;
1263 }
1264 $myext = ".$IMAGE_TYPE"
1265 unless $myext;
1266 my $graphic = "<td class=\"titlegraphic\"";
1267 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1268 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1269 $graphic .= "><img";
1270 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1271 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1272 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1273 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
1274 $graphic .= "\n src=\"$mydir/$myname$myext\"></td>\n";
1275 return $graphic;
1276}
1277
1278sub do_cmd_maketitle {
1279 local($_) = @_;
1280 my $the_title = "\n<div class=\"titlepage\">";
1281 if ($TITLE_PAGE_GRAPHIC) {
1282 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1283 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1284 . "<tr align=\"right\">\n<td>"
1285 . make_my_titlepage()
1286 . "</td>\n"
1287 . make_my_titlegraphic()
1288 . "</tr>\n</table>");
1289 }
1290 else {
1291 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1292 . make_my_titlegraphic()
1293 . "<td>"
1294 . make_my_titlepage()
1295 . "</td></tr>\n</table>");
1296 }
1297 }
1298 else {
1299 $the_title .= ("\n<center>"
1300 . make_my_titlepage()
1301 . "\n</center>");
1302 }
1303 $the_title .= "\n</div>";
1304 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001305 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001306 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001307}
1308
1309
Fred Drake885215c1998-05-20 21:32:09 +00001310#
Fred Drakea0f4c941998-07-24 22:16:04 +00001311# Module synopsis support
1312#
1313
1314require SynopsisTable;
1315
Fred Drakef7685d71998-07-25 03:31:46 +00001316sub get_chapter_id(){
1317 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001318 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1319 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001320 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001321}
1322
Fred Drake643d76d2000-09-09 06:07:37 +00001323# 'chapter' => 'SynopsisTable instance'
1324%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001325
1326sub get_synopsis_table($){
1327 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001328 my $key;
1329 foreach $key (keys %ModuleSynopses) {
1330 if ($key eq $chap) {
1331 return $ModuleSynopses{$chap};
1332 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001333 }
Fred Drake643d76d2000-09-09 06:07:37 +00001334 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001335 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001336 return $st;
1337}
1338
Fred Drake62e43691998-08-10 19:40:44 +00001339sub do_cmd_moduleauthor{
1340 local($_) = @_;
1341 next_argument();
1342 next_argument();
1343 return $_;
1344}
1345
1346sub do_cmd_sectionauthor{
1347 local($_) = @_;
1348 next_argument();
1349 next_argument();
1350 return $_;
1351}
1352
Fred Drakea0f4c941998-07-24 22:16:04 +00001353sub do_cmd_declaremodule{
1354 local($_) = @_;
1355 my $key = next_optional_argument();
1356 my $type = next_argument();
1357 my $name = next_argument();
1358 my $st = get_synopsis_table(get_chapter_id());
1359 #
1360 $key = $name unless $key;
1361 $type = 'built-in' if $type eq 'builtin';
1362 $st->declare($name, $key, $type);
1363 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001364 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001365}
1366
1367sub do_cmd_modulesynopsis{
1368 local($_) = @_;
1369 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001370 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001371 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001372}
1373
1374sub do_cmd_localmoduletable{
1375 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001376 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001377 my $st = get_synopsis_table($chap);
1378 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001379 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001380}
1381
1382sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001383 my $key;
1384 my $st, $file;
1385 foreach $key (keys %ModuleSynopses) {
1386 $st = $ModuleSynopses{$key};
1387 $file = $st->get_file();
1388 if ($file) {
1389 process_localmoduletables_in_file($file);
1390 }
1391 else {
1392 print "\nsynopsis table $key has no file association";
1393 }
1394 }
1395}
1396
1397sub process_localmoduletables_in_file{
1398 my $file = @_[0];
1399 open(MYFILE, "<$file");
1400 local($_);
1401 sysread(MYFILE, $_, 1024*1024);
1402 close(MYFILE);
1403 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001404 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001405 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001406 my $chap = $1;
1407 my $st = get_synopsis_table($chap);
1408 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001409 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001410 }
Fred Drake643d76d2000-09-09 06:07:37 +00001411 open(MYFILE,">$file");
1412 print MYFILE $_;
1413 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001414}
Fred Drake557460c1999-03-02 16:05:35 +00001415sub process_python_state{
1416 process_all_localmoduletables();
Fred Drake557460c1999-03-02 16:05:35 +00001417}
Fred Drakea0f4c941998-07-24 22:16:04 +00001418
1419
1420#
1421# "See also:" -- references placed at the end of a \section
1422#
1423
1424sub do_env_seealso{
Fred Drakee15956b2000-04-03 04:51:13 +00001425 return "<div class='seealso'>\n "
1426 . "<p class='heading'><b>See Also:</b></p>\n"
Fred Drake90fdda51999-02-16 20:27:42 +00001427 . @_[0]
1428 . '</div>';
Fred Drakea0f4c941998-07-24 22:16:04 +00001429}
1430
1431sub do_cmd_seemodule{
1432 # Insert the right magic to jump to the module definition. This should
1433 # work most of the time, at least for repeat builds....
1434 local($_) = @_;
1435 my $key = next_optional_argument();
1436 my $module = next_argument();
1437 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001438 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001439 $key = $module
1440 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001441 if ($text =~ /\.$/) {
1442 $period = '';
1443 }
Fred Drakee15956b2000-04-03 04:51:13 +00001444 return '<dl compact class="seemodule">'
1445 . "\n <dt>Module <b><tt class='module'><a href='module-$key.html'>"
Fred Drake84bd6f31999-05-11 15:42:51 +00001446 . "$module</a></tt>:</b>"
1447 . "\n <dd>$text$period\n </dl>"
Fred Drake90fdda51999-02-16 20:27:42 +00001448 . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001449}
1450
Fred Drake643d76d2000-09-09 06:07:37 +00001451sub handle_rfclike_reference{
1452 local($_, $what) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001453 my $rfcnum = next_argument();
1454 my $title = next_argument();
1455 my $text = next_argument();
1456 my $url = get_rfc_url($rfcnum);
1457 return '<dl compact class="seerfc">'
1458 . "\n <dt><a href=\"$url\""
1459 . "\n title=\"$title\""
Fred Drake643d76d2000-09-09 06:07:37 +00001460 . "\n >$what $rfcnum, <em>$title</em></a>:"
Fred Drake37cc0c02000-04-26 18:05:24 +00001461 . "\n <dd>$text\n </dl>"
1462 . $_;
1463}
1464
Fred Drake643d76d2000-09-09 06:07:37 +00001465sub do_cmd_seepep{
1466 return handle_rfclike_reference(@_[0], "PEP");
1467}
1468
1469sub do_cmd_seerfc{
1470 return handle_rfclike_reference(@_[0], "RFC");
1471}
1472
Fred Drake48449982000-09-12 17:52:33 +00001473sub do_cmd_seetitle{
1474 local($_) = @_;
1475 my $url = next_optional_argument();
1476 my $title = next_argument();
1477 my $text = next_argument();
1478 if ($url) {
1479 return '<dl compact class="seetitle">'
1480 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
1481 . "\n class=\"url\">$title</a></em>"
1482 . "\n <dd>$text\n </dl>"
1483 . $_;
1484 }
1485 return '<dl compact class="seetitle">'
1486 . "\n <dt><em class=\"citetitle\""
1487 . "\n >$title</em>"
1488 . "\n <dd>$text\n </dl>"
1489 . $_;
1490}
1491
Fred Drakeef4d1112000-05-09 16:17:51 +00001492sub do_cmd_seeurl{
1493 local($_) = @_;
1494 my $url = next_argument();
1495 my $text = next_argument();
1496 return '<dl compact class="seeurl">'
1497 . "\n <dt><a href=\"$url\""
1498 . "\n class=\"url\">$url</a>"
1499 . "\n <dd>$text\n </dl>"
1500 . $_;
1501}
1502
Fred Drakea0f4c941998-07-24 22:16:04 +00001503sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001504 local($_) = @_;
1505 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001506 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001507}
1508
1509
1510#
Fred Drake885215c1998-05-20 21:32:09 +00001511# Definition list support.
1512#
1513
1514sub do_env_definitions{
Fred Drake37cc0c02000-04-26 18:05:24 +00001515 return "<dl class='definitions'>" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001516}
1517
1518sub do_cmd_term{
1519 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001520 my $term = next_argument();
1521 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001522 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001523 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001524}
1525
1526
Fred Drake38178fd2000-09-22 17:05:04 +00001527# I don't recall exactly why this was needed, but it was very much needed.
1528# We'll see if anything breaks when I move the "code" line out -- some
1529# things broke with it in.
1530
1531#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001532process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001533declaremodule # [] # {} # {}
1534memberline # [] # {}
1535methodline # [] # {} # {}
1536modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001537platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001538samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001539setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001540withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001541_RAW_ARG_DEFERRED_CMDS_
1542
1543
Fred Drake6659c301998-03-03 22:02:19 +000015441; # This must be the last line