blob: a0b4551e6dcce3fbc2f24a59d0eca04996163e0c [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]; }
Fred Drake7898ccd2003-07-08 15:57:52 +000092sub do_cmd_texteuro { '&#8364;' . $_[0]); }
Fred Drake49b33fa2002-11-15 19:04:10 +000093sub do_cmd_textgreater{ '&gt;' . $_[0]; }
94sub do_cmd_textless{ '&lt;' . $_[0]; }
95sub do_cmd_textunderscore{ '_' . $_[0]; }
96sub do_cmd_infinity{ '&infin;' . $_[0]; }
97sub do_cmd_plusminus{ '&plusmn;' . $_[0]; }
98sub do_cmd_menuselection{ $_[0]; }
99sub do_cmd_sub{ ' > ' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +0000100
101
Fred Drake6659c301998-03-03 22:02:19 +0000102# words typeset in a special way (not in HTML though)
103
Fred Drake49b33fa2002-11-15 19:04:10 +0000104sub do_cmd_ABC{ 'ABC' . $_[0]; }
Fred Drake5bbeb8d2003-02-04 15:01:37 +0000105sub do_cmd_UNIX{ '<font style="font-variant: small-caps;">Unix</font>'
106 . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000107sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
108sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
109sub do_cmd_C{ 'C' . $_[0]; }
110sub do_cmd_Cpp{ 'C++' . $_[0]; }
111sub do_cmd_EOF{ 'EOF' . $_[0]; }
112sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000113
Fred Drake49b33fa2002-11-15 19:04:10 +0000114sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000115
Fred Draked07868a1998-05-14 21:00:28 +0000116$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000117$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000118$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000119$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000120
Fred Drake49b33fa2002-11-15 19:04:10 +0000121sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
122sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000123sub do_cmd_release{
124 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000125 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000126 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000127}
128
Fred Drakef1927a62001-06-20 21:29:30 +0000129sub do_cmd_setreleaseinfo{
130 local($_) = @_;
131 $RELEASE_INFO = next_argument();
132 return $_;
133}
134
Fred Drake3cdb89d2000-09-14 20:17:23 +0000135sub do_cmd_setshortversion{
136 local($_) = @_;
137 $SHORT_VERSION = next_argument();
138 return $_;
139}
140
Fred Drake6659c301998-03-03 22:02:19 +0000141sub do_cmd_authoraddress{
142 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000143 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000144 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000145}
146
Fred Drake49b33fa2002-11-15 19:04:10 +0000147#sub do_cmd_developer{ do_cmd_author($_[0]); }
148#sub do_cmd_developers{ do_cmd_author($_[0]); }
149#sub do_cmd_developersaddress{ do_cmd_authoraddress($_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000150
Fred Drake6659c301998-03-03 22:02:19 +0000151sub do_cmd_hackscore{
152 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000153 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000154 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000155}
156
Fred Drakef5478632002-05-23 17:59:16 +0000157sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000158 local($_,$before,$after) = @_;
159 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000160 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000161}
162
Fred Drake3cdb89d2000-09-14 20:17:23 +0000163$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000164sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000165 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000166 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000167 "</var><big>\]</big><var>");
168 }
169 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000170 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000171 }
Fred Drake6659c301998-03-03 22:02:19 +0000172}
173
Fred Drakec9a44381998-03-17 06:29:13 +0000174# Logical formatting (some based on texinfo), needs to be converted to
175# minimalist HTML. The "minimalist" is primarily to reduce the size of
176# output files for users that read them over the network rather than
177# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000178
Fred Drake49b33fa2002-11-15 19:04:10 +0000179sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000180sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000181 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000182sub do_cmd_code{
Fred Drake49b33fa2002-11-15 19:04:10 +0000183 return use_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000185 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000186sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000187 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000188sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000189 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000191 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000193 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000194sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000195 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000197 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000199 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000201 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000203 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000205 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_regexp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000207 return use_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000208sub do_cmd_character{
Fred Drake49b33fa2002-11-15 19:04:10 +0000209 return use_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000210sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000211 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000212sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000213 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000214sub do_cmd_longprogramopt{
215 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000216 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000218 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000219sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000220 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000221sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000222 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000224 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000226 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000227sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000228 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000229sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000230 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000231sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000232 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000233sub do_cmd_samp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000234 return use_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000235sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000236 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000237sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000238 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000239sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000240 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000241sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000242 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000243# This can be changed/overridden for translations:
244%NoticeNames = ('note' => 'Note:',
245 'warning' => 'Warning:',
246 );
247
Fred Drake92350b32001-10-09 18:01:23 +0000248sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000249 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000250 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000251 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000252 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000253 '</span>'); }
254sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000255 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000256 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000257 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000258 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000259 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000260
Fred Drake6ca33772001-12-14 22:50:06 +0000261sub do_env_notice{
262 local($_) = @_;
263 my $notice = next_optional_argument();
264 if (!$notice) {
265 $notice = 'note';
266 }
267 my $label = $NoticeNames{$notice};
268 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
269 . $_
270 . '</div>');
271}
272
Fred Drake3d5a04a2000-08-03 17:25:44 +0000273sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000274 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000275sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000276 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000277
Fred Drakec9a44381998-03-17 06:29:13 +0000278
Fred Drake25817041999-01-13 17:06:34 +0000279sub do_cmd_refmodule{
280 # Insert the right magic to jump to the module definition.
281 local($_) = @_;
282 my $key = next_optional_argument();
283 my $module = next_argument();
284 $key = $module
285 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000286 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000287 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000288}
289
Fred Drake1a7af391998-04-01 22:44:56 +0000290sub do_cmd_newsgroup{
291 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000292 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000293 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000294 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
295 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000296 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000297}
Fred Drakefc16e781998-03-12 21:03:26 +0000298
299sub do_cmd_envvar{
300 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000301 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000302 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000303 # The <tt> here is really to keep buildindex.py from making
304 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000305 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000306 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000307 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000308 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000309 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000310}
311
Fred Drake6659c301998-03-03 22:02:19 +0000312sub do_cmd_url{
313 # use the URL as both text and hyperlink
314 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000315 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000316 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000317 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000318 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000319}
320
321sub do_cmd_manpage{
322 # two parameters: \manpage{name}{section}
323 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000324 my $page = next_argument();
325 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000326 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000327}
328
Fred Drakedbfe7682002-04-03 02:47:14 +0000329$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000330#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
331$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000332
333sub get_rfc_url($$){
334 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000335 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000336}
337
338sub do_cmd_pep{
339 local($_) = @_;
340 my $rfcnumber = next_argument();
341 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000342 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000343 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000344 # Save the reference
345 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
346 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000347 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
348 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000349}
350
Fred Drake6659c301998-03-03 22:02:19 +0000351sub do_cmd_rfc{
352 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000353 my $rfcnumber = next_argument();
354 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000355 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000356 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000357 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000358 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000359 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000360 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
361 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000362}
363
Fred Drake77602f22001-07-06 22:43:02 +0000364sub do_cmd_ulink{
365 local($_) = @_;
366 my $text = next_argument();
367 my $url = next_argument();
368 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
369}
370
Fred Drakec9f5fe01999-11-09 16:59:42 +0000371sub do_cmd_citetitle{
372 local($_) = @_;
373 my $url = next_optional_argument();
374 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000375 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000376 my $repl = '';
377 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000378 $repl = ("<em class=\"citetitle\"><a\n"
379 . " href=\"$url\"\n"
380 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000381 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000382 }
383 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000384 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000385 }
386 return $repl . $_;
387}
388
Fred Drake6659c301998-03-03 22:02:19 +0000389sub do_cmd_deprecated{
390 # two parameters: \deprecated{version}{whattodo}
391 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000392 my $release = next_argument();
393 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000394 return ('<div class="versionnote">'
395 . "<b>Deprecated since release $release.</b>"
396 . "\n$reason</div><p>"
397 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000398}
399
Fred Drakef5478632002-05-23 17:59:16 +0000400sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000401 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000402 my $type = $_[0];
403 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000404 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000405 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000406 my $text = "$type in version $release.";
407 if ($explanation) {
408 $text = "$type in version $release:\n$explanation.";
409 }
Fred Drakef1927a62001-06-20 21:29:30 +0000410 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000411}
412
413sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000414 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000415}
416
417sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000418 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000419}
420
Fred Drake557460c1999-03-02 16:05:35 +0000421#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000422# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000423#
424sub do_cmd_platform{
425 local($_) = @_;
426 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000427 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000428 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000429 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000430 return "\n<p class=\"availability\">Availability: <span"
431 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000432}
433
Fred Drake557460c1999-03-02 16:05:35 +0000434$IGNORE_PLATFORM_ANNOTATION = '';
435sub do_cmd_ignorePlatformAnnotation{
436 local($_) = @_;
437 $IGNORE_PLATFORM_ANNOTATION = next_argument();
438 return $_;
439}
440
Fred Drake6659c301998-03-03 22:02:19 +0000441
442# index commands
443
444$INDEX_SUBITEM = "";
445
Fred Drakef5478632002-05-23 17:59:16 +0000446sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000447 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000448}
449
450sub do_cmd_setindexsubitem{
451 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000452 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000453 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000454}
455
Fred Drakefc16e781998-03-12 21:03:26 +0000456sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000457 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000458 # do things in the right order, but we need to at least strip this stuff
459 # out, and leave anything that the second argument expanded out to.
460 #
461 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000462 my $oldsubitem = $INDEX_SUBITEM;
463 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000464 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000465 my $br_id = ++$globals{'max_id'};
466 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000467 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000468 return
469 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000470 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000471 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000472}
473
Fred Drake08932051998-04-17 02:15:42 +0000474# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000475# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
476# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000477#
Fred Drake49b33fa2002-11-15 19:04:10 +0000478sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000479
Fred Drake42b31a51998-03-27 05:16:10 +0000480# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000481#
Fred Drake08932051998-04-17 02:15:42 +0000482open(IDXFILE, '>index.dat') || die "\n$!\n";
483open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000484print INTLABELS "%internal_labels = ();\n";
485print INTLABELS "1; # hack in case there are no entries\n\n";
486
487# Using \0 for this is bad because we can't use common tools to work with the
488# resulting files. Things like grep can be useful with this stuff!
489#
490$IDXFILE_FIELD_SEP = "\1";
491
Fred Drakef5478632002-05-23 17:59:16 +0000492sub write_idxfile($$){
493 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000494 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000495}
496
Fred Drake42b31a51998-03-27 05:16:10 +0000497
Fred Drakef5478632002-05-23 17:59:16 +0000498sub gen_link($$){
499 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000500 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000501 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000502}
503
Fred Drakef5478632002-05-23 17:59:16 +0000504sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000505 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000506 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000507 $str = gen_index_id($str, '');
508 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000509 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000510}
511
Fred Drakef5478632002-05-23 17:59:16 +0000512sub new_link_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000513 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000514 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000515 my $ahref = gen_link($CURRENT_FILE, $name);
516 return ($name, $aname, $ahref);
517}
518
Fred Drakeab032151999-05-13 18:36:54 +0000519$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000520sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000521 my $count = @_;
522 my $i = 0;
523 for (; $i < $count; ++$i) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000524 my $name = $_[$i];
Fred Drakeab032151999-05-13 18:36:54 +0000525 my $cmd = "idx_cmd_$name";
526 die "\nNo function $cmd() defined!\n"
527 if (!defined &$cmd);
528 eval ("sub do_cmd_$name { return process_index_macros("
Fred Drake49b33fa2002-11-15 19:04:10 +0000529 . "\$_[0], '$name'); }");
Fred Drakeab032151999-05-13 18:36:54 +0000530 if (length($IndexMacroPattern) == 0) {
531 $IndexMacroPattern = "$name";
532 }
533 else {
534 $IndexMacroPattern .= "|$name";
535 }
536 }
537}
538
539$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000540sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000541 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000542 my $cmdname = $_[1]; # This is what triggered us in the first place;
Fred Drakeab032151999-05-13 18:36:54 +0000543 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000544 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000545 my $cmd = "idx_cmd_$cmdname";
546 print "\nIndexing: \\$cmdname"
547 if $DEBUG_INDEXING;
548 &$cmd($ahref); # modifies $_ and adds index entries
549 while (/^[\s\n]*\\($IndexMacroPattern)</) {
550 $cmdname = "$1";
551 print " \\$cmdname"
552 if $DEBUG_INDEXING;
553 $cmd = "idx_cmd_$cmdname";
554 if (!defined &$cmd) {
555 last;
556 }
557 else {
558 s/^[\s\n]*\\$cmdname//;
559 &$cmd($ahref);
560 }
561 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000562 if (/^[ \t\r\n]/) {
563 $_ = substr($_, 1);
564 }
Fred Drake62e43691998-08-10 19:40:44 +0000565 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000566}
567
Fred Drakeab032151999-05-13 18:36:54 +0000568define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000569sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000570 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000571 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000572}
573
Fred Drakeab032151999-05-13 18:36:54 +0000574define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000575sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000576 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000577 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
578 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000579}
580
581define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000582sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000583 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000584 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000585 add_index_entry("$str1!$str2", $_[0]);
586 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000587}
588
Fred Drakeab032151999-05-13 18:36:54 +0000589define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000590sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000591 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000592 my $str2 = next_argument();
593 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000594 add_index_entry("$str1!$str2 $str3", $_[0]);
595 add_index_entry("$str2!$str3, $str1", $_[0]);
596 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000597}
598
Fred Drakeab032151999-05-13 18:36:54 +0000599define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000600sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000601 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000602 my $str2 = next_argument();
603 my $str3 = next_argument();
604 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000605 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
606 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
607 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
608 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000609}
610
Fred Drakeab032151999-05-13 18:36:54 +0000611define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000612sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000613 my $str = next_argument();
614 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000615 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000616}
Fred Drake6659c301998-03-03 22:02:19 +0000617
Fred Drakef5478632002-05-23 17:59:16 +0000618sub my_typed_index_helper($$){
619 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000620 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000621 add_index_entry("$str $word", $ahref);
622 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000623}
624
Fred Drakeab032151999-05-13 18:36:54 +0000625define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000626sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
627sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
628sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
629sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000630
Fred Drakeab032151999-05-13 18:36:54 +0000631define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000632sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000633 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000634 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000635 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000636}
637
638
Fred Drakef5478632002-05-23 17:59:16 +0000639sub make_mod_index_entry($$){
640 my($str, $define) = @_;
641 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000642 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000643 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
644 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000645 $str = gen_index_id($str, $define);
646 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000647 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000648
Fred Drakec9a44381998-03-17 06:29:13 +0000649 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000650 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000651 $str =~ /(<tt.*<\/tt>)/;
652 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000653 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000654 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000655 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000656}
657
Fred Drake557460c1999-03-02 16:05:35 +0000658
Fred Drakec9a44381998-03-17 06:29:13 +0000659$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000660$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000661
Fred Drakef5478632002-05-23 17:59:16 +0000662sub define_module($$){
663 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000664 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000665 if ($word ne "built-in" && $word ne "extension"
666 && $word ne "standard" && $word ne "") {
667 write_warnings("Bad module type '$word'"
668 . " for \\declaremodule (module $name)");
669 $word = "";
670 }
Fred Drake6659c301998-03-03 22:02:19 +0000671 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000672 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000673 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000674 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000675 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000676 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000677}
678
Fred Drakef5478632002-05-23 17:59:16 +0000679sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000680 local($word, $_) = @_;
681 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000682 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000683}
684
Fred Drake49b33fa2002-11-15 19:04:10 +0000685sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
686sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
687sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
688sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
689# local($_) = @_;
690# my $name = next_argument();
691# return define_module('standard', $name) . $_;
692# }
Fred Drake6659c301998-03-03 22:02:19 +0000693
Fred Drakef5478632002-05-23 17:59:16 +0000694sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000695 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000696 my $str = next_argument();
697 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000698 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000699 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
700 # just inline it all here
701 $str = gen_index_id($str, 'REF');
702 $index{$str} .= $ahref;
703 write_idxfile($ahref, $str);
704}
705
Fred Drake6659c301998-03-03 22:02:19 +0000706# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000707define_indexing_macro('refmodindex', 'refbimodindex',
708 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000709sub idx_cmd_refmodindex($){
710 return ref_module_index_helper('', $_[0]); }
711sub idx_cmd_refbimodindex($){
712 return ref_module_index_helper('built-in', $_[0]); }
713sub idx_cmd_refexmodindex($){
714 return ref_module_index_helper('extension', $_[0]);}
715sub idx_cmd_refstmodindex($){
716 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000717
Fred Drake49b33fa2002-11-15 19:04:10 +0000718sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000719
Fred Drakef5478632002-05-23 17:59:16 +0000720sub init_myformat(){
Fred Drakeafc7ce12001-01-22 17:33:24 +0000721 $anchor_invisible_mark = '&nbsp;';
722 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000723 $anchor_mark = '';
724 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000725}
Fred Drake42b31a51998-03-27 05:16:10 +0000726init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000727
Fred Drakeab032151999-05-13 18:36:54 +0000728# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000729# instead of the dummy filler.
730#
Fred Drakef5478632002-05-23 17:59:16 +0000731sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000732 my $str = $_[0];
Fred Drakef5478632002-05-23 17:59:16 +0000733 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000734 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000735 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000736}
737
Fred Drake77602f22001-07-06 22:43:02 +0000738
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000739%TokenToTargetMapping = (); # language:token -> link target
740%DefinedGrammars = (); # language -> full grammar text
741%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000742
743sub do_cmd_token{
744 local($_) = @_;
745 my $token = next_argument();
746 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
747 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
748 # recursive definition or display-only productionlist
749 return "$token";
750 }
751 if ($target eq '') {
752 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
753 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
754 print "Adding '$CURRENT_FILE' to back-patch list.\n";
755 }
756 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
757 }
758 return "<a href=\"$target\">$token</a>" . $_;
759}
760
Fred Drake16bb4192001-08-20 21:36:38 +0000761sub do_cmd_grammartoken{
762 return do_cmd_token(@_);
763}
764
Fred Drake77602f22001-07-06 22:43:02 +0000765sub do_env_productionlist{
766 local($_) = @_;
767 my $lang = next_optional_argument();
768 my $filename = "grammar-$lang.txt";
769 if ($lang eq '') {
770 $filename = 'grammar.txt';
771 }
772 local($CURRENT_GRAMMAR) = $lang;
773 $DefinedGrammars{$lang} .= $_;
774 return ("<dl><dd class=\"grammar\">\n"
775 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000776 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000777 . translate_commands(translate_environments($_))
778 . "</table>\n"
779 . "</div>\n"
780 . (($lang eq '*')
781 ? ''
782 : ("<a class=\"grammar-footer\"\n"
783 . " href=\"$filename\" type=\"text/plain\"\n"
784 . " >Download entire grammar as text.</a>\n"))
785 . "</dd></dl>");
786}
787
788sub do_cmd_production{
789 local($_) = @_;
790 my $token = next_argument();
791 my $defn = next_argument();
792 my $lang = $CURRENT_GRAMMAR;
793 local($CURRENT_TOKEN) = $token;
794 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000795 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000796 . " <td><code>$token</code></td>\n"
797 . " <td>&nbsp;::=&nbsp;</td>\n"
798 . " <td><code>"
799 . translate_commands($defn)
800 . "</code></td></tr>"
801 . $_);
802 }
803 my $target;
804 if ($lang eq '') {
805 $target = "$CURRENT_FILE\#tok-$token";
806 }
807 else {
808 $target = "$CURRENT_FILE\#tok-$lang-$token";
809 }
810 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000811 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000812 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
813 . " <td>&nbsp;::=&nbsp;</td>\n"
814 . " <td><code>"
815 . translate_commands($defn)
816 . "</code></td></tr>"
817 . $_);
818}
819
Fred Drake53815882002-03-15 23:21:37 +0000820sub do_cmd_productioncont{
821 local($_) = @_;
822 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000823 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000824 return ("<tr valign=\"baseline\">\n"
825 . " <td>&nbsp;</td>\n"
826 . " <td>&nbsp;</td>\n"
827 . " <td><code>"
828 . translate_commands($defn)
829 . "</code></td></tr>"
830 . $_);
831}
832
Fred Drakef5478632002-05-23 17:59:16 +0000833sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000834 my $lang;
835 my $filename;
836 local($_);
837 print "process_grammar_files()\n";
838 foreach $lang (keys %DefinedGrammars) {
839 $filename = "grammar-$lang.txt";
840 if ($lang eq '*') {
841 next;
842 }
843 if ($lang eq '') {
844 $filename = 'grammar.txt';
845 }
846 open(GRAMMAR, ">$filename") || die "\n$!\n";
847 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
848 close(GRAMMAR);
849 print "Wrote grammar file $filename\n";
850 }
851 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
852 foreach $filename (keys %BackpatchGrammarFiles) {
853 print "\nBack-patching grammar links in $filename\n";
854 my $buffer;
855 open(GRAMMAR, "<$filename") || die "\n$!\n";
856 # read all of the file into the buffer
857 sysread(GRAMMAR, $buffer, 1024*1024);
858 close(GRAMMAR);
859 while ($buffer =~ /$PATTERN/) {
860 my($lang, $token) = ($1, $2);
861 my $target = $TokenToTargetMapping{"$lang:$token"};
862 my $source = "<pyGrammarToken><$lang><$token>";
863 $buffer =~ s/$source/$target/g;
864 }
865 open(GRAMMAR, ">$filename") || die "\n$!\n";
866 print GRAMMAR $buffer;
867 close(GRAMMAR);
868 }
869}
870
Fred Drakef5478632002-05-23 17:59:16 +0000871sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000872 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000873 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000874 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
875 s/\\token(<<\d+>>)(.+)\1/$2/g;
876 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000877 s/<<\d+>>//g;
878 s/;SPMgt;/>/g;
879 s/;SPMlt;/</g;
880 s/;SPMquot;/\"/g;
881 return $_;
882}
883
884
Fred Drakee15956b2000-04-03 04:51:13 +0000885$REFCOUNTS_LOADED = 0;
886
Fred Drakef5478632002-05-23 17:59:16 +0000887sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000888 $REFCOUNTS_LOADED = 1;
889
Fred Drake49b33fa2002-11-15 19:04:10 +0000890 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drakee15956b2000-04-03 04:51:13 +0000891 chop $mydir; # remove trailing '/'
892 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
893 chop $mydir; # remove trailing '/'
894 $mydir = getcwd() . "$dd$mydir"
895 unless $mydir =~ s|^/|/|;
896 local $_;
897 my $filename = "$mydir${dd}api${dd}refcounts.dat";
898 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
899 print "[loading API refcount data]";
900 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000901 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000902 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
903 #print "\n$func($param) --> $count";
904 $REFCOUNTS{"$func:$param"} = $count;
905 }
906 }
907}
908
Fred Drakef5478632002-05-23 17:59:16 +0000909sub get_refcount($$){
910 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000911 load_refcounts()
912 unless $REFCOUNTS_LOADED;
913 return $REFCOUNTS{"$func:$param"};
914}
915
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000916
917$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000918$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000919
Fred Drakef5478632002-05-23 17:59:16 +0000920sub cfuncline_helper($$$){
921 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000922 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000923 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000924 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000925 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000926 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
927 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000928 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
929 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
930 . "<td>$args)</td>"
931 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000932}
933sub do_cmd_cfuncline{
934 local($_) = @_;
935 my $type = next_argument();
936 my $name = next_argument();
937 my $args = next_argument();
938 my $siginfo = cfuncline_helper($type, $name, $args);
939 return "<dt>$siginfo\n<dd>" . $_;
940}
941sub do_env_cfuncdesc{
942 local($_) = @_;
943 my $type = next_argument();
944 my $name = next_argument();
945 my $args = next_argument();
946 my $siginfo = cfuncline_helper($type, $name, $args);
947 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000948 my $rcinfo = '';
949 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000950 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000951 }
952 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000953 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000954 }
Fred Drakec2578c52000-04-10 18:26:45 +0000955 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000956 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000957 }
Fred Drakee15956b2000-04-03 04:51:13 +0000958 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000959 $rcinfo = ( "\n<div class=\"refcount-info\">"
960 . "\n <span class=\"label\">Return value:</span>"
961 . "\n <span class=\"value\">$rcinfo.</span>"
962 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000963 }
Fred Drake34adb8a2002-04-15 20:48:40 +0000964 return "<dl><dt>$siginfo\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000965 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000966 . $_
967 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000968}
969
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000970sub do_cmd_cmemberline{
971 local($_) = @_;
972 my $container = next_argument();
973 my $type = next_argument();
974 my $name = next_argument();
975 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000976 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000977 $idx =~ s/ \(.*\)//;
978 return "<dt>$type <b>$idx</b>\n<dd>"
979 . $_;
980}
981sub do_env_cmemberdesc{
982 local($_) = @_;
983 my $container = next_argument();
984 my $type = next_argument();
985 my $name = next_argument();
986 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000987 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000988 $idx =~ s/ \(.*\)//;
989 return "<dl><dt>$type <b>$idx</b>\n<dd>"
990 . $_
991 . '</dl>';
992}
993
Fred Drakee15956b2000-04-03 04:51:13 +0000994sub do_env_csimplemacrodesc{
995 local($_) = @_;
996 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000997 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000998 return "<dl><dt><b>$idx</b>\n<dd>"
999 . $_
1000 . '</dl>'
1001}
1002
Fred Drake6659c301998-03-03 22:02:19 +00001003sub do_env_ctypedesc{
1004 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001005 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001006 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001007 $index_name = $type_name
1008 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001009 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001010 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1011 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001012 . $_
1013 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001014}
1015
1016sub do_env_cvardesc{
1017 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001018 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001019 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001020 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001021 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001022 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001023 return "<dl><dt>$var_type <b>$idx</b>\n"
1024 . '<dd>'
1025 . $_
1026 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001027}
1028
Fred Drake3cdb89d2000-09-14 20:17:23 +00001029sub convert_args($){
1030 local($IN_DESC_HANDLER) = 1;
1031 local($_) = @_;
1032 return translate_commands($_);
1033}
1034
Fred Drakef6e90272002-06-18 18:24:16 +00001035sub funcline_helper($$$){
1036 my($first, $idxitem, $arglist) = @_;
1037 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001038 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1039 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1040 . "\n <td><var>$arglist</var>)</td></tr></table>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001041}
1042
Fred Drake6659c301998-03-03 22:02:19 +00001043sub do_env_funcdesc{
1044 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001045 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001046 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001047 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1048 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001049 . get_indexsubitem());
1050 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001051 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001052 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001053}
1054
1055sub do_env_funcdescni{
1056 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001057 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001058 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001059 my $prefix = "<tt class=\"function\">$function_name</tt>";
1060 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001061}
1062
1063sub do_cmd_funcline{
1064 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001065 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001066 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001067 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001068 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1069 $prefix =~ s/\(\)//;
1070
Fred Drakef6e90272002-06-18 18:24:16 +00001071 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001072}
1073
Fred Drake6b3fb781999-07-12 16:50:09 +00001074sub do_cmd_funclineni{
1075 local($_) = @_;
1076 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001077 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001078 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001079
Fred Drakef6e90272002-06-18 18:24:16 +00001080 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001081}
1082
Fred Drake6659c301998-03-03 22:02:19 +00001083# Change this flag to index the opcode entries. I don't think it's very
1084# useful to index them, since they're only presented to describe the dis
1085# module.
1086#
1087$INDEX_OPCODES = 0;
1088
1089sub do_env_opcodedesc{
1090 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001091 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001092 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001093 my $idx;
1094 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001095 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1096 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001097 $idx =~ s/ \(byte code instruction\)//;
1098 }
1099 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001100 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001101 }
1102 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001103 if ($arg_list) {
1104 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1105 }
Fred Drake62e43691998-08-10 19:40:44 +00001106 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001107}
1108
1109sub do_env_datadesc{
1110 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001111 my $dataname = next_argument();
1112 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001113 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001114 return "<dl><dt><b>$idx</b>\n<dd>"
1115 . $_
1116 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001117}
1118
1119sub do_env_datadescni{
1120 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001121 my $idx = next_argument();
1122 if (! $STRING_INDEX_TT) {
1123 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001124 }
Fred Drake62e43691998-08-10 19:40:44 +00001125 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001126}
1127
1128sub do_cmd_dataline{
1129 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001130 my $data_name = next_argument();
1131 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001132 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001133 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001134}
1135
Fred Drakeadb272c2000-04-10 17:47:14 +00001136sub do_cmd_datalineni{
1137 local($_) = @_;
1138 my $data_name = next_argument();
1139 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1140}
1141
Fred Drake42b31a51998-03-27 05:16:10 +00001142sub do_env_excdesc{
1143 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001144 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001145 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakef6e90272002-06-18 18:24:16 +00001146 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001147 . "\n<dd>"
1148 . $_
1149 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001150}
1151
Fred Drake62e43691998-08-10 19:40:44 +00001152sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001153
1154
Fred Drakef5478632002-05-23 17:59:16 +00001155sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001156 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001157 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001158 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001159 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001160 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001161 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001162 my $prefix = "$TLSTART$what$TLEND$idx";
1163 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001164}
1165
Fred Drake643d76d2000-09-09 06:07:37 +00001166sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001167 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001168}
1169
Fred Drake06a01e82001-05-11 01:00:30 +00001170sub do_env_classdescstar{
1171 local($_) = @_;
1172 $THIS_CLASS = next_argument();
1173 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001174 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001175 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001176 my $prefix = "${TLSTART}class$TLEND$idx";
1177 # Can't use funcline_helper() since there is no args list.
1178 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001179}
1180
Fred Drake643d76d2000-09-09 06:07:37 +00001181sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001182 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001183}
1184
Fred Drake42b31a51998-03-27 05:16:10 +00001185
1186sub do_env_methoddesc{
1187 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001188 my $class_name = next_optional_argument();
1189 $class_name = $THIS_CLASS
1190 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001191 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001192 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001193 my $extra = '';
1194 if ($class_name) {
1195 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001196 }
Fred Drakef1927a62001-06-20 21:29:30 +00001197 my $idx = make_str_index_entry(
1198 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001199 $idx =~ s/ \(.*\)//;
1200 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001201 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001202}
1203
1204
Fred Drake7d45f6d1999-01-05 14:39:27 +00001205sub do_cmd_methodline{
1206 local($_) = @_;
1207 my $class_name = next_optional_argument();
1208 $class_name = $THIS_CLASS
1209 unless $class_name;
1210 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001211 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001212 my $extra = '';
1213 if ($class_name) {
1214 $extra = " ($class_name method)";
1215 }
Fred Drakef1927a62001-06-20 21:29:30 +00001216 my $idx = make_str_index_entry(
1217 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001218 $idx =~ s/ \(.*\)//;
1219 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001220 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001221}
1222
1223
Fred Draked64a40d1998-09-10 18:59:13 +00001224sub do_cmd_methodlineni{
1225 local($_) = @_;
1226 next_optional_argument();
1227 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001228 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001229 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001230}
1231
Fred Drake42b31a51998-03-27 05:16:10 +00001232sub do_env_methoddescni{
1233 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001234 next_optional_argument();
1235 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001236 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001237 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001238}
1239
1240
1241sub do_env_memberdesc{
1242 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001243 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001244 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001245 $class = $THIS_CLASS
1246 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001247 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001248 $extra = " ($class attribute)"
1249 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001250 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001251 $idx =~ s/ \(.*\)//;
1252 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001253 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001254}
1255
1256
Fred Drake5ccf3301998-04-17 20:04:09 +00001257sub do_cmd_memberline{
1258 local($_) = @_;
1259 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001260 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001261 $class = $THIS_CLASS
1262 unless $class;
1263 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001264 $extra = " ($class attribute)"
1265 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001266 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001267 $idx =~ s/ \(.*\)//;
1268 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001269 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001270}
1271
Fred Drakef269e592001-07-17 23:05:57 +00001272
Fred Drake42b31a51998-03-27 05:16:10 +00001273sub do_env_memberdescni{
1274 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001275 next_optional_argument();
1276 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001277 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001278 . $_
1279 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001280}
1281
1282
Fred Drake5ccf3301998-04-17 20:04:09 +00001283sub do_cmd_memberlineni{
1284 local($_) = @_;
1285 next_optional_argument();
1286 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001287 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001288}
1289
Fred Drakef269e592001-07-17 23:05:57 +00001290
1291@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001292
Fred Drakecb199762001-08-16 21:56:24 +00001293%FontConversions = ('cdata' => 'tt class="cdata"',
1294 'character' => 'tt class="character"',
1295 'class' => 'tt class="class"',
1296 'command' => 'code',
1297 'constant' => 'tt class="constant"',
1298 'exception' => 'tt class="exception"',
1299 'file' => 'tt class="file"',
1300 'filenq' => 'tt class="file"',
1301 'kbd' => 'kbd',
1302 'member' => 'tt class="member"',
1303 'programopt' => 'b',
1304 'textrm' => '',
1305 );
1306
Fred Drakef5478632002-05-23 17:59:16 +00001307sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001308 # do a little magic on a font name to get the right behavior in the first
1309 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001310 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001311 if (defined $FontConversions{$font}) {
1312 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001313 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001314 return $font;
1315}
1316
Fred Drakef5478632002-05-23 17:59:16 +00001317sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001318 my $a = $_[0];
1319 if (!defined $a) {
1320 return '';
1321 }
Fred Drakee15956b2000-04-03 04:51:13 +00001322 my $mark = substr($a, 0, 1);
1323 my $r = '';
1324 if ($mark eq 'c')
1325 { $r = ' align="center"'; }
1326 elsif ($mark eq 'r')
1327 { $r = ' align="right"'; }
1328 elsif ($mark eq 'l')
1329 { $r = ' align="left"'; }
1330 elsif ($mark eq 'p')
1331 { $r = ' align="left"'; }
1332 return $r;
1333}
1334
Fred Drakef5478632002-05-23 17:59:16 +00001335sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001336 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001337 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001338 my $a1 = figure_column_alignment($s1);
1339 my $a2 = figure_column_alignment($s2);
1340 my $a3 = figure_column_alignment($s3);
1341 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001342 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001343 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1344 $col_aligns[1] = "<td$a2>";
1345 $col_aligns[2] = "<td$a3>";
1346 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001347 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001348 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001349 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001350}
1351
Fred Drakef5478632002-05-23 17:59:16 +00001352sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001353 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001354 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001355 if ($font) {
1356 $sfont = "<$font>";
1357 $efont = "</$font>";
1358 $efont =~ s/ .*>/>/;
1359 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001360 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001361}
1362
1363sub do_env_tableii{
1364 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001365 my $arg = next_argument();
1366 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001367 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001368 my $h1 = next_argument();
1369 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001370 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001371 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001372 my $a1 = $col_aligns[0];
1373 my $a2 = $col_aligns[1];
1374 s/\\lineii</\\lineii[$a1|$a2]</g;
1375 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001376 . "\n <thead>"
1377 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001378 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1379 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001380 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001381 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001382 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001383 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001384 . "\n </tbody>"
1385 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001386}
1387
Fred Drakeda72b932000-09-21 15:58:02 +00001388sub do_env_longtableii{
1389 return do_env_tableii(@_);
1390}
1391
Fred Drake6659c301998-03-03 22:02:19 +00001392sub do_cmd_lineii{
1393 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001394 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001395 my $c1 = next_argument();
1396 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001397 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001398 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001399 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001400 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001401 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001402 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001403 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001404 }
Fred Drakee15956b2000-04-03 04:51:13 +00001405 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1406 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001407 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001408}
1409
1410sub do_env_tableiii{
1411 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001412 my $arg = next_argument();
1413 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001414 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001415 my $h1 = next_argument();
1416 my $h2 = next_argument();
1417 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001418 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001419 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001420 my $a1 = $col_aligns[0];
1421 my $a2 = $col_aligns[1];
1422 my $a3 = $col_aligns[2];
1423 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1424 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001425 . "\n <thead>"
1426 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001427 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1428 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1429 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001430 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001431 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001432 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001433 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001434 . "\n </tbody>"
1435 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001436}
1437
Fred Drakeda72b932000-09-21 15:58:02 +00001438sub do_env_longtableiii{
1439 return do_env_tableiii(@_);
1440}
1441
Fred Drake6659c301998-03-03 22:02:19 +00001442sub do_cmd_lineiii{
1443 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001444 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001445 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001446 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001447 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001448 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001449 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001450 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001451 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001452 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001453 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001454 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001455 }
Fred Drakee15956b2000-04-03 04:51:13 +00001456 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001457 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001458 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001459 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001460}
1461
Fred Drakea0f4c941998-07-24 22:16:04 +00001462sub do_env_tableiv{
1463 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001464 my $arg = next_argument();
1465 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001466 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001467 my $h1 = next_argument();
1468 my $h2 = next_argument();
1469 my $h3 = next_argument();
1470 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001471 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001472 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001473 my $a1 = $col_aligns[0];
1474 my $a2 = $col_aligns[1];
1475 my $a3 = $col_aligns[2];
1476 my $a4 = $col_aligns[3];
1477 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1478 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001479 . "\n <thead>"
1480 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001481 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1482 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1483 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1484 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001485 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001486 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001487 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001488 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001489 . "\n </tbody>"
1490 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001491}
1492
Fred Drakeda72b932000-09-21 15:58:02 +00001493sub do_env_longtableiv{
1494 return do_env_tableiv(@_);
1495}
1496
Fred Drakea0f4c941998-07-24 22:16:04 +00001497sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001498 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001499 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001500 my $c1 = next_argument();
1501 my $c2 = next_argument();
1502 my $c3 = next_argument();
1503 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001504 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001505 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001506 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001507 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001508 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001509 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001510 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001511 }
Fred Drakee15956b2000-04-03 04:51:13 +00001512 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001513 . " $c2align$c2</td>\n"
1514 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001515 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001516 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001517}
1518
Fred Drakef269e592001-07-17 23:05:57 +00001519sub do_env_tablev{
1520 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001521 my $arg = next_argument();
1522 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001523 my $font = fix_font(next_argument());
1524 my $h1 = next_argument();
1525 my $h2 = next_argument();
1526 my $h3 = next_argument();
1527 my $h4 = next_argument();
1528 my $h5 = next_argument();
1529 s/[\s\n]+//;
1530 $globals{'lineifont'} = $font;
1531 my $a1 = $col_aligns[0];
1532 my $a2 = $col_aligns[1];
1533 my $a3 = $col_aligns[2];
1534 my $a4 = $col_aligns[3];
1535 my $a5 = $col_aligns[4];
1536 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1537 return '<table border align="center" style="border-collapse: collapse">'
1538 . "\n <thead>"
1539 . "\n <tr class=\"tableheader\">"
1540 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1541 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1542 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1543 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1544 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1545 . "\n </tr>"
1546 . "\n </thead>"
1547 . "\n <tbody valign=\"baseline\">"
1548 . $_
1549 . "\n </tbody>"
1550 . "\n</table>";
1551}
1552
1553sub do_env_longtablev{
1554 return do_env_tablev(@_);
1555}
1556
1557sub do_cmd_linev{
1558 local($_) = @_;
1559 my $aligns = next_optional_argument();
1560 my $c1 = next_argument();
1561 my $c2 = next_argument();
1562 my $c3 = next_argument();
1563 my $c4 = next_argument();
1564 my $c5 = next_argument();
1565 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001566 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001567 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001568 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001569 my $padding = '';
1570 if ($c1align =~ /align="right"/ || $c1 eq '') {
1571 $padding = '&nbsp;';
1572 }
1573 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1574 . " $c2align$c2</td>\n"
1575 . " $c3align$c3</td>\n"
1576 . " $c4align$c4</td>\n"
1577 . " $c5align$c5</td>"
1578 . $_;
1579}
1580
Fred Drake3be20742000-08-31 06:22:54 +00001581
1582# These can be used to control the title page appearance;
1583# they need a little bit of documentation.
1584#
1585# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1586# $ICONSERVER directory, or include path information (other than "./"). The
1587# default image type will be assumed if an extension is not provided.
1588#
1589# If specified, the "title page" will contain two colums: one containing the
1590# title/author/etc., and the other containing the graphic. Use the other
1591# four variables listed here to control specific details of the layout; all
1592# are optional.
1593#
1594# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1595# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1596# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1597# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1598# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1599
Fred Drakef5478632002-05-23 17:59:16 +00001600sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001601 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001602 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001603 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001604 }
1605 else {
1606 write_warnings("\nThis document has no title.");
1607 }
Fred Drake6659c301998-03-03 22:02:19 +00001608 if ($t_author) {
1609 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001610 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001611 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001612 "<b><font size=\"+2\">$t_author"
1613 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001614 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001615 }
1616 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001617 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1618 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001619 }
Fred Drake3be20742000-08-31 06:22:54 +00001620 }
1621 else {
1622 write_warnings("\nThere is no author for this document.");
1623 }
Fred Drake6659c301998-03-03 22:02:19 +00001624 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001625 $the_title .= "\n<p>$t_institute</p>";
1626 }
Fred Draked07868a1998-05-14 21:00:28 +00001627 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001628 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1629 }
Fred Drake6659c301998-03-03 22:02:19 +00001630 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001631 $the_title .= "\n<p><i>$t_affil</i></p>";
1632 }
Fred Drake6659c301998-03-03 22:02:19 +00001633 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001634 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001635 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001636 $the_title .= ('<strong>Release '
1637 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001638 }
Fred Drakede77bc52000-12-14 18:36:12 +00001639 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001640 }
1641 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001642 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001643 }
1644 else {
1645 $the_title .= "\n<p>";
1646 }
Fred Drake6659c301998-03-03 22:02:19 +00001647 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001648 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001649 }
1650 return $the_title;
1651}
1652
Fred Drakef5478632002-05-23 17:59:16 +00001653sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001654 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001655 my $graphic = "<td class=\"titlegraphic\"";
1656 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1657 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1658 $graphic .= "><img";
1659 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1660 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1661 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1662 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001663 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001664 return $graphic;
1665}
1666
Fred Drakef5478632002-05-23 17:59:16 +00001667sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001668 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001669 my $the_title = "\n";
1670 if ($EXTERNAL_UP_LINK) {
1671 # This generates a <LINK> element in the wrong place (the
1672 # body), but I don't see any other way to get this generated
1673 # at all. Browsers like Mozilla, that support navigation
1674 # links, can make use of this.
1675 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1676 . ($EXTERNAL_UP_TITLE
1677 ? " title='$EXTERNAL_UP_TITLE'" : '')
1678 . ">\n");
1679 }
1680 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001681 if ($TITLE_PAGE_GRAPHIC) {
1682 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1683 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1684 . "<tr align=\"right\">\n<td>"
1685 . make_my_titlepage()
1686 . "</td>\n"
1687 . make_my_titlegraphic()
1688 . "</tr>\n</table>");
1689 }
1690 else {
1691 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1692 . make_my_titlegraphic()
1693 . "<td>"
1694 . make_my_titlepage()
1695 . "</td></tr>\n</table>");
1696 }
1697 }
1698 else {
1699 $the_title .= ("\n<center>"
1700 . make_my_titlepage()
1701 . "\n</center>");
1702 }
1703 $the_title .= "\n</div>";
1704 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001705 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001706 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001707}
1708
1709
Fred Drake885215c1998-05-20 21:32:09 +00001710#
Fred Drakea0f4c941998-07-24 22:16:04 +00001711# Module synopsis support
1712#
1713
1714require SynopsisTable;
1715
Fred Drakef7685d71998-07-25 03:31:46 +00001716sub get_chapter_id(){
1717 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001718 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001719 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001720 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001721}
1722
Fred Drake643d76d2000-09-09 06:07:37 +00001723# 'chapter' => 'SynopsisTable instance'
1724%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001725
1726sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001727 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001728 my $key;
1729 foreach $key (keys %ModuleSynopses) {
1730 if ($key eq $chap) {
1731 return $ModuleSynopses{$chap};
1732 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001733 }
Fred Drake643d76d2000-09-09 06:07:37 +00001734 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001735 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001736 return $st;
1737}
1738
Fred Drake62e43691998-08-10 19:40:44 +00001739sub do_cmd_moduleauthor{
1740 local($_) = @_;
1741 next_argument();
1742 next_argument();
1743 return $_;
1744}
1745
1746sub do_cmd_sectionauthor{
1747 local($_) = @_;
1748 next_argument();
1749 next_argument();
1750 return $_;
1751}
1752
Fred Drakea0f4c941998-07-24 22:16:04 +00001753sub do_cmd_declaremodule{
1754 local($_) = @_;
1755 my $key = next_optional_argument();
1756 my $type = next_argument();
1757 my $name = next_argument();
1758 my $st = get_synopsis_table(get_chapter_id());
1759 #
1760 $key = $name unless $key;
1761 $type = 'built-in' if $type eq 'builtin';
1762 $st->declare($name, $key, $type);
1763 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001764 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001765}
1766
1767sub do_cmd_modulesynopsis{
1768 local($_) = @_;
1769 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001770 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001771 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001772}
1773
1774sub do_cmd_localmoduletable{
1775 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001776 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001777 my $st = get_synopsis_table($chap);
1778 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001779 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001780}
1781
Fred Drakef5478632002-05-23 17:59:16 +00001782sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001783 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001784 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001785 my $st = $ModuleSynopses{$key};
1786 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001787 if ($file) {
1788 process_localmoduletables_in_file($file);
1789 }
1790 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001791 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001792 }
1793 }
1794}
1795
Fred Drakef5478632002-05-23 17:59:16 +00001796sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001797 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001798 open(MYFILE, "<$file");
1799 local($_);
1800 sysread(MYFILE, $_, 1024*1024);
1801 close(MYFILE);
1802 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001803 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001804 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001805 my $chap = $1;
1806 my $st = get_synopsis_table($chap);
1807 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001808 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001809 }
Fred Drake643d76d2000-09-09 06:07:37 +00001810 open(MYFILE,">$file");
1811 print MYFILE $_;
1812 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001813}
Fred Drakef5478632002-05-23 17:59:16 +00001814sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001815 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001816 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001817}
Fred Drakea0f4c941998-07-24 22:16:04 +00001818
1819
1820#
1821# "See also:" -- references placed at the end of a \section
1822#
1823
1824sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001825 return ("<div class=\"seealso\">\n "
1826 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001827 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001828 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001829}
1830
Fred Drake5ed35fd2001-11-30 18:09:54 +00001831sub do_env_seealsostar{
1832 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001833 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001834 . '</div>');
1835}
1836
Fred Drakea0f4c941998-07-24 22:16:04 +00001837sub do_cmd_seemodule{
1838 # Insert the right magic to jump to the module definition. This should
1839 # work most of the time, at least for repeat builds....
1840 local($_) = @_;
1841 my $key = next_optional_argument();
1842 my $module = next_argument();
1843 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001844 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001845 $key = $module
1846 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001847 if ($text =~ /\.$/) {
1848 $period = '';
1849 }
Fred Drakef1927a62001-06-20 21:29:30 +00001850 return ('<dl compact class="seemodule">'
1851 . "\n <dt>Module <b><tt class=\"module\">"
1852 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1853 . "\n <dd>$text$period\n </dl>"
1854 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001855}
1856
Fred Drakee0197bf2001-04-12 04:03:22 +00001857sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001858 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001859 my $s = "$str";
1860 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1861 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1862 return $s;
1863}
1864
Fred Drakef5478632002-05-23 17:59:16 +00001865sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001866 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001867 my $rfcnum = next_argument();
1868 my $title = next_argument();
1869 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001870 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001871 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001872 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001873 return '<dl compact class="seerfc">'
1874 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001875 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001876 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001877 . "\n <dd>$text\n </dl>"
1878 . $_;
1879}
1880
Fred Drake643d76d2000-09-09 06:07:37 +00001881sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001882 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001883}
1884
1885sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001886 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001887 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001888}
1889
Fred Drake48449982000-09-12 17:52:33 +00001890sub do_cmd_seetitle{
1891 local($_) = @_;
1892 my $url = next_optional_argument();
1893 my $title = next_argument();
1894 my $text = next_argument();
1895 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001896 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001897 return '<dl compact class="seetitle">'
1898 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001899 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001900 . "\n <dd>$text\n </dl>"
1901 . $_;
1902 }
1903 return '<dl compact class="seetitle">'
1904 . "\n <dt><em class=\"citetitle\""
1905 . "\n >$title</em>"
1906 . "\n <dd>$text\n </dl>"
1907 . $_;
1908}
1909
Fred Drakeef4d1112000-05-09 16:17:51 +00001910sub do_cmd_seeurl{
1911 local($_) = @_;
1912 my $url = next_argument();
1913 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001914 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001915 return '<dl compact class="seeurl">'
1916 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001917 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001918 . "\n <dd>$text\n </dl>"
1919 . $_;
1920}
1921
Fred Drakea0f4c941998-07-24 22:16:04 +00001922sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001923 local($_) = @_;
1924 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001925 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001926}
1927
1928
1929#
Fred Drake885215c1998-05-20 21:32:09 +00001930# Definition list support.
1931#
1932
1933sub do_env_definitions{
Fred Drake49b33fa2002-11-15 19:04:10 +00001934 return "<dl class=\"definitions\">" . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001935}
1936
1937sub do_cmd_term{
1938 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001939 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001940 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001941 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001942 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001943}
1944
1945
Fred Drake38178fd2000-09-22 17:05:04 +00001946# I don't recall exactly why this was needed, but it was very much needed.
1947# We'll see if anything breaks when I move the "code" line out -- some
1948# things broke with it in.
1949
1950#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001951process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001952declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001953funcline # {} # {}
1954funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001955memberline # [] # {}
1956methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001957methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001958modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001959platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001960samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001961setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001962withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001963_RAW_ARG_DEFERRED_CMDS_
1964
1965
Fred Drake8a5e6792002-04-15 18:41:31 +00001966$alltt_start = '<div class="verbatim"><pre>';
1967$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001968
Fred Drakef5478632002-05-23 17:59:16 +00001969sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001970 local ($_) = @_;
1971 local($closures,$reopens,@open_block_tags);
1972
1973 # get the tag-strings for all open tags
1974 local(@keep_open_tags) = @$open_tags_R;
1975 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1976
1977 # get the tags for text-level tags only
1978 $open_tags_R = [ @keep_open_tags ];
1979 local($local_closures, $local_reopens);
1980 ($local_closures, $local_reopens,@open_block_tags)
1981 = &preserve_open_block_tags
1982 if (@$open_tags_R);
1983
1984 $open_tags_R = [ @open_block_tags ];
1985
1986 do {
1987 local($open_tags_R) = [ @open_block_tags ];
1988 local(@save_open_tags) = ();
1989
1990 local($cnt) = ++$global{'max_id'};
1991 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1992 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1993
1994 $_ = &translate_environments($_);
1995 $_ = &translate_commands($_) if (/\\/);
1996
1997 # preserve space-runs, using &nbsp;
1998 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1999 s/(<BR>) /$1;SPMnbsp;/g;
2000
2001 $_ = join('', $closures, $alltt_start, $local_reopens
2002 , $_
2003 , &balance_tags() #, $local_closures
2004 , $alltt_end, $reopens);
2005 undef $open_tags_R; undef @save_open_tags;
2006 };
2007 $open_tags_R = [ @keep_open_tags ];
2008 $_;
2009}
2010
Fred Drake6fc22f62002-06-17 15:01:05 +00002011# List of all filenames produced ny do_cmd_verbatiminput()
2012%VerbatimFiles = ();
2013@VerbatimOutputs = ();
2014
2015sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002016 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002017 #
2018 # Re-write the source filename to always use a .txt extension
2019 # so that Web servers will present it as text/plain. This is
2020 # needed since there is no other even moderately reliable way
2021 # to get the right Content-Type header on text files for
2022 # servers which we can't configure (like python.org mirrors).
2023 #
2024 if (defined $VerbatimFiles{$file}) {
2025 # We've seen this one before; re-use the same output file.
2026 return $VerbatimFiles{$file};
2027 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002028 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002029 $filename = "$srcname.txt";
2030 #
2031 # We need to determine if our default filename is already
2032 # being used, and find a new one it it is. If the name is in
2033 # used, this algorithm will first attempt to include the
2034 # source extension as part of the name, and if that is also in
2035 # use (if the same file is included multiple times, or if
2036 # another source file has that as the base name), a counter is
2037 # used instead.
2038 #
2039 my $found = 1;
2040 FIND:
2041 while ($found) {
2042 foreach $fn (@VerbatimOutputs) {
2043 if ($fn eq $filename) {
2044 if ($found == 1) {
2045 $srcext =~ s/^[.]//; # Remove '.' from extension
2046 $filename = "$srcname-$srcext.txt";
2047 }
2048 else {
2049 $filename = "$srcname-$found.txt";
2050 }
2051 ++$found;
2052 next FIND;
2053 }
2054 }
2055 $found = 0;
2056 }
2057 push @VerbatimOutputs, $filename;
2058 $VerbatimFiles{$file} = $filename;
2059 return $filename;
2060}
2061
Fred Drake57e52ef2001-06-15 21:31:57 +00002062sub do_cmd_verbatiminput{
2063 local($_) = @_;
2064 my $fname = next_argument();
2065 my $file;
2066 my $found = 0;
2067 my $texpath;
2068 # Search TEXINPUTS for the input file, the way we're supposed to:
2069 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2070 $file = "$texpath$dd$fname";
2071 last if ($found = (-f $file));
2072 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002073 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002074 my $text;
2075 if ($found) {
2076 open(MYFILE, "<$file") || die "\n$!\n";
2077 read(MYFILE, $text, 1024*1024);
2078 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002079 $filename = get_verbatim_output_name($file);
2080 # Now that we have a filename, write it out.
2081 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002082 print MYFILE $text;
2083 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002084 #
2085 # These rewrites convert the raw text to something that will
2086 # be properly visible as HTML and also will pass through the
2087 # vagaries of conversion through LaTeX2HTML. The order in
2088 # which the specific rewrites are performed is significant.
2089 #
2090 $text =~ s/\&/\&amp;/g;
2091 # These need to happen before the normal < and > re-writes,
2092 # since we need to avoid LaTeX2HTML's attempt to perform
2093 # ligature processing without regard to context (since it
2094 # doesn't have font information).
2095 $text =~ s/--/-&\#45;/g;
2096 $text =~ s/<</\&lt;\&\#60;/g;
2097 $text =~ s/>>/\&gt;\&\#62;/g;
2098 # Just normal re-writes...
2099 $text =~ s/</\&lt;/g;
2100 $text =~ s/>/\&gt;/g;
2101 # These last isn't needed for the HTML, but is needed to get
2102 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2103 # of &sol; since many browsers don't support that.
2104 $text =~ s/\\/\&\#92;/g;
2105 }
2106 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002107 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2108 }
2109 my $note = 'Download as text.';
2110 if ($file ne $filename) {
2111 $note = ('Download as text (original file name: <span class="file">'
2112 . $fname
2113 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002114 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002115 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002116 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002117 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002118 . "<a href=\"$filename\" type=\"text/plain\""
2119 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002120 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002121 . $_);
2122}
Fred Drake86333602001-04-10 17:13:39 +00002123
Fred Drake6659c301998-03-03 22:02:19 +000021241; # This must be the last line