blob: 036b2ee63a82ce9d17aa07121224efa9f79bbfdc [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
2#
3# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
4#
5# Extension to LaTeX2HTML for documents using myformat.sty.
6# Subroutines of the form do_cmd_<name> here define translations
7# for LaTeX commands \<name> defined in the corresponding .sty file.
8
9package main;
10
Fred Drake7a40c072000-10-02 14:43:38 +000011use File::Basename;
12
Fred Drake6659c301998-03-03 22:02:19 +000013
Fred Drake08932051998-04-17 02:15:42 +000014sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000015 my $param;
16 $param = missing_braces()
17 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
18 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000019 return $param;
Fred Drake08932051998-04-17 02:15:42 +000020}
21
22sub next_optional_argument{
23 my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000024 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000025 return $param;
Fred Drake08932051998-04-17 02:15:42 +000026}
27
Fred Drake7a40c072000-10-02 14:43:38 +000028sub make_icon_filename($){
29 my($myname, $mydir, $myext) = fileparse(@_[0], '\..*');
30 chop $mydir;
31 if ($mydir eq '.') {
32 $mydir = $ICONSERVER;
33 }
34 $myext = ".$IMAGE_TYPE"
35 unless $myext;
36 return "$mydir$dd$myname$myext";
37}
38
Fred Drake7a40c072000-10-02 14:43:38 +000039sub get_link_icon($){
40 my $url = @_[0];
41 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
42 # absolute URL; assume it points off-site
43 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
Fred Drakef1927a62001-06-20 21:29:30 +000044 return (" <img src=\"$icon\"\n"
45 . ' border="0" class="offsitelink"'
Fred Drake5f84c9b2000-10-03 06:05:25 +000046 . ($OFF_SITE_LINK_ICON_HEIGHT
Fred Drakef1927a62001-06-20 21:29:30 +000047 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000048 : '')
49 . ($OFF_SITE_LINK_ICON_WIDTH
Fred Drakef1927a62001-06-20 21:29:30 +000050 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000051 : '')
Fred Drakef1927a62001-06-20 21:29:30 +000052 . " alt=\"[off-site link]\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +000053 . " >");
54 }
55 return '';
56}
Fred Drakee16f6791998-05-15 04:28:37 +000057
58# This is a fairly simple hack; it supports \let when it is used to create
59# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000060# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000061#
62sub do_cmd_let{
63 local($_) = @_;
64 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000065 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000066 if ($matched) {
67 my($new, $old) = ($1, $3);
68 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
69 print "\ndefining handler for \\$new using \\$old\n";
70 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000071 else {
72 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
73 if ($matched) {
74 my($new, $char) = ($1, $3);
75 eval "sub do_cmd_$new { \"\\$char\" . \@_[0]; }";
76 print "\ndefining handler for \\$new to insert '$char'\n";
77 }
78 else {
79 write_warnings("Could not interpret \\let construct...");
80 }
81 }
Fred Drake62e43691998-08-10 19:40:44 +000082 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000083}
84
85
Fred Drakec3fd45f2000-06-15 22:41:48 +000086# the older version of LaTeX2HTML we use doesn't support this, but we use it:
87
88sub do_cmd_textasciitilde{ '~' . @_[0]; }
Fred Drake056a71d2001-04-21 05:48:07 +000089sub do_cmd_textasciicircum{ '^' . @_[0]; }
Fred Drake6fe46602001-06-23 03:13:30 +000090sub do_cmd_textbar{ '|' . @_[0]; }
91sub do_cmd_infinity{ '&infin;' . @_[0]; }
92sub do_cmd_plusminus{ '&plusmn;' . @_[0]; }
Fred Drake77602f22001-07-06 22:43:02 +000093sub do_cmd_menuselection{ @_[0]; }
94sub do_cmd_sub{ ' > ' . @_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +000095
96
Fred Drake6659c301998-03-03 22:02:19 +000097# words typeset in a special way (not in HTML though)
98
99sub do_cmd_ABC{ 'ABC' . @_[0]; }
100sub do_cmd_UNIX{ 'Unix'. @_[0]; }
101sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
102sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
103sub do_cmd_C{ 'C' . @_[0]; }
104sub do_cmd_Cpp{ 'C++' . @_[0]; }
105sub do_cmd_EOF{ 'EOF' . @_[0]; }
Fred Drakee15956b2000-04-03 04:51:13 +0000106sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000107
108sub do_cmd_e{ '&#92;' . @_[0]; }
109
Fred Draked07868a1998-05-14 21:00:28 +0000110$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000111$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000112$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000113$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000114
Fred Draked04592a2000-10-25 16:15:13 +0000115sub do_cmd_version{ $PACKAGE_VERSION . @_[0]; }
Fred Drake3cdb89d2000-09-14 20:17:23 +0000116sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000117sub do_cmd_release{
118 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000119 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000120 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000121}
122
Fred Drakef1927a62001-06-20 21:29:30 +0000123sub do_cmd_setreleaseinfo{
124 local($_) = @_;
125 $RELEASE_INFO = next_argument();
126 return $_;
127}
128
Fred Drake3cdb89d2000-09-14 20:17:23 +0000129sub do_cmd_setshortversion{
130 local($_) = @_;
131 $SHORT_VERSION = next_argument();
132 return $_;
133}
134
Fred Drake6659c301998-03-03 22:02:19 +0000135sub do_cmd_authoraddress{
136 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000137 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000138 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000139}
140
Fred Drakee16f6791998-05-15 04:28:37 +0000141#sub do_cmd_developer{ do_cmd_author(@_[0]); }
142#sub do_cmd_developers{ do_cmd_author(@_[0]); }
143#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000144
Fred Drake6659c301998-03-03 22:02:19 +0000145sub do_cmd_hackscore{
146 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000147 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000148 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000149}
150
Fred Drake08932051998-04-17 02:15:42 +0000151sub use_wrappers{
152 local($_,$before,$after) = @_;
153 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000154 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000155}
156
Fred Drake3cdb89d2000-09-14 20:17:23 +0000157$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000158sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000159 if ($IN_DESC_HANDLER) {
160 return use_wrappers(@_[0], "</var><big>\[</big><var>",
161 "</var><big>\]</big><var>");
162 }
163 else {
164 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
165 }
Fred Drake6659c301998-03-03 22:02:19 +0000166}
167
Fred Drakec9a44381998-03-17 06:29:13 +0000168# Logical formatting (some based on texinfo), needs to be converted to
169# minimalist HTML. The "minimalist" is primarily to reduce the size of
170# output files for users that read them over the network rather than
171# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000172
Fred Drake2cafcbb1999-03-25 16:57:04 +0000173# \file and \samp are at the end of this file since they screw up fontlock.
174
Fred Drake2ff880e1999-02-05 18:31:29 +0000175sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000176sub do_cmd_makevar{
177 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000178sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000179 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000180sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000181 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000182sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000183 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000185 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000186sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000187 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000188sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000189 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000191 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000193 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000194sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000195 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000197 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000199 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000201 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000203 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000205 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000207 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000208sub do_cmd_programopt{
209 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000210sub do_cmd_longprogramopt{
211 # note that the --- will be later converted to -- by LaTeX2HTML
212 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000213sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000214 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000215sub do_cmd_mailheader{
Fred Drake479384e2001-09-26 18:46:36 +0000216 return use_wrappers(@_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000218 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_var{
220 return use_wrappers(@_[0], "<var>", "</var>"); }
221sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000222 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000224 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000226 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000227sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000228 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000229sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000230 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000231sub do_cmd_kbd{
232 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
233sub do_cmd_strong{
234 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000235sub do_cmd_textbf{
236 return use_wrappers(@_[0], '<b>', '</b>'); }
237sub do_cmd_textit{
238 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake92350b32001-10-09 18:01:23 +0000239sub do_cmd_note{
240 return use_wrappers(
241 @_[0],
242 "<span class=\"note\"><b class=\"label\">Note:</b>\n",
243 '</span>'); }
244sub do_cmd_warning{
245 return use_wrappers(
246 @_[0],
247 "<span class=\"warning\"><b class=\"label\">Warning:</b>\n",
248 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000249
Fred Drake3d5a04a2000-08-03 17:25:44 +0000250sub do_cmd_moreargs{
251 return '...' . @_[0]; }
252sub do_cmd_unspecified{
253 return '...' . @_[0]; }
254
Fred Drakec9a44381998-03-17 06:29:13 +0000255
Fred Drake25817041999-01-13 17:06:34 +0000256sub do_cmd_refmodule{
257 # Insert the right magic to jump to the module definition.
258 local($_) = @_;
259 my $key = next_optional_argument();
260 my $module = next_argument();
261 $key = $module
262 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000263 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000264 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000265}
266
Fred Drake1a7af391998-04-01 22:44:56 +0000267sub do_cmd_newsgroup{
268 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000269 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000270 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000271 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
272 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000273 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000274}
Fred Drakefc16e781998-03-12 21:03:26 +0000275
276sub do_cmd_envvar{
277 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000278 my $envvar = next_argument();
279 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000280 # The <tt> here is really to keep buildindex.py from making
281 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000282 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000283 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000284 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000285 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000286 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000287}
288
Fred Drake6659c301998-03-03 22:02:19 +0000289sub do_cmd_url{
290 # use the URL as both text and hyperlink
291 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000292 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000293 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000294 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000295 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000296}
297
298sub do_cmd_manpage{
299 # two parameters: \manpage{name}{section}
300 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000301 my $page = next_argument();
302 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000303 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000304}
305
Fred Drakef1927a62001-06-20 21:29:30 +0000306$PEP_FORMAT = "http://python.sourceforge.net/peps/pep-%04d.html";
307#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
308$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000309
310sub get_rfc_url($$){
311 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000312 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000313}
314
315sub do_cmd_pep{
316 local($_) = @_;
317 my $rfcnumber = next_argument();
318 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000319 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000320 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000321 # Save the reference
322 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
323 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000324 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
325 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000326}
327
Fred Drake6659c301998-03-03 22:02:19 +0000328sub do_cmd_rfc{
329 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000330 my $rfcnumber = next_argument();
331 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000332 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000333 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000334 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000335 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000336 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000337 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
338 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000339}
340
Fred Drake77602f22001-07-06 22:43:02 +0000341sub do_cmd_ulink{
342 local($_) = @_;
343 my $text = next_argument();
344 my $url = next_argument();
345 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
346}
347
Fred Drakec9f5fe01999-11-09 16:59:42 +0000348sub do_cmd_citetitle{
349 local($_) = @_;
350 my $url = next_optional_argument();
351 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000352 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000353 my $repl = '';
354 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000355 $repl = ("<em class=\"citetitle\"><a\n"
356 . " href=\"$url\"\n"
357 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000358 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000359 }
360 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000361 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000362 }
363 return $repl . $_;
364}
365
Fred Drake6659c301998-03-03 22:02:19 +0000366sub do_cmd_deprecated{
367 # two parameters: \deprecated{version}{whattodo}
368 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000369 my $release = next_argument();
370 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000371 return ('<div class="versionnote">'
372 . "<b>Deprecated since release $release.</b>"
373 . "\n$reason</div><p>"
374 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000375}
376
Fred Drakec2b29d02001-04-18 03:11:04 +0000377sub versionnote{
378 # one or two parameters: \versionnote[explanation]{version}
379 my $type = @_[0];
380 local $_ = @_[1];
381 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000382 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000383 my $text = "$type in version $release.";
384 if ($explanation) {
385 $text = "$type in version $release:\n$explanation.";
386 }
Fred Drakef1927a62001-06-20 21:29:30 +0000387 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000388}
389
390sub do_cmd_versionadded{
391 return versionnote('New', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000392}
393
394sub do_cmd_versionchanged{
Fred Drakec2b29d02001-04-18 03:11:04 +0000395 return versionnote('Changed', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000396}
397
Fred Drake557460c1999-03-02 16:05:35 +0000398#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000399# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000400#
401sub do_cmd_platform{
402 local($_) = @_;
403 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000404 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000405 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000406 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000407 return "\n<p class=\"availability\">Availability: <span"
408 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000409}
410
Fred Drake557460c1999-03-02 16:05:35 +0000411$IGNORE_PLATFORM_ANNOTATION = '';
412sub do_cmd_ignorePlatformAnnotation{
413 local($_) = @_;
414 $IGNORE_PLATFORM_ANNOTATION = next_argument();
415 return $_;
416}
417
Fred Drake6659c301998-03-03 22:02:19 +0000418
419# index commands
420
421$INDEX_SUBITEM = "";
422
423sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000424 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000425}
426
427sub do_cmd_setindexsubitem{
428 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000429 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000430 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000431}
432
Fred Drakefc16e781998-03-12 21:03:26 +0000433sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000434 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000435 # do things in the right order, but we need to at least strip this stuff
436 # out, and leave anything that the second argument expanded out to.
437 #
438 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000439 my $oldsubitem = $INDEX_SUBITEM;
440 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000441 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000442 my $br_id = ++$globals{'max_id'};
443 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000444 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000445 return
446 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000447 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000448 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000449}
450
Fred Drake08932051998-04-17 02:15:42 +0000451# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000452# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
453# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000454#
Fred Drake62e43691998-08-10 19:40:44 +0000455sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000456
Fred Drake42b31a51998-03-27 05:16:10 +0000457# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000458#
Fred Drake08932051998-04-17 02:15:42 +0000459open(IDXFILE, '>index.dat') || die "\n$!\n";
460open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000461print INTLABELS "%internal_labels = ();\n";
462print INTLABELS "1; # hack in case there are no entries\n\n";
463
464# Using \0 for this is bad because we can't use common tools to work with the
465# resulting files. Things like grep can be useful with this stuff!
466#
467$IDXFILE_FIELD_SEP = "\1";
468
Fred Drakeccc62721999-01-05 22:16:29 +0000469sub write_idxfile{
470 my ($ahref, $str) = @_;
471 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000472}
473
Fred Drake42b31a51998-03-27 05:16:10 +0000474
475sub gen_link{
476 my($node,$target) = @_;
477 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000478 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000479}
480
Fred Drake42b31a51998-03-27 05:16:10 +0000481sub add_index_entry{
482 # add an entry to the index structures; ignore the return value
483 my($str,$ahref) = @_;
484 $str = gen_index_id($str, '');
485 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000486 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000487}
488
Fred Drakeccc62721999-01-05 22:16:29 +0000489sub new_link_info{
490 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000491 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000492 my $ahref = gen_link($CURRENT_FILE, $name);
493 return ($name, $aname, $ahref);
494}
495
Fred Drakeab032151999-05-13 18:36:54 +0000496$IndexMacroPattern = '';
497sub define_indexing_macro{
498 my $count = @_;
499 my $i = 0;
500 for (; $i < $count; ++$i) {
501 my $name = @_[$i];
502 my $cmd = "idx_cmd_$name";
503 die "\nNo function $cmd() defined!\n"
504 if (!defined &$cmd);
505 eval ("sub do_cmd_$name { return process_index_macros("
506 . "\@_[0], '$name'); }");
507 if (length($IndexMacroPattern) == 0) {
508 $IndexMacroPattern = "$name";
509 }
510 else {
511 $IndexMacroPattern .= "|$name";
512 }
513 }
514}
515
516$DEBUG_INDEXING = 0;
517sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000518 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000519 my $cmdname = @_[1]; # This is what triggered us in the first place;
520 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000521 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000522 my $cmd = "idx_cmd_$cmdname";
523 print "\nIndexing: \\$cmdname"
524 if $DEBUG_INDEXING;
525 &$cmd($ahref); # modifies $_ and adds index entries
526 while (/^[\s\n]*\\($IndexMacroPattern)</) {
527 $cmdname = "$1";
528 print " \\$cmdname"
529 if $DEBUG_INDEXING;
530 $cmd = "idx_cmd_$cmdname";
531 if (!defined &$cmd) {
532 last;
533 }
534 else {
535 s/^[\s\n]*\\$cmdname//;
536 &$cmd($ahref);
537 }
538 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000539 if (/^[ \t\r\n]/) {
540 $_ = substr($_, 1);
541 }
Fred Drake62e43691998-08-10 19:40:44 +0000542 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000543}
544
Fred Drakeab032151999-05-13 18:36:54 +0000545define_indexing_macro('index');
546sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000547 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000548 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000549}
550
Fred Drakeab032151999-05-13 18:36:54 +0000551define_indexing_macro('kwindex');
552sub idx_cmd_kwindex{
553 my $str = next_argument();
554 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
555 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
556}
557
558define_indexing_macro('indexii');
559sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000560 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000561 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000562 add_index_entry("$str1!$str2", @_[0]);
563 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000564}
565
Fred Drakeab032151999-05-13 18:36:54 +0000566define_indexing_macro('indexiii');
567sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000568 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000569 my $str2 = next_argument();
570 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000571 add_index_entry("$str1!$str2 $str3", @_[0]);
572 add_index_entry("$str2!$str3, $str1", @_[0]);
573 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000574}
575
Fred Drakeab032151999-05-13 18:36:54 +0000576define_indexing_macro('indexiv');
577sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000578 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000579 my $str2 = next_argument();
580 my $str3 = next_argument();
581 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000582 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
583 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
584 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
585 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000586}
587
Fred Drakeab032151999-05-13 18:36:54 +0000588define_indexing_macro('ttindex');
589sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000590 my $str = next_argument();
591 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000592 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000593}
Fred Drake6659c301998-03-03 22:02:19 +0000594
595sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000596 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000597 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000598 add_index_entry("$str $word", $ahref);
599 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000600}
601
Fred Drakeab032151999-05-13 18:36:54 +0000602define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
603sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
604sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
605sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
606sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000607
Fred Drakeab032151999-05-13 18:36:54 +0000608define_indexing_macro('bifuncindex');
609sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000610 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000611 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drakee15956b2000-04-03 04:51:13 +0000612 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000613}
614
615
Fred Drake6659c301998-03-03 22:02:19 +0000616sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000617 my($str,$define) = @_;
618 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000619 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000620 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
621 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000622 $str = gen_index_id($str, $define);
623 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000624 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000625
Fred Drakec9a44381998-03-17 06:29:13 +0000626 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000627 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000628 $str =~ /(<tt.*<\/tt>)/;
629 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000630 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000631 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000632 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000633}
634
Fred Drake557460c1999-03-02 16:05:35 +0000635
Fred Drakec9a44381998-03-17 06:29:13 +0000636$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000637$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000638
Fred Drakea0f4c941998-07-24 22:16:04 +0000639sub define_module{
640 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000641 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000642 if ($word ne "built-in" && $word ne "extension"
643 && $word ne "standard" && $word ne "") {
644 write_warnings("Bad module type '$word'"
645 . " for \\declaremodule (module $name)");
646 $word = "";
647 }
Fred Drake6659c301998-03-03 22:02:19 +0000648 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000649 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000650 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000651 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000652 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000653 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000654}
655
656sub my_module_index_helper{
657 local($word, $_) = @_;
658 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000659 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000660}
661
Fred Drake62e43691998-08-10 19:40:44 +0000662sub do_cmd_modindex{ return my_module_index_helper('', @_); }
663sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
664sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
665sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000666
Fred Drakeab032151999-05-13 18:36:54 +0000667sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000668 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000669 my $str = next_argument();
670 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000671 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000672 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
673 # just inline it all here
674 $str = gen_index_id($str, 'REF');
675 $index{$str} .= $ahref;
676 write_idxfile($ahref, $str);
677}
678
Fred Drake6659c301998-03-03 22:02:19 +0000679# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000680define_indexing_macro('refmodindex', 'refbimodindex',
681 'refexmodindex', 'refstmodindex');
682sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
683sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
684sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
685sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000686
Fred Drake62e43691998-08-10 19:40:44 +0000687sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000688
689sub init_myformat{
Fred Drakeafc7ce12001-01-22 17:33:24 +0000690 $anchor_invisible_mark = '&nbsp;';
691 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000692 $anchor_mark = '';
693 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000694}
Fred Drake42b31a51998-03-27 05:16:10 +0000695init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000696
Fred Drakeab032151999-05-13 18:36:54 +0000697# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000698# instead of the dummy filler.
699#
700sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000701 my($str) = @_;
702 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000703 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000704 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000705}
706
Fred Drake77602f22001-07-06 22:43:02 +0000707
708%TokenToTargetMapping = ();
709%DefinedGrammars = ();
710%BackpatchGrammarFiles = ();
711
712sub do_cmd_token{
713 local($_) = @_;
714 my $token = next_argument();
715 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
716 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
717 # recursive definition or display-only productionlist
718 return "$token";
719 }
720 if ($target eq '') {
721 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
722 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
723 print "Adding '$CURRENT_FILE' to back-patch list.\n";
724 }
725 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
726 }
727 return "<a href=\"$target\">$token</a>" . $_;
728}
729
Fred Drake16bb4192001-08-20 21:36:38 +0000730sub do_cmd_grammartoken{
731 return do_cmd_token(@_);
732}
733
Fred Drake77602f22001-07-06 22:43:02 +0000734sub do_env_productionlist{
735 local($_) = @_;
736 my $lang = next_optional_argument();
737 my $filename = "grammar-$lang.txt";
738 if ($lang eq '') {
739 $filename = 'grammar.txt';
740 }
741 local($CURRENT_GRAMMAR) = $lang;
742 $DefinedGrammars{$lang} .= $_;
743 return ("<dl><dd class=\"grammar\">\n"
744 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000745 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000746 . translate_commands(translate_environments($_))
747 . "</table>\n"
748 . "</div>\n"
749 . (($lang eq '*')
750 ? ''
751 : ("<a class=\"grammar-footer\"\n"
752 . " href=\"$filename\" type=\"text/plain\"\n"
753 . " >Download entire grammar as text.</a>\n"))
754 . "</dd></dl>");
755}
756
757sub do_cmd_production{
758 local($_) = @_;
759 my $token = next_argument();
760 my $defn = next_argument();
761 my $lang = $CURRENT_GRAMMAR;
762 local($CURRENT_TOKEN) = $token;
763 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000764 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000765 . " <td><code>$token</code></td>\n"
766 . " <td>&nbsp;::=&nbsp;</td>\n"
767 . " <td><code>"
768 . translate_commands($defn)
769 . "</code></td></tr>"
770 . $_);
771 }
772 my $target;
773 if ($lang eq '') {
774 $target = "$CURRENT_FILE\#tok-$token";
775 }
776 else {
777 $target = "$CURRENT_FILE\#tok-$lang-$token";
778 }
779 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000780 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000781 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
782 . " <td>&nbsp;::=&nbsp;</td>\n"
783 . " <td><code>"
784 . translate_commands($defn)
785 . "</code></td></tr>"
786 . $_);
787}
788
789sub process_grammar_files{
790 my $lang;
791 my $filename;
792 local($_);
793 print "process_grammar_files()\n";
794 foreach $lang (keys %DefinedGrammars) {
795 $filename = "grammar-$lang.txt";
796 if ($lang eq '*') {
797 next;
798 }
799 if ($lang eq '') {
800 $filename = 'grammar.txt';
801 }
802 open(GRAMMAR, ">$filename") || die "\n$!\n";
803 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
804 close(GRAMMAR);
805 print "Wrote grammar file $filename\n";
806 }
807 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
808 foreach $filename (keys %BackpatchGrammarFiles) {
809 print "\nBack-patching grammar links in $filename\n";
810 my $buffer;
811 open(GRAMMAR, "<$filename") || die "\n$!\n";
812 # read all of the file into the buffer
813 sysread(GRAMMAR, $buffer, 1024*1024);
814 close(GRAMMAR);
815 while ($buffer =~ /$PATTERN/) {
816 my($lang, $token) = ($1, $2);
817 my $target = $TokenToTargetMapping{"$lang:$token"};
818 my $source = "<pyGrammarToken><$lang><$token>";
819 $buffer =~ s/$source/$target/g;
820 }
821 open(GRAMMAR, ">$filename") || die "\n$!\n";
822 print GRAMMAR $buffer;
823 close(GRAMMAR);
824 }
825}
826
827sub strip_grammar_markup{
828 local($_) = @_;
829 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
830 s/\\token(<<\d+>>)(.+)\1/\2/g;
831 s/\\e([^a-zA-Z])/\\\1/g;
832 s/<<\d+>>//g;
833 s/;SPMgt;/>/g;
834 s/;SPMlt;/</g;
835 s/;SPMquot;/\"/g;
836 return $_;
837}
838
839
Fred Drakee15956b2000-04-03 04:51:13 +0000840$REFCOUNTS_LOADED = 0;
841
842sub load_refcounts{
843 $REFCOUNTS_LOADED = 1;
844
Fred Drakee15956b2000-04-03 04:51:13 +0000845 my $myname, $mydir, $myext;
846 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
847 chop $mydir; # remove trailing '/'
848 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
849 chop $mydir; # remove trailing '/'
850 $mydir = getcwd() . "$dd$mydir"
851 unless $mydir =~ s|^/|/|;
852 local $_;
853 my $filename = "$mydir${dd}api${dd}refcounts.dat";
854 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
855 print "[loading API refcount data]";
856 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000857 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000858 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
859 #print "\n$func($param) --> $count";
860 $REFCOUNTS{"$func:$param"} = $count;
861 }
862 }
863}
864
865sub get_refcount{
866 my ($func, $param) = @_;
867 load_refcounts()
868 unless $REFCOUNTS_LOADED;
869 return $REFCOUNTS{"$func:$param"};
870}
871
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000872
873$TLSTART = '<span class="typelabel">';
874$TLEND = '</span>';
875
Fred Drake6659c301998-03-03 22:02:19 +0000876sub do_env_cfuncdesc{
877 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000878 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000879 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000880 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000881 my $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000882 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000883 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000884 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000885 my $result_rc = get_refcount($function_name, '');
886 my $rcinfo = '';
887 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000888 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000889 }
890 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000891 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000892 }
Fred Drakec2578c52000-04-10 18:26:45 +0000893 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000894 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000895 }
Fred Drakee15956b2000-04-03 04:51:13 +0000896 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000897 $rcinfo = ( "\n<div class=\"refcount-info\">"
898 . "\n <span class=\"label\">Return value:</span>"
899 . "\n <span class=\"value\">$rcinfo.</span>"
900 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000901 }
Fred Drakec612a142001-03-29 18:24:08 +0000902 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000903 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000904 . $_
905 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000906}
907
Fred Drakee15956b2000-04-03 04:51:13 +0000908sub do_env_csimplemacrodesc{
909 local($_) = @_;
910 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000911 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000912 return "<dl><dt><b>$idx</b>\n<dd>"
913 . $_
914 . '</dl>'
915}
916
Fred Drake6659c301998-03-03 22:02:19 +0000917sub do_env_ctypedesc{
918 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000919 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000920 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000921 $index_name = $type_name
922 unless $index_name;
923 my($name,$aname,$ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000924 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
925 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000926 . $_
927 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000928}
929
930sub do_env_cvardesc{
931 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000932 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000933 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000934 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000935 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000936 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000937 return "<dl><dt>$var_type <b>$idx</b>\n"
938 . '<dd>'
939 . $_
940 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000941}
942
Fred Drake3cdb89d2000-09-14 20:17:23 +0000943sub convert_args($){
944 local($IN_DESC_HANDLER) = 1;
945 local($_) = @_;
946 return translate_commands($_);
947}
948
Fred Drake6659c301998-03-03 22:02:19 +0000949sub do_env_funcdesc{
950 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000951 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000952 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000953 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
954 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +0000955 . get_indexsubitem());
956 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000957 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakec612a142001-03-29 18:24:08 +0000958 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000959}
960
961sub do_env_funcdescni{
962 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000963 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000964 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000965 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
Fred Drakec612a142001-03-29 18:24:08 +0000966 . "(<var>$arg_list</var>)\n"
Fred Drake90fdda51999-02-16 20:27:42 +0000967 . '<dd>'
968 . $_
969 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000970}
971
972sub do_cmd_funcline{
973 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000974 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000975 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000976 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000977 my $idx = make_str_index_entry($prefix . get_indexsubitem());
978 $prefix =~ s/\(\)//;
979
Fred Drakec612a142001-03-29 18:24:08 +0000980 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000981}
982
Fred Drake6b3fb781999-07-12 16:50:09 +0000983sub do_cmd_funclineni{
984 local($_) = @_;
985 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000986 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000987 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000988
Fred Drakec612a142001-03-29 18:24:08 +0000989 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +0000990}
991
Fred Drake6659c301998-03-03 22:02:19 +0000992# Change this flag to index the opcode entries. I don't think it's very
993# useful to index them, since they're only presented to describe the dis
994# module.
995#
996$INDEX_OPCODES = 0;
997
998sub do_env_opcodedesc{
999 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001000 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001001 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001002 my $idx;
1003 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001004 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1005 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001006 $idx =~ s/ \(byte code instruction\)//;
1007 }
1008 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001009 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001010 }
1011 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001012 if ($arg_list) {
1013 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1014 }
Fred Drake62e43691998-08-10 19:40:44 +00001015 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001016}
1017
1018sub do_env_datadesc{
1019 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001020 my $dataname = next_argument();
1021 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001022 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001023 return "<dl><dt><b>$idx</b>\n<dd>"
1024 . $_
1025 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001026}
1027
1028sub do_env_datadescni{
1029 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001030 my $idx = next_argument();
1031 if (! $STRING_INDEX_TT) {
1032 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001033 }
Fred Drake62e43691998-08-10 19:40:44 +00001034 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001035}
1036
1037sub do_cmd_dataline{
1038 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001039 my $data_name = next_argument();
1040 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001041 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001042 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001043}
1044
Fred Drakeadb272c2000-04-10 17:47:14 +00001045sub do_cmd_datalineni{
1046 local($_) = @_;
1047 my $data_name = next_argument();
1048 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1049}
1050
Fred Drake42b31a51998-03-27 05:16:10 +00001051sub do_env_excdesc{
1052 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001053 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001054 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001055 return ("<dl><dt><b>${TLSTART}exception$TLEND $idx</b>"
1056 . "\n<dd>"
1057 . $_
1058 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001059}
1060
Fred Drake62e43691998-08-10 19:40:44 +00001061sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001062
1063
Fred Drake643d76d2000-09-09 06:07:37 +00001064sub handle_classlike_descriptor{
1065 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001066 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001067 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001068 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001069 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001070 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001071 return ("<dl><dt><b>$TLSTART$what$TLEND $idx</b>"
1072 . "(<var>$arg_list</var>)\n<dd>"
Fred Drakeab357ec2001-03-02 18:57:05 +00001073 . $_
1074 . '</dl>');
Fred Drakec9a44381998-03-17 06:29:13 +00001075}
1076
Fred Drake643d76d2000-09-09 06:07:37 +00001077sub do_env_classdesc{
1078 return handle_classlike_descriptor(@_[0], "class");
1079}
1080
Fred Drake06a01e82001-05-11 01:00:30 +00001081sub do_env_classdescstar{
1082 local($_) = @_;
1083 $THIS_CLASS = next_argument();
1084 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001085 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001086 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001087 return ("<dl><dt><b>${TLSTART}class$TLEND $idx</b>\n<dd>"
Fred Drake06a01e82001-05-11 01:00:30 +00001088 . $_
1089 . '</dl>');
1090}
1091
Fred Drake643d76d2000-09-09 06:07:37 +00001092sub do_env_excclassdesc{
1093 return handle_classlike_descriptor(@_[0], "exception");
1094}
1095
Fred Drake42b31a51998-03-27 05:16:10 +00001096
1097sub do_env_methoddesc{
1098 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001099 my $class_name = next_optional_argument();
1100 $class_name = $THIS_CLASS
1101 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001102 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001103 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001104 my $extra = '';
1105 if ($class_name) {
1106 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001107 }
Fred Drakef1927a62001-06-20 21:29:30 +00001108 my $idx = make_str_index_entry(
1109 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001110 $idx =~ s/ \(.*\)//;
1111 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001112 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001113}
1114
1115
Fred Drake7d45f6d1999-01-05 14:39:27 +00001116sub do_cmd_methodline{
1117 local($_) = @_;
1118 my $class_name = next_optional_argument();
1119 $class_name = $THIS_CLASS
1120 unless $class_name;
1121 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001122 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001123 my $extra = '';
1124 if ($class_name) {
1125 $extra = " ($class_name method)";
1126 }
Fred Drakef1927a62001-06-20 21:29:30 +00001127 my $idx = make_str_index_entry(
1128 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001129 $idx =~ s/ \(.*\)//;
1130 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001131 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake7d45f6d1999-01-05 14:39:27 +00001132 . $_;
1133}
1134
1135
Fred Draked64a40d1998-09-10 18:59:13 +00001136sub do_cmd_methodlineni{
1137 local($_) = @_;
1138 next_optional_argument();
1139 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001140 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001141 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Draked64a40d1998-09-10 18:59:13 +00001142 . $_;
1143}
1144
Fred Drake42b31a51998-03-27 05:16:10 +00001145sub do_env_methoddescni{
1146 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001147 next_optional_argument();
1148 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001149 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001150 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001151 . $_
1152 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001153}
1154
1155
1156sub do_env_memberdesc{
1157 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001158 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001159 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001160 $class = $THIS_CLASS
1161 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001162 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001163 $extra = " ($class attribute)"
1164 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001165 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001166 $idx =~ s/ \(.*\)//;
1167 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001168 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001169}
1170
1171
Fred Drake5ccf3301998-04-17 20:04:09 +00001172sub do_cmd_memberline{
1173 local($_) = @_;
1174 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001175 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001176 $class = $THIS_CLASS
1177 unless $class;
1178 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001179 $extra = " ($class attribute)"
1180 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001181 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001182 $idx =~ s/ \(.*\)//;
1183 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001184 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001185}
1186
Fred Drakef269e592001-07-17 23:05:57 +00001187
Fred Drake42b31a51998-03-27 05:16:10 +00001188sub do_env_memberdescni{
1189 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001190 next_optional_argument();
1191 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001192 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001193 . $_
1194 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001195}
1196
1197
Fred Drake5ccf3301998-04-17 20:04:09 +00001198sub do_cmd_memberlineni{
1199 local($_) = @_;
1200 next_optional_argument();
1201 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001202 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001203}
1204
Fred Drakef269e592001-07-17 23:05:57 +00001205
1206@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001207
Fred Drakecb199762001-08-16 21:56:24 +00001208%FontConversions = ('cdata' => 'tt class="cdata"',
1209 'character' => 'tt class="character"',
1210 'class' => 'tt class="class"',
1211 'command' => 'code',
1212 'constant' => 'tt class="constant"',
1213 'exception' => 'tt class="exception"',
1214 'file' => 'tt class="file"',
1215 'filenq' => 'tt class="file"',
1216 'kbd' => 'kbd',
1217 'member' => 'tt class="member"',
1218 'programopt' => 'b',
1219 'textrm' => '',
1220 );
1221
Fred Drakef74e5b71999-04-28 14:58:49 +00001222sub fix_font{
1223 # do a little magic on a font name to get the right behavior in the first
1224 # column of the output table
1225 my $font = @_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001226 if (defined $FontConversions{$font}) {
1227 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001228 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001229 return $font;
1230}
1231
Fred Drakee15956b2000-04-03 04:51:13 +00001232sub figure_column_alignment{
1233 my $a = @_[0];
1234 my $mark = substr($a, 0, 1);
1235 my $r = '';
1236 if ($mark eq 'c')
1237 { $r = ' align="center"'; }
1238 elsif ($mark eq 'r')
1239 { $r = ' align="right"'; }
1240 elsif ($mark eq 'l')
1241 { $r = ' align="left"'; }
1242 elsif ($mark eq 'p')
1243 { $r = ' align="left"'; }
1244 return $r;
1245}
1246
Fred Drake6659c301998-03-03 22:02:19 +00001247sub setup_column_alignments{
1248 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001249 my($s1,$s2,$s3,$s4,$a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001250 my $a1 = figure_column_alignment($s1);
1251 my $a2 = figure_column_alignment($s2);
1252 my $a3 = figure_column_alignment($s3);
1253 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001254 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001255 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1256 $col_aligns[1] = "<td$a2>";
1257 $col_aligns[2] = "<td$a3>";
1258 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001259 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001260 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001261 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001262}
1263
1264sub get_table_col1_fonts{
1265 my $font = $globals{'lineifont'};
1266 my ($sfont,$efont) = ('', '');
1267 if ($font) {
1268 $sfont = "<$font>";
1269 $efont = "</$font>";
1270 $efont =~ s/ .*>/>/;
1271 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001272 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001273}
1274
1275sub do_env_tableii{
1276 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001277 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001278 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001279 my $h1 = next_argument();
1280 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001281 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001282 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001283 my $a1 = $col_aligns[0];
1284 my $a2 = $col_aligns[1];
1285 s/\\lineii</\\lineii[$a1|$a2]</g;
1286 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001287 . "\n <thead>"
1288 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001289 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1290 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001291 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001292 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001293 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001294 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001295 . "\n </tbody>"
1296 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001297}
1298
Fred Drakeda72b932000-09-21 15:58:02 +00001299sub do_env_longtableii{
1300 return do_env_tableii(@_);
1301}
1302
Fred Drake6659c301998-03-03 22:02:19 +00001303sub do_cmd_lineii{
1304 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001305 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001306 my $c1 = next_argument();
1307 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001308 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001309 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001310 $c2 = '&nbsp;' if ($c2 eq '');
1311 my($c1align,$c2align) = split('\|', $aligns);
1312 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001313 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001314 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001315 }
Fred Drakee15956b2000-04-03 04:51:13 +00001316 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1317 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001318 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001319}
1320
1321sub do_env_tableiii{
1322 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001323 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001324 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001325 my $h1 = next_argument();
1326 my $h2 = next_argument();
1327 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001328 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001329 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001330 my $a1 = $col_aligns[0];
1331 my $a2 = $col_aligns[1];
1332 my $a3 = $col_aligns[2];
1333 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1334 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001335 . "\n <thead>"
1336 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001337 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1338 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1339 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001340 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001341 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001342 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001343 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001344 . "\n </tbody>"
1345 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001346}
1347
Fred Drakeda72b932000-09-21 15:58:02 +00001348sub do_env_longtableiii{
1349 return do_env_tableiii(@_);
1350}
1351
Fred Drake6659c301998-03-03 22:02:19 +00001352sub do_cmd_lineiii{
1353 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001354 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001355 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001356 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001357 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001358 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001359 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001360 $c3 = '&nbsp;' if ($c3 eq '');
1361 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1362 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001363 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001364 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001365 }
Fred Drakee15956b2000-04-03 04:51:13 +00001366 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001367 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001368 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001369 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001370}
1371
Fred Drakea0f4c941998-07-24 22:16:04 +00001372sub do_env_tableiv{
1373 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001374 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001375 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001376 my $h1 = next_argument();
1377 my $h2 = next_argument();
1378 my $h3 = next_argument();
1379 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001380 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001381 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001382 my $a1 = $col_aligns[0];
1383 my $a2 = $col_aligns[1];
1384 my $a3 = $col_aligns[2];
1385 my $a4 = $col_aligns[3];
1386 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1387 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001388 . "\n <thead>"
1389 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001390 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1391 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1392 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1393 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001394 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001395 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001396 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001397 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001398 . "\n </tbody>"
1399 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001400}
1401
Fred Drakeda72b932000-09-21 15:58:02 +00001402sub do_env_longtableiv{
1403 return do_env_tableiv(@_);
1404}
1405
Fred Drakea0f4c941998-07-24 22:16:04 +00001406sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001407 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001408 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001409 my $c1 = next_argument();
1410 my $c2 = next_argument();
1411 my $c3 = next_argument();
1412 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001413 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001414 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001415 $c4 = '&nbsp;' if ($c4 eq '');
1416 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1417 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001418 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001419 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001420 }
Fred Drakee15956b2000-04-03 04:51:13 +00001421 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001422 . " $c2align$c2</td>\n"
1423 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001424 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001425 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001426}
1427
Fred Drakef269e592001-07-17 23:05:57 +00001428sub do_env_tablev{
1429 local($_) = @_;
1430 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1431 my $font = fix_font(next_argument());
1432 my $h1 = next_argument();
1433 my $h2 = next_argument();
1434 my $h3 = next_argument();
1435 my $h4 = next_argument();
1436 my $h5 = next_argument();
1437 s/[\s\n]+//;
1438 $globals{'lineifont'} = $font;
1439 my $a1 = $col_aligns[0];
1440 my $a2 = $col_aligns[1];
1441 my $a3 = $col_aligns[2];
1442 my $a4 = $col_aligns[3];
1443 my $a5 = $col_aligns[4];
1444 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1445 return '<table border align="center" style="border-collapse: collapse">'
1446 . "\n <thead>"
1447 . "\n <tr class=\"tableheader\">"
1448 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1449 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1450 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1451 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1452 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1453 . "\n </tr>"
1454 . "\n </thead>"
1455 . "\n <tbody valign=\"baseline\">"
1456 . $_
1457 . "\n </tbody>"
1458 . "\n</table>";
1459}
1460
1461sub do_env_longtablev{
1462 return do_env_tablev(@_);
1463}
1464
1465sub do_cmd_linev{
1466 local($_) = @_;
1467 my $aligns = next_optional_argument();
1468 my $c1 = next_argument();
1469 my $c2 = next_argument();
1470 my $c3 = next_argument();
1471 my $c4 = next_argument();
1472 my $c5 = next_argument();
1473 s/[\s\n]+//;
1474 my($sfont,$efont) = get_table_col1_fonts();
1475 $c5 = '&nbsp;' if ($c5 eq '');
1476 my($c1align,$c2align,$c3align,$c4align,$c5align) = split('\|', $aligns);
1477 my $padding = '';
1478 if ($c1align =~ /align="right"/ || $c1 eq '') {
1479 $padding = '&nbsp;';
1480 }
1481 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1482 . " $c2align$c2</td>\n"
1483 . " $c3align$c3</td>\n"
1484 . " $c4align$c4</td>\n"
1485 . " $c5align$c5</td>"
1486 . $_;
1487}
1488
Fred Drake3be20742000-08-31 06:22:54 +00001489
1490# These can be used to control the title page appearance;
1491# they need a little bit of documentation.
1492#
1493# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1494# $ICONSERVER directory, or include path information (other than "./"). The
1495# default image type will be assumed if an extension is not provided.
1496#
1497# If specified, the "title page" will contain two colums: one containing the
1498# title/author/etc., and the other containing the graphic. Use the other
1499# four variables listed here to control specific details of the layout; all
1500# are optional.
1501#
1502# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1503# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1504# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1505# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1506# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1507
1508sub make_my_titlepage() {
1509 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001510 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001511 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001512 }
1513 else {
1514 write_warnings("\nThis document has no title.");
1515 }
Fred Drake6659c301998-03-03 22:02:19 +00001516 if ($t_author) {
1517 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001518 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001519 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001520 "<b><font size=\"+2\">$t_author"
1521 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001522 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001523 }
1524 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001525 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1526 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001527 }
Fred Drake3be20742000-08-31 06:22:54 +00001528 }
1529 else {
1530 write_warnings("\nThere is no author for this document.");
1531 }
Fred Drake6659c301998-03-03 22:02:19 +00001532 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001533 $the_title .= "\n<p>$t_institute</p>";
1534 }
Fred Draked07868a1998-05-14 21:00:28 +00001535 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001536 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1537 }
Fred Drake6659c301998-03-03 22:02:19 +00001538 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001539 $the_title .= "\n<p><i>$t_affil</i></p>";
1540 }
Fred Drake6659c301998-03-03 22:02:19 +00001541 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001542 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001543 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001544 $the_title .= ('<strong>Release '
1545 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001546 }
Fred Drakede77bc52000-12-14 18:36:12 +00001547 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001548 }
1549 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001550 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001551 }
1552 else {
1553 $the_title .= "\n<p>";
1554 }
Fred Drake6659c301998-03-03 22:02:19 +00001555 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001556 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001557 }
1558 return $the_title;
1559}
1560
Fred Drake3be20742000-08-31 06:22:54 +00001561sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001562 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001563 my $graphic = "<td class=\"titlegraphic\"";
1564 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1565 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1566 $graphic .= "><img";
1567 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1568 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1569 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1570 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001571 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001572 return $graphic;
1573}
1574
1575sub do_cmd_maketitle {
1576 local($_) = @_;
1577 my $the_title = "\n<div class=\"titlepage\">";
1578 if ($TITLE_PAGE_GRAPHIC) {
1579 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1580 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1581 . "<tr align=\"right\">\n<td>"
1582 . make_my_titlepage()
1583 . "</td>\n"
1584 . make_my_titlegraphic()
1585 . "</tr>\n</table>");
1586 }
1587 else {
1588 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1589 . make_my_titlegraphic()
1590 . "<td>"
1591 . make_my_titlepage()
1592 . "</td></tr>\n</table>");
1593 }
1594 }
1595 else {
1596 $the_title .= ("\n<center>"
1597 . make_my_titlepage()
1598 . "\n</center>");
1599 }
1600 $the_title .= "\n</div>";
1601 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001602 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001603 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001604}
1605
1606
Fred Drake885215c1998-05-20 21:32:09 +00001607#
Fred Drakea0f4c941998-07-24 22:16:04 +00001608# Module synopsis support
1609#
1610
1611require SynopsisTable;
1612
Fred Drakef7685d71998-07-25 03:31:46 +00001613sub get_chapter_id(){
1614 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001615 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1616 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001617 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001618}
1619
Fred Drake643d76d2000-09-09 06:07:37 +00001620# 'chapter' => 'SynopsisTable instance'
1621%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001622
1623sub get_synopsis_table($){
1624 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001625 my $key;
1626 foreach $key (keys %ModuleSynopses) {
1627 if ($key eq $chap) {
1628 return $ModuleSynopses{$chap};
1629 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001630 }
Fred Drake643d76d2000-09-09 06:07:37 +00001631 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001632 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001633 return $st;
1634}
1635
Fred Drake62e43691998-08-10 19:40:44 +00001636sub do_cmd_moduleauthor{
1637 local($_) = @_;
1638 next_argument();
1639 next_argument();
1640 return $_;
1641}
1642
1643sub do_cmd_sectionauthor{
1644 local($_) = @_;
1645 next_argument();
1646 next_argument();
1647 return $_;
1648}
1649
Fred Drakea0f4c941998-07-24 22:16:04 +00001650sub do_cmd_declaremodule{
1651 local($_) = @_;
1652 my $key = next_optional_argument();
1653 my $type = next_argument();
1654 my $name = next_argument();
1655 my $st = get_synopsis_table(get_chapter_id());
1656 #
1657 $key = $name unless $key;
1658 $type = 'built-in' if $type eq 'builtin';
1659 $st->declare($name, $key, $type);
1660 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001661 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001662}
1663
1664sub do_cmd_modulesynopsis{
1665 local($_) = @_;
1666 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001667 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001668 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001669}
1670
1671sub do_cmd_localmoduletable{
1672 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001673 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001674 my $st = get_synopsis_table($chap);
1675 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001676 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001677}
1678
1679sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001680 my $key;
1681 my $st, $file;
1682 foreach $key (keys %ModuleSynopses) {
1683 $st = $ModuleSynopses{$key};
1684 $file = $st->get_file();
1685 if ($file) {
1686 process_localmoduletables_in_file($file);
1687 }
1688 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001689 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001690 }
1691 }
1692}
1693
1694sub process_localmoduletables_in_file{
1695 my $file = @_[0];
1696 open(MYFILE, "<$file");
1697 local($_);
1698 sysread(MYFILE, $_, 1024*1024);
1699 close(MYFILE);
1700 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001701 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001702 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001703 my $chap = $1;
1704 my $st = get_synopsis_table($chap);
1705 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001706 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001707 }
Fred Drake643d76d2000-09-09 06:07:37 +00001708 open(MYFILE,">$file");
1709 print MYFILE $_;
1710 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001711}
Fred Drake557460c1999-03-02 16:05:35 +00001712sub process_python_state{
1713 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001714 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001715}
Fred Drakea0f4c941998-07-24 22:16:04 +00001716
1717
1718#
1719# "See also:" -- references placed at the end of a \section
1720#
1721
1722sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001723 return ("<div class=\"seealso\">\n "
1724 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1725 . @_[0]
1726 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001727}
1728
Fred Drake5ed35fd2001-11-30 18:09:54 +00001729sub do_env_seealsostar{
1730 return ("<div class=\"seealso-simple\">\n "
1731 . @_[0]
1732 . '</div>');
1733}
1734
Fred Drakea0f4c941998-07-24 22:16:04 +00001735sub do_cmd_seemodule{
1736 # Insert the right magic to jump to the module definition. This should
1737 # work most of the time, at least for repeat builds....
1738 local($_) = @_;
1739 my $key = next_optional_argument();
1740 my $module = next_argument();
1741 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001742 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001743 $key = $module
1744 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001745 if ($text =~ /\.$/) {
1746 $period = '';
1747 }
Fred Drakef1927a62001-06-20 21:29:30 +00001748 return ('<dl compact class="seemodule">'
1749 . "\n <dt>Module <b><tt class=\"module\">"
1750 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1751 . "\n <dd>$text$period\n </dl>"
1752 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001753}
1754
Fred Drakee0197bf2001-04-12 04:03:22 +00001755sub strip_html_markup($){
1756 my $str = @_[0];
1757 my $s = "$str";
1758 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1759 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1760 return $s;
1761}
1762
Fred Drake643d76d2000-09-09 06:07:37 +00001763sub handle_rfclike_reference{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001764 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001765 my $rfcnum = next_argument();
1766 my $title = next_argument();
1767 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001768 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001769 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001770 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001771 return '<dl compact class="seerfc">'
1772 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001773 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001774 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001775 . "\n <dd>$text\n </dl>"
1776 . $_;
1777}
1778
Fred Drake643d76d2000-09-09 06:07:37 +00001779sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001780 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001781}
1782
1783sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001784 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001785}
1786
Fred Drake48449982000-09-12 17:52:33 +00001787sub do_cmd_seetitle{
1788 local($_) = @_;
1789 my $url = next_optional_argument();
1790 my $title = next_argument();
1791 my $text = next_argument();
1792 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001793 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001794 return '<dl compact class="seetitle">'
1795 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001796 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001797 . "\n <dd>$text\n </dl>"
1798 . $_;
1799 }
1800 return '<dl compact class="seetitle">'
1801 . "\n <dt><em class=\"citetitle\""
1802 . "\n >$title</em>"
1803 . "\n <dd>$text\n </dl>"
1804 . $_;
1805}
1806
Fred Drakeef4d1112000-05-09 16:17:51 +00001807sub do_cmd_seeurl{
1808 local($_) = @_;
1809 my $url = next_argument();
1810 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001811 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001812 return '<dl compact class="seeurl">'
1813 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001814 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001815 . "\n <dd>$text\n </dl>"
1816 . $_;
1817}
1818
Fred Drakea0f4c941998-07-24 22:16:04 +00001819sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001820 local($_) = @_;
1821 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001822 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001823}
1824
1825
1826#
Fred Drake885215c1998-05-20 21:32:09 +00001827# Definition list support.
1828#
1829
1830sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001831 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001832}
1833
1834sub do_cmd_term{
1835 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001836 my $term = next_argument();
1837 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001838 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001839 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001840}
1841
1842
Fred Drake38178fd2000-09-22 17:05:04 +00001843# I don't recall exactly why this was needed, but it was very much needed.
1844# We'll see if anything breaks when I move the "code" line out -- some
1845# things broke with it in.
1846
1847#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001848process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001849declaremodule # [] # {} # {}
1850memberline # [] # {}
1851methodline # [] # {} # {}
1852modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001853platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001854samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001855setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001856withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001857_RAW_ARG_DEFERRED_CMDS_
1858
1859
Fred Drake86333602001-04-10 17:13:39 +00001860$alltt_start = '<dl><dd><pre class="verbatim">';
1861$alltt_end = '</pre></dl>';
1862
1863sub do_env_alltt {
1864 local ($_) = @_;
1865 local($closures,$reopens,@open_block_tags);
1866
1867 # get the tag-strings for all open tags
1868 local(@keep_open_tags) = @$open_tags_R;
1869 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1870
1871 # get the tags for text-level tags only
1872 $open_tags_R = [ @keep_open_tags ];
1873 local($local_closures, $local_reopens);
1874 ($local_closures, $local_reopens,@open_block_tags)
1875 = &preserve_open_block_tags
1876 if (@$open_tags_R);
1877
1878 $open_tags_R = [ @open_block_tags ];
1879
1880 do {
1881 local($open_tags_R) = [ @open_block_tags ];
1882 local(@save_open_tags) = ();
1883
1884 local($cnt) = ++$global{'max_id'};
1885 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1886 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1887
1888 $_ = &translate_environments($_);
1889 $_ = &translate_commands($_) if (/\\/);
1890
1891 # preserve space-runs, using &nbsp;
1892 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1893 s/(<BR>) /$1;SPMnbsp;/g;
1894
1895 $_ = join('', $closures, $alltt_start, $local_reopens
1896 , $_
1897 , &balance_tags() #, $local_closures
1898 , $alltt_end, $reopens);
1899 undef $open_tags_R; undef @save_open_tags;
1900 };
1901 $open_tags_R = [ @keep_open_tags ];
1902 $_;
1903}
1904
Fred Drake57e52ef2001-06-15 21:31:57 +00001905sub do_cmd_verbatiminput{
1906 local($_) = @_;
1907 my $fname = next_argument();
1908 my $file;
1909 my $found = 0;
1910 my $texpath;
1911 # Search TEXINPUTS for the input file, the way we're supposed to:
1912 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1913 $file = "$texpath$dd$fname";
1914 last if ($found = (-f $file));
1915 }
Fred Drake77602f22001-07-06 22:43:02 +00001916 my $srcname;
Fred Drake57e52ef2001-06-15 21:31:57 +00001917 my $text;
1918 if ($found) {
1919 open(MYFILE, "<$file") || die "\n$!\n";
1920 read(MYFILE, $text, 1024*1024);
1921 close(MYFILE);
Fred Drake77602f22001-07-06 22:43:02 +00001922 use File::Basename;
1923 my $srcdir, $srcext;
1924 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1925 open(MYFILE, ">$srcname.txt");
1926 print MYFILE $text;
1927 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00001928 #
1929 # These rewrites convert the raw text to something that will
1930 # be properly visible as HTML and also will pass through the
1931 # vagaries of conversion through LaTeX2HTML. The order in
1932 # which the specific rewrites are performed is significant.
1933 #
1934 $text =~ s/\&/\&amp;/g;
1935 # These need to happen before the normal < and > re-writes,
1936 # since we need to avoid LaTeX2HTML's attempt to perform
1937 # ligature processing without regard to context (since it
1938 # doesn't have font information).
1939 $text =~ s/--/-&\#45;/g;
1940 $text =~ s/<</\&lt;\&\#60;/g;
1941 $text =~ s/>>/\&gt;\&\#62;/g;
1942 # Just normal re-writes...
1943 $text =~ s/</\&lt;/g;
1944 $text =~ s/>/\&gt;/g;
1945 # These last isn't needed for the HTML, but is needed to get
1946 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1947 # of &sol; since many browsers don't support that.
1948 $text =~ s/\\/\&\#92;/g;
1949 }
1950 else {
1951 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1952 }
Fred Drake77602f22001-07-06 22:43:02 +00001953 return ('<dl><dd><pre class="verbatim">'
Fred Drake57e52ef2001-06-15 21:31:57 +00001954 . $text
Fred Drake77602f22001-07-06 22:43:02 +00001955 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1956 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1957 . ">Download as text.</a>"
1958 . "\n</div>\n</dd></dl>"
Fred Drake57e52ef2001-06-15 21:31:57 +00001959 . $_);
1960}
Fred Drake86333602001-04-10 17:13:39 +00001961
Fred Drake6659c301998-03-03 22:02:19 +000019621; # This must be the last line