blob: 92cf65564d3c1d07ed15bbfd6ea7a07235c4ed69 [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
Fred Drakef171ad92002-03-13 02:44:50 +000088sub do_cmd_textasciitilde{ '&#126;' . @_[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]; }
Fred Drake58fb2372002-03-05 04:04:06 +000091sub do_cmd_textgreater{ '&gt;' . @_[0]; }
92sub do_cmd_textless{ '&lt;' . @_[0]; }
Fred Drake6fe46602001-06-23 03:13:30 +000093sub do_cmd_infinity{ '&infin;' . @_[0]; }
94sub do_cmd_plusminus{ '&plusmn;' . @_[0]; }
Fred Drake77602f22001-07-06 22:43:02 +000095sub do_cmd_menuselection{ @_[0]; }
96sub do_cmd_sub{ ' > ' . @_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +000097
98
Fred Drake6659c301998-03-03 22:02:19 +000099# words typeset in a special way (not in HTML though)
100
101sub do_cmd_ABC{ 'ABC' . @_[0]; }
102sub do_cmd_UNIX{ 'Unix'. @_[0]; }
103sub do_cmd_ASCII{ 'ASCII' . @_[0]; }
104sub do_cmd_POSIX{ 'POSIX' . @_[0]; }
105sub do_cmd_C{ 'C' . @_[0]; }
106sub do_cmd_Cpp{ 'C++' . @_[0]; }
107sub do_cmd_EOF{ 'EOF' . @_[0]; }
Fred Drakee15956b2000-04-03 04:51:13 +0000108sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000109
110sub do_cmd_e{ '&#92;' . @_[0]; }
111
Fred Draked07868a1998-05-14 21:00:28 +0000112$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000113$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000114$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000115$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000116
Fred Draked04592a2000-10-25 16:15:13 +0000117sub do_cmd_version{ $PACKAGE_VERSION . @_[0]; }
Fred Drake3cdb89d2000-09-14 20:17:23 +0000118sub do_cmd_shortversion{ $SHORT_VERSION . @_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000119sub do_cmd_release{
120 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000121 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000122 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000123}
124
Fred Drakef1927a62001-06-20 21:29:30 +0000125sub do_cmd_setreleaseinfo{
126 local($_) = @_;
127 $RELEASE_INFO = next_argument();
128 return $_;
129}
130
Fred Drake3cdb89d2000-09-14 20:17:23 +0000131sub do_cmd_setshortversion{
132 local($_) = @_;
133 $SHORT_VERSION = next_argument();
134 return $_;
135}
136
Fred Drake6659c301998-03-03 22:02:19 +0000137sub do_cmd_authoraddress{
138 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000139 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000140 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000141}
142
Fred Drakee16f6791998-05-15 04:28:37 +0000143#sub do_cmd_developer{ do_cmd_author(@_[0]); }
144#sub do_cmd_developers{ do_cmd_author(@_[0]); }
145#sub do_cmd_developersaddress{ do_cmd_authoraddress(@_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000146
Fred Drake6659c301998-03-03 22:02:19 +0000147sub do_cmd_hackscore{
148 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000149 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000150 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000151}
152
Fred Drake08932051998-04-17 02:15:42 +0000153sub use_wrappers{
154 local($_,$before,$after) = @_;
155 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000156 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000157}
158
Fred Drake3cdb89d2000-09-14 20:17:23 +0000159$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000160sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000161 if ($IN_DESC_HANDLER) {
162 return use_wrappers(@_[0], "</var><big>\[</big><var>",
163 "</var><big>\]</big><var>");
164 }
165 else {
166 return use_wrappers(@_[0], "<big>\[</big>", "<big>\]</big>");
167 }
Fred Drake6659c301998-03-03 22:02:19 +0000168}
169
Fred Drakec9a44381998-03-17 06:29:13 +0000170# Logical formatting (some based on texinfo), needs to be converted to
171# minimalist HTML. The "minimalist" is primarily to reduce the size of
172# output files for users that read them over the network rather than
173# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000174
Fred Drake2cafcbb1999-03-25 16:57:04 +0000175# \file and \samp are at the end of this file since they screw up fontlock.
176
Fred Drake2ff880e1999-02-05 18:31:29 +0000177sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000178sub do_cmd_makevar{
179 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000180sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000181 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000182sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000183 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000185 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000186sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000187 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000188sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000189 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000191 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000193 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000194sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000195 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000197 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000199 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000201 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000203 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000205 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000207 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000208sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000209 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000210sub do_cmd_programopt{
211 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000212sub do_cmd_longprogramopt{
213 # note that the --- will be later converted to -- by LaTeX2HTML
214 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000215sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000216 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000217sub do_cmd_mailheader{
Fred Drake479384e2001-09-26 18:46:36 +0000218 return use_wrappers(@_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000220 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000221sub do_cmd_var{
222 return use_wrappers(@_[0], "<var>", "</var>"); }
223sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000224 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000226 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000227sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000228 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000229sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000230 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000231sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000232 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000233sub do_cmd_kbd{
234 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
235sub do_cmd_strong{
236 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000237sub do_cmd_textbf{
238 return use_wrappers(@_[0], '<b>', '</b>'); }
239sub do_cmd_textit{
240 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000241# This can be changed/overridden for translations:
242%NoticeNames = ('note' => 'Note:',
243 'warning' => 'Warning:',
244 );
245
Fred Drake92350b32001-10-09 18:01:23 +0000246sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000247 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000248 return use_wrappers(
249 @_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000250 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000251 '</span>'); }
252sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000253 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000254 return use_wrappers(
255 @_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000256 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000257 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000258
Fred Drake6ca33772001-12-14 22:50:06 +0000259sub do_env_notice{
260 local($_) = @_;
261 my $notice = next_optional_argument();
262 if (!$notice) {
263 $notice = 'note';
264 }
265 my $label = $NoticeNames{$notice};
266 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
267 . $_
268 . '</div>');
269}
270
Fred Drake3d5a04a2000-08-03 17:25:44 +0000271sub do_cmd_moreargs{
272 return '...' . @_[0]; }
273sub do_cmd_unspecified{
274 return '...' . @_[0]; }
275
Fred Drakec9a44381998-03-17 06:29:13 +0000276
Fred Drake25817041999-01-13 17:06:34 +0000277sub do_cmd_refmodule{
278 # Insert the right magic to jump to the module definition.
279 local($_) = @_;
280 my $key = next_optional_argument();
281 my $module = next_argument();
282 $key = $module
283 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000284 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000285 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000286}
287
Fred Drake1a7af391998-04-01 22:44:56 +0000288sub do_cmd_newsgroup{
289 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000290 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000291 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000292 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
293 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000294 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000295}
Fred Drakefc16e781998-03-12 21:03:26 +0000296
297sub do_cmd_envvar{
298 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000299 my $envvar = next_argument();
300 my($name,$aname,$ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000301 # The <tt> here is really to keep buildindex.py from making
302 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000303 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000304 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000305 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000306 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000307 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000308}
309
Fred Drake6659c301998-03-03 22:02:19 +0000310sub do_cmd_url{
311 # use the URL as both text and hyperlink
312 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000313 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000314 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000315 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000316 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000317}
318
319sub do_cmd_manpage{
320 # two parameters: \manpage{name}{section}
321 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000322 my $page = next_argument();
323 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000324 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000325}
326
Fred Drakef1927a62001-06-20 21:29:30 +0000327$PEP_FORMAT = "http://python.sourceforge.net/peps/pep-%04d.html";
328#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
329$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000330
331sub get_rfc_url($$){
332 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000333 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000334}
335
336sub do_cmd_pep{
337 local($_) = @_;
338 my $rfcnumber = next_argument();
339 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000340 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000341 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000342 # Save the reference
343 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
344 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000345 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
346 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000347}
348
Fred Drake6659c301998-03-03 22:02:19 +0000349sub do_cmd_rfc{
350 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000351 my $rfcnumber = next_argument();
352 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000353 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000354 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000355 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000356 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000357 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000358 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
359 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000360}
361
Fred Drake77602f22001-07-06 22:43:02 +0000362sub do_cmd_ulink{
363 local($_) = @_;
364 my $text = next_argument();
365 my $url = next_argument();
366 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
367}
368
Fred Drakec9f5fe01999-11-09 16:59:42 +0000369sub do_cmd_citetitle{
370 local($_) = @_;
371 my $url = next_optional_argument();
372 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000373 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000374 my $repl = '';
375 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000376 $repl = ("<em class=\"citetitle\"><a\n"
377 . " href=\"$url\"\n"
378 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000379 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000380 }
381 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000382 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000383 }
384 return $repl . $_;
385}
386
Fred Drake6659c301998-03-03 22:02:19 +0000387sub do_cmd_deprecated{
388 # two parameters: \deprecated{version}{whattodo}
389 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000390 my $release = next_argument();
391 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000392 return ('<div class="versionnote">'
393 . "<b>Deprecated since release $release.</b>"
394 . "\n$reason</div><p>"
395 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000396}
397
Fred Drakec2b29d02001-04-18 03:11:04 +0000398sub versionnote{
399 # one or two parameters: \versionnote[explanation]{version}
400 my $type = @_[0];
401 local $_ = @_[1];
402 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000403 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000404 my $text = "$type in version $release.";
405 if ($explanation) {
406 $text = "$type in version $release:\n$explanation.";
407 }
Fred Drakef1927a62001-06-20 21:29:30 +0000408 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000409}
410
411sub do_cmd_versionadded{
412 return versionnote('New', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000413}
414
415sub do_cmd_versionchanged{
Fred Drakec2b29d02001-04-18 03:11:04 +0000416 return versionnote('Changed', @_);
Fred Drake897d12b1998-07-27 20:33:17 +0000417}
418
Fred Drake557460c1999-03-02 16:05:35 +0000419#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000420# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000421#
422sub do_cmd_platform{
423 local($_) = @_;
424 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000425 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000426 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000427 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000428 return "\n<p class=\"availability\">Availability: <span"
429 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000430}
431
Fred Drake557460c1999-03-02 16:05:35 +0000432$IGNORE_PLATFORM_ANNOTATION = '';
433sub do_cmd_ignorePlatformAnnotation{
434 local($_) = @_;
435 $IGNORE_PLATFORM_ANNOTATION = next_argument();
436 return $_;
437}
438
Fred Drake6659c301998-03-03 22:02:19 +0000439
440# index commands
441
442$INDEX_SUBITEM = "";
443
444sub get_indexsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000445 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000446}
447
448sub do_cmd_setindexsubitem{
449 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000450 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000451 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000452}
453
Fred Drakefc16e781998-03-12 21:03:26 +0000454sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000455 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000456 # do things in the right order, but we need to at least strip this stuff
457 # out, and leave anything that the second argument expanded out to.
458 #
459 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000460 my $oldsubitem = $INDEX_SUBITEM;
461 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000462 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000463 my $br_id = ++$globals{'max_id'};
464 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000465 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000466 return
467 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000468 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000469 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000470}
471
Fred Drake08932051998-04-17 02:15:42 +0000472# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000473# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
474# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000475#
Fred Drake62e43691998-08-10 19:40:44 +0000476sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000477
Fred Drake42b31a51998-03-27 05:16:10 +0000478# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000479#
Fred Drake08932051998-04-17 02:15:42 +0000480open(IDXFILE, '>index.dat') || die "\n$!\n";
481open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000482print INTLABELS "%internal_labels = ();\n";
483print INTLABELS "1; # hack in case there are no entries\n\n";
484
485# Using \0 for this is bad because we can't use common tools to work with the
486# resulting files. Things like grep can be useful with this stuff!
487#
488$IDXFILE_FIELD_SEP = "\1";
489
Fred Drakeccc62721999-01-05 22:16:29 +0000490sub write_idxfile{
491 my ($ahref, $str) = @_;
492 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000493}
494
Fred Drake42b31a51998-03-27 05:16:10 +0000495
496sub gen_link{
497 my($node,$target) = @_;
498 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000499 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000500}
501
Fred Drake42b31a51998-03-27 05:16:10 +0000502sub add_index_entry{
503 # add an entry to the index structures; ignore the return value
504 my($str,$ahref) = @_;
505 $str = gen_index_id($str, '');
506 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000507 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000508}
509
Fred Drakeccc62721999-01-05 22:16:29 +0000510sub new_link_info{
511 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000512 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000513 my $ahref = gen_link($CURRENT_FILE, $name);
514 return ($name, $aname, $ahref);
515}
516
Fred Drakeab032151999-05-13 18:36:54 +0000517$IndexMacroPattern = '';
518sub define_indexing_macro{
519 my $count = @_;
520 my $i = 0;
521 for (; $i < $count; ++$i) {
522 my $name = @_[$i];
523 my $cmd = "idx_cmd_$name";
524 die "\nNo function $cmd() defined!\n"
525 if (!defined &$cmd);
526 eval ("sub do_cmd_$name { return process_index_macros("
527 . "\@_[0], '$name'); }");
528 if (length($IndexMacroPattern) == 0) {
529 $IndexMacroPattern = "$name";
530 }
531 else {
532 $IndexMacroPattern .= "|$name";
533 }
534 }
535}
536
537$DEBUG_INDEXING = 0;
538sub process_index_macros{
Fred Drake42b31a51998-03-27 05:16:10 +0000539 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000540 my $cmdname = @_[1]; # This is what triggered us in the first place;
541 # we know it's real, so just process it.
Fred Drakeccc62721999-01-05 22:16:29 +0000542 my($name,$aname,$ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000543 my $cmd = "idx_cmd_$cmdname";
544 print "\nIndexing: \\$cmdname"
545 if $DEBUG_INDEXING;
546 &$cmd($ahref); # modifies $_ and adds index entries
547 while (/^[\s\n]*\\($IndexMacroPattern)</) {
548 $cmdname = "$1";
549 print " \\$cmdname"
550 if $DEBUG_INDEXING;
551 $cmd = "idx_cmd_$cmdname";
552 if (!defined &$cmd) {
553 last;
554 }
555 else {
556 s/^[\s\n]*\\$cmdname//;
557 &$cmd($ahref);
558 }
559 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000560 if (/^[ \t\r\n]/) {
561 $_ = substr($_, 1);
562 }
Fred Drake62e43691998-08-10 19:40:44 +0000563 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000564}
565
Fred Drakeab032151999-05-13 18:36:54 +0000566define_indexing_macro('index');
567sub idx_cmd_index{
Fred Drakeccc62721999-01-05 22:16:29 +0000568 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000569 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000570}
571
Fred Drakeab032151999-05-13 18:36:54 +0000572define_indexing_macro('kwindex');
573sub idx_cmd_kwindex{
574 my $str = next_argument();
575 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
576 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
577}
578
579define_indexing_macro('indexii');
580sub idx_cmd_indexii{
Fred Drakeccc62721999-01-05 22:16:29 +0000581 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000582 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000583 add_index_entry("$str1!$str2", @_[0]);
584 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000585}
586
Fred Drakeab032151999-05-13 18:36:54 +0000587define_indexing_macro('indexiii');
588sub idx_cmd_indexiii{
Fred Drakeccc62721999-01-05 22:16:29 +0000589 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000590 my $str2 = next_argument();
591 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000592 add_index_entry("$str1!$str2 $str3", @_[0]);
593 add_index_entry("$str2!$str3, $str1", @_[0]);
594 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000595}
596
Fred Drakeab032151999-05-13 18:36:54 +0000597define_indexing_macro('indexiv');
598sub idx_cmd_indexiv{
Fred Drakeccc62721999-01-05 22:16:29 +0000599 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000600 my $str2 = next_argument();
601 my $str3 = next_argument();
602 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000603 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
604 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
605 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
606 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000607}
608
Fred Drakeab032151999-05-13 18:36:54 +0000609define_indexing_macro('ttindex');
610sub idx_cmd_ttindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000611 my $str = next_argument();
612 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000613 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000614}
Fred Drake6659c301998-03-03 22:02:19 +0000615
616sub my_typed_index_helper{
Fred Drakeab032151999-05-13 18:36:54 +0000617 my($word,$ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000618 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000619 add_index_entry("$str $word", $ahref);
620 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000621}
622
Fred Drakeab032151999-05-13 18:36:54 +0000623define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
624sub idx_cmd_stindex{ my_typed_index_helper('statement', @_[0]); }
625sub idx_cmd_opindex{ my_typed_index_helper('operator', @_[0]); }
626sub idx_cmd_exindex{ my_typed_index_helper('exception', @_[0]); }
627sub idx_cmd_obindex{ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000628
Fred Drakeab032151999-05-13 18:36:54 +0000629define_indexing_macro('bifuncindex');
630sub idx_cmd_bifuncindex{
Fred Drakeccc62721999-01-05 22:16:29 +0000631 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000632 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drakee15956b2000-04-03 04:51:13 +0000633 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000634}
635
636
Fred Drake6659c301998-03-03 22:02:19 +0000637sub make_mod_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000638 my($str,$define) = @_;
639 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000640 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000641 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
642 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000643 $str = gen_index_id($str, $define);
644 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000645 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000646
Fred Drakec9a44381998-03-17 06:29:13 +0000647 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000648 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000649 $str =~ /(<tt.*<\/tt>)/;
650 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000651 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000652 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000653 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000654}
655
Fred Drake557460c1999-03-02 16:05:35 +0000656
Fred Drakec9a44381998-03-17 06:29:13 +0000657$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000658$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000659
Fred Drakea0f4c941998-07-24 22:16:04 +0000660sub define_module{
661 my($word,$name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000662 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000663 if ($word ne "built-in" && $word ne "extension"
664 && $word ne "standard" && $word ne "") {
665 write_warnings("Bad module type '$word'"
666 . " for \\declaremodule (module $name)");
667 $word = "";
668 }
Fred Drake6659c301998-03-03 22:02:19 +0000669 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000670 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000671 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000672 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000673 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000674 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000675}
676
677sub my_module_index_helper{
678 local($word, $_) = @_;
679 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000680 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000681}
682
Fred Drake62e43691998-08-10 19:40:44 +0000683sub do_cmd_modindex{ return my_module_index_helper('', @_); }
684sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
685sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
686sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000687
Fred Drakeab032151999-05-13 18:36:54 +0000688sub ref_module_index_helper{
Fred Drake37cc0c02000-04-26 18:05:24 +0000689 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000690 my $str = next_argument();
691 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000692 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000693 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
694 # just inline it all here
695 $str = gen_index_id($str, 'REF');
696 $index{$str} .= $ahref;
697 write_idxfile($ahref, $str);
698}
699
Fred Drake6659c301998-03-03 22:02:19 +0000700# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000701define_indexing_macro('refmodindex', 'refbimodindex',
702 'refexmodindex', 'refstmodindex');
703sub idx_cmd_refmodindex{ return ref_module_index_helper('', @_); }
704sub idx_cmd_refbimodindex{ return ref_module_index_helper('built-in', @_); }
705sub idx_cmd_refexmodindex{ return ref_module_index_helper('extension', @_); }
706sub idx_cmd_refstmodindex{ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000707
Fred Drake62e43691998-08-10 19:40:44 +0000708sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000709
710sub init_myformat{
Fred Drakeafc7ce12001-01-22 17:33:24 +0000711 $anchor_invisible_mark = '&nbsp;';
712 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000713 $anchor_mark = '';
714 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000715}
Fred Drake42b31a51998-03-27 05:16:10 +0000716init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000717
Fred Drakeab032151999-05-13 18:36:54 +0000718# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000719# instead of the dummy filler.
720#
721sub make_str_index_entry{
Fred Drakeccc62721999-01-05 22:16:29 +0000722 my($str) = @_;
723 my($name,$aname,$ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000724 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000725 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000726}
727
Fred Drake77602f22001-07-06 22:43:02 +0000728
729%TokenToTargetMapping = ();
730%DefinedGrammars = ();
731%BackpatchGrammarFiles = ();
732
733sub do_cmd_token{
734 local($_) = @_;
735 my $token = next_argument();
736 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
737 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
738 # recursive definition or display-only productionlist
739 return "$token";
740 }
741 if ($target eq '') {
742 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
743 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
744 print "Adding '$CURRENT_FILE' to back-patch list.\n";
745 }
746 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
747 }
748 return "<a href=\"$target\">$token</a>" . $_;
749}
750
Fred Drake16bb4192001-08-20 21:36:38 +0000751sub do_cmd_grammartoken{
752 return do_cmd_token(@_);
753}
754
Fred Drake77602f22001-07-06 22:43:02 +0000755sub do_env_productionlist{
756 local($_) = @_;
757 my $lang = next_optional_argument();
758 my $filename = "grammar-$lang.txt";
759 if ($lang eq '') {
760 $filename = 'grammar.txt';
761 }
762 local($CURRENT_GRAMMAR) = $lang;
763 $DefinedGrammars{$lang} .= $_;
764 return ("<dl><dd class=\"grammar\">\n"
765 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000766 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000767 . translate_commands(translate_environments($_))
768 . "</table>\n"
769 . "</div>\n"
770 . (($lang eq '*')
771 ? ''
772 : ("<a class=\"grammar-footer\"\n"
773 . " href=\"$filename\" type=\"text/plain\"\n"
774 . " >Download entire grammar as text.</a>\n"))
775 . "</dd></dl>");
776}
777
778sub do_cmd_production{
779 local($_) = @_;
780 my $token = next_argument();
781 my $defn = next_argument();
782 my $lang = $CURRENT_GRAMMAR;
783 local($CURRENT_TOKEN) = $token;
784 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000785 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000786 . " <td><code>$token</code></td>\n"
787 . " <td>&nbsp;::=&nbsp;</td>\n"
788 . " <td><code>"
789 . translate_commands($defn)
790 . "</code></td></tr>"
791 . $_);
792 }
793 my $target;
794 if ($lang eq '') {
795 $target = "$CURRENT_FILE\#tok-$token";
796 }
797 else {
798 $target = "$CURRENT_FILE\#tok-$lang-$token";
799 }
800 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000801 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000802 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
803 . " <td>&nbsp;::=&nbsp;</td>\n"
804 . " <td><code>"
805 . translate_commands($defn)
806 . "</code></td></tr>"
807 . $_);
808}
809
Fred Drake53815882002-03-15 23:21:37 +0000810sub do_cmd_productioncont{
811 local($_) = @_;
812 my $defn = next_argument();
813 return ("<tr valign=\"baseline\">\n"
814 . " <td>&nbsp;</td>\n"
815 . " <td>&nbsp;</td>\n"
816 . " <td><code>"
817 . translate_commands($defn)
818 . "</code></td></tr>"
819 . $_);
820}
821
Fred Drake77602f22001-07-06 22:43:02 +0000822sub process_grammar_files{
823 my $lang;
824 my $filename;
825 local($_);
826 print "process_grammar_files()\n";
827 foreach $lang (keys %DefinedGrammars) {
828 $filename = "grammar-$lang.txt";
829 if ($lang eq '*') {
830 next;
831 }
832 if ($lang eq '') {
833 $filename = 'grammar.txt';
834 }
835 open(GRAMMAR, ">$filename") || die "\n$!\n";
836 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
837 close(GRAMMAR);
838 print "Wrote grammar file $filename\n";
839 }
840 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
841 foreach $filename (keys %BackpatchGrammarFiles) {
842 print "\nBack-patching grammar links in $filename\n";
843 my $buffer;
844 open(GRAMMAR, "<$filename") || die "\n$!\n";
845 # read all of the file into the buffer
846 sysread(GRAMMAR, $buffer, 1024*1024);
847 close(GRAMMAR);
848 while ($buffer =~ /$PATTERN/) {
849 my($lang, $token) = ($1, $2);
850 my $target = $TokenToTargetMapping{"$lang:$token"};
851 my $source = "<pyGrammarToken><$lang><$token>";
852 $buffer =~ s/$source/$target/g;
853 }
854 open(GRAMMAR, ">$filename") || die "\n$!\n";
855 print GRAMMAR $buffer;
856 close(GRAMMAR);
857 }
858}
859
860sub strip_grammar_markup{
861 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000862 s/\\productioncont/ /g;
Fred Drake77602f22001-07-06 22:43:02 +0000863 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
864 s/\\token(<<\d+>>)(.+)\1/\2/g;
865 s/\\e([^a-zA-Z])/\\\1/g;
866 s/<<\d+>>//g;
867 s/;SPMgt;/>/g;
868 s/;SPMlt;/</g;
869 s/;SPMquot;/\"/g;
870 return $_;
871}
872
873
Fred Drakee15956b2000-04-03 04:51:13 +0000874$REFCOUNTS_LOADED = 0;
875
876sub load_refcounts{
877 $REFCOUNTS_LOADED = 1;
878
Fred Drakee15956b2000-04-03 04:51:13 +0000879 my $myname, $mydir, $myext;
880 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
881 chop $mydir; # remove trailing '/'
882 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
883 chop $mydir; # remove trailing '/'
884 $mydir = getcwd() . "$dd$mydir"
885 unless $mydir =~ s|^/|/|;
886 local $_;
887 my $filename = "$mydir${dd}api${dd}refcounts.dat";
888 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
889 print "[loading API refcount data]";
890 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000891 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000892 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
893 #print "\n$func($param) --> $count";
894 $REFCOUNTS{"$func:$param"} = $count;
895 }
896 }
897}
898
899sub get_refcount{
900 my ($func, $param) = @_;
901 load_refcounts()
902 unless $REFCOUNTS_LOADED;
903 return $REFCOUNTS{"$func:$param"};
904}
905
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000906
907$TLSTART = '<span class="typelabel">';
908$TLEND = '</span>';
909
Fred Drake6659c301998-03-03 22:02:19 +0000910sub do_env_cfuncdesc{
911 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000912 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000913 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000914 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000915 my $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000916 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000917 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000918 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000919 my $result_rc = get_refcount($function_name, '');
920 my $rcinfo = '';
921 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000922 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000923 }
924 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000925 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000926 }
Fred Drakec2578c52000-04-10 18:26:45 +0000927 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000928 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000929 }
Fred Drakee15956b2000-04-03 04:51:13 +0000930 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000931 $rcinfo = ( "\n<div class=\"refcount-info\">"
932 . "\n <span class=\"label\">Return value:</span>"
933 . "\n <span class=\"value\">$rcinfo.</span>"
934 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000935 }
Fred Drakec612a142001-03-29 18:24:08 +0000936 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000937 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000938 . $_
939 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000940}
941
Fred Drakee15956b2000-04-03 04:51:13 +0000942sub do_env_csimplemacrodesc{
943 local($_) = @_;
944 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000945 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000946 return "<dl><dt><b>$idx</b>\n<dd>"
947 . $_
948 . '</dl>'
949}
950
Fred Drake6659c301998-03-03 22:02:19 +0000951sub do_env_ctypedesc{
952 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000953 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000954 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000955 $index_name = $type_name
956 unless $index_name;
957 my($name,$aname,$ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000958 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
959 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000960 . $_
961 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000962}
963
964sub do_env_cvardesc{
965 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000966 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000967 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000968 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000969 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000970 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000971 return "<dl><dt>$var_type <b>$idx</b>\n"
972 . '<dd>'
973 . $_
974 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000975}
976
Fred Drake3cdb89d2000-09-14 20:17:23 +0000977sub convert_args($){
978 local($IN_DESC_HANDLER) = 1;
979 local($_) = @_;
980 return translate_commands($_);
981}
982
Fred Drake6659c301998-03-03 22:02:19 +0000983sub do_env_funcdesc{
984 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000985 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000986 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000987 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
988 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +0000989 . get_indexsubitem());
990 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000991 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakec612a142001-03-29 18:24:08 +0000992 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000993}
994
995sub do_env_funcdescni{
996 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000997 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000998 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000999 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
Fred Drakec612a142001-03-29 18:24:08 +00001000 . "(<var>$arg_list</var>)\n"
Fred Drake90fdda51999-02-16 20:27:42 +00001001 . '<dd>'
1002 . $_
1003 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001004}
1005
1006sub do_cmd_funcline{
1007 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001008 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001009 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001010 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001011 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1012 $prefix =~ s/\(\)//;
1013
Fred Drakec612a142001-03-29 18:24:08 +00001014 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001015}
1016
Fred Drake6b3fb781999-07-12 16:50:09 +00001017sub do_cmd_funclineni{
1018 local($_) = @_;
1019 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001020 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001021 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001022
Fred Drakec612a142001-03-29 18:24:08 +00001023 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001024}
1025
Fred Drake6659c301998-03-03 22:02:19 +00001026# Change this flag to index the opcode entries. I don't think it's very
1027# useful to index them, since they're only presented to describe the dis
1028# module.
1029#
1030$INDEX_OPCODES = 0;
1031
1032sub do_env_opcodedesc{
1033 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001034 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001035 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001036 my $idx;
1037 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001038 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1039 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001040 $idx =~ s/ \(byte code instruction\)//;
1041 }
1042 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001043 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001044 }
1045 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001046 if ($arg_list) {
1047 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1048 }
Fred Drake62e43691998-08-10 19:40:44 +00001049 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001050}
1051
1052sub do_env_datadesc{
1053 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001054 my $dataname = next_argument();
1055 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001056 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001057 return "<dl><dt><b>$idx</b>\n<dd>"
1058 . $_
1059 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001060}
1061
1062sub do_env_datadescni{
1063 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001064 my $idx = next_argument();
1065 if (! $STRING_INDEX_TT) {
1066 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001067 }
Fred Drake62e43691998-08-10 19:40:44 +00001068 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001069}
1070
1071sub do_cmd_dataline{
1072 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001073 my $data_name = next_argument();
1074 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001075 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001076 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001077}
1078
Fred Drakeadb272c2000-04-10 17:47:14 +00001079sub do_cmd_datalineni{
1080 local($_) = @_;
1081 my $data_name = next_argument();
1082 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1083}
1084
Fred Drake42b31a51998-03-27 05:16:10 +00001085sub do_env_excdesc{
1086 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001087 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001088 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001089 return ("<dl><dt><b>${TLSTART}exception$TLEND $idx</b>"
1090 . "\n<dd>"
1091 . $_
1092 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001093}
1094
Fred Drake62e43691998-08-10 19:40:44 +00001095sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001096
1097
Fred Drake643d76d2000-09-09 06:07:37 +00001098sub handle_classlike_descriptor{
1099 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001100 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001101 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001102 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001103 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001104 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001105 return ("<dl><dt><b>$TLSTART$what$TLEND $idx</b>"
1106 . "(<var>$arg_list</var>)\n<dd>"
Fred Drakeab357ec2001-03-02 18:57:05 +00001107 . $_
1108 . '</dl>');
Fred Drakec9a44381998-03-17 06:29:13 +00001109}
1110
Fred Drake643d76d2000-09-09 06:07:37 +00001111sub do_env_classdesc{
1112 return handle_classlike_descriptor(@_[0], "class");
1113}
1114
Fred Drake06a01e82001-05-11 01:00:30 +00001115sub do_env_classdescstar{
1116 local($_) = @_;
1117 $THIS_CLASS = next_argument();
1118 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001119 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001120 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001121 return ("<dl><dt><b>${TLSTART}class$TLEND $idx</b>\n<dd>"
Fred Drake06a01e82001-05-11 01:00:30 +00001122 . $_
1123 . '</dl>');
1124}
1125
Fred Drake643d76d2000-09-09 06:07:37 +00001126sub do_env_excclassdesc{
1127 return handle_classlike_descriptor(@_[0], "exception");
1128}
1129
Fred Drake42b31a51998-03-27 05:16:10 +00001130
1131sub do_env_methoddesc{
1132 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001133 my $class_name = next_optional_argument();
1134 $class_name = $THIS_CLASS
1135 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001136 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001137 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001138 my $extra = '';
1139 if ($class_name) {
1140 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001141 }
Fred Drakef1927a62001-06-20 21:29:30 +00001142 my $idx = make_str_index_entry(
1143 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001144 $idx =~ s/ \(.*\)//;
1145 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001146 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001147}
1148
1149
Fred Drake7d45f6d1999-01-05 14:39:27 +00001150sub do_cmd_methodline{
1151 local($_) = @_;
1152 my $class_name = next_optional_argument();
1153 $class_name = $THIS_CLASS
1154 unless $class_name;
1155 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001156 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001157 my $extra = '';
1158 if ($class_name) {
1159 $extra = " ($class_name method)";
1160 }
Fred Drakef1927a62001-06-20 21:29:30 +00001161 my $idx = make_str_index_entry(
1162 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001163 $idx =~ s/ \(.*\)//;
1164 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001165 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake7d45f6d1999-01-05 14:39:27 +00001166 . $_;
1167}
1168
1169
Fred Draked64a40d1998-09-10 18:59:13 +00001170sub do_cmd_methodlineni{
1171 local($_) = @_;
1172 next_optional_argument();
1173 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001174 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001175 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Draked64a40d1998-09-10 18:59:13 +00001176 . $_;
1177}
1178
Fred Drake42b31a51998-03-27 05:16:10 +00001179sub do_env_methoddescni{
1180 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001181 next_optional_argument();
1182 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001183 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001184 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001185 . $_
1186 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001187}
1188
1189
1190sub do_env_memberdesc{
1191 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001192 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001193 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001194 $class = $THIS_CLASS
1195 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001196 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001197 $extra = " ($class attribute)"
1198 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001199 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001200 $idx =~ s/ \(.*\)//;
1201 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001202 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001203}
1204
1205
Fred Drake5ccf3301998-04-17 20:04:09 +00001206sub do_cmd_memberline{
1207 local($_) = @_;
1208 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001209 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001210 $class = $THIS_CLASS
1211 unless $class;
1212 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001213 $extra = " ($class attribute)"
1214 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001215 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001216 $idx =~ s/ \(.*\)//;
1217 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001218 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001219}
1220
Fred Drakef269e592001-07-17 23:05:57 +00001221
Fred Drake42b31a51998-03-27 05:16:10 +00001222sub do_env_memberdescni{
1223 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001224 next_optional_argument();
1225 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001226 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001227 . $_
1228 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001229}
1230
1231
Fred Drake5ccf3301998-04-17 20:04:09 +00001232sub do_cmd_memberlineni{
1233 local($_) = @_;
1234 next_optional_argument();
1235 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001236 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001237}
1238
Fred Drakef269e592001-07-17 23:05:57 +00001239
1240@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001241
Fred Drakecb199762001-08-16 21:56:24 +00001242%FontConversions = ('cdata' => 'tt class="cdata"',
1243 'character' => 'tt class="character"',
1244 'class' => 'tt class="class"',
1245 'command' => 'code',
1246 'constant' => 'tt class="constant"',
1247 'exception' => 'tt class="exception"',
1248 'file' => 'tt class="file"',
1249 'filenq' => 'tt class="file"',
1250 'kbd' => 'kbd',
1251 'member' => 'tt class="member"',
1252 'programopt' => 'b',
1253 'textrm' => '',
1254 );
1255
Fred Drakef74e5b71999-04-28 14:58:49 +00001256sub fix_font{
1257 # do a little magic on a font name to get the right behavior in the first
1258 # column of the output table
1259 my $font = @_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001260 if (defined $FontConversions{$font}) {
1261 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001262 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001263 return $font;
1264}
1265
Fred Drakee15956b2000-04-03 04:51:13 +00001266sub figure_column_alignment{
1267 my $a = @_[0];
1268 my $mark = substr($a, 0, 1);
1269 my $r = '';
1270 if ($mark eq 'c')
1271 { $r = ' align="center"'; }
1272 elsif ($mark eq 'r')
1273 { $r = ' align="right"'; }
1274 elsif ($mark eq 'l')
1275 { $r = ' align="left"'; }
1276 elsif ($mark eq 'p')
1277 { $r = ' align="left"'; }
1278 return $r;
1279}
1280
Fred Drake6659c301998-03-03 22:02:19 +00001281sub setup_column_alignments{
1282 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001283 my($s1,$s2,$s3,$s4,$a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001284 my $a1 = figure_column_alignment($s1);
1285 my $a2 = figure_column_alignment($s2);
1286 my $a3 = figure_column_alignment($s3);
1287 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001288 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001289 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1290 $col_aligns[1] = "<td$a2>";
1291 $col_aligns[2] = "<td$a3>";
1292 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001293 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001294 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001295 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001296}
1297
1298sub get_table_col1_fonts{
1299 my $font = $globals{'lineifont'};
1300 my ($sfont,$efont) = ('', '');
1301 if ($font) {
1302 $sfont = "<$font>";
1303 $efont = "</$font>";
1304 $efont =~ s/ .*>/>/;
1305 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001306 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001307}
1308
1309sub do_env_tableii{
1310 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001311 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001312 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001313 my $h1 = next_argument();
1314 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001315 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001316 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001317 my $a1 = $col_aligns[0];
1318 my $a2 = $col_aligns[1];
1319 s/\\lineii</\\lineii[$a1|$a2]</g;
1320 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001321 . "\n <thead>"
1322 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001323 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1324 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001325 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001326 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001327 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001328 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001329 . "\n </tbody>"
1330 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001331}
1332
Fred Drakeda72b932000-09-21 15:58:02 +00001333sub do_env_longtableii{
1334 return do_env_tableii(@_);
1335}
1336
Fred Drake6659c301998-03-03 22:02:19 +00001337sub do_cmd_lineii{
1338 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001339 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001340 my $c1 = next_argument();
1341 my $c2 = 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 $c2 = '&nbsp;' if ($c2 eq '');
1345 my($c1align,$c2align) = 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"
1351 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001352 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001353}
1354
1355sub do_env_tableiii{
1356 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001357 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001358 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001359 my $h1 = next_argument();
1360 my $h2 = next_argument();
1361 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001362 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001363 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001364 my $a1 = $col_aligns[0];
1365 my $a2 = $col_aligns[1];
1366 my $a3 = $col_aligns[2];
1367 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1368 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001369 . "\n <thead>"
1370 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001371 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1372 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1373 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001374 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001375 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001376 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001377 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001378 . "\n </tbody>"
1379 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001380}
1381
Fred Drakeda72b932000-09-21 15:58:02 +00001382sub do_env_longtableiii{
1383 return do_env_tableiii(@_);
1384}
1385
Fred Drake6659c301998-03-03 22:02:19 +00001386sub do_cmd_lineiii{
1387 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001388 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001389 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001390 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001391 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001392 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001393 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001394 $c3 = '&nbsp;' if ($c3 eq '');
1395 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1396 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001397 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001398 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001399 }
Fred Drakee15956b2000-04-03 04:51:13 +00001400 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001401 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001402 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001403 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001404}
1405
Fred Drakea0f4c941998-07-24 22:16:04 +00001406sub do_env_tableiv{
1407 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001408 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001409 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001410 my $h1 = next_argument();
1411 my $h2 = next_argument();
1412 my $h3 = next_argument();
1413 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001414 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001415 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001416 my $a1 = $col_aligns[0];
1417 my $a2 = $col_aligns[1];
1418 my $a3 = $col_aligns[2];
1419 my $a4 = $col_aligns[3];
1420 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1421 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001422 . "\n <thead>"
1423 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001424 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1425 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1426 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1427 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001428 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001429 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001430 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001431 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001432 . "\n </tbody>"
1433 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001434}
1435
Fred Drakeda72b932000-09-21 15:58:02 +00001436sub do_env_longtableiv{
1437 return do_env_tableiv(@_);
1438}
1439
Fred Drakea0f4c941998-07-24 22:16:04 +00001440sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001441 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001442 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001443 my $c1 = next_argument();
1444 my $c2 = next_argument();
1445 my $c3 = next_argument();
1446 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001447 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001448 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001449 $c4 = '&nbsp;' if ($c4 eq '');
1450 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1451 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001452 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001453 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001454 }
Fred Drakee15956b2000-04-03 04:51:13 +00001455 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001456 . " $c2align$c2</td>\n"
1457 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001458 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001459 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001460}
1461
Fred Drakef269e592001-07-17 23:05:57 +00001462sub do_env_tablev{
1463 local($_) = @_;
1464 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1465 my $font = fix_font(next_argument());
1466 my $h1 = next_argument();
1467 my $h2 = next_argument();
1468 my $h3 = next_argument();
1469 my $h4 = next_argument();
1470 my $h5 = next_argument();
1471 s/[\s\n]+//;
1472 $globals{'lineifont'} = $font;
1473 my $a1 = $col_aligns[0];
1474 my $a2 = $col_aligns[1];
1475 my $a3 = $col_aligns[2];
1476 my $a4 = $col_aligns[3];
1477 my $a5 = $col_aligns[4];
1478 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1479 return '<table border align="center" style="border-collapse: collapse">'
1480 . "\n <thead>"
1481 . "\n <tr class=\"tableheader\">"
1482 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1483 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1484 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1485 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1486 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1487 . "\n </tr>"
1488 . "\n </thead>"
1489 . "\n <tbody valign=\"baseline\">"
1490 . $_
1491 . "\n </tbody>"
1492 . "\n</table>";
1493}
1494
1495sub do_env_longtablev{
1496 return do_env_tablev(@_);
1497}
1498
1499sub do_cmd_linev{
1500 local($_) = @_;
1501 my $aligns = next_optional_argument();
1502 my $c1 = next_argument();
1503 my $c2 = next_argument();
1504 my $c3 = next_argument();
1505 my $c4 = next_argument();
1506 my $c5 = next_argument();
1507 s/[\s\n]+//;
1508 my($sfont,$efont) = get_table_col1_fonts();
1509 $c5 = '&nbsp;' if ($c5 eq '');
1510 my($c1align,$c2align,$c3align,$c4align,$c5align) = split('\|', $aligns);
1511 my $padding = '';
1512 if ($c1align =~ /align="right"/ || $c1 eq '') {
1513 $padding = '&nbsp;';
1514 }
1515 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1516 . " $c2align$c2</td>\n"
1517 . " $c3align$c3</td>\n"
1518 . " $c4align$c4</td>\n"
1519 . " $c5align$c5</td>"
1520 . $_;
1521}
1522
Fred Drake3be20742000-08-31 06:22:54 +00001523
1524# These can be used to control the title page appearance;
1525# they need a little bit of documentation.
1526#
1527# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1528# $ICONSERVER directory, or include path information (other than "./"). The
1529# default image type will be assumed if an extension is not provided.
1530#
1531# If specified, the "title page" will contain two colums: one containing the
1532# title/author/etc., and the other containing the graphic. Use the other
1533# four variables listed here to control specific details of the layout; all
1534# are optional.
1535#
1536# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1537# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1538# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1539# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1540# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1541
1542sub make_my_titlepage() {
1543 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001544 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001545 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001546 }
1547 else {
1548 write_warnings("\nThis document has no title.");
1549 }
Fred Drake6659c301998-03-03 22:02:19 +00001550 if ($t_author) {
1551 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001552 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001553 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001554 "<b><font size=\"+2\">$t_author"
1555 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001556 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001557 }
1558 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001559 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1560 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001561 }
Fred Drake3be20742000-08-31 06:22:54 +00001562 }
1563 else {
1564 write_warnings("\nThere is no author for this document.");
1565 }
Fred Drake6659c301998-03-03 22:02:19 +00001566 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001567 $the_title .= "\n<p>$t_institute</p>";
1568 }
Fred Draked07868a1998-05-14 21:00:28 +00001569 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001570 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1571 }
Fred Drake6659c301998-03-03 22:02:19 +00001572 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001573 $the_title .= "\n<p><i>$t_affil</i></p>";
1574 }
Fred Drake6659c301998-03-03 22:02:19 +00001575 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001576 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001577 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001578 $the_title .= ('<strong>Release '
1579 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001580 }
Fred Drakede77bc52000-12-14 18:36:12 +00001581 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001582 }
1583 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001584 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001585 }
1586 else {
1587 $the_title .= "\n<p>";
1588 }
Fred Drake6659c301998-03-03 22:02:19 +00001589 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001590 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001591 }
1592 return $the_title;
1593}
1594
Fred Drake3be20742000-08-31 06:22:54 +00001595sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001596 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001597 my $graphic = "<td class=\"titlegraphic\"";
1598 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1599 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1600 $graphic .= "><img";
1601 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1602 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1603 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1604 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001605 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001606 return $graphic;
1607}
1608
1609sub do_cmd_maketitle {
1610 local($_) = @_;
1611 my $the_title = "\n<div class=\"titlepage\">";
1612 if ($TITLE_PAGE_GRAPHIC) {
1613 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1614 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1615 . "<tr align=\"right\">\n<td>"
1616 . make_my_titlepage()
1617 . "</td>\n"
1618 . make_my_titlegraphic()
1619 . "</tr>\n</table>");
1620 }
1621 else {
1622 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1623 . make_my_titlegraphic()
1624 . "<td>"
1625 . make_my_titlepage()
1626 . "</td></tr>\n</table>");
1627 }
1628 }
1629 else {
1630 $the_title .= ("\n<center>"
1631 . make_my_titlepage()
1632 . "\n</center>");
1633 }
1634 $the_title .= "\n</div>";
1635 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001636 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001637 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001638}
1639
1640
Fred Drake885215c1998-05-20 21:32:09 +00001641#
Fred Drakea0f4c941998-07-24 22:16:04 +00001642# Module synopsis support
1643#
1644
1645require SynopsisTable;
1646
Fred Drakef7685d71998-07-25 03:31:46 +00001647sub get_chapter_id(){
1648 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001649 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1650 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001651 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001652}
1653
Fred Drake643d76d2000-09-09 06:07:37 +00001654# 'chapter' => 'SynopsisTable instance'
1655%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001656
1657sub get_synopsis_table($){
1658 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001659 my $key;
1660 foreach $key (keys %ModuleSynopses) {
1661 if ($key eq $chap) {
1662 return $ModuleSynopses{$chap};
1663 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001664 }
Fred Drake643d76d2000-09-09 06:07:37 +00001665 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001666 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001667 return $st;
1668}
1669
Fred Drake62e43691998-08-10 19:40:44 +00001670sub do_cmd_moduleauthor{
1671 local($_) = @_;
1672 next_argument();
1673 next_argument();
1674 return $_;
1675}
1676
1677sub do_cmd_sectionauthor{
1678 local($_) = @_;
1679 next_argument();
1680 next_argument();
1681 return $_;
1682}
1683
Fred Drakea0f4c941998-07-24 22:16:04 +00001684sub do_cmd_declaremodule{
1685 local($_) = @_;
1686 my $key = next_optional_argument();
1687 my $type = next_argument();
1688 my $name = next_argument();
1689 my $st = get_synopsis_table(get_chapter_id());
1690 #
1691 $key = $name unless $key;
1692 $type = 'built-in' if $type eq 'builtin';
1693 $st->declare($name, $key, $type);
1694 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001695 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001696}
1697
1698sub do_cmd_modulesynopsis{
1699 local($_) = @_;
1700 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001701 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001702 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001703}
1704
1705sub do_cmd_localmoduletable{
1706 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001707 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001708 my $st = get_synopsis_table($chap);
1709 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001710 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001711}
1712
1713sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001714 my $key;
1715 my $st, $file;
1716 foreach $key (keys %ModuleSynopses) {
1717 $st = $ModuleSynopses{$key};
1718 $file = $st->get_file();
1719 if ($file) {
1720 process_localmoduletables_in_file($file);
1721 }
1722 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001723 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001724 }
1725 }
1726}
1727
1728sub process_localmoduletables_in_file{
1729 my $file = @_[0];
1730 open(MYFILE, "<$file");
1731 local($_);
1732 sysread(MYFILE, $_, 1024*1024);
1733 close(MYFILE);
1734 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001735 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001736 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001737 my $chap = $1;
1738 my $st = get_synopsis_table($chap);
1739 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001740 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001741 }
Fred Drake643d76d2000-09-09 06:07:37 +00001742 open(MYFILE,">$file");
1743 print MYFILE $_;
1744 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001745}
Fred Drake557460c1999-03-02 16:05:35 +00001746sub process_python_state{
1747 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001748 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001749}
Fred Drakea0f4c941998-07-24 22:16:04 +00001750
1751
1752#
1753# "See also:" -- references placed at the end of a \section
1754#
1755
1756sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001757 return ("<div class=\"seealso\">\n "
1758 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1759 . @_[0]
1760 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001761}
1762
Fred Drake5ed35fd2001-11-30 18:09:54 +00001763sub do_env_seealsostar{
1764 return ("<div class=\"seealso-simple\">\n "
1765 . @_[0]
1766 . '</div>');
1767}
1768
Fred Drakea0f4c941998-07-24 22:16:04 +00001769sub do_cmd_seemodule{
1770 # Insert the right magic to jump to the module definition. This should
1771 # work most of the time, at least for repeat builds....
1772 local($_) = @_;
1773 my $key = next_optional_argument();
1774 my $module = next_argument();
1775 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001776 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001777 $key = $module
1778 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001779 if ($text =~ /\.$/) {
1780 $period = '';
1781 }
Fred Drakef1927a62001-06-20 21:29:30 +00001782 return ('<dl compact class="seemodule">'
1783 . "\n <dt>Module <b><tt class=\"module\">"
1784 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1785 . "\n <dd>$text$period\n </dl>"
1786 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001787}
1788
Fred Drakee0197bf2001-04-12 04:03:22 +00001789sub strip_html_markup($){
1790 my $str = @_[0];
1791 my $s = "$str";
1792 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1793 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1794 return $s;
1795}
1796
Fred Drake643d76d2000-09-09 06:07:37 +00001797sub handle_rfclike_reference{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001798 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001799 my $rfcnum = next_argument();
1800 my $title = next_argument();
1801 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001802 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001803 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001804 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001805 return '<dl compact class="seerfc">'
1806 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001807 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001808 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001809 . "\n <dd>$text\n </dl>"
1810 . $_;
1811}
1812
Fred Drake643d76d2000-09-09 06:07:37 +00001813sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001814 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001815}
1816
1817sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001818 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001819}
1820
Fred Drake48449982000-09-12 17:52:33 +00001821sub do_cmd_seetitle{
1822 local($_) = @_;
1823 my $url = next_optional_argument();
1824 my $title = next_argument();
1825 my $text = next_argument();
1826 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001827 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001828 return '<dl compact class="seetitle">'
1829 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001830 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001831 . "\n <dd>$text\n </dl>"
1832 . $_;
1833 }
1834 return '<dl compact class="seetitle">'
1835 . "\n <dt><em class=\"citetitle\""
1836 . "\n >$title</em>"
1837 . "\n <dd>$text\n </dl>"
1838 . $_;
1839}
1840
Fred Drakeef4d1112000-05-09 16:17:51 +00001841sub do_cmd_seeurl{
1842 local($_) = @_;
1843 my $url = next_argument();
1844 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001845 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001846 return '<dl compact class="seeurl">'
1847 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001848 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001849 . "\n <dd>$text\n </dl>"
1850 . $_;
1851}
1852
Fred Drakea0f4c941998-07-24 22:16:04 +00001853sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001854 local($_) = @_;
1855 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001856 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001857}
1858
1859
1860#
Fred Drake885215c1998-05-20 21:32:09 +00001861# Definition list support.
1862#
1863
1864sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001865 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001866}
1867
1868sub do_cmd_term{
1869 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001870 my $term = next_argument();
1871 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001872 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001873 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001874}
1875
1876
Fred Drake38178fd2000-09-22 17:05:04 +00001877# I don't recall exactly why this was needed, but it was very much needed.
1878# We'll see if anything breaks when I move the "code" line out -- some
1879# things broke with it in.
1880
1881#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001882process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001883declaremodule # [] # {} # {}
1884memberline # [] # {}
1885methodline # [] # {} # {}
1886modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001887platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001888samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001889setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001890withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001891_RAW_ARG_DEFERRED_CMDS_
1892
1893
Fred Drake86333602001-04-10 17:13:39 +00001894$alltt_start = '<dl><dd><pre class="verbatim">';
1895$alltt_end = '</pre></dl>';
1896
1897sub do_env_alltt {
1898 local ($_) = @_;
1899 local($closures,$reopens,@open_block_tags);
1900
1901 # get the tag-strings for all open tags
1902 local(@keep_open_tags) = @$open_tags_R;
1903 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1904
1905 # get the tags for text-level tags only
1906 $open_tags_R = [ @keep_open_tags ];
1907 local($local_closures, $local_reopens);
1908 ($local_closures, $local_reopens,@open_block_tags)
1909 = &preserve_open_block_tags
1910 if (@$open_tags_R);
1911
1912 $open_tags_R = [ @open_block_tags ];
1913
1914 do {
1915 local($open_tags_R) = [ @open_block_tags ];
1916 local(@save_open_tags) = ();
1917
1918 local($cnt) = ++$global{'max_id'};
1919 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1920 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1921
1922 $_ = &translate_environments($_);
1923 $_ = &translate_commands($_) if (/\\/);
1924
1925 # preserve space-runs, using &nbsp;
1926 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1927 s/(<BR>) /$1;SPMnbsp;/g;
1928
1929 $_ = join('', $closures, $alltt_start, $local_reopens
1930 , $_
1931 , &balance_tags() #, $local_closures
1932 , $alltt_end, $reopens);
1933 undef $open_tags_R; undef @save_open_tags;
1934 };
1935 $open_tags_R = [ @keep_open_tags ];
1936 $_;
1937}
1938
Fred Drake57e52ef2001-06-15 21:31:57 +00001939sub do_cmd_verbatiminput{
1940 local($_) = @_;
1941 my $fname = next_argument();
1942 my $file;
1943 my $found = 0;
1944 my $texpath;
1945 # Search TEXINPUTS for the input file, the way we're supposed to:
1946 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1947 $file = "$texpath$dd$fname";
1948 last if ($found = (-f $file));
1949 }
Fred Drake77602f22001-07-06 22:43:02 +00001950 my $srcname;
Fred Drake57e52ef2001-06-15 21:31:57 +00001951 my $text;
1952 if ($found) {
1953 open(MYFILE, "<$file") || die "\n$!\n";
1954 read(MYFILE, $text, 1024*1024);
1955 close(MYFILE);
Fred Drake77602f22001-07-06 22:43:02 +00001956 use File::Basename;
1957 my $srcdir, $srcext;
1958 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1959 open(MYFILE, ">$srcname.txt");
1960 print MYFILE $text;
1961 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00001962 #
1963 # These rewrites convert the raw text to something that will
1964 # be properly visible as HTML and also will pass through the
1965 # vagaries of conversion through LaTeX2HTML. The order in
1966 # which the specific rewrites are performed is significant.
1967 #
1968 $text =~ s/\&/\&amp;/g;
1969 # These need to happen before the normal < and > re-writes,
1970 # since we need to avoid LaTeX2HTML's attempt to perform
1971 # ligature processing without regard to context (since it
1972 # doesn't have font information).
1973 $text =~ s/--/-&\#45;/g;
1974 $text =~ s/<</\&lt;\&\#60;/g;
1975 $text =~ s/>>/\&gt;\&\#62;/g;
1976 # Just normal re-writes...
1977 $text =~ s/</\&lt;/g;
1978 $text =~ s/>/\&gt;/g;
1979 # These last isn't needed for the HTML, but is needed to get
1980 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1981 # of &sol; since many browsers don't support that.
1982 $text =~ s/\\/\&\#92;/g;
1983 }
1984 else {
1985 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1986 }
Fred Drake77602f22001-07-06 22:43:02 +00001987 return ('<dl><dd><pre class="verbatim">'
Fred Drake57e52ef2001-06-15 21:31:57 +00001988 . $text
Fred Drake77602f22001-07-06 22:43:02 +00001989 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1990 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1991 . ">Download as text.</a>"
1992 . "\n</div>\n</dd></dl>"
Fred Drake57e52ef2001-06-15 21:31:57 +00001993 . $_);
1994}
Fred Drake86333602001-04-10 17:13:39 +00001995
Fred Drake6659c301998-03-03 22:02:19 +000019961; # This must be the last line