blob: 3fc745477f09be91c43ba14a0761258ec88c4182 [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
727%TokenToTargetMapping = ();
728%DefinedGrammars = ();
729%BackpatchGrammarFiles = ();
730
731sub do_cmd_token{
732 local($_) = @_;
733 my $token = next_argument();
734 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
735 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
736 # recursive definition or display-only productionlist
737 return "$token";
738 }
739 if ($target eq '') {
740 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
741 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
742 print "Adding '$CURRENT_FILE' to back-patch list.\n";
743 }
744 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
745 }
746 return "<a href=\"$target\">$token</a>" . $_;
747}
748
Fred Drake16bb4192001-08-20 21:36:38 +0000749sub do_cmd_grammartoken{
750 return do_cmd_token(@_);
751}
752
Fred Drake77602f22001-07-06 22:43:02 +0000753sub do_env_productionlist{
754 local($_) = @_;
755 my $lang = next_optional_argument();
756 my $filename = "grammar-$lang.txt";
757 if ($lang eq '') {
758 $filename = 'grammar.txt';
759 }
760 local($CURRENT_GRAMMAR) = $lang;
761 $DefinedGrammars{$lang} .= $_;
762 return ("<dl><dd class=\"grammar\">\n"
763 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000764 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000765 . translate_commands(translate_environments($_))
766 . "</table>\n"
767 . "</div>\n"
768 . (($lang eq '*')
769 ? ''
770 : ("<a class=\"grammar-footer\"\n"
771 . " href=\"$filename\" type=\"text/plain\"\n"
772 . " >Download entire grammar as text.</a>\n"))
773 . "</dd></dl>");
774}
775
776sub do_cmd_production{
777 local($_) = @_;
778 my $token = next_argument();
779 my $defn = next_argument();
780 my $lang = $CURRENT_GRAMMAR;
781 local($CURRENT_TOKEN) = $token;
782 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000783 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000784 . " <td><code>$token</code></td>\n"
785 . " <td>&nbsp;::=&nbsp;</td>\n"
786 . " <td><code>"
787 . translate_commands($defn)
788 . "</code></td></tr>"
789 . $_);
790 }
791 my $target;
792 if ($lang eq '') {
793 $target = "$CURRENT_FILE\#tok-$token";
794 }
795 else {
796 $target = "$CURRENT_FILE\#tok-$lang-$token";
797 }
798 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000799 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000800 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
801 . " <td>&nbsp;::=&nbsp;</td>\n"
802 . " <td><code>"
803 . translate_commands($defn)
804 . "</code></td></tr>"
805 . $_);
806}
807
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 Drake34adb8a2002-04-15 20:48:40 +0000917 return "$type <b>$idx</b>(<var>$args</var>)";
918}
919sub do_cmd_cfuncline{
920 local($_) = @_;
921 my $type = next_argument();
922 my $name = next_argument();
923 my $args = next_argument();
924 my $siginfo = cfuncline_helper($type, $name, $args);
925 return "<dt>$siginfo\n<dd>" . $_;
926}
927sub do_env_cfuncdesc{
928 local($_) = @_;
929 my $type = next_argument();
930 my $name = next_argument();
931 my $args = next_argument();
932 my $siginfo = cfuncline_helper($type, $name, $args);
933 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000934 my $rcinfo = '';
935 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000936 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000937 }
938 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000939 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000940 }
Fred Drakec2578c52000-04-10 18:26:45 +0000941 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000942 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000943 }
Fred Drakee15956b2000-04-03 04:51:13 +0000944 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000945 $rcinfo = ( "\n<div class=\"refcount-info\">"
946 . "\n <span class=\"label\">Return value:</span>"
947 . "\n <span class=\"value\">$rcinfo.</span>"
948 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000949 }
Fred Drake34adb8a2002-04-15 20:48:40 +0000950 return "<dl><dt>$siginfo\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000951 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000952 . $_
953 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000954}
955
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000956sub do_cmd_cmemberline{
957 local($_) = @_;
958 my $container = next_argument();
959 my $type = next_argument();
960 my $name = next_argument();
961 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000962 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000963 $idx =~ s/ \(.*\)//;
964 return "<dt>$type <b>$idx</b>\n<dd>"
965 . $_;
966}
967sub do_env_cmemberdesc{
968 local($_) = @_;
969 my $container = next_argument();
970 my $type = next_argument();
971 my $name = next_argument();
972 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000973 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000974 $idx =~ s/ \(.*\)//;
975 return "<dl><dt>$type <b>$idx</b>\n<dd>"
976 . $_
977 . '</dl>';
978}
979
Fred Drakee15956b2000-04-03 04:51:13 +0000980sub do_env_csimplemacrodesc{
981 local($_) = @_;
982 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000983 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000984 return "<dl><dt><b>$idx</b>\n<dd>"
985 . $_
986 . '</dl>'
987}
988
Fred Drake6659c301998-03-03 22:02:19 +0000989sub do_env_ctypedesc{
990 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000991 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000992 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +0000993 $index_name = $type_name
994 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +0000995 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +0000996 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
997 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +0000998 . $_
999 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001000}
1001
1002sub do_env_cvardesc{
1003 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001004 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001005 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001006 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001007 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001008 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001009 return "<dl><dt>$var_type <b>$idx</b>\n"
1010 . '<dd>'
1011 . $_
1012 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001013}
1014
Fred Drake3cdb89d2000-09-14 20:17:23 +00001015sub convert_args($){
1016 local($IN_DESC_HANDLER) = 1;
1017 local($_) = @_;
1018 return translate_commands($_);
1019}
1020
Fred Drakef6e90272002-06-18 18:24:16 +00001021sub funcline_helper($$$){
1022 my($first, $idxitem, $arglist) = @_;
1023 return (($first ? '<dl>' : '')
1024 . "<dt><b>$idxitem</b>(<var>$arglist</var>)\n<dd>");
1025}
1026
Fred Drake6659c301998-03-03 22:02:19 +00001027sub do_env_funcdesc{
1028 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001029 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001030 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001031 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1032 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001033 . get_indexsubitem());
1034 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001035 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001036 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001037}
1038
1039sub do_env_funcdescni{
1040 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001041 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001042 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001043 my $prefix = "<tt class=\"function\">$function_name</tt>";
1044 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001045}
1046
1047sub do_cmd_funcline{
1048 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001049 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001050 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001051 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001052 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1053 $prefix =~ s/\(\)//;
1054
Fred Drakef6e90272002-06-18 18:24:16 +00001055 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001056}
1057
Fred Drake6b3fb781999-07-12 16:50:09 +00001058sub do_cmd_funclineni{
1059 local($_) = @_;
1060 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001061 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001062 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001063
Fred Drakef6e90272002-06-18 18:24:16 +00001064 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001065}
1066
Fred Drake6659c301998-03-03 22:02:19 +00001067# Change this flag to index the opcode entries. I don't think it's very
1068# useful to index them, since they're only presented to describe the dis
1069# module.
1070#
1071$INDEX_OPCODES = 0;
1072
1073sub do_env_opcodedesc{
1074 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001075 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001076 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001077 my $idx;
1078 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001079 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1080 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001081 $idx =~ s/ \(byte code instruction\)//;
1082 }
1083 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001084 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001085 }
1086 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001087 if ($arg_list) {
1088 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1089 }
Fred Drake62e43691998-08-10 19:40:44 +00001090 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001091}
1092
1093sub do_env_datadesc{
1094 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001095 my $dataname = next_argument();
1096 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001097 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001098 return "<dl><dt><b>$idx</b>\n<dd>"
1099 . $_
1100 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001101}
1102
1103sub do_env_datadescni{
1104 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001105 my $idx = next_argument();
1106 if (! $STRING_INDEX_TT) {
1107 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001108 }
Fred Drake62e43691998-08-10 19:40:44 +00001109 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001110}
1111
1112sub do_cmd_dataline{
1113 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001114 my $data_name = next_argument();
1115 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001116 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001117 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001118}
1119
Fred Drakeadb272c2000-04-10 17:47:14 +00001120sub do_cmd_datalineni{
1121 local($_) = @_;
1122 my $data_name = next_argument();
1123 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1124}
1125
Fred Drake42b31a51998-03-27 05:16:10 +00001126sub do_env_excdesc{
1127 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001128 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001129 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakef6e90272002-06-18 18:24:16 +00001130 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001131 . "\n<dd>"
1132 . $_
1133 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001134}
1135
Fred Drake62e43691998-08-10 19:40:44 +00001136sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001137
1138
Fred Drakef5478632002-05-23 17:59:16 +00001139sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001140 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001141 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001142 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001143 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001144 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001145 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001146 my $prefix = "$TLSTART$what$TLEND$idx";
1147 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001148}
1149
Fred Drake643d76d2000-09-09 06:07:37 +00001150sub do_env_classdesc{
1151 return handle_classlike_descriptor(@_[0], "class");
1152}
1153
Fred Drake06a01e82001-05-11 01:00:30 +00001154sub do_env_classdescstar{
1155 local($_) = @_;
1156 $THIS_CLASS = next_argument();
1157 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001158 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001159 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001160 my $prefix = "${TLSTART}class$TLEND$idx";
1161 # Can't use funcline_helper() since there is no args list.
1162 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001163}
1164
Fred Drake643d76d2000-09-09 06:07:37 +00001165sub do_env_excclassdesc{
1166 return handle_classlike_descriptor(@_[0], "exception");
1167}
1168
Fred Drake42b31a51998-03-27 05:16:10 +00001169
1170sub do_env_methoddesc{
1171 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001172 my $class_name = next_optional_argument();
1173 $class_name = $THIS_CLASS
1174 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001175 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001176 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001177 my $extra = '';
1178 if ($class_name) {
1179 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001180 }
Fred Drakef1927a62001-06-20 21:29:30 +00001181 my $idx = make_str_index_entry(
1182 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001183 $idx =~ s/ \(.*\)//;
1184 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001185 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001186}
1187
1188
Fred Drake7d45f6d1999-01-05 14:39:27 +00001189sub do_cmd_methodline{
1190 local($_) = @_;
1191 my $class_name = next_optional_argument();
1192 $class_name = $THIS_CLASS
1193 unless $class_name;
1194 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001195 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001196 my $extra = '';
1197 if ($class_name) {
1198 $extra = " ($class_name method)";
1199 }
Fred Drakef1927a62001-06-20 21:29:30 +00001200 my $idx = make_str_index_entry(
1201 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001202 $idx =~ s/ \(.*\)//;
1203 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001204 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001205}
1206
1207
Fred Draked64a40d1998-09-10 18:59:13 +00001208sub do_cmd_methodlineni{
1209 local($_) = @_;
1210 next_optional_argument();
1211 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001212 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001213 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001214}
1215
Fred Drake42b31a51998-03-27 05:16:10 +00001216sub do_env_methoddescni{
1217 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001218 next_optional_argument();
1219 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001220 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001221 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001222}
1223
1224
1225sub do_env_memberdesc{
1226 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001227 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001228 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001229 $class = $THIS_CLASS
1230 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001231 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001232 $extra = " ($class attribute)"
1233 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001234 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001235 $idx =~ s/ \(.*\)//;
1236 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001237 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001238}
1239
1240
Fred Drake5ccf3301998-04-17 20:04:09 +00001241sub do_cmd_memberline{
1242 local($_) = @_;
1243 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001244 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001245 $class = $THIS_CLASS
1246 unless $class;
1247 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001248 $extra = " ($class attribute)"
1249 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001250 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001251 $idx =~ s/ \(.*\)//;
1252 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001253 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001254}
1255
Fred Drakef269e592001-07-17 23:05:57 +00001256
Fred Drake42b31a51998-03-27 05:16:10 +00001257sub do_env_memberdescni{
1258 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001259 next_optional_argument();
1260 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001261 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001262 . $_
1263 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001264}
1265
1266
Fred Drake5ccf3301998-04-17 20:04:09 +00001267sub do_cmd_memberlineni{
1268 local($_) = @_;
1269 next_optional_argument();
1270 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001271 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001272}
1273
Fred Drakef269e592001-07-17 23:05:57 +00001274
1275@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001276
Fred Drakecb199762001-08-16 21:56:24 +00001277%FontConversions = ('cdata' => 'tt class="cdata"',
1278 'character' => 'tt class="character"',
1279 'class' => 'tt class="class"',
1280 'command' => 'code',
1281 'constant' => 'tt class="constant"',
1282 'exception' => 'tt class="exception"',
1283 'file' => 'tt class="file"',
1284 'filenq' => 'tt class="file"',
1285 'kbd' => 'kbd',
1286 'member' => 'tt class="member"',
1287 'programopt' => 'b',
1288 'textrm' => '',
1289 );
1290
Fred Drakef5478632002-05-23 17:59:16 +00001291sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001292 # do a little magic on a font name to get the right behavior in the first
1293 # column of the output table
1294 my $font = @_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001295 if (defined $FontConversions{$font}) {
1296 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001297 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001298 return $font;
1299}
1300
Fred Drakef5478632002-05-23 17:59:16 +00001301sub figure_column_alignment($){
Fred Drakee15956b2000-04-03 04:51:13 +00001302 my $a = @_[0];
1303 my $mark = substr($a, 0, 1);
1304 my $r = '';
1305 if ($mark eq 'c')
1306 { $r = ' align="center"'; }
1307 elsif ($mark eq 'r')
1308 { $r = ' align="right"'; }
1309 elsif ($mark eq 'l')
1310 { $r = ' align="left"'; }
1311 elsif ($mark eq 'p')
1312 { $r = ' align="left"'; }
1313 return $r;
1314}
1315
Fred Drakef5478632002-05-23 17:59:16 +00001316sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001317 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001318 my($s1, $s2, $s3, $s4, $a5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001319 my $a1 = figure_column_alignment($s1);
1320 my $a2 = figure_column_alignment($s2);
1321 my $a3 = figure_column_alignment($s3);
1322 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001323 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001324 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1325 $col_aligns[1] = "<td$a2>";
1326 $col_aligns[2] = "<td$a3>";
1327 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001328 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001329 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001330 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001331}
1332
Fred Drakef5478632002-05-23 17:59:16 +00001333sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001334 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001335 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001336 if ($font) {
1337 $sfont = "<$font>";
1338 $efont = "</$font>";
1339 $efont =~ s/ .*>/>/;
1340 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001341 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001342}
1343
1344sub do_env_tableii{
1345 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001346 my $arg = next_argument();
1347 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001348 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001349 my $h1 = next_argument();
1350 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001351 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001352 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001353 my $a1 = $col_aligns[0];
1354 my $a2 = $col_aligns[1];
1355 s/\\lineii</\\lineii[$a1|$a2]</g;
1356 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001357 . "\n <thead>"
1358 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001359 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1360 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001361 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001362 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001363 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001364 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001365 . "\n </tbody>"
1366 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001367}
1368
Fred Drakeda72b932000-09-21 15:58:02 +00001369sub do_env_longtableii{
1370 return do_env_tableii(@_);
1371}
1372
Fred Drake6659c301998-03-03 22:02:19 +00001373sub do_cmd_lineii{
1374 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001375 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001376 my $c1 = next_argument();
1377 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001378 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001379 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001380 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001381 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001382 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001383 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001384 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001385 }
Fred Drakee15956b2000-04-03 04:51:13 +00001386 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1387 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001388 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001389}
1390
1391sub do_env_tableiii{
1392 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001393 my $arg = next_argument();
1394 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001395 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001396 my $h1 = next_argument();
1397 my $h2 = next_argument();
1398 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001399 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001400 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001401 my $a1 = $col_aligns[0];
1402 my $a2 = $col_aligns[1];
1403 my $a3 = $col_aligns[2];
1404 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1405 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001406 . "\n <thead>"
1407 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001408 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1409 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1410 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001411 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001412 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001413 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001414 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001415 . "\n </tbody>"
1416 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001417}
1418
Fred Drakeda72b932000-09-21 15:58:02 +00001419sub do_env_longtableiii{
1420 return do_env_tableiii(@_);
1421}
1422
Fred Drake6659c301998-03-03 22:02:19 +00001423sub do_cmd_lineiii{
1424 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001425 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001426 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001427 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001428 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001429 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001430 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001431 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001432 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001433 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001434 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001435 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001436 }
Fred Drakee15956b2000-04-03 04:51:13 +00001437 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001438 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001439 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001440 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001441}
1442
Fred Drakea0f4c941998-07-24 22:16:04 +00001443sub do_env_tableiv{
1444 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001445 my $arg = next_argument();
1446 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001447 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001448 my $h1 = next_argument();
1449 my $h2 = next_argument();
1450 my $h3 = next_argument();
1451 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001452 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001453 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001454 my $a1 = $col_aligns[0];
1455 my $a2 = $col_aligns[1];
1456 my $a3 = $col_aligns[2];
1457 my $a4 = $col_aligns[3];
1458 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1459 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001460 . "\n <thead>"
1461 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001462 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1463 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1464 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1465 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001466 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001467 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001468 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001469 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001470 . "\n </tbody>"
1471 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001472}
1473
Fred Drakeda72b932000-09-21 15:58:02 +00001474sub do_env_longtableiv{
1475 return do_env_tableiv(@_);
1476}
1477
Fred Drakea0f4c941998-07-24 22:16:04 +00001478sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001479 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001480 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001481 my $c1 = next_argument();
1482 my $c2 = next_argument();
1483 my $c3 = next_argument();
1484 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001485 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001486 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001487 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001488 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001489 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001490 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001491 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001492 }
Fred Drakee15956b2000-04-03 04:51:13 +00001493 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001494 . " $c2align$c2</td>\n"
1495 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001496 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001497 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001498}
1499
Fred Drakef269e592001-07-17 23:05:57 +00001500sub do_env_tablev{
1501 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001502 my $arg = next_argument();
1503 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001504 my $font = fix_font(next_argument());
1505 my $h1 = next_argument();
1506 my $h2 = next_argument();
1507 my $h3 = next_argument();
1508 my $h4 = next_argument();
1509 my $h5 = next_argument();
1510 s/[\s\n]+//;
1511 $globals{'lineifont'} = $font;
1512 my $a1 = $col_aligns[0];
1513 my $a2 = $col_aligns[1];
1514 my $a3 = $col_aligns[2];
1515 my $a4 = $col_aligns[3];
1516 my $a5 = $col_aligns[4];
1517 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1518 return '<table border align="center" style="border-collapse: collapse">'
1519 . "\n <thead>"
1520 . "\n <tr class=\"tableheader\">"
1521 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1522 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1523 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1524 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1525 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1526 . "\n </tr>"
1527 . "\n </thead>"
1528 . "\n <tbody valign=\"baseline\">"
1529 . $_
1530 . "\n </tbody>"
1531 . "\n</table>";
1532}
1533
1534sub do_env_longtablev{
1535 return do_env_tablev(@_);
1536}
1537
1538sub do_cmd_linev{
1539 local($_) = @_;
1540 my $aligns = next_optional_argument();
1541 my $c1 = next_argument();
1542 my $c2 = next_argument();
1543 my $c3 = next_argument();
1544 my $c4 = next_argument();
1545 my $c5 = next_argument();
1546 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001547 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001548 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001549 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001550 my $padding = '';
1551 if ($c1align =~ /align="right"/ || $c1 eq '') {
1552 $padding = '&nbsp;';
1553 }
1554 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1555 . " $c2align$c2</td>\n"
1556 . " $c3align$c3</td>\n"
1557 . " $c4align$c4</td>\n"
1558 . " $c5align$c5</td>"
1559 . $_;
1560}
1561
Fred Drake3be20742000-08-31 06:22:54 +00001562
1563# These can be used to control the title page appearance;
1564# they need a little bit of documentation.
1565#
1566# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1567# $ICONSERVER directory, or include path information (other than "./"). The
1568# default image type will be assumed if an extension is not provided.
1569#
1570# If specified, the "title page" will contain two colums: one containing the
1571# title/author/etc., and the other containing the graphic. Use the other
1572# four variables listed here to control specific details of the layout; all
1573# are optional.
1574#
1575# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1576# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1577# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1578# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1579# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1580
Fred Drakef5478632002-05-23 17:59:16 +00001581sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001582 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001583 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001584 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001585 }
1586 else {
1587 write_warnings("\nThis document has no title.");
1588 }
Fred Drake6659c301998-03-03 22:02:19 +00001589 if ($t_author) {
1590 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001591 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001592 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001593 "<b><font size=\"+2\">$t_author"
1594 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001595 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001596 }
1597 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001598 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1599 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001600 }
Fred Drake3be20742000-08-31 06:22:54 +00001601 }
1602 else {
1603 write_warnings("\nThere is no author for this document.");
1604 }
Fred Drake6659c301998-03-03 22:02:19 +00001605 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001606 $the_title .= "\n<p>$t_institute</p>";
1607 }
Fred Draked07868a1998-05-14 21:00:28 +00001608 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001609 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1610 }
Fred Drake6659c301998-03-03 22:02:19 +00001611 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001612 $the_title .= "\n<p><i>$t_affil</i></p>";
1613 }
Fred Drake6659c301998-03-03 22:02:19 +00001614 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001615 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001616 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001617 $the_title .= ('<strong>Release '
1618 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001619 }
Fred Drakede77bc52000-12-14 18:36:12 +00001620 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001621 }
1622 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001623 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001624 }
1625 else {
1626 $the_title .= "\n<p>";
1627 }
Fred Drake6659c301998-03-03 22:02:19 +00001628 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001629 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001630 }
1631 return $the_title;
1632}
1633
Fred Drakef5478632002-05-23 17:59:16 +00001634sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001635 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001636 my $graphic = "<td class=\"titlegraphic\"";
1637 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1638 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1639 $graphic .= "><img";
1640 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1641 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1642 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1643 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001644 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001645 return $graphic;
1646}
1647
Fred Drakef5478632002-05-23 17:59:16 +00001648sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001649 local($_) = @_;
1650 my $the_title = "\n<div class=\"titlepage\">";
1651 if ($TITLE_PAGE_GRAPHIC) {
1652 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1653 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1654 . "<tr align=\"right\">\n<td>"
1655 . make_my_titlepage()
1656 . "</td>\n"
1657 . make_my_titlegraphic()
1658 . "</tr>\n</table>");
1659 }
1660 else {
1661 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1662 . make_my_titlegraphic()
1663 . "<td>"
1664 . make_my_titlepage()
1665 . "</td></tr>\n</table>");
1666 }
1667 }
1668 else {
1669 $the_title .= ("\n<center>"
1670 . make_my_titlepage()
1671 . "\n</center>");
1672 }
1673 $the_title .= "\n</div>";
1674 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001675 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001676 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001677}
1678
1679
Fred Drake885215c1998-05-20 21:32:09 +00001680#
Fred Drakea0f4c941998-07-24 22:16:04 +00001681# Module synopsis support
1682#
1683
1684require SynopsisTable;
1685
Fred Drakef7685d71998-07-25 03:31:46 +00001686sub get_chapter_id(){
1687 my $id = do_cmd_thechapter('');
Fred Drake45f26011998-08-04 22:07:18 +00001688 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/\1/;
1689 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001690 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001691}
1692
Fred Drake643d76d2000-09-09 06:07:37 +00001693# 'chapter' => 'SynopsisTable instance'
1694%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001695
1696sub get_synopsis_table($){
Fred Drakef5478632002-05-23 17:59:16 +00001697 my $chap = @_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001698 my $key;
1699 foreach $key (keys %ModuleSynopses) {
1700 if ($key eq $chap) {
1701 return $ModuleSynopses{$chap};
1702 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001703 }
Fred Drake643d76d2000-09-09 06:07:37 +00001704 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001705 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001706 return $st;
1707}
1708
Fred Drake62e43691998-08-10 19:40:44 +00001709sub do_cmd_moduleauthor{
1710 local($_) = @_;
1711 next_argument();
1712 next_argument();
1713 return $_;
1714}
1715
1716sub do_cmd_sectionauthor{
1717 local($_) = @_;
1718 next_argument();
1719 next_argument();
1720 return $_;
1721}
1722
Fred Drakea0f4c941998-07-24 22:16:04 +00001723sub do_cmd_declaremodule{
1724 local($_) = @_;
1725 my $key = next_optional_argument();
1726 my $type = next_argument();
1727 my $name = next_argument();
1728 my $st = get_synopsis_table(get_chapter_id());
1729 #
1730 $key = $name unless $key;
1731 $type = 'built-in' if $type eq 'builtin';
1732 $st->declare($name, $key, $type);
1733 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001734 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001735}
1736
1737sub do_cmd_modulesynopsis{
1738 local($_) = @_;
1739 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001740 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001741 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001742}
1743
1744sub do_cmd_localmoduletable{
1745 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001746 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001747 my $st = get_synopsis_table($chap);
1748 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001749 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001750}
1751
Fred Drakef5478632002-05-23 17:59:16 +00001752sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001753 my $key;
1754 my $st, $file;
1755 foreach $key (keys %ModuleSynopses) {
1756 $st = $ModuleSynopses{$key};
1757 $file = $st->get_file();
1758 if ($file) {
1759 process_localmoduletables_in_file($file);
1760 }
1761 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001762 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001763 }
1764 }
1765}
1766
Fred Drakef5478632002-05-23 17:59:16 +00001767sub process_localmoduletables_in_file($){
Fred Drake643d76d2000-09-09 06:07:37 +00001768 my $file = @_[0];
1769 open(MYFILE, "<$file");
1770 local($_);
1771 sysread(MYFILE, $_, 1024*1024);
1772 close(MYFILE);
1773 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001774 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001775 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001776 my $chap = $1;
1777 my $st = get_synopsis_table($chap);
1778 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001779 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001780 }
Fred Drake643d76d2000-09-09 06:07:37 +00001781 open(MYFILE,">$file");
1782 print MYFILE $_;
1783 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001784}
Fred Drakef5478632002-05-23 17:59:16 +00001785sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001786 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001787 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001788}
Fred Drakea0f4c941998-07-24 22:16:04 +00001789
1790
1791#
1792# "See also:" -- references placed at the end of a \section
1793#
1794
1795sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001796 return ("<div class=\"seealso\">\n "
1797 . "<p class=\"heading\"><b>See Also:</b></p>\n"
1798 . @_[0]
1799 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001800}
1801
Fred Drake5ed35fd2001-11-30 18:09:54 +00001802sub do_env_seealsostar{
1803 return ("<div class=\"seealso-simple\">\n "
1804 . @_[0]
1805 . '</div>');
1806}
1807
Fred Drakea0f4c941998-07-24 22:16:04 +00001808sub do_cmd_seemodule{
1809 # Insert the right magic to jump to the module definition. This should
1810 # work most of the time, at least for repeat builds....
1811 local($_) = @_;
1812 my $key = next_optional_argument();
1813 my $module = next_argument();
1814 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001815 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001816 $key = $module
1817 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001818 if ($text =~ /\.$/) {
1819 $period = '';
1820 }
Fred Drakef1927a62001-06-20 21:29:30 +00001821 return ('<dl compact class="seemodule">'
1822 . "\n <dt>Module <b><tt class=\"module\">"
1823 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1824 . "\n <dd>$text$period\n </dl>"
1825 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001826}
1827
Fred Drakee0197bf2001-04-12 04:03:22 +00001828sub strip_html_markup($){
1829 my $str = @_[0];
1830 my $s = "$str";
1831 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1832 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1833 return $s;
1834}
1835
Fred Drakef5478632002-05-23 17:59:16 +00001836sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001837 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001838 my $rfcnum = next_argument();
1839 my $title = next_argument();
1840 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001841 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001842 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001843 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001844 return '<dl compact class="seerfc">'
1845 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001846 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001847 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001848 . "\n <dd>$text\n </dl>"
1849 . $_;
1850}
1851
Fred Drake643d76d2000-09-09 06:07:37 +00001852sub do_cmd_seepep{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001853 return handle_rfclike_reference(@_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001854}
1855
1856sub do_cmd_seerfc{
Fred Drakeafc7ce12001-01-22 17:33:24 +00001857 return handle_rfclike_reference(@_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001858}
1859
Fred Drake48449982000-09-12 17:52:33 +00001860sub do_cmd_seetitle{
1861 local($_) = @_;
1862 my $url = next_optional_argument();
1863 my $title = next_argument();
1864 my $text = next_argument();
1865 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001866 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001867 return '<dl compact class="seetitle">'
1868 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001869 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001870 . "\n <dd>$text\n </dl>"
1871 . $_;
1872 }
1873 return '<dl compact class="seetitle">'
1874 . "\n <dt><em class=\"citetitle\""
1875 . "\n >$title</em>"
1876 . "\n <dd>$text\n </dl>"
1877 . $_;
1878}
1879
Fred Drakeef4d1112000-05-09 16:17:51 +00001880sub do_cmd_seeurl{
1881 local($_) = @_;
1882 my $url = next_argument();
1883 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001884 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001885 return '<dl compact class="seeurl">'
1886 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001887 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001888 . "\n <dd>$text\n </dl>"
1889 . $_;
1890}
1891
Fred Drakea0f4c941998-07-24 22:16:04 +00001892sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001893 local($_) = @_;
1894 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001895 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001896}
1897
1898
1899#
Fred Drake885215c1998-05-20 21:32:09 +00001900# Definition list support.
1901#
1902
1903sub do_env_definitions{
Fred Drakef1927a62001-06-20 21:29:30 +00001904 return "<dl class=\"definitions\">" . @_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001905}
1906
1907sub do_cmd_term{
1908 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001909 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001910 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001911 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001912 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001913}
1914
1915
Fred Drake38178fd2000-09-22 17:05:04 +00001916# I don't recall exactly why this was needed, but it was very much needed.
1917# We'll see if anything breaks when I move the "code" line out -- some
1918# things broke with it in.
1919
1920#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001921process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001922declaremodule # [] # {} # {}
1923memberline # [] # {}
1924methodline # [] # {} # {}
1925modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001926platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001927samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001928setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001929withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001930_RAW_ARG_DEFERRED_CMDS_
1931
1932
Fred Drake8a5e6792002-04-15 18:41:31 +00001933$alltt_start = '<div class="verbatim"><pre>';
1934$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001935
Fred Drakef5478632002-05-23 17:59:16 +00001936sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001937 local ($_) = @_;
1938 local($closures,$reopens,@open_block_tags);
1939
1940 # get the tag-strings for all open tags
1941 local(@keep_open_tags) = @$open_tags_R;
1942 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1943
1944 # get the tags for text-level tags only
1945 $open_tags_R = [ @keep_open_tags ];
1946 local($local_closures, $local_reopens);
1947 ($local_closures, $local_reopens,@open_block_tags)
1948 = &preserve_open_block_tags
1949 if (@$open_tags_R);
1950
1951 $open_tags_R = [ @open_block_tags ];
1952
1953 do {
1954 local($open_tags_R) = [ @open_block_tags ];
1955 local(@save_open_tags) = ();
1956
1957 local($cnt) = ++$global{'max_id'};
1958 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1959 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1960
1961 $_ = &translate_environments($_);
1962 $_ = &translate_commands($_) if (/\\/);
1963
1964 # preserve space-runs, using &nbsp;
1965 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1966 s/(<BR>) /$1;SPMnbsp;/g;
1967
1968 $_ = join('', $closures, $alltt_start, $local_reopens
1969 , $_
1970 , &balance_tags() #, $local_closures
1971 , $alltt_end, $reopens);
1972 undef $open_tags_R; undef @save_open_tags;
1973 };
1974 $open_tags_R = [ @keep_open_tags ];
1975 $_;
1976}
1977
Fred Drake6fc22f62002-06-17 15:01:05 +00001978# List of all filenames produced ny do_cmd_verbatiminput()
1979%VerbatimFiles = ();
1980@VerbatimOutputs = ();
1981
1982sub get_verbatim_output_name($){
1983 my $file = @_[0];
1984 #
1985 # Re-write the source filename to always use a .txt extension
1986 # so that Web servers will present it as text/plain. This is
1987 # needed since there is no other even moderately reliable way
1988 # to get the right Content-Type header on text files for
1989 # servers which we can't configure (like python.org mirrors).
1990 #
1991 if (defined $VerbatimFiles{$file}) {
1992 # We've seen this one before; re-use the same output file.
1993 return $VerbatimFiles{$file};
1994 }
1995 use File::Basename;
1996 my $srcname, $srcdir, $srcext;
1997 ($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
1998 $filename = "$srcname.txt";
1999 #
2000 # We need to determine if our default filename is already
2001 # being used, and find a new one it it is. If the name is in
2002 # used, this algorithm will first attempt to include the
2003 # source extension as part of the name, and if that is also in
2004 # use (if the same file is included multiple times, or if
2005 # another source file has that as the base name), a counter is
2006 # used instead.
2007 #
2008 my $found = 1;
2009 FIND:
2010 while ($found) {
2011 foreach $fn (@VerbatimOutputs) {
2012 if ($fn eq $filename) {
2013 if ($found == 1) {
2014 $srcext =~ s/^[.]//; # Remove '.' from extension
2015 $filename = "$srcname-$srcext.txt";
2016 }
2017 else {
2018 $filename = "$srcname-$found.txt";
2019 }
2020 ++$found;
2021 next FIND;
2022 }
2023 }
2024 $found = 0;
2025 }
2026 push @VerbatimOutputs, $filename;
2027 $VerbatimFiles{$file} = $filename;
2028 return $filename;
2029}
2030
Fred Drake57e52ef2001-06-15 21:31:57 +00002031sub do_cmd_verbatiminput{
2032 local($_) = @_;
2033 my $fname = next_argument();
2034 my $file;
2035 my $found = 0;
2036 my $texpath;
2037 # Search TEXINPUTS for the input file, the way we're supposed to:
2038 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2039 $file = "$texpath$dd$fname";
2040 last if ($found = (-f $file));
2041 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002042 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002043 my $text;
2044 if ($found) {
2045 open(MYFILE, "<$file") || die "\n$!\n";
2046 read(MYFILE, $text, 1024*1024);
2047 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002048 $filename = get_verbatim_output_name($file);
2049 # Now that we have a filename, write it out.
2050 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002051 print MYFILE $text;
2052 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002053 #
2054 # These rewrites convert the raw text to something that will
2055 # be properly visible as HTML and also will pass through the
2056 # vagaries of conversion through LaTeX2HTML. The order in
2057 # which the specific rewrites are performed is significant.
2058 #
2059 $text =~ s/\&/\&amp;/g;
2060 # These need to happen before the normal < and > re-writes,
2061 # since we need to avoid LaTeX2HTML's attempt to perform
2062 # ligature processing without regard to context (since it
2063 # doesn't have font information).
2064 $text =~ s/--/-&\#45;/g;
2065 $text =~ s/<</\&lt;\&\#60;/g;
2066 $text =~ s/>>/\&gt;\&\#62;/g;
2067 # Just normal re-writes...
2068 $text =~ s/</\&lt;/g;
2069 $text =~ s/>/\&gt;/g;
2070 # These last isn't needed for the HTML, but is needed to get
2071 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2072 # of &sol; since many browsers don't support that.
2073 $text =~ s/\\/\&\#92;/g;
2074 }
2075 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002076 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2077 }
2078 my $note = 'Download as text.';
2079 if ($file ne $filename) {
2080 $note = ('Download as text (original file name: <span class="file">'
2081 . $fname
2082 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002083 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002084 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002085 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002086 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002087 . "<a href=\"$filename\" type=\"text/plain\""
2088 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002089 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002090 . $_);
2091}
Fred Drake86333602001-04-10 17:13:39 +00002092
Fred Drake6659c301998-03-03 22:02:19 +000020931; # This must be the last line