blob: 6e2ad3e67b6cec9d64cad74a29a9cd21c96cb15d [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 Drake90fdda51999-02-16 20:27:42 +0000215sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000216 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_var{
218 return use_wrappers(@_[0], "<var>", "</var>"); }
219sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000220 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000221sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000222 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000224 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000225sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000226 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000227sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000228 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000229sub do_cmd_kbd{
230 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
231sub do_cmd_strong{
232 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000233sub do_cmd_textbf{
234 return use_wrappers(@_[0], '<b>', '</b>'); }
235sub do_cmd_textit{
236 return use_wrappers(@_[0], '<i>', '</i>'); }
237
Fred Drake3d5a04a2000-08-03 17:25:44 +0000238sub do_cmd_moreargs{
239 return '...' . @_[0]; }
240sub do_cmd_unspecified{
241 return '...' . @_[0]; }
242
Fred Drakec9a44381998-03-17 06:29:13 +0000243
Fred Drake25817041999-01-13 17:06:34 +0000244sub do_cmd_refmodule{
245 # Insert the right magic to jump to the module definition.
246 local($_) = @_;
247 my $key = next_optional_argument();
248 my $module = next_argument();
249 $key = $module
250 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000251 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000252 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000253}
254
Fred Drake1a7af391998-04-01 22:44:56 +0000255sub do_cmd_newsgroup{
256 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000257 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000258 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000259 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
260 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000261 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000262}
Fred Drakefc16e781998-03-12 21:03:26 +0000263
264sub do_cmd_envvar{
265 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000266 my $envvar = next_argument();
267 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000268 # The <tt> here is really to keep buildindex.py from making
269 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000270 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000271 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000272 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000273 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000274 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000275}
276
Fred Drake6659c301998-03-03 22:02:19 +0000277sub do_cmd_url{
278 # use the URL as both text and hyperlink
279 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000280 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000281 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000282 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000283 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000284}
285
286sub do_cmd_manpage{
287 # two parameters: \manpage{name}{section}
288 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000289 my $page = next_argument();
290 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000291 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000292}
293
Fred Drakef1927a62001-06-20 21:29:30 +0000294$PEP_FORMAT = "http://python.sourceforge.net/peps/pep-%04d.html";
295#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
296$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000297
298sub get_rfc_url($$){
299 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000300 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000301}
302
303sub do_cmd_pep{
304 local($_) = @_;
305 my $rfcnumber = next_argument();
306 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000307 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000308 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000309 # Save the reference
310 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
311 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000312 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
313 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000314}
315
Fred Drake6659c301998-03-03 22:02:19 +0000316sub do_cmd_rfc{
317 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000318 my $rfcnumber = next_argument();
319 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000320 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000321 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000322 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000323 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000324 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000325 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
326 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000327}
328
Fred Drake77602f22001-07-06 22:43:02 +0000329sub do_cmd_ulink{
330 local($_) = @_;
331 my $text = next_argument();
332 my $url = next_argument();
333 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
334}
335
Fred Drakec9f5fe01999-11-09 16:59:42 +0000336sub do_cmd_citetitle{
337 local($_) = @_;
338 my $url = next_optional_argument();
339 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000340 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000341 my $repl = '';
342 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000343 $repl = ("<em class=\"citetitle\"><a\n"
344 . " href=\"$url\"\n"
345 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000346 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000347 }
348 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000349 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000350 }
351 return $repl . $_;
352}
353
Fred Drake6659c301998-03-03 22:02:19 +0000354sub do_cmd_deprecated{
355 # two parameters: \deprecated{version}{whattodo}
356 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000357 my $release = next_argument();
358 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000359 return ('<div class="versionnote">'
360 . "<b>Deprecated since release $release.</b>"
361 . "\n$reason</div><p>"
362 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000363}
364
Fred Drakec2b29d02001-04-18 03:11:04 +0000365sub versionnote{
366 # one or two parameters: \versionnote[explanation]{version}
367 my $type = @_[0];
368 local $_ = @_[1];
369 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000370 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000371 my $text = "$type in version $release.";
372 if ($explanation) {
373 $text = "$type in version $release:\n$explanation.";
374 }
Fred Drakef1927a62001-06-20 21:29:30 +0000375 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000376}
377
378sub do_cmd_versionadded{
379 return versionnote('New', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000380}
381
382sub do_cmd_versionchanged{
Fred Drakec2b29d02001-04-18 03:11:04 +0000383 return versionnote('Changed', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000384}
385
Fred Drake557460c1999-03-02 16:05:35 +0000386#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000387# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000388#
389sub do_cmd_platform{
390 local($_) = @_;
391 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000392 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000393 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000394 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000395 return "\n<p class=\"availability\">Availability: <span"
396 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000397}
398
Fred Drake557460c1999-03-02 16:05:35 +0000399$IGNORE_PLATFORM_ANNOTATION = '';
400sub do_cmd_ignorePlatformAnnotation{
401 local($_) = @_;
402 $IGNORE_PLATFORM_ANNOTATION = next_argument();
403 return $_;
404}
405
Fred Drake6659c301998-03-03 22:02:19 +0000406
407# index commands
408
409$INDEX_SUBITEM = "";
410
411sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000412 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000413}
414
415sub do_cmd_setindexsubitem{
416 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000417 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000418 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000419}
420
Fred Drakefc16e781998-03-12 21:03:26 +0000421sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000422 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000423 # do things in the right order, but we need to at least strip this stuff
424 # out, and leave anything that the second argument expanded out to.
425 #
426 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000427 my $oldsubitem = $INDEX_SUBITEM;
428 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000429 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000430 my $br_id = ++$globals{'max_id'};
431 my $marker = "$O$br_id$C";
Fred Drake7d45f6d1999-01-05 14:39:27 +0000432 return
433 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000434 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000435 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000436}
437
Fred Drake08932051998-04-17 02:15:42 +0000438# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000439# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
440# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000441#
Fred Drake62e43691998-08-10 19:40:44 +0000442sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000443
Fred Drake42b31a51998-03-27 05:16:10 +0000444# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000445#
Fred Drake08932051998-04-17 02:15:42 +0000446open(IDXFILE, '>index.dat') || die "\n$!\n";
447open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000448print INTLABELS "%internal_labels = ();\n";
449print INTLABELS "1; # hack in case there are no entries\n\n";
450
451# Using \0 for this is bad because we can't use common tools to work with the
452# resulting files. Things like grep can be useful with this stuff!
453#
454$IDXFILE_FIELD_SEP = "\1";
455
Fred Drakeccc62721999-01-05 22:16:29 +0000456sub write_idxfile{
457 my ($ahref, $str) = @_;
458 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000459}
460
Fred Drake42b31a51998-03-27 05:16:10 +0000461
462sub gen_link{
463 my($node,$target) = @_;
464 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000465 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000466}
467
Fred Drake42b31a51998-03-27 05:16:10 +0000468sub add_index_entry{
469 # add an entry to the index structures; ignore the return value
470 my($str,$ahref) = @_;
471 $str = gen_index_id($str, '');
472 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000473 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000474}
475
Fred Drakeccc62721999-01-05 22:16:29 +0000476sub new_link_info{
477 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000478 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000479 my $ahref = gen_link($CURRENT_FILE, $name);
480 return ($name, $aname, $ahref);
481}
482
Fred Drakeab032151999-05-13 18:36:54 +0000483$IndexMacroPattern = '';
484sub define_indexing_macro{
485 my $count = @_;
486 my $i = 0;
487 for (; $i < $count; ++$i) {
488 my $name = @_[$i];
489 my $cmd = "idx_cmd_$name";
490 die "\nNo function $cmd() defined!\n"
491 if (!defined &$cmd);
492 eval ("sub do_cmd_$name { return process_index_macros("
493 . "\@_[0], '$name'); }");
494 if (length($IndexMacroPattern) == 0) {
495 $IndexMacroPattern = "$name";
496 }
497 else {
498 $IndexMacroPattern .= "|$name";
499 }
500 }
501}
502
503$DEBUG_INDEXING = 0;
504sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000505 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000506 my $cmdname = @_[1]; # This is what triggered us in the first place;
507 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000508 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000509 my $cmd = "idx_cmd_$cmdname";
510 print "\nIndexing: \\$cmdname"
511 if $DEBUG_INDEXING;
512 &$cmd($ahref); # modifies $_ and adds index entries
513 while (/^[\s\n]*\\($IndexMacroPattern)</) {
514 $cmdname = "$1";
515 print " \\$cmdname"
516 if $DEBUG_INDEXING;
517 $cmd = "idx_cmd_$cmdname";
518 if (!defined &$cmd) {
519 last;
520 }
521 else {
522 s/^[\s\n]*\\$cmdname//;
523 &$cmd($ahref);
524 }
525 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000526 if (/^[ \t\r\n]/) {
527 $_ = substr($_, 1);
528 }
Fred Drake62e43691998-08-10 19:40:44 +0000529 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000530}
531
Fred Drakeab032151999-05-13 18:36:54 +0000532define_indexing_macro('index');
533sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000534 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000535 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000536}
537
Fred Drakeab032151999-05-13 18:36:54 +0000538define_indexing_macro('kwindex');
539sub idx_cmd_kwindex{
540 my $str = next_argument();
541 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
542 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
543}
544
545define_indexing_macro('indexii');
546sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000547 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000548 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000549 add_index_entry("$str1!$str2", @_[0]);
550 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000551}
552
Fred Drakeab032151999-05-13 18:36:54 +0000553define_indexing_macro('indexiii');
554sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000555 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000556 my $str2 = next_argument();
557 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000558 add_index_entry("$str1!$str2 $str3", @_[0]);
559 add_index_entry("$str2!$str3, $str1", @_[0]);
560 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000561}
562
Fred Drakeab032151999-05-13 18:36:54 +0000563define_indexing_macro('indexiv');
564sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000565 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000566 my $str2 = next_argument();
567 my $str3 = next_argument();
568 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000569 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
570 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
571 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
572 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000573}
574
Fred Drakeab032151999-05-13 18:36:54 +0000575define_indexing_macro('ttindex');
576sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000577 my $str = next_argument();
578 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000579 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000580}
Fred Drake6659c301998-03-03 22:02:19 +0000581
582sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000583 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000584 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000585 add_index_entry("$str $word", $ahref);
586 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000587}
588
Fred Drakeab032151999-05-13 18:36:54 +0000589define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
590sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
591sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
592sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
593sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000594
Fred Drakeab032151999-05-13 18:36:54 +0000595define_indexing_macro('bifuncindex');
596sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000597 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000598 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drakee15956b2000-04-03 04:51:13 +0000599 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000600}
601
602
Fred Drake6659c301998-03-03 22:02:19 +0000603sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000604 my($str,$define) = @_;
605 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000606 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000607 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
608 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000609 $str = gen_index_id($str, $define);
610 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000611 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000612
Fred Drakec9a44381998-03-17 06:29:13 +0000613 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000614 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000615 $str =~ /(<tt.*<\/tt>)/;
616 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000617 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000618 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000619 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000620}
621
Fred Drake557460c1999-03-02 16:05:35 +0000622
Fred Drakec9a44381998-03-17 06:29:13 +0000623$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000624$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000625
Fred Drakea0f4c941998-07-24 22:16:04 +0000626sub define_module{
627 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000628 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000629 if ($word ne "built-in" && $word ne "extension"
630 && $word ne "standard" && $word ne "") {
631 write_warnings("Bad module type '$word'"
632 . " for \\declaremodule (module $name)");
633 $word = "";
634 }
Fred Drake6659c301998-03-03 22:02:19 +0000635 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000636 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000637 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000638 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000639 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000640 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000641}
642
643sub my_module_index_helper{
644 local($word, $_) = @_;
645 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000646 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000647}
648
Fred Drake62e43691998-08-10 19:40:44 +0000649sub do_cmd_modindex{ return my_module_index_helper('', @_); }
650sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
651sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
652sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000653
Fred Drakeab032151999-05-13 18:36:54 +0000654sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000655 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000656 my $str = next_argument();
657 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000658 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000659 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
660 # just inline it all here
661 $str = gen_index_id($str, 'REF');
662 $index{$str} .= $ahref;
663 write_idxfile($ahref, $str);
664}
665
Fred Drake6659c301998-03-03 22:02:19 +0000666# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000667define_indexing_macro('refmodindex', 'refbimodindex',
668 'refexmodindex', 'refstmodindex');
669sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
670sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
671sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
672sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000673
Fred Drake62e43691998-08-10 19:40:44 +0000674sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000675
676sub init_myformat{
Fred Drakeafc7ce12001-01-22 17:33:24 +0000677 $anchor_invisible_mark = '&nbsp;';
678 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000679 $anchor_mark = '';
680 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000681}
Fred Drake42b31a51998-03-27 05:16:10 +0000682init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000683
Fred Drakeab032151999-05-13 18:36:54 +0000684# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000685# instead of the dummy filler.
686#
687sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000688 my($str) = @_;
689 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000690 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000691 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000692}
693
Fred Drake77602f22001-07-06 22:43:02 +0000694
695%TokenToTargetMapping = ();
696%DefinedGrammars = ();
697%BackpatchGrammarFiles = ();
698
699sub do_cmd_token{
700 local($_) = @_;
701 my $token = next_argument();
702 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
703 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
704 # recursive definition or display-only productionlist
705 return "$token";
706 }
707 if ($target eq '') {
708 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
709 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
710 print "Adding '$CURRENT_FILE' to back-patch list.\n";
711 }
712 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
713 }
714 return "<a href=\"$target\">$token</a>" . $_;
715}
716
717sub do_env_productionlist{
718 local($_) = @_;
719 my $lang = next_optional_argument();
720 my $filename = "grammar-$lang.txt";
721 if ($lang eq '') {
722 $filename = 'grammar.txt';
723 }
724 local($CURRENT_GRAMMAR) = $lang;
725 $DefinedGrammars{$lang} .= $_;
726 return ("<dl><dd class=\"grammar\">\n"
727 . "<div class=\"productions\">\n"
728 . "<table cellpadding=\"2\" valign=\"baseline\">\n"
729 . translate_commands(translate_environments($_))
730 . "</table>\n"
731 . "</div>\n"
732 . (($lang eq '*')
733 ? ''
734 : ("<a class=\"grammar-footer\"\n"
735 . " href=\"$filename\" type=\"text/plain\"\n"
736 . " >Download entire grammar as text.</a>\n"))
737 . "</dd></dl>");
738}
739
740sub do_cmd_production{
741 local($_) = @_;
742 my $token = next_argument();
743 my $defn = next_argument();
744 my $lang = $CURRENT_GRAMMAR;
745 local($CURRENT_TOKEN) = $token;
746 if ($lang eq '*') {
747 return ("<tr>\n"
748 . " <td><code>$token</code></td>\n"
749 . " <td>&nbsp;::=&nbsp;</td>\n"
750 . " <td><code>"
751 . translate_commands($defn)
752 . "</code></td></tr>"
753 . $_);
754 }
755 my $target;
756 if ($lang eq '') {
757 $target = "$CURRENT_FILE\#tok-$token";
758 }
759 else {
760 $target = "$CURRENT_FILE\#tok-$lang-$token";
761 }
762 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
763 return ("<tr>\n"
764 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
765 . " <td>&nbsp;::=&nbsp;</td>\n"
766 . " <td><code>"
767 . translate_commands($defn)
768 . "</code></td></tr>"
769 . $_);
770}
771
772sub process_grammar_files{
773 my $lang;
774 my $filename;
775 local($_);
776 print "process_grammar_files()\n";
777 foreach $lang (keys %DefinedGrammars) {
778 $filename = "grammar-$lang.txt";
779 if ($lang eq '*') {
780 next;
781 }
782 if ($lang eq '') {
783 $filename = 'grammar.txt';
784 }
785 open(GRAMMAR, ">$filename") || die "\n$!\n";
786 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
787 close(GRAMMAR);
788 print "Wrote grammar file $filename\n";
789 }
790 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
791 foreach $filename (keys %BackpatchGrammarFiles) {
792 print "\nBack-patching grammar links in $filename\n";
793 my $buffer;
794 open(GRAMMAR, "<$filename") || die "\n$!\n";
795 # read all of the file into the buffer
796 sysread(GRAMMAR, $buffer, 1024*1024);
797 close(GRAMMAR);
798 while ($buffer =~ /$PATTERN/) {
799 my($lang, $token) = ($1, $2);
800 my $target = $TokenToTargetMapping{"$lang:$token"};
801 my $source = "<pyGrammarToken><$lang><$token>";
802 $buffer =~ s/$source/$target/g;
803 }
804 open(GRAMMAR, ">$filename") || die "\n$!\n";
805 print GRAMMAR $buffer;
806 close(GRAMMAR);
807 }
808}
809
810sub strip_grammar_markup{
811 local($_) = @_;
812 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
813 s/\\token(<<\d+>>)(.+)\1/\2/g;
814 s/\\e([^a-zA-Z])/\\\1/g;
815 s/<<\d+>>//g;
816 s/;SPMgt;/>/g;
817 s/;SPMlt;/</g;
818 s/;SPMquot;/\"/g;
819 return $_;
820}
821
822
Fred Drakee15956b2000-04-03 04:51:13 +0000823$REFCOUNTS_LOADED = 0;
824
825sub load_refcounts{
826 $REFCOUNTS_LOADED = 1;
827
Fred Drakee15956b2000-04-03 04:51:13 +0000828 my $myname, $mydir, $myext;
829 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
830 chop $mydir; # remove trailing '/'
831 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
832 chop $mydir; # remove trailing '/'
833 $mydir = getcwd() . "$dd$mydir"
834 unless $mydir =~ s|^/|/|;
835 local $_;
836 my $filename = "$mydir${dd}api${dd}refcounts.dat";
837 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
838 print "[loading API refcount data]";
839 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000840 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000841 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
842 #print "\n$func($param) --> $count";
843 $REFCOUNTS{"$func:$param"} = $count;
844 }
845 }
846}
847
848sub get_refcount{
849 my ($func, $param) = @_;
850 load_refcounts()
851 unless $REFCOUNTS_LOADED;
852 return $REFCOUNTS{"$func:$param"};
853}
854
Fred Drake6659c301998-03-03 22:02:19 +0000855sub do_env_cfuncdesc{
856 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000857 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000858 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000859 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000860 my $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000861 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000862 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000863 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000864 my $result_rc = get_refcount($function_name, '');
865 my $rcinfo = '';
866 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000867 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000868 }
869 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000870 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000871 }
Fred Drakec2578c52000-04-10 18:26:45 +0000872 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000873 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000874 }
Fred Drakee15956b2000-04-03 04:51:13 +0000875 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000876 $rcinfo = ( "\n<div class=\"refcount-info\">"
877 . "\n <span class=\"label\">Return value:</span>"
878 . "\n <span class=\"value\">$rcinfo.</span>"
879 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000880 }
Fred Drakec612a142001-03-29 18:24:08 +0000881 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000882 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000883 . $_
884 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000885}
886
Fred Drakee15956b2000-04-03 04:51:13 +0000887sub do_env_csimplemacrodesc{
888 local($_) = @_;
889 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000890 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000891 return "<dl><dt><b>$idx</b>\n<dd>"
892 . $_
893 . '</dl>'
894}
895
Fred Drake6659c301998-03-03 22:02:19 +0000896sub do_env_ctypedesc{
897 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000898 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000899 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000900 $index_name = $type_name
901 unless $index_name;
902 my($name,$aname,$ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000903 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
904 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000905 . $_
906 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000907}
908
909sub do_env_cvardesc{
910 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000911 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000912 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000913 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000914 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000915 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000916 return "<dl><dt>$var_type <b>$idx</b>\n"
917 . '<dd>'
918 . $_
919 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000920}
921
Fred Drake3cdb89d2000-09-14 20:17:23 +0000922sub convert_args($){
923 local($IN_DESC_HANDLER) = 1;
924 local($_) = @_;
925 return translate_commands($_);
926}
927
Fred Drake6659c301998-03-03 22:02:19 +0000928sub do_env_funcdesc{
929 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000930 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000931 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000932 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
933 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +0000934 . get_indexsubitem());
935 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000936 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakec612a142001-03-29 18:24:08 +0000937 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000938}
939
940sub do_env_funcdescni{
941 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000942 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000943 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000944 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
Fred Drakec612a142001-03-29 18:24:08 +0000945 . "(<var>$arg_list</var>)\n"
Fred Drake90fdda51999-02-16 20:27:42 +0000946 . '<dd>'
947 . $_
948 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000949}
950
951sub do_cmd_funcline{
952 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000953 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000954 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000955 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000956 my $idx = make_str_index_entry($prefix . get_indexsubitem());
957 $prefix =~ s/\(\)//;
958
Fred Drakec612a142001-03-29 18:24:08 +0000959 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000960}
961
Fred Drake6b3fb781999-07-12 16:50:09 +0000962sub do_cmd_funclineni{
963 local($_) = @_;
964 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000965 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000966 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000967
Fred Drakec612a142001-03-29 18:24:08 +0000968 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +0000969}
970
Fred Drake6659c301998-03-03 22:02:19 +0000971# Change this flag to index the opcode entries. I don't think it's very
972# useful to index them, since they're only presented to describe the dis
973# module.
974#
975$INDEX_OPCODES = 0;
976
977sub do_env_opcodedesc{
978 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000979 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000980 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000981 my $idx;
982 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +0000983 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
984 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +0000985 $idx =~ s/ \(byte code instruction\)//;
986 }
987 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000988 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +0000989 }
990 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +0000991 if ($arg_list) {
992 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
993 }
Fred Drake62e43691998-08-10 19:40:44 +0000994 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000995}
996
997sub do_env_datadesc{
998 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000999 my $dataname = next_argument();
1000 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001001 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001002 return "<dl><dt><b>$idx</b>\n<dd>"
1003 . $_
1004 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001005}
1006
1007sub do_env_datadescni{
1008 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001009 my $idx = next_argument();
1010 if (! $STRING_INDEX_TT) {
1011 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001012 }
Fred Drake62e43691998-08-10 19:40:44 +00001013 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001014}
1015
1016sub do_cmd_dataline{
1017 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001018 my $data_name = next_argument();
1019 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001020 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001021 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001022}
1023
Fred Drakeadb272c2000-04-10 17:47:14 +00001024sub do_cmd_datalineni{
1025 local($_) = @_;
1026 my $data_name = next_argument();
1027 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1028}
1029
Fred Drake42b31a51998-03-27 05:16:10 +00001030sub do_env_excdesc{
1031 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001032 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001033 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakeab357ec2001-03-02 18:57:05 +00001034 return "<dl><dt><b>exception $idx</b>\n<dd>" . $_ . '</dl>'
Fred Drake42b31a51998-03-27 05:16:10 +00001035}
1036
Fred Drake62e43691998-08-10 19:40:44 +00001037sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001038
1039
Fred Drake643d76d2000-09-09 06:07:37 +00001040sub handle_classlike_descriptor{
1041 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001042 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001043 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001044 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001045 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001046 $idx =~ s/ \(.*\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001047 return ("<dl><dt><b>$what $idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakeab357ec2001-03-02 18:57:05 +00001048 . $_
1049 . '</dl>');
Fred Drakec9a44381998-03-17 06:29:13 +00001050}
1051
Fred Drake643d76d2000-09-09 06:07:37 +00001052sub do_env_classdesc{
1053 return handle_classlike_descriptor(@_[0], "class");
1054}
1055
Fred Drake06a01e82001-05-11 01:00:30 +00001056sub do_env_classdescstar{
1057 local($_) = @_;
1058 $THIS_CLASS = next_argument();
1059 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001060 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001061 $idx =~ s/ \(.*\)//;
1062 return ("<dl><dt><b>class $idx</b>\n<dd>"
1063 . $_
1064 . '</dl>');
1065}
1066
Fred Drake643d76d2000-09-09 06:07:37 +00001067sub do_env_excclassdesc{
1068 return handle_classlike_descriptor(@_[0], "exception");
1069}
1070
Fred Drake42b31a51998-03-27 05:16:10 +00001071
1072sub do_env_methoddesc{
1073 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001074 my $class_name = next_optional_argument();
1075 $class_name = $THIS_CLASS
1076 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001077 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001078 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001079 my $extra = '';
1080 if ($class_name) {
1081 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001082 }
Fred Drakef1927a62001-06-20 21:29:30 +00001083 my $idx = make_str_index_entry(
1084 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001085 $idx =~ s/ \(.*\)//;
1086 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001087 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001088}
1089
1090
Fred Drake7d45f6d1999-01-05 14:39:27 +00001091sub do_cmd_methodline{
1092 local($_) = @_;
1093 my $class_name = next_optional_argument();
1094 $class_name = $THIS_CLASS
1095 unless $class_name;
1096 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001097 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001098 my $extra = '';
1099 if ($class_name) {
1100 $extra = " ($class_name method)";
1101 }
Fred Drakef1927a62001-06-20 21:29:30 +00001102 my $idx = make_str_index_entry(
1103 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001104 $idx =~ s/ \(.*\)//;
1105 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001106 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake7d45f6d1999-01-05 14:39:27 +00001107 . $_;
1108}
1109
1110
Fred Draked64a40d1998-09-10 18:59:13 +00001111sub do_cmd_methodlineni{
1112 local($_) = @_;
1113 next_optional_argument();
1114 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001115 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001116 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Draked64a40d1998-09-10 18:59:13 +00001117 . $_;
1118}
1119
Fred Drake42b31a51998-03-27 05:16:10 +00001120sub do_env_methoddescni{
1121 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001122 next_optional_argument();
1123 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001124 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001125 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001126 . $_
1127 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001128}
1129
1130
1131sub do_env_memberdesc{
1132 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001133 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001134 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001135 $class = $THIS_CLASS
1136 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001137 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001138 $extra = " ($class attribute)"
1139 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001140 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001141 $idx =~ s/ \(.*\)//;
1142 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001143 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001144}
1145
1146
Fred Drake5ccf3301998-04-17 20:04:09 +00001147sub do_cmd_memberline{
1148 local($_) = @_;
1149 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001150 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001151 $class = $THIS_CLASS
1152 unless $class;
1153 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001154 $extra = " ($class attribute)"
1155 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001156 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001157 $idx =~ s/ \(.*\)//;
1158 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001159 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001160}
1161
Fred Drake42b31a51998-03-27 05:16:10 +00001162sub do_env_memberdescni{
1163 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001164 next_optional_argument();
1165 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001166 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001167 . $_
1168 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001169}
1170
1171
Fred Drake5ccf3301998-04-17 20:04:09 +00001172sub do_cmd_memberlineni{
1173 local($_) = @_;
1174 next_optional_argument();
1175 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001176 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001177}
1178
Fred Drakee15956b2000-04-03 04:51:13 +00001179@col_aligns = ('<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001180
Fred Drakef74e5b71999-04-28 14:58:49 +00001181sub fix_font{
1182 # do a little magic on a font name to get the right behavior in the first
1183 # column of the output table
1184 my $font = @_[0];
1185 if ($font eq 'textrm') {
1186 $font = '';
1187 }
1188 elsif ($font eq 'file' || $font eq 'filenq') {
Fred Drakee15956b2000-04-03 04:51:13 +00001189 $font = 'tt class="file"';
1190 }
1191 elsif ($font eq 'member') {
1192 $font = 'tt class="member"';
Fred Drakef74e5b71999-04-28 14:58:49 +00001193 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001194 elsif ($font eq 'class') {
1195 $font = 'tt class="class"';
1196 }
Fred Drake7388f732000-06-28 21:06:08 +00001197 elsif ($font eq 'constant') {
1198 $font = 'tt class="constant"';
1199 }
Fred Drakecb0fc9c2000-08-09 13:45:04 +00001200 elsif ($font eq 'kbd') {
1201 $font = 'kbd';
1202 }
Fred Draked04592a2000-10-25 16:15:13 +00001203 elsif ($font eq 'programopt') {
1204 $font = 'b';
1205 }
Fred Drakeafc7ce12001-01-22 17:33:24 +00001206 elsif ($font eq 'exception') {
1207 $font = 'tt class="exception"';
1208 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001209 return $font;
1210}
1211
Fred Drakee15956b2000-04-03 04:51:13 +00001212sub figure_column_alignment{
1213 my $a = @_[0];
1214 my $mark = substr($a, 0, 1);
1215 my $r = '';
1216 if ($mark eq 'c')
1217 { $r = ' align="center"'; }
1218 elsif ($mark eq 'r')
1219 { $r = ' align="right"'; }
1220 elsif ($mark eq 'l')
1221 { $r = ' align="left"'; }
1222 elsif ($mark eq 'p')
1223 { $r = ' align="left"'; }
1224 return $r;
1225}
1226
Fred Drake6659c301998-03-03 22:02:19 +00001227sub setup_column_alignments{
1228 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001229 my($s1,$s2,$s3,$s4) = split(/[|]/,$_);
1230 my $a1 = figure_column_alignment($s1);
1231 my $a2 = figure_column_alignment($s2);
1232 my $a3 = figure_column_alignment($s3);
1233 my $a4 = figure_column_alignment($s4);
1234 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1235 $col_aligns[1] = "<td$a2>";
1236 $col_aligns[2] = "<td$a3>";
1237 $col_aligns[3] = "<td$a4>";
Fred Drake79189b51999-04-28 13:54:30 +00001238 # return the aligned header start tags
Fred Drakee15956b2000-04-03 04:51:13 +00001239 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>");
1240}
1241
1242sub get_table_col1_fonts{
1243 my $font = $globals{'lineifont'};
1244 my ($sfont,$efont) = ('', '');
1245 if ($font) {
1246 $sfont = "<$font>";
1247 $efont = "</$font>";
1248 $efont =~ s/ .*>/>/;
1249 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001250 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001251}
1252
1253sub do_env_tableii{
1254 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001255 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001256 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001257 my $h1 = next_argument();
1258 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001259 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001260 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001261 my $a1 = $col_aligns[0];
1262 my $a2 = $col_aligns[1];
1263 s/\\lineii</\\lineii[$a1|$a2]</g;
1264 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001265 . "\n <thead>"
1266 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001267 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1268 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001269 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001270 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001271 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001272 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001273 . "\n </tbody>"
1274 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001275}
1276
Fred Drakeda72b932000-09-21 15:58:02 +00001277sub do_env_longtableii{
1278 return do_env_tableii(@_);
1279}
1280
Fred Drake6659c301998-03-03 22:02:19 +00001281sub do_cmd_lineii{
1282 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001283 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001284 my $c1 = next_argument();
1285 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001286 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001287 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001288 $c2 = '&nbsp;' if ($c2 eq '');
1289 my($c1align,$c2align) = split('\|', $aligns);
1290 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001291 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001292 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001293 }
Fred Drakee15956b2000-04-03 04:51:13 +00001294 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1295 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001296 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001297}
1298
1299sub do_env_tableiii{
1300 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001301 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001302 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001303 my $h1 = next_argument();
1304 my $h2 = next_argument();
1305 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001306 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001307 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001308 my $a1 = $col_aligns[0];
1309 my $a2 = $col_aligns[1];
1310 my $a3 = $col_aligns[2];
1311 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1312 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001313 . "\n <thead>"
1314 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001315 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1316 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1317 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001318 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001319 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001320 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001321 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001322 . "\n </tbody>"
1323 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001324}
1325
Fred Drakeda72b932000-09-21 15:58:02 +00001326sub do_env_longtableiii{
1327 return do_env_tableiii(@_);
1328}
1329
Fred Drake6659c301998-03-03 22:02:19 +00001330sub do_cmd_lineiii{
1331 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001332 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001333 my $c1 = next_argument();
1334 my $c2 = next_argument();
1335 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001336 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001337 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001338 $c3 = '&nbsp;' if ($c3 eq '');
1339 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1340 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001341 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001342 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001343 }
Fred Drakee15956b2000-04-03 04:51:13 +00001344 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001345 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001346 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001347 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001348}
1349
Fred Drakea0f4c941998-07-24 22:16:04 +00001350sub do_env_tableiv{
1351 local($_) = @_;
1352 my($th1,$th2,$th3,$th4) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001353 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001354 my $h1 = next_argument();
1355 my $h2 = next_argument();
1356 my $h3 = next_argument();
1357 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001358 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001359 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001360 my $a1 = $col_aligns[0];
1361 my $a2 = $col_aligns[1];
1362 my $a3 = $col_aligns[2];
1363 my $a4 = $col_aligns[3];
1364 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1365 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001366 . "\n <thead>"
1367 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001368 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1369 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1370 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1371 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001372 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001373 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001374 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001375 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001376 . "\n </tbody>"
1377 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001378}
1379
Fred Drakeda72b932000-09-21 15:58:02 +00001380sub do_env_longtableiv{
1381 return do_env_tableiv(@_);
1382}
1383
Fred Drakea0f4c941998-07-24 22:16:04 +00001384sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001385 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001386 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001387 my $c1 = next_argument();
1388 my $c2 = next_argument();
1389 my $c3 = next_argument();
1390 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001391 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001392 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001393 $c4 = '&nbsp;' if ($c4 eq '');
1394 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1395 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001396 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001397 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001398 }
Fred Drakee15956b2000-04-03 04:51:13 +00001399 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001400 . " $c2align$c2</td>\n"
1401 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001402 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001403 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001404}
1405
Fred Drake3be20742000-08-31 06:22:54 +00001406
1407# These can be used to control the title page appearance;
1408# they need a little bit of documentation.
1409#
1410# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1411# $ICONSERVER directory, or include path information (other than "./"). The
1412# default image type will be assumed if an extension is not provided.
1413#
1414# If specified, the "title page" will contain two colums: one containing the
1415# title/author/etc., and the other containing the graphic. Use the other
1416# four variables listed here to control specific details of the layout; all
1417# are optional.
1418#
1419# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1420# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1421# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1422# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1423# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1424
1425sub make_my_titlepage() {
1426 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001427 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001428 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001429 }
1430 else {
1431 write_warnings("\nThis document has no title.");
1432 }
Fred Drake6659c301998-03-03 22:02:19 +00001433 if ($t_author) {
1434 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001435 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001436 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001437 "<b><font size=\"+2\">$t_author"
1438 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001439 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001440 }
1441 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001442 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1443 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001444 }
Fred Drake3be20742000-08-31 06:22:54 +00001445 }
1446 else {
1447 write_warnings("\nThere is no author for this document.");
1448 }
Fred Drake6659c301998-03-03 22:02:19 +00001449 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001450 $the_title .= "\n<p>$t_institute</p>";
1451 }
Fred Draked07868a1998-05-14 21:00:28 +00001452 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001453 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1454 }
Fred Drake6659c301998-03-03 22:02:19 +00001455 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001456 $the_title .= "\n<p><i>$t_affil</i></p>";
1457 }
Fred Drake6659c301998-03-03 22:02:19 +00001458 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001459 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001460 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001461 $the_title .= ('<strong>Release '
1462 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001463 }
Fred Drakede77bc52000-12-14 18:36:12 +00001464 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001465 }
1466 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001467 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001468 }
1469 else {
1470 $the_title .= "\n<p>";
1471 }
Fred Drake6659c301998-03-03 22:02:19 +00001472 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001473 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001474 }
1475 return $the_title;
1476}
1477
Fred Drake3be20742000-08-31 06:22:54 +00001478sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001479 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001480 my $graphic = "<td class=\"titlegraphic\"";
1481 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1482 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1483 $graphic .= "><img";
1484 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1485 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1486 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1487 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001488 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001489 return $graphic;
1490}
1491
1492sub do_cmd_maketitle {
1493 local($_) = @_;
1494 my $the_title = "\n<div class=\"titlepage\">";
1495 if ($TITLE_PAGE_GRAPHIC) {
1496 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1497 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1498 . "<tr align=\"right\">\n<td>"
1499 . make_my_titlepage()
1500 . "</td>\n"
1501 . make_my_titlegraphic()
1502 . "</tr>\n</table>");
1503 }
1504 else {
1505 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1506 . make_my_titlegraphic()
1507 . "<td>"
1508 . make_my_titlepage()
1509 . "</td></tr>\n</table>");
1510 }
1511 }
1512 else {
1513 $the_title .= ("\n<center>"
1514 . make_my_titlepage()
1515 . "\n</center>");
1516 }
1517 $the_title .= "\n</div>";
1518 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001519 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001520 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001521}
1522
1523
Fred Drake885215c1998-05-20 21:32:09 +00001524#
Fred Drakea0f4c941998-07-24 22:16:04 +00001525# Module synopsis support
1526#
1527
1528require SynopsisTable;
1529
Fred Drakef7685d71998-07-25 03:31:46 +00001530sub get_chapter_id(){
1531 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001532 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1533 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001534 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001535}
1536
Fred Drake643d76d2000-09-09 06:07:37 +00001537# 'chapter' => 'SynopsisTable instance'
1538%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001539
1540sub get_synopsis_table($){
1541 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001542 my $key;
1543 foreach $key (keys %ModuleSynopses) {
1544 if ($key eq $chap) {
1545 return $ModuleSynopses{$chap};
1546 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001547 }
Fred Drake643d76d2000-09-09 06:07:37 +00001548 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001549 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001550 return $st;
1551}
1552
Fred Drake62e43691998-08-10 19:40:44 +00001553sub do_cmd_moduleauthor{
1554 local($_) = @_;
1555 next_argument();
1556 next_argument();
1557 return $_;
1558}
1559
1560sub do_cmd_sectionauthor{
1561 local($_) = @_;
1562 next_argument();
1563 next_argument();
1564 return $_;
1565}
1566
Fred Drakea0f4c941998-07-24 22:16:04 +00001567sub do_cmd_declaremodule{
1568 local($_) = @_;
1569 my $key = next_optional_argument();
1570 my $type = next_argument();
1571 my $name = next_argument();
1572 my $st = get_synopsis_table(get_chapter_id());
1573 #
1574 $key = $name unless $key;
1575 $type = 'built-in' if $type eq 'builtin';
1576 $st->declare($name, $key, $type);
1577 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001578 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001579}
1580
1581sub do_cmd_modulesynopsis{
1582 local($_) = @_;
1583 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001584 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001585 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001586}
1587
1588sub do_cmd_localmoduletable{
1589 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001590 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001591 my $st = get_synopsis_table($chap);
1592 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001593 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001594}
1595
1596sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001597 my $key;
1598 my $st, $file;
1599 foreach $key (keys %ModuleSynopses) {
1600 $st = $ModuleSynopses{$key};
1601 $file = $st->get_file();
1602 if ($file) {
1603 process_localmoduletables_in_file($file);
1604 }
1605 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001606 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001607 }
1608 }
1609}
1610
1611sub process_localmoduletables_in_file{
1612 my $file = @_[0];
1613 open(MYFILE, "<$file");
1614 local($_);
1615 sysread(MYFILE, $_, 1024*1024);
1616 close(MYFILE);
1617 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001618 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001619 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001620 my $chap = $1;
1621 my $st = get_synopsis_table($chap);
1622 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001623 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001624 }
Fred Drake643d76d2000-09-09 06:07:37 +00001625 open(MYFILE,">$file");
1626 print MYFILE $_;
1627 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001628}
Fred Drake557460c1999-03-02 16:05:35 +00001629sub process_python_state{
1630 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001631 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001632}
Fred Drakea0f4c941998-07-24 22:16:04 +00001633
1634
1635#
1636# "See also:" -- references placed at the end of a \section
1637#
1638
1639sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001640 return ("<div class=\"seealso\">\n "
1641 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1642 . @_[0]
1643 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001644}
1645
1646sub do_cmd_seemodule{
1647 # Insert the right magic to jump to the module definition. This should
1648 # work most of the time, at least for repeat builds....
1649 local($_) = @_;
1650 my $key = next_optional_argument();
1651 my $module = next_argument();
1652 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001653 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001654 $key = $module
1655 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001656 if ($text =~ /\.$/) {
1657 $period = '';
1658 }
Fred Drakef1927a62001-06-20 21:29:30 +00001659 return ('<dl compact class="seemodule">'
1660 . "\n <dt>Module <b><tt class=\"module\">"
1661 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1662 . "\n <dd>$text$period\n </dl>"
1663 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001664}
1665
Fred Drakee0197bf2001-04-12 04:03:22 +00001666sub strip_html_markup($){
1667 my $str = @_[0];
1668 my $s = "$str";
1669 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1670 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1671 return $s;
1672}
1673
Fred Drake643d76d2000-09-09 06:07:37 +00001674sub handle_rfclike_reference{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001675 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001676 my $rfcnum = next_argument();
1677 my $title = next_argument();
1678 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001679 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001680 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001681 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001682 return '<dl compact class="seerfc">'
1683 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001684 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001685 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001686 . "\n <dd>$text\n </dl>"
1687 . $_;
1688}
1689
Fred Drake643d76d2000-09-09 06:07:37 +00001690sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001691 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001692}
1693
1694sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001695 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001696}
1697
Fred Drake48449982000-09-12 17:52:33 +00001698sub do_cmd_seetitle{
1699 local($_) = @_;
1700 my $url = next_optional_argument();
1701 my $title = next_argument();
1702 my $text = next_argument();
1703 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001704 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001705 return '<dl compact class="seetitle">'
1706 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001707 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001708 . "\n <dd>$text\n </dl>"
1709 . $_;
1710 }
1711 return '<dl compact class="seetitle">'
1712 . "\n <dt><em class=\"citetitle\""
1713 . "\n >$title</em>"
1714 . "\n <dd>$text\n </dl>"
1715 . $_;
1716}
1717
Fred Drakeef4d1112000-05-09 16:17:51 +00001718sub do_cmd_seeurl{
1719 local($_) = @_;
1720 my $url = next_argument();
1721 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001722 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001723 return '<dl compact class="seeurl">'
1724 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001725 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001726 . "\n <dd>$text\n </dl>"
1727 . $_;
1728}
1729
Fred Drakea0f4c941998-07-24 22:16:04 +00001730sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001731 local($_) = @_;
1732 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001733 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001734}
1735
1736
1737#
Fred Drake885215c1998-05-20 21:32:09 +00001738# Definition list support.
1739#
1740
1741sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001742 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001743}
1744
1745sub do_cmd_term{
1746 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001747 my $term = next_argument();
1748 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001749 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001750 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001751}
1752
1753
Fred Drake38178fd2000-09-22 17:05:04 +00001754# I don't recall exactly why this was needed, but it was very much needed.
1755# We'll see if anything breaks when I move the "code" line out -- some
1756# things broke with it in.
1757
1758#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001759process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001760declaremodule # [] # {} # {}
1761memberline # [] # {}
1762methodline # [] # {} # {}
1763modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001764platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001765samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001766setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001767withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001768_RAW_ARG_DEFERRED_CMDS_
1769
1770
Fred Drake86333602001-04-10 17:13:39 +00001771$alltt_start = '<dl><dd><pre class="verbatim">';
1772$alltt_end = '</pre></dl>';
1773
1774sub do_env_alltt {
1775 local ($_) = @_;
1776 local($closures,$reopens,@open_block_tags);
1777
1778 # get the tag-strings for all open tags
1779 local(@keep_open_tags) = @$open_tags_R;
1780 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1781
1782 # get the tags for text-level tags only
1783 $open_tags_R = [ @keep_open_tags ];
1784 local($local_closures, $local_reopens);
1785 ($local_closures, $local_reopens,@open_block_tags)
1786 = &preserve_open_block_tags
1787 if (@$open_tags_R);
1788
1789 $open_tags_R = [ @open_block_tags ];
1790
1791 do {
1792 local($open_tags_R) = [ @open_block_tags ];
1793 local(@save_open_tags) = ();
1794
1795 local($cnt) = ++$global{'max_id'};
1796 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1797 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1798
1799 $_ = &translate_environments($_);
1800 $_ = &translate_commands($_) if (/\\/);
1801
1802 # preserve space-runs, using &nbsp;
1803 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1804 s/(<BR>) /$1;SPMnbsp;/g;
1805
1806 $_ = join('', $closures, $alltt_start, $local_reopens
1807 , $_
1808 , &balance_tags() #, $local_closures
1809 , $alltt_end, $reopens);
1810 undef $open_tags_R; undef @save_open_tags;
1811 };
1812 $open_tags_R = [ @keep_open_tags ];
1813 $_;
1814}
1815
Fred Drake57e52ef2001-06-15 21:31:57 +00001816sub do_cmd_verbatiminput{
1817 local($_) = @_;
1818 my $fname = next_argument();
1819 my $file;
1820 my $found = 0;
1821 my $texpath;
1822 # Search TEXINPUTS for the input file, the way we're supposed to:
1823 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1824 $file = "$texpath$dd$fname";
1825 last if ($found = (-f $file));
1826 }
Fred Drake77602f22001-07-06 22:43:02 +00001827 my $srcname;
Fred Drake57e52ef2001-06-15 21:31:57 +00001828 my $text;
1829 if ($found) {
1830 open(MYFILE, "<$file") || die "\n$!\n";
1831 read(MYFILE, $text, 1024*1024);
1832 close(MYFILE);
Fred Drake77602f22001-07-06 22:43:02 +00001833 use File::Basename;
1834 my $srcdir, $srcext;
1835 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1836 open(MYFILE, ">$srcname.txt");
1837 print MYFILE $text;
1838 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00001839 #
1840 # These rewrites convert the raw text to something that will
1841 # be properly visible as HTML and also will pass through the
1842 # vagaries of conversion through LaTeX2HTML. The order in
1843 # which the specific rewrites are performed is significant.
1844 #
1845 $text =~ s/\&/\&amp;/g;
1846 # These need to happen before the normal < and > re-writes,
1847 # since we need to avoid LaTeX2HTML's attempt to perform
1848 # ligature processing without regard to context (since it
1849 # doesn't have font information).
1850 $text =~ s/--/-&\#45;/g;
1851 $text =~ s/<</\&lt;\&\#60;/g;
1852 $text =~ s/>>/\&gt;\&\#62;/g;
1853 # Just normal re-writes...
1854 $text =~ s/</\&lt;/g;
1855 $text =~ s/>/\&gt;/g;
1856 # These last isn't needed for the HTML, but is needed to get
1857 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1858 # of &sol; since many browsers don't support that.
1859 $text =~ s/\\/\&\#92;/g;
1860 }
1861 else {
1862 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1863 }
Fred Drake77602f22001-07-06 22:43:02 +00001864 return ('<dl><dd><pre class="verbatim">'
Fred Drake57e52ef2001-06-15 21:31:57 +00001865 . $text
Fred Drake77602f22001-07-06 22:43:02 +00001866 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1867 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1868 . ">Download as text.</a>"
1869 . "\n</div>\n</dd></dl>"
Fred Drake57e52ef2001-06-15 21:31:57 +00001870 . $_);
1871}
Fred Drake86333602001-04-10 17:13:39 +00001872
Fred Drake6659c301998-03-03 22:02:19 +000018731; # This must be the last line