blob: dabab666987cc40e56dc5d34048bc766cb3e68da [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{
216 return use_wrappers(@_[0], '<tt class="mimeheader">', '</tt>'); }
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>'); }
239
Fred Drake3d5a04a2000-08-03 17:25:44 +0000240sub do_cmd_moreargs{
241 return '...' . @_[0]; }
242sub do_cmd_unspecified{
243 return '...' . @_[0]; }
244
Fred Drakec9a44381998-03-17 06:29:13 +0000245
Fred Drake25817041999-01-13 17:06:34 +0000246sub do_cmd_refmodule{
247 # Insert the right magic to jump to the module definition.
248 local($_) = @_;
249 my $key = next_optional_argument();
250 my $module = next_argument();
251 $key = $module
252 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000253 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000254 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000255}
256
Fred Drake1a7af391998-04-01 22:44:56 +0000257sub do_cmd_newsgroup{
258 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000259 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000260 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000261 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
262 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000263 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000264}
Fred Drakefc16e781998-03-12 21:03:26 +0000265
266sub do_cmd_envvar{
267 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000268 my $envvar = next_argument();
269 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000270 # The <tt> here is really to keep buildindex.py from making
271 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000272 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000273 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000274 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000275 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000276 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000277}
278
Fred Drake6659c301998-03-03 22:02:19 +0000279sub do_cmd_url{
280 # use the URL as both text and hyperlink
281 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000282 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000283 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000284 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000285 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000286}
287
288sub do_cmd_manpage{
289 # two parameters: \manpage{name}{section}
290 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000291 my $page = next_argument();
292 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000293 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000294}
295
Fred Drakef1927a62001-06-20 21:29:30 +0000296$PEP_FORMAT = "http://python.sourceforge.net/peps/pep-%04d.html";
297#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
298$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000299
300sub get_rfc_url($$){
301 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000302 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000303}
304
305sub do_cmd_pep{
306 local($_) = @_;
307 my $rfcnumber = next_argument();
308 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000309 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000310 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000311 # Save the reference
312 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
313 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000314 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
315 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000316}
317
Fred Drake6659c301998-03-03 22:02:19 +0000318sub do_cmd_rfc{
319 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000320 my $rfcnumber = next_argument();
321 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000322 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000323 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000324 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000325 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000326 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000327 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
328 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000329}
330
Fred Drake77602f22001-07-06 22:43:02 +0000331sub do_cmd_ulink{
332 local($_) = @_;
333 my $text = next_argument();
334 my $url = next_argument();
335 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
336}
337
Fred Drakec9f5fe01999-11-09 16:59:42 +0000338sub do_cmd_citetitle{
339 local($_) = @_;
340 my $url = next_optional_argument();
341 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000342 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000343 my $repl = '';
344 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000345 $repl = ("<em class=\"citetitle\"><a\n"
346 . " href=\"$url\"\n"
347 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000348 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000349 }
350 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000351 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000352 }
353 return $repl . $_;
354}
355
Fred Drake6659c301998-03-03 22:02:19 +0000356sub do_cmd_deprecated{
357 # two parameters: \deprecated{version}{whattodo}
358 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000359 my $release = next_argument();
360 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000361 return ('<div class="versionnote">'
362 . "<b>Deprecated since release $release.</b>"
363 . "\n$reason</div><p>"
364 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000365}
366
Fred Drakec2b29d02001-04-18 03:11:04 +0000367sub versionnote{
368 # one or two parameters: \versionnote[explanation]{version}
369 my $type = @_[0];
370 local $_ = @_[1];
371 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000372 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000373 my $text = "$type in version $release.";
374 if ($explanation) {
375 $text = "$type in version $release:\n$explanation.";
376 }
Fred Drakef1927a62001-06-20 21:29:30 +0000377 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000378}
379
380sub do_cmd_versionadded{
381 return versionnote('New', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000382}
383
384sub do_cmd_versionchanged{
Fred Drakec2b29d02001-04-18 03:11:04 +0000385 return versionnote('Changed', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000386}
387
Fred Drake557460c1999-03-02 16:05:35 +0000388#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000389# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000390#
391sub do_cmd_platform{
392 local($_) = @_;
393 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000394 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000395 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000396 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000397 return "\n<p class=\"availability\">Availability: <span"
398 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000399}
400
Fred Drake557460c1999-03-02 16:05:35 +0000401$IGNORE_PLATFORM_ANNOTATION = '';
402sub do_cmd_ignorePlatformAnnotation{
403 local($_) = @_;
404 $IGNORE_PLATFORM_ANNOTATION = next_argument();
405 return $_;
406}
407
Fred Drake6659c301998-03-03 22:02:19 +0000408
409# index commands
410
411$INDEX_SUBITEM = "";
412
413sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000414 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000415}
416
417sub do_cmd_setindexsubitem{
418 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000419 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000420 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000421}
422
Fred Drakefc16e781998-03-12 21:03:26 +0000423sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000424 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000425 # do things in the right order, but we need to at least strip this stuff
426 # out, and leave anything that the second argument expanded out to.
427 #
428 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000429 my $oldsubitem = $INDEX_SUBITEM;
430 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000431 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000432 my $br_id = ++$globals{'max_id'};
433 my $marker = "$O$br_id$C";
Fred Drake7d45f6d1999-01-05 14:39:27 +0000434 return
435 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000436 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000437 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000438}
439
Fred Drake08932051998-04-17 02:15:42 +0000440# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000441# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
442# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000443#
Fred Drake62e43691998-08-10 19:40:44 +0000444sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000445
Fred Drake42b31a51998-03-27 05:16:10 +0000446# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000447#
Fred Drake08932051998-04-17 02:15:42 +0000448open(IDXFILE, '>index.dat') || die "\n$!\n";
449open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000450print INTLABELS "%internal_labels = ();\n";
451print INTLABELS "1; # hack in case there are no entries\n\n";
452
453# Using \0 for this is bad because we can't use common tools to work with the
454# resulting files. Things like grep can be useful with this stuff!
455#
456$IDXFILE_FIELD_SEP = "\1";
457
Fred Drakeccc62721999-01-05 22:16:29 +0000458sub write_idxfile{
459 my ($ahref, $str) = @_;
460 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000461}
462
Fred Drake42b31a51998-03-27 05:16:10 +0000463
464sub gen_link{
465 my($node,$target) = @_;
466 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000467 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000468}
469
Fred Drake42b31a51998-03-27 05:16:10 +0000470sub add_index_entry{
471 # add an entry to the index structures; ignore the return value
472 my($str,$ahref) = @_;
473 $str = gen_index_id($str, '');
474 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000475 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000476}
477
Fred Drakeccc62721999-01-05 22:16:29 +0000478sub new_link_info{
479 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000480 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000481 my $ahref = gen_link($CURRENT_FILE, $name);
482 return ($name, $aname, $ahref);
483}
484
Fred Drakeab032151999-05-13 18:36:54 +0000485$IndexMacroPattern = '';
486sub define_indexing_macro{
487 my $count = @_;
488 my $i = 0;
489 for (; $i < $count; ++$i) {
490 my $name = @_[$i];
491 my $cmd = "idx_cmd_$name";
492 die "\nNo function $cmd() defined!\n"
493 if (!defined &$cmd);
494 eval ("sub do_cmd_$name { return process_index_macros("
495 . "\@_[0], '$name'); }");
496 if (length($IndexMacroPattern) == 0) {
497 $IndexMacroPattern = "$name";
498 }
499 else {
500 $IndexMacroPattern .= "|$name";
501 }
502 }
503}
504
505$DEBUG_INDEXING = 0;
506sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000507 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000508 my $cmdname = @_[1]; # This is what triggered us in the first place;
509 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000510 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000511 my $cmd = "idx_cmd_$cmdname";
512 print "\nIndexing: \\$cmdname"
513 if $DEBUG_INDEXING;
514 &$cmd($ahref); # modifies $_ and adds index entries
515 while (/^[\s\n]*\\($IndexMacroPattern)</) {
516 $cmdname = "$1";
517 print " \\$cmdname"
518 if $DEBUG_INDEXING;
519 $cmd = "idx_cmd_$cmdname";
520 if (!defined &$cmd) {
521 last;
522 }
523 else {
524 s/^[\s\n]*\\$cmdname//;
525 &$cmd($ahref);
526 }
527 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000528 if (/^[ \t\r\n]/) {
529 $_ = substr($_, 1);
530 }
Fred Drake62e43691998-08-10 19:40:44 +0000531 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000532}
533
Fred Drakeab032151999-05-13 18:36:54 +0000534define_indexing_macro('index');
535sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000536 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000537 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000538}
539
Fred Drakeab032151999-05-13 18:36:54 +0000540define_indexing_macro('kwindex');
541sub idx_cmd_kwindex{
542 my $str = next_argument();
543 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
544 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
545}
546
547define_indexing_macro('indexii');
548sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000549 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000550 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000551 add_index_entry("$str1!$str2", @_[0]);
552 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000553}
554
Fred Drakeab032151999-05-13 18:36:54 +0000555define_indexing_macro('indexiii');
556sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000557 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000558 my $str2 = next_argument();
559 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000560 add_index_entry("$str1!$str2 $str3", @_[0]);
561 add_index_entry("$str2!$str3, $str1", @_[0]);
562 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000563}
564
Fred Drakeab032151999-05-13 18:36:54 +0000565define_indexing_macro('indexiv');
566sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000567 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000568 my $str2 = next_argument();
569 my $str3 = next_argument();
570 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000571 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
572 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
573 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
574 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000575}
576
Fred Drakeab032151999-05-13 18:36:54 +0000577define_indexing_macro('ttindex');
578sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000579 my $str = next_argument();
580 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000581 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000582}
Fred Drake6659c301998-03-03 22:02:19 +0000583
584sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000585 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000586 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000587 add_index_entry("$str $word", $ahref);
588 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000589}
590
Fred Drakeab032151999-05-13 18:36:54 +0000591define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
592sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
593sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
594sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
595sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000596
Fred Drakeab032151999-05-13 18:36:54 +0000597define_indexing_macro('bifuncindex');
598sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000599 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000600 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drakee15956b2000-04-03 04:51:13 +0000601 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000602}
603
604
Fred Drake6659c301998-03-03 22:02:19 +0000605sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000606 my($str,$define) = @_;
607 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000608 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000609 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
610 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000611 $str = gen_index_id($str, $define);
612 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000613 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000614
Fred Drakec9a44381998-03-17 06:29:13 +0000615 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000616 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000617 $str =~ /(<tt.*<\/tt>)/;
618 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000619 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000620 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000621 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000622}
623
Fred Drake557460c1999-03-02 16:05:35 +0000624
Fred Drakec9a44381998-03-17 06:29:13 +0000625$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000626$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000627
Fred Drakea0f4c941998-07-24 22:16:04 +0000628sub define_module{
629 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000630 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000631 if ($word ne "built-in" && $word ne "extension"
632 && $word ne "standard" && $word ne "") {
633 write_warnings("Bad module type '$word'"
634 . " for \\declaremodule (module $name)");
635 $word = "";
636 }
Fred Drake6659c301998-03-03 22:02:19 +0000637 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000638 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000639 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000640 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000641 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000642 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000643}
644
645sub my_module_index_helper{
646 local($word, $_) = @_;
647 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000648 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000649}
650
Fred Drake62e43691998-08-10 19:40:44 +0000651sub do_cmd_modindex{ return my_module_index_helper('', @_); }
652sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
653sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
654sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000655
Fred Drakeab032151999-05-13 18:36:54 +0000656sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000657 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000658 my $str = next_argument();
659 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000660 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000661 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
662 # just inline it all here
663 $str = gen_index_id($str, 'REF');
664 $index{$str} .= $ahref;
665 write_idxfile($ahref, $str);
666}
667
Fred Drake6659c301998-03-03 22:02:19 +0000668# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000669define_indexing_macro('refmodindex', 'refbimodindex',
670 'refexmodindex', 'refstmodindex');
671sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
672sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
673sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
674sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000675
Fred Drake62e43691998-08-10 19:40:44 +0000676sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000677
678sub init_myformat{
Fred Drakeafc7ce12001-01-22 17:33:24 +0000679 $anchor_invisible_mark = '&nbsp;';
680 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000681 $anchor_mark = '';
682 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000683}
Fred Drake42b31a51998-03-27 05:16:10 +0000684init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000685
Fred Drakeab032151999-05-13 18:36:54 +0000686# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000687# instead of the dummy filler.
688#
689sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000690 my($str) = @_;
691 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000692 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000693 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000694}
695
Fred Drake77602f22001-07-06 22:43:02 +0000696
697%TokenToTargetMapping = ();
698%DefinedGrammars = ();
699%BackpatchGrammarFiles = ();
700
701sub do_cmd_token{
702 local($_) = @_;
703 my $token = next_argument();
704 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
705 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
706 # recursive definition or display-only productionlist
707 return "$token";
708 }
709 if ($target eq '') {
710 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
711 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
712 print "Adding '$CURRENT_FILE' to back-patch list.\n";
713 }
714 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
715 }
716 return "<a href=\"$target\">$token</a>" . $_;
717}
718
719sub do_env_productionlist{
720 local($_) = @_;
721 my $lang = next_optional_argument();
722 my $filename = "grammar-$lang.txt";
723 if ($lang eq '') {
724 $filename = 'grammar.txt';
725 }
726 local($CURRENT_GRAMMAR) = $lang;
727 $DefinedGrammars{$lang} .= $_;
728 return ("<dl><dd class=\"grammar\">\n"
729 . "<div class=\"productions\">\n"
730 . "<table cellpadding=\"2\" valign=\"baseline\">\n"
731 . translate_commands(translate_environments($_))
732 . "</table>\n"
733 . "</div>\n"
734 . (($lang eq '*')
735 ? ''
736 : ("<a class=\"grammar-footer\"\n"
737 . " href=\"$filename\" type=\"text/plain\"\n"
738 . " >Download entire grammar as text.</a>\n"))
739 . "</dd></dl>");
740}
741
742sub do_cmd_production{
743 local($_) = @_;
744 my $token = next_argument();
745 my $defn = next_argument();
746 my $lang = $CURRENT_GRAMMAR;
747 local($CURRENT_TOKEN) = $token;
748 if ($lang eq '*') {
749 return ("<tr>\n"
750 . " <td><code>$token</code></td>\n"
751 . " <td>&nbsp;::=&nbsp;</td>\n"
752 . " <td><code>"
753 . translate_commands($defn)
754 . "</code></td></tr>"
755 . $_);
756 }
757 my $target;
758 if ($lang eq '') {
759 $target = "$CURRENT_FILE\#tok-$token";
760 }
761 else {
762 $target = "$CURRENT_FILE\#tok-$lang-$token";
763 }
764 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
765 return ("<tr>\n"
766 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
767 . " <td>&nbsp;::=&nbsp;</td>\n"
768 . " <td><code>"
769 . translate_commands($defn)
770 . "</code></td></tr>"
771 . $_);
772}
773
774sub process_grammar_files{
775 my $lang;
776 my $filename;
777 local($_);
778 print "process_grammar_files()\n";
779 foreach $lang (keys %DefinedGrammars) {
780 $filename = "grammar-$lang.txt";
781 if ($lang eq '*') {
782 next;
783 }
784 if ($lang eq '') {
785 $filename = 'grammar.txt';
786 }
787 open(GRAMMAR, ">$filename") || die "\n$!\n";
788 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
789 close(GRAMMAR);
790 print "Wrote grammar file $filename\n";
791 }
792 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
793 foreach $filename (keys %BackpatchGrammarFiles) {
794 print "\nBack-patching grammar links in $filename\n";
795 my $buffer;
796 open(GRAMMAR, "<$filename") || die "\n$!\n";
797 # read all of the file into the buffer
798 sysread(GRAMMAR, $buffer, 1024*1024);
799 close(GRAMMAR);
800 while ($buffer =~ /$PATTERN/) {
801 my($lang, $token) = ($1, $2);
802 my $target = $TokenToTargetMapping{"$lang:$token"};
803 my $source = "<pyGrammarToken><$lang><$token>";
804 $buffer =~ s/$source/$target/g;
805 }
806 open(GRAMMAR, ">$filename") || die "\n$!\n";
807 print GRAMMAR $buffer;
808 close(GRAMMAR);
809 }
810}
811
812sub strip_grammar_markup{
813 local($_) = @_;
814 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
815 s/\\token(<<\d+>>)(.+)\1/\2/g;
816 s/\\e([^a-zA-Z])/\\\1/g;
817 s/<<\d+>>//g;
818 s/;SPMgt;/>/g;
819 s/;SPMlt;/</g;
820 s/;SPMquot;/\"/g;
821 return $_;
822}
823
824
Fred Drakee15956b2000-04-03 04:51:13 +0000825$REFCOUNTS_LOADED = 0;
826
827sub load_refcounts{
828 $REFCOUNTS_LOADED = 1;
829
Fred Drakee15956b2000-04-03 04:51:13 +0000830 my $myname, $mydir, $myext;
831 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
832 chop $mydir; # remove trailing '/'
833 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
834 chop $mydir; # remove trailing '/'
835 $mydir = getcwd() . "$dd$mydir"
836 unless $mydir =~ s|^/|/|;
837 local $_;
838 my $filename = "$mydir${dd}api${dd}refcounts.dat";
839 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
840 print "[loading API refcount data]";
841 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000842 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000843 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
844 #print "\n$func($param) --> $count";
845 $REFCOUNTS{"$func:$param"} = $count;
846 }
847 }
848}
849
850sub get_refcount{
851 my ($func, $param) = @_;
852 load_refcounts()
853 unless $REFCOUNTS_LOADED;
854 return $REFCOUNTS{"$func:$param"};
855}
856
Fred Drake6659c301998-03-03 22:02:19 +0000857sub do_env_cfuncdesc{
858 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000859 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000860 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000861 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000862 my $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000863 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000864 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000865 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000866 my $result_rc = get_refcount($function_name, '');
867 my $rcinfo = '';
868 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000869 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000870 }
871 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000872 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000873 }
Fred Drakec2578c52000-04-10 18:26:45 +0000874 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000875 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000876 }
Fred Drakee15956b2000-04-03 04:51:13 +0000877 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000878 $rcinfo = ( "\n<div class=\"refcount-info\">"
879 . "\n <span class=\"label\">Return value:</span>"
880 . "\n <span class=\"value\">$rcinfo.</span>"
881 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000882 }
Fred Drakec612a142001-03-29 18:24:08 +0000883 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000884 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000885 . $_
886 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000887}
888
Fred Drakee15956b2000-04-03 04:51:13 +0000889sub do_env_csimplemacrodesc{
890 local($_) = @_;
891 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000892 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000893 return "<dl><dt><b>$idx</b>\n<dd>"
894 . $_
895 . '</dl>'
896}
897
Fred Drake6659c301998-03-03 22:02:19 +0000898sub do_env_ctypedesc{
899 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000900 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000901 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000902 $index_name = $type_name
903 unless $index_name;
904 my($name,$aname,$ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000905 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
906 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000907 . $_
908 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000909}
910
911sub do_env_cvardesc{
912 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000913 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000914 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000915 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000916 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000917 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000918 return "<dl><dt>$var_type <b>$idx</b>\n"
919 . '<dd>'
920 . $_
921 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000922}
923
Fred Drake3cdb89d2000-09-14 20:17:23 +0000924sub convert_args($){
925 local($IN_DESC_HANDLER) = 1;
926 local($_) = @_;
927 return translate_commands($_);
928}
929
Fred Drake6659c301998-03-03 22:02:19 +0000930sub do_env_funcdesc{
931 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000932 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000933 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000934 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
935 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +0000936 . get_indexsubitem());
937 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000938 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakec612a142001-03-29 18:24:08 +0000939 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000940}
941
942sub do_env_funcdescni{
943 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000944 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000945 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000946 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
Fred Drakec612a142001-03-29 18:24:08 +0000947 . "(<var>$arg_list</var>)\n"
Fred Drake90fdda51999-02-16 20:27:42 +0000948 . '<dd>'
949 . $_
950 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000951}
952
953sub do_cmd_funcline{
954 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000955 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000956 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000957 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000958 my $idx = make_str_index_entry($prefix . get_indexsubitem());
959 $prefix =~ s/\(\)//;
960
Fred Drakec612a142001-03-29 18:24:08 +0000961 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000962}
963
Fred Drake6b3fb781999-07-12 16:50:09 +0000964sub do_cmd_funclineni{
965 local($_) = @_;
966 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000967 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000968 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +0000969
Fred Drakec612a142001-03-29 18:24:08 +0000970 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +0000971}
972
Fred Drake6659c301998-03-03 22:02:19 +0000973# Change this flag to index the opcode entries. I don't think it's very
974# useful to index them, since they're only presented to describe the dis
975# module.
976#
977$INDEX_OPCODES = 0;
978
979sub do_env_opcodedesc{
980 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000981 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000982 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000983 my $idx;
984 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +0000985 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
986 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +0000987 $idx =~ s/ \(byte code instruction\)//;
988 }
989 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000990 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +0000991 }
992 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +0000993 if ($arg_list) {
994 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
995 }
Fred Drake62e43691998-08-10 19:40:44 +0000996 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000997}
998
999sub do_env_datadesc{
1000 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001001 my $dataname = next_argument();
1002 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001003 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001004 return "<dl><dt><b>$idx</b>\n<dd>"
1005 . $_
1006 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001007}
1008
1009sub do_env_datadescni{
1010 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001011 my $idx = next_argument();
1012 if (! $STRING_INDEX_TT) {
1013 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001014 }
Fred Drake62e43691998-08-10 19:40:44 +00001015 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001016}
1017
1018sub do_cmd_dataline{
1019 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001020 my $data_name = next_argument();
1021 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001022 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001023 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001024}
1025
Fred Drakeadb272c2000-04-10 17:47:14 +00001026sub do_cmd_datalineni{
1027 local($_) = @_;
1028 my $data_name = next_argument();
1029 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1030}
1031
Fred Drake42b31a51998-03-27 05:16:10 +00001032sub do_env_excdesc{
1033 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001034 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001035 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakeab357ec2001-03-02 18:57:05 +00001036 return "<dl><dt><b>exception $idx</b>\n<dd>" . $_ . '</dl>'
Fred Drake42b31a51998-03-27 05:16:10 +00001037}
1038
Fred Drake62e43691998-08-10 19:40:44 +00001039sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001040
1041
Fred Drake643d76d2000-09-09 06:07:37 +00001042sub handle_classlike_descriptor{
1043 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001044 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001045 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001046 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001047 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001048 $idx =~ s/ \(.*\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001049 return ("<dl><dt><b>$what $idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakeab357ec2001-03-02 18:57:05 +00001050 . $_
1051 . '</dl>');
Fred Drakec9a44381998-03-17 06:29:13 +00001052}
1053
Fred Drake643d76d2000-09-09 06:07:37 +00001054sub do_env_classdesc{
1055 return handle_classlike_descriptor(@_[0], "class");
1056}
1057
Fred Drake06a01e82001-05-11 01:00:30 +00001058sub do_env_classdescstar{
1059 local($_) = @_;
1060 $THIS_CLASS = next_argument();
1061 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001062 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001063 $idx =~ s/ \(.*\)//;
1064 return ("<dl><dt><b>class $idx</b>\n<dd>"
1065 . $_
1066 . '</dl>');
1067}
1068
Fred Drake643d76d2000-09-09 06:07:37 +00001069sub do_env_excclassdesc{
1070 return handle_classlike_descriptor(@_[0], "exception");
1071}
1072
Fred Drake42b31a51998-03-27 05:16:10 +00001073
1074sub do_env_methoddesc{
1075 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001076 my $class_name = next_optional_argument();
1077 $class_name = $THIS_CLASS
1078 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001079 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001080 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001081 my $extra = '';
1082 if ($class_name) {
1083 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001084 }
Fred Drakef1927a62001-06-20 21:29:30 +00001085 my $idx = make_str_index_entry(
1086 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001087 $idx =~ s/ \(.*\)//;
1088 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001089 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001090}
1091
1092
Fred Drake7d45f6d1999-01-05 14:39:27 +00001093sub do_cmd_methodline{
1094 local($_) = @_;
1095 my $class_name = next_optional_argument();
1096 $class_name = $THIS_CLASS
1097 unless $class_name;
1098 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001099 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001100 my $extra = '';
1101 if ($class_name) {
1102 $extra = " ($class_name method)";
1103 }
Fred Drakef1927a62001-06-20 21:29:30 +00001104 my $idx = make_str_index_entry(
1105 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001106 $idx =~ s/ \(.*\)//;
1107 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001108 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake7d45f6d1999-01-05 14:39:27 +00001109 . $_;
1110}
1111
1112
Fred Draked64a40d1998-09-10 18:59:13 +00001113sub do_cmd_methodlineni{
1114 local($_) = @_;
1115 next_optional_argument();
1116 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001117 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001118 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Draked64a40d1998-09-10 18:59:13 +00001119 . $_;
1120}
1121
Fred Drake42b31a51998-03-27 05:16:10 +00001122sub do_env_methoddescni{
1123 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001124 next_optional_argument();
1125 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001126 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001127 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001128 . $_
1129 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001130}
1131
1132
1133sub do_env_memberdesc{
1134 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001135 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001136 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001137 $class = $THIS_CLASS
1138 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001139 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001140 $extra = " ($class attribute)"
1141 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001142 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001143 $idx =~ s/ \(.*\)//;
1144 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001145 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001146}
1147
1148
Fred Drake5ccf3301998-04-17 20:04:09 +00001149sub do_cmd_memberline{
1150 local($_) = @_;
1151 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001152 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001153 $class = $THIS_CLASS
1154 unless $class;
1155 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001156 $extra = " ($class attribute)"
1157 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001158 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001159 $idx =~ s/ \(.*\)//;
1160 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001161 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001162}
1163
Fred Drakef269e592001-07-17 23:05:57 +00001164
Fred Drake42b31a51998-03-27 05:16:10 +00001165sub do_env_memberdescni{
1166 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001167 next_optional_argument();
1168 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001169 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001170 . $_
1171 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001172}
1173
1174
Fred Drake5ccf3301998-04-17 20:04:09 +00001175sub do_cmd_memberlineni{
1176 local($_) = @_;
1177 next_optional_argument();
1178 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001179 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001180}
1181
Fred Drakef269e592001-07-17 23:05:57 +00001182
1183@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001184
Fred Drakef74e5b71999-04-28 14:58:49 +00001185sub fix_font{
1186 # do a little magic on a font name to get the right behavior in the first
1187 # column of the output table
1188 my $font = @_[0];
1189 if ($font eq 'textrm') {
1190 $font = '';
1191 }
1192 elsif ($font eq 'file' || $font eq 'filenq') {
Fred Drakee15956b2000-04-03 04:51:13 +00001193 $font = 'tt class="file"';
1194 }
1195 elsif ($font eq 'member') {
1196 $font = 'tt class="member"';
Fred Drakef74e5b71999-04-28 14:58:49 +00001197 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001198 elsif ($font eq 'class') {
1199 $font = 'tt class="class"';
1200 }
Fred Drake7388f732000-06-28 21:06:08 +00001201 elsif ($font eq 'constant') {
1202 $font = 'tt class="constant"';
1203 }
Fred Drakecb0fc9c2000-08-09 13:45:04 +00001204 elsif ($font eq 'kbd') {
1205 $font = 'kbd';
1206 }
Fred Draked04592a2000-10-25 16:15:13 +00001207 elsif ($font eq 'programopt') {
1208 $font = 'b';
1209 }
Fred Drakeafc7ce12001-01-22 17:33:24 +00001210 elsif ($font eq 'exception') {
1211 $font = 'tt class="exception"';
1212 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001213 return $font;
1214}
1215
Fred Drakee15956b2000-04-03 04:51:13 +00001216sub figure_column_alignment{
1217 my $a = @_[0];
1218 my $mark = substr($a, 0, 1);
1219 my $r = '';
1220 if ($mark eq 'c')
1221 { $r = ' align="center"'; }
1222 elsif ($mark eq 'r')
1223 { $r = ' align="right"'; }
1224 elsif ($mark eq 'l')
1225 { $r = ' align="left"'; }
1226 elsif ($mark eq 'p')
1227 { $r = ' align="left"'; }
1228 return $r;
1229}
1230
Fred Drake6659c301998-03-03 22:02:19 +00001231sub setup_column_alignments{
1232 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001233 my($s1,$s2,$s3,$s4,$a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001234 my $a1 = figure_column_alignment($s1);
1235 my $a2 = figure_column_alignment($s2);
1236 my $a3 = figure_column_alignment($s3);
1237 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001238 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001239 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1240 $col_aligns[1] = "<td$a2>";
1241 $col_aligns[2] = "<td$a3>";
1242 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001243 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001244 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001245 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001246}
1247
1248sub get_table_col1_fonts{
1249 my $font = $globals{'lineifont'};
1250 my ($sfont,$efont) = ('', '');
1251 if ($font) {
1252 $sfont = "<$font>";
1253 $efont = "</$font>";
1254 $efont =~ s/ .*>/>/;
1255 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001256 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001257}
1258
1259sub do_env_tableii{
1260 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001261 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001262 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001263 my $h1 = next_argument();
1264 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001265 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001266 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001267 my $a1 = $col_aligns[0];
1268 my $a2 = $col_aligns[1];
1269 s/\\lineii</\\lineii[$a1|$a2]</g;
1270 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001271 . "\n <thead>"
1272 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001273 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1274 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001275 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001276 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001277 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001278 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001279 . "\n </tbody>"
1280 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001281}
1282
Fred Drakeda72b932000-09-21 15:58:02 +00001283sub do_env_longtableii{
1284 return do_env_tableii(@_);
1285}
1286
Fred Drake6659c301998-03-03 22:02:19 +00001287sub do_cmd_lineii{
1288 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001289 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001290 my $c1 = next_argument();
1291 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001292 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001293 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001294 $c2 = '&nbsp;' if ($c2 eq '');
1295 my($c1align,$c2align) = split('\|', $aligns);
1296 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001297 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001298 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001299 }
Fred Drakee15956b2000-04-03 04:51:13 +00001300 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1301 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001302 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001303}
1304
1305sub do_env_tableiii{
1306 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001307 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001308 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001309 my $h1 = next_argument();
1310 my $h2 = next_argument();
1311 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001312 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001313 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001314 my $a1 = $col_aligns[0];
1315 my $a2 = $col_aligns[1];
1316 my $a3 = $col_aligns[2];
1317 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1318 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001319 . "\n <thead>"
1320 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001321 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1322 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1323 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001324 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001325 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001326 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001327 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001328 . "\n </tbody>"
1329 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001330}
1331
Fred Drakeda72b932000-09-21 15:58:02 +00001332sub do_env_longtableiii{
1333 return do_env_tableiii(@_);
1334}
1335
Fred Drake6659c301998-03-03 22:02:19 +00001336sub do_cmd_lineiii{
1337 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001338 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001339 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001340 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001341 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001342 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001343 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001344 $c3 = '&nbsp;' if ($c3 eq '');
1345 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1346 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001347 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001348 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001349 }
Fred Drakee15956b2000-04-03 04:51:13 +00001350 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001351 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001352 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001353 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001354}
1355
Fred Drakea0f4c941998-07-24 22:16:04 +00001356sub do_env_tableiv{
1357 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001358 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001359 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001360 my $h1 = next_argument();
1361 my $h2 = next_argument();
1362 my $h3 = next_argument();
1363 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001364 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001365 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001366 my $a1 = $col_aligns[0];
1367 my $a2 = $col_aligns[1];
1368 my $a3 = $col_aligns[2];
1369 my $a4 = $col_aligns[3];
1370 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1371 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001372 . "\n <thead>"
1373 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001374 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1375 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1376 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1377 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001378 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001379 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001380 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001381 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001382 . "\n </tbody>"
1383 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001384}
1385
Fred Drakeda72b932000-09-21 15:58:02 +00001386sub do_env_longtableiv{
1387 return do_env_tableiv(@_);
1388}
1389
Fred Drakea0f4c941998-07-24 22:16:04 +00001390sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001391 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001392 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001393 my $c1 = next_argument();
1394 my $c2 = next_argument();
1395 my $c3 = next_argument();
1396 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001397 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001398 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001399 $c4 = '&nbsp;' if ($c4 eq '');
1400 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1401 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001402 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001403 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001404 }
Fred Drakee15956b2000-04-03 04:51:13 +00001405 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001406 . " $c2align$c2</td>\n"
1407 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001408 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001409 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001410}
1411
Fred Drakef269e592001-07-17 23:05:57 +00001412sub do_env_tablev{
1413 local($_) = @_;
1414 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1415 my $font = fix_font(next_argument());
1416 my $h1 = next_argument();
1417 my $h2 = next_argument();
1418 my $h3 = next_argument();
1419 my $h4 = next_argument();
1420 my $h5 = next_argument();
1421 s/[\s\n]+//;
1422 $globals{'lineifont'} = $font;
1423 my $a1 = $col_aligns[0];
1424 my $a2 = $col_aligns[1];
1425 my $a3 = $col_aligns[2];
1426 my $a4 = $col_aligns[3];
1427 my $a5 = $col_aligns[4];
1428 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1429 return '<table border align="center" style="border-collapse: collapse">'
1430 . "\n <thead>"
1431 . "\n <tr class=\"tableheader\">"
1432 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1433 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1434 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1435 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1436 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1437 . "\n </tr>"
1438 . "\n </thead>"
1439 . "\n <tbody valign=\"baseline\">"
1440 . $_
1441 . "\n </tbody>"
1442 . "\n</table>";
1443}
1444
1445sub do_env_longtablev{
1446 return do_env_tablev(@_);
1447}
1448
1449sub do_cmd_linev{
1450 local($_) = @_;
1451 my $aligns = next_optional_argument();
1452 my $c1 = next_argument();
1453 my $c2 = next_argument();
1454 my $c3 = next_argument();
1455 my $c4 = next_argument();
1456 my $c5 = next_argument();
1457 s/[\s\n]+//;
1458 my($sfont,$efont) = get_table_col1_fonts();
1459 $c5 = '&nbsp;' if ($c5 eq '');
1460 my($c1align,$c2align,$c3align,$c4align,$c5align) = split('\|', $aligns);
1461 my $padding = '';
1462 if ($c1align =~ /align="right"/ || $c1 eq '') {
1463 $padding = '&nbsp;';
1464 }
1465 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1466 . " $c2align$c2</td>\n"
1467 . " $c3align$c3</td>\n"
1468 . " $c4align$c4</td>\n"
1469 . " $c5align$c5</td>"
1470 . $_;
1471}
1472
Fred Drake3be20742000-08-31 06:22:54 +00001473
1474# These can be used to control the title page appearance;
1475# they need a little bit of documentation.
1476#
1477# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1478# $ICONSERVER directory, or include path information (other than "./"). The
1479# default image type will be assumed if an extension is not provided.
1480#
1481# If specified, the "title page" will contain two colums: one containing the
1482# title/author/etc., and the other containing the graphic. Use the other
1483# four variables listed here to control specific details of the layout; all
1484# are optional.
1485#
1486# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1487# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1488# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1489# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1490# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1491
1492sub make_my_titlepage() {
1493 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001494 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001495 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001496 }
1497 else {
1498 write_warnings("\nThis document has no title.");
1499 }
Fred Drake6659c301998-03-03 22:02:19 +00001500 if ($t_author) {
1501 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001502 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001503 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001504 "<b><font size=\"+2\">$t_author"
1505 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001506 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001507 }
1508 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001509 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1510 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001511 }
Fred Drake3be20742000-08-31 06:22:54 +00001512 }
1513 else {
1514 write_warnings("\nThere is no author for this document.");
1515 }
Fred Drake6659c301998-03-03 22:02:19 +00001516 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001517 $the_title .= "\n<p>$t_institute</p>";
1518 }
Fred Draked07868a1998-05-14 21:00:28 +00001519 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001520 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1521 }
Fred Drake6659c301998-03-03 22:02:19 +00001522 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001523 $the_title .= "\n<p><i>$t_affil</i></p>";
1524 }
Fred Drake6659c301998-03-03 22:02:19 +00001525 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001526 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001527 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001528 $the_title .= ('<strong>Release '
1529 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001530 }
Fred Drakede77bc52000-12-14 18:36:12 +00001531 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001532 }
1533 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001534 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001535 }
1536 else {
1537 $the_title .= "\n<p>";
1538 }
Fred Drake6659c301998-03-03 22:02:19 +00001539 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001540 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001541 }
1542 return $the_title;
1543}
1544
Fred Drake3be20742000-08-31 06:22:54 +00001545sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001546 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001547 my $graphic = "<td class=\"titlegraphic\"";
1548 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1549 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1550 $graphic .= "><img";
1551 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1552 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1553 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1554 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001555 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001556 return $graphic;
1557}
1558
1559sub do_cmd_maketitle {
1560 local($_) = @_;
1561 my $the_title = "\n<div class=\"titlepage\">";
1562 if ($TITLE_PAGE_GRAPHIC) {
1563 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1564 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1565 . "<tr align=\"right\">\n<td>"
1566 . make_my_titlepage()
1567 . "</td>\n"
1568 . make_my_titlegraphic()
1569 . "</tr>\n</table>");
1570 }
1571 else {
1572 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1573 . make_my_titlegraphic()
1574 . "<td>"
1575 . make_my_titlepage()
1576 . "</td></tr>\n</table>");
1577 }
1578 }
1579 else {
1580 $the_title .= ("\n<center>"
1581 . make_my_titlepage()
1582 . "\n</center>");
1583 }
1584 $the_title .= "\n</div>";
1585 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001586 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001587 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001588}
1589
1590
Fred Drake885215c1998-05-20 21:32:09 +00001591#
Fred Drakea0f4c941998-07-24 22:16:04 +00001592# Module synopsis support
1593#
1594
1595require SynopsisTable;
1596
Fred Drakef7685d71998-07-25 03:31:46 +00001597sub get_chapter_id(){
1598 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001599 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1600 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001601 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001602}
1603
Fred Drake643d76d2000-09-09 06:07:37 +00001604# 'chapter' => 'SynopsisTable instance'
1605%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001606
1607sub get_synopsis_table($){
1608 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001609 my $key;
1610 foreach $key (keys %ModuleSynopses) {
1611 if ($key eq $chap) {
1612 return $ModuleSynopses{$chap};
1613 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001614 }
Fred Drake643d76d2000-09-09 06:07:37 +00001615 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001616 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001617 return $st;
1618}
1619
Fred Drake62e43691998-08-10 19:40:44 +00001620sub do_cmd_moduleauthor{
1621 local($_) = @_;
1622 next_argument();
1623 next_argument();
1624 return $_;
1625}
1626
1627sub do_cmd_sectionauthor{
1628 local($_) = @_;
1629 next_argument();
1630 next_argument();
1631 return $_;
1632}
1633
Fred Drakea0f4c941998-07-24 22:16:04 +00001634sub do_cmd_declaremodule{
1635 local($_) = @_;
1636 my $key = next_optional_argument();
1637 my $type = next_argument();
1638 my $name = next_argument();
1639 my $st = get_synopsis_table(get_chapter_id());
1640 #
1641 $key = $name unless $key;
1642 $type = 'built-in' if $type eq 'builtin';
1643 $st->declare($name, $key, $type);
1644 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001645 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001646}
1647
1648sub do_cmd_modulesynopsis{
1649 local($_) = @_;
1650 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001651 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001652 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001653}
1654
1655sub do_cmd_localmoduletable{
1656 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001657 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001658 my $st = get_synopsis_table($chap);
1659 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001660 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001661}
1662
1663sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001664 my $key;
1665 my $st, $file;
1666 foreach $key (keys %ModuleSynopses) {
1667 $st = $ModuleSynopses{$key};
1668 $file = $st->get_file();
1669 if ($file) {
1670 process_localmoduletables_in_file($file);
1671 }
1672 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001673 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001674 }
1675 }
1676}
1677
1678sub process_localmoduletables_in_file{
1679 my $file = @_[0];
1680 open(MYFILE, "<$file");
1681 local($_);
1682 sysread(MYFILE, $_, 1024*1024);
1683 close(MYFILE);
1684 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001685 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001686 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001687 my $chap = $1;
1688 my $st = get_synopsis_table($chap);
1689 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001690 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001691 }
Fred Drake643d76d2000-09-09 06:07:37 +00001692 open(MYFILE,">$file");
1693 print MYFILE $_;
1694 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001695}
Fred Drake557460c1999-03-02 16:05:35 +00001696sub process_python_state{
1697 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001698 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001699}
Fred Drakea0f4c941998-07-24 22:16:04 +00001700
1701
1702#
1703# "See also:" -- references placed at the end of a \section
1704#
1705
1706sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001707 return ("<div class=\"seealso\">\n "
1708 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1709 . @_[0]
1710 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001711}
1712
1713sub do_cmd_seemodule{
1714 # Insert the right magic to jump to the module definition. This should
1715 # work most of the time, at least for repeat builds....
1716 local($_) = @_;
1717 my $key = next_optional_argument();
1718 my $module = next_argument();
1719 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001720 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001721 $key = $module
1722 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001723 if ($text =~ /\.$/) {
1724 $period = '';
1725 }
Fred Drakef1927a62001-06-20 21:29:30 +00001726 return ('<dl compact class="seemodule">'
1727 . "\n <dt>Module <b><tt class=\"module\">"
1728 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1729 . "\n <dd>$text$period\n </dl>"
1730 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001731}
1732
Fred Drakee0197bf2001-04-12 04:03:22 +00001733sub strip_html_markup($){
1734 my $str = @_[0];
1735 my $s = "$str";
1736 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1737 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1738 return $s;
1739}
1740
Fred Drake643d76d2000-09-09 06:07:37 +00001741sub handle_rfclike_reference{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001742 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001743 my $rfcnum = next_argument();
1744 my $title = next_argument();
1745 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001746 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001747 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001748 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001749 return '<dl compact class="seerfc">'
1750 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001751 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001752 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001753 . "\n <dd>$text\n </dl>"
1754 . $_;
1755}
1756
Fred Drake643d76d2000-09-09 06:07:37 +00001757sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001758 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001759}
1760
1761sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001762 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001763}
1764
Fred Drake48449982000-09-12 17:52:33 +00001765sub do_cmd_seetitle{
1766 local($_) = @_;
1767 my $url = next_optional_argument();
1768 my $title = next_argument();
1769 my $text = next_argument();
1770 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001771 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001772 return '<dl compact class="seetitle">'
1773 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001774 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001775 . "\n <dd>$text\n </dl>"
1776 . $_;
1777 }
1778 return '<dl compact class="seetitle">'
1779 . "\n <dt><em class=\"citetitle\""
1780 . "\n >$title</em>"
1781 . "\n <dd>$text\n </dl>"
1782 . $_;
1783}
1784
Fred Drakeef4d1112000-05-09 16:17:51 +00001785sub do_cmd_seeurl{
1786 local($_) = @_;
1787 my $url = next_argument();
1788 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001789 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001790 return '<dl compact class="seeurl">'
1791 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001792 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001793 . "\n <dd>$text\n </dl>"
1794 . $_;
1795}
1796
Fred Drakea0f4c941998-07-24 22:16:04 +00001797sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001798 local($_) = @_;
1799 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001800 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001801}
1802
1803
1804#
Fred Drake885215c1998-05-20 21:32:09 +00001805# Definition list support.
1806#
1807
1808sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001809 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001810}
1811
1812sub do_cmd_term{
1813 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001814 my $term = next_argument();
1815 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001816 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001817 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001818}
1819
1820
Fred Drake38178fd2000-09-22 17:05:04 +00001821# I don't recall exactly why this was needed, but it was very much needed.
1822# We'll see if anything breaks when I move the "code" line out -- some
1823# things broke with it in.
1824
1825#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001826process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001827declaremodule # [] # {} # {}
1828memberline # [] # {}
1829methodline # [] # {} # {}
1830modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001831platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001832samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001833setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001834withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001835_RAW_ARG_DEFERRED_CMDS_
1836
1837
Fred Drake86333602001-04-10 17:13:39 +00001838$alltt_start = '<dl><dd><pre class="verbatim">';
1839$alltt_end = '</pre></dl>';
1840
1841sub do_env_alltt {
1842 local ($_) = @_;
1843 local($closures,$reopens,@open_block_tags);
1844
1845 # get the tag-strings for all open tags
1846 local(@keep_open_tags) = @$open_tags_R;
1847 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1848
1849 # get the tags for text-level tags only
1850 $open_tags_R = [ @keep_open_tags ];
1851 local($local_closures, $local_reopens);
1852 ($local_closures, $local_reopens,@open_block_tags)
1853 = &preserve_open_block_tags
1854 if (@$open_tags_R);
1855
1856 $open_tags_R = [ @open_block_tags ];
1857
1858 do {
1859 local($open_tags_R) = [ @open_block_tags ];
1860 local(@save_open_tags) = ();
1861
1862 local($cnt) = ++$global{'max_id'};
1863 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1864 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1865
1866 $_ = &translate_environments($_);
1867 $_ = &translate_commands($_) if (/\\/);
1868
1869 # preserve space-runs, using &nbsp;
1870 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1871 s/(<BR>) /$1;SPMnbsp;/g;
1872
1873 $_ = join('', $closures, $alltt_start, $local_reopens
1874 , $_
1875 , &balance_tags() #, $local_closures
1876 , $alltt_end, $reopens);
1877 undef $open_tags_R; undef @save_open_tags;
1878 };
1879 $open_tags_R = [ @keep_open_tags ];
1880 $_;
1881}
1882
Fred Drake57e52ef2001-06-15 21:31:57 +00001883sub do_cmd_verbatiminput{
1884 local($_) = @_;
1885 my $fname = next_argument();
1886 my $file;
1887 my $found = 0;
1888 my $texpath;
1889 # Search TEXINPUTS for the input file, the way we're supposed to:
1890 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1891 $file = "$texpath$dd$fname";
1892 last if ($found = (-f $file));
1893 }
Fred Drake77602f22001-07-06 22:43:02 +00001894 my $srcname;
Fred Drake57e52ef2001-06-15 21:31:57 +00001895 my $text;
1896 if ($found) {
1897 open(MYFILE, "<$file") || die "\n$!\n";
1898 read(MYFILE, $text, 1024*1024);
1899 close(MYFILE);
Fred Drake77602f22001-07-06 22:43:02 +00001900 use File::Basename;
1901 my $srcdir, $srcext;
1902 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1903 open(MYFILE, ">$srcname.txt");
1904 print MYFILE $text;
1905 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00001906 #
1907 # These rewrites convert the raw text to something that will
1908 # be properly visible as HTML and also will pass through the
1909 # vagaries of conversion through LaTeX2HTML. The order in
1910 # which the specific rewrites are performed is significant.
1911 #
1912 $text =~ s/\&/\&amp;/g;
1913 # These need to happen before the normal < and > re-writes,
1914 # since we need to avoid LaTeX2HTML's attempt to perform
1915 # ligature processing without regard to context (since it
1916 # doesn't have font information).
1917 $text =~ s/--/-&\#45;/g;
1918 $text =~ s/<</\&lt;\&\#60;/g;
1919 $text =~ s/>>/\&gt;\&\#62;/g;
1920 # Just normal re-writes...
1921 $text =~ s/</\&lt;/g;
1922 $text =~ s/>/\&gt;/g;
1923 # These last isn't needed for the HTML, but is needed to get
1924 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1925 # of &sol; since many browsers don't support that.
1926 $text =~ s/\\/\&\#92;/g;
1927 }
1928 else {
1929 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1930 }
Fred Drake77602f22001-07-06 22:43:02 +00001931 return ('<dl><dd><pre class="verbatim">'
Fred Drake57e52ef2001-06-15 21:31:57 +00001932 . $text
Fred Drake77602f22001-07-06 22:43:02 +00001933 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1934 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1935 . ">Download as text.</a>"
1936 . "\n</div>\n</dd></dl>"
Fred Drake57e52ef2001-06-15 21:31:57 +00001937 . $_);
1938}
Fred Drake86333602001-04-10 17:13:39 +00001939
Fred Drake6659c301998-03-03 22:02:19 +000019401; # This must be the last line