blob: 58a4a889845d68d8a41f1a3108dd0eb2b3ad7608 [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 Drake6659c301998-03-03 22:02:19 +000074$PYTHON_VERSION = '';
75
76sub do_cmd_version{ $PYTHON_VERSION . @_[0]; }
77sub do_cmd_release{
78 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +000079 $PYTHON_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +000080 return $_;
Fred Drake6659c301998-03-03 22:02:19 +000081}
82
83sub do_cmd_authoraddress{
84 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +000085 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +000086 return $_;
Fred Drake6659c301998-03-03 22:02:19 +000087}
88
Fred Drakee16f6791998-05-15 04:28:37 +000089#sub do_cmd_developer{ do_cmd_author(@_[0]); }
90#sub do_cmd_developers{ do_cmd_author(@_[0]); }
91#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +000092
Fred Drake6659c301998-03-03 22:02:19 +000093sub do_cmd_hackscore{
94 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +000095 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +000096 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +000097}
98
Fred Drake08932051998-04-17 02:15:42 +000099sub use_wrappers{
100 local($_,$before,$after) = @_;
101 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000102 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000103}
104
Fred Drake62e43691998-08-10 19:40:44 +0000105sub use_sans_serif{
Fred Drakeccc62721999-01-05 22:16:29 +0000106 return use_wrappers(@_[0], '<font face="sans-serif">', '</font>');
Fred Drake62e43691998-08-10 19:40:44 +0000107}
108sub use_italics{
109 return use_wrappers(@_[0], '<i>', '</i>');
110}
Fred Drake08932051998-04-17 02:15:42 +0000111
Fred Drake6659c301998-03-03 22:02:19 +0000112sub do_cmd_optional{
Fred Drake62e43691998-08-10 19:40:44 +0000113 return use_wrappers(@_[0], "</var><big>\[</big><var>",
114 "</var><big>\]</big><var>");
Fred Drake6659c301998-03-03 22:02:19 +0000115}
116
Fred Drakec9a44381998-03-17 06:29:13 +0000117# Logical formatting (some based on texinfo), needs to be converted to
118# minimalist HTML. The "minimalist" is primarily to reduce the size of
119# output files for users that read them over the network rather than
120# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000121
Fred Drake2cafcbb1999-03-25 16:57:04 +0000122# \file and \samp are at the end of this file since they screw up fontlock.
123
Fred Drake2ff880e1999-02-05 18:31:29 +0000124sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000125sub do_cmd_makevar{
126 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000127sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000128 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000129sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000130 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000131sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000132 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000133sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000134 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000135sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000136 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000137sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000138 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000139sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000140 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000141sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000142 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000143sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000144 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000145sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000146 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000147sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000148 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000149sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000150 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000151sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000152 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000153sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000154 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000155sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000156 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000157sub do_cmd_programopt{
158 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000159sub do_cmd_longprogramopt{
160 # note that the --- will be later converted to -- by LaTeX2HTML
161 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000162sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000163 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000164sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000165 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000166sub do_cmd_var{
167 return use_wrappers(@_[0], "<var>", "</var>"); }
168sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000169 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000170sub do_cmd_emph{
171 return use_italics(@_); }
172sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000173 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000174sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000175 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000176sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000177 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000178sub do_cmd_kbd{
179 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
180sub do_cmd_strong{
181 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000182sub do_cmd_textbf{
183 return use_wrappers(@_[0], '<b>', '</b>'); }
184sub do_cmd_textit{
185 return use_wrappers(@_[0], '<i>', '</i>'); }
186
Fred Drake3d5a04a2000-08-03 17:25:44 +0000187sub do_cmd_moreargs{
188 return '...' . @_[0]; }
189sub do_cmd_unspecified{
190 return '...' . @_[0]; }
191
Fred Drakec9a44381998-03-17 06:29:13 +0000192
Fred Drake25817041999-01-13 17:06:34 +0000193sub do_cmd_refmodule{
194 # Insert the right magic to jump to the module definition.
195 local($_) = @_;
196 my $key = next_optional_argument();
197 my $module = next_argument();
198 $key = $module
199 unless $key;
Fred Drakee15956b2000-04-03 04:51:13 +0000200 return "<tt class='module'><a href='module-$key.html'>$module</a></tt>"
201 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000202}
203
Fred Drake1a7af391998-04-01 22:44:56 +0000204sub do_cmd_newsgroup{
205 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000206 my $newsgroup = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000207 my $stuff = "<span class='newsgroup'><a href='news:$newsgroup'>"
208 . "$newsgroup</a></span>";
Fred Drake62e43691998-08-10 19:40:44 +0000209 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000210}
Fred Drakefc16e781998-03-12 21:03:26 +0000211
212sub do_cmd_envvar{
213 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000214 my $envvar = next_argument();
215 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000216 # The <tt> here is really to keep buildindex.py from making
217 # the variable name case-insensitive.
218 add_index_entry("environment variables!$envvar@<tt>\$$envvar</tt>",
219 $ahref);
Fred Drake42b31a51998-03-27 05:16:10 +0000220 add_index_entry("$envvar@\$$envvar", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000221 $aname =~ s/<a/<a class="envvar"/;
Fred Draked37cecf1999-09-23 16:45:08 +0000222 return "$aname\$$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000223}
224
Fred Drake6659c301998-03-03 22:02:19 +0000225sub do_cmd_url{
226 # use the URL as both text and hyperlink
227 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000228 my $url = next_argument();
Fred Drake6659c301998-03-03 22:02:19 +0000229 $url =~ s/~/&#126;/g;
Fred Drakee15956b2000-04-03 04:51:13 +0000230 return "<a class=\"url\" href=\"$url\">$url</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000231}
232
233sub do_cmd_manpage{
234 # two parameters: \manpage{name}{section}
235 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000236 my $page = next_argument();
237 my $section = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000238 return "<span class='manpage'><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000239}
240
Fred Drake643d76d2000-09-09 06:07:37 +0000241sub get_pep_url{
242 my $rfcnum = sprintf("%04d", @_[0]);
243 return "http://python.sourceforge.net/peps/pep-$rfcnum.html";
244}
245
246sub do_cmd_pep{
247 local($_) = @_;
248 my $rfcnumber = next_argument();
249 my $id = "rfcref-" . ++$global{'max_id'};
250 my $href = get_pep_url($rfcnumber);
251 # Save the reference
252 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
253 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
254 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber</a>"
255 . $_);
256}
257
Fred Drake37cc0c02000-04-26 18:05:24 +0000258sub get_rfc_url{
259 my $rfcnum = sprintf("%04d", @_[0]);
260 return "http://www.ietf.org/rfc/rfc$rfcnum.txt";
261}
262
Fred Drake6659c301998-03-03 22:02:19 +0000263sub do_cmd_rfc{
264 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000265 my $rfcnumber = next_argument();
266 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drake37cc0c02000-04-26 18:05:24 +0000267 my $href = get_rfc_url($rfcnumber);
Fred Drake6659c301998-03-03 22:02:19 +0000268 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000269 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000270 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drakee15956b2000-04-03 04:51:13 +0000271 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber</a>"
Fred Draked52879c1999-09-22 19:58:51 +0000272 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000273}
274
Fred Drakec9f5fe01999-11-09 16:59:42 +0000275sub do_cmd_citetitle{
276 local($_) = @_;
277 my $url = next_optional_argument();
278 my $title = next_argument();
279 my $repl = '';
280 if ($url) {
281 $repl = ("<em class='citetitle'><a\n"
282 . " href='$url'\n"
283 . " title='$title'\n"
284 . " >$title</a></em>");
285 }
286 else {
287 $repl = "<em class='citetitle'\n >$title</em>";
288 }
289 return $repl . $_;
290}
291
Fred Drake6659c301998-03-03 22:02:19 +0000292sub do_cmd_deprecated{
293 # two parameters: \deprecated{version}{whattodo}
294 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000295 my $release = next_argument();
296 my $reason = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000297 return "<b>Deprecated since release $release.</b>\n$reason<p>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000298}
299
Fred Drake897d12b1998-07-27 20:33:17 +0000300sub do_cmd_versionadded{
301 # one parameter: \versionadded{version}
302 local($_) = @_;
303 my $release = next_argument();
Fred Drake2116d981999-02-02 18:02:48 +0000304 return "\nNew in version $release.\n" . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000305}
306
307sub do_cmd_versionchanged{
308 # one parameter: \versionchanged{version}
309 local($_) = @_;
Fred Drake52e76842000-05-02 17:37:42 +0000310 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000311 my $release = next_argument();
Fred Drake52e76842000-05-02 17:37:42 +0000312 my $text = "\nChanged in version $release.\n";
313 if ($release) {
314 $text = "\nChanged in version $release:\n$explanation.\n";
315 }
316 return $text . $_;
Fred Drake897d12b1998-07-27 20:33:17 +0000317}
318
Fred Drake557460c1999-03-02 16:05:35 +0000319#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000320# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000321#
322sub do_cmd_platform{
323 local($_) = @_;
324 my $platform = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000325 $ModulePlatforms{"<tt class='module'>$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000326 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000327 if $platform eq 'Mac';
Fred Drakee15956b2000-04-03 04:51:13 +0000328 return "\n<p class='availability'>Availability: <span"
329 . "\n class='platform'>$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000330}
331
Fred Drake557460c1999-03-02 16:05:35 +0000332$IGNORE_PLATFORM_ANNOTATION = '';
333sub do_cmd_ignorePlatformAnnotation{
334 local($_) = @_;
335 $IGNORE_PLATFORM_ANNOTATION = next_argument();
336 return $_;
337}
338
Fred Drake6659c301998-03-03 22:02:19 +0000339
340# index commands
341
342$INDEX_SUBITEM = "";
343
344sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000345 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000346}
347
348sub do_cmd_setindexsubitem{
349 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000350 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000351 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000352}
353
Fred Drakefc16e781998-03-12 21:03:26 +0000354sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000355 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000356 # do things in the right order, but we need to at least strip this stuff
357 # out, and leave anything that the second argument expanded out to.
358 #
359 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000360 my $oldsubitem = $INDEX_SUBITEM;
361 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000362 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000363 my $br_id = ++$globals{'max_id'};
364 my $marker = "$O$br_id$C";
Fred Drake7d45f6d1999-01-05 14:39:27 +0000365 return
366 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000367 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000368 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000369}
370
Fred Drake08932051998-04-17 02:15:42 +0000371# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000372# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
373# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000374#
Fred Drake62e43691998-08-10 19:40:44 +0000375sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000376
Fred Drake42b31a51998-03-27 05:16:10 +0000377# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000378#
Fred Drake08932051998-04-17 02:15:42 +0000379open(IDXFILE, '>index.dat') || die "\n$!\n";
380open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000381print INTLABELS "%internal_labels = ();\n";
382print INTLABELS "1; # hack in case there are no entries\n\n";
383
384# Using \0 for this is bad because we can't use common tools to work with the
385# resulting files. Things like grep can be useful with this stuff!
386#
387$IDXFILE_FIELD_SEP = "\1";
388
Fred Drakeccc62721999-01-05 22:16:29 +0000389sub write_idxfile{
390 my ($ahref, $str) = @_;
391 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000392}
393
Fred Drake42b31a51998-03-27 05:16:10 +0000394
395sub gen_link{
396 my($node,$target) = @_;
397 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakee15956b2000-04-03 04:51:13 +0000398 return "<a href='$node#$target'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000399}
400
Fred Drake42b31a51998-03-27 05:16:10 +0000401sub add_index_entry{
402 # add an entry to the index structures; ignore the return value
403 my($str,$ahref) = @_;
404 $str = gen_index_id($str, '');
405 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000406 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000407}
408
Fred Drakeccc62721999-01-05 22:16:29 +0000409sub new_link_info{
410 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakee15956b2000-04-03 04:51:13 +0000411 my $aname = "<a name='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000412 my $ahref = gen_link($CURRENT_FILE, $name);
413 return ($name, $aname, $ahref);
414}
415
Fred Drakeab032151999-05-13 18:36:54 +0000416$IndexMacroPattern = '';
417sub define_indexing_macro{
418 my $count = @_;
419 my $i = 0;
420 for (; $i < $count; ++$i) {
421 my $name = @_[$i];
422 my $cmd = "idx_cmd_$name";
423 die "\nNo function $cmd() defined!\n"
424 if (!defined &$cmd);
425 eval ("sub do_cmd_$name { return process_index_macros("
426 . "\@_[0], '$name'); }");
427 if (length($IndexMacroPattern) == 0) {
428 $IndexMacroPattern = "$name";
429 }
430 else {
431 $IndexMacroPattern .= "|$name";
432 }
433 }
434}
435
436$DEBUG_INDEXING = 0;
437sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000438 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000439 my $cmdname = @_[1]; # This is what triggered us in the first place;
440 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000441 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000442 my $cmd = "idx_cmd_$cmdname";
443 print "\nIndexing: \\$cmdname"
444 if $DEBUG_INDEXING;
445 &$cmd($ahref); # modifies $_ and adds index entries
446 while (/^[\s\n]*\\($IndexMacroPattern)</) {
447 $cmdname = "$1";
448 print " \\$cmdname"
449 if $DEBUG_INDEXING;
450 $cmd = "idx_cmd_$cmdname";
451 if (!defined &$cmd) {
452 last;
453 }
454 else {
455 s/^[\s\n]*\\$cmdname//;
456 &$cmd($ahref);
457 }
458 }
Fred Drake62e43691998-08-10 19:40:44 +0000459 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000460}
461
Fred Drakeab032151999-05-13 18:36:54 +0000462define_indexing_macro('index');
463sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000464 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000465 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000466}
467
Fred Drakeab032151999-05-13 18:36:54 +0000468define_indexing_macro('kwindex');
469sub idx_cmd_kwindex{
470 my $str = next_argument();
471 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
472 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
473}
474
475define_indexing_macro('indexii');
476sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000477 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000478 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000479 add_index_entry("$str1!$str2", @_[0]);
480 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000481}
482
Fred Drakeab032151999-05-13 18:36:54 +0000483define_indexing_macro('indexiii');
484sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000485 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000486 my $str2 = next_argument();
487 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000488 add_index_entry("$str1!$str2 $str3", @_[0]);
489 add_index_entry("$str2!$str3, $str1", @_[0]);
490 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000491}
492
Fred Drakeab032151999-05-13 18:36:54 +0000493define_indexing_macro('indexiv');
494sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000495 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000496 my $str2 = next_argument();
497 my $str3 = next_argument();
498 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000499 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
500 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
501 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
502 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000503}
504
Fred Drakeab032151999-05-13 18:36:54 +0000505define_indexing_macro('ttindex');
506sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000507 my $str = next_argument();
508 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000509 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000510}
Fred Drake6659c301998-03-03 22:02:19 +0000511
512sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000513 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000514 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000515 add_index_entry("$str $word", $ahref);
516 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000517}
518
Fred Drakeab032151999-05-13 18:36:54 +0000519define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
520sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
521sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
522sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
523sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000524
Fred Drakeab032151999-05-13 18:36:54 +0000525define_indexing_macro('bifuncindex');
526sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000527 my $str = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000528 add_index_entry("<tt class='function'>$str()</tt> (built-in function)",
529 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000530}
531
532
Fred Drake6659c301998-03-03 22:02:19 +0000533sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000534 my($str,$define) = @_;
535 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000536 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000537 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
538 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000539 $str = gen_index_id($str, $define);
540 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000541 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000542
Fred Drakec9a44381998-03-17 06:29:13 +0000543 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000544 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000545 $str =~ /(<tt.*<\/tt>)/;
546 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000547 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000548 }
Fred Drake62e43691998-08-10 19:40:44 +0000549 return "$aname$anchor_invisible_mark</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000550}
551
Fred Drake557460c1999-03-02 16:05:35 +0000552
Fred Drakec9a44381998-03-17 06:29:13 +0000553$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000554$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000555
Fred Drakea0f4c941998-07-24 22:16:04 +0000556sub define_module{
557 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000558 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000559 if ($word ne "built-in" && $word ne "extension"
560 && $word ne "standard" && $word ne "") {
561 write_warnings("Bad module type '$word'"
562 . " for \\declaremodule (module $name)");
563 $word = "";
564 }
Fred Drake6659c301998-03-03 22:02:19 +0000565 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000566 $THIS_MODULE = "$name";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000567 $INDEX_SUBITEM = "(in $name)";
568 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000569 return make_mod_index_entry(
570 "<tt class='module'>$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000571}
572
573sub my_module_index_helper{
574 local($word, $_) = @_;
575 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000576 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000577}
578
Fred Drake62e43691998-08-10 19:40:44 +0000579sub do_cmd_modindex{ return my_module_index_helper('', @_); }
580sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
581sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
582sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000583
Fred Drakeab032151999-05-13 18:36:54 +0000584sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000585 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000586 my $str = next_argument();
587 $word = "$word " if $word;
Fred Drakee15956b2000-04-03 04:51:13 +0000588 $str = "<tt class='module'>$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000589 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
590 # just inline it all here
591 $str = gen_index_id($str, 'REF');
592 $index{$str} .= $ahref;
593 write_idxfile($ahref, $str);
594}
595
Fred Drake6659c301998-03-03 22:02:19 +0000596# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000597define_indexing_macro('refmodindex', 'refbimodindex',
598 'refexmodindex', 'refstmodindex');
599sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
600sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
601sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
602sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000603
Fred Drake62e43691998-08-10 19:40:44 +0000604sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000605
606sub init_myformat{
Fred Drake08932051998-04-17 02:15:42 +0000607# $anchor_invisible_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000608 $anchor_mark = '';
609 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000610}
Fred Drake42b31a51998-03-27 05:16:10 +0000611init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000612
Fred Drakeab032151999-05-13 18:36:54 +0000613# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000614# instead of the dummy filler.
615#
616sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000617 my($str) = @_;
618 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000619 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000620 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000621}
622
Fred Drakee15956b2000-04-03 04:51:13 +0000623$REFCOUNTS_LOADED = 0;
624
625sub load_refcounts{
626 $REFCOUNTS_LOADED = 1;
627
628 use File::Basename;
629 my $myname, $mydir, $myext;
630 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
631 chop $mydir; # remove trailing '/'
632 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
633 chop $mydir; # remove trailing '/'
634 $mydir = getcwd() . "$dd$mydir"
635 unless $mydir =~ s|^/|/|;
636 local $_;
637 my $filename = "$mydir${dd}api${dd}refcounts.dat";
638 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
639 print "[loading API refcount data]";
640 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000641 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000642 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
643 #print "\n$func($param) --> $count";
644 $REFCOUNTS{"$func:$param"} = $count;
645 }
646 }
647}
648
649sub get_refcount{
650 my ($func, $param) = @_;
651 load_refcounts()
652 unless $REFCOUNTS_LOADED;
653 return $REFCOUNTS{"$func:$param"};
654}
655
Fred Drake6659c301998-03-03 22:02:19 +0000656sub do_env_cfuncdesc{
657 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000658 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000659 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000660 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000661 my $idx = make_str_index_entry(
662 "<tt class='cfunction'>$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000663 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000664 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000665 my $result_rc = get_refcount($function_name, '');
666 my $rcinfo = '';
667 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000668 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000669 }
670 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000671 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000672 }
Fred Drakec2578c52000-04-10 18:26:45 +0000673 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000674 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000675 }
Fred Drakee15956b2000-04-03 04:51:13 +0000676 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000677 $rcinfo = ( "\n<div class=\"refcount-info\">"
678 . "\n <span class=\"label\">Return value:</span>"
679 . "\n <span class=\"value\">$rcinfo.</span>"
680 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000681 }
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000682 return "<dl><dt>$return_type <b>$idx</b> (<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000683 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000684 . $_
685 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000686}
687
Fred Drakee15956b2000-04-03 04:51:13 +0000688sub do_env_csimplemacrodesc{
689 local($_) = @_;
690 my $name = next_argument();
691 my $idx = make_str_index_entry("<tt class='macro'>$name</tt>");
692 return "<dl><dt><b>$idx</b>\n<dd>"
693 . $_
694 . '</dl>'
695}
696
Fred Drake6659c301998-03-03 22:02:19 +0000697sub do_env_ctypedesc{
698 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000699 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000700 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000701 $index_name = $type_name
702 unless $index_name;
703 my($name,$aname,$ahref) = new_link_info();
704 add_index_entry("<tt class='ctype'>$index_name</tt> (C type)", $ahref);
705 return "<dl><dt><b><tt class='ctype'>$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000706 . $_
707 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000708}
709
710sub do_env_cvardesc{
711 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000712 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000713 my $var_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000714 my $idx = make_str_index_entry("<tt class='cdata'>$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000715 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000716 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000717 return "<dl><dt>$var_type <b>$idx</b>\n"
718 . '<dd>'
719 . $_
720 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000721}
722
723sub do_env_funcdesc{
724 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000725 my $function_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000726 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000727 my $idx = make_str_index_entry("<tt class='function'>$function_name()</tt>"
Fred Drake08932051998-04-17 02:15:42 +0000728 . get_indexsubitem());
729 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000730 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drake62e43691998-08-10 19:40:44 +0000731 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000732}
733
734sub do_env_funcdescni{
735 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000736 my $function_name = next_argument();
737 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000738 return "<dl><dt><b><tt class='function'>$function_name</tt></b>"
Fred Drake90fdda51999-02-16 20:27:42 +0000739 . " (<var>$arg_list</var>)\n"
740 . '<dd>'
741 . $_
742 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000743}
744
745sub do_cmd_funcline{
746 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000747 my $function_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000748 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000749 my $prefix = "<tt class='function'>$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000750 my $idx = make_str_index_entry($prefix . get_indexsubitem());
751 $prefix =~ s/\(\)//;
752
753 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000754}
755
Fred Drake6b3fb781999-07-12 16:50:09 +0000756sub do_cmd_funclineni{
757 local($_) = @_;
758 my $function_name = next_argument();
759 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000760 my $prefix = "<tt class='function'>$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000761
762 return "<dt><b>$prefix</b> (<var>$arg_list</var>)\n<dd>" . $_;
763}
764
Fred Drake6659c301998-03-03 22:02:19 +0000765# Change this flag to index the opcode entries. I don't think it's very
766# useful to index them, since they're only presented to describe the dis
767# module.
768#
769$INDEX_OPCODES = 0;
770
771sub do_env_opcodedesc{
772 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000773 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000774 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000775 my $idx;
776 if ($INDEX_OPCODES) {
Fred Drakee15956b2000-04-03 04:51:13 +0000777 $idx = make_str_index_entry("<tt class='opcode'>$opcode_name</tt>"
778 . " (byte code instruction)");
Fred Drake08932051998-04-17 02:15:42 +0000779 $idx =~ s/ \(byte code instruction\)//;
780 }
781 else {
Fred Drakee15956b2000-04-03 04:51:13 +0000782 $idx = "<tt class='opcode'>$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +0000783 }
784 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +0000785 if ($arg_list) {
786 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
787 }
Fred Drake62e43691998-08-10 19:40:44 +0000788 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000789}
790
791sub do_env_datadesc{
792 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000793 my $dataname = next_argument();
794 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000795 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000796 return "<dl><dt><b>$idx</b>\n<dd>"
797 . $_
798 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000799}
800
801sub do_env_datadescni{
802 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000803 my $idx = next_argument();
804 if (! $STRING_INDEX_TT) {
805 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +0000806 }
Fred Drake62e43691998-08-10 19:40:44 +0000807 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000808}
809
810sub do_cmd_dataline{
811 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000812 my $data_name = next_argument();
813 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +0000814 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000815 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000816}
817
Fred Drakeadb272c2000-04-10 17:47:14 +0000818sub do_cmd_datalineni{
819 local($_) = @_;
820 my $data_name = next_argument();
821 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
822}
823
Fred Drake42b31a51998-03-27 05:16:10 +0000824sub do_env_excdesc{
825 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000826 my $excname = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000827 my $idx = make_str_index_entry("<tt class='exception'>$excname</tt>");
Fred Drake62e43691998-08-10 19:40:44 +0000828 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>'
Fred Drake42b31a51998-03-27 05:16:10 +0000829}
830
Fred Drake62e43691998-08-10 19:40:44 +0000831sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000832
833
Fred Drake643d76d2000-09-09 06:07:37 +0000834sub handle_classlike_descriptor{
835 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000836 $THIS_CLASS = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000837 my $arg_list = next_argument();
838 $idx = make_str_index_entry(
Fred Drake643d76d2000-09-09 06:07:37 +0000839 "<tt class='$what'>$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +0000840 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000841 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +0000842}
843
Fred Drake643d76d2000-09-09 06:07:37 +0000844sub do_env_classdesc{
845 return handle_classlike_descriptor(@_[0], "class");
846}
847
848sub do_env_excclassdesc{
849 return handle_classlike_descriptor(@_[0], "exception");
850}
851
Fred Drake42b31a51998-03-27 05:16:10 +0000852
853sub do_env_methoddesc{
854 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000855 my $class_name = next_optional_argument();
856 $class_name = $THIS_CLASS
857 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +0000858 my $method = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000859 my $arg_list = next_argument();
860 my $extra = '';
861 if ($class_name) {
862 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +0000863 }
Fred Drakee15956b2000-04-03 04:51:13 +0000864 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +0000865 $idx =~ s/ \(.*\)//;
866 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000867 return "<dl><dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000868}
869
870
Fred Drake7d45f6d1999-01-05 14:39:27 +0000871sub do_cmd_methodline{
872 local($_) = @_;
873 my $class_name = next_optional_argument();
874 $class_name = $THIS_CLASS
875 unless $class_name;
876 my $method = next_argument();
877 my $arg_list = next_argument();
878 my $extra = '';
879 if ($class_name) {
880 $extra = " ($class_name method)";
881 }
Fred Drakee15956b2000-04-03 04:51:13 +0000882 my $idx = make_str_index_entry("<tt class='method'>$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +0000883 $idx =~ s/ \(.*\)//;
884 $idx =~ s/\(\)//;
885 return "<dt><b>$idx</b> (<var>$arg_list</var>)\n<dd>"
886 . $_;
887}
888
889
Fred Draked64a40d1998-09-10 18:59:13 +0000890sub do_cmd_methodlineni{
891 local($_) = @_;
892 next_optional_argument();
893 my $method = next_argument();
894 my $arg_list = next_argument();
895 return "<dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
896 . $_;
897}
898
Fred Drake42b31a51998-03-27 05:16:10 +0000899sub do_env_methoddescni{
900 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000901 next_optional_argument();
902 my $method = next_argument();
903 my $arg_list = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000904 return "<dl><dt><b>$method</b> (<var>$arg_list</var>)\n<dd>"
905 . $_
906 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000907}
908
909
910sub do_env_memberdesc{
911 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000912 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000913 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000914 $class = $THIS_CLASS
915 unless $class;
Fred Drake08932051998-04-17 02:15:42 +0000916 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000917 $extra = " ($class attribute)"
918 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000919 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +0000920 $idx =~ s/ \(.*\)//;
921 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000922 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000923}
924
925
Fred Drake5ccf3301998-04-17 20:04:09 +0000926sub do_cmd_memberline{
927 local($_) = @_;
928 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000929 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +0000930 $class = $THIS_CLASS
931 unless $class;
932 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +0000933 $extra = " ($class attribute)"
934 if ($class ne '');
Fred Drakee15956b2000-04-03 04:51:13 +0000935 my $idx = make_str_index_entry("<tt class='member'>$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +0000936 $idx =~ s/ \(.*\)//;
937 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000938 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000939}
940
Fred Drake42b31a51998-03-27 05:16:10 +0000941sub do_env_memberdescni{
942 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000943 next_optional_argument();
944 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000945 return "<dl><dt><b><tt class='member'>$member</tt></b>\n<dd>"
946 . $_
947 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +0000948}
949
950
Fred Drake5ccf3301998-04-17 20:04:09 +0000951sub do_cmd_memberlineni{
952 local($_) = @_;
953 next_optional_argument();
954 my $member = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000955 return "<dt><b><tt class='member'>$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +0000956}
957
Fred Drakee15956b2000-04-03 04:51:13 +0000958@col_aligns = ('<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +0000959
Fred Drakef74e5b71999-04-28 14:58:49 +0000960sub fix_font{
961 # do a little magic on a font name to get the right behavior in the first
962 # column of the output table
963 my $font = @_[0];
964 if ($font eq 'textrm') {
965 $font = '';
966 }
967 elsif ($font eq 'file' || $font eq 'filenq') {
Fred Drakee15956b2000-04-03 04:51:13 +0000968 $font = 'tt class="file"';
969 }
970 elsif ($font eq 'member') {
971 $font = 'tt class="member"';
Fred Drakef74e5b71999-04-28 14:58:49 +0000972 }
Fred Drake7388f732000-06-28 21:06:08 +0000973 elsif ($font eq 'constant') {
974 $font = 'tt class="constant"';
975 }
Fred Drakecb0fc9c2000-08-09 13:45:04 +0000976 elsif ($font eq 'kbd') {
977 $font = 'kbd';
978 }
Fred Drakef74e5b71999-04-28 14:58:49 +0000979 return $font;
980}
981
Fred Drakee15956b2000-04-03 04:51:13 +0000982sub figure_column_alignment{
983 my $a = @_[0];
984 my $mark = substr($a, 0, 1);
985 my $r = '';
986 if ($mark eq 'c')
987 { $r = ' align="center"'; }
988 elsif ($mark eq 'r')
989 { $r = ' align="right"'; }
990 elsif ($mark eq 'l')
991 { $r = ' align="left"'; }
992 elsif ($mark eq 'p')
993 { $r = ' align="left"'; }
994 return $r;
995}
996
Fred Drake6659c301998-03-03 22:02:19 +0000997sub setup_column_alignments{
998 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000999 my($s1,$s2,$s3,$s4) = split(/[|]/,$_);
1000 my $a1 = figure_column_alignment($s1);
1001 my $a2 = figure_column_alignment($s2);
1002 my $a3 = figure_column_alignment($s3);
1003 my $a4 = figure_column_alignment($s4);
1004 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1005 $col_aligns[1] = "<td$a2>";
1006 $col_aligns[2] = "<td$a3>";
1007 $col_aligns[3] = "<td$a4>";
Fred Drake79189b51999-04-28 13:54:30 +00001008 # return the aligned header start tags
Fred Drakee15956b2000-04-03 04:51:13 +00001009 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>");
1010}
1011
1012sub get_table_col1_fonts{
1013 my $font = $globals{'lineifont'};
1014 my ($sfont,$efont) = ('', '');
1015 if ($font) {
1016 $sfont = "<$font>";
1017 $efont = "</$font>";
1018 $efont =~ s/ .*>/>/;
1019 }
1020 return ($font, $sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001021}
1022
1023sub do_env_tableii{
1024 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001025 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001026 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001027 my $h1 = next_argument();
1028 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001029 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001030 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001031 my $a1 = $col_aligns[0];
1032 my $a2 = $col_aligns[1];
1033 s/\\lineii</\\lineii[$a1|$a2]</g;
1034 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001035 . "\n <thead>"
Fred Drake3be20742000-08-31 06:22:54 +00001036 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001037 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1038 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001039 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001040 . "\n <tbody valign='baseline'>"
1041 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001042 . "\n </tbody>"
1043 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001044}
1045
1046sub do_cmd_lineii{
1047 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001048 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001049 my $c1 = next_argument();
1050 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001051 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001052 my($font,$sfont,$efont) = get_table_col1_fonts();
1053 $c2 = '&nbsp;' if ($c2 eq '');
1054 my($c1align,$c2align) = split('\|', $aligns);
1055 my $padding = '';
1056 if ($c1align =~ /align="right"/) {
1057 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001058 }
Fred Drakee15956b2000-04-03 04:51:13 +00001059 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1060 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001061 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001062}
1063
1064sub do_env_tableiii{
1065 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001066 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001067 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001068 my $h1 = next_argument();
1069 my $h2 = next_argument();
1070 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001071 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001072 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001073 my $a1 = $col_aligns[0];
1074 my $a2 = $col_aligns[1];
1075 my $a3 = $col_aligns[2];
1076 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1077 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001078 . "\n <thead>"
1079 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001080 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1081 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1082 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001083 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001084 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001085 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001086 . "\n </tbody>"
1087 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001088}
1089
1090sub do_cmd_lineiii{
1091 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001092 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001093 my $c1 = next_argument();
1094 my $c2 = next_argument();
1095 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001096 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001097 my($font,$sfont,$efont) = get_table_col1_fonts();
1098 $c3 = '&nbsp;' if ($c3 eq '');
1099 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1100 my $padding = '';
1101 if ($c1align =~ /align="right"/) {
1102 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001103 }
Fred Drakee15956b2000-04-03 04:51:13 +00001104 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001105 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001106 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001107 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001108}
1109
Fred Drakea0f4c941998-07-24 22:16:04 +00001110sub do_env_tableiv{
1111 local($_) = @_;
1112 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001113 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001114 my $h1 = next_argument();
1115 my $h2 = next_argument();
1116 my $h3 = next_argument();
1117 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001118 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001119 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001120 my $a1 = $col_aligns[0];
1121 my $a2 = $col_aligns[1];
1122 my $a3 = $col_aligns[2];
1123 my $a4 = $col_aligns[3];
1124 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1125 return '<table border align="center" style="border-collapse: collapse">'
Fred Drakef74e5b71999-04-28 14:58:49 +00001126 . "\n <thead>"
1127 . "\n <tr$TABLE_HEADER_BGCOLOR>"
Fred Drakee15956b2000-04-03 04:51:13 +00001128 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1129 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1130 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1131 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001132 . "\n </thead>"
Fred Drakee15956b2000-04-03 04:51:13 +00001133 . "\n <tbody valign='baseline'>"
Fred Drake62e43691998-08-10 19:40:44 +00001134 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001135 . "\n </tbody>"
1136 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001137}
1138
Fred Drakea0f4c941998-07-24 22:16:04 +00001139sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001140 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001141 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001142 my $c1 = next_argument();
1143 my $c2 = next_argument();
1144 my $c3 = next_argument();
1145 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001146 s/[\s\n]+//;
Fred Drakee15956b2000-04-03 04:51:13 +00001147 my($font,$sfont,$efont) = get_table_col1_fonts();
1148 $c4 = '&nbsp;' if ($c4 eq '');
1149 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1150 my $padding = '';
1151 if ($c1align =~ /align="right"/) {
1152 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001153 }
Fred Drakee15956b2000-04-03 04:51:13 +00001154 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001155 . " $c2align$c2</td>\n"
1156 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001157 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001158 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001159}
1160
Fred Drake3be20742000-08-31 06:22:54 +00001161
1162# These can be used to control the title page appearance;
1163# they need a little bit of documentation.
1164#
1165# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1166# $ICONSERVER directory, or include path information (other than "./"). The
1167# default image type will be assumed if an extension is not provided.
1168#
1169# If specified, the "title page" will contain two colums: one containing the
1170# title/author/etc., and the other containing the graphic. Use the other
1171# four variables listed here to control specific details of the layout; all
1172# are optional.
1173#
1174# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1175# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1176# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1177# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1178# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1179
1180sub make_my_titlepage() {
1181 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001182 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001183 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001184 }
1185 else {
1186 write_warnings("\nThis document has no title.");
1187 }
Fred Drake6659c301998-03-03 22:02:19 +00001188 if ($t_author) {
1189 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001190 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001191 $href = make_named_href('author', $href,
1192 "<b><font size='+2'>$t_author</font></b>");
Fred Drakec9a44381998-03-17 06:29:13 +00001193 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001194 }
1195 else {
Fred Drake2d1f81e1999-02-09 16:03:31 +00001196 $the_title .= ("\n<p><b><font size='+2'>$t_author</font></b></p>");
Fred Drake6659c301998-03-03 22:02:19 +00001197 }
Fred Drake3be20742000-08-31 06:22:54 +00001198 }
1199 else {
1200 write_warnings("\nThere is no author for this document.");
1201 }
Fred Drake6659c301998-03-03 22:02:19 +00001202 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001203 $the_title .= "\n<p>$t_institute</p>";
1204 }
Fred Draked07868a1998-05-14 21:00:28 +00001205 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001206 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1207 }
Fred Drake6659c301998-03-03 22:02:19 +00001208 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001209 $the_title .= "\n<p><i>$t_affil</i></p>";
1210 }
Fred Drake6659c301998-03-03 22:02:19 +00001211 if ($t_date) {
Fred Drakec9a44381998-03-17 06:29:13 +00001212 $the_title .= "\n<p><strong>$t_date</strong>";
Fred Drake6659c301998-03-03 22:02:19 +00001213 if ($PYTHON_VERSION) {
Fred Drake3be20742000-08-31 06:22:54 +00001214 $the_title .= "<br><strong>Release $PYTHON_VERSION</strong>";
1215 }
Fred Drake6659c301998-03-03 22:02:19 +00001216 $the_title .= "</p>"
1217 }
1218 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001219 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001220 }
1221 else {
1222 $the_title .= "\n<p>";
1223 }
Fred Drake6659c301998-03-03 22:02:19 +00001224 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001225 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001226 }
1227 return $the_title;
1228}
1229
1230use File::Basename;
1231
1232sub make_my_titlegraphic() {
1233 my($myname, $mydir, $myext) = fileparse($TITLE_PAGE_GRAPHIC, '\..*');
1234 chop $mydir;
1235 if ($mydir eq '.') {
1236 $mydir = $ICONSERVER;
1237 }
1238 $myext = ".$IMAGE_TYPE"
1239 unless $myext;
1240 my $graphic = "<td class=\"titlegraphic\"";
1241 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1242 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1243 $graphic .= "><img";
1244 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1245 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1246 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1247 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
1248 $graphic .= "\n src=\"$mydir/$myname$myext\"></td>\n";
1249 return $graphic;
1250}
1251
1252sub do_cmd_maketitle {
1253 local($_) = @_;
1254 my $the_title = "\n<div class=\"titlepage\">";
1255 if ($TITLE_PAGE_GRAPHIC) {
1256 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1257 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1258 . "<tr align=\"right\">\n<td>"
1259 . make_my_titlepage()
1260 . "</td>\n"
1261 . make_my_titlegraphic()
1262 . "</tr>\n</table>");
1263 }
1264 else {
1265 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1266 . make_my_titlegraphic()
1267 . "<td>"
1268 . make_my_titlepage()
1269 . "</td></tr>\n</table>");
1270 }
1271 }
1272 else {
1273 $the_title .= ("\n<center>"
1274 . make_my_titlepage()
1275 . "\n</center>");
1276 }
1277 $the_title .= "\n</div>";
1278 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001279 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001280 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001281}
1282
1283
Fred Drake885215c1998-05-20 21:32:09 +00001284#
Fred Drakea0f4c941998-07-24 22:16:04 +00001285# Module synopsis support
1286#
1287
1288require SynopsisTable;
1289
Fred Drakef7685d71998-07-25 03:31:46 +00001290sub get_chapter_id(){
1291 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001292 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1293 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001294 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001295}
1296
Fred Drake643d76d2000-09-09 06:07:37 +00001297# 'chapter' => 'SynopsisTable instance'
1298%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001299
1300sub get_synopsis_table($){
1301 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001302 my $key;
1303 foreach $key (keys %ModuleSynopses) {
1304 if ($key eq $chap) {
1305 return $ModuleSynopses{$chap};
1306 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001307 }
Fred Drake643d76d2000-09-09 06:07:37 +00001308 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001309 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001310 return $st;
1311}
1312
Fred Drake62e43691998-08-10 19:40:44 +00001313sub do_cmd_moduleauthor{
1314 local($_) = @_;
1315 next_argument();
1316 next_argument();
1317 return $_;
1318}
1319
1320sub do_cmd_sectionauthor{
1321 local($_) = @_;
1322 next_argument();
1323 next_argument();
1324 return $_;
1325}
1326
Fred Drakea0f4c941998-07-24 22:16:04 +00001327sub do_cmd_declaremodule{
1328 local($_) = @_;
1329 my $key = next_optional_argument();
1330 my $type = next_argument();
1331 my $name = next_argument();
1332 my $st = get_synopsis_table(get_chapter_id());
1333 #
1334 $key = $name unless $key;
1335 $type = 'built-in' if $type eq 'builtin';
1336 $st->declare($name, $key, $type);
1337 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001338 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001339}
1340
1341sub do_cmd_modulesynopsis{
1342 local($_) = @_;
1343 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001344 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001345 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001346}
1347
1348sub do_cmd_localmoduletable{
1349 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001350 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001351 my $st = get_synopsis_table($chap);
1352 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001353 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001354}
1355
1356sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001357 my $key;
1358 my $st, $file;
1359 foreach $key (keys %ModuleSynopses) {
1360 $st = $ModuleSynopses{$key};
1361 $file = $st->get_file();
1362 if ($file) {
1363 process_localmoduletables_in_file($file);
1364 }
1365 else {
1366 print "\nsynopsis table $key has no file association";
1367 }
1368 }
1369}
1370
1371sub process_localmoduletables_in_file{
1372 my $file = @_[0];
1373 open(MYFILE, "<$file");
1374 local($_);
1375 sysread(MYFILE, $_, 1024*1024);
1376 close(MYFILE);
1377 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001378 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001379 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001380 my $chap = $1;
1381 my $st = get_synopsis_table($chap);
1382 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001383 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001384 }
Fred Drake643d76d2000-09-09 06:07:37 +00001385 open(MYFILE,">$file");
1386 print MYFILE $_;
1387 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001388}
Fred Drake557460c1999-03-02 16:05:35 +00001389sub process_python_state{
1390 process_all_localmoduletables();
Fred Drake557460c1999-03-02 16:05:35 +00001391}
Fred Drakea0f4c941998-07-24 22:16:04 +00001392
1393
1394#
1395# "See also:" -- references placed at the end of a \section
1396#
1397
1398sub do_env_seealso{
Fred Drakee15956b2000-04-03 04:51:13 +00001399 return "<div class='seealso'>\n "
1400 . "<p class='heading'><b>See Also:</b></p>\n"
Fred Drake90fdda51999-02-16 20:27:42 +00001401 . @_[0]
1402 . '</div>';
Fred Drakea0f4c941998-07-24 22:16:04 +00001403}
1404
1405sub do_cmd_seemodule{
1406 # Insert the right magic to jump to the module definition. This should
1407 # work most of the time, at least for repeat builds....
1408 local($_) = @_;
1409 my $key = next_optional_argument();
1410 my $module = next_argument();
1411 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001412 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001413 $key = $module
1414 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001415 if ($text =~ /\.$/) {
1416 $period = '';
1417 }
Fred Drakee15956b2000-04-03 04:51:13 +00001418 return '<dl compact class="seemodule">'
1419 . "\n <dt>Module <b><tt class='module'><a href='module-$key.html'>"
Fred Drake84bd6f31999-05-11 15:42:51 +00001420 . "$module</a></tt>:</b>"
1421 . "\n <dd>$text$period\n </dl>"
Fred Drake90fdda51999-02-16 20:27:42 +00001422 . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001423}
1424
Fred Drake643d76d2000-09-09 06:07:37 +00001425sub handle_rfclike_reference{
1426 local($_, $what) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001427 my $rfcnum = next_argument();
1428 my $title = next_argument();
1429 my $text = next_argument();
1430 my $url = get_rfc_url($rfcnum);
1431 return '<dl compact class="seerfc">'
1432 . "\n <dt><a href=\"$url\""
1433 . "\n title=\"$title\""
Fred Drake643d76d2000-09-09 06:07:37 +00001434 . "\n >$what $rfcnum, <em>$title</em></a>:"
Fred Drake37cc0c02000-04-26 18:05:24 +00001435 . "\n <dd>$text\n </dl>"
1436 . $_;
1437}
1438
Fred Drake643d76d2000-09-09 06:07:37 +00001439sub do_cmd_seepep{
1440 return handle_rfclike_reference(@_[0], "PEP");
1441}
1442
1443sub do_cmd_seerfc{
1444 return handle_rfclike_reference(@_[0], "RFC");
1445}
1446
Fred Drake48449982000-09-12 17:52:33 +00001447sub do_cmd_seetitle{
1448 local($_) = @_;
1449 my $url = next_optional_argument();
1450 my $title = next_argument();
1451 my $text = next_argument();
1452 if ($url) {
1453 return '<dl compact class="seetitle">'
1454 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
1455 . "\n class=\"url\">$title</a></em>"
1456 . "\n <dd>$text\n </dl>"
1457 . $_;
1458 }
1459 return '<dl compact class="seetitle">'
1460 . "\n <dt><em class=\"citetitle\""
1461 . "\n >$title</em>"
1462 . "\n <dd>$text\n </dl>"
1463 . $_;
1464}
1465
Fred Drakeef4d1112000-05-09 16:17:51 +00001466sub do_cmd_seeurl{
1467 local($_) = @_;
1468 my $url = next_argument();
1469 my $text = next_argument();
1470 return '<dl compact class="seeurl">'
1471 . "\n <dt><a href=\"$url\""
1472 . "\n class=\"url\">$url</a>"
1473 . "\n <dd>$text\n </dl>"
1474 . $_;
1475}
1476
Fred Drakea0f4c941998-07-24 22:16:04 +00001477sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001478 local($_) = @_;
1479 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001480 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001481}
1482
1483
1484#
Fred Drake885215c1998-05-20 21:32:09 +00001485# Definition list support.
1486#
1487
1488sub do_env_definitions{
Fred Drake37cc0c02000-04-26 18:05:24 +00001489 return "<dl class='definitions'>" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001490}
1491
1492sub do_cmd_term{
1493 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001494 my $term = next_argument();
1495 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001496 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001497 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001498}
1499
1500
Fred Drake2ff880e1999-02-05 18:31:29 +00001501process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
1502code # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001503declaremodule # [] # {} # {}
1504memberline # [] # {}
1505methodline # [] # {} # {}
1506modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001507platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001508samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001509setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001510withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001511_RAW_ARG_DEFERRED_CMDS_
1512
1513
Fred Drake6659c301998-03-03 22:02:19 +000015141; # This must be the last line