blob: 1459076a167bbf8010f544fc6846dfce29c2fe5a [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 Drake49b33fa2002-11-15 19:04:10 +000011use warnings;
Fred Drake7a40c072000-10-02 14:43:38 +000012use File::Basename;
13
Fred Drake6659c301998-03-03 22:02:19 +000014
Fred Drake08932051998-04-17 02:15:42 +000015sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000016 my $param;
17 $param = missing_braces()
18 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
19 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000020 return $param;
Fred Drake08932051998-04-17 02:15:42 +000021}
22
23sub next_optional_argument{
Fred Drakef5478632002-05-23 17:59:16 +000024 my($param, $rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000025 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000026 return $param;
Fred Drake08932051998-04-17 02:15:42 +000027}
28
Fred Drake7a40c072000-10-02 14:43:38 +000029sub make_icon_filename($){
Fred Drake49b33fa2002-11-15 19:04:10 +000030 my($myname, $mydir, $myext) = fileparse($_[0], '\..*');
Fred Drake7a40c072000-10-02 14:43:38 +000031 chop $mydir;
32 if ($mydir eq '.') {
33 $mydir = $ICONSERVER;
34 }
35 $myext = ".$IMAGE_TYPE"
36 unless $myext;
37 return "$mydir$dd$myname$myext";
38}
39
Fred Drake7a40c072000-10-02 14:43:38 +000040sub get_link_icon($){
Fred Drake49b33fa2002-11-15 19:04:10 +000041 my $url = $_[0];
Fred Drake7a40c072000-10-02 14:43:38 +000042 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
43 # absolute URL; assume it points off-site
44 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
Fred Drakef1927a62001-06-20 21:29:30 +000045 return (" <img src=\"$icon\"\n"
46 . ' border="0" class="offsitelink"'
Fred Drake5f84c9b2000-10-03 06:05:25 +000047 . ($OFF_SITE_LINK_ICON_HEIGHT
Fred Drakef1927a62001-06-20 21:29:30 +000048 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000049 : '')
50 . ($OFF_SITE_LINK_ICON_WIDTH
Fred Drakef1927a62001-06-20 21:29:30 +000051 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000052 : '')
Fred Drakef1927a62001-06-20 21:29:30 +000053 . " alt=\"[off-site link]\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +000054 . " >");
55 }
56 return '';
57}
Fred Drakee16f6791998-05-15 04:28:37 +000058
59# This is a fairly simple hack; it supports \let when it is used to create
60# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000061# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000062#
63sub do_cmd_let{
64 local($_) = @_;
65 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000066 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000067 if ($matched) {
68 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
71 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000072 else {
73 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
74 if ($matched) {
75 my($new, $char) = ($1, $3);
Fred Drake49b33fa2002-11-15 19:04:10 +000076 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
Fred Drake7a4ad0f1998-05-15 13:45:54 +000077 print "\ndefining handler for \\$new to insert '$char'\n";
78 }
79 else {
80 write_warnings("Could not interpret \\let construct...");
81 }
82 }
Fred Drake62e43691998-08-10 19:40:44 +000083 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000084}
85
86
Fred Drakec3fd45f2000-06-15 22:41:48 +000087# the older version of LaTeX2HTML we use doesn't support this, but we use it:
88
Fred Drake49b33fa2002-11-15 19:04:10 +000089sub do_cmd_textasciitilde{ '&#126;' . $_[0]; }
90sub do_cmd_textasciicircum{ '^' . $_[0]; }
91sub do_cmd_textbar{ '|' . $_[0]; }
92sub do_cmd_textgreater{ '&gt;' . $_[0]; }
93sub do_cmd_textless{ '&lt;' . $_[0]; }
94sub do_cmd_textunderscore{ '_' . $_[0]; }
95sub do_cmd_infinity{ '&infin;' . $_[0]; }
96sub do_cmd_plusminus{ '&plusmn;' . $_[0]; }
97sub do_cmd_menuselection{ $_[0]; }
98sub do_cmd_sub{ ' > ' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +000099
100
Fred Drake6659c301998-03-03 22:02:19 +0000101# words typeset in a special way (not in HTML though)
102
Fred Drake49b33fa2002-11-15 19:04:10 +0000103sub do_cmd_ABC{ 'ABC' . $_[0]; }
Fred Drake5bbeb8d2003-02-04 15:01:37 +0000104sub do_cmd_UNIX{ '<font style="font-variant: small-caps;">Unix</font>'
105 . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000106sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
107sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
108sub do_cmd_C{ 'C' . $_[0]; }
109sub do_cmd_Cpp{ 'C++' . $_[0]; }
110sub do_cmd_EOF{ 'EOF' . $_[0]; }
111sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000112
Fred Drake49b33fa2002-11-15 19:04:10 +0000113sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000114
Fred Draked07868a1998-05-14 21:00:28 +0000115$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000116$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000117$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000118$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000119
Fred Drake49b33fa2002-11-15 19:04:10 +0000120sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
121sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000122sub do_cmd_release{
123 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000124 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000125 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000126}
127
Fred Drakef1927a62001-06-20 21:29:30 +0000128sub do_cmd_setreleaseinfo{
129 local($_) = @_;
130 $RELEASE_INFO = next_argument();
131 return $_;
132}
133
Fred Drake3cdb89d2000-09-14 20:17:23 +0000134sub do_cmd_setshortversion{
135 local($_) = @_;
136 $SHORT_VERSION = next_argument();
137 return $_;
138}
139
Fred Drake6659c301998-03-03 22:02:19 +0000140sub do_cmd_authoraddress{
141 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000142 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000143 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000144}
145
Fred Drake49b33fa2002-11-15 19:04:10 +0000146#sub do_cmd_developer{ do_cmd_author($_[0]); }
147#sub do_cmd_developers{ do_cmd_author($_[0]); }
148#sub do_cmd_developersaddress{ do_cmd_authoraddress($_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000149
Fred Drake6659c301998-03-03 22:02:19 +0000150sub do_cmd_hackscore{
151 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000152 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000153 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000154}
155
Fred Drakef5478632002-05-23 17:59:16 +0000156sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000157 local($_,$before,$after) = @_;
158 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000159 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000160}
161
Fred Drake3cdb89d2000-09-14 20:17:23 +0000162$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000163sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000164 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000165 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000166 "</var><big>\]</big><var>");
167 }
168 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000169 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000170 }
Fred Drake6659c301998-03-03 22:02:19 +0000171}
172
Fred Drakec9a44381998-03-17 06:29:13 +0000173# Logical formatting (some based on texinfo), needs to be converted to
174# minimalist HTML. The "minimalist" is primarily to reduce the size of
175# output files for users that read them over the network rather than
176# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000177
Fred Drake49b33fa2002-11-15 19:04:10 +0000178sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000179sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000180 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000181sub do_cmd_code{
Fred Drake49b33fa2002-11-15 19:04:10 +0000182 return use_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000183sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000184 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000185sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000186 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000187sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000188 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000189sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000190 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000191sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000192 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000193sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000194 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000195sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000196 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000197sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000198 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000199sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000200 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000201sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000202 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000203sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000204 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000205sub do_cmd_regexp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000206 return use_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000207sub do_cmd_character{
Fred Drake49b33fa2002-11-15 19:04:10 +0000208 return use_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000209sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000210 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000211sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000212 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000213sub do_cmd_longprogramopt{
214 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000215 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000216sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000217 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000218sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000219 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000220sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000221 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000222sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000223 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000224sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000225 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000226sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000227 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000228sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000229 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000230sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000231 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000232sub do_cmd_samp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000233 return use_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000234sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000235 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000236sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000237 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000238sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000239 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000240sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000241 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000242# This can be changed/overridden for translations:
243%NoticeNames = ('note' => 'Note:',
244 'warning' => 'Warning:',
245 );
246
Fred Drake92350b32001-10-09 18:01:23 +0000247sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000248 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000249 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000250 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000251 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000252 '</span>'); }
253sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000254 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000255 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000256 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000257 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000258 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000259
Fred Drake6ca33772001-12-14 22:50:06 +0000260sub do_env_notice{
261 local($_) = @_;
262 my $notice = next_optional_argument();
263 if (!$notice) {
264 $notice = 'note';
265 }
266 my $label = $NoticeNames{$notice};
267 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
268 . $_
269 . '</div>');
270}
271
Fred Drake3d5a04a2000-08-03 17:25:44 +0000272sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000273 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000274sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000275 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000276
Fred Drakec9a44381998-03-17 06:29:13 +0000277
Fred Drake25817041999-01-13 17:06:34 +0000278sub do_cmd_refmodule{
279 # Insert the right magic to jump to the module definition.
280 local($_) = @_;
281 my $key = next_optional_argument();
282 my $module = next_argument();
283 $key = $module
284 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000285 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000286 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000287}
288
Fred Drake1a7af391998-04-01 22:44:56 +0000289sub do_cmd_newsgroup{
290 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000291 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000292 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000293 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
294 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000295 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000296}
Fred Drakefc16e781998-03-12 21:03:26 +0000297
298sub do_cmd_envvar{
299 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000300 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000301 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000302 # The <tt> here is really to keep buildindex.py from making
303 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000304 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000305 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000306 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000307 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000308 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000309}
310
Fred Drake6659c301998-03-03 22:02:19 +0000311sub do_cmd_url{
312 # use the URL as both text and hyperlink
313 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000314 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000315 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000316 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000317 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000318}
319
320sub do_cmd_manpage{
321 # two parameters: \manpage{name}{section}
322 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000323 my $page = next_argument();
324 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000325 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000326}
327
Fred Drakedbfe7682002-04-03 02:47:14 +0000328$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000329#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
330$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000331
332sub get_rfc_url($$){
333 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000334 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000335}
336
337sub do_cmd_pep{
338 local($_) = @_;
339 my $rfcnumber = next_argument();
340 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000341 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000342 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000343 # Save the reference
344 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
345 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000346 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
347 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000348}
349
Fred Drake6659c301998-03-03 22:02:19 +0000350sub do_cmd_rfc{
351 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000352 my $rfcnumber = next_argument();
353 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000354 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000355 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000356 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000357 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000358 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000359 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
360 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000361}
362
Fred Drake77602f22001-07-06 22:43:02 +0000363sub do_cmd_ulink{
364 local($_) = @_;
365 my $text = next_argument();
366 my $url = next_argument();
367 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
368}
369
Fred Drakec9f5fe01999-11-09 16:59:42 +0000370sub do_cmd_citetitle{
371 local($_) = @_;
372 my $url = next_optional_argument();
373 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000374 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000375 my $repl = '';
376 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000377 $repl = ("<em class=\"citetitle\"><a\n"
378 . " href=\"$url\"\n"
379 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000380 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000381 }
382 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000383 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000384 }
385 return $repl . $_;
386}
387
Fred Drake6659c301998-03-03 22:02:19 +0000388sub do_cmd_deprecated{
389 # two parameters: \deprecated{version}{whattodo}
390 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000391 my $release = next_argument();
392 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000393 return ('<div class="versionnote">'
394 . "<b>Deprecated since release $release.</b>"
395 . "\n$reason</div><p>"
396 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000397}
398
Fred Drakef5478632002-05-23 17:59:16 +0000399sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000400 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000401 my $type = $_[0];
402 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000403 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000404 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000405 my $text = "$type in version $release.";
406 if ($explanation) {
407 $text = "$type in version $release:\n$explanation.";
408 }
Fred Drakef1927a62001-06-20 21:29:30 +0000409 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000410}
411
412sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000413 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000414}
415
416sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000417 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000418}
419
Fred Drake557460c1999-03-02 16:05:35 +0000420#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000421# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000422#
423sub do_cmd_platform{
424 local($_) = @_;
425 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000426 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000427 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000428 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000429 return "\n<p class=\"availability\">Availability: <span"
430 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000431}
432
Fred Drake557460c1999-03-02 16:05:35 +0000433$IGNORE_PLATFORM_ANNOTATION = '';
434sub do_cmd_ignorePlatformAnnotation{
435 local($_) = @_;
436 $IGNORE_PLATFORM_ANNOTATION = next_argument();
437 return $_;
438}
439
Fred Drake6659c301998-03-03 22:02:19 +0000440
441# index commands
442
443$INDEX_SUBITEM = "";
444
Fred Drakef5478632002-05-23 17:59:16 +0000445sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000446 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000447}
448
449sub do_cmd_setindexsubitem{
450 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000451 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000452 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000453}
454
Fred Drakefc16e781998-03-12 21:03:26 +0000455sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000456 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000457 # do things in the right order, but we need to at least strip this stuff
458 # out, and leave anything that the second argument expanded out to.
459 #
460 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000461 my $oldsubitem = $INDEX_SUBITEM;
462 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000463 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000464 my $br_id = ++$globals{'max_id'};
465 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000466 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000467 return
468 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000469 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000470 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000471}
472
Fred Drake08932051998-04-17 02:15:42 +0000473# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000474# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
475# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000476#
Fred Drake49b33fa2002-11-15 19:04:10 +0000477sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000478
Fred Drake42b31a51998-03-27 05:16:10 +0000479# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000480#
Fred Drake08932051998-04-17 02:15:42 +0000481open(IDXFILE, '>index.dat') || die "\n$!\n";
482open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000483print INTLABELS "%internal_labels = ();\n";
484print INTLABELS "1; # hack in case there are no entries\n\n";
485
486# Using \0 for this is bad because we can't use common tools to work with the
487# resulting files. Things like grep can be useful with this stuff!
488#
489$IDXFILE_FIELD_SEP = "\1";
490
Fred Drakef5478632002-05-23 17:59:16 +0000491sub write_idxfile($$){
492 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000493 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000494}
495
Fred Drake42b31a51998-03-27 05:16:10 +0000496
Fred Drakef5478632002-05-23 17:59:16 +0000497sub gen_link($$){
498 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000499 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000500 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000501}
502
Fred Drakef5478632002-05-23 17:59:16 +0000503sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000504 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000505 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000506 $str = gen_index_id($str, '');
507 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000508 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000509}
510
Fred Drakef5478632002-05-23 17:59:16 +0000511sub new_link_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000512 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000513 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000514 my $ahref = gen_link($CURRENT_FILE, $name);
515 return ($name, $aname, $ahref);
516}
517
Fred Drakeab032151999-05-13 18:36:54 +0000518$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000519sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000520 my $count = @_;
521 my $i = 0;
522 for (; $i < $count; ++$i) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000523 my $name = $_[$i];
Fred Drakeab032151999-05-13 18:36:54 +0000524 my $cmd = "idx_cmd_$name";
525 die "\nNo function $cmd() defined!\n"
526 if (!defined &$cmd);
527 eval ("sub do_cmd_$name { return process_index_macros("
Fred Drake49b33fa2002-11-15 19:04:10 +0000528 . "\$_[0], '$name'); }");
Fred Drakeab032151999-05-13 18:36:54 +0000529 if (length($IndexMacroPattern) == 0) {
530 $IndexMacroPattern = "$name";
531 }
532 else {
533 $IndexMacroPattern .= "|$name";
534 }
535 }
536}
537
538$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000539sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000540 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000541 my $cmdname = $_[1]; # This is what triggered us in the first place;
Fred Drakeab032151999-05-13 18:36:54 +0000542 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000543 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000544 my $cmd = "idx_cmd_$cmdname";
545 print "\nIndexing: \\$cmdname"
546 if $DEBUG_INDEXING;
547 &$cmd($ahref); # modifies $_ and adds index entries
548 while (/^[\s\n]*\\($IndexMacroPattern)</) {
549 $cmdname = "$1";
550 print " \\$cmdname"
551 if $DEBUG_INDEXING;
552 $cmd = "idx_cmd_$cmdname";
553 if (!defined &$cmd) {
554 last;
555 }
556 else {
557 s/^[\s\n]*\\$cmdname//;
558 &$cmd($ahref);
559 }
560 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000561 if (/^[ \t\r\n]/) {
562 $_ = substr($_, 1);
563 }
Fred Drake62e43691998-08-10 19:40:44 +0000564 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000565}
566
Fred Drakeab032151999-05-13 18:36:54 +0000567define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000568sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000569 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000570 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000571}
572
Fred Drakeab032151999-05-13 18:36:54 +0000573define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000574sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000575 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000576 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
577 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000578}
579
580define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000581sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000582 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000583 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000584 add_index_entry("$str1!$str2", $_[0]);
585 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000586}
587
Fred Drakeab032151999-05-13 18:36:54 +0000588define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000589sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000590 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000591 my $str2 = next_argument();
592 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000593 add_index_entry("$str1!$str2 $str3", $_[0]);
594 add_index_entry("$str2!$str3, $str1", $_[0]);
595 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000596}
597
Fred Drakeab032151999-05-13 18:36:54 +0000598define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000599sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000600 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000601 my $str2 = next_argument();
602 my $str3 = next_argument();
603 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000604 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
605 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
606 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
607 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000608}
609
Fred Drakeab032151999-05-13 18:36:54 +0000610define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000611sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000612 my $str = next_argument();
613 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000614 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000615}
Fred Drake6659c301998-03-03 22:02:19 +0000616
Fred Drakef5478632002-05-23 17:59:16 +0000617sub my_typed_index_helper($$){
618 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000619 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000620 add_index_entry("$str $word", $ahref);
621 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000622}
623
Fred Drakeab032151999-05-13 18:36:54 +0000624define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000625sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
626sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
627sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
628sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000629
Fred Drakeab032151999-05-13 18:36:54 +0000630define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000631sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000632 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000633 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000634 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000635}
636
637
Fred Drakef5478632002-05-23 17:59:16 +0000638sub make_mod_index_entry($$){
639 my($str, $define) = @_;
640 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000641 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000642 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
643 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000644 $str = gen_index_id($str, $define);
645 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000646 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000647
Fred Drakec9a44381998-03-17 06:29:13 +0000648 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000649 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000650 $str =~ /(<tt.*<\/tt>)/;
651 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000652 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000653 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000654 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000655}
656
Fred Drake557460c1999-03-02 16:05:35 +0000657
Fred Drakec9a44381998-03-17 06:29:13 +0000658$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000659$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000660
Fred Drakef5478632002-05-23 17:59:16 +0000661sub define_module($$){
662 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000663 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000664 if ($word ne "built-in" && $word ne "extension"
665 && $word ne "standard" && $word ne "") {
666 write_warnings("Bad module type '$word'"
667 . " for \\declaremodule (module $name)");
668 $word = "";
669 }
Fred Drake6659c301998-03-03 22:02:19 +0000670 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000671 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000672 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000673 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000674 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000675 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000676}
677
Fred Drakef5478632002-05-23 17:59:16 +0000678sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000679 local($word, $_) = @_;
680 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000681 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000682}
683
Fred Drake49b33fa2002-11-15 19:04:10 +0000684sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
685sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
686sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
687sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
688# local($_) = @_;
689# my $name = next_argument();
690# return define_module('standard', $name) . $_;
691# }
Fred Drake6659c301998-03-03 22:02:19 +0000692
Fred Drakef5478632002-05-23 17:59:16 +0000693sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000694 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000695 my $str = next_argument();
696 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000697 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000698 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
699 # just inline it all here
700 $str = gen_index_id($str, 'REF');
701 $index{$str} .= $ahref;
702 write_idxfile($ahref, $str);
703}
704
Fred Drake6659c301998-03-03 22:02:19 +0000705# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000706define_indexing_macro('refmodindex', 'refbimodindex',
707 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000708sub idx_cmd_refmodindex($){
709 return ref_module_index_helper('', $_[0]); }
710sub idx_cmd_refbimodindex($){
711 return ref_module_index_helper('built-in', $_[0]); }
712sub idx_cmd_refexmodindex($){
713 return ref_module_index_helper('extension', $_[0]);}
714sub idx_cmd_refstmodindex($){
715 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000716
Fred Drake49b33fa2002-11-15 19:04:10 +0000717sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000718
Fred Drakef5478632002-05-23 17:59:16 +0000719sub init_myformat(){
Fred Drakeafc7ce12001-01-22 17:33:24 +0000720 $anchor_invisible_mark = '&nbsp;';
721 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000722 $anchor_mark = '';
723 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000724}
Fred Drake42b31a51998-03-27 05:16:10 +0000725init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000726
Fred Drakeab032151999-05-13 18:36:54 +0000727# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000728# instead of the dummy filler.
729#
Fred Drakef5478632002-05-23 17:59:16 +0000730sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000731 my $str = $_[0];
Fred Drakef5478632002-05-23 17:59:16 +0000732 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000733 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000734 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000735}
736
Fred Drake77602f22001-07-06 22:43:02 +0000737
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000738%TokenToTargetMapping = (); # language:token -> link target
739%DefinedGrammars = (); # language -> full grammar text
740%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000741
742sub do_cmd_token{
743 local($_) = @_;
744 my $token = next_argument();
745 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
746 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
747 # recursive definition or display-only productionlist
748 return "$token";
749 }
750 if ($target eq '') {
751 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
752 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
753 print "Adding '$CURRENT_FILE' to back-patch list.\n";
754 }
755 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
756 }
757 return "<a href=\"$target\">$token</a>" . $_;
758}
759
Fred Drake16bb4192001-08-20 21:36:38 +0000760sub do_cmd_grammartoken{
761 return do_cmd_token(@_);
762}
763
Fred Drake77602f22001-07-06 22:43:02 +0000764sub do_env_productionlist{
765 local($_) = @_;
766 my $lang = next_optional_argument();
767 my $filename = "grammar-$lang.txt";
768 if ($lang eq '') {
769 $filename = 'grammar.txt';
770 }
771 local($CURRENT_GRAMMAR) = $lang;
772 $DefinedGrammars{$lang} .= $_;
773 return ("<dl><dd class=\"grammar\">\n"
774 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000775 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000776 . translate_commands(translate_environments($_))
777 . "</table>\n"
778 . "</div>\n"
779 . (($lang eq '*')
780 ? ''
781 : ("<a class=\"grammar-footer\"\n"
782 . " href=\"$filename\" type=\"text/plain\"\n"
783 . " >Download entire grammar as text.</a>\n"))
784 . "</dd></dl>");
785}
786
787sub do_cmd_production{
788 local($_) = @_;
789 my $token = next_argument();
790 my $defn = next_argument();
791 my $lang = $CURRENT_GRAMMAR;
792 local($CURRENT_TOKEN) = $token;
793 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000794 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000795 . " <td><code>$token</code></td>\n"
796 . " <td>&nbsp;::=&nbsp;</td>\n"
797 . " <td><code>"
798 . translate_commands($defn)
799 . "</code></td></tr>"
800 . $_);
801 }
802 my $target;
803 if ($lang eq '') {
804 $target = "$CURRENT_FILE\#tok-$token";
805 }
806 else {
807 $target = "$CURRENT_FILE\#tok-$lang-$token";
808 }
809 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000810 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000811 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
812 . " <td>&nbsp;::=&nbsp;</td>\n"
813 . " <td><code>"
814 . translate_commands($defn)
815 . "</code></td></tr>"
816 . $_);
817}
818
Fred Drake53815882002-03-15 23:21:37 +0000819sub do_cmd_productioncont{
820 local($_) = @_;
821 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000822 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000823 return ("<tr valign=\"baseline\">\n"
824 . " <td>&nbsp;</td>\n"
825 . " <td>&nbsp;</td>\n"
826 . " <td><code>"
827 . translate_commands($defn)
828 . "</code></td></tr>"
829 . $_);
830}
831
Fred Drakef5478632002-05-23 17:59:16 +0000832sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000833 my $lang;
834 my $filename;
835 local($_);
836 print "process_grammar_files()\n";
837 foreach $lang (keys %DefinedGrammars) {
838 $filename = "grammar-$lang.txt";
839 if ($lang eq '*') {
840 next;
841 }
842 if ($lang eq '') {
843 $filename = 'grammar.txt';
844 }
845 open(GRAMMAR, ">$filename") || die "\n$!\n";
846 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
847 close(GRAMMAR);
848 print "Wrote grammar file $filename\n";
849 }
850 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
851 foreach $filename (keys %BackpatchGrammarFiles) {
852 print "\nBack-patching grammar links in $filename\n";
853 my $buffer;
854 open(GRAMMAR, "<$filename") || die "\n$!\n";
855 # read all of the file into the buffer
856 sysread(GRAMMAR, $buffer, 1024*1024);
857 close(GRAMMAR);
858 while ($buffer =~ /$PATTERN/) {
859 my($lang, $token) = ($1, $2);
860 my $target = $TokenToTargetMapping{"$lang:$token"};
861 my $source = "<pyGrammarToken><$lang><$token>";
862 $buffer =~ s/$source/$target/g;
863 }
864 open(GRAMMAR, ">$filename") || die "\n$!\n";
865 print GRAMMAR $buffer;
866 close(GRAMMAR);
867 }
868}
869
Fred Drakef5478632002-05-23 17:59:16 +0000870sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000871 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000872 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000873 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
874 s/\\token(<<\d+>>)(.+)\1/$2/g;
875 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000876 s/<<\d+>>//g;
877 s/;SPMgt;/>/g;
878 s/;SPMlt;/</g;
879 s/;SPMquot;/\"/g;
880 return $_;
881}
882
883
Fred Drakee15956b2000-04-03 04:51:13 +0000884$REFCOUNTS_LOADED = 0;
885
Fred Drakef5478632002-05-23 17:59:16 +0000886sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000887 $REFCOUNTS_LOADED = 1;
888
Fred Drake49b33fa2002-11-15 19:04:10 +0000889 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drakee15956b2000-04-03 04:51:13 +0000890 chop $mydir; # remove trailing '/'
891 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
892 chop $mydir; # remove trailing '/'
893 $mydir = getcwd() . "$dd$mydir"
894 unless $mydir =~ s|^/|/|;
895 local $_;
896 my $filename = "$mydir${dd}api${dd}refcounts.dat";
897 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
898 print "[loading API refcount data]";
899 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000900 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000901 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
902 #print "\n$func($param) --> $count";
903 $REFCOUNTS{"$func:$param"} = $count;
904 }
905 }
906}
907
Fred Drakef5478632002-05-23 17:59:16 +0000908sub get_refcount($$){
909 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000910 load_refcounts()
911 unless $REFCOUNTS_LOADED;
912 return $REFCOUNTS{"$func:$param"};
913}
914
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000915
916$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000917$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000918
Fred Drakef5478632002-05-23 17:59:16 +0000919sub cfuncline_helper($$$){
920 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000921 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000922 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000923 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000924 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000925 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
926 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000927 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
928 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
929 . "<td>$args)</td>"
930 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000931}
932sub do_cmd_cfuncline{
933 local($_) = @_;
934 my $type = next_argument();
935 my $name = next_argument();
936 my $args = next_argument();
937 my $siginfo = cfuncline_helper($type, $name, $args);
938 return "<dt>$siginfo\n<dd>" . $_;
939}
940sub do_env_cfuncdesc{
941 local($_) = @_;
942 my $type = next_argument();
943 my $name = next_argument();
944 my $args = next_argument();
945 my $siginfo = cfuncline_helper($type, $name, $args);
946 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000947 my $rcinfo = '';
948 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000949 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000950 }
951 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000952 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000953 }
Fred Drakec2578c52000-04-10 18:26:45 +0000954 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000955 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000956 }
Fred Drakee15956b2000-04-03 04:51:13 +0000957 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000958 $rcinfo = ( "\n<div class=\"refcount-info\">"
959 . "\n <span class=\"label\">Return value:</span>"
960 . "\n <span class=\"value\">$rcinfo.</span>"
961 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000962 }
Fred Drake34adb8a2002-04-15 20:48:40 +0000963 return "<dl><dt>$siginfo\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000964 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000965 . $_
966 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000967}
968
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000969sub do_cmd_cmemberline{
970 local($_) = @_;
971 my $container = next_argument();
972 my $type = next_argument();
973 my $name = next_argument();
974 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000975 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000976 $idx =~ s/ \(.*\)//;
977 return "<dt>$type <b>$idx</b>\n<dd>"
978 . $_;
979}
980sub do_env_cmemberdesc{
981 local($_) = @_;
982 my $container = next_argument();
983 my $type = next_argument();
984 my $name = next_argument();
985 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000986 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000987 $idx =~ s/ \(.*\)//;
988 return "<dl><dt>$type <b>$idx</b>\n<dd>"
989 . $_
990 . '</dl>';
991}
992
Fred Drakee15956b2000-04-03 04:51:13 +0000993sub do_env_csimplemacrodesc{
994 local($_) = @_;
995 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000996 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000997 return "<dl><dt><b>$idx</b>\n<dd>"
998 . $_
999 . '</dl>'
1000}
1001
Fred Drake6659c301998-03-03 22:02:19 +00001002sub do_env_ctypedesc{
1003 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001004 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001005 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001006 $index_name = $type_name
1007 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001008 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001009 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1010 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001011 . $_
1012 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001013}
1014
1015sub do_env_cvardesc{
1016 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001017 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001018 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001019 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001020 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001021 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001022 return "<dl><dt>$var_type <b>$idx</b>\n"
1023 . '<dd>'
1024 . $_
1025 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001026}
1027
Fred Drake3cdb89d2000-09-14 20:17:23 +00001028sub convert_args($){
1029 local($IN_DESC_HANDLER) = 1;
1030 local($_) = @_;
1031 return translate_commands($_);
1032}
1033
Fred Drakef6e90272002-06-18 18:24:16 +00001034sub funcline_helper($$$){
1035 my($first, $idxitem, $arglist) = @_;
1036 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001037 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1038 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1039 . "\n <td><var>$arglist</var>)</td></tr></table>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001040}
1041
Fred Drake6659c301998-03-03 22:02:19 +00001042sub do_env_funcdesc{
1043 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001044 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001045 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001046 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1047 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001048 . get_indexsubitem());
1049 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001050 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001051 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001052}
1053
1054sub do_env_funcdescni{
1055 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001056 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001057 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001058 my $prefix = "<tt class=\"function\">$function_name</tt>";
1059 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001060}
1061
1062sub do_cmd_funcline{
1063 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001064 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001065 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001066 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001067 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1068 $prefix =~ s/\(\)//;
1069
Fred Drakef6e90272002-06-18 18:24:16 +00001070 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001071}
1072
Fred Drake6b3fb781999-07-12 16:50:09 +00001073sub do_cmd_funclineni{
1074 local($_) = @_;
1075 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001076 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001077 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001078
Fred Drakef6e90272002-06-18 18:24:16 +00001079 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001080}
1081
Fred Drake6659c301998-03-03 22:02:19 +00001082# Change this flag to index the opcode entries. I don't think it's very
1083# useful to index them, since they're only presented to describe the dis
1084# module.
1085#
1086$INDEX_OPCODES = 0;
1087
1088sub do_env_opcodedesc{
1089 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001090 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001091 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001092 my $idx;
1093 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001094 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1095 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001096 $idx =~ s/ \(byte code instruction\)//;
1097 }
1098 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001099 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001100 }
1101 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001102 if ($arg_list) {
1103 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1104 }
Fred Drake62e43691998-08-10 19:40:44 +00001105 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001106}
1107
1108sub do_env_datadesc{
1109 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001110 my $dataname = next_argument();
1111 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001112 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001113 return "<dl><dt><b>$idx</b>\n<dd>"
1114 . $_
1115 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001116}
1117
1118sub do_env_datadescni{
1119 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001120 my $idx = next_argument();
1121 if (! $STRING_INDEX_TT) {
1122 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001123 }
Fred Drake62e43691998-08-10 19:40:44 +00001124 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001125}
1126
1127sub do_cmd_dataline{
1128 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001129 my $data_name = next_argument();
1130 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001131 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001132 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001133}
1134
Fred Drakeadb272c2000-04-10 17:47:14 +00001135sub do_cmd_datalineni{
1136 local($_) = @_;
1137 my $data_name = next_argument();
1138 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1139}
1140
Fred Drake42b31a51998-03-27 05:16:10 +00001141sub do_env_excdesc{
1142 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001143 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001144 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakef6e90272002-06-18 18:24:16 +00001145 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001146 . "\n<dd>"
1147 . $_
1148 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001149}
1150
Fred Drake62e43691998-08-10 19:40:44 +00001151sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001152
1153
Fred Drakef5478632002-05-23 17:59:16 +00001154sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001155 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001156 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001157 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001158 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001159 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001160 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001161 my $prefix = "$TLSTART$what$TLEND$idx";
1162 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001163}
1164
Fred Drake643d76d2000-09-09 06:07:37 +00001165sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001166 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001167}
1168
Fred Drake06a01e82001-05-11 01:00:30 +00001169sub do_env_classdescstar{
1170 local($_) = @_;
1171 $THIS_CLASS = next_argument();
1172 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001173 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001174 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001175 my $prefix = "${TLSTART}class$TLEND$idx";
1176 # Can't use funcline_helper() since there is no args list.
1177 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001178}
1179
Fred Drake643d76d2000-09-09 06:07:37 +00001180sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001181 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001182}
1183
Fred Drake42b31a51998-03-27 05:16:10 +00001184
1185sub do_env_methoddesc{
1186 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001187 my $class_name = next_optional_argument();
1188 $class_name = $THIS_CLASS
1189 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001190 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001191 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001192 my $extra = '';
1193 if ($class_name) {
1194 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001195 }
Fred Drakef1927a62001-06-20 21:29:30 +00001196 my $idx = make_str_index_entry(
1197 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001198 $idx =~ s/ \(.*\)//;
1199 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001200 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001201}
1202
1203
Fred Drake7d45f6d1999-01-05 14:39:27 +00001204sub do_cmd_methodline{
1205 local($_) = @_;
1206 my $class_name = next_optional_argument();
1207 $class_name = $THIS_CLASS
1208 unless $class_name;
1209 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001210 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001211 my $extra = '';
1212 if ($class_name) {
1213 $extra = " ($class_name method)";
1214 }
Fred Drakef1927a62001-06-20 21:29:30 +00001215 my $idx = make_str_index_entry(
1216 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001217 $idx =~ s/ \(.*\)//;
1218 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001219 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001220}
1221
1222
Fred Draked64a40d1998-09-10 18:59:13 +00001223sub do_cmd_methodlineni{
1224 local($_) = @_;
1225 next_optional_argument();
1226 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001227 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001228 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001229}
1230
Fred Drake42b31a51998-03-27 05:16:10 +00001231sub do_env_methoddescni{
1232 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001233 next_optional_argument();
1234 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001235 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001236 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001237}
1238
1239
1240sub do_env_memberdesc{
1241 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001242 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001243 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001244 $class = $THIS_CLASS
1245 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001246 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001247 $extra = " ($class attribute)"
1248 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001249 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001250 $idx =~ s/ \(.*\)//;
1251 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001252 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001253}
1254
1255
Fred Drake5ccf3301998-04-17 20:04:09 +00001256sub do_cmd_memberline{
1257 local($_) = @_;
1258 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001259 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001260 $class = $THIS_CLASS
1261 unless $class;
1262 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001263 $extra = " ($class attribute)"
1264 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001265 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001266 $idx =~ s/ \(.*\)//;
1267 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001268 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001269}
1270
Fred Drakef269e592001-07-17 23:05:57 +00001271
Fred Drake42b31a51998-03-27 05:16:10 +00001272sub do_env_memberdescni{
1273 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001274 next_optional_argument();
1275 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001276 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001277 . $_
1278 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001279}
1280
1281
Fred Drake5ccf3301998-04-17 20:04:09 +00001282sub do_cmd_memberlineni{
1283 local($_) = @_;
1284 next_optional_argument();
1285 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001286 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001287}
1288
Fred Drakef269e592001-07-17 23:05:57 +00001289
1290@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001291
Fred Drakecb199762001-08-16 21:56:24 +00001292%FontConversions = ('cdata' => 'tt class="cdata"',
1293 'character' => 'tt class="character"',
1294 'class' => 'tt class="class"',
1295 'command' => 'code',
1296 'constant' => 'tt class="constant"',
1297 'exception' => 'tt class="exception"',
1298 'file' => 'tt class="file"',
1299 'filenq' => 'tt class="file"',
1300 'kbd' => 'kbd',
1301 'member' => 'tt class="member"',
1302 'programopt' => 'b',
1303 'textrm' => '',
1304 );
1305
Fred Drakef5478632002-05-23 17:59:16 +00001306sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001307 # do a little magic on a font name to get the right behavior in the first
1308 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001309 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001310 if (defined $FontConversions{$font}) {
1311 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001312 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001313 return $font;
1314}
1315
Fred Drakef5478632002-05-23 17:59:16 +00001316sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001317 my $a = $_[0];
1318 if (!defined $a) {
1319 return '';
1320 }
Fred Drakee15956b2000-04-03 04:51:13 +00001321 my $mark = substr($a, 0, 1);
1322 my $r = '';
1323 if ($mark eq 'c')
1324 { $r = ' align="center"'; }
1325 elsif ($mark eq 'r')
1326 { $r = ' align="right"'; }
1327 elsif ($mark eq 'l')
1328 { $r = ' align="left"'; }
1329 elsif ($mark eq 'p')
1330 { $r = ' align="left"'; }
1331 return $r;
1332}
1333
Fred Drakef5478632002-05-23 17:59:16 +00001334sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001335 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001336 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001337 my $a1 = figure_column_alignment($s1);
1338 my $a2 = figure_column_alignment($s2);
1339 my $a3 = figure_column_alignment($s3);
1340 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001341 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001342 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1343 $col_aligns[1] = "<td$a2>";
1344 $col_aligns[2] = "<td$a3>";
1345 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001346 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001347 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001348 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001349}
1350
Fred Drakef5478632002-05-23 17:59:16 +00001351sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001352 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001353 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001354 if ($font) {
1355 $sfont = "<$font>";
1356 $efont = "</$font>";
1357 $efont =~ s/ .*>/>/;
1358 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001359 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001360}
1361
1362sub do_env_tableii{
1363 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001364 my $arg = next_argument();
1365 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001366 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001367 my $h1 = next_argument();
1368 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001369 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001370 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001371 my $a1 = $col_aligns[0];
1372 my $a2 = $col_aligns[1];
1373 s/\\lineii</\\lineii[$a1|$a2]</g;
1374 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001375 . "\n <thead>"
1376 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001377 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1378 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001379 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001380 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001381 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001382 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001383 . "\n </tbody>"
1384 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001385}
1386
Fred Drakeda72b932000-09-21 15:58:02 +00001387sub do_env_longtableii{
1388 return do_env_tableii(@_);
1389}
1390
Fred Drake6659c301998-03-03 22:02:19 +00001391sub do_cmd_lineii{
1392 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001393 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001394 my $c1 = next_argument();
1395 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001396 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001397 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001398 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001399 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001400 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001401 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001402 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001403 }
Fred Drakee15956b2000-04-03 04:51:13 +00001404 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1405 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001406 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001407}
1408
1409sub do_env_tableiii{
1410 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001411 my $arg = next_argument();
1412 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001413 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001414 my $h1 = next_argument();
1415 my $h2 = next_argument();
1416 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001417 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001418 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001419 my $a1 = $col_aligns[0];
1420 my $a2 = $col_aligns[1];
1421 my $a3 = $col_aligns[2];
1422 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1423 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001424 . "\n <thead>"
1425 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001426 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1427 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1428 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001429 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001430 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001431 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001432 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001433 . "\n </tbody>"
1434 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001435}
1436
Fred Drakeda72b932000-09-21 15:58:02 +00001437sub do_env_longtableiii{
1438 return do_env_tableiii(@_);
1439}
1440
Fred Drake6659c301998-03-03 22:02:19 +00001441sub do_cmd_lineiii{
1442 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001443 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001444 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001445 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001446 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001447 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001448 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001449 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001450 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001451 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001452 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001453 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001454 }
Fred Drakee15956b2000-04-03 04:51:13 +00001455 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001456 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001457 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001458 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001459}
1460
Fred Drakea0f4c941998-07-24 22:16:04 +00001461sub do_env_tableiv{
1462 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001463 my $arg = next_argument();
1464 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001465 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001466 my $h1 = next_argument();
1467 my $h2 = next_argument();
1468 my $h3 = next_argument();
1469 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001470 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001471 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001472 my $a1 = $col_aligns[0];
1473 my $a2 = $col_aligns[1];
1474 my $a3 = $col_aligns[2];
1475 my $a4 = $col_aligns[3];
1476 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1477 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001478 . "\n <thead>"
1479 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001480 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1481 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1482 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1483 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001484 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001485 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001486 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001487 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001488 . "\n </tbody>"
1489 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001490}
1491
Fred Drakeda72b932000-09-21 15:58:02 +00001492sub do_env_longtableiv{
1493 return do_env_tableiv(@_);
1494}
1495
Fred Drakea0f4c941998-07-24 22:16:04 +00001496sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001497 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001498 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001499 my $c1 = next_argument();
1500 my $c2 = next_argument();
1501 my $c3 = next_argument();
1502 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001503 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001504 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001505 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001506 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001507 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001508 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001509 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001510 }
Fred Drakee15956b2000-04-03 04:51:13 +00001511 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001512 . " $c2align$c2</td>\n"
1513 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001514 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001515 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001516}
1517
Fred Drakef269e592001-07-17 23:05:57 +00001518sub do_env_tablev{
1519 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001520 my $arg = next_argument();
1521 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001522 my $font = fix_font(next_argument());
1523 my $h1 = next_argument();
1524 my $h2 = next_argument();
1525 my $h3 = next_argument();
1526 my $h4 = next_argument();
1527 my $h5 = next_argument();
1528 s/[\s\n]+//;
1529 $globals{'lineifont'} = $font;
1530 my $a1 = $col_aligns[0];
1531 my $a2 = $col_aligns[1];
1532 my $a3 = $col_aligns[2];
1533 my $a4 = $col_aligns[3];
1534 my $a5 = $col_aligns[4];
1535 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1536 return '<table border align="center" style="border-collapse: collapse">'
1537 . "\n <thead>"
1538 . "\n <tr class=\"tableheader\">"
1539 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1540 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1541 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1542 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1543 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1544 . "\n </tr>"
1545 . "\n </thead>"
1546 . "\n <tbody valign=\"baseline\">"
1547 . $_
1548 . "\n </tbody>"
1549 . "\n</table>";
1550}
1551
1552sub do_env_longtablev{
1553 return do_env_tablev(@_);
1554}
1555
1556sub do_cmd_linev{
1557 local($_) = @_;
1558 my $aligns = next_optional_argument();
1559 my $c1 = next_argument();
1560 my $c2 = next_argument();
1561 my $c3 = next_argument();
1562 my $c4 = next_argument();
1563 my $c5 = next_argument();
1564 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001565 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001566 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001567 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001568 my $padding = '';
1569 if ($c1align =~ /align="right"/ || $c1 eq '') {
1570 $padding = '&nbsp;';
1571 }
1572 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1573 . " $c2align$c2</td>\n"
1574 . " $c3align$c3</td>\n"
1575 . " $c4align$c4</td>\n"
1576 . " $c5align$c5</td>"
1577 . $_;
1578}
1579
Fred Drake3be20742000-08-31 06:22:54 +00001580
1581# These can be used to control the title page appearance;
1582# they need a little bit of documentation.
1583#
1584# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1585# $ICONSERVER directory, or include path information (other than "./"). The
1586# default image type will be assumed if an extension is not provided.
1587#
1588# If specified, the "title page" will contain two colums: one containing the
1589# title/author/etc., and the other containing the graphic. Use the other
1590# four variables listed here to control specific details of the layout; all
1591# are optional.
1592#
1593# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1594# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1595# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1596# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1597# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1598
Fred Drakef5478632002-05-23 17:59:16 +00001599sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001600 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001601 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001602 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001603 }
1604 else {
1605 write_warnings("\nThis document has no title.");
1606 }
Fred Drake6659c301998-03-03 22:02:19 +00001607 if ($t_author) {
1608 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001609 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001610 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001611 "<b><font size=\"+2\">$t_author"
1612 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001613 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001614 }
1615 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001616 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1617 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001618 }
Fred Drake3be20742000-08-31 06:22:54 +00001619 }
1620 else {
1621 write_warnings("\nThere is no author for this document.");
1622 }
Fred Drake6659c301998-03-03 22:02:19 +00001623 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001624 $the_title .= "\n<p>$t_institute</p>";
1625 }
Fred Draked07868a1998-05-14 21:00:28 +00001626 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001627 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1628 }
Fred Drake6659c301998-03-03 22:02:19 +00001629 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001630 $the_title .= "\n<p><i>$t_affil</i></p>";
1631 }
Fred Drake6659c301998-03-03 22:02:19 +00001632 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001633 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001634 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001635 $the_title .= ('<strong>Release '
1636 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001637 }
Fred Drakede77bc52000-12-14 18:36:12 +00001638 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001639 }
1640 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001641 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001642 }
1643 else {
1644 $the_title .= "\n<p>";
1645 }
Fred Drake6659c301998-03-03 22:02:19 +00001646 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001647 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001648 }
1649 return $the_title;
1650}
1651
Fred Drakef5478632002-05-23 17:59:16 +00001652sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001653 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001654 my $graphic = "<td class=\"titlegraphic\"";
1655 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1656 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1657 $graphic .= "><img";
1658 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1659 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1660 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1661 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001662 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001663 return $graphic;
1664}
1665
Fred Drakef5478632002-05-23 17:59:16 +00001666sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001667 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001668 my $the_title = "\n";
1669 if ($EXTERNAL_UP_LINK) {
1670 # This generates a <LINK> element in the wrong place (the
1671 # body), but I don't see any other way to get this generated
1672 # at all. Browsers like Mozilla, that support navigation
1673 # links, can make use of this.
1674 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1675 . ($EXTERNAL_UP_TITLE
1676 ? " title='$EXTERNAL_UP_TITLE'" : '')
1677 . ">\n");
1678 }
1679 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001680 if ($TITLE_PAGE_GRAPHIC) {
1681 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1682 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1683 . "<tr align=\"right\">\n<td>"
1684 . make_my_titlepage()
1685 . "</td>\n"
1686 . make_my_titlegraphic()
1687 . "</tr>\n</table>");
1688 }
1689 else {
1690 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1691 . make_my_titlegraphic()
1692 . "<td>"
1693 . make_my_titlepage()
1694 . "</td></tr>\n</table>");
1695 }
1696 }
1697 else {
1698 $the_title .= ("\n<center>"
1699 . make_my_titlepage()
1700 . "\n</center>");
1701 }
1702 $the_title .= "\n</div>";
1703 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001704 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001705 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001706}
1707
1708
Fred Drake885215c1998-05-20 21:32:09 +00001709#
Fred Drakea0f4c941998-07-24 22:16:04 +00001710# Module synopsis support
1711#
1712
1713require SynopsisTable;
1714
Fred Drakef7685d71998-07-25 03:31:46 +00001715sub get_chapter_id(){
1716 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001717 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001718 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001719 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001720}
1721
Fred Drake643d76d2000-09-09 06:07:37 +00001722# 'chapter' => 'SynopsisTable instance'
1723%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001724
1725sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001726 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001727 my $key;
1728 foreach $key (keys %ModuleSynopses) {
1729 if ($key eq $chap) {
1730 return $ModuleSynopses{$chap};
1731 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001732 }
Fred Drake643d76d2000-09-09 06:07:37 +00001733 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001734 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001735 return $st;
1736}
1737
Fred Drake62e43691998-08-10 19:40:44 +00001738sub do_cmd_moduleauthor{
1739 local($_) = @_;
1740 next_argument();
1741 next_argument();
1742 return $_;
1743}
1744
1745sub do_cmd_sectionauthor{
1746 local($_) = @_;
1747 next_argument();
1748 next_argument();
1749 return $_;
1750}
1751
Fred Drakea0f4c941998-07-24 22:16:04 +00001752sub do_cmd_declaremodule{
1753 local($_) = @_;
1754 my $key = next_optional_argument();
1755 my $type = next_argument();
1756 my $name = next_argument();
1757 my $st = get_synopsis_table(get_chapter_id());
1758 #
1759 $key = $name unless $key;
1760 $type = 'built-in' if $type eq 'builtin';
1761 $st->declare($name, $key, $type);
1762 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001763 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001764}
1765
1766sub do_cmd_modulesynopsis{
1767 local($_) = @_;
1768 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001769 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001770 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001771}
1772
1773sub do_cmd_localmoduletable{
1774 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001775 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001776 my $st = get_synopsis_table($chap);
1777 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001778 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001779}
1780
Fred Drakef5478632002-05-23 17:59:16 +00001781sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001782 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001783 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001784 my $st = $ModuleSynopses{$key};
1785 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001786 if ($file) {
1787 process_localmoduletables_in_file($file);
1788 }
1789 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001790 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001791 }
1792 }
1793}
1794
Fred Drakef5478632002-05-23 17:59:16 +00001795sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001796 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001797 open(MYFILE, "<$file");
1798 local($_);
1799 sysread(MYFILE, $_, 1024*1024);
1800 close(MYFILE);
1801 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001802 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001803 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001804 my $chap = $1;
1805 my $st = get_synopsis_table($chap);
1806 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001807 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001808 }
Fred Drake643d76d2000-09-09 06:07:37 +00001809 open(MYFILE,">$file");
1810 print MYFILE $_;
1811 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001812}
Fred Drakef5478632002-05-23 17:59:16 +00001813sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001814 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001815 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001816}
Fred Drakea0f4c941998-07-24 22:16:04 +00001817
1818
1819#
1820# "See also:" -- references placed at the end of a \section
1821#
1822
1823sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001824 return ("<div class=\"seealso\">\n "
1825 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001826 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001827 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001828}
1829
Fred Drake5ed35fd2001-11-30 18:09:54 +00001830sub do_env_seealsostar{
1831 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001832 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001833 . '</div>');
1834}
1835
Fred Drakea0f4c941998-07-24 22:16:04 +00001836sub do_cmd_seemodule{
1837 # Insert the right magic to jump to the module definition. This should
1838 # work most of the time, at least for repeat builds....
1839 local($_) = @_;
1840 my $key = next_optional_argument();
1841 my $module = next_argument();
1842 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001843 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001844 $key = $module
1845 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001846 if ($text =~ /\.$/) {
1847 $period = '';
1848 }
Fred Drakef1927a62001-06-20 21:29:30 +00001849 return ('<dl compact class="seemodule">'
1850 . "\n <dt>Module <b><tt class=\"module\">"
1851 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1852 . "\n <dd>$text$period\n </dl>"
1853 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001854}
1855
Fred Drakee0197bf2001-04-12 04:03:22 +00001856sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001857 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001858 my $s = "$str";
1859 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1860 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1861 return $s;
1862}
1863
Fred Drakef5478632002-05-23 17:59:16 +00001864sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001865 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001866 my $rfcnum = next_argument();
1867 my $title = next_argument();
1868 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001869 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001870 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001871 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001872 return '<dl compact class="seerfc">'
1873 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001874 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001875 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001876 . "\n <dd>$text\n </dl>"
1877 . $_;
1878}
1879
Fred Drake643d76d2000-09-09 06:07:37 +00001880sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001881 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001882}
1883
1884sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001885 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001886 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001887}
1888
Fred Drake48449982000-09-12 17:52:33 +00001889sub do_cmd_seetitle{
1890 local($_) = @_;
1891 my $url = next_optional_argument();
1892 my $title = next_argument();
1893 my $text = next_argument();
1894 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001895 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001896 return '<dl compact class="seetitle">'
1897 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001898 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001899 . "\n <dd>$text\n </dl>"
1900 . $_;
1901 }
1902 return '<dl compact class="seetitle">'
1903 . "\n <dt><em class=\"citetitle\""
1904 . "\n >$title</em>"
1905 . "\n <dd>$text\n </dl>"
1906 . $_;
1907}
1908
Fred Drakeef4d1112000-05-09 16:17:51 +00001909sub do_cmd_seeurl{
1910 local($_) = @_;
1911 my $url = next_argument();
1912 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001913 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001914 return '<dl compact class="seeurl">'
1915 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001916 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001917 . "\n <dd>$text\n </dl>"
1918 . $_;
1919}
1920
Fred Drakea0f4c941998-07-24 22:16:04 +00001921sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001922 local($_) = @_;
1923 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001924 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001925}
1926
1927
1928#
Fred Drake885215c1998-05-20 21:32:09 +00001929# Definition list support.
1930#
1931
1932sub do_env_definitions{
Fred Drake49b33fa2002-11-15 19:04:10 +00001933 return "<dl class=\"definitions\">" . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001934}
1935
1936sub do_cmd_term{
1937 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001938 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001939 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001940 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001941 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001942}
1943
1944
Fred Drake38178fd2000-09-22 17:05:04 +00001945# I don't recall exactly why this was needed, but it was very much needed.
1946# We'll see if anything breaks when I move the "code" line out -- some
1947# things broke with it in.
1948
1949#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001950process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001951declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001952funcline # {} # {}
1953funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001954memberline # [] # {}
1955methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001956methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001957modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001958platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001959samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001960setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001961withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001962_RAW_ARG_DEFERRED_CMDS_
1963
1964
Fred Drake8a5e6792002-04-15 18:41:31 +00001965$alltt_start = '<div class="verbatim"><pre>';
1966$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001967
Fred Drakef5478632002-05-23 17:59:16 +00001968sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001969 local ($_) = @_;
1970 local($closures,$reopens,@open_block_tags);
1971
1972 # get the tag-strings for all open tags
1973 local(@keep_open_tags) = @$open_tags_R;
1974 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1975
1976 # get the tags for text-level tags only
1977 $open_tags_R = [ @keep_open_tags ];
1978 local($local_closures, $local_reopens);
1979 ($local_closures, $local_reopens,@open_block_tags)
1980 = &preserve_open_block_tags
1981 if (@$open_tags_R);
1982
1983 $open_tags_R = [ @open_block_tags ];
1984
1985 do {
1986 local($open_tags_R) = [ @open_block_tags ];
1987 local(@save_open_tags) = ();
1988
1989 local($cnt) = ++$global{'max_id'};
1990 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1991 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1992
1993 $_ = &translate_environments($_);
1994 $_ = &translate_commands($_) if (/\\/);
1995
1996 # preserve space-runs, using &nbsp;
1997 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1998 s/(<BR>) /$1;SPMnbsp;/g;
1999
2000 $_ = join('', $closures, $alltt_start, $local_reopens
2001 , $_
2002 , &balance_tags() #, $local_closures
2003 , $alltt_end, $reopens);
2004 undef $open_tags_R; undef @save_open_tags;
2005 };
2006 $open_tags_R = [ @keep_open_tags ];
2007 $_;
2008}
2009
Fred Drake6fc22f62002-06-17 15:01:05 +00002010# List of all filenames produced ny do_cmd_verbatiminput()
2011%VerbatimFiles = ();
2012@VerbatimOutputs = ();
2013
2014sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002015 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002016 #
2017 # Re-write the source filename to always use a .txt extension
2018 # so that Web servers will present it as text/plain. This is
2019 # needed since there is no other even moderately reliable way
2020 # to get the right Content-Type header on text files for
2021 # servers which we can't configure (like python.org mirrors).
2022 #
2023 if (defined $VerbatimFiles{$file}) {
2024 # We've seen this one before; re-use the same output file.
2025 return $VerbatimFiles{$file};
2026 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002027 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002028 $filename = "$srcname.txt";
2029 #
2030 # We need to determine if our default filename is already
2031 # being used, and find a new one it it is. If the name is in
2032 # used, this algorithm will first attempt to include the
2033 # source extension as part of the name, and if that is also in
2034 # use (if the same file is included multiple times, or if
2035 # another source file has that as the base name), a counter is
2036 # used instead.
2037 #
2038 my $found = 1;
2039 FIND:
2040 while ($found) {
2041 foreach $fn (@VerbatimOutputs) {
2042 if ($fn eq $filename) {
2043 if ($found == 1) {
2044 $srcext =~ s/^[.]//; # Remove '.' from extension
2045 $filename = "$srcname-$srcext.txt";
2046 }
2047 else {
2048 $filename = "$srcname-$found.txt";
2049 }
2050 ++$found;
2051 next FIND;
2052 }
2053 }
2054 $found = 0;
2055 }
2056 push @VerbatimOutputs, $filename;
2057 $VerbatimFiles{$file} = $filename;
2058 return $filename;
2059}
2060
Fred Drake57e52ef2001-06-15 21:31:57 +00002061sub do_cmd_verbatiminput{
2062 local($_) = @_;
2063 my $fname = next_argument();
2064 my $file;
2065 my $found = 0;
2066 my $texpath;
2067 # Search TEXINPUTS for the input file, the way we're supposed to:
2068 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2069 $file = "$texpath$dd$fname";
2070 last if ($found = (-f $file));
2071 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002072 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002073 my $text;
2074 if ($found) {
2075 open(MYFILE, "<$file") || die "\n$!\n";
2076 read(MYFILE, $text, 1024*1024);
2077 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002078 $filename = get_verbatim_output_name($file);
2079 # Now that we have a filename, write it out.
2080 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002081 print MYFILE $text;
2082 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002083 #
2084 # These rewrites convert the raw text to something that will
2085 # be properly visible as HTML and also will pass through the
2086 # vagaries of conversion through LaTeX2HTML. The order in
2087 # which the specific rewrites are performed is significant.
2088 #
2089 $text =~ s/\&/\&amp;/g;
2090 # These need to happen before the normal < and > re-writes,
2091 # since we need to avoid LaTeX2HTML's attempt to perform
2092 # ligature processing without regard to context (since it
2093 # doesn't have font information).
2094 $text =~ s/--/-&\#45;/g;
2095 $text =~ s/<</\&lt;\&\#60;/g;
2096 $text =~ s/>>/\&gt;\&\#62;/g;
2097 # Just normal re-writes...
2098 $text =~ s/</\&lt;/g;
2099 $text =~ s/>/\&gt;/g;
2100 # These last isn't needed for the HTML, but is needed to get
2101 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2102 # of &sol; since many browsers don't support that.
2103 $text =~ s/\\/\&\#92;/g;
2104 }
2105 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002106 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2107 }
2108 my $note = 'Download as text.';
2109 if ($file ne $filename) {
2110 $note = ('Download as text (original file name: <span class="file">'
2111 . $fname
2112 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002113 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002114 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002115 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002116 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002117 . "<a href=\"$filename\" type=\"text/plain\""
2118 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002119 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002120 . $_);
2121}
Fred Drake86333602001-04-10 17:13:39 +00002122
Fred Drake6659c301998-03-03 22:02:19 +000021231; # This must be the last line