blob: d5d000f664918564286b755015afef6e13d04cdf [file] [log] [blame]
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
Fred Drake6659c301998-03-03 22:02:19 +00002#
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)
Fred Drake1b1ca0c2003-09-05 15:43:58 +000019 ||(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 Drake2fc88a62003-08-05 03:45:37 +000054 . " />");
Fred Drake7a40c072000-10-02 14:43:38 +000055 }
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) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +000068 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
Fred Drakee16f6791998-05-15 04:28:37 +000071 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000072 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +000073 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
74 if ($matched) {
75 my($new, $char) = ($1, $3);
76 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
77 print "\ndefining handler for \\$new to insert '$char'\n";
78 }
79 else {
80 write_warnings("Could not interpret \\let construct...");
81 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000082 }
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 Drake7adcfad2003-07-10 17:04:45 +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]; }
Fred Drakef0f6d122004-01-23 08:52:28 +000098sub do_cmd_guilabel{
99 return use_wrappers($_[0]. '<span class="guilabel">', '</span>'); }
Fred Drakebd5fdd92003-07-16 14:01:56 +0000100sub do_cmd_menuselection{
Fred Drakef0f6d122004-01-23 08:52:28 +0000101 return use_wrappers($_[0], '<span class="guilabel">', '</span>'); }
102sub do_cmd_sub{
103 return '</span> &gt; <span class="guilabel">' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +0000104
105
Fred Drake6659c301998-03-03 22:02:19 +0000106# words typeset in a special way (not in HTML though)
107
Fred Drake49b33fa2002-11-15 19:04:10 +0000108sub do_cmd_ABC{ 'ABC' . $_[0]; }
Fred Drake5bbeb8d2003-02-04 15:01:37 +0000109sub do_cmd_UNIX{ '<font style="font-variant: small-caps;">Unix</font>'
110 . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000111sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
112sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
113sub do_cmd_C{ 'C' . $_[0]; }
114sub do_cmd_Cpp{ 'C++' . $_[0]; }
115sub do_cmd_EOF{ 'EOF' . $_[0]; }
116sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000117
Fred Drake49b33fa2002-11-15 19:04:10 +0000118sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000119
Fred Draked07868a1998-05-14 21:00:28 +0000120$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000121$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000122$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000123$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000124
Fred Drake49b33fa2002-11-15 19:04:10 +0000125sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
126sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000127sub do_cmd_release{
128 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000129 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000130 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000131}
132
Fred Drakef1927a62001-06-20 21:29:30 +0000133sub do_cmd_setreleaseinfo{
134 local($_) = @_;
135 $RELEASE_INFO = next_argument();
136 return $_;
137}
138
Fred Drake3cdb89d2000-09-14 20:17:23 +0000139sub do_cmd_setshortversion{
140 local($_) = @_;
141 $SHORT_VERSION = next_argument();
142 return $_;
143}
144
Fred Drake6659c301998-03-03 22:02:19 +0000145sub do_cmd_authoraddress{
146 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000147 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000148 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000149}
150
151sub 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 Drake345555d2003-12-30 16:19:28 +0000157# Helper used in many places that arbitrary code-like text appears:
158
159sub codetext($){
160 my $text = "$_[0]";
161 $text =~ s/--/-\&#45;/go;
162 return $text;
163}
164
Fred Drakef5478632002-05-23 17:59:16 +0000165sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000166 local($_,$before,$after) = @_;
167 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000168 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000169}
170
Fred Drake345555d2003-12-30 16:19:28 +0000171sub use_code_wrappers($$$){
172 local($_,$before,$after) = @_;
173 my $stuff = codetext(next_argument());
174 return $before . $stuff . $after . $_;
175}
176
Fred Drake3cdb89d2000-09-14 20:17:23 +0000177$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000178sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000179 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000180 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000181 "</var><big>\]</big><var>");
182 }
183 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000184 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000185 }
Fred Drake6659c301998-03-03 22:02:19 +0000186}
187
Fred Drakec9a44381998-03-17 06:29:13 +0000188# Logical formatting (some based on texinfo), needs to be converted to
189# minimalist HTML. The "minimalist" is primarily to reduce the size of
190# output files for users that read them over the network rather than
191# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000192
Fred Drake49b33fa2002-11-15 19:04:10 +0000193sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000194sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000195 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_code{
Fred Drake345555d2003-12-30 16:19:28 +0000197 return use_code_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000199 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000201 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000203 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000205 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000207 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000208sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000209 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000210sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000211 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000212sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000213 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000214sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000215 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000216sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000217 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000218sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000219 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000220sub do_cmd_regexp{
Fred Drake345555d2003-12-30 16:19:28 +0000221 return use_code_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000222sub do_cmd_character{
Fred Drake345555d2003-12-30 16:19:28 +0000223 return use_code_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000224sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000225 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000226sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000227 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000228sub do_cmd_longprogramopt{
229 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000230 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000231sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000232 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000233sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000234 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000235sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000236 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000237sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000238 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000239sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000240 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000241sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000242 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000243sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000244 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000245sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000246 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000247sub do_cmd_samp{
Fred Drake345555d2003-12-30 16:19:28 +0000248 return use_code_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000249sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000250 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000251sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000252 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000253sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000254 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000255sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000256 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000257# This can be changed/overridden for translations:
258%NoticeNames = ('note' => 'Note:',
259 'warning' => 'Warning:',
260 );
261
Fred Drake92350b32001-10-09 18:01:23 +0000262sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000263 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000264 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000265 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000266 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000267 '</span>'); }
268sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000269 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000270 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000271 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000272 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000273 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000274
Fred Drake6ca33772001-12-14 22:50:06 +0000275sub do_env_notice{
276 local($_) = @_;
277 my $notice = next_optional_argument();
278 if (!$notice) {
279 $notice = 'note';
280 }
281 my $label = $NoticeNames{$notice};
282 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
283 . $_
284 . '</div>');
285}
286
Fred Drake3d5a04a2000-08-03 17:25:44 +0000287sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000288 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000289sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000290 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000291
Fred Drakec9a44381998-03-17 06:29:13 +0000292
Fred Drake25817041999-01-13 17:06:34 +0000293sub do_cmd_refmodule{
294 # Insert the right magic to jump to the module definition.
295 local($_) = @_;
296 my $key = next_optional_argument();
297 my $module = next_argument();
298 $key = $module
299 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000300 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000301 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000302}
303
Fred Drake1a7af391998-04-01 22:44:56 +0000304sub do_cmd_newsgroup{
305 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000306 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000307 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000308 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
309 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000310 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000311}
Fred Drakefc16e781998-03-12 21:03:26 +0000312
313sub do_cmd_envvar{
314 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000315 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000316 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000317 # The <tt> here is really to keep buildindex.py from making
318 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000319 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000320 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000321 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000322 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000323 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000324}
325
Fred Drake6659c301998-03-03 22:02:19 +0000326sub do_cmd_url{
327 # use the URL as both text and hyperlink
328 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000329 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000330 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000331 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000332 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000333}
334
335sub do_cmd_manpage{
336 # two parameters: \manpage{name}{section}
337 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000338 my $page = next_argument();
339 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000340 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000341}
342
Fred Drakedbfe7682002-04-03 02:47:14 +0000343$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000344#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
345$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000346
347sub get_rfc_url($$){
348 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000349 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000350}
351
352sub do_cmd_pep{
353 local($_) = @_;
354 my $rfcnumber = next_argument();
355 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000356 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000357 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000358 # Save the reference
359 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
360 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake04bf7242003-11-26 20:55:49 +0000361 return ("<a class=\"rfc\" id='$id'\n"
Fred Drake2fc88a62003-08-05 03:45:37 +0000362 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000363}
364
Fred Drake6659c301998-03-03 22:02:19 +0000365sub do_cmd_rfc{
366 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000367 my $rfcnumber = next_argument();
368 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000369 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000370 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000371 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000372 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000373 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake04bf7242003-11-26 20:55:49 +0000374 return ("<a class=\"rfc\" id='$id'\nhref=\"$href\">"
Fred Drake2fc88a62003-08-05 03:45:37 +0000375 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000376}
377
Fred Drake77602f22001-07-06 22:43:02 +0000378sub do_cmd_ulink{
379 local($_) = @_;
380 my $text = next_argument();
381 my $url = next_argument();
382 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
383}
384
Fred Drakec9f5fe01999-11-09 16:59:42 +0000385sub do_cmd_citetitle{
386 local($_) = @_;
387 my $url = next_optional_argument();
388 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000389 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000390 my $repl = '';
391 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000392 $repl = ("<em class=\"citetitle\"><a\n"
393 . " href=\"$url\"\n"
394 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000395 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000396 }
397 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000398 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000399 }
400 return $repl . $_;
401}
402
Fred Drake6659c301998-03-03 22:02:19 +0000403sub do_cmd_deprecated{
404 # two parameters: \deprecated{version}{whattodo}
405 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000406 my $release = next_argument();
407 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000408 return ('<div class="versionnote">'
409 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000410 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000411 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000412}
413
Fred Drakef5478632002-05-23 17:59:16 +0000414sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000415 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000416 my $type = $_[0];
417 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000418 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000419 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000420 my $text = "$type in version $release.";
421 if ($explanation) {
422 $text = "$type in version $release:\n$explanation.";
423 }
Fred Drakef1927a62001-06-20 21:29:30 +0000424 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000425}
426
427sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000428 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000429}
430
431sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000432 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000433}
434
Fred Drake557460c1999-03-02 16:05:35 +0000435#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000436# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000437#
438sub do_cmd_platform{
439 local($_) = @_;
440 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000441 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000442 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000443 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000444 return "\n<p class=\"availability\">Availability: <span"
445 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000446}
447
Fred Drake557460c1999-03-02 16:05:35 +0000448$IGNORE_PLATFORM_ANNOTATION = '';
449sub do_cmd_ignorePlatformAnnotation{
450 local($_) = @_;
451 $IGNORE_PLATFORM_ANNOTATION = next_argument();
452 return $_;
453}
454
Fred Drake6659c301998-03-03 22:02:19 +0000455
456# index commands
457
458$INDEX_SUBITEM = "";
459
Fred Drakef5478632002-05-23 17:59:16 +0000460sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000461 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000462}
463
464sub do_cmd_setindexsubitem{
465 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000466 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000467 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000468}
469
Fred Drakefc16e781998-03-12 21:03:26 +0000470sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000471 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000472 # do things in the right order, but we need to at least strip this stuff
473 # out, and leave anything that the second argument expanded out to.
474 #
475 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000476 my $oldsubitem = $INDEX_SUBITEM;
477 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000478 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000479 my $br_id = ++$globals{'max_id'};
480 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000481 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000482 return
483 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000484 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000485 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000486}
487
Fred Drake08932051998-04-17 02:15:42 +0000488# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000489# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
490# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000491#
Fred Drake49b33fa2002-11-15 19:04:10 +0000492sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000493
Fred Drake42b31a51998-03-27 05:16:10 +0000494# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000495#
Fred Drake08932051998-04-17 02:15:42 +0000496open(IDXFILE, '>index.dat') || die "\n$!\n";
497open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000498print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000499print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000500
501# Using \0 for this is bad because we can't use common tools to work with the
502# resulting files. Things like grep can be useful with this stuff!
503#
504$IDXFILE_FIELD_SEP = "\1";
505
Fred Drakef5478632002-05-23 17:59:16 +0000506sub write_idxfile($$){
507 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000508 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000509}
510
Fred Drake42b31a51998-03-27 05:16:10 +0000511
Fred Drakef5478632002-05-23 17:59:16 +0000512sub gen_link($$){
513 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000514 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000515 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000516}
517
Fred Drakef5478632002-05-23 17:59:16 +0000518sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000519 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000520 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000521 $str = gen_index_id($str, '');
522 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000523 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000524}
525
Fred Drake04bf7242003-11-26 20:55:49 +0000526sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000527 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake04bf7242003-11-26 20:55:49 +0000528 my $aname = "<a id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000529 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000530 return ($name, $ahref);
531}
532
533sub new_link_info(){
534 my($name, $ahref) = new_link_name_info();
535 my $aname = "<a id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000536 return ($name, $aname, $ahref);
537}
538
Fred Drakeab032151999-05-13 18:36:54 +0000539$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000540sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000541 my $count = @_;
542 my $i = 0;
543 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000544 my $name = $_[$i];
545 my $cmd = "idx_cmd_$name";
546 die "\nNo function $cmd() defined!\n"
547 if (!defined &$cmd);
548 eval ("sub do_cmd_$name { return process_index_macros("
549 . "\$_[0], '$name'); }");
550 if (length($IndexMacroPattern) == 0) {
551 $IndexMacroPattern = "$name";
552 }
553 else {
554 $IndexMacroPattern .= "|$name";
555 }
Fred Drakeab032151999-05-13 18:36:54 +0000556 }
557}
558
559$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000560sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000561 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000562 my $cmdname = $_[1]; # This is what triggered us in the first place;
563 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000564 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000565 my $cmd = "idx_cmd_$cmdname";
566 print "\nIndexing: \\$cmdname"
567 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000568 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000569 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000570 $cmdname = "$1";
571 print " \\$cmdname"
572 if $DEBUG_INDEXING;
573 $cmd = "idx_cmd_$cmdname";
574 if (!defined &$cmd) {
575 last;
576 }
577 else {
578 s/^[\s\n]*\\$cmdname//;
579 &$cmd($ahref);
580 }
Fred Drakeab032151999-05-13 18:36:54 +0000581 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000582 if (/^[ \t\r\n]/) {
583 $_ = substr($_, 1);
584 }
Fred Drake62e43691998-08-10 19:40:44 +0000585 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000586}
587
Fred Drakeab032151999-05-13 18:36:54 +0000588define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000589sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000590 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000591 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000592}
593
Fred Drakeab032151999-05-13 18:36:54 +0000594define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000595sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000596 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000597 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
598 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000599}
600
601define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000602sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000603 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000604 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000605 add_index_entry("$str1!$str2", $_[0]);
606 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000607}
608
Fred Drakeab032151999-05-13 18:36:54 +0000609define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000610sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000611 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000612 my $str2 = next_argument();
613 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000614 add_index_entry("$str1!$str2 $str3", $_[0]);
615 add_index_entry("$str2!$str3, $str1", $_[0]);
616 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000617}
618
Fred Drakeab032151999-05-13 18:36:54 +0000619define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000620sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000621 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000622 my $str2 = next_argument();
623 my $str3 = next_argument();
624 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000625 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
626 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
627 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
628 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000629}
630
Fred Drakeab032151999-05-13 18:36:54 +0000631define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000632sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000633 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000634 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000635 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000636}
Fred Drake6659c301998-03-03 22:02:19 +0000637
Fred Drakef5478632002-05-23 17:59:16 +0000638sub my_typed_index_helper($$){
639 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000640 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000641 add_index_entry("$str $word", $ahref);
642 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000643}
644
Fred Drakeab032151999-05-13 18:36:54 +0000645define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000646sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
647sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
648sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
649sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000650
Fred Drakeab032151999-05-13 18:36:54 +0000651define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000652sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000653 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000654 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000655 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000656}
657
658
Fred Drakef5478632002-05-23 17:59:16 +0000659sub make_mod_index_entry($$){
660 my($str, $define) = @_;
661 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000662 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000663 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
664 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000665 $str = gen_index_id($str, $define);
666 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000667 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000668
Fred Drakec9a44381998-03-17 06:29:13 +0000669 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000670 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000671 $str =~ /(<tt.*<\/tt>)/;
672 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000673 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000674 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000675 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000676}
677
Fred Drake557460c1999-03-02 16:05:35 +0000678
Fred Drakec9a44381998-03-17 06:29:13 +0000679$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000680$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000681
Fred Drakef5478632002-05-23 17:59:16 +0000682sub define_module($$){
683 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000684 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000685 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000686 && $word ne "standard" && $word ne "") {
687 write_warnings("Bad module type '$word'"
688 . " for \\declaremodule (module $name)");
689 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000690 }
Fred Drake6659c301998-03-03 22:02:19 +0000691 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000692 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000693 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000694 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000695 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000696 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000697}
698
Fred Drakef5478632002-05-23 17:59:16 +0000699sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000700 local($word, $_) = @_;
701 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000702 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000703}
704
Fred Drake49b33fa2002-11-15 19:04:10 +0000705sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
706sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
707sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
708sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
709# local($_) = @_;
710# my $name = next_argument();
711# return define_module('standard', $name) . $_;
712# }
Fred Drake6659c301998-03-03 22:02:19 +0000713
Fred Drakef5478632002-05-23 17:59:16 +0000714sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000715 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000716 my $str = next_argument();
717 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000718 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000719 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
720 # just inline it all here
721 $str = gen_index_id($str, 'REF');
722 $index{$str} .= $ahref;
723 write_idxfile($ahref, $str);
724}
725
Fred Drake6659c301998-03-03 22:02:19 +0000726# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000727define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000728 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000729sub idx_cmd_refmodindex($){
730 return ref_module_index_helper('', $_[0]); }
731sub idx_cmd_refbimodindex($){
732 return ref_module_index_helper('built-in', $_[0]); }
733sub idx_cmd_refexmodindex($){
734 return ref_module_index_helper('extension', $_[0]);}
735sub idx_cmd_refstmodindex($){
736 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000737
Fred Drake49b33fa2002-11-15 19:04:10 +0000738sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000739
Fred Drakef5478632002-05-23 17:59:16 +0000740sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000741 # These markers must be non-empty or the main latex2html script
742 # may remove a surrounding element that has not other content as
743 # "extraneous"; this ensures these elements (usually hyperlink
744 # targets) are not removed improperly. We use comments since
745 # there's no meaningful actual content.
746 # Thanks to Dave Kuhlman for figuring why some named anchors were
747 # being lost.
748 $anchor_invisible_mark = '<!--x-->';
749 $anchor_invisible_mark2 = '<!--y-->';
750 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000751 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000752}
Fred Drake42b31a51998-03-27 05:16:10 +0000753init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000754
Fred Drakeab032151999-05-13 18:36:54 +0000755# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000756# instead of the dummy filler.
757#
Fred Drakef5478632002-05-23 17:59:16 +0000758sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000759 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000760 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000761 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000762 if ($str =~ /^<[a-z]+\b/) {
763 my $s = "$str";
764 $s =~ s/^<([a-z]+)\b/<$1 id='$name'/;
765 return $s;
766 }
767 else {
768 return "<a id='$name'>$str</a>";
769 }
Fred Drake6659c301998-03-03 22:02:19 +0000770}
771
Fred Drake77602f22001-07-06 22:43:02 +0000772
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000773%TokenToTargetMapping = (); # language:token -> link target
774%DefinedGrammars = (); # language -> full grammar text
775%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000776
777sub do_cmd_token{
778 local($_) = @_;
779 my $token = next_argument();
780 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
781 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
782 # recursive definition or display-only productionlist
783 return "$token";
784 }
785 if ($target eq '') {
786 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
787 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
788 print "Adding '$CURRENT_FILE' to back-patch list.\n";
789 }
790 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
791 }
792 return "<a href=\"$target\">$token</a>" . $_;
793}
794
Fred Drake16bb4192001-08-20 21:36:38 +0000795sub do_cmd_grammartoken{
796 return do_cmd_token(@_);
797}
798
Fred Drake77602f22001-07-06 22:43:02 +0000799sub do_env_productionlist{
800 local($_) = @_;
801 my $lang = next_optional_argument();
802 my $filename = "grammar-$lang.txt";
803 if ($lang eq '') {
804 $filename = 'grammar.txt';
805 }
806 local($CURRENT_GRAMMAR) = $lang;
807 $DefinedGrammars{$lang} .= $_;
808 return ("<dl><dd class=\"grammar\">\n"
809 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000810 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000811 . translate_commands(translate_environments($_))
812 . "</table>\n"
813 . "</div>\n"
814 . (($lang eq '*')
815 ? ''
816 : ("<a class=\"grammar-footer\"\n"
817 . " href=\"$filename\" type=\"text/plain\"\n"
818 . " >Download entire grammar as text.</a>\n"))
819 . "</dd></dl>");
820}
821
822sub do_cmd_production{
823 local($_) = @_;
824 my $token = next_argument();
825 my $defn = next_argument();
826 my $lang = $CURRENT_GRAMMAR;
827 local($CURRENT_TOKEN) = $token;
828 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000829 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000830 . " <td><code>$token</code></td>\n"
831 . " <td>&nbsp;::=&nbsp;</td>\n"
832 . " <td><code>"
833 . translate_commands($defn)
834 . "</code></td></tr>"
835 . $_);
836 }
837 my $target;
838 if ($lang eq '') {
839 $target = "$CURRENT_FILE\#tok-$token";
840 }
841 else {
842 $target = "$CURRENT_FILE\#tok-$lang-$token";
843 }
844 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000845 return ("<tr valign=\"baseline\">\n"
Fred Drake04bf7242003-11-26 20:55:49 +0000846 . " <td><code><a id='tok-$token'>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000847 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000848 . " <td>&nbsp;::=&nbsp;</td>\n"
849 . " <td><code>"
850 . translate_commands($defn)
851 . "</code></td></tr>"
852 . $_);
853}
854
Fred Drake53815882002-03-15 23:21:37 +0000855sub do_cmd_productioncont{
856 local($_) = @_;
857 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000858 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000859 return ("<tr valign=\"baseline\">\n"
860 . " <td>&nbsp;</td>\n"
861 . " <td>&nbsp;</td>\n"
862 . " <td><code>"
863 . translate_commands($defn)
864 . "</code></td></tr>"
865 . $_);
866}
867
Fred Drakef5478632002-05-23 17:59:16 +0000868sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000869 my $lang;
870 my $filename;
871 local($_);
872 print "process_grammar_files()\n";
873 foreach $lang (keys %DefinedGrammars) {
874 $filename = "grammar-$lang.txt";
875 if ($lang eq '*') {
876 next;
877 }
878 if ($lang eq '') {
879 $filename = 'grammar.txt';
880 }
881 open(GRAMMAR, ">$filename") || die "\n$!\n";
882 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
883 close(GRAMMAR);
884 print "Wrote grammar file $filename\n";
885 }
886 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
887 foreach $filename (keys %BackpatchGrammarFiles) {
888 print "\nBack-patching grammar links in $filename\n";
889 my $buffer;
890 open(GRAMMAR, "<$filename") || die "\n$!\n";
891 # read all of the file into the buffer
892 sysread(GRAMMAR, $buffer, 1024*1024);
893 close(GRAMMAR);
894 while ($buffer =~ /$PATTERN/) {
895 my($lang, $token) = ($1, $2);
896 my $target = $TokenToTargetMapping{"$lang:$token"};
897 my $source = "<pyGrammarToken><$lang><$token>";
898 $buffer =~ s/$source/$target/g;
899 }
900 open(GRAMMAR, ">$filename") || die "\n$!\n";
901 print GRAMMAR $buffer;
902 close(GRAMMAR);
903 }
904}
905
Fred Drakef5478632002-05-23 17:59:16 +0000906sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000907 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000908 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000909 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
910 s/\\token(<<\d+>>)(.+)\1/$2/g;
911 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000912 s/<<\d+>>//g;
913 s/;SPMgt;/>/g;
914 s/;SPMlt;/</g;
915 s/;SPMquot;/\"/g;
916 return $_;
917}
918
919
Fred Drakee15956b2000-04-03 04:51:13 +0000920$REFCOUNTS_LOADED = 0;
921
Fred Drakef5478632002-05-23 17:59:16 +0000922sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000923 $REFCOUNTS_LOADED = 1;
924
Fred Drake49b33fa2002-11-15 19:04:10 +0000925 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000926 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000927 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000928 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000929 $mydir = getcwd() . "$dd$mydir"
930 unless $mydir =~ s|^/|/|;
931 local $_;
932 my $filename = "$mydir${dd}api${dd}refcounts.dat";
933 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
934 print "[loading API refcount data]";
935 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000936 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000937 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
938 #print "\n$func($param) --> $count";
939 $REFCOUNTS{"$func:$param"} = $count;
940 }
941 }
942}
943
Fred Drakef5478632002-05-23 17:59:16 +0000944sub get_refcount($$){
945 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000946 load_refcounts()
947 unless $REFCOUNTS_LOADED;
948 return $REFCOUNTS{"$func:$param"};
949}
950
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000951
952$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000953$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000954
Fred Drakef5478632002-05-23 17:59:16 +0000955sub cfuncline_helper($$$){
956 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000957 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000958 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000959 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000960 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000961 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
962 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000963 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
964 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
965 . "<td>$args)</td>"
966 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000967}
968sub do_cmd_cfuncline{
969 local($_) = @_;
970 my $type = next_argument();
971 my $name = next_argument();
972 my $args = next_argument();
973 my $siginfo = cfuncline_helper($type, $name, $args);
974 return "<dt>$siginfo\n<dd>" . $_;
975}
976sub do_env_cfuncdesc{
977 local($_) = @_;
978 my $type = next_argument();
979 my $name = next_argument();
980 my $args = next_argument();
981 my $siginfo = cfuncline_helper($type, $name, $args);
982 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000983 my $rcinfo = '';
984 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000985 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000986 }
987 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000988 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000989 }
Fred Drakec2578c52000-04-10 18:26:45 +0000990 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000991 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000992 }
Fred Drakee15956b2000-04-03 04:51:13 +0000993 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000994 $rcinfo = ( "\n<div class=\"refcount-info\">"
995 . "\n <span class=\"label\">Return value:</span>"
996 . "\n <span class=\"value\">$rcinfo.</span>"
997 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000998 }
Fred Drake2fc88a62003-08-05 03:45:37 +0000999 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001000 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001001 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001002 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001003}
1004
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001005sub do_cmd_cmemberline{
1006 local($_) = @_;
1007 my $container = next_argument();
1008 my $type = next_argument();
1009 my $name = next_argument();
1010 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001011 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001012 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001013 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001014 . $_;
1015}
1016sub do_env_cmemberdesc{
1017 local($_) = @_;
1018 my $container = next_argument();
1019 my $type = next_argument();
1020 my $name = next_argument();
1021 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001022 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001023 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001024 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001025 . $_
1026 . '</dl>';
1027}
1028
Fred Drakee15956b2000-04-03 04:51:13 +00001029sub do_env_csimplemacrodesc{
1030 local($_) = @_;
1031 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001032 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001033 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001034 . $_
1035 . '</dl>'
1036}
1037
Fred Drake6659c301998-03-03 22:02:19 +00001038sub do_env_ctypedesc{
1039 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001040 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001041 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001042 $index_name = $type_name
1043 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001044 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001045 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001046 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1047 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001048 . $_
1049 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001050}
1051
1052sub do_env_cvardesc{
1053 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001054 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001055 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001056 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001057 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001058 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001059 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001060 . '<dd>'
1061 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001062 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001063}
1064
Fred Drake3cdb89d2000-09-14 20:17:23 +00001065sub convert_args($){
1066 local($IN_DESC_HANDLER) = 1;
1067 local($_) = @_;
1068 return translate_commands($_);
1069}
1070
Fred Drakef6e90272002-06-18 18:24:16 +00001071sub funcline_helper($$$){
1072 my($first, $idxitem, $arglist) = @_;
1073 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001074 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1075 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001076 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001077}
1078
Fred Drake6659c301998-03-03 22:02:19 +00001079sub do_env_funcdesc{
1080 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001081 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001082 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001083 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1084 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001085 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001086 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001087 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001088 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001089}
1090
1091sub do_env_funcdescni{
1092 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001093 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001094 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001095 my $prefix = "<tt class=\"function\">$function_name</tt>";
1096 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001097}
1098
1099sub do_cmd_funcline{
1100 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001101 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001102 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001103 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001104 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1105 $prefix =~ s/\(\)//;
1106
Fred Drakef6e90272002-06-18 18:24:16 +00001107 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001108}
1109
Fred Drake6b3fb781999-07-12 16:50:09 +00001110sub do_cmd_funclineni{
1111 local($_) = @_;
1112 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001113 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001114 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001115
Fred Drakef6e90272002-06-18 18:24:16 +00001116 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001117}
1118
Fred Drake6659c301998-03-03 22:02:19 +00001119# Change this flag to index the opcode entries. I don't think it's very
1120# useful to index them, since they're only presented to describe the dis
1121# module.
1122#
1123$INDEX_OPCODES = 0;
1124
1125sub do_env_opcodedesc{
1126 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001127 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001128 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001129 my $idx;
1130 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001131 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001132 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001133 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001134 }
1135 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001136 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001137 }
1138 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001139 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001140 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001141 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001142 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001143}
1144
1145sub do_env_datadesc{
1146 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001147 my $dataname = next_argument();
1148 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001149 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001150 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001151 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001152 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001153}
1154
1155sub do_env_datadescni{
1156 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001157 my $idx = next_argument();
1158 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001159 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001160 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001161 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001162}
1163
1164sub do_cmd_dataline{
1165 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001166 my $data_name = next_argument();
1167 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001168 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001169 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001170}
1171
Fred Drakeadb272c2000-04-10 17:47:14 +00001172sub do_cmd_datalineni{
1173 local($_) = @_;
1174 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001175 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001176}
1177
Fred Drake42b31a51998-03-27 05:16:10 +00001178sub do_env_excdesc{
1179 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001180 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001181 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001182 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001183 . "\n<dd>"
1184 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001185 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001186}
1187
Fred Drake62e43691998-08-10 19:40:44 +00001188sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001189
1190
Fred Drakef5478632002-05-23 17:59:16 +00001191sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001192 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001193 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001194 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001195 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001196 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001197 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001198 my $prefix = "$TLSTART$what$TLEND$idx";
1199 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001200}
1201
Fred Drake643d76d2000-09-09 06:07:37 +00001202sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001203 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001204}
1205
Fred Drake06a01e82001-05-11 01:00:30 +00001206sub do_env_classdescstar{
1207 local($_) = @_;
1208 $THIS_CLASS = next_argument();
1209 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001210 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001211 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001212 my $prefix = "${TLSTART}class$TLEND$idx";
1213 # Can't use funcline_helper() since there is no args list.
1214 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001215}
1216
Fred Drake643d76d2000-09-09 06:07:37 +00001217sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001218 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001219}
1220
Fred Drake42b31a51998-03-27 05:16:10 +00001221
1222sub do_env_methoddesc{
1223 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001224 my $class_name = next_optional_argument();
1225 $class_name = $THIS_CLASS
1226 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001227 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001228 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001229 my $extra = '';
1230 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001231 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001232 }
Fred Drakef1927a62001-06-20 21:29:30 +00001233 my $idx = make_str_index_entry(
1234 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001235 $idx =~ s/ \(.*\)//;
1236 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001237 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001238}
1239
1240
Fred Drake7d45f6d1999-01-05 14:39:27 +00001241sub do_cmd_methodline{
1242 local($_) = @_;
1243 my $class_name = next_optional_argument();
1244 $class_name = $THIS_CLASS
1245 unless $class_name;
1246 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001247 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001248 my $extra = '';
1249 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001250 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001251 }
Fred Drakef1927a62001-06-20 21:29:30 +00001252 my $idx = make_str_index_entry(
1253 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001254 $idx =~ s/ \(.*\)//;
1255 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001256 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001257}
1258
1259
Fred Draked64a40d1998-09-10 18:59:13 +00001260sub do_cmd_methodlineni{
1261 local($_) = @_;
1262 next_optional_argument();
1263 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001264 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001265 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001266}
1267
Fred Drake42b31a51998-03-27 05:16:10 +00001268sub do_env_methoddescni{
1269 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001270 next_optional_argument();
1271 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001272 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001273 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001274}
1275
1276
1277sub do_env_memberdesc{
1278 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001279 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001280 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001281 $class = $THIS_CLASS
1282 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001283 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001284 $extra = " ($class attribute)"
1285 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001286 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001287 $idx =~ s/ \(.*\)//;
1288 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001289 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001290}
1291
1292
Fred Drake5ccf3301998-04-17 20:04:09 +00001293sub do_cmd_memberline{
1294 local($_) = @_;
1295 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001296 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001297 $class = $THIS_CLASS
1298 unless $class;
1299 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001300 $extra = " ($class attribute)"
1301 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001302 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001303 $idx =~ s/ \(.*\)//;
1304 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001305 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001306}
1307
Fred Drakef269e592001-07-17 23:05:57 +00001308
Fred Drake42b31a51998-03-27 05:16:10 +00001309sub do_env_memberdescni{
1310 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001311 next_optional_argument();
1312 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001313 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001314 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001315 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001316}
1317
1318
Fred Drake5ccf3301998-04-17 20:04:09 +00001319sub do_cmd_memberlineni{
1320 local($_) = @_;
1321 next_optional_argument();
1322 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001323 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001324}
1325
Fred Drakef269e592001-07-17 23:05:57 +00001326
1327@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001328
Fred Drakecb199762001-08-16 21:56:24 +00001329%FontConversions = ('cdata' => 'tt class="cdata"',
1330 'character' => 'tt class="character"',
1331 'class' => 'tt class="class"',
1332 'command' => 'code',
1333 'constant' => 'tt class="constant"',
1334 'exception' => 'tt class="exception"',
1335 'file' => 'tt class="file"',
1336 'filenq' => 'tt class="file"',
1337 'kbd' => 'kbd',
1338 'member' => 'tt class="member"',
1339 'programopt' => 'b',
1340 'textrm' => '',
1341 );
1342
Fred Drakef5478632002-05-23 17:59:16 +00001343sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001344 # do a little magic on a font name to get the right behavior in the first
1345 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001346 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001347 if (defined $FontConversions{$font}) {
1348 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001349 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001350 return $font;
1351}
1352
Fred Drakef5478632002-05-23 17:59:16 +00001353sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001354 my $a = $_[0];
1355 if (!defined $a) {
1356 return '';
1357 }
Fred Drakee15956b2000-04-03 04:51:13 +00001358 my $mark = substr($a, 0, 1);
1359 my $r = '';
1360 if ($mark eq 'c')
1361 { $r = ' align="center"'; }
1362 elsif ($mark eq 'r')
1363 { $r = ' align="right"'; }
1364 elsif ($mark eq 'l')
1365 { $r = ' align="left"'; }
1366 elsif ($mark eq 'p')
1367 { $r = ' align="left"'; }
1368 return $r;
1369}
1370
Fred Drakef5478632002-05-23 17:59:16 +00001371sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001372 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001373 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001374 my $a1 = figure_column_alignment($s1);
1375 my $a2 = figure_column_alignment($s2);
1376 my $a3 = figure_column_alignment($s3);
1377 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001378 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001379 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1380 $col_aligns[1] = "<td$a2>";
1381 $col_aligns[2] = "<td$a3>";
1382 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001383 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001384 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001385 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001386}
1387
Fred Drakef5478632002-05-23 17:59:16 +00001388sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001389 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001390 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001391 if ($font) {
1392 $sfont = "<$font>";
1393 $efont = "</$font>";
1394 $efont =~ s/ .*>/>/;
1395 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001396 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001397}
1398
1399sub do_env_tableii{
1400 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001401 my $arg = next_argument();
1402 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001403 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001404 my $h1 = next_argument();
1405 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001406 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001407 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001408 my $a1 = $col_aligns[0];
1409 my $a2 = $col_aligns[1];
1410 s/\\lineii</\\lineii[$a1|$a2]</g;
1411 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001412 . "\n <thead>"
1413 . "\n <tr class=\"tableheader\">"
1414 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1415 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1416 . "\n </tr>"
1417 . "\n </thead>"
1418 . "\n <tbody valign=\"baseline\">"
1419 . $_
1420 . "\n </tbody>"
1421 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001422}
1423
Fred Drakeda72b932000-09-21 15:58:02 +00001424sub do_env_longtableii{
1425 return do_env_tableii(@_);
1426}
1427
Fred Drake6659c301998-03-03 22:02:19 +00001428sub do_cmd_lineii{
1429 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001430 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001431 my $c1 = next_argument();
1432 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001433 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001434 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001435 $c1 = '&nbsp;' if ($c1 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001436 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001437 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001438 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001439 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001440 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001441 }
Fred Drakee15956b2000-04-03 04:51:13 +00001442 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1443 . " $c2align$c2</td>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001444 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001445}
1446
1447sub do_env_tableiii{
1448 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001449 my $arg = next_argument();
1450 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001451 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001452 my $h1 = next_argument();
1453 my $h2 = next_argument();
1454 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001455 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001456 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001457 my $a1 = $col_aligns[0];
1458 my $a2 = $col_aligns[1];
1459 my $a3 = $col_aligns[2];
1460 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1461 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001462 . "\n <thead>"
1463 . "\n <tr class=\"tableheader\">"
1464 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1465 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1466 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1467 . "\n </tr>"
1468 . "\n </thead>"
1469 . "\n <tbody valign=\"baseline\">"
1470 . $_
1471 . "\n </tbody>"
1472 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001473}
1474
Fred Drakeda72b932000-09-21 15:58:02 +00001475sub do_env_longtableiii{
1476 return do_env_tableiii(@_);
1477}
1478
Fred Drake6659c301998-03-03 22:02:19 +00001479sub do_cmd_lineiii{
1480 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001481 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001482 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001483 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001484 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001485 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001486 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001487 $c1 = '&nbsp;' if ($c1 eq '');
1488 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001489 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001490 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001491 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001492 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001493 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001494 }
Fred Drakee15956b2000-04-03 04:51:13 +00001495 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001496 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001497 . " $c3align$c3</td>"
1498 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001499}
1500
Fred Drakea0f4c941998-07-24 22:16:04 +00001501sub do_env_tableiv{
1502 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001503 my $arg = next_argument();
1504 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001505 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001506 my $h1 = next_argument();
1507 my $h2 = next_argument();
1508 my $h3 = next_argument();
1509 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001510 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001511 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001512 my $a1 = $col_aligns[0];
1513 my $a2 = $col_aligns[1];
1514 my $a3 = $col_aligns[2];
1515 my $a4 = $col_aligns[3];
1516 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1517 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001518 . "\n <thead>"
1519 . "\n <tr class=\"tableheader\">"
1520 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1521 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1522 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1523 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1524 . "\n </tr>"
1525 . "\n </thead>"
1526 . "\n <tbody valign=\"baseline\">"
1527 . $_
1528 . "\n </tbody>"
1529 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001530}
1531
Fred Drakeda72b932000-09-21 15:58:02 +00001532sub do_env_longtableiv{
1533 return do_env_tableiv(@_);
1534}
1535
Fred Drakea0f4c941998-07-24 22:16:04 +00001536sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001537 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001538 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001539 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001540 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001541 my $c3 = next_argument();
1542 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001543 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001544 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001545 $c1 = '&nbsp;' if ($c1 eq '');
1546 $c2 = '&nbsp;' if ($c2 eq '');
1547 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001548 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001549 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001550 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001551 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001552 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001553 }
Fred Drakee15956b2000-04-03 04:51:13 +00001554 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001555 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001556 . " $c3align$c3</td>\n"
1557 . " $c4align$c4</td>"
1558 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001559}
1560
Fred Drakef269e592001-07-17 23:05:57 +00001561sub do_env_tablev{
1562 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001563 my $arg = next_argument();
1564 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001565 my $font = fix_font(next_argument());
1566 my $h1 = next_argument();
1567 my $h2 = next_argument();
1568 my $h3 = next_argument();
1569 my $h4 = next_argument();
1570 my $h5 = next_argument();
1571 s/[\s\n]+//;
1572 $globals{'lineifont'} = $font;
1573 my $a1 = $col_aligns[0];
1574 my $a2 = $col_aligns[1];
1575 my $a3 = $col_aligns[2];
1576 my $a4 = $col_aligns[3];
1577 my $a5 = $col_aligns[4];
1578 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1579 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001580 . "\n <thead>"
1581 . "\n <tr class=\"tableheader\">"
1582 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1583 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1584 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1585 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1586 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1587 . "\n </tr>"
1588 . "\n </thead>"
1589 . "\n <tbody valign=\"baseline\">"
1590 . $_
1591 . "\n </tbody>"
1592 . "\n</table>";
Fred Drakef269e592001-07-17 23:05:57 +00001593}
1594
1595sub do_env_longtablev{
1596 return do_env_tablev(@_);
1597}
1598
1599sub do_cmd_linev{
1600 local($_) = @_;
1601 my $aligns = next_optional_argument();
1602 my $c1 = next_argument();
1603 my $c2 = next_argument();
1604 my $c3 = next_argument();
1605 my $c4 = next_argument();
1606 my $c5 = next_argument();
1607 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001608 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001609 $c1 = '&nbsp;' if ($c1 eq '');
1610 $c2 = '&nbsp;' if ($c2 eq '');
1611 $c3 = '&nbsp;' if ($c3 eq '');
1612 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef269e592001-07-17 23:05:57 +00001613 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001614 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001615 my $padding = '';
1616 if ($c1align =~ /align="right"/ || $c1 eq '') {
1617 $padding = '&nbsp;';
1618 }
1619 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1620 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001621 . " $c3align$c3</td>\n"
1622 . " $c4align$c4</td>\n"
1623 . " $c5align$c5</td>"
1624 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001625}
1626
Fred Drake3be20742000-08-31 06:22:54 +00001627
1628# These can be used to control the title page appearance;
1629# they need a little bit of documentation.
1630#
1631# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1632# $ICONSERVER directory, or include path information (other than "./"). The
1633# default image type will be assumed if an extension is not provided.
1634#
1635# If specified, the "title page" will contain two colums: one containing the
1636# title/author/etc., and the other containing the graphic. Use the other
1637# four variables listed here to control specific details of the layout; all
1638# are optional.
1639#
1640# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1641# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1642# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1643# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1644# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1645
Fred Drakef5478632002-05-23 17:59:16 +00001646sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001647 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001648 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001649 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001650 }
1651 else {
1652 write_warnings("\nThis document has no title.");
1653 }
Fred Drake6659c301998-03-03 22:02:19 +00001654 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001655 if ($t_authorURL) {
1656 my $href = translate_commands($t_authorURL);
1657 $href = make_named_href('author', $href,
1658 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001659 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001660 $the_title .= "\n<p>$href</p>";
1661 }
Fred Drake3be20742000-08-31 06:22:54 +00001662 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001663 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001664 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001665 }
Fred Drake3be20742000-08-31 06:22:54 +00001666 }
1667 else {
1668 write_warnings("\nThere is no author for this document.");
1669 }
Fred Drake6659c301998-03-03 22:02:19 +00001670 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001671 $the_title .= "\n<p>$t_institute</p>";
1672 }
Fred Draked07868a1998-05-14 21:00:28 +00001673 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001674 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1675 }
Fred Drake6659c301998-03-03 22:02:19 +00001676 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001677 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001678 }
Fred Drake6659c301998-03-03 22:02:19 +00001679 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001680 $the_title .= "\n<p>";
1681 if ($PACKAGE_VERSION) {
1682 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001683 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001684 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001685 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001686 }
1687 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001688 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001689 }
1690 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001691 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001692 }
Fred Drake6659c301998-03-03 22:02:19 +00001693 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001694 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001695 }
1696 return $the_title;
1697}
1698
Fred Drakef5478632002-05-23 17:59:16 +00001699sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001700 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001701 my $graphic = "<td class=\"titlegraphic\"";
1702 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1703 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1704 $graphic .= "><img";
1705 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1706 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1707 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1708 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001709 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001710 return $graphic;
1711}
1712
Fred Drakef5478632002-05-23 17:59:16 +00001713sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001714 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001715 my $the_title = "\n";
1716 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001717 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001718 # body), but I don't see any other way to get this generated
1719 # at all. Browsers like Mozilla, that support navigation
1720 # links, can make use of this.
1721 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1722 . ($EXTERNAL_UP_TITLE
1723 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001724 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001725 }
1726 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001727 if ($TITLE_PAGE_GRAPHIC) {
1728 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1729 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1730 . "<tr align=\"right\">\n<td>"
1731 . make_my_titlepage()
1732 . "</td>\n"
1733 . make_my_titlegraphic()
1734 . "</tr>\n</table>");
1735 }
1736 else {
1737 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1738 . make_my_titlegraphic()
1739 . "<td>"
1740 . make_my_titlepage()
1741 . "</td></tr>\n</table>");
1742 }
1743 }
1744 else {
1745 $the_title .= ("\n<center>"
1746 . make_my_titlepage()
1747 . "\n</center>");
1748 }
1749 $the_title .= "\n</div>";
1750 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001751 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001752 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001753}
1754
1755
Fred Drake885215c1998-05-20 21:32:09 +00001756#
Fred Drakea0f4c941998-07-24 22:16:04 +00001757# Module synopsis support
1758#
1759
1760require SynopsisTable;
1761
Fred Drakef7685d71998-07-25 03:31:46 +00001762sub get_chapter_id(){
1763 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001764 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001765 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001766 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001767}
1768
Fred Drake643d76d2000-09-09 06:07:37 +00001769# 'chapter' => 'SynopsisTable instance'
1770%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001771
1772sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001773 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001774 my $key;
1775 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001776 if ($key eq $chap) {
1777 return $ModuleSynopses{$chap};
1778 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001779 }
Fred Drake643d76d2000-09-09 06:07:37 +00001780 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001781 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001782 return $st;
1783}
1784
Fred Drake62e43691998-08-10 19:40:44 +00001785sub do_cmd_moduleauthor{
1786 local($_) = @_;
1787 next_argument();
1788 next_argument();
1789 return $_;
1790}
1791
1792sub do_cmd_sectionauthor{
1793 local($_) = @_;
1794 next_argument();
1795 next_argument();
1796 return $_;
1797}
1798
Fred Drakea0f4c941998-07-24 22:16:04 +00001799sub do_cmd_declaremodule{
1800 local($_) = @_;
1801 my $key = next_optional_argument();
1802 my $type = next_argument();
1803 my $name = next_argument();
1804 my $st = get_synopsis_table(get_chapter_id());
1805 #
1806 $key = $name unless $key;
1807 $type = 'built-in' if $type eq 'builtin';
1808 $st->declare($name, $key, $type);
1809 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001810 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001811}
1812
1813sub do_cmd_modulesynopsis{
1814 local($_) = @_;
1815 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001816 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001817 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001818}
1819
1820sub do_cmd_localmoduletable{
1821 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001822 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001823 my $st = get_synopsis_table($chap);
1824 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001825 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001826}
1827
Fred Drakef5478632002-05-23 17:59:16 +00001828sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001829 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001830 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001831 my $st = $ModuleSynopses{$key};
1832 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001833 if ($file) {
1834 process_localmoduletables_in_file($file);
1835 }
1836 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001837 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001838 }
1839 }
1840}
1841
Fred Drakef5478632002-05-23 17:59:16 +00001842sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001843 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001844 open(MYFILE, "<$file");
1845 local($_);
1846 sysread(MYFILE, $_, 1024*1024);
1847 close(MYFILE);
1848 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001849 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001850 my $match = $&;
1851 my $chap = $1;
1852 my $st = get_synopsis_table($chap);
1853 my $data = $st->tohtml();
1854 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001855 }
Fred Drake643d76d2000-09-09 06:07:37 +00001856 open(MYFILE,">$file");
1857 print MYFILE $_;
1858 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001859}
Fred Drakef5478632002-05-23 17:59:16 +00001860sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001861 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001862 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001863}
Fred Drakea0f4c941998-07-24 22:16:04 +00001864
1865
1866#
1867# "See also:" -- references placed at the end of a \section
1868#
1869
1870sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001871 return ("<div class=\"seealso\">\n "
1872 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001873 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001874 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001875}
1876
Fred Drake5ed35fd2001-11-30 18:09:54 +00001877sub do_env_seealsostar{
1878 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001879 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001880 . '</div>');
1881}
1882
Fred Drakea0f4c941998-07-24 22:16:04 +00001883sub do_cmd_seemodule{
1884 # Insert the right magic to jump to the module definition. This should
1885 # work most of the time, at least for repeat builds....
1886 local($_) = @_;
1887 my $key = next_optional_argument();
1888 my $module = next_argument();
1889 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001890 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001891 $key = $module
1892 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001893 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001894 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001895 }
Fred Drakef1927a62001-06-20 21:29:30 +00001896 return ('<dl compact class="seemodule">'
1897 . "\n <dt>Module <b><tt class=\"module\">"
1898 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1899 . "\n <dd>$text$period\n </dl>"
1900 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001901}
1902
Fred Drakee0197bf2001-04-12 04:03:22 +00001903sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001904 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001905 my $s = "$str";
1906 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1907 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1908 return $s;
1909}
1910
Fred Drakef5478632002-05-23 17:59:16 +00001911sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001912 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001913 my $rfcnum = next_argument();
1914 my $title = next_argument();
1915 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001916 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001917 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001918 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001919 return '<dl compact class="seerfc">'
1920 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001921 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001922 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001923 . "\n <dd>$text\n </dl>"
1924 . $_;
1925}
1926
Fred Drake643d76d2000-09-09 06:07:37 +00001927sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001928 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001929}
1930
1931sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001932 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001933 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001934}
1935
Fred Drake48449982000-09-12 17:52:33 +00001936sub do_cmd_seetitle{
1937 local($_) = @_;
1938 my $url = next_optional_argument();
1939 my $title = next_argument();
1940 my $text = next_argument();
1941 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001942 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001943 return '<dl compact class="seetitle">'
1944 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001945 . "\n >$title$icon</a></em></dt>"
1946 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001947 . $_;
1948 }
1949 return '<dl compact class="seetitle">'
1950 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001951 . "\n >$title</em></dt>"
1952 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001953 . $_;
1954}
1955
Fred Drake4f687b32004-01-08 14:57:27 +00001956sub do_cmd_seelink{
1957 local($_) = @_;
1958 my $url = next_argument();
1959 my $linktext = next_argument();
1960 my $text = next_argument();
1961 my $icon = get_link_icon($url);
1962 return '<dl compact class="seeurl">'
1963 . "\n <dt><a href='$url'"
1964 . "\n >$linktext$icon</a></dt>"
1965 . "\n <dd>$text</dd>\n </dl>"
1966 . $_;
1967}
1968
Fred Drakeef4d1112000-05-09 16:17:51 +00001969sub do_cmd_seeurl{
1970 local($_) = @_;
1971 my $url = next_argument();
1972 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001973 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001974 return '<dl compact class="seeurl">'
1975 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001976 . "\n class=\"url\">$url$icon</a></dt>"
1977 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001978 . $_;
1979}
1980
Fred Drakea0f4c941998-07-24 22:16:04 +00001981sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001982 local($_) = @_;
1983 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001984 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001985}
1986
1987
1988#
Fred Drake885215c1998-05-20 21:32:09 +00001989# Definition list support.
1990#
1991
1992sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001993 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001994}
1995
1996sub do_cmd_term{
1997 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001998 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001999 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00002000 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00002001 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00002002}
2003
2004
Fred Drake4e72e052003-07-15 22:00:36 +00002005# Commands listed here have process-order dependencies; these often
2006# are related to indexing operations.
2007# XXX Not sure why funclineni, methodlineni, and samp are here.
2008#
Fred Drake2ff880e1999-02-05 18:31:29 +00002009process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002010declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002011funcline # {} # {}
2012funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002013memberline # [] # {}
2014methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002015methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002016modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00002017bifuncindex # {}
2018exindex # {}
2019indexii # {} # {}
2020indexiii # {} # {} # {}
2021indexiv # {} # {} # {} # {}
2022kwindex # {}
2023obindex # {}
2024opindex # {}
2025stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002026platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002027samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002028setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002029withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002030_RAW_ARG_DEFERRED_CMDS_
2031
2032
Fred Drake8a5e6792002-04-15 18:41:31 +00002033$alltt_start = '<div class="verbatim"><pre>';
2034$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002035
Fred Drakef5478632002-05-23 17:59:16 +00002036sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002037 local ($_) = @_;
2038 local($closures,$reopens,@open_block_tags);
2039
2040 # get the tag-strings for all open tags
2041 local(@keep_open_tags) = @$open_tags_R;
2042 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2043
2044 # get the tags for text-level tags only
2045 $open_tags_R = [ @keep_open_tags ];
2046 local($local_closures, $local_reopens);
2047 ($local_closures, $local_reopens,@open_block_tags)
2048 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002049 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002050
2051 $open_tags_R = [ @open_block_tags ];
2052
2053 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002054 local($open_tags_R) = [ @open_block_tags ];
2055 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002056
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002057 local($cnt) = ++$global{'max_id'};
2058 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2059 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002060
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002061 $_ = &translate_environments($_);
2062 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002063
Fred Drake41aa0182003-09-05 15:43:00 +00002064 # remove spurious <BR> someone sticks in; not sure where they
2065 # actually come from
2066 # XXX the replacement space is there to accomodate something
2067 # broken that inserts a space in front of the first line of
2068 # the environment
2069 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002070
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002071 $_ = join('', $closures, $alltt_start, $local_reopens
2072 , $_
2073 , &balance_tags() #, $local_closures
2074 , $alltt_end, $reopens);
2075 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002076 };
2077 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002078 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002079}
2080
Fred Drake345555d2003-12-30 16:19:28 +00002081# List of all filenames produced my do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002082%VerbatimFiles = ();
2083@VerbatimOutputs = ();
2084
2085sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002086 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002087 #
2088 # Re-write the source filename to always use a .txt extension
2089 # so that Web servers will present it as text/plain. This is
2090 # needed since there is no other even moderately reliable way
2091 # to get the right Content-Type header on text files for
2092 # servers which we can't configure (like python.org mirrors).
2093 #
2094 if (defined $VerbatimFiles{$file}) {
2095 # We've seen this one before; re-use the same output file.
2096 return $VerbatimFiles{$file};
2097 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002098 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002099 $filename = "$srcname.txt";
2100 #
2101 # We need to determine if our default filename is already
2102 # being used, and find a new one it it is. If the name is in
2103 # used, this algorithm will first attempt to include the
2104 # source extension as part of the name, and if that is also in
2105 # use (if the same file is included multiple times, or if
2106 # another source file has that as the base name), a counter is
2107 # used instead.
2108 #
2109 my $found = 1;
2110 FIND:
2111 while ($found) {
2112 foreach $fn (@VerbatimOutputs) {
2113 if ($fn eq $filename) {
2114 if ($found == 1) {
2115 $srcext =~ s/^[.]//; # Remove '.' from extension
2116 $filename = "$srcname-$srcext.txt";
2117 }
2118 else {
2119 $filename = "$srcname-$found.txt";
2120 }
2121 ++$found;
2122 next FIND;
2123 }
2124 }
2125 $found = 0;
2126 }
2127 push @VerbatimOutputs, $filename;
2128 $VerbatimFiles{$file} = $filename;
2129 return $filename;
2130}
2131
Fred Drake57e52ef2001-06-15 21:31:57 +00002132sub do_cmd_verbatiminput{
2133 local($_) = @_;
2134 my $fname = next_argument();
2135 my $file;
2136 my $found = 0;
2137 my $texpath;
2138 # Search TEXINPUTS for the input file, the way we're supposed to:
2139 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2140 $file = "$texpath$dd$fname";
2141 last if ($found = (-f $file));
2142 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002143 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002144 my $text;
2145 if ($found) {
2146 open(MYFILE, "<$file") || die "\n$!\n";
2147 read(MYFILE, $text, 1024*1024);
2148 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002149 $filename = get_verbatim_output_name($file);
2150 # Now that we have a filename, write it out.
2151 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002152 print MYFILE $text;
2153 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002154 #
2155 # These rewrites convert the raw text to something that will
2156 # be properly visible as HTML and also will pass through the
2157 # vagaries of conversion through LaTeX2HTML. The order in
2158 # which the specific rewrites are performed is significant.
2159 #
2160 $text =~ s/\&/\&amp;/g;
2161 # These need to happen before the normal < and > re-writes,
2162 # since we need to avoid LaTeX2HTML's attempt to perform
2163 # ligature processing without regard to context (since it
2164 # doesn't have font information).
2165 $text =~ s/--/-&\#45;/g;
2166 $text =~ s/<</\&lt;\&\#60;/g;
2167 $text =~ s/>>/\&gt;\&\#62;/g;
2168 # Just normal re-writes...
2169 $text =~ s/</\&lt;/g;
2170 $text =~ s/>/\&gt;/g;
2171 # These last isn't needed for the HTML, but is needed to get
2172 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2173 # of &sol; since many browsers don't support that.
2174 $text =~ s/\\/\&\#92;/g;
2175 }
2176 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002177 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2178 }
2179 my $note = 'Download as text.';
2180 if ($file ne $filename) {
2181 $note = ('Download as text (original file name: <span class="file">'
2182 . $fname
2183 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002184 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002185 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002186 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002187 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002188 . "<a href=\"$filename\" type=\"text/plain\""
2189 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002190 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002191 . $_);
2192}
Fred Drake86333602001-04-10 17:13:39 +00002193
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021941; # This must be the last line