blob: 8968df36ab793e3406b0ac492e5deb69d9b69b47 [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]; }
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
810sub process_grammar_files{
811 my $lang;
812 my $filename;
813 local($_);
814 print "process_grammar_files()\n";
815 foreach $lang (keys %DefinedGrammars) {
816 $filename = "grammar-$lang.txt";
817 if ($lang eq '*') {
818 next;
819 }
820 if ($lang eq '') {
821 $filename = 'grammar.txt';
822 }
823 open(GRAMMAR, ">$filename") || die "\n$!\n";
824 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
825 close(GRAMMAR);
826 print "Wrote grammar file $filename\n";
827 }
828 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
829 foreach $filename (keys %BackpatchGrammarFiles) {
830 print "\nBack-patching grammar links in $filename\n";
831 my $buffer;
832 open(GRAMMAR, "<$filename") || die "\n$!\n";
833 # read all of the file into the buffer
834 sysread(GRAMMAR, $buffer, 1024*1024);
835 close(GRAMMAR);
836 while ($buffer =~ /$PATTERN/) {
837 my($lang, $token) = ($1, $2);
838 my $target = $TokenToTargetMapping{"$lang:$token"};
839 my $source = "<pyGrammarToken><$lang><$token>";
840 $buffer =~ s/$source/$target/g;
841 }
842 open(GRAMMAR, ">$filename") || die "\n$!\n";
843 print GRAMMAR $buffer;
844 close(GRAMMAR);
845 }
846}
847
848sub strip_grammar_markup{
849 local($_) = @_;
850 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
851 s/\\token(<<\d+>>)(.+)\1/\2/g;
852 s/\\e([^a-zA-Z])/\\\1/g;
853 s/<<\d+>>//g;
854 s/;SPMgt;/>/g;
855 s/;SPMlt;/</g;
856 s/;SPMquot;/\"/g;
857 return $_;
858}
859
860
Fred Drakee15956b2000-04-03 04:51:13 +0000861$REFCOUNTS_LOADED = 0;
862
863sub load_refcounts{
864 $REFCOUNTS_LOADED = 1;
865
Fred Drakee15956b2000-04-03 04:51:13 +0000866 my $myname, $mydir, $myext;
867 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
868 chop $mydir; # remove trailing '/'
869 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
870 chop $mydir; # remove trailing '/'
871 $mydir = getcwd() . "$dd$mydir"
872 unless $mydir =~ s|^/|/|;
873 local $_;
874 my $filename = "$mydir${dd}api${dd}refcounts.dat";
875 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
876 print "[loading API refcount data]";
877 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000878 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000879 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
880 #print "\n$func($param) --> $count";
881 $REFCOUNTS{"$func:$param"} = $count;
882 }
883 }
884}
885
886sub get_refcount{
887 my ($func, $param) = @_;
888 load_refcounts()
889 unless $REFCOUNTS_LOADED;
890 return $REFCOUNTS{"$func:$param"};
891}
892
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000893
894$TLSTART = '<span class="typelabel">';
895$TLEND = '</span>';
896
Fred Drake6659c301998-03-03 22:02:19 +0000897sub do_env_cfuncdesc{
898 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000899 my $return_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000900 my $function_name = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000901 my $arg_list = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000902 my $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000903 "<tt class=\"cfunction\">$function_name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000904 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000905 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drakee15956b2000-04-03 04:51:13 +0000906 my $result_rc = get_refcount($function_name, '');
907 my $rcinfo = '';
908 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000909 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000910 }
911 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000912 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000913 }
Fred Drakec2578c52000-04-10 18:26:45 +0000914 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000915 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000916 }
Fred Drakee15956b2000-04-03 04:51:13 +0000917 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000918 $rcinfo = ( "\n<div class=\"refcount-info\">"
919 . "\n <span class=\"label\">Return value:</span>"
920 . "\n <span class=\"value\">$rcinfo.</span>"
921 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000922 }
Fred Drakec612a142001-03-29 18:24:08 +0000923 return "<dl><dt>$return_type <b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000924 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000925 . $_
926 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000927}
928
Fred Drakee15956b2000-04-03 04:51:13 +0000929sub do_env_csimplemacrodesc{
930 local($_) = @_;
931 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000932 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000933 return "<dl><dt><b>$idx</b>\n<dd>"
934 . $_
935 . '</dl>'
936}
937
Fred Drake6659c301998-03-03 22:02:19 +0000938sub do_env_ctypedesc{
939 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000940 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000941 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000942 $index_name = $type_name
943 unless $index_name;
944 my($name,$aname,$ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000945 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
946 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000947 . $_
948 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +0000949}
950
951sub do_env_cvardesc{
952 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000953 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000954 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000955 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +0000956 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000957 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +0000958 return "<dl><dt>$var_type <b>$idx</b>\n"
959 . '<dd>'
960 . $_
961 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000962}
963
Fred Drake3cdb89d2000-09-14 20:17:23 +0000964sub convert_args($){
965 local($IN_DESC_HANDLER) = 1;
966 local($_) = @_;
967 return translate_commands($_);
968}
969
Fred Drake6659c301998-03-03 22:02:19 +0000970sub do_env_funcdesc{
971 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000972 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000973 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000974 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
975 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +0000976 . get_indexsubitem());
977 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +0000978 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakec612a142001-03-29 18:24:08 +0000979 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000980}
981
982sub do_env_funcdescni{
983 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000984 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000985 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000986 return "<dl><dt><b><tt class=\"function\">$function_name</tt></b>"
Fred Drakec612a142001-03-29 18:24:08 +0000987 . "(<var>$arg_list</var>)\n"
Fred Drake90fdda51999-02-16 20:27:42 +0000988 . '<dd>'
989 . $_
990 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000991}
992
993sub do_cmd_funcline{
994 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000995 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +0000996 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +0000997 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +0000998 my $idx = make_str_index_entry($prefix . get_indexsubitem());
999 $prefix =~ s/\(\)//;
1000
Fred Drakec612a142001-03-29 18:24:08 +00001001 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001002}
1003
Fred Drake6b3fb781999-07-12 16:50:09 +00001004sub do_cmd_funclineni{
1005 local($_) = @_;
1006 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001007 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001008 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001009
Fred Drakec612a142001-03-29 18:24:08 +00001010 return "<dt><b>$prefix</b>(<var>$arg_list</var>)\n<dd>" . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001011}
1012
Fred Drake6659c301998-03-03 22:02:19 +00001013# Change this flag to index the opcode entries. I don't think it's very
1014# useful to index them, since they're only presented to describe the dis
1015# module.
1016#
1017$INDEX_OPCODES = 0;
1018
1019sub do_env_opcodedesc{
1020 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001021 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001022 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001023 my $idx;
1024 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001025 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1026 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001027 $idx =~ s/ \(byte code instruction\)//;
1028 }
1029 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001030 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001031 }
1032 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001033 if ($arg_list) {
1034 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1035 }
Fred Drake62e43691998-08-10 19:40:44 +00001036 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001037}
1038
1039sub do_env_datadesc{
1040 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001041 my $dataname = next_argument();
1042 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001043 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001044 return "<dl><dt><b>$idx</b>\n<dd>"
1045 . $_
1046 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001047}
1048
1049sub do_env_datadescni{
1050 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001051 my $idx = next_argument();
1052 if (! $STRING_INDEX_TT) {
1053 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001054 }
Fred Drake62e43691998-08-10 19:40:44 +00001055 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001056}
1057
1058sub do_cmd_dataline{
1059 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001060 my $data_name = next_argument();
1061 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001062 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001063 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001064}
1065
Fred Drakeadb272c2000-04-10 17:47:14 +00001066sub do_cmd_datalineni{
1067 local($_) = @_;
1068 my $data_name = next_argument();
1069 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1070}
1071
Fred Drake42b31a51998-03-27 05:16:10 +00001072sub do_env_excdesc{
1073 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001074 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001075 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001076 return ("<dl><dt><b>${TLSTART}exception$TLEND $idx</b>"
1077 . "\n<dd>"
1078 . $_
1079 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001080}
1081
Fred Drake62e43691998-08-10 19:40:44 +00001082sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001083
1084
Fred Drake643d76d2000-09-09 06:07:37 +00001085sub handle_classlike_descriptor{
1086 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001087 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001088 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001089 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001090 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001091 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001092 return ("<dl><dt><b>$TLSTART$what$TLEND $idx</b>"
1093 . "(<var>$arg_list</var>)\n<dd>"
Fred Drakeab357ec2001-03-02 18:57:05 +00001094 . $_
1095 . '</dl>');
Fred Drakec9a44381998-03-17 06:29:13 +00001096}
1097
Fred Drake643d76d2000-09-09 06:07:37 +00001098sub do_env_classdesc{
1099 return handle_classlike_descriptor(@_[0], "class");
1100}
1101
Fred Drake06a01e82001-05-11 01:00:30 +00001102sub do_env_classdescstar{
1103 local($_) = @_;
1104 $THIS_CLASS = next_argument();
1105 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001106 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001107 $idx =~ s/ \(.*\)//;
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001108 return ("<dl><dt><b>${TLSTART}class$TLEND $idx</b>\n<dd>"
Fred Drake06a01e82001-05-11 01:00:30 +00001109 . $_
1110 . '</dl>');
1111}
1112
Fred Drake643d76d2000-09-09 06:07:37 +00001113sub do_env_excclassdesc{
1114 return handle_classlike_descriptor(@_[0], "exception");
1115}
1116
Fred Drake42b31a51998-03-27 05:16:10 +00001117
1118sub do_env_methoddesc{
1119 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001120 my $class_name = next_optional_argument();
1121 $class_name = $THIS_CLASS
1122 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001123 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001124 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001125 my $extra = '';
1126 if ($class_name) {
1127 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001128 }
Fred Drakef1927a62001-06-20 21:29:30 +00001129 my $idx = make_str_index_entry(
1130 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001131 $idx =~ s/ \(.*\)//;
1132 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001133 return "<dl><dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001134}
1135
1136
Fred Drake7d45f6d1999-01-05 14:39:27 +00001137sub do_cmd_methodline{
1138 local($_) = @_;
1139 my $class_name = next_optional_argument();
1140 $class_name = $THIS_CLASS
1141 unless $class_name;
1142 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001143 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001144 my $extra = '';
1145 if ($class_name) {
1146 $extra = " ($class_name method)";
1147 }
Fred Drakef1927a62001-06-20 21:29:30 +00001148 my $idx = make_str_index_entry(
1149 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001150 $idx =~ s/ \(.*\)//;
1151 $idx =~ s/\(\)//;
Fred Drakec612a142001-03-29 18:24:08 +00001152 return "<dt><b>$idx</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake7d45f6d1999-01-05 14:39:27 +00001153 . $_;
1154}
1155
1156
Fred Draked64a40d1998-09-10 18:59:13 +00001157sub do_cmd_methodlineni{
1158 local($_) = @_;
1159 next_optional_argument();
1160 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001161 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001162 return "<dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Draked64a40d1998-09-10 18:59:13 +00001163 . $_;
1164}
1165
Fred Drake42b31a51998-03-27 05:16:10 +00001166sub do_env_methoddescni{
1167 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001168 next_optional_argument();
1169 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001170 my $arg_list = convert_args(next_argument());
Fred Drakec612a142001-03-29 18:24:08 +00001171 return "<dl><dt><b>$method</b>(<var>$arg_list</var>)\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001172 . $_
1173 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001174}
1175
1176
1177sub do_env_memberdesc{
1178 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001179 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001180 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001181 $class = $THIS_CLASS
1182 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001183 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001184 $extra = " ($class attribute)"
1185 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001186 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001187 $idx =~ s/ \(.*\)//;
1188 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001189 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001190}
1191
1192
Fred Drake5ccf3301998-04-17 20:04:09 +00001193sub do_cmd_memberline{
1194 local($_) = @_;
1195 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001196 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001197 $class = $THIS_CLASS
1198 unless $class;
1199 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001200 $extra = " ($class attribute)"
1201 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001202 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001203 $idx =~ s/ \(.*\)//;
1204 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001205 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001206}
1207
Fred Drakef269e592001-07-17 23:05:57 +00001208
Fred Drake42b31a51998-03-27 05:16:10 +00001209sub do_env_memberdescni{
1210 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001211 next_optional_argument();
1212 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001213 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001214 . $_
1215 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001216}
1217
1218
Fred Drake5ccf3301998-04-17 20:04:09 +00001219sub do_cmd_memberlineni{
1220 local($_) = @_;
1221 next_optional_argument();
1222 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001223 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001224}
1225
Fred Drakef269e592001-07-17 23:05:57 +00001226
1227@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001228
Fred Drakecb199762001-08-16 21:56:24 +00001229%FontConversions = ('cdata' => 'tt class="cdata"',
1230 'character' => 'tt class="character"',
1231 'class' => 'tt class="class"',
1232 'command' => 'code',
1233 'constant' => 'tt class="constant"',
1234 'exception' => 'tt class="exception"',
1235 'file' => 'tt class="file"',
1236 'filenq' => 'tt class="file"',
1237 'kbd' => 'kbd',
1238 'member' => 'tt class="member"',
1239 'programopt' => 'b',
1240 'textrm' => '',
1241 );
1242
Fred Drakef74e5b71999-04-28 14:58:49 +00001243sub fix_font{
1244 # do a little magic on a font name to get the right behavior in the first
1245 # column of the output table
1246 my $font = @_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001247 if (defined $FontConversions{$font}) {
1248 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001249 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001250 return $font;
1251}
1252
Fred Drakee15956b2000-04-03 04:51:13 +00001253sub figure_column_alignment{
1254 my $a = @_[0];
1255 my $mark = substr($a, 0, 1);
1256 my $r = '';
1257 if ($mark eq 'c')
1258 { $r = ' align="center"'; }
1259 elsif ($mark eq 'r')
1260 { $r = ' align="right"'; }
1261 elsif ($mark eq 'l')
1262 { $r = ' align="left"'; }
1263 elsif ($mark eq 'p')
1264 { $r = ' align="left"'; }
1265 return $r;
1266}
1267
Fred Drake6659c301998-03-03 22:02:19 +00001268sub setup_column_alignments{
1269 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001270 my($s1,$s2,$s3,$s4,$a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001271 my $a1 = figure_column_alignment($s1);
1272 my $a2 = figure_column_alignment($s2);
1273 my $a3 = figure_column_alignment($s3);
1274 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001275 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001276 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1277 $col_aligns[1] = "<td$a2>";
1278 $col_aligns[2] = "<td$a3>";
1279 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001280 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001281 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001282 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001283}
1284
1285sub get_table_col1_fonts{
1286 my $font = $globals{'lineifont'};
1287 my ($sfont,$efont) = ('', '');
1288 if ($font) {
1289 $sfont = "<$font>";
1290 $efont = "</$font>";
1291 $efont =~ s/ .*>/>/;
1292 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001293 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001294}
1295
1296sub do_env_tableii{
1297 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001298 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001299 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001300 my $h1 = next_argument();
1301 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001302 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001303 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001304 my $a1 = $col_aligns[0];
1305 my $a2 = $col_aligns[1];
1306 s/\\lineii</\\lineii[$a1|$a2]</g;
1307 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001308 . "\n <thead>"
1309 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001310 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1311 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001312 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001313 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001314 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001315 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001316 . "\n </tbody>"
1317 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001318}
1319
Fred Drakeda72b932000-09-21 15:58:02 +00001320sub do_env_longtableii{
1321 return do_env_tableii(@_);
1322}
1323
Fred Drake6659c301998-03-03 22:02:19 +00001324sub do_cmd_lineii{
1325 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001326 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001327 my $c1 = next_argument();
1328 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001329 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001330 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001331 $c2 = '&nbsp;' if ($c2 eq '');
1332 my($c1align,$c2align) = split('\|', $aligns);
1333 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001334 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001335 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001336 }
Fred Drakee15956b2000-04-03 04:51:13 +00001337 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1338 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001339 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001340}
1341
1342sub do_env_tableiii{
1343 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001344 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001345 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001346 my $h1 = next_argument();
1347 my $h2 = next_argument();
1348 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001349 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001350 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001351 my $a1 = $col_aligns[0];
1352 my $a2 = $col_aligns[1];
1353 my $a3 = $col_aligns[2];
1354 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1355 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001356 . "\n <thead>"
1357 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001358 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1359 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1360 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001361 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001362 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001363 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001364 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001365 . "\n </tbody>"
1366 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001367}
1368
Fred Drakeda72b932000-09-21 15:58:02 +00001369sub do_env_longtableiii{
1370 return do_env_tableiii(@_);
1371}
1372
Fred Drake6659c301998-03-03 22:02:19 +00001373sub do_cmd_lineiii{
1374 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001375 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001376 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001377 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001378 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001379 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001380 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001381 $c3 = '&nbsp;' if ($c3 eq '');
1382 my($c1align,$c2align,$c3align) = split('\|', $aligns);
1383 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001384 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001385 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001386 }
Fred Drakee15956b2000-04-03 04:51:13 +00001387 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001388 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001389 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001390 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001391}
1392
Fred Drakea0f4c941998-07-24 22:16:04 +00001393sub do_env_tableiv{
1394 local($_) = @_;
Fred Drakef269e592001-07-17 23:05:57 +00001395 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
Fred Drakef74e5b71999-04-28 14:58:49 +00001396 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001397 my $h1 = next_argument();
1398 my $h2 = next_argument();
1399 my $h3 = next_argument();
1400 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001401 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001402 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001403 my $a1 = $col_aligns[0];
1404 my $a2 = $col_aligns[1];
1405 my $a3 = $col_aligns[2];
1406 my $a4 = $col_aligns[3];
1407 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1408 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001409 . "\n <thead>"
1410 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001411 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1412 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1413 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1414 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001415 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001416 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001417 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001418 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001419 . "\n </tbody>"
1420 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001421}
1422
Fred Drakeda72b932000-09-21 15:58:02 +00001423sub do_env_longtableiv{
1424 return do_env_tableiv(@_);
1425}
1426
Fred Drakea0f4c941998-07-24 22:16:04 +00001427sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001428 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001429 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001430 my $c1 = next_argument();
1431 my $c2 = next_argument();
1432 my $c3 = next_argument();
1433 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001434 s/[\s\n]+//;
Fred Drakee463f8e2000-11-30 07:17:27 +00001435 my($sfont,$efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001436 $c4 = '&nbsp;' if ($c4 eq '');
1437 my($c1align,$c2align,$c3align,$c4align) = split('\|', $aligns);
1438 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001439 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001440 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001441 }
Fred Drakee15956b2000-04-03 04:51:13 +00001442 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001443 . " $c2align$c2</td>\n"
1444 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001445 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001446 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001447}
1448
Fred Drakef269e592001-07-17 23:05:57 +00001449sub do_env_tablev{
1450 local($_) = @_;
1451 my($th1,$th2,$th3,$th4,$th5) = setup_column_alignments(next_argument());
1452 my $font = fix_font(next_argument());
1453 my $h1 = next_argument();
1454 my $h2 = next_argument();
1455 my $h3 = next_argument();
1456 my $h4 = next_argument();
1457 my $h5 = next_argument();
1458 s/[\s\n]+//;
1459 $globals{'lineifont'} = $font;
1460 my $a1 = $col_aligns[0];
1461 my $a2 = $col_aligns[1];
1462 my $a3 = $col_aligns[2];
1463 my $a4 = $col_aligns[3];
1464 my $a5 = $col_aligns[4];
1465 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1466 return '<table border align="center" style="border-collapse: collapse">'
1467 . "\n <thead>"
1468 . "\n <tr class=\"tableheader\">"
1469 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1470 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1471 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1472 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1473 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1474 . "\n </tr>"
1475 . "\n </thead>"
1476 . "\n <tbody valign=\"baseline\">"
1477 . $_
1478 . "\n </tbody>"
1479 . "\n</table>";
1480}
1481
1482sub do_env_longtablev{
1483 return do_env_tablev(@_);
1484}
1485
1486sub do_cmd_linev{
1487 local($_) = @_;
1488 my $aligns = next_optional_argument();
1489 my $c1 = next_argument();
1490 my $c2 = next_argument();
1491 my $c3 = next_argument();
1492 my $c4 = next_argument();
1493 my $c5 = next_argument();
1494 s/[\s\n]+//;
1495 my($sfont,$efont) = get_table_col1_fonts();
1496 $c5 = '&nbsp;' if ($c5 eq '');
1497 my($c1align,$c2align,$c3align,$c4align,$c5align) = split('\|', $aligns);
1498 my $padding = '';
1499 if ($c1align =~ /align="right"/ || $c1 eq '') {
1500 $padding = '&nbsp;';
1501 }
1502 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1503 . " $c2align$c2</td>\n"
1504 . " $c3align$c3</td>\n"
1505 . " $c4align$c4</td>\n"
1506 . " $c5align$c5</td>"
1507 . $_;
1508}
1509
Fred Drake3be20742000-08-31 06:22:54 +00001510
1511# These can be used to control the title page appearance;
1512# they need a little bit of documentation.
1513#
1514# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1515# $ICONSERVER directory, or include path information (other than "./"). The
1516# default image type will be assumed if an extension is not provided.
1517#
1518# If specified, the "title page" will contain two colums: one containing the
1519# title/author/etc., and the other containing the graphic. Use the other
1520# four variables listed here to control specific details of the layout; all
1521# are optional.
1522#
1523# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1524# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1525# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1526# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1527# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1528
1529sub make_my_titlepage() {
1530 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001531 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001532 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001533 }
1534 else {
1535 write_warnings("\nThis document has no title.");
1536 }
Fred Drake6659c301998-03-03 22:02:19 +00001537 if ($t_author) {
1538 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001539 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001540 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001541 "<b><font size=\"+2\">$t_author"
1542 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001543 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001544 }
1545 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001546 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1547 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001548 }
Fred Drake3be20742000-08-31 06:22:54 +00001549 }
1550 else {
1551 write_warnings("\nThere is no author for this document.");
1552 }
Fred Drake6659c301998-03-03 22:02:19 +00001553 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001554 $the_title .= "\n<p>$t_institute</p>";
1555 }
Fred Draked07868a1998-05-14 21:00:28 +00001556 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001557 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1558 }
Fred Drake6659c301998-03-03 22:02:19 +00001559 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001560 $the_title .= "\n<p><i>$t_affil</i></p>";
1561 }
Fred Drake6659c301998-03-03 22:02:19 +00001562 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001563 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001564 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001565 $the_title .= ('<strong>Release '
1566 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001567 }
Fred Drakede77bc52000-12-14 18:36:12 +00001568 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001569 }
1570 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001571 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001572 }
1573 else {
1574 $the_title .= "\n<p>";
1575 }
Fred Drake6659c301998-03-03 22:02:19 +00001576 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001577 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001578 }
1579 return $the_title;
1580}
1581
Fred Drake3be20742000-08-31 06:22:54 +00001582sub make_my_titlegraphic() {
Fred Drake7a40c072000-10-02 14:43:38 +00001583 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001584 my $graphic = "<td class=\"titlegraphic\"";
1585 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1586 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1587 $graphic .= "><img";
1588 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1589 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1590 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1591 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001592 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001593 return $graphic;
1594}
1595
1596sub do_cmd_maketitle {
1597 local($_) = @_;
1598 my $the_title = "\n<div class=\"titlepage\">";
1599 if ($TITLE_PAGE_GRAPHIC) {
1600 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1601 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1602 . "<tr align=\"right\">\n<td>"
1603 . make_my_titlepage()
1604 . "</td>\n"
1605 . make_my_titlegraphic()
1606 . "</tr>\n</table>");
1607 }
1608 else {
1609 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1610 . make_my_titlegraphic()
1611 . "<td>"
1612 . make_my_titlepage()
1613 . "</td></tr>\n</table>");
1614 }
1615 }
1616 else {
1617 $the_title .= ("\n<center>"
1618 . make_my_titlepage()
1619 . "\n</center>");
1620 }
1621 $the_title .= "\n</div>";
1622 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001623 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001624 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001625}
1626
1627
Fred Drake885215c1998-05-20 21:32:09 +00001628#
Fred Drakea0f4c941998-07-24 22:16:04 +00001629# Module synopsis support
1630#
1631
1632require SynopsisTable;
1633
Fred Drakef7685d71998-07-25 03:31:46 +00001634sub get_chapter_id(){
1635 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001636 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1637 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001638 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001639}
1640
Fred Drake643d76d2000-09-09 06:07:37 +00001641# 'chapter' => 'SynopsisTable instance'
1642%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001643
1644sub get_synopsis_table($){
1645 my($chap) = @_;
Fred Drakef7685d71998-07-25 03:31:46 +00001646 my $key;
1647 foreach $key (keys %ModuleSynopses) {
1648 if ($key eq $chap) {
1649 return $ModuleSynopses{$chap};
1650 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001651 }
Fred Drake643d76d2000-09-09 06:07:37 +00001652 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001653 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001654 return $st;
1655}
1656
Fred Drake62e43691998-08-10 19:40:44 +00001657sub do_cmd_moduleauthor{
1658 local($_) = @_;
1659 next_argument();
1660 next_argument();
1661 return $_;
1662}
1663
1664sub do_cmd_sectionauthor{
1665 local($_) = @_;
1666 next_argument();
1667 next_argument();
1668 return $_;
1669}
1670
Fred Drakea0f4c941998-07-24 22:16:04 +00001671sub do_cmd_declaremodule{
1672 local($_) = @_;
1673 my $key = next_optional_argument();
1674 my $type = next_argument();
1675 my $name = next_argument();
1676 my $st = get_synopsis_table(get_chapter_id());
1677 #
1678 $key = $name unless $key;
1679 $type = 'built-in' if $type eq 'builtin';
1680 $st->declare($name, $key, $type);
1681 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001682 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001683}
1684
1685sub do_cmd_modulesynopsis{
1686 local($_) = @_;
1687 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001688 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001689 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001690}
1691
1692sub do_cmd_localmoduletable{
1693 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001694 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001695 my $st = get_synopsis_table($chap);
1696 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001697 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001698}
1699
1700sub process_all_localmoduletables{
Fred Drake643d76d2000-09-09 06:07:37 +00001701 my $key;
1702 my $st, $file;
1703 foreach $key (keys %ModuleSynopses) {
1704 $st = $ModuleSynopses{$key};
1705 $file = $st->get_file();
1706 if ($file) {
1707 process_localmoduletables_in_file($file);
1708 }
1709 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001710 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001711 }
1712 }
1713}
1714
1715sub process_localmoduletables_in_file{
1716 my $file = @_[0];
1717 open(MYFILE, "<$file");
1718 local($_);
1719 sysread(MYFILE, $_, 1024*1024);
1720 close(MYFILE);
1721 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001722 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001723 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001724 my $chap = $1;
1725 my $st = get_synopsis_table($chap);
1726 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001727 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001728 }
Fred Drake643d76d2000-09-09 06:07:37 +00001729 open(MYFILE,">$file");
1730 print MYFILE $_;
1731 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001732}
Fred Drake557460c1999-03-02 16:05:35 +00001733sub process_python_state{
1734 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001735 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001736}
Fred Drakea0f4c941998-07-24 22:16:04 +00001737
1738
1739#
1740# "See also:" -- references placed at the end of a \section
1741#
1742
1743sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001744 return ("<div class=\"seealso\">\n "
1745 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1746 . @_[0]
1747 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001748}
1749
Fred Drake5ed35fd2001-11-30 18:09:54 +00001750sub do_env_seealsostar{
1751 return ("<div class=\"seealso-simple\">\n "
1752 . @_[0]
1753 . '</div>');
1754}
1755
Fred Drakea0f4c941998-07-24 22:16:04 +00001756sub do_cmd_seemodule{
1757 # Insert the right magic to jump to the module definition. This should
1758 # work most of the time, at least for repeat builds....
1759 local($_) = @_;
1760 my $key = next_optional_argument();
1761 my $module = next_argument();
1762 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001763 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001764 $key = $module
1765 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001766 if ($text =~ /\.$/) {
1767 $period = '';
1768 }
Fred Drakef1927a62001-06-20 21:29:30 +00001769 return ('<dl compact class="seemodule">'
1770 . "\n <dt>Module <b><tt class=\"module\">"
1771 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1772 . "\n <dd>$text$period\n </dl>"
1773 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001774}
1775
Fred Drakee0197bf2001-04-12 04:03:22 +00001776sub strip_html_markup($){
1777 my $str = @_[0];
1778 my $s = "$str";
1779 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1780 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1781 return $s;
1782}
1783
Fred Drake643d76d2000-09-09 06:07:37 +00001784sub handle_rfclike_reference{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001785 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001786 my $rfcnum = next_argument();
1787 my $title = next_argument();
1788 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001789 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001790 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001791 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001792 return '<dl compact class="seerfc">'
1793 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001794 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001795 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001796 . "\n <dd>$text\n </dl>"
1797 . $_;
1798}
1799
Fred Drake643d76d2000-09-09 06:07:37 +00001800sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001801 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001802}
1803
1804sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001805 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001806}
1807
Fred Drake48449982000-09-12 17:52:33 +00001808sub do_cmd_seetitle{
1809 local($_) = @_;
1810 my $url = next_optional_argument();
1811 my $title = next_argument();
1812 my $text = next_argument();
1813 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001814 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001815 return '<dl compact class="seetitle">'
1816 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001817 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001818 . "\n <dd>$text\n </dl>"
1819 . $_;
1820 }
1821 return '<dl compact class="seetitle">'
1822 . "\n <dt><em class=\"citetitle\""
1823 . "\n >$title</em>"
1824 . "\n <dd>$text\n </dl>"
1825 . $_;
1826}
1827
Fred Drakeef4d1112000-05-09 16:17:51 +00001828sub do_cmd_seeurl{
1829 local($_) = @_;
1830 my $url = next_argument();
1831 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001832 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001833 return '<dl compact class="seeurl">'
1834 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001835 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001836 . "\n <dd>$text\n </dl>"
1837 . $_;
1838}
1839
Fred Drakea0f4c941998-07-24 22:16:04 +00001840sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001841 local($_) = @_;
1842 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001843 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001844}
1845
1846
1847#
Fred Drake885215c1998-05-20 21:32:09 +00001848# Definition list support.
1849#
1850
1851sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001852 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001853}
1854
1855sub do_cmd_term{
1856 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001857 my $term = next_argument();
1858 my($name,$aname,$ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001859 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001860 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001861}
1862
1863
Fred Drake38178fd2000-09-22 17:05:04 +00001864# I don't recall exactly why this was needed, but it was very much needed.
1865# We'll see if anything breaks when I move the "code" line out -- some
1866# things broke with it in.
1867
1868#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001869process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001870declaremodule # [] # {} # {}
1871memberline # [] # {}
1872methodline # [] # {} # {}
1873modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001874platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001875samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001876setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001877withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001878_RAW_ARG_DEFERRED_CMDS_
1879
1880
Fred Drake86333602001-04-10 17:13:39 +00001881$alltt_start = '<dl><dd><pre class="verbatim">';
1882$alltt_end = '</pre></dl>';
1883
1884sub do_env_alltt {
1885 local ($_) = @_;
1886 local($closures,$reopens,@open_block_tags);
1887
1888 # get the tag-strings for all open tags
1889 local(@keep_open_tags) = @$open_tags_R;
1890 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1891
1892 # get the tags for text-level tags only
1893 $open_tags_R = [ @keep_open_tags ];
1894 local($local_closures, $local_reopens);
1895 ($local_closures, $local_reopens,@open_block_tags)
1896 = &preserve_open_block_tags
1897 if (@$open_tags_R);
1898
1899 $open_tags_R = [ @open_block_tags ];
1900
1901 do {
1902 local($open_tags_R) = [ @open_block_tags ];
1903 local(@save_open_tags) = ();
1904
1905 local($cnt) = ++$global{'max_id'};
1906 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1907 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1908
1909 $_ = &translate_environments($_);
1910 $_ = &translate_commands($_) if (/\\/);
1911
1912 # preserve space-runs, using &nbsp;
1913 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1914 s/(<BR>) /$1;SPMnbsp;/g;
1915
1916 $_ = join('', $closures, $alltt_start, $local_reopens
1917 , $_
1918 , &balance_tags() #, $local_closures
1919 , $alltt_end, $reopens);
1920 undef $open_tags_R; undef @save_open_tags;
1921 };
1922 $open_tags_R = [ @keep_open_tags ];
1923 $_;
1924}
1925
Fred Drake57e52ef2001-06-15 21:31:57 +00001926sub do_cmd_verbatiminput{
1927 local($_) = @_;
1928 my $fname = next_argument();
1929 my $file;
1930 my $found = 0;
1931 my $texpath;
1932 # Search TEXINPUTS for the input file, the way we're supposed to:
1933 foreach $texpath (split /$envkey/, $TEXINPUTS) {
1934 $file = "$texpath$dd$fname";
1935 last if ($found = (-f $file));
1936 }
Fred Drake77602f22001-07-06 22:43:02 +00001937 my $srcname;
Fred Drake57e52ef2001-06-15 21:31:57 +00001938 my $text;
1939 if ($found) {
1940 open(MYFILE, "<$file") || die "\n$!\n";
1941 read(MYFILE, $text, 1024*1024);
1942 close(MYFILE);
Fred Drake77602f22001-07-06 22:43:02 +00001943 use File::Basename;
1944 my $srcdir, $srcext;
1945 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1946 open(MYFILE, ">$srcname.txt");
1947 print MYFILE $text;
1948 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00001949 #
1950 # These rewrites convert the raw text to something that will
1951 # be properly visible as HTML and also will pass through the
1952 # vagaries of conversion through LaTeX2HTML. The order in
1953 # which the specific rewrites are performed is significant.
1954 #
1955 $text =~ s/\&/\&amp;/g;
1956 # These need to happen before the normal < and > re-writes,
1957 # since we need to avoid LaTeX2HTML's attempt to perform
1958 # ligature processing without regard to context (since it
1959 # doesn't have font information).
1960 $text =~ s/--/-&\#45;/g;
1961 $text =~ s/<</\&lt;\&\#60;/g;
1962 $text =~ s/>>/\&gt;\&\#62;/g;
1963 # Just normal re-writes...
1964 $text =~ s/</\&lt;/g;
1965 $text =~ s/>/\&gt;/g;
1966 # These last isn't needed for the HTML, but is needed to get
1967 # past LaTeX2HTML processing TeX macros. We use &#92; instead
1968 # of &sol; since many browsers don't support that.
1969 $text =~ s/\\/\&\#92;/g;
1970 }
1971 else {
1972 $text = '<b>Could not locate requested file <i>$fname</i>!</b>\n';
1973 }
Fred Drake77602f22001-07-06 22:43:02 +00001974 return ('<dl><dd><pre class="verbatim">'
Fred Drake57e52ef2001-06-15 21:31:57 +00001975 . $text
Fred Drake77602f22001-07-06 22:43:02 +00001976 . "</pre>\n<div class=\"verbatiminput-footer\">\n"
1977 . "<a href=\"$srcname.txt\" type=\"text/plain\""
1978 . ">Download as text.</a>"
1979 . "\n</div>\n</dd></dl>"
Fred Drake57e52ef2001-06-15 21:31:57 +00001980 . $_);
1981}
Fred Drake86333602001-04-10 17:13:39 +00001982
Fred Drake6659c301998-03-03 22:02:19 +000019831; # This must be the last line