blob: 879134674beb6f8c95bcefa0ab06e1659bcb4a7c [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{
Fred Drakef5478632002-05-23 17:59:16 +000023 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 Drakef5478632002-05-23 17:59:16 +0000153sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000154 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 Drake2ff880e1999-02-05 18:31:29 +0000175sub do_cmd_pytype{ return @_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000176sub do_cmd_makevar{
177 return use_wrappers(@_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000178sub do_cmd_code{
Fred Drakee15956b2000-04-03 04:51:13 +0000179 return use_wrappers(@_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000180sub do_cmd_module{
Fred Drakee15956b2000-04-03 04:51:13 +0000181 return use_wrappers(@_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000182sub do_cmd_keyword{
Fred Drakee15956b2000-04-03 04:51:13 +0000183 return use_wrappers(@_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_exception{
Fred Drakee15956b2000-04-03 04:51:13 +0000185 return use_wrappers(@_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000186sub do_cmd_class{
Fred Drakee15956b2000-04-03 04:51:13 +0000187 return use_wrappers(@_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000188sub do_cmd_function{
Fred Drakee15956b2000-04-03 04:51:13 +0000189 return use_wrappers(@_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_constant{
Fred Drakee15956b2000-04-03 04:51:13 +0000191 return use_wrappers(@_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_member{
Fred Drakee15956b2000-04-03 04:51:13 +0000193 return use_wrappers(@_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000194sub do_cmd_method{
Fred Drakee15956b2000-04-03 04:51:13 +0000195 return use_wrappers(@_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_cfunction{
Fred Drakee15956b2000-04-03 04:51:13 +0000197 return use_wrappers(@_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_cdata{
Fred Drakee15956b2000-04-03 04:51:13 +0000199 return use_wrappers(@_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_ctype{
Fred Drakee15956b2000-04-03 04:51:13 +0000201 return use_wrappers(@_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_regexp{
Fred Drakee15956b2000-04-03 04:51:13 +0000203 return use_wrappers(@_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_character{
Fred Drakee15956b2000-04-03 04:51:13 +0000205 return use_wrappers(@_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_program{
Fred Drakee15956b2000-04-03 04:51:13 +0000207 return use_wrappers(@_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000208sub do_cmd_programopt{
209 return use_wrappers(@_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000210sub do_cmd_longprogramopt{
211 # note that the --- will be later converted to -- by LaTeX2HTML
212 return use_wrappers(@_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000213sub do_cmd_email{
Fred Drakee15956b2000-04-03 04:51:13 +0000214 return use_wrappers(@_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000215sub do_cmd_mailheader{
Fred Drake479384e2001-09-26 18:46:36 +0000216 return use_wrappers(@_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_mimetype{
Fred Drakee15956b2000-04-03 04:51:13 +0000218 return use_wrappers(@_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_var{
220 return use_wrappers(@_[0], "<var>", "</var>"); }
221sub do_cmd_dfn{
Fred Drakee15956b2000-04-03 04:51:13 +0000222 return use_wrappers(@_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_emph{
Fred Drake38178fd2000-09-22 17:05:04 +0000224 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_file{
Fred Drake3d5a04a2000-08-03 17:25:44 +0000226 return use_wrappers(@_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000227sub do_cmd_filenq{
Fred Drakee15956b2000-04-03 04:51:13 +0000228 return do_cmd_file(@_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000229sub do_cmd_samp{
Fred Drakee15956b2000-04-03 04:51:13 +0000230 return use_wrappers(@_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000231sub do_cmd_kbd{
232 return use_wrappers(@_[0], '<kbd>', '</kbd>'); }
233sub do_cmd_strong{
234 return use_wrappers(@_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000235sub do_cmd_textbf{
236 return use_wrappers(@_[0], '<b>', '</b>'); }
237sub do_cmd_textit{
238 return use_wrappers(@_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000239# This can be changed/overridden for translations:
240%NoticeNames = ('note' => 'Note:',
241 'warning' => 'Warning:',
242 );
243
Fred Drake92350b32001-10-09 18:01:23 +0000244sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000245 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000246 return use_wrappers(
247 @_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000248 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000249 '</span>'); }
250sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000251 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000252 return use_wrappers(
253 @_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000254 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000255 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000256
Fred Drake6ca33772001-12-14 22:50:06 +0000257sub do_env_notice{
258 local($_) = @_;
259 my $notice = next_optional_argument();
260 if (!$notice) {
261 $notice = 'note';
262 }
263 my $label = $NoticeNames{$notice};
264 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
265 . $_
266 . '</div>');
267}
268
Fred Drake3d5a04a2000-08-03 17:25:44 +0000269sub do_cmd_moreargs{
270 return '...' . @_[0]; }
271sub do_cmd_unspecified{
272 return '...' . @_[0]; }
273
Fred Drakec9a44381998-03-17 06:29:13 +0000274
Fred Drake25817041999-01-13 17:06:34 +0000275sub do_cmd_refmodule{
276 # Insert the right magic to jump to the module definition.
277 local($_) = @_;
278 my $key = next_optional_argument();
279 my $module = next_argument();
280 $key = $module
281 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000282 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000283 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000284}
285
Fred Drake1a7af391998-04-01 22:44:56 +0000286sub do_cmd_newsgroup{
287 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000288 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000289 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000290 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
291 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000292 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000293}
Fred Drakefc16e781998-03-12 21:03:26 +0000294
295sub do_cmd_envvar{
296 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000297 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000298 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000299 # The <tt> here is really to keep buildindex.py from making
300 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000301 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000302 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000303 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000304 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000305 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000306}
307
Fred Drake6659c301998-03-03 22:02:19 +0000308sub do_cmd_url{
309 # use the URL as both text and hyperlink
310 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000311 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000312 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000313 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000314 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000315}
316
317sub do_cmd_manpage{
318 # two parameters: \manpage{name}{section}
319 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000320 my $page = next_argument();
321 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000322 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000323}
324
Fred Drakedbfe7682002-04-03 02:47:14 +0000325$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000326#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
327$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000328
329sub get_rfc_url($$){
330 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000331 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000332}
333
334sub do_cmd_pep{
335 local($_) = @_;
336 my $rfcnumber = next_argument();
337 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000338 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000339 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000340 # Save the reference
341 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
342 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000343 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
344 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000345}
346
Fred Drake6659c301998-03-03 22:02:19 +0000347sub do_cmd_rfc{
348 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000349 my $rfcnumber = next_argument();
350 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000351 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000352 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000353 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000354 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000355 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000356 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
357 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000358}
359
Fred Drake77602f22001-07-06 22:43:02 +0000360sub do_cmd_ulink{
361 local($_) = @_;
362 my $text = next_argument();
363 my $url = next_argument();
364 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
365}
366
Fred Drakec9f5fe01999-11-09 16:59:42 +0000367sub do_cmd_citetitle{
368 local($_) = @_;
369 my $url = next_optional_argument();
370 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000371 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000372 my $repl = '';
373 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000374 $repl = ("<em class=\"citetitle\"><a\n"
375 . " href=\"$url\"\n"
376 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000377 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000378 }
379 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000380 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000381 }
382 return $repl . $_;
383}
384
Fred Drake6659c301998-03-03 22:02:19 +0000385sub do_cmd_deprecated{
386 # two parameters: \deprecated{version}{whattodo}
387 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000388 my $release = next_argument();
389 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000390 return ('<div class="versionnote">'
391 . "<b>Deprecated since release $release.</b>"
392 . "\n$reason</div><p>"
393 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000394}
395
Fred Drakef5478632002-05-23 17:59:16 +0000396sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000397 # one or two parameters: \versionnote[explanation]{version}
398 my $type = @_[0];
399 local $_ = @_[1];
400 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000401 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000402 my $text = "$type in version $release.";
403 if ($explanation) {
404 $text = "$type in version $release:\n$explanation.";
405 }
Fred Drakef1927a62001-06-20 21:29:30 +0000406 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000407}
408
409sub do_cmd_versionadded{
Fred Drakef5478632002-05-23 17:59:16 +0000410 return versionnote('New', @_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000411}
412
413sub do_cmd_versionchanged{
Fred Drakef5478632002-05-23 17:59:16 +0000414 return versionnote('Changed', @_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000415}
416
Fred Drake557460c1999-03-02 16:05:35 +0000417#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000418# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000419#
420sub do_cmd_platform{
421 local($_) = @_;
422 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000423 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000424 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000425 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000426 return "\n<p class=\"availability\">Availability: <span"
427 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000428}
429
Fred Drake557460c1999-03-02 16:05:35 +0000430$IGNORE_PLATFORM_ANNOTATION = '';
431sub do_cmd_ignorePlatformAnnotation{
432 local($_) = @_;
433 $IGNORE_PLATFORM_ANNOTATION = next_argument();
434 return $_;
435}
436
Fred Drake6659c301998-03-03 22:02:19 +0000437
438# index commands
439
440$INDEX_SUBITEM = "";
441
Fred Drakef5478632002-05-23 17:59:16 +0000442sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000443 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000444}
445
446sub do_cmd_setindexsubitem{
447 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000448 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000449 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000450}
451
Fred Drakefc16e781998-03-12 21:03:26 +0000452sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000453 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000454 # do things in the right order, but we need to at least strip this stuff
455 # out, and leave anything that the second argument expanded out to.
456 #
457 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000458 my $oldsubitem = $INDEX_SUBITEM;
459 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000460 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000461 my $br_id = ++$globals{'max_id'};
462 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000463 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000464 return
465 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000466 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000467 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000468}
469
Fred Drake08932051998-04-17 02:15:42 +0000470# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000471# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
472# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000473#
Fred Drake62e43691998-08-10 19:40:44 +0000474sub do_cmd_makemodindex{ return @_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000475
Fred Drake42b31a51998-03-27 05:16:10 +0000476# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000477#
Fred Drake08932051998-04-17 02:15:42 +0000478open(IDXFILE, '>index.dat') || die "\n$!\n";
479open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000480print INTLABELS "%internal_labels = ();\n";
481print INTLABELS "1; # hack in case there are no entries\n\n";
482
483# Using \0 for this is bad because we can't use common tools to work with the
484# resulting files. Things like grep can be useful with this stuff!
485#
486$IDXFILE_FIELD_SEP = "\1";
487
Fred Drakef5478632002-05-23 17:59:16 +0000488sub write_idxfile($$){
489 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000490 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000491}
492
Fred Drake42b31a51998-03-27 05:16:10 +0000493
Fred Drakef5478632002-05-23 17:59:16 +0000494sub gen_link($$){
495 my($node, $target) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000496 print INTLABELS "\$internal_labels{\"$target\"} = \"$URL/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000497 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000498}
499
Fred Drakef5478632002-05-23 17:59:16 +0000500sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000501 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000502 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000503 $str = gen_index_id($str, '');
504 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000505 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000506}
507
Fred Drakef5478632002-05-23 17:59:16 +0000508sub new_link_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000509 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000510 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000511 my $ahref = gen_link($CURRENT_FILE, $name);
512 return ($name, $aname, $ahref);
513}
514
Fred Drakeab032151999-05-13 18:36:54 +0000515$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000516sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000517 my $count = @_;
518 my $i = 0;
519 for (; $i < $count; ++$i) {
520 my $name = @_[$i];
521 my $cmd = "idx_cmd_$name";
522 die "\nNo function $cmd() defined!\n"
523 if (!defined &$cmd);
524 eval ("sub do_cmd_$name { return process_index_macros("
525 . "\@_[0], '$name'); }");
526 if (length($IndexMacroPattern) == 0) {
527 $IndexMacroPattern = "$name";
528 }
529 else {
530 $IndexMacroPattern .= "|$name";
531 }
532 }
533}
534
535$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000536sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000537 local($_) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000538 my $cmdname = @_[1]; # This is what triggered us in the first place;
539 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000540 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000541 my $cmd = "idx_cmd_$cmdname";
542 print "\nIndexing: \\$cmdname"
543 if $DEBUG_INDEXING;
544 &$cmd($ahref); # modifies $_ and adds index entries
545 while (/^[\s\n]*\\($IndexMacroPattern)</) {
546 $cmdname = "$1";
547 print " \\$cmdname"
548 if $DEBUG_INDEXING;
549 $cmd = "idx_cmd_$cmdname";
550 if (!defined &$cmd) {
551 last;
552 }
553 else {
554 s/^[\s\n]*\\$cmdname//;
555 &$cmd($ahref);
556 }
557 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000558 if (/^[ \t\r\n]/) {
559 $_ = substr($_, 1);
560 }
Fred Drake62e43691998-08-10 19:40:44 +0000561 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000562}
563
Fred Drakeab032151999-05-13 18:36:54 +0000564define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000565sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000566 my $str = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000567 add_index_entry("$str", @_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000568}
569
Fred Drakeab032151999-05-13 18:36:54 +0000570define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000571sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000572 my $str = next_argument();
573 add_index_entry("<tt>$str</tt>!keyword", @_[0]);
574 add_index_entry("keyword!<tt>$str</tt>", @_[0]);
575}
576
577define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000578sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000579 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000580 my $str2 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000581 add_index_entry("$str1!$str2", @_[0]);
582 add_index_entry("$str2!$str1", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000583}
584
Fred Drakeab032151999-05-13 18:36:54 +0000585define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000586sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000587 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000588 my $str2 = next_argument();
589 my $str3 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000590 add_index_entry("$str1!$str2 $str3", @_[0]);
591 add_index_entry("$str2!$str3, $str1", @_[0]);
592 add_index_entry("$str3!$str1 $str2", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000593}
594
Fred Drakeab032151999-05-13 18:36:54 +0000595define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000596sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000597 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000598 my $str2 = next_argument();
599 my $str3 = next_argument();
600 my $str4 = next_argument();
Fred Drakeab032151999-05-13 18:36:54 +0000601 add_index_entry("$str1!$str2 $str3 $str4", @_[0]);
602 add_index_entry("$str2!$str3 $str4, $str1", @_[0]);
603 add_index_entry("$str3!$str4, $str1 $str2", @_[0]);
604 add_index_entry("$str4!$$str1 $str2 $str3", @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000605}
606
Fred Drakeab032151999-05-13 18:36:54 +0000607define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000608sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000609 my $str = next_argument();
610 my $entry = $str . get_indexsubitem();
Fred Drakeab032151999-05-13 18:36:54 +0000611 add_index_entry($entry, @_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000612}
Fred Drake6659c301998-03-03 22:02:19 +0000613
Fred Drakef5478632002-05-23 17:59:16 +0000614sub my_typed_index_helper($$){
615 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000616 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000617 add_index_entry("$str $word", $ahref);
618 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000619}
620
Fred Drakeab032151999-05-13 18:36:54 +0000621define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drakef5478632002-05-23 17:59:16 +0000622sub idx_cmd_stindex($){ my_typed_index_helper('statement', @_[0]); }
623sub idx_cmd_opindex($){ my_typed_index_helper('operator', @_[0]); }
624sub idx_cmd_exindex($){ my_typed_index_helper('exception', @_[0]); }
625sub idx_cmd_obindex($){ my_typed_index_helper('object', @_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000626
Fred Drakeab032151999-05-13 18:36:54 +0000627define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000628sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000629 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000630 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drakee15956b2000-04-03 04:51:13 +0000631 @_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000632}
633
634
Fred Drakef5478632002-05-23 17:59:16 +0000635sub make_mod_index_entry($$){
636 my($str, $define) = @_;
637 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000638 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000639 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
640 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000641 $str = gen_index_id($str, $define);
642 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000643 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000644
Fred Drakec9a44381998-03-17 06:29:13 +0000645 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000646 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000647 $str =~ /(<tt.*<\/tt>)/;
648 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000649 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000650 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000651 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000652}
653
Fred Drake557460c1999-03-02 16:05:35 +0000654
Fred Drakec9a44381998-03-17 06:29:13 +0000655$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000656$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000657
Fred Drakef5478632002-05-23 17:59:16 +0000658sub define_module($$){
659 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000660 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000661 if ($word ne "built-in" && $word ne "extension"
662 && $word ne "standard" && $word ne "") {
663 write_warnings("Bad module type '$word'"
664 . " for \\declaremodule (module $name)");
665 $word = "";
666 }
Fred Drake6659c301998-03-03 22:02:19 +0000667 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000668 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000669 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000670 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000671 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000672 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000673}
674
Fred Drakef5478632002-05-23 17:59:16 +0000675sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000676 local($word, $_) = @_;
677 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000678 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000679}
680
Fred Drake62e43691998-08-10 19:40:44 +0000681sub do_cmd_modindex{ return my_module_index_helper('', @_); }
682sub do_cmd_bimodindex{ return my_module_index_helper('built-in', @_); }
683sub do_cmd_exmodindex{ return my_module_index_helper('extension', @_); }
684sub do_cmd_stmodindex{ return my_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000685
Fred Drakef5478632002-05-23 17:59:16 +0000686sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000687 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000688 my $str = next_argument();
689 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000690 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000691 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
692 # just inline it all here
693 $str = gen_index_id($str, 'REF');
694 $index{$str} .= $ahref;
695 write_idxfile($ahref, $str);
696}
697
Fred Drake6659c301998-03-03 22:02:19 +0000698# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000699define_indexing_macro('refmodindex', 'refbimodindex',
700 'refexmodindex', 'refstmodindex');
Fred Drakef5478632002-05-23 17:59:16 +0000701sub idx_cmd_refmodindex($){ return ref_module_index_helper('', @_); }
702sub idx_cmd_refbimodindex($){ return ref_module_index_helper('built-in', @_); }
703sub idx_cmd_refexmodindex($){ return ref_module_index_helper('extension', @_);}
704sub idx_cmd_refstmodindex($){ return ref_module_index_helper('standard', @_); }
Fred Drake6659c301998-03-03 22:02:19 +0000705
Fred Drake62e43691998-08-10 19:40:44 +0000706sub do_cmd_nodename{ return do_cmd_label(@_); }
Fred Drake6659c301998-03-03 22:02:19 +0000707
Fred Drakef5478632002-05-23 17:59:16 +0000708sub init_myformat(){
Fred Drakeafc7ce12001-01-22 17:33:24 +0000709 $anchor_invisible_mark = '&nbsp;';
710 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000711 $anchor_mark = '';
712 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000713}
Fred Drake42b31a51998-03-27 05:16:10 +0000714init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000715
Fred Drakeab032151999-05-13 18:36:54 +0000716# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000717# instead of the dummy filler.
718#
Fred Drakef5478632002-05-23 17:59:16 +0000719sub make_str_index_entry($){
720 my $str = @_[0];
721 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000722 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000723 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000724}
725
Fred Drake77602f22001-07-06 22:43:02 +0000726
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000727%TokenToTargetMapping = (); # language:token -> link target
728%DefinedGrammars = (); # language -> full grammar text
729%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000730
731sub do_cmd_token{
732 local($_) = @_;
733 my $token = next_argument();
734 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
735 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
736 # recursive definition or display-only productionlist
737 return "$token";
738 }
739 if ($target eq '') {
740 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
741 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
742 print "Adding '$CURRENT_FILE' to back-patch list.\n";
743 }
744 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
745 }
746 return "<a href=\"$target\">$token</a>" . $_;
747}
748
Fred Drake16bb4192001-08-20 21:36:38 +0000749sub do_cmd_grammartoken{
750 return do_cmd_token(@_);
751}
752
Fred Drake77602f22001-07-06 22:43:02 +0000753sub do_env_productionlist{
754 local($_) = @_;
755 my $lang = next_optional_argument();
756 my $filename = "grammar-$lang.txt";
757 if ($lang eq '') {
758 $filename = 'grammar.txt';
759 }
760 local($CURRENT_GRAMMAR) = $lang;
761 $DefinedGrammars{$lang} .= $_;
762 return ("<dl><dd class=\"grammar\">\n"
763 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000764 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000765 . translate_commands(translate_environments($_))
766 . "</table>\n"
767 . "</div>\n"
768 . (($lang eq '*')
769 ? ''
770 : ("<a class=\"grammar-footer\"\n"
771 . " href=\"$filename\" type=\"text/plain\"\n"
772 . " >Download entire grammar as text.</a>\n"))
773 . "</dd></dl>");
774}
775
776sub do_cmd_production{
777 local($_) = @_;
778 my $token = next_argument();
779 my $defn = next_argument();
780 my $lang = $CURRENT_GRAMMAR;
781 local($CURRENT_TOKEN) = $token;
782 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000783 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000784 . " <td><code>$token</code></td>\n"
785 . " <td>&nbsp;::=&nbsp;</td>\n"
786 . " <td><code>"
787 . translate_commands($defn)
788 . "</code></td></tr>"
789 . $_);
790 }
791 my $target;
792 if ($lang eq '') {
793 $target = "$CURRENT_FILE\#tok-$token";
794 }
795 else {
796 $target = "$CURRENT_FILE\#tok-$lang-$token";
797 }
798 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000799 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000800 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
801 . " <td>&nbsp;::=&nbsp;</td>\n"
802 . " <td><code>"
803 . translate_commands($defn)
804 . "</code></td></tr>"
805 . $_);
806}
807
Fred Drake53815882002-03-15 23:21:37 +0000808sub do_cmd_productioncont{
809 local($_) = @_;
810 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000811 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000812 return ("<tr valign=\"baseline\">\n"
813 . " <td>&nbsp;</td>\n"
814 . " <td>&nbsp;</td>\n"
815 . " <td><code>"
816 . translate_commands($defn)
817 . "</code></td></tr>"
818 . $_);
819}
820
Fred Drakef5478632002-05-23 17:59:16 +0000821sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000822 my $lang;
823 my $filename;
824 local($_);
825 print "process_grammar_files()\n";
826 foreach $lang (keys %DefinedGrammars) {
827 $filename = "grammar-$lang.txt";
828 if ($lang eq '*') {
829 next;
830 }
831 if ($lang eq '') {
832 $filename = 'grammar.txt';
833 }
834 open(GRAMMAR, ">$filename") || die "\n$!\n";
835 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
836 close(GRAMMAR);
837 print "Wrote grammar file $filename\n";
838 }
839 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
840 foreach $filename (keys %BackpatchGrammarFiles) {
841 print "\nBack-patching grammar links in $filename\n";
842 my $buffer;
843 open(GRAMMAR, "<$filename") || die "\n$!\n";
844 # read all of the file into the buffer
845 sysread(GRAMMAR, $buffer, 1024*1024);
846 close(GRAMMAR);
847 while ($buffer =~ /$PATTERN/) {
848 my($lang, $token) = ($1, $2);
849 my $target = $TokenToTargetMapping{"$lang:$token"};
850 my $source = "<pyGrammarToken><$lang><$token>";
851 $buffer =~ s/$source/$target/g;
852 }
853 open(GRAMMAR, ">$filename") || die "\n$!\n";
854 print GRAMMAR $buffer;
855 close(GRAMMAR);
856 }
857}
858
Fred Drakef5478632002-05-23 17:59:16 +0000859sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000860 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000861 s/\\productioncont/ /g;
Fred Drake77602f22001-07-06 22:43:02 +0000862 s/\\production(<<\d+>>)(.+)\1/\n\2 ::= /g;
863 s/\\token(<<\d+>>)(.+)\1/\2/g;
864 s/\\e([^a-zA-Z])/\\\1/g;
865 s/<<\d+>>//g;
866 s/;SPMgt;/>/g;
867 s/;SPMlt;/</g;
868 s/;SPMquot;/\"/g;
869 return $_;
870}
871
872
Fred Drakee15956b2000-04-03 04:51:13 +0000873$REFCOUNTS_LOADED = 0;
874
Fred Drakef5478632002-05-23 17:59:16 +0000875sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000876 $REFCOUNTS_LOADED = 1;
877
Fred Drakee15956b2000-04-03 04:51:13 +0000878 my $myname, $mydir, $myext;
879 ($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
880 chop $mydir; # remove trailing '/'
881 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
882 chop $mydir; # remove trailing '/'
883 $mydir = getcwd() . "$dd$mydir"
884 unless $mydir =~ s|^/|/|;
885 local $_;
886 my $filename = "$mydir${dd}api${dd}refcounts.dat";
887 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
888 print "[loading API refcount data]";
889 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000890 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000891 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
892 #print "\n$func($param) --> $count";
893 $REFCOUNTS{"$func:$param"} = $count;
894 }
895 }
896}
897
Fred Drakef5478632002-05-23 17:59:16 +0000898sub get_refcount($$){
899 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000900 load_refcounts()
901 unless $REFCOUNTS_LOADED;
902 return $REFCOUNTS{"$func:$param"};
903}
904
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000905
906$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000907$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000908
Fred Drakef5478632002-05-23 17:59:16 +0000909sub cfuncline_helper($$$){
910 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000911 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000912 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000913 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000914 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake4837fa32002-06-18 18:30:28 +0000915 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/\1<var>\2<\/var>,/g;
916 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/\1<var>\2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000917 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
918 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
919 . "<td>$args)</td>"
920 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000921}
922sub do_cmd_cfuncline{
923 local($_) = @_;
924 my $type = next_argument();
925 my $name = next_argument();
926 my $args = next_argument();
927 my $siginfo = cfuncline_helper($type, $name, $args);
928 return "<dt>$siginfo\n<dd>" . $_;
929}
930sub do_env_cfuncdesc{
931 local($_) = @_;
932 my $type = next_argument();
933 my $name = next_argument();
934 my $args = next_argument();
935 my $siginfo = cfuncline_helper($type, $name, $args);
936 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000937 my $rcinfo = '';
938 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000939 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000940 }
941 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000942 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000943 }
Fred Drakec2578c52000-04-10 18:26:45 +0000944 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000945 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000946 }
Fred Drakee15956b2000-04-03 04:51:13 +0000947 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000948 $rcinfo = ( "\n<div class=\"refcount-info\">"
949 . "\n <span class=\"label\">Return value:</span>"
950 . "\n <span class=\"value\">$rcinfo.</span>"
951 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000952 }
Fred Drake34adb8a2002-04-15 20:48:40 +0000953 return "<dl><dt>$siginfo\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000954 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000955 . $_
956 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000957}
958
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000959sub do_cmd_cmemberline{
960 local($_) = @_;
961 my $container = next_argument();
962 my $type = next_argument();
963 my $name = next_argument();
964 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000965 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000966 $idx =~ s/ \(.*\)//;
967 return "<dt>$type <b>$idx</b>\n<dd>"
968 . $_;
969}
970sub do_env_cmemberdesc{
971 local($_) = @_;
972 my $container = next_argument();
973 my $type = next_argument();
974 my $name = next_argument();
975 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000976 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000977 $idx =~ s/ \(.*\)//;
978 return "<dl><dt>$type <b>$idx</b>\n<dd>"
979 . $_
980 . '</dl>';
981}
982
Fred Drakee15956b2000-04-03 04:51:13 +0000983sub do_env_csimplemacrodesc{
984 local($_) = @_;
985 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000986 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000987 return "<dl><dt><b>$idx</b>\n<dd>"
988 . $_
989 . '</dl>'
990}
991
Fred Drake6659c301998-03-03 22:02:19 +0000992sub do_env_ctypedesc{
993 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000994 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000995 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000996 $index_name = $type_name
997 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +0000998 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000999 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1000 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001001 . $_
1002 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001003}
1004
1005sub do_env_cvardesc{
1006 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001007 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001008 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001009 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001010 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001011 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001012 return "<dl><dt>$var_type <b>$idx</b>\n"
1013 . '<dd>'
1014 . $_
1015 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001016}
1017
Fred Drake3cdb89d2000-09-14 20:17:23 +00001018sub convert_args($){
1019 local($IN_DESC_HANDLER) = 1;
1020 local($_) = @_;
1021 return translate_commands($_);
1022}
1023
Fred Drakef6e90272002-06-18 18:24:16 +00001024sub funcline_helper($$$){
1025 my($first, $idxitem, $arglist) = @_;
1026 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001027 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1028 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1029 . "\n <td><var>$arglist</var>)</td></tr></table>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001030}
1031
Fred Drake6659c301998-03-03 22:02:19 +00001032sub do_env_funcdesc{
1033 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001034 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001035 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001036 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1037 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001038 . get_indexsubitem());
1039 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001040 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001041 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001042}
1043
1044sub do_env_funcdescni{
1045 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001046 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001047 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001048 my $prefix = "<tt class=\"function\">$function_name</tt>";
1049 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001050}
1051
1052sub do_cmd_funcline{
1053 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001054 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001055 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001056 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001057 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1058 $prefix =~ s/\(\)//;
1059
Fred Drakef6e90272002-06-18 18:24:16 +00001060 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001061}
1062
Fred Drake6b3fb781999-07-12 16:50:09 +00001063sub do_cmd_funclineni{
1064 local($_) = @_;
1065 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001066 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001067 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001068
Fred Drakef6e90272002-06-18 18:24:16 +00001069 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001070}
1071
Fred Drake6659c301998-03-03 22:02:19 +00001072# Change this flag to index the opcode entries. I don't think it's very
1073# useful to index them, since they're only presented to describe the dis
1074# module.
1075#
1076$INDEX_OPCODES = 0;
1077
1078sub do_env_opcodedesc{
1079 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001080 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001081 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001082 my $idx;
1083 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001084 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1085 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001086 $idx =~ s/ \(byte code instruction\)//;
1087 }
1088 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001089 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001090 }
1091 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001092 if ($arg_list) {
1093 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1094 }
Fred Drake62e43691998-08-10 19:40:44 +00001095 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001096}
1097
1098sub do_env_datadesc{
1099 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001100 my $dataname = next_argument();
1101 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001102 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001103 return "<dl><dt><b>$idx</b>\n<dd>"
1104 . $_
1105 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001106}
1107
1108sub do_env_datadescni{
1109 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001110 my $idx = next_argument();
1111 if (! $STRING_INDEX_TT) {
1112 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001113 }
Fred Drake62e43691998-08-10 19:40:44 +00001114 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001115}
1116
1117sub do_cmd_dataline{
1118 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001119 my $data_name = next_argument();
1120 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001121 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001122 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001123}
1124
Fred Drakeadb272c2000-04-10 17:47:14 +00001125sub do_cmd_datalineni{
1126 local($_) = @_;
1127 my $data_name = next_argument();
1128 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1129}
1130
Fred Drake42b31a51998-03-27 05:16:10 +00001131sub do_env_excdesc{
1132 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001133 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001134 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakef6e90272002-06-18 18:24:16 +00001135 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001136 . "\n<dd>"
1137 . $_
1138 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001139}
1140
Fred Drake62e43691998-08-10 19:40:44 +00001141sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001142
1143
Fred Drakef5478632002-05-23 17:59:16 +00001144sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001145 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001146 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001147 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001148 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001149 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001150 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001151 my $prefix = "$TLSTART$what$TLEND$idx";
1152 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001153}
1154
Fred Drake643d76d2000-09-09 06:07:37 +00001155sub do_env_classdesc{
1156 return handle_classlike_descriptor(@_[0], "class");
1157}
1158
Fred Drake06a01e82001-05-11 01:00:30 +00001159sub do_env_classdescstar{
1160 local($_) = @_;
1161 $THIS_CLASS = next_argument();
1162 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001163 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001164 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001165 my $prefix = "${TLSTART}class$TLEND$idx";
1166 # Can't use funcline_helper() since there is no args list.
1167 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001168}
1169
Fred Drake643d76d2000-09-09 06:07:37 +00001170sub do_env_excclassdesc{
1171 return handle_classlike_descriptor(@_[0], "exception");
1172}
1173
Fred Drake42b31a51998-03-27 05:16:10 +00001174
1175sub do_env_methoddesc{
1176 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001177 my $class_name = next_optional_argument();
1178 $class_name = $THIS_CLASS
1179 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001180 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001181 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001182 my $extra = '';
1183 if ($class_name) {
1184 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001185 }
Fred Drakef1927a62001-06-20 21:29:30 +00001186 my $idx = make_str_index_entry(
1187 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001188 $idx =~ s/ \(.*\)//;
1189 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001190 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001191}
1192
1193
Fred Drake7d45f6d1999-01-05 14:39:27 +00001194sub do_cmd_methodline{
1195 local($_) = @_;
1196 my $class_name = next_optional_argument();
1197 $class_name = $THIS_CLASS
1198 unless $class_name;
1199 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001200 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001201 my $extra = '';
1202 if ($class_name) {
1203 $extra = " ($class_name method)";
1204 }
Fred Drakef1927a62001-06-20 21:29:30 +00001205 my $idx = make_str_index_entry(
1206 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001207 $idx =~ s/ \(.*\)//;
1208 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001209 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001210}
1211
1212
Fred Draked64a40d1998-09-10 18:59:13 +00001213sub do_cmd_methodlineni{
1214 local($_) = @_;
1215 next_optional_argument();
1216 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001217 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001218 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001219}
1220
Fred Drake42b31a51998-03-27 05:16:10 +00001221sub do_env_methoddescni{
1222 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001223 next_optional_argument();
1224 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001225 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001226 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001227}
1228
1229
1230sub do_env_memberdesc{
1231 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001232 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001233 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001234 $class = $THIS_CLASS
1235 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001236 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001237 $extra = " ($class attribute)"
1238 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001239 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001240 $idx =~ s/ \(.*\)//;
1241 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001242 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001243}
1244
1245
Fred Drake5ccf3301998-04-17 20:04:09 +00001246sub do_cmd_memberline{
1247 local($_) = @_;
1248 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001249 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001250 $class = $THIS_CLASS
1251 unless $class;
1252 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001253 $extra = " ($class attribute)"
1254 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001255 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001256 $idx =~ s/ \(.*\)//;
1257 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001258 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001259}
1260
Fred Drakef269e592001-07-17 23:05:57 +00001261
Fred Drake42b31a51998-03-27 05:16:10 +00001262sub do_env_memberdescni{
1263 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001264 next_optional_argument();
1265 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001266 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001267 . $_
1268 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001269}
1270
1271
Fred Drake5ccf3301998-04-17 20:04:09 +00001272sub do_cmd_memberlineni{
1273 local($_) = @_;
1274 next_optional_argument();
1275 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001276 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001277}
1278
Fred Drakef269e592001-07-17 23:05:57 +00001279
1280@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001281
Fred Drakecb199762001-08-16 21:56:24 +00001282%FontConversions = ('cdata' => 'tt class="cdata"',
1283 'character' => 'tt class="character"',
1284 'class' => 'tt class="class"',
1285 'command' => 'code',
1286 'constant' => 'tt class="constant"',
1287 'exception' => 'tt class="exception"',
1288 'file' => 'tt class="file"',
1289 'filenq' => 'tt class="file"',
1290 'kbd' => 'kbd',
1291 'member' => 'tt class="member"',
1292 'programopt' => 'b',
1293 'textrm' => '',
1294 );
1295
Fred Drakef5478632002-05-23 17:59:16 +00001296sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001297 # do a little magic on a font name to get the right behavior in the first
1298 # column of the output table
1299 my $font = @_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001300 if (defined $FontConversions{$font}) {
1301 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001302 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001303 return $font;
1304}
1305
Fred Drakef5478632002-05-23 17:59:16 +00001306sub figure_column_alignment($){
Fred Drakee15956b2000-04-03 04:51:13 +00001307 my $a = @_[0];
1308 my $mark = substr($a, 0, 1);
1309 my $r = '';
1310 if ($mark eq 'c')
1311 { $r = ' align="center"'; }
1312 elsif ($mark eq 'r')
1313 { $r = ' align="right"'; }
1314 elsif ($mark eq 'l')
1315 { $r = ' align="left"'; }
1316 elsif ($mark eq 'p')
1317 { $r = ' align="left"'; }
1318 return $r;
1319}
1320
Fred Drakef5478632002-05-23 17:59:16 +00001321sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001322 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001323 my($s1, $s2, $s3, $s4, $a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001324 my $a1 = figure_column_alignment($s1);
1325 my $a2 = figure_column_alignment($s2);
1326 my $a3 = figure_column_alignment($s3);
1327 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001328 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001329 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1330 $col_aligns[1] = "<td$a2>";
1331 $col_aligns[2] = "<td$a3>";
1332 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001333 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001334 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001335 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001336}
1337
Fred Drakef5478632002-05-23 17:59:16 +00001338sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001339 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001340 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001341 if ($font) {
1342 $sfont = "<$font>";
1343 $efont = "</$font>";
1344 $efont =~ s/ .*>/>/;
1345 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001346 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001347}
1348
1349sub do_env_tableii{
1350 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001351 my $arg = next_argument();
1352 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001353 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001354 my $h1 = next_argument();
1355 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001356 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001357 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001358 my $a1 = $col_aligns[0];
1359 my $a2 = $col_aligns[1];
1360 s/\\lineii</\\lineii[$a1|$a2]</g;
1361 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001362 . "\n <thead>"
1363 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001364 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1365 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001366 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001367 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001368 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001369 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001370 . "\n </tbody>"
1371 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001372}
1373
Fred Drakeda72b932000-09-21 15:58:02 +00001374sub do_env_longtableii{
1375 return do_env_tableii(@_);
1376}
1377
Fred Drake6659c301998-03-03 22:02:19 +00001378sub do_cmd_lineii{
1379 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001380 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001381 my $c1 = next_argument();
1382 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001383 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001384 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001385 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001386 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001387 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001388 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001389 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001390 }
Fred Drakee15956b2000-04-03 04:51:13 +00001391 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1392 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001393 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001394}
1395
1396sub do_env_tableiii{
1397 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001398 my $arg = next_argument();
1399 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001400 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001401 my $h1 = next_argument();
1402 my $h2 = next_argument();
1403 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001404 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001405 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001406 my $a1 = $col_aligns[0];
1407 my $a2 = $col_aligns[1];
1408 my $a3 = $col_aligns[2];
1409 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1410 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001411 . "\n <thead>"
1412 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001413 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1414 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1415 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001416 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001417 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001418 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001419 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001420 . "\n </tbody>"
1421 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001422}
1423
Fred Drakeda72b932000-09-21 15:58:02 +00001424sub do_env_longtableiii{
1425 return do_env_tableiii(@_);
1426}
1427
Fred Drake6659c301998-03-03 22:02:19 +00001428sub do_cmd_lineiii{
1429 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001430 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001431 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001432 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001433 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001434 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001435 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001436 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001437 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001438 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 Drake58b2bfd1998-04-02 20:14: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"
Fred Drakee15956b2000-04-03 04:51:13 +00001444 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001445 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001446}
1447
Fred Drakea0f4c941998-07-24 22:16:04 +00001448sub do_env_tableiv{
1449 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001450 my $arg = next_argument();
1451 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001452 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001453 my $h1 = next_argument();
1454 my $h2 = next_argument();
1455 my $h3 = next_argument();
1456 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001457 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001458 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001459 my $a1 = $col_aligns[0];
1460 my $a2 = $col_aligns[1];
1461 my $a3 = $col_aligns[2];
1462 my $a4 = $col_aligns[3];
1463 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1464 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001465 . "\n <thead>"
1466 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001467 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1468 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1469 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1470 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001471 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001472 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001473 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001474 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001475 . "\n </tbody>"
1476 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001477}
1478
Fred Drakeda72b932000-09-21 15:58:02 +00001479sub do_env_longtableiv{
1480 return do_env_tableiv(@_);
1481}
1482
Fred Drakea0f4c941998-07-24 22:16:04 +00001483sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001484 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001485 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001486 my $c1 = next_argument();
1487 my $c2 = next_argument();
1488 my $c3 = next_argument();
1489 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001490 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001491 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001492 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001493 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001494 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001495 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001496 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001497 }
Fred Drakee15956b2000-04-03 04:51:13 +00001498 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001499 . " $c2align$c2</td>\n"
1500 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001501 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001502 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001503}
1504
Fred Drakef269e592001-07-17 23:05:57 +00001505sub do_env_tablev{
1506 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001507 my $arg = next_argument();
1508 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001509 my $font = fix_font(next_argument());
1510 my $h1 = next_argument();
1511 my $h2 = next_argument();
1512 my $h3 = next_argument();
1513 my $h4 = next_argument();
1514 my $h5 = next_argument();
1515 s/[\s\n]+//;
1516 $globals{'lineifont'} = $font;
1517 my $a1 = $col_aligns[0];
1518 my $a2 = $col_aligns[1];
1519 my $a3 = $col_aligns[2];
1520 my $a4 = $col_aligns[3];
1521 my $a5 = $col_aligns[4];
1522 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1523 return '<table border align="center" style="border-collapse: collapse">'
1524 . "\n <thead>"
1525 . "\n <tr class=\"tableheader\">"
1526 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1527 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1528 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1529 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1530 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1531 . "\n </tr>"
1532 . "\n </thead>"
1533 . "\n <tbody valign=\"baseline\">"
1534 . $_
1535 . "\n </tbody>"
1536 . "\n</table>";
1537}
1538
1539sub do_env_longtablev{
1540 return do_env_tablev(@_);
1541}
1542
1543sub do_cmd_linev{
1544 local($_) = @_;
1545 my $aligns = next_optional_argument();
1546 my $c1 = next_argument();
1547 my $c2 = next_argument();
1548 my $c3 = next_argument();
1549 my $c4 = next_argument();
1550 my $c5 = next_argument();
1551 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001552 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001553 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001554 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001555 my $padding = '';
1556 if ($c1align =~ /align="right"/ || $c1 eq '') {
1557 $padding = '&nbsp;';
1558 }
1559 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1560 . " $c2align$c2</td>\n"
1561 . " $c3align$c3</td>\n"
1562 . " $c4align$c4</td>\n"
1563 . " $c5align$c5</td>"
1564 . $_;
1565}
1566
Fred Drake3be20742000-08-31 06:22:54 +00001567
1568# These can be used to control the title page appearance;
1569# they need a little bit of documentation.
1570#
1571# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1572# $ICONSERVER directory, or include path information (other than "./"). The
1573# default image type will be assumed if an extension is not provided.
1574#
1575# If specified, the "title page" will contain two colums: one containing the
1576# title/author/etc., and the other containing the graphic. Use the other
1577# four variables listed here to control specific details of the layout; all
1578# are optional.
1579#
1580# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1581# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1582# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1583# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1584# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1585
Fred Drakef5478632002-05-23 17:59:16 +00001586sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001587 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001588 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001589 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001590 }
1591 else {
1592 write_warnings("\nThis document has no title.");
1593 }
Fred Drake6659c301998-03-03 22:02:19 +00001594 if ($t_author) {
1595 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001596 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001597 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001598 "<b><font size=\"+2\">$t_author"
1599 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001600 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001601 }
1602 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001603 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1604 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001605 }
Fred Drake3be20742000-08-31 06:22:54 +00001606 }
1607 else {
1608 write_warnings("\nThere is no author for this document.");
1609 }
Fred Drake6659c301998-03-03 22:02:19 +00001610 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001611 $the_title .= "\n<p>$t_institute</p>";
1612 }
Fred Draked07868a1998-05-14 21:00:28 +00001613 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001614 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1615 }
Fred Drake6659c301998-03-03 22:02:19 +00001616 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001617 $the_title .= "\n<p><i>$t_affil</i></p>";
1618 }
Fred Drake6659c301998-03-03 22:02:19 +00001619 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001620 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001621 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001622 $the_title .= ('<strong>Release '
1623 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001624 }
Fred Drakede77bc52000-12-14 18:36:12 +00001625 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001626 }
1627 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001628 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001629 }
1630 else {
1631 $the_title .= "\n<p>";
1632 }
Fred Drake6659c301998-03-03 22:02:19 +00001633 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001634 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001635 }
1636 return $the_title;
1637}
1638
Fred Drakef5478632002-05-23 17:59:16 +00001639sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001640 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001641 my $graphic = "<td class=\"titlegraphic\"";
1642 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1643 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1644 $graphic .= "><img";
1645 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1646 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1647 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1648 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001649 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001650 return $graphic;
1651}
1652
Fred Drakef5478632002-05-23 17:59:16 +00001653sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001654 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001655 my $the_title = "\n";
1656 if ($EXTERNAL_UP_LINK) {
1657 # This generates a <LINK> element in the wrong place (the
1658 # body), but I don't see any other way to get this generated
1659 # at all. Browsers like Mozilla, that support navigation
1660 # links, can make use of this.
1661 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1662 . ($EXTERNAL_UP_TITLE
1663 ? " title='$EXTERNAL_UP_TITLE'" : '')
1664 . ">\n");
1665 }
1666 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001667 if ($TITLE_PAGE_GRAPHIC) {
1668 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1669 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1670 . "<tr align=\"right\">\n<td>"
1671 . make_my_titlepage()
1672 . "</td>\n"
1673 . make_my_titlegraphic()
1674 . "</tr>\n</table>");
1675 }
1676 else {
1677 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1678 . make_my_titlegraphic()
1679 . "<td>"
1680 . make_my_titlepage()
1681 . "</td></tr>\n</table>");
1682 }
1683 }
1684 else {
1685 $the_title .= ("\n<center>"
1686 . make_my_titlepage()
1687 . "\n</center>");
1688 }
1689 $the_title .= "\n</div>";
1690 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001691 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001692 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001693}
1694
1695
Fred Drake885215c1998-05-20 21:32:09 +00001696#
Fred Drakea0f4c941998-07-24 22:16:04 +00001697# Module synopsis support
1698#
1699
1700require SynopsisTable;
1701
Fred Drakef7685d71998-07-25 03:31:46 +00001702sub get_chapter_id(){
1703 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001704 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1705 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001706 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001707}
1708
Fred Drake643d76d2000-09-09 06:07:37 +00001709# 'chapter' => 'SynopsisTable instance'
1710%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001711
1712sub get_synopsis_table($){
Fred Drakef5478632002-05-23 17:59:16 +00001713 my $chap = @_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001714 my $key;
1715 foreach $key (keys %ModuleSynopses) {
1716 if ($key eq $chap) {
1717 return $ModuleSynopses{$chap};
1718 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001719 }
Fred Drake643d76d2000-09-09 06:07:37 +00001720 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001721 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001722 return $st;
1723}
1724
Fred Drake62e43691998-08-10 19:40:44 +00001725sub do_cmd_moduleauthor{
1726 local($_) = @_;
1727 next_argument();
1728 next_argument();
1729 return $_;
1730}
1731
1732sub do_cmd_sectionauthor{
1733 local($_) = @_;
1734 next_argument();
1735 next_argument();
1736 return $_;
1737}
1738
Fred Drakea0f4c941998-07-24 22:16:04 +00001739sub do_cmd_declaremodule{
1740 local($_) = @_;
1741 my $key = next_optional_argument();
1742 my $type = next_argument();
1743 my $name = next_argument();
1744 my $st = get_synopsis_table(get_chapter_id());
1745 #
1746 $key = $name unless $key;
1747 $type = 'built-in' if $type eq 'builtin';
1748 $st->declare($name, $key, $type);
1749 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001750 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001751}
1752
1753sub do_cmd_modulesynopsis{
1754 local($_) = @_;
1755 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001756 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001757 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001758}
1759
1760sub do_cmd_localmoduletable{
1761 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001762 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001763 my $st = get_synopsis_table($chap);
1764 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001765 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001766}
1767
Fred Drakef5478632002-05-23 17:59:16 +00001768sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001769 my $key;
1770 my $st, $file;
1771 foreach $key (keys %ModuleSynopses) {
1772 $st = $ModuleSynopses{$key};
1773 $file = $st->get_file();
1774 if ($file) {
1775 process_localmoduletables_in_file($file);
1776 }
1777 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001778 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001779 }
1780 }
1781}
1782
Fred Drakef5478632002-05-23 17:59:16 +00001783sub process_localmoduletables_in_file($){
Fred Drake643d76d2000-09-09 06:07:37 +00001784 my $file = @_[0];
1785 open(MYFILE, "<$file");
1786 local($_);
1787 sysread(MYFILE, $_, 1024*1024);
1788 close(MYFILE);
1789 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001790 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001791 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001792 my $chap = $1;
1793 my $st = get_synopsis_table($chap);
1794 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001795 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001796 }
Fred Drake643d76d2000-09-09 06:07:37 +00001797 open(MYFILE,">$file");
1798 print MYFILE $_;
1799 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001800}
Fred Drakef5478632002-05-23 17:59:16 +00001801sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001802 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001803 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001804}
Fred Drakea0f4c941998-07-24 22:16:04 +00001805
1806
1807#
1808# "See also:" -- references placed at the end of a \section
1809#
1810
1811sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001812 return ("<div class=\"seealso\">\n "
1813 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1814 . @_[0]
1815 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001816}
1817
Fred Drake5ed35fd2001-11-30 18:09:54 +00001818sub do_env_seealsostar{
1819 return ("<div class=\"seealso-simple\">\n "
1820 . @_[0]
1821 . '</div>');
1822}
1823
Fred Drakea0f4c941998-07-24 22:16:04 +00001824sub do_cmd_seemodule{
1825 # Insert the right magic to jump to the module definition. This should
1826 # work most of the time, at least for repeat builds....
1827 local($_) = @_;
1828 my $key = next_optional_argument();
1829 my $module = next_argument();
1830 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001831 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001832 $key = $module
1833 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001834 if ($text =~ /\.$/) {
1835 $period = '';
1836 }
Fred Drakef1927a62001-06-20 21:29:30 +00001837 return ('<dl compact class="seemodule">'
1838 . "\n <dt>Module <b><tt class=\"module\">"
1839 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1840 . "\n <dd>$text$period\n </dl>"
1841 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001842}
1843
Fred Drakee0197bf2001-04-12 04:03:22 +00001844sub strip_html_markup($){
1845 my $str = @_[0];
1846 my $s = "$str";
1847 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1848 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1849 return $s;
1850}
1851
Fred Drakef5478632002-05-23 17:59:16 +00001852sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001853 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001854 my $rfcnum = next_argument();
1855 my $title = next_argument();
1856 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001857 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001858 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001859 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001860 return '<dl compact class="seerfc">'
1861 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001862 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001863 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001864 . "\n <dd>$text\n </dl>"
1865 . $_;
1866}
1867
Fred Drake643d76d2000-09-09 06:07:37 +00001868sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001869 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001870}
1871
1872sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001873 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drakeafc7ce12001-01-22 17:33:24 +00001874 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001875}
1876
Fred Drake48449982000-09-12 17:52:33 +00001877sub do_cmd_seetitle{
1878 local($_) = @_;
1879 my $url = next_optional_argument();
1880 my $title = next_argument();
1881 my $text = next_argument();
1882 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001883 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001884 return '<dl compact class="seetitle">'
1885 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001886 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001887 . "\n <dd>$text\n </dl>"
1888 . $_;
1889 }
1890 return '<dl compact class="seetitle">'
1891 . "\n <dt><em class=\"citetitle\""
1892 . "\n >$title</em>"
1893 . "\n <dd>$text\n </dl>"
1894 . $_;
1895}
1896
Fred Drakeef4d1112000-05-09 16:17:51 +00001897sub do_cmd_seeurl{
1898 local($_) = @_;
1899 my $url = next_argument();
1900 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001901 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001902 return '<dl compact class="seeurl">'
1903 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001904 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001905 . "\n <dd>$text\n </dl>"
1906 . $_;
1907}
1908
Fred Drakea0f4c941998-07-24 22:16:04 +00001909sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001910 local($_) = @_;
1911 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001912 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001913}
1914
1915
1916#
Fred Drake885215c1998-05-20 21:32:09 +00001917# Definition list support.
1918#
1919
1920sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001921 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001922}
1923
1924sub do_cmd_term{
1925 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001926 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001927 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001928 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001929 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001930}
1931
1932
Fred Drake38178fd2000-09-22 17:05:04 +00001933# I don't recall exactly why this was needed, but it was very much needed.
1934# We'll see if anything breaks when I move the "code" line out -- some
1935# things broke with it in.
1936
1937#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001938process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001939declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001940funcline # {} # {}
1941funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001942memberline # [] # {}
1943methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001944methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001945modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001946platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001947samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001948setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001949withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001950_RAW_ARG_DEFERRED_CMDS_
1951
1952
Fred Drake8a5e6792002-04-15 18:41:31 +00001953$alltt_start = '<div class="verbatim"><pre>';
1954$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001955
Fred Drakef5478632002-05-23 17:59:16 +00001956sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001957 local ($_) = @_;
1958 local($closures,$reopens,@open_block_tags);
1959
1960 # get the tag-strings for all open tags
1961 local(@keep_open_tags) = @$open_tags_R;
1962 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1963
1964 # get the tags for text-level tags only
1965 $open_tags_R = [ @keep_open_tags ];
1966 local($local_closures, $local_reopens);
1967 ($local_closures, $local_reopens,@open_block_tags)
1968 = &preserve_open_block_tags
1969 if (@$open_tags_R);
1970
1971 $open_tags_R = [ @open_block_tags ];
1972
1973 do {
1974 local($open_tags_R) = [ @open_block_tags ];
1975 local(@save_open_tags) = ();
1976
1977 local($cnt) = ++$global{'max_id'};
1978 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1979 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1980
1981 $_ = &translate_environments($_);
1982 $_ = &translate_commands($_) if (/\\/);
1983
1984 # preserve space-runs, using &nbsp;
1985 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1986 s/(<BR>) /$1;SPMnbsp;/g;
1987
1988 $_ = join('', $closures, $alltt_start, $local_reopens
1989 , $_
1990 , &balance_tags() #, $local_closures
1991 , $alltt_end, $reopens);
1992 undef $open_tags_R; undef @save_open_tags;
1993 };
1994 $open_tags_R = [ @keep_open_tags ];
1995 $_;
1996}
1997
Fred Drake6fc22f62002-06-17 15:01:05 +00001998# List of all filenames produced ny do_cmd_verbatiminput()
1999%VerbatimFiles = ();
2000@VerbatimOutputs = ();
2001
2002sub get_verbatim_output_name($){
2003 my $file = @_[0];
2004 #
2005 # Re-write the source filename to always use a .txt extension
2006 # so that Web servers will present it as text/plain. This is
2007 # needed since there is no other even moderately reliable way
2008 # to get the right Content-Type header on text files for
2009 # servers which we can't configure (like python.org mirrors).
2010 #
2011 if (defined $VerbatimFiles{$file}) {
2012 # We've seen this one before; re-use the same output file.
2013 return $VerbatimFiles{$file};
2014 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002015 my $srcname, $srcdir, $srcext;
2016 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
2017 $filename = "$srcname.txt";
2018 #
2019 # We need to determine if our default filename is already
2020 # being used, and find a new one it it is. If the name is in
2021 # used, this algorithm will first attempt to include the
2022 # source extension as part of the name, and if that is also in
2023 # use (if the same file is included multiple times, or if
2024 # another source file has that as the base name), a counter is
2025 # used instead.
2026 #
2027 my $found = 1;
2028 FIND:
2029 while ($found) {
2030 foreach $fn (@VerbatimOutputs) {
2031 if ($fn eq $filename) {
2032 if ($found == 1) {
2033 $srcext =~ s/^[.]//; # Remove '.' from extension
2034 $filename = "$srcname-$srcext.txt";
2035 }
2036 else {
2037 $filename = "$srcname-$found.txt";
2038 }
2039 ++$found;
2040 next FIND;
2041 }
2042 }
2043 $found = 0;
2044 }
2045 push @VerbatimOutputs, $filename;
2046 $VerbatimFiles{$file} = $filename;
2047 return $filename;
2048}
2049
Fred Drake57e52ef2001-06-15 21:31:57 +00002050sub do_cmd_verbatiminput{
2051 local($_) = @_;
2052 my $fname = next_argument();
2053 my $file;
2054 my $found = 0;
2055 my $texpath;
2056 # Search TEXINPUTS for the input file, the way we're supposed to:
2057 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2058 $file = "$texpath$dd$fname";
2059 last if ($found = (-f $file));
2060 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002061 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002062 my $text;
2063 if ($found) {
2064 open(MYFILE, "<$file") || die "\n$!\n";
2065 read(MYFILE, $text, 1024*1024);
2066 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002067 $filename = get_verbatim_output_name($file);
2068 # Now that we have a filename, write it out.
2069 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002070 print MYFILE $text;
2071 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002072 #
2073 # These rewrites convert the raw text to something that will
2074 # be properly visible as HTML and also will pass through the
2075 # vagaries of conversion through LaTeX2HTML. The order in
2076 # which the specific rewrites are performed is significant.
2077 #
2078 $text =~ s/\&/\&amp;/g;
2079 # These need to happen before the normal < and > re-writes,
2080 # since we need to avoid LaTeX2HTML's attempt to perform
2081 # ligature processing without regard to context (since it
2082 # doesn't have font information).
2083 $text =~ s/--/-&\#45;/g;
2084 $text =~ s/<</\&lt;\&\#60;/g;
2085 $text =~ s/>>/\&gt;\&\#62;/g;
2086 # Just normal re-writes...
2087 $text =~ s/</\&lt;/g;
2088 $text =~ s/>/\&gt;/g;
2089 # These last isn't needed for the HTML, but is needed to get
2090 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2091 # of &sol; since many browsers don't support that.
2092 $text =~ s/\\/\&\#92;/g;
2093 }
2094 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002095 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2096 }
2097 my $note = 'Download as text.';
2098 if ($file ne $filename) {
2099 $note = ('Download as text (original file name: <span class="file">'
2100 . $fname
2101 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002102 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002103 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002104 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002105 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002106 . "<a href=\"$filename\" type=\"text/plain\""
2107 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002108 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002109 . $_);
2110}
Fred Drake86333602001-04-10 17:13:39 +00002111
Fred Drake6659c301998-03-03 22:02:19 +000021121; # This must be the last line