blob: 3b551390c7e85d1f7ac076643d4e2c4365600a62 [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
2#
3# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
4#
5# Extension to LaTeX2HTML for documents using myformat.sty.
6# Subroutines of the form do_cmd_<name> here define translations
7# for LaTeX commands \<name> defined in the corresponding .sty file.
8
9package main;
10
Fred Drake7a40c072000-10-02 14:43:38 +000011use File::Basename;
12
Fred Drake6659c301998-03-03 22:02:19 +000013
Fred Drake08932051998-04-17 02:15:42 +000014sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000015 my $param;
16 $param = missing_braces()
17 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
18 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000019 return $param;
Fred Drake08932051998-04-17 02:15:42 +000020}
21
22sub next_optional_argument{
23 my($param,$rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000024 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000025 return $param;
Fred Drake08932051998-04-17 02:15:42 +000026}
27
Fred Drake7a40c072000-10-02 14:43:38 +000028sub make_icon_filename($){
29 my($myname, $mydir, $myext) = fileparse(@_[0], '\..*');
30 chop $mydir;
31 if ($mydir eq '.') {
32 $mydir = $ICONSERVER;
33 }
34 $myext = ".$IMAGE_TYPE"
35 unless $myext;
36 return "$mydir$dd$myname$myext";
37}
38
Fred Drake7a40c072000-10-02 14:43:38 +000039sub get_link_icon($){
40 my $url = @_[0];
41 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
42 # absolute URL; assume it points off-site
43 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
Fred Drakef1927a62001-06-20 21:29:30 +000044 return (" <img src=\"$icon\"\n"
45 . ' border="0" class="offsitelink"'
Fred Drake5f84c9b2000-10-03 06:05:25 +000046 . ($OFF_SITE_LINK_ICON_HEIGHT
Fred Drakef1927a62001-06-20 21:29:30 +000047 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000048 : '')
49 . ($OFF_SITE_LINK_ICON_WIDTH
Fred Drakef1927a62001-06-20 21:29:30 +000050 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000051 : '')
Fred Drakef1927a62001-06-20 21:29:30 +000052 . " alt=\"[off-site link]\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +000053 . " >");
54 }
55 return '';
56}
Fred Drakee16f6791998-05-15 04:28:37 +000057
58# This is a fairly simple hack; it supports \let when it is used to create
59# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000060# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000061#
62sub do_cmd_let{
63 local($_) = @_;
64 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000065 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000066 if ($matched) {
67 my($new, $old) = ($1, $3);
68 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
69 print "\ndefining handler for \\$new using \\$old\n";
70 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000071 else {
72 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
73 if ($matched) {
74 my($new, $char) = ($1, $3);
75 eval "sub do_cmd_$new { \"\\$char\" . \@_[0]; }";
76 print "\ndefining handler for \\$new to insert '$char'\n";
77 }
78 else {
79 write_warnings("Could not interpret \\let construct...");
80 }
81 }
Fred Drake62e43691998-08-10 19:40:44 +000082 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000083}
84
85
Fred Drakec3fd45f2000-06-15 22:41:48 +000086# the older version of LaTeX2HTML we use doesn't support this, but we use it:
87
88sub do_cmd_textasciitilde{ '~' . @_[0]; }
Fred Drake056a71d2001-04-21 05:48:07 +000089sub do_cmd_textasciicircum{ '^' . @_[0]; }
Fred Drake6fe46602001-06-23 03:13:30 +000090sub do_cmd_textbar{ '|' . @_[0]; }
91sub do_cmd_infinity{ '&infin;' . @_[0]; }
92sub do_cmd_plusminus{ '&plusmn;' . @_[0]; }
Fred Drake77602f22001-07-06 22:43:02 +000093sub do_cmd_menuselection{ @_[0]; }
94sub do_cmd_sub{ ' > ' . @_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +000095
96
Fred Drake6659c301998-03-03 22:02:19 +000097# words typeset in a special way (not in HTML though)
98
99sub do_cmd_ABC{ 'ABC' . @_[0]; }
100sub do_cmd_UNIX{ 'Unix'. @_[0]; }
101sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
102sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
103sub do_cmd_C{ 'C' . @_[0]; }
104sub do_cmd_Cpp{ 'C++' . @_[0]; }
105sub do_cmd_EOF{ 'EOF' . @_[0]; }
Fred Drakee15956b2000-04-03 04:51:13 +0000106sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000107
108sub do_cmd_e{ '&#92;' . @_[0]; }
109
Fred Draked07868a1998-05-14 21:00:28 +0000110$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000111$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000112$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000113$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000114
Fred Draked04592a2000-10-25 16:15:13 +0000115sub do_cmd_version{ $PACKAGE_VERSION . @_[0]; }
Fred Drake3cdb89d2000-09-14 20:17:23 +0000116sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000117sub do_cmd_release{
118 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000119 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000120 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000121}
122
Fred Drakef1927a62001-06-20 21:29:30 +0000123sub do_cmd_setreleaseinfo{
124 local($_) = @_;
125 $RELEASE_INFO = next_argument();
126 return $_;
127}
128
Fred Drake3cdb89d2000-09-14 20:17:23 +0000129sub do_cmd_setshortversion{
130 local($_) = @_;
131 $SHORT_VERSION = next_argument();
132 return $_;
133}
134
Fred Drake6659c301998-03-03 22:02:19 +0000135sub do_cmd_authoraddress{
136 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000137 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000138 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000139}
140
Fred Drakee16f6791998-05-15 04:28:37 +0000141#sub do_cmd_developer{ do_cmd_author(@_[0]); }
142#sub do_cmd_developers{ do_cmd_author(@_[0]); }
143#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000144
Fred Drake6659c301998-03-03 22:02:19 +0000145sub do_cmd_hackscore{
146 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000147 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000148 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000149}
150
Fred Drake08932051998-04-17 02:15:42 +0000151sub use_wrappers{
152 local($_,$before,$after) = @_;
153 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000154 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000155}
156
Fred Drake3cdb89d2000-09-14 20:17:23 +0000157$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000158sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000159 if ($IN_DESC_HANDLER) {
160 return use_wrappers(@_[0], "</var><big>\[</big><var>",
161 "</var><big>\]</big><var>");
162 }
163 else {
164 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
165 }
Fred Drake6659c301998-03-03 22:02:19 +0000166}
167
Fred Drakec9a44381998-03-17 06:29:13 +0000168# Logical formatting (some based on texinfo), needs to be converted to
169# minimalist HTML. The "minimalist" is primarily to reduce the size of
170# output files for users that read them over the network rather than
171# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000172
Fred Drake2cafcbb1999-03-25 16:57:04 +0000173# \file and \samp are at the end of this file since they screw up fontlock.
174
Fred Drake2ff880e1999-02-05 18:31:29 +0000175sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000176sub do_cmd_makevar{
177 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000178sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000179 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000180sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000181 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000182sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000183 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000185 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000186sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000187 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000188sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000189 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000191 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000193 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000194sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000195 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000197 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000199 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000201 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000203 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000205 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000207 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000208sub do_cmd_programopt{
209 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000210sub do_cmd_longprogramopt{
211 # note that the --- will be later converted to -- by LaTeX2HTML
212 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000213sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000214 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000215sub do_cmd_mailheader{
Fred Drake479384e2001-09-26 18:46:36 +0000216 return use_wrappers(@_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000218 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_var{
220 return use_wrappers(@_[0], "<var>", "</var>"); }
221sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000222 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000224 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000226 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000227sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000228 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000229sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000230 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000231sub do_cmd_kbd{
232 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
233sub do_cmd_strong{
234 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000235sub do_cmd_textbf{
236 return use_wrappers(@_[0], '<b>', '</b>'); }
237sub do_cmd_textit{
238 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000239# This can be changed/overridden for translations:
240%NoticeNames = ('note' => 'Note:',
241 'warning' => 'Warning:',
242 );
243
Fred Drake92350b32001-10-09 18:01:23 +0000244sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000245 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000246 return use_wrappers(
247 @_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000248 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000249 '</span>'); }
250sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000251 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000252 return use_wrappers(
253 @_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000254 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000255 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000256
Fred Drake6ca33772001-12-14 22:50:06 +0000257sub do_env_notice{
258 local($_) = @_;
259 my $notice = next_optional_argument();
260 if (!$notice) {
261 $notice = 'note';
262 }
263 my $label = $NoticeNames{$notice};
264 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
265 . $_
266 . '</div>');
267}
268
Fred Drake3d5a04a2000-08-03 17:25:44 +0000269sub do_cmd_moreargs{
270 return '...' . @_[0]; }
271sub do_cmd_unspecified{
272 return '...' . @_[0]; }
273
Fred Drakec9a44381998-03-17 06:29:13 +0000274
Fred Drake25817041999-01-13 17:06:34 +0000275sub do_cmd_refmodule{
276 # Insert the right magic to jump to the module definition.
277 local($_) = @_;
278 my $key = next_optional_argument();
279 my $module = next_argument();
280 $key = $module
281 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000282 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000283 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000284}
285
Fred Drake1a7af391998-04-01 22:44:56 +0000286sub do_cmd_newsgroup{
287 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000288 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000289 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000290 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
291 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000292 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000293}
Fred Drakefc16e781998-03-12 21:03:26 +0000294
295sub do_cmd_envvar{
296 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000297 my $envvar = next_argument();
298 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000299 # The <tt> here is really to keep buildindex.py from making
300 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000301 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000302 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000303 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000304 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000305 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000306}
307
Fred Drake6659c301998-03-03 22:02:19 +0000308sub do_cmd_url{
309 # use the URL as both text and hyperlink
310 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000311 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000312 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000313 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000314 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000315}
316
317sub do_cmd_manpage{
318 # two parameters: \manpage{name}{section}
319 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000320 my $page = next_argument();
321 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000322 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000323}
324
Fred Drakef1927a62001-06-20 21:29:30 +0000325$PEP_FORMAT = "http://python.sourceforge.net/peps/pep-%04d.html";
326#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
327$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000328
329sub get_rfc_url($$){
330 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000331 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000332}
333
334sub do_cmd_pep{
335 local($_) = @_;
336 my $rfcnumber = next_argument();
337 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000338 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000339 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000340 # Save the reference
341 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
342 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000343 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
344 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000345}
346
Fred Drake6659c301998-03-03 22:02:19 +0000347sub do_cmd_rfc{
348 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000349 my $rfcnumber = next_argument();
350 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000351 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000352 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000353 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000354 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000355 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000356 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
357 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000358}
359
Fred Drake77602f22001-07-06 22:43:02 +0000360sub do_cmd_ulink{
361 local($_) = @_;
362 my $text = next_argument();
363 my $url = next_argument();
364 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
365}
366
Fred Drakec9f5fe01999-11-09 16:59:42 +0000367sub do_cmd_citetitle{
368 local($_) = @_;
369 my $url = next_optional_argument();
370 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000371 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000372 my $repl = '';
373 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000374 $repl = ("<em class=\"citetitle\"><a\n"
375 . " href=\"$url\"\n"
376 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000377 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000378 }
379 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000380 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000381 }
382 return $repl . $_;
383}
384
Fred Drake6659c301998-03-03 22:02:19 +0000385sub do_cmd_deprecated{
386 # two parameters: \deprecated{version}{whattodo}
387 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000388 my $release = next_argument();
389 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000390 return ('<div class="versionnote">'
391 . "<b>Deprecated since release $release.</b>"
392 . "\n$reason</div><p>"
393 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000394}
395
Fred Drakec2b29d02001-04-18 03:11:04 +0000396sub versionnote{
397 # one or two parameters: \versionnote[explanation]{version}
398 my $type = @_[0];
399 local $_ = @_[1];
400 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000401 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000402 my $text = "$type in version $release.";
403 if ($explanation) {
404 $text = "$type in version $release:\n$explanation.";
405 }
Fred Drakef1927a62001-06-20 21:29:30 +0000406 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000407}
408
409sub do_cmd_versionadded{
410 return versionnote('New', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000411}
412
413sub do_cmd_versionchanged{
Fred Drakec2b29d02001-04-18 03:11:04 +0000414 return versionnote('Changed', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000415}
416
Fred Drake557460c1999-03-02 16:05:35 +0000417#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000418# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000419#
420sub do_cmd_platform{
421 local($_) = @_;
422 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000423 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000424 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000425 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000426 return "\n<p class=\"availability\">Availability: <span"
427 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000428}
429
Fred Drake557460c1999-03-02 16:05:35 +0000430$IGNORE_PLATFORM_ANNOTATION = '';
431sub do_cmd_ignorePlatformAnnotation{
432 local($_) = @_;
433 $IGNORE_PLATFORM_ANNOTATION = next_argument();
434 return $_;
435}
436
Fred Drake6659c301998-03-03 22:02:19 +0000437
438# index commands
439
440$INDEX_SUBITEM = "";
441
442sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000443 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000444}
445
446sub do_cmd_setindexsubitem{
447 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000448 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000449 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000450}
451
Fred Drakefc16e781998-03-12 21:03:26 +0000452sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000453 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000454 # do things in the right order, but we need to at least strip this stuff
455 # out, and leave anything that the second argument expanded out to.
456 #
457 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000458 my $oldsubitem = $INDEX_SUBITEM;
459 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000460 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000461 my $br_id = ++$globals{'max_id'};
462 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000463 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000464 return
465 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000466 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000467 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000468}
469
Fred Drake08932051998-04-17 02:15:42 +0000470# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000471# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
472# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000473#
Fred Drake62e43691998-08-10 19:40:44 +0000474sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000475
Fred Drake42b31a51998-03-27 05:16:10 +0000476# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000477#
Fred Drake08932051998-04-17 02:15:42 +0000478open(IDXFILE, '>index.dat') || die "\n$!\n";
479open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000480print INTLABELS "%internal_labels = ();\n";
481print INTLABELS "1; # hack in case there are no entries\n\n";
482
483# Using \0 for this is bad because we can't use common tools to work with the
484# resulting files. Things like grep can be useful with this stuff!
485#
486$IDXFILE_FIELD_SEP = "\1";
487
Fred Drakeccc62721999-01-05 22:16:29 +0000488sub write_idxfile{
489 my ($ahref, $str) = @_;
490 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000491}
492
Fred Drake42b31a51998-03-27 05:16:10 +0000493
494sub gen_link{
495 my($node,$target) = @_;
496 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000497 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000498}
499
Fred Drake42b31a51998-03-27 05:16:10 +0000500sub add_index_entry{
501 # add an entry to the index structures; ignore the return value
502 my($str,$ahref) = @_;
503 $str = gen_index_id($str, '');
504 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000505 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000506}
507
Fred Drakeccc62721999-01-05 22:16:29 +0000508sub new_link_info{
509 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000510 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000511 my $ahref = gen_link($CURRENT_FILE, $name);
512 return ($name, $aname, $ahref);
513}
514
Fred Drakeab032151999-05-13 18:36:54 +0000515$IndexMacroPattern = '';
516sub define_indexing_macro{
517 my $count = @_;
518 my $i = 0;
519 for (; $i < $count; ++$i) {
520 my $name = @_[$i];
521 my $cmd = "idx_cmd_$name";
522 die "\nNo function $cmd() defined!\n"
523 if (!defined &$cmd);
524 eval ("sub do_cmd_$name { return process_index_macros("
525 . "\@_[0], '$name'); }");
526 if (length($IndexMacroPattern) == 0) {
527 $IndexMacroPattern = "$name";
528 }
529 else {
530 $IndexMacroPattern .= "|$name";
531 }
532 }
533}
534
535$DEBUG_INDEXING = 0;
536sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000537 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000538 my $cmdname = @_[1]; # This is what triggered us in the first place;
539 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000540 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000541 my $cmd = "idx_cmd_$cmdname";
542 print "\nIndexing: \\$cmdname"
543 if $DEBUG_INDEXING;
544 &$cmd($ahref); # modifies $_ and adds index entries
545 while (/^[\s\n]*\\($IndexMacroPattern)</) {
546 $cmdname = "$1";
547 print " \\$cmdname"
548 if $DEBUG_INDEXING;
549 $cmd = "idx_cmd_$cmdname";
550 if (!defined &$cmd) {
551 last;
552 }
553 else {
554 s/^[\s\n]*\\$cmdname//;
555 &$cmd($ahref);
556 }
557 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000558 if (/^[ \t\r\n]/) {
559 $_ = substr($_, 1);
560 }
Fred Drake62e43691998-08-10 19:40:44 +0000561 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000562}
563
Fred Drakeab032151999-05-13 18:36:54 +0000564define_indexing_macro('index');
565sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000566 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000567 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000568}
569
Fred Drakeab032151999-05-13 18:36:54 +0000570define_indexing_macro('kwindex');
571sub idx_cmd_kwindex{
572 my $str = next_argument();
573 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
574 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
575}
576
577define_indexing_macro('indexii');
578sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000579 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000580 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000581 add_index_entry("$str1!$str2", @_[0]);
582 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000583}
584
Fred Drakeab032151999-05-13 18:36:54 +0000585define_indexing_macro('indexiii');
586sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000587 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000588 my $str2 = next_argument();
589 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000590 add_index_entry("$str1!$str2 $str3", @_[0]);
591 add_index_entry("$str2!$str3, $str1", @_[0]);
592 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000593}
594
Fred Drakeab032151999-05-13 18:36:54 +0000595define_indexing_macro('indexiv');
596sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000597 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000598 my $str2 = next_argument();
599 my $str3 = next_argument();
600 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000601 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
602 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
603 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
604 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000605}
606
Fred Drakeab032151999-05-13 18:36:54 +0000607define_indexing_macro('ttindex');
608sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000609 my $str = next_argument();
610 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000611 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000612}
Fred Drake6659c301998-03-03 22:02:19 +0000613
614sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000615 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000616 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000617 add_index_entry("$str $word", $ahref);
618 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000619}
620
Fred Drakeab032151999-05-13 18:36:54 +0000621define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
622sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
623sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
624sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
625sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000626
Fred Drakeab032151999-05-13 18:36:54 +0000627define_indexing_macro('bifuncindex');
628sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000629 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000630 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drakee15956b2000-04-03 04:51:13 +0000631 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000632}
633
634
Fred Drake6659c301998-03-03 22:02:19 +0000635sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000636 my($str,$define) = @_;
637 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000638 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000639 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
640 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000641 $str = gen_index_id($str, $define);
642 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000643 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000644
Fred Drakec9a44381998-03-17 06:29:13 +0000645 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000646 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000647 $str =~ /(<tt.*<\/tt>)/;
648 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000649 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000650 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000651 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000652}
653
Fred Drake557460c1999-03-02 16:05:35 +0000654
Fred Drakec9a44381998-03-17 06:29:13 +0000655$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000656$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000657
Fred Drakea0f4c941998-07-24 22:16:04 +0000658sub define_module{
659 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000660 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000661 if ($word ne "built-in" && $word ne "extension"
662 && $word ne "standard" && $word ne "") {
663 write_warnings("Bad module type '$word'"
664 . " for \\declaremodule (module $name)");
665 $word = "";
666 }
Fred Drake6659c301998-03-03 22:02:19 +0000667 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000668 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000669 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000670 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000671 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000672 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000673}
674
675sub my_module_index_helper{
676 local($word, $_) = @_;
677 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000678 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000679}
680
Fred Drake62e43691998-08-10 19:40:44 +0000681sub do_cmd_modindex{ return my_module_index_helper('', @_); }
682sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
683sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
684sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000685
Fred Drakeab032151999-05-13 18:36:54 +0000686sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000687 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000688 my $str = next_argument();
689 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000690 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000691 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
692 # just inline it all here
693 $str = gen_index_id($str, 'REF');
694 $index{$str} .= $ahref;
695 write_idxfile($ahref, $str);
696}
697
Fred Drake6659c301998-03-03 22:02:19 +0000698# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000699define_indexing_macro('refmodindex', 'refbimodindex',
700 'refexmodindex', 'refstmodindex');
701sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
702sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
703sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
704sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000705
Fred Drake62e43691998-08-10 19:40:44 +0000706sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000707
708sub init_myformat{
Fred Drakeafc7ce12001-01-22 17:33:24 +0000709 $anchor_invisible_mark = '&nbsp;';
710 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000711 $anchor_mark = '';
712 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000713}
Fred Drake42b31a51998-03-27 05:16:10 +0000714init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000715
Fred Drakeab032151999-05-13 18:36:54 +0000716# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000717# instead of the dummy filler.
718#
719sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000720 my($str) = @_;
721 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000722 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000723 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000724}
725
Fred Drake77602f22001-07-06 22:43:02 +0000726
727%TokenToTargetMapping = ();
728%DefinedGrammars = ();
729%BackpatchGrammarFiles = ();
730
731sub do_cmd_token{
732 local($_) = @_;
733 my $token = next_argument();
734 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
735 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
736 # recursive definition or display-only productionlist
737 return "$token";
738 }
739 if ($target eq '') {
740 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
741 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
742 print "Adding '$CURRENT_FILE' to back-patch list.\n";
743 }
744 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
745 }
746 return "<a href=\"$target\">$token</a>" . $_;
747}
748
Fred Drake16bb4192001-08-20 21:36:38 +0000749sub do_cmd_grammartoken{
750 return do_cmd_token(@_);
751}
752
Fred Drake77602f22001-07-06 22:43:02 +0000753sub do_env_productionlist{
754 local($_) = @_;
755 my $lang = next_optional_argument();
756 my $filename = "grammar-$lang.txt";
757 if ($lang eq '') {
758 $filename = 'grammar.txt';
759 }
760 local($CURRENT_GRAMMAR) = $lang;
761 $DefinedGrammars{$lang} .= $_;
762 return ("<dl><dd class=\"grammar\">\n"
763 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000764 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000765 . translate_commands(translate_environments($_))
766 . "</table>\n"
767 . "</div>\n"
768 . (($lang eq '*')
769 ? ''
770 : ("<a class=\"grammar-footer\"\n"
771 . " href=\"$filename\" type=\"text/plain\"\n"
772 . " >Download entire grammar as text.</a>\n"))
773 . "</dd></dl>");
774}
775
776sub do_cmd_production{
777 local($_) = @_;
778 my $token = next_argument();
779 my $defn = next_argument();
780 my $lang = $CURRENT_GRAMMAR;
781 local($CURRENT_TOKEN) = $token;
782 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000783 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000784 . " <td><code>$token</code></td>\n"
785 . " <td>&nbsp;::=&nbsp;</td>\n"
786 . " <td><code>"
787 . translate_commands($defn)
788 . "</code></td></tr>"
789 . $_);
790 }
791 my $target;
792 if ($lang eq '') {
793 $target = "$CURRENT_FILE\#tok-$token";
794 }
795 else {
796 $target = "$CURRENT_FILE\#tok-$lang-$token";
797 }
798 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000799 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000800 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
801 . " <td>&nbsp;::=&nbsp;</td>\n"
802 . " <td><code>"
803 . translate_commands($defn)
804 . "</code></td></tr>"
805 . $_);
806}
807
808sub process_grammar_files{
809 my $lang;
810 my $filename;
811 local($_);
812 print "process_grammar_files()\n";
813 foreach $lang (keys %DefinedGrammars) {
814 $filename = "grammar-$lang.txt";
815 if ($lang eq '*') {
816 next;
817 }
818 if ($lang eq '') {
819 $filename = 'grammar.txt';
820 }
821 open(GRAMMAR, ">$filename") || die "\n$!\n";
822 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
823 close(GRAMMAR);
824 print "Wrote grammar file $filename\n";
825 }
826 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
827 foreach $filename (keys %BackpatchGrammarFiles) {
828 print "\nBack-patching grammar links in $filename\n";
829 my $buffer;
830 open(GRAMMAR, "<$filename") || die "\n$!\n";
831 # read all of the file into the buffer
832 sysread(GRAMMAR, $buffer, 1024*1024);
833 close(GRAMMAR);
834 while ($buffer =~ /$PATTERN/) {
835 my($lang, $token) = ($1, $2);
836 my $target = $TokenToTargetMapping{"$lang:$token"};
837 my $source = "<pyGrammarToken><$lang><$token>";
838 $buffer =~ s/$source/$target/g;
839 }
840 open(GRAMMAR, ">$filename") || die "\n$!\n";
841 print GRAMMAR $buffer;
842 close(GRAMMAR);
843 }
844}
845
846sub strip_grammar_markup{
847 local($_) = @_;
848 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
849 s/\\token(<<\d+>>)(.+)\1/\2/g;
850 s/\\e([^a-zA-Z])/\\\1/g;
851 s/<<\d+>>//g;
852 s/;SPMgt;/>/g;
853 s/;SPMlt;/</g;
854 s/;SPMquot;/\"/g;
855 return $_;
856}
857
858
Fred Drakee15956b2000-04-03 04:51:13 +0000859$REFCOUNTS_LOADED = 0;
860
861sub load_refcounts{
862 $REFCOUNTS_LOADED = 1;
863
Fred Drakee15956b2000-04-03 04:51:13 +0000864 my $myname, $mydir, $myext;
865 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
866 chop $mydir; # remove trailing '/'
867 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
868 chop $mydir; # remove trailing '/'
869 $mydir = getcwd() . "$dd$mydir"
870 unless $mydir =~ s|^/|/|;
871 local $_;
872 my $filename = "$mydir${dd}api${dd}refcounts.dat";
873 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
874 print "[loading API refcount data]";
875 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000876 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000877 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
878 #print "\n$func($param) --> $count";
879 $REFCOUNTS{"$func:$param"} = $count;
880 }
881 }
882}
883
884sub get_refcount{
885 my ($func, $param) = @_;
886 load_refcounts()
887 unless $REFCOUNTS_LOADED;
888 return $REFCOUNTS{"$func:$param"};
889}
890
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000891
892$TLSTART = '<span class="typelabel">';
893$TLEND = '</span>';
894
Fred Drake6659c301998-03-03 22:02:19 +0000895sub do_env_cfuncdesc{
896 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000897 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000898 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000899 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000900 my $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000901 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000902 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000903 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000904 my $result_rc = get_refcount($function_name, '');
905 my $rcinfo = '';
906 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000907 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000908 }
909 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000910 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000911 }
Fred Drakec2578c52000-04-10 18:26:45 +0000912 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000913 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000914 }
Fred Drakee15956b2000-04-03 04:51:13 +0000915 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000916 $rcinfo = ( "\n<div class=\"refcount-info\">"
917 . "\n <span class=\"label\">Return value:</span>"
918 . "\n <span class=\"value\">$rcinfo.</span>"
919 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000920 }
Fred Drakec612a142001-03-29 18:24:08 +0000921 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000922 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000923 . $_
924 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000925}
926
Fred Drakee15956b2000-04-03 04:51:13 +0000927sub do_env_csimplemacrodesc{
928 local($_) = @_;
929 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000930 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000931 return "<dl><dt><b>$idx</b>\n<dd>"
932 . $_
933 . '</dl>'
934}
935
Fred Drake6659c301998-03-03 22:02:19 +0000936sub do_env_ctypedesc{
937 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000938 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000939 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000940 $index_name = $type_name
941 unless $index_name;
942 my($name,$aname,$ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000943 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
944 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000945 . $_
946 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000947}
948
949sub do_env_cvardesc{
950 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000951 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000952 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000953 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000954 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000955 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000956 return "<dl><dt>$var_type <b>$idx</b>\n"
957 . '<dd>'
958 . $_
959 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000960}
961
Fred Drake3cdb89d2000-09-14 20:17:23 +0000962sub convert_args($){
963 local($IN_DESC_HANDLER) = 1;
964 local($_) = @_;
965 return translate_commands($_);
966}
967
Fred Drake6659c301998-03-03 22:02:19 +0000968sub do_env_funcdesc{
969 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000970 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000971 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000972 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
973 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +0000974 . get_indexsubitem());
975 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000976 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakec612a142001-03-29 18:24:08 +0000977 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000978}
979
980sub do_env_funcdescni{
981 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000982 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000983 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000984 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
Fred Drakec612a142001-03-29 18:24:08 +0000985 . "(<var>$arg_list</var>)\n"
Fred Drake90fdda51999-02-16 20:27:42 +0000986 . '<dd>'
987 . $_
988 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000989}
990
991sub do_cmd_funcline{
992 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000993 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000994 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000995 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000996 my $idx = make_str_index_entry($prefix . get_indexsubitem());
997 $prefix =~ s/\(\)//;
998
Fred Drakec612a142001-03-29 18:24:08 +0000999 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001000}
1001
Fred Drake6b3fb781999-07-12 16:50:09 +00001002sub do_cmd_funclineni{
1003 local($_) = @_;
1004 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001005 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001006 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001007
Fred Drakec612a142001-03-29 18:24:08 +00001008 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001009}
1010
Fred Drake6659c301998-03-03 22:02:19 +00001011# Change this flag to index the opcode entries. I don't think it's very
1012# useful to index them, since they're only presented to describe the dis
1013# module.
1014#
1015$INDEX_OPCODES = 0;
1016
1017sub do_env_opcodedesc{
1018 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001019 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001020 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001021 my $idx;
1022 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001023 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1024 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001025 $idx =~ s/ \(byte code instruction\)//;
1026 }
1027 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001028 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001029 }
1030 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001031 if ($arg_list) {
1032 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1033 }
Fred Drake62e43691998-08-10 19:40:44 +00001034 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001035}
1036
1037sub do_env_datadesc{
1038 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001039 my $dataname = next_argument();
1040 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001041 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001042 return "<dl><dt><b>$idx</b>\n<dd>"
1043 . $_
1044 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001045}
1046
1047sub do_env_datadescni{
1048 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001049 my $idx = next_argument();
1050 if (! $STRING_INDEX_TT) {
1051 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001052 }
Fred Drake62e43691998-08-10 19:40:44 +00001053 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001054}
1055
1056sub do_cmd_dataline{
1057 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001058 my $data_name = next_argument();
1059 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001060 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001061 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001062}
1063
Fred Drakeadb272c2000-04-10 17:47:14 +00001064sub do_cmd_datalineni{
1065 local($_) = @_;
1066 my $data_name = next_argument();
1067 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1068}
1069
Fred Drake42b31a51998-03-27 05:16:10 +00001070sub do_env_excdesc{
1071 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001072 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001073 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001074 return ("<dl><dt><b>${TLSTART}exception$TLEND $idx</b>"
1075 . "\n<dd>"
1076 . $_
1077 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001078}
1079
Fred Drake62e43691998-08-10 19:40:44 +00001080sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001081
1082
Fred Drake643d76d2000-09-09 06:07:37 +00001083sub handle_classlike_descriptor{
1084 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001085 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001086 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001087 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001088 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001089 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001090 return ("<dl><dt><b>$TLSTART$what$TLEND $idx</b>"
1091 . "(<var>$arg_list</var>)\n<dd>"
Fred Drakeab357ec2001-03-02 18:57:05 +00001092 . $_
1093 . '</dl>');
Fred Drakec9a44381998-03-17 06:29:13 +00001094}
1095
Fred Drake643d76d2000-09-09 06:07:37 +00001096sub do_env_classdesc{
1097 return handle_classlike_descriptor(@_[0], "class");
1098}
1099
Fred Drake06a01e82001-05-11 01:00:30 +00001100sub do_env_classdescstar{
1101 local($_) = @_;
1102 $THIS_CLASS = next_argument();
1103 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001104 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001105 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001106 return ("<dl><dt><b>${TLSTART}class$TLEND $idx</b>\n<dd>"
Fred Drake06a01e82001-05-11 01:00:30 +00001107 . $_
1108 . '</dl>');
1109}
1110
Fred Drake643d76d2000-09-09 06:07:37 +00001111sub do_env_excclassdesc{
1112 return handle_classlike_descriptor(@_[0], "exception");
1113}
1114
Fred Drake42b31a51998-03-27 05:16:10 +00001115
1116sub do_env_methoddesc{
1117 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001118 my $class_name = next_optional_argument();
1119 $class_name = $THIS_CLASS
1120 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001121 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001122 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001123 my $extra = '';
1124 if ($class_name) {
1125 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001126 }
Fred Drakef1927a62001-06-20 21:29:30 +00001127 my $idx = make_str_index_entry(
1128 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001129 $idx =~ s/ \(.*\)//;
1130 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001131 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001132}
1133
1134
Fred Drake7d45f6d1999-01-05 14:39:27 +00001135sub do_cmd_methodline{
1136 local($_) = @_;
1137 my $class_name = next_optional_argument();
1138 $class_name = $THIS_CLASS
1139 unless $class_name;
1140 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001141 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001142 my $extra = '';
1143 if ($class_name) {
1144 $extra = " ($class_name method)";
1145 }
Fred Drakef1927a62001-06-20 21:29:30 +00001146 my $idx = make_str_index_entry(
1147 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001148 $idx =~ s/ \(.*\)//;
1149 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001150 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake7d45f6d1999-01-05 14:39:27 +00001151 . $_;
1152}
1153
1154
Fred Draked64a40d1998-09-10 18:59:13 +00001155sub do_cmd_methodlineni{
1156 local($_) = @_;
1157 next_optional_argument();
1158 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001159 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001160 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Draked64a40d1998-09-10 18:59:13 +00001161 . $_;
1162}
1163
Fred Drake42b31a51998-03-27 05:16:10 +00001164sub do_env_methoddescni{
1165 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001166 next_optional_argument();
1167 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001168 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001169 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001170 . $_
1171 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001172}
1173
1174
1175sub do_env_memberdesc{
1176 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001177 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001178 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001179 $class = $THIS_CLASS
1180 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001181 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001182 $extra = " ($class attribute)"
1183 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001184 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001185 $idx =~ s/ \(.*\)//;
1186 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001187 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001188}
1189
1190
Fred Drake5ccf3301998-04-17 20:04:09 +00001191sub do_cmd_memberline{
1192 local($_) = @_;
1193 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001194 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001195 $class = $THIS_CLASS
1196 unless $class;
1197 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001198 $extra = " ($class attribute)"
1199 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001200 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001201 $idx =~ s/ \(.*\)//;
1202 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001203 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001204}
1205
Fred Drakef269e592001-07-17 23:05:57 +00001206
Fred Drake42b31a51998-03-27 05:16:10 +00001207sub do_env_memberdescni{
1208 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001209 next_optional_argument();
1210 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001211 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001212 . $_
1213 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001214}
1215
1216
Fred Drake5ccf3301998-04-17 20:04:09 +00001217sub do_cmd_memberlineni{
1218 local($_) = @_;
1219 next_optional_argument();
1220 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001221 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001222}
1223
Fred Drakef269e592001-07-17 23:05:57 +00001224
1225@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001226
Fred Drakecb199762001-08-16 21:56:24 +00001227%FontConversions = ('cdata' => 'tt class="cdata"',
1228 'character' => 'tt class="character"',
1229 'class' => 'tt class="class"',
1230 'command' => 'code',
1231 'constant' => 'tt class="constant"',
1232 'exception' => 'tt class="exception"',
1233 'file' => 'tt class="file"',
1234 'filenq' => 'tt class="file"',
1235 'kbd' => 'kbd',
1236 'member' => 'tt class="member"',
1237 'programopt' => 'b',
1238 'textrm' => '',
1239 );
1240
Fred Drakef74e5b71999-04-28 14:58:49 +00001241sub fix_font{
1242 # do a little magic on a font name to get the right behavior in the first
1243 # column of the output table
1244 my $font = @_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001245 if (defined $FontConversions{$font}) {
1246 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001247 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001248 return $font;
1249}
1250
Fred Drakee15956b2000-04-03 04:51:13 +00001251sub figure_column_alignment{
1252 my $a = @_[0];
1253 my $mark = substr($a, 0, 1);
1254 my $r = '';
1255 if ($mark eq 'c')
1256 { $r = ' align="center"'; }
1257 elsif ($mark eq 'r')
1258 { $r = ' align="right"'; }
1259 elsif ($mark eq 'l')
1260 { $r = ' align="left"'; }
1261 elsif ($mark eq 'p')
1262 { $r = ' align="left"'; }
1263 return $r;
1264}
1265
Fred Drake6659c301998-03-03 22:02:19 +00001266sub setup_column_alignments{
1267 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001268 my($s1,$s2,$s3,$s4,$a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001269 my $a1 = figure_column_alignment($s1);
1270 my $a2 = figure_column_alignment($s2);
1271 my $a3 = figure_column_alignment($s3);
1272 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001273 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001274 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1275 $col_aligns[1] = "<td$a2>";
1276 $col_aligns[2] = "<td$a3>";
1277 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001278 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001279 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001280 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001281}
1282
1283sub get_table_col1_fonts{
1284 my $font = $globals{'lineifont'};
1285 my ($sfont,$efont) = ('', '');
1286 if ($font) {
1287 $sfont = "<$font>";
1288 $efont = "</$font>";
1289 $efont =~ s/ .*>/>/;
1290 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001291 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001292}
1293
1294sub do_env_tableii{
1295 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001296 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001297 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001298 my $h1 = next_argument();
1299 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001300 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001301 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001302 my $a1 = $col_aligns[0];
1303 my $a2 = $col_aligns[1];
1304 s/\\lineii</\\lineii[$a1|$a2]</g;
1305 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001306 . "\n <thead>"
1307 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001308 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1309 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001310 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001311 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001312 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001313 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001314 . "\n </tbody>"
1315 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001316}
1317
Fred Drakeda72b932000-09-21 15:58:02 +00001318sub do_env_longtableii{
1319 return do_env_tableii(@_);
1320}
1321
Fred Drake6659c301998-03-03 22:02:19 +00001322sub do_cmd_lineii{
1323 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001324 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001325 my $c1 = next_argument();
1326 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001327 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001328 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001329 $c2 = '&nbsp;' if ($c2 eq '');
1330 my($c1align,$c2align) = split('\|', $aligns);
1331 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001332 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001333 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001334 }
Fred Drakee15956b2000-04-03 04:51:13 +00001335 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1336 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001337 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001338}
1339
1340sub do_env_tableiii{
1341 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001342 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001343 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001344 my $h1 = next_argument();
1345 my $h2 = next_argument();
1346 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001347 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001348 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001349 my $a1 = $col_aligns[0];
1350 my $a2 = $col_aligns[1];
1351 my $a3 = $col_aligns[2];
1352 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1353 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001354 . "\n <thead>"
1355 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001356 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1357 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1358 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001359 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001360 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001361 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001362 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001363 . "\n </tbody>"
1364 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001365}
1366
Fred Drakeda72b932000-09-21 15:58:02 +00001367sub do_env_longtableiii{
1368 return do_env_tableiii(@_);
1369}
1370
Fred Drake6659c301998-03-03 22:02:19 +00001371sub do_cmd_lineiii{
1372 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001373 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001374 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001375 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001376 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001377 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001378 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001379 $c3 = '&nbsp;' if ($c3 eq '');
1380 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1381 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001382 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001383 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001384 }
Fred Drakee15956b2000-04-03 04:51:13 +00001385 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001386 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001387 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001388 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001389}
1390
Fred Drakea0f4c941998-07-24 22:16:04 +00001391sub do_env_tableiv{
1392 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001393 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001394 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001395 my $h1 = next_argument();
1396 my $h2 = next_argument();
1397 my $h3 = next_argument();
1398 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001399 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001400 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001401 my $a1 = $col_aligns[0];
1402 my $a2 = $col_aligns[1];
1403 my $a3 = $col_aligns[2];
1404 my $a4 = $col_aligns[3];
1405 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1406 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001407 . "\n <thead>"
1408 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001409 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1410 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1411 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1412 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001413 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001414 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001415 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001416 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001417 . "\n </tbody>"
1418 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001419}
1420
Fred Drakeda72b932000-09-21 15:58:02 +00001421sub do_env_longtableiv{
1422 return do_env_tableiv(@_);
1423}
1424
Fred Drakea0f4c941998-07-24 22:16:04 +00001425sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001426 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001427 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001428 my $c1 = next_argument();
1429 my $c2 = next_argument();
1430 my $c3 = next_argument();
1431 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001432 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001433 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001434 $c4 = '&nbsp;' if ($c4 eq '');
1435 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1436 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001437 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001438 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001439 }
Fred Drakee15956b2000-04-03 04:51:13 +00001440 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001441 . " $c2align$c2</td>\n"
1442 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001443 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001444 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001445}
1446
Fred Drakef269e592001-07-17 23:05:57 +00001447sub do_env_tablev{
1448 local($_) = @_;
1449 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1450 my $font = fix_font(next_argument());
1451 my $h1 = next_argument();
1452 my $h2 = next_argument();
1453 my $h3 = next_argument();
1454 my $h4 = next_argument();
1455 my $h5 = next_argument();
1456 s/[\s\n]+//;
1457 $globals{'lineifont'} = $font;
1458 my $a1 = $col_aligns[0];
1459 my $a2 = $col_aligns[1];
1460 my $a3 = $col_aligns[2];
1461 my $a4 = $col_aligns[3];
1462 my $a5 = $col_aligns[4];
1463 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1464 return '<table border align="center" style="border-collapse: collapse">'
1465 . "\n <thead>"
1466 . "\n <tr class=\"tableheader\">"
1467 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1468 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1469 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1470 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1471 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1472 . "\n </tr>"
1473 . "\n </thead>"
1474 . "\n <tbody valign=\"baseline\">"
1475 . $_
1476 . "\n </tbody>"
1477 . "\n</table>";
1478}
1479
1480sub do_env_longtablev{
1481 return do_env_tablev(@_);
1482}
1483
1484sub do_cmd_linev{
1485 local($_) = @_;
1486 my $aligns = next_optional_argument();
1487 my $c1 = next_argument();
1488 my $c2 = next_argument();
1489 my $c3 = next_argument();
1490 my $c4 = next_argument();
1491 my $c5 = next_argument();
1492 s/[\s\n]+//;
1493 my($sfont,$efont) = get_table_col1_fonts();
1494 $c5 = '&nbsp;' if ($c5 eq '');
1495 my($c1align,$c2align,$c3align,$c4align,$c5align) = split('\|', $aligns);
1496 my $padding = '';
1497 if ($c1align =~ /align="right"/ || $c1 eq '') {
1498 $padding = '&nbsp;';
1499 }
1500 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1501 . " $c2align$c2</td>\n"
1502 . " $c3align$c3</td>\n"
1503 . " $c4align$c4</td>\n"
1504 . " $c5align$c5</td>"
1505 . $_;
1506}
1507
Fred Drake3be20742000-08-31 06:22:54 +00001508
1509# These can be used to control the title page appearance;
1510# they need a little bit of documentation.
1511#
1512# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1513# $ICONSERVER directory, or include path information (other than "./"). The
1514# default image type will be assumed if an extension is not provided.
1515#
1516# If specified, the "title page" will contain two colums: one containing the
1517# title/author/etc., and the other containing the graphic. Use the other
1518# four variables listed here to control specific details of the layout; all
1519# are optional.
1520#
1521# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1522# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1523# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1524# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1525# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1526
1527sub make_my_titlepage() {
1528 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001529 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001530 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001531 }
1532 else {
1533 write_warnings("\nThis document has no title.");
1534 }
Fred Drake6659c301998-03-03 22:02:19 +00001535 if ($t_author) {
1536 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001537 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001538 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001539 "<b><font size=\"+2\">$t_author"
1540 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001541 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001542 }
1543 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001544 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1545 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001546 }
Fred Drake3be20742000-08-31 06:22:54 +00001547 }
1548 else {
1549 write_warnings("\nThere is no author for this document.");
1550 }
Fred Drake6659c301998-03-03 22:02:19 +00001551 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001552 $the_title .= "\n<p>$t_institute</p>";
1553 }
Fred Draked07868a1998-05-14 21:00:28 +00001554 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001555 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1556 }
Fred Drake6659c301998-03-03 22:02:19 +00001557 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001558 $the_title .= "\n<p><i>$t_affil</i></p>";
1559 }
Fred Drake6659c301998-03-03 22:02:19 +00001560 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001561 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001562 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001563 $the_title .= ('<strong>Release '
1564 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001565 }
Fred Drakede77bc52000-12-14 18:36:12 +00001566 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001567 }
1568 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001569 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001570 }
1571 else {
1572 $the_title .= "\n<p>";
1573 }
Fred Drake6659c301998-03-03 22:02:19 +00001574 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001575 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001576 }
1577 return $the_title;
1578}
1579
Fred Drake3be20742000-08-31 06:22:54 +00001580sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001581 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001582 my $graphic = "<td class=\"titlegraphic\"";
1583 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1584 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1585 $graphic .= "><img";
1586 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1587 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1588 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1589 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001590 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001591 return $graphic;
1592}
1593
1594sub do_cmd_maketitle {
1595 local($_) = @_;
1596 my $the_title = "\n<div class=\"titlepage\">";
1597 if ($TITLE_PAGE_GRAPHIC) {
1598 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1599 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1600 . "<tr align=\"right\">\n<td>"
1601 . make_my_titlepage()
1602 . "</td>\n"
1603 . make_my_titlegraphic()
1604 . "</tr>\n</table>");
1605 }
1606 else {
1607 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1608 . make_my_titlegraphic()
1609 . "<td>"
1610 . make_my_titlepage()
1611 . "</td></tr>\n</table>");
1612 }
1613 }
1614 else {
1615 $the_title .= ("\n<center>"
1616 . make_my_titlepage()
1617 . "\n</center>");
1618 }
1619 $the_title .= "\n</div>";
1620 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001621 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001622 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001623}
1624
1625
Fred Drake885215c1998-05-20 21:32:09 +00001626#
Fred Drakea0f4c941998-07-24 22:16:04 +00001627# Module synopsis support
1628#
1629
1630require SynopsisTable;
1631
Fred Drakef7685d71998-07-25 03:31:46 +00001632sub get_chapter_id(){
1633 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001634 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1635 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001636 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001637}
1638
Fred Drake643d76d2000-09-09 06:07:37 +00001639# 'chapter' => 'SynopsisTable instance'
1640%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001641
1642sub get_synopsis_table($){
1643 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001644 my $key;
1645 foreach $key (keys %ModuleSynopses) {
1646 if ($key eq $chap) {
1647 return $ModuleSynopses{$chap};
1648 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001649 }
Fred Drake643d76d2000-09-09 06:07:37 +00001650 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001651 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001652 return $st;
1653}
1654
Fred Drake62e43691998-08-10 19:40:44 +00001655sub do_cmd_moduleauthor{
1656 local($_) = @_;
1657 next_argument();
1658 next_argument();
1659 return $_;
1660}
1661
1662sub do_cmd_sectionauthor{
1663 local($_) = @_;
1664 next_argument();
1665 next_argument();
1666 return $_;
1667}
1668
Fred Drakea0f4c941998-07-24 22:16:04 +00001669sub do_cmd_declaremodule{
1670 local($_) = @_;
1671 my $key = next_optional_argument();
1672 my $type = next_argument();
1673 my $name = next_argument();
1674 my $st = get_synopsis_table(get_chapter_id());
1675 #
1676 $key = $name unless $key;
1677 $type = 'built-in' if $type eq 'builtin';
1678 $st->declare($name, $key, $type);
1679 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001680 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001681}
1682
1683sub do_cmd_modulesynopsis{
1684 local($_) = @_;
1685 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001686 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001687 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001688}
1689
1690sub do_cmd_localmoduletable{
1691 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001692 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001693 my $st = get_synopsis_table($chap);
1694 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001695 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001696}
1697
1698sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001699 my $key;
1700 my $st, $file;
1701 foreach $key (keys %ModuleSynopses) {
1702 $st = $ModuleSynopses{$key};
1703 $file = $st->get_file();
1704 if ($file) {
1705 process_localmoduletables_in_file($file);
1706 }
1707 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001708 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001709 }
1710 }
1711}
1712
1713sub process_localmoduletables_in_file{
1714 my $file = @_[0];
1715 open(MYFILE, "<$file");
1716 local($_);
1717 sysread(MYFILE, $_, 1024*1024);
1718 close(MYFILE);
1719 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001720 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001721 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001722 my $chap = $1;
1723 my $st = get_synopsis_table($chap);
1724 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001725 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001726 }
Fred Drake643d76d2000-09-09 06:07:37 +00001727 open(MYFILE,">$file");
1728 print MYFILE $_;
1729 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001730}
Fred Drake557460c1999-03-02 16:05:35 +00001731sub process_python_state{
1732 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001733 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001734}
Fred Drakea0f4c941998-07-24 22:16:04 +00001735
1736
1737#
1738# "See also:" -- references placed at the end of a \section
1739#
1740
1741sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001742 return ("<div class=\"seealso\">\n "
1743 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1744 . @_[0]
1745 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001746}
1747
Fred Drake5ed35fd2001-11-30 18:09:54 +00001748sub do_env_seealsostar{
1749 return ("<div class=\"seealso-simple\">\n "
1750 . @_[0]
1751 . '</div>');
1752}
1753
Fred Drakea0f4c941998-07-24 22:16:04 +00001754sub do_cmd_seemodule{
1755 # Insert the right magic to jump to the module definition. This should
1756 # work most of the time, at least for repeat builds....
1757 local($_) = @_;
1758 my $key = next_optional_argument();
1759 my $module = next_argument();
1760 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001761 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001762 $key = $module
1763 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001764 if ($text =~ /\.$/) {
1765 $period = '';
1766 }
Fred Drakef1927a62001-06-20 21:29:30 +00001767 return ('<dl compact class="seemodule">'
1768 . "\n <dt>Module <b><tt class=\"module\">"
1769 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1770 . "\n <dd>$text$period\n </dl>"
1771 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001772}
1773
Fred Drakee0197bf2001-04-12 04:03:22 +00001774sub strip_html_markup($){
1775 my $str = @_[0];
1776 my $s = "$str";
1777 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1778 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1779 return $s;
1780}
1781
Fred Drake643d76d2000-09-09 06:07:37 +00001782sub handle_rfclike_reference{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001783 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001784 my $rfcnum = next_argument();
1785 my $title = next_argument();
1786 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001787 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001788 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001789 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001790 return '<dl compact class="seerfc">'
1791 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001792 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001793 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001794 . "\n <dd>$text\n </dl>"
1795 . $_;
1796}
1797
Fred Drake643d76d2000-09-09 06:07:37 +00001798sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001799 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001800}
1801
1802sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001803 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001804}
1805
Fred Drake48449982000-09-12 17:52:33 +00001806sub do_cmd_seetitle{
1807 local($_) = @_;
1808 my $url = next_optional_argument();
1809 my $title = next_argument();
1810 my $text = next_argument();
1811 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001812 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001813 return '<dl compact class="seetitle">'
1814 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001815 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001816 . "\n <dd>$text\n </dl>"
1817 . $_;
1818 }
1819 return '<dl compact class="seetitle">'
1820 . "\n <dt><em class=\"citetitle\""
1821 . "\n >$title</em>"
1822 . "\n <dd>$text\n </dl>"
1823 . $_;
1824}
1825
Fred Drakeef4d1112000-05-09 16:17:51 +00001826sub do_cmd_seeurl{
1827 local($_) = @_;
1828 my $url = next_argument();
1829 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001830 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001831 return '<dl compact class="seeurl">'
1832 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001833 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001834 . "\n <dd>$text\n </dl>"
1835 . $_;
1836}
1837
Fred Drakea0f4c941998-07-24 22:16:04 +00001838sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001839 local($_) = @_;
1840 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001841 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001842}
1843
1844
1845#
Fred Drake885215c1998-05-20 21:32:09 +00001846# Definition list support.
1847#
1848
1849sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001850 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001851}
1852
1853sub do_cmd_term{
1854 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001855 my $term = next_argument();
1856 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001857 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001858 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001859}
1860
1861
Fred Drake38178fd2000-09-22 17:05:04 +00001862# I don't recall exactly why this was needed, but it was very much needed.
1863# We'll see if anything breaks when I move the "code" line out -- some
1864# things broke with it in.
1865
1866#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001867process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001868declaremodule # [] # {} # {}
1869memberline # [] # {}
1870methodline # [] # {} # {}
1871modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001872platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001873samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001874setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001875withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001876_RAW_ARG_DEFERRED_CMDS_
1877
1878
Fred Drake86333602001-04-10 17:13:39 +00001879$alltt_start = '<dl><dd><pre class="verbatim">';
1880$alltt_end = '</pre></dl>';
1881
1882sub do_env_alltt {
1883 local ($_) = @_;
1884 local($closures,$reopens,@open_block_tags);
1885
1886 # get the tag-strings for all open tags
1887 local(@keep_open_tags) = @$open_tags_R;
1888 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1889
1890 # get the tags for text-level tags only
1891 $open_tags_R = [ @keep_open_tags ];
1892 local($local_closures, $local_reopens);
1893 ($local_closures, $local_reopens,@open_block_tags)
1894 = &preserve_open_block_tags
1895 if (@$open_tags_R);
1896
1897 $open_tags_R = [ @open_block_tags ];
1898
1899 do {
1900 local($open_tags_R) = [ @open_block_tags ];
1901 local(@save_open_tags) = ();
1902
1903 local($cnt) = ++$global{'max_id'};
1904 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1905 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1906
1907 $_ = &translate_environments($_);
1908 $_ = &translate_commands($_) if (/\\/);
1909
1910 # preserve space-runs, using &nbsp;
1911 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1912 s/(<BR>) /$1;SPMnbsp;/g;
1913
1914 $_ = join('', $closures, $alltt_start, $local_reopens
1915 , $_
1916 , &balance_tags() #, $local_closures
1917 , $alltt_end, $reopens);
1918 undef $open_tags_R; undef @save_open_tags;
1919 };
1920 $open_tags_R = [ @keep_open_tags ];
1921 $_;
1922}
1923
Fred Drake57e52ef2001-06-15 21:31:57 +00001924sub do_cmd_verbatiminput{
1925 local($_) = @_;
1926 my $fname = next_argument();
1927 my $file;
1928 my $found = 0;
1929 my $texpath;
1930 # Search TEXINPUTS for the input file, the way we're supposed to:
1931 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1932 $file = "$texpath$dd$fname";
1933 last if ($found = (-f $file));
1934 }
Fred Drake77602f22001-07-06 22:43:02 +00001935 my $srcname;
Fred Drake57e52ef2001-06-15 21:31:57 +00001936 my $text;
1937 if ($found) {
1938 open(MYFILE, "<$file") || die "\n$!\n";
1939 read(MYFILE, $text, 1024*1024);
1940 close(MYFILE);
Fred Drake77602f22001-07-06 22:43:02 +00001941 use File::Basename;
1942 my $srcdir, $srcext;
1943 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1944 open(MYFILE, ">$srcname.txt");
1945 print MYFILE $text;
1946 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00001947 #
1948 # These rewrites convert the raw text to something that will
1949 # be properly visible as HTML and also will pass through the
1950 # vagaries of conversion through LaTeX2HTML. The order in
1951 # which the specific rewrites are performed is significant.
1952 #
1953 $text =~ s/\&/\&amp;/g;
1954 # These need to happen before the normal < and > re-writes,
1955 # since we need to avoid LaTeX2HTML's attempt to perform
1956 # ligature processing without regard to context (since it
1957 # doesn't have font information).
1958 $text =~ s/--/-&\#45;/g;
1959 $text =~ s/<</\&lt;\&\#60;/g;
1960 $text =~ s/>>/\&gt;\&\#62;/g;
1961 # Just normal re-writes...
1962 $text =~ s/</\&lt;/g;
1963 $text =~ s/>/\&gt;/g;
1964 # These last isn't needed for the HTML, but is needed to get
1965 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1966 # of &sol; since many browsers don't support that.
1967 $text =~ s/\\/\&\#92;/g;
1968 }
1969 else {
1970 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1971 }
Fred Drake77602f22001-07-06 22:43:02 +00001972 return ('<dl><dd><pre class="verbatim">'
Fred Drake57e52ef2001-06-15 21:31:57 +00001973 . $text
Fred Drake77602f22001-07-06 22:43:02 +00001974 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1975 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1976 . ">Download as text.</a>"
1977 . "\n</div>\n</dd></dl>"
Fred Drake57e52ef2001-06-15 21:31:57 +00001978 . $_);
1979}
Fred Drake86333602001-04-10 17:13:39 +00001980
Fred Drake6659c301998-03-03 22:02:19 +000019811; # This must be the last line