blob: c7f2ffb5b6dfefe203fe2777762eb324de4d7574 [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 Drake0c1b2532004-10-29 19:47:52 +0000361 return ("<a class=\"rfc\" id='$id' xml: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 Drake0c1b2532004-10-29 19:47:52 +0000374 return ("<a class=\"rfc\" id='$id' xml: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 Drake0c1b2532004-10-29 19:47:52 +0000528 my $aname = "<a id='$name' xml: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();
Fred Drake0c1b2532004-10-29 19:47:52 +0000535 my $aname = "<a id='$name' xml: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 Drake899072a2004-04-08 15:30:12 +0000582# XXX I don't remember why I added this to begin with.
583# if (/^[ \t\r\n]/) {
584# $_ = substr($_, 1);
585# }
Fred Drake62e43691998-08-10 19:40:44 +0000586 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000587}
588
Fred Drakeab032151999-05-13 18:36:54 +0000589define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000590sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000591 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000592 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000593}
594
Fred Drakeab032151999-05-13 18:36:54 +0000595define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000596sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000597 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000598 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
599 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000600}
601
602define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000603sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000604 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000605 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000606 add_index_entry("$str1!$str2", $_[0]);
607 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000608}
609
Fred Drakeab032151999-05-13 18:36:54 +0000610define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000611sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000612 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000613 my $str2 = next_argument();
614 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000615 add_index_entry("$str1!$str2 $str3", $_[0]);
616 add_index_entry("$str2!$str3, $str1", $_[0]);
617 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000618}
619
Fred Drakeab032151999-05-13 18:36:54 +0000620define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000621sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000622 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000623 my $str2 = next_argument();
624 my $str3 = next_argument();
625 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000626 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
627 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
628 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
629 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000630}
631
Fred Drakeab032151999-05-13 18:36:54 +0000632define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000633sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000634 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000635 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000636 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000637}
Fred Drake6659c301998-03-03 22:02:19 +0000638
Fred Drakef5478632002-05-23 17:59:16 +0000639sub my_typed_index_helper($$){
640 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000641 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000642 add_index_entry("$str $word", $ahref);
643 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000644}
645
Fred Drakeab032151999-05-13 18:36:54 +0000646define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000647sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
648sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
649sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
650sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000651
Fred Drakeab032151999-05-13 18:36:54 +0000652define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000653sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000654 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000655 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000656 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000657}
658
659
Fred Drakef5478632002-05-23 17:59:16 +0000660sub make_mod_index_entry($$){
661 my($str, $define) = @_;
662 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000663 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000664 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
665 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000666 $str = gen_index_id($str, $define);
667 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000668 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000669
Fred Drakec9a44381998-03-17 06:29:13 +0000670 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000671 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000672 $str =~ /(<tt.*<\/tt>)/;
673 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000674 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000675 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000676 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000677}
678
Fred Drake557460c1999-03-02 16:05:35 +0000679
Fred Drakec9a44381998-03-17 06:29:13 +0000680$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000681$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000682
Fred Drakef5478632002-05-23 17:59:16 +0000683sub define_module($$){
684 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000685 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000686 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000687 && $word ne "standard" && $word ne "") {
688 write_warnings("Bad module type '$word'"
689 . " for \\declaremodule (module $name)");
690 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000691 }
Fred Drake6659c301998-03-03 22:02:19 +0000692 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000693 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000694 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000695 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000696 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000697 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000698}
699
Fred Drakef5478632002-05-23 17:59:16 +0000700sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000701 local($word, $_) = @_;
702 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000703 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000704}
705
Fred Drake49b33fa2002-11-15 19:04:10 +0000706sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
707sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
708sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
709sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
710# local($_) = @_;
711# my $name = next_argument();
712# return define_module('standard', $name) . $_;
713# }
Fred Drake6659c301998-03-03 22:02:19 +0000714
Fred Drakef5478632002-05-23 17:59:16 +0000715sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000716 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000717 my $str = next_argument();
718 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000719 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000720 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
721 # just inline it all here
722 $str = gen_index_id($str, 'REF');
723 $index{$str} .= $ahref;
724 write_idxfile($ahref, $str);
725}
726
Fred Drake6659c301998-03-03 22:02:19 +0000727# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000728define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000729 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000730sub idx_cmd_refmodindex($){
731 return ref_module_index_helper('', $_[0]); }
732sub idx_cmd_refbimodindex($){
733 return ref_module_index_helper('built-in', $_[0]); }
734sub idx_cmd_refexmodindex($){
735 return ref_module_index_helper('extension', $_[0]);}
736sub idx_cmd_refstmodindex($){
737 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000738
Fred Drake49b33fa2002-11-15 19:04:10 +0000739sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000740
Fred Drakef5478632002-05-23 17:59:16 +0000741sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000742 # These markers must be non-empty or the main latex2html script
743 # may remove a surrounding element that has not other content as
744 # "extraneous"; this ensures these elements (usually hyperlink
745 # targets) are not removed improperly. We use comments since
746 # there's no meaningful actual content.
747 # Thanks to Dave Kuhlman for figuring why some named anchors were
748 # being lost.
749 $anchor_invisible_mark = '<!--x-->';
750 $anchor_invisible_mark2 = '<!--y-->';
751 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000752 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000753}
Fred Drake42b31a51998-03-27 05:16:10 +0000754init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000755
Fred Drakeab032151999-05-13 18:36:54 +0000756# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000757# instead of the dummy filler.
758#
Fred Drakef5478632002-05-23 17:59:16 +0000759sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000760 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000761 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000762 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000763 if ($str =~ /^<[a-z]+\b/) {
764 my $s = "$str";
Fred Drake0c1b2532004-10-29 19:47:52 +0000765 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
Fred Drake04bf7242003-11-26 20:55:49 +0000766 return $s;
767 }
768 else {
Fred Drake0c1b2532004-10-29 19:47:52 +0000769 return "<a id='$name' xml:id='$name'>$str</a>";
Fred Drake04bf7242003-11-26 20:55:49 +0000770 }
Fred Drake6659c301998-03-03 22:02:19 +0000771}
772
Fred Drake77602f22001-07-06 22:43:02 +0000773
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000774%TokenToTargetMapping = (); # language:token -> link target
775%DefinedGrammars = (); # language -> full grammar text
776%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000777
778sub do_cmd_token{
779 local($_) = @_;
780 my $token = next_argument();
781 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
782 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
783 # recursive definition or display-only productionlist
784 return "$token";
785 }
786 if ($target eq '') {
787 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
788 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
789 print "Adding '$CURRENT_FILE' to back-patch list.\n";
790 }
791 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
792 }
793 return "<a href=\"$target\">$token</a>" . $_;
794}
795
Fred Drake16bb4192001-08-20 21:36:38 +0000796sub do_cmd_grammartoken{
797 return do_cmd_token(@_);
798}
799
Fred Drake77602f22001-07-06 22:43:02 +0000800sub do_env_productionlist{
801 local($_) = @_;
802 my $lang = next_optional_argument();
803 my $filename = "grammar-$lang.txt";
804 if ($lang eq '') {
805 $filename = 'grammar.txt';
806 }
807 local($CURRENT_GRAMMAR) = $lang;
808 $DefinedGrammars{$lang} .= $_;
809 return ("<dl><dd class=\"grammar\">\n"
810 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000811 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000812 . translate_commands(translate_environments($_))
813 . "</table>\n"
814 . "</div>\n"
815 . (($lang eq '*')
816 ? ''
817 : ("<a class=\"grammar-footer\"\n"
818 . " href=\"$filename\" type=\"text/plain\"\n"
819 . " >Download entire grammar as text.</a>\n"))
820 . "</dd></dl>");
821}
822
823sub do_cmd_production{
824 local($_) = @_;
825 my $token = next_argument();
826 my $defn = next_argument();
827 my $lang = $CURRENT_GRAMMAR;
828 local($CURRENT_TOKEN) = $token;
829 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000830 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000831 . " <td><code>$token</code></td>\n"
832 . " <td>&nbsp;::=&nbsp;</td>\n"
833 . " <td><code>"
834 . translate_commands($defn)
835 . "</code></td></tr>"
836 . $_);
837 }
838 my $target;
839 if ($lang eq '') {
840 $target = "$CURRENT_FILE\#tok-$token";
841 }
842 else {
843 $target = "$CURRENT_FILE\#tok-$lang-$token";
844 }
845 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000846 return ("<tr valign=\"baseline\">\n"
Fred Drake0c1b2532004-10-29 19:47:52 +0000847 . " <td><code><a id='tok-$token' xml:id='tok-$token'>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000848 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000849 . " <td>&nbsp;::=&nbsp;</td>\n"
850 . " <td><code>"
851 . translate_commands($defn)
852 . "</code></td></tr>"
853 . $_);
854}
855
Fred Drake53815882002-03-15 23:21:37 +0000856sub do_cmd_productioncont{
857 local($_) = @_;
858 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000859 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000860 return ("<tr valign=\"baseline\">\n"
861 . " <td>&nbsp;</td>\n"
862 . " <td>&nbsp;</td>\n"
863 . " <td><code>"
864 . translate_commands($defn)
865 . "</code></td></tr>"
866 . $_);
867}
868
Fred Drakef5478632002-05-23 17:59:16 +0000869sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000870 my $lang;
871 my $filename;
872 local($_);
873 print "process_grammar_files()\n";
874 foreach $lang (keys %DefinedGrammars) {
875 $filename = "grammar-$lang.txt";
876 if ($lang eq '*') {
877 next;
878 }
879 if ($lang eq '') {
880 $filename = 'grammar.txt';
881 }
882 open(GRAMMAR, ">$filename") || die "\n$!\n";
883 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
884 close(GRAMMAR);
885 print "Wrote grammar file $filename\n";
886 }
887 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
888 foreach $filename (keys %BackpatchGrammarFiles) {
889 print "\nBack-patching grammar links in $filename\n";
890 my $buffer;
891 open(GRAMMAR, "<$filename") || die "\n$!\n";
892 # read all of the file into the buffer
893 sysread(GRAMMAR, $buffer, 1024*1024);
894 close(GRAMMAR);
895 while ($buffer =~ /$PATTERN/) {
896 my($lang, $token) = ($1, $2);
897 my $target = $TokenToTargetMapping{"$lang:$token"};
898 my $source = "<pyGrammarToken><$lang><$token>";
899 $buffer =~ s/$source/$target/g;
900 }
901 open(GRAMMAR, ">$filename") || die "\n$!\n";
902 print GRAMMAR $buffer;
903 close(GRAMMAR);
904 }
905}
906
Fred Drakef5478632002-05-23 17:59:16 +0000907sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000908 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000909 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000910 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
911 s/\\token(<<\d+>>)(.+)\1/$2/g;
912 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000913 s/<<\d+>>//g;
914 s/;SPMgt;/>/g;
915 s/;SPMlt;/</g;
916 s/;SPMquot;/\"/g;
917 return $_;
918}
919
920
Fred Drakee15956b2000-04-03 04:51:13 +0000921$REFCOUNTS_LOADED = 0;
922
Fred Drakef5478632002-05-23 17:59:16 +0000923sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000924 $REFCOUNTS_LOADED = 1;
925
Fred Drake49b33fa2002-11-15 19:04:10 +0000926 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000927 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000928 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000929 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000930 $mydir = getcwd() . "$dd$mydir"
931 unless $mydir =~ s|^/|/|;
932 local $_;
933 my $filename = "$mydir${dd}api${dd}refcounts.dat";
934 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
935 print "[loading API refcount data]";
936 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000937 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000938 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
939 #print "\n$func($param) --> $count";
940 $REFCOUNTS{"$func:$param"} = $count;
941 }
942 }
943}
944
Fred Drakef5478632002-05-23 17:59:16 +0000945sub get_refcount($$){
946 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000947 load_refcounts()
948 unless $REFCOUNTS_LOADED;
949 return $REFCOUNTS{"$func:$param"};
950}
951
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000952
953$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000954$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000955
Fred Drakef5478632002-05-23 17:59:16 +0000956sub cfuncline_helper($$$){
957 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000958 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000959 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000960 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000961 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000962 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
963 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000964 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
965 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
966 . "<td>$args)</td>"
967 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000968}
969sub do_cmd_cfuncline{
970 local($_) = @_;
971 my $type = next_argument();
972 my $name = next_argument();
973 my $args = next_argument();
974 my $siginfo = cfuncline_helper($type, $name, $args);
975 return "<dt>$siginfo\n<dd>" . $_;
976}
977sub do_env_cfuncdesc{
978 local($_) = @_;
979 my $type = next_argument();
980 my $name = next_argument();
981 my $args = next_argument();
982 my $siginfo = cfuncline_helper($type, $name, $args);
983 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000984 my $rcinfo = '';
985 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000986 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000987 }
988 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000989 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000990 }
Fred Drakec2578c52000-04-10 18:26:45 +0000991 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000992 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000993 }
Fred Drakee15956b2000-04-03 04:51:13 +0000994 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000995 $rcinfo = ( "\n<div class=\"refcount-info\">"
996 . "\n <span class=\"label\">Return value:</span>"
997 . "\n <span class=\"value\">$rcinfo.</span>"
998 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000999 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001000 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001001 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001002 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001003 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001004}
1005
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001006sub do_cmd_cmemberline{
1007 local($_) = @_;
1008 my $container = next_argument();
1009 my $type = next_argument();
1010 my $name = next_argument();
1011 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001012 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001013 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001014 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001015 . $_;
1016}
1017sub do_env_cmemberdesc{
1018 local($_) = @_;
1019 my $container = next_argument();
1020 my $type = next_argument();
1021 my $name = next_argument();
1022 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001023 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001024 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001025 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001026 . $_
1027 . '</dl>';
1028}
1029
Fred Drakee15956b2000-04-03 04:51:13 +00001030sub do_env_csimplemacrodesc{
1031 local($_) = @_;
1032 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001033 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001034 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001035 . $_
1036 . '</dl>'
1037}
1038
Fred Drake6659c301998-03-03 22:02:19 +00001039sub do_env_ctypedesc{
1040 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001041 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001042 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001043 $index_name = $type_name
1044 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001045 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001046 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001047 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1048 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001049 . $_
1050 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001051}
1052
1053sub do_env_cvardesc{
1054 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001055 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001056 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001057 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001058 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001059 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001060 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001061 . '<dd>'
1062 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001063 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001064}
1065
Fred Drake3cdb89d2000-09-14 20:17:23 +00001066sub convert_args($){
1067 local($IN_DESC_HANDLER) = 1;
1068 local($_) = @_;
1069 return translate_commands($_);
1070}
1071
Fred Drakef6e90272002-06-18 18:24:16 +00001072sub funcline_helper($$$){
1073 my($first, $idxitem, $arglist) = @_;
1074 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001075 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1076 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001077 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001078}
1079
Fred Drake6659c301998-03-03 22:02:19 +00001080sub do_env_funcdesc{
1081 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001082 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001083 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001084 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1085 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001086 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001087 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001088 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001089 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001090}
1091
1092sub do_env_funcdescni{
1093 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001094 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001095 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001096 my $prefix = "<tt class=\"function\">$function_name</tt>";
1097 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001098}
1099
1100sub do_cmd_funcline{
1101 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001102 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001103 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001104 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001105 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1106 $prefix =~ s/\(\)//;
1107
Fred Drakef6e90272002-06-18 18:24:16 +00001108 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001109}
1110
Fred Drake6b3fb781999-07-12 16:50:09 +00001111sub do_cmd_funclineni{
1112 local($_) = @_;
1113 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001114 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001115 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001116
Fred Drakef6e90272002-06-18 18:24:16 +00001117 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001118}
1119
Fred Drake6659c301998-03-03 22:02:19 +00001120# Change this flag to index the opcode entries. I don't think it's very
1121# useful to index them, since they're only presented to describe the dis
1122# module.
1123#
1124$INDEX_OPCODES = 0;
1125
1126sub do_env_opcodedesc{
1127 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001128 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001129 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001130 my $idx;
1131 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001132 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001133 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001134 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001135 }
1136 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001137 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001138 }
1139 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001140 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001141 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001142 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001143 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001144}
1145
1146sub do_env_datadesc{
1147 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001148 my $dataname = next_argument();
1149 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001150 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001151 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001152 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001153 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001154}
1155
1156sub do_env_datadescni{
1157 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001158 my $idx = next_argument();
1159 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001160 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001161 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001162 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001163}
1164
1165sub do_cmd_dataline{
1166 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001167 my $data_name = next_argument();
1168 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001169 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001170 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001171}
1172
Fred Drakeadb272c2000-04-10 17:47:14 +00001173sub do_cmd_datalineni{
1174 local($_) = @_;
1175 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001176 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001177}
1178
Fred Drake42b31a51998-03-27 05:16:10 +00001179sub do_env_excdesc{
1180 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001181 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001182 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001183 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001184 . "\n<dd>"
1185 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001186 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001187}
1188
Fred Drake62e43691998-08-10 19:40:44 +00001189sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001190
1191
Fred Drakef5478632002-05-23 17:59:16 +00001192sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001193 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001194 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001195 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001196 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001197 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001198 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001199 my $prefix = "$TLSTART$what$TLEND$idx";
1200 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001201}
1202
Fred Drake643d76d2000-09-09 06:07:37 +00001203sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001204 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001205}
1206
Fred Drake06a01e82001-05-11 01:00:30 +00001207sub do_env_classdescstar{
1208 local($_) = @_;
1209 $THIS_CLASS = next_argument();
1210 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001211 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001212 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001213 my $prefix = "${TLSTART}class$TLEND$idx";
1214 # Can't use funcline_helper() since there is no args list.
1215 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001216}
1217
Fred Drake643d76d2000-09-09 06:07:37 +00001218sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001219 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001220}
1221
Fred Drake42b31a51998-03-27 05:16:10 +00001222
1223sub do_env_methoddesc{
1224 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001225 my $class_name = next_optional_argument();
1226 $class_name = $THIS_CLASS
1227 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001228 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001229 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001230 my $extra = '';
1231 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001232 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001233 }
Fred Drakef1927a62001-06-20 21:29:30 +00001234 my $idx = make_str_index_entry(
1235 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001236 $idx =~ s/ \(.*\)//;
1237 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001238 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001239}
1240
1241
Fred Drake7d45f6d1999-01-05 14:39:27 +00001242sub do_cmd_methodline{
1243 local($_) = @_;
1244 my $class_name = next_optional_argument();
1245 $class_name = $THIS_CLASS
1246 unless $class_name;
1247 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001248 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001249 my $extra = '';
1250 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001251 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001252 }
Fred Drakef1927a62001-06-20 21:29:30 +00001253 my $idx = make_str_index_entry(
1254 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001255 $idx =~ s/ \(.*\)//;
1256 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001257 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001258}
1259
1260
Fred Draked64a40d1998-09-10 18:59:13 +00001261sub do_cmd_methodlineni{
1262 local($_) = @_;
1263 next_optional_argument();
1264 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001265 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001266 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001267}
1268
Fred Drake42b31a51998-03-27 05:16:10 +00001269sub do_env_methoddescni{
1270 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001271 next_optional_argument();
1272 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001273 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001274 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001275}
1276
1277
1278sub do_env_memberdesc{
1279 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001280 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001281 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001282 $class = $THIS_CLASS
1283 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001284 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001285 $extra = " ($class attribute)"
1286 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001287 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001288 $idx =~ s/ \(.*\)//;
1289 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001290 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001291}
1292
1293
Fred Drake5ccf3301998-04-17 20:04:09 +00001294sub do_cmd_memberline{
1295 local($_) = @_;
1296 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001297 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001298 $class = $THIS_CLASS
1299 unless $class;
1300 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001301 $extra = " ($class attribute)"
1302 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001303 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001304 $idx =~ s/ \(.*\)//;
1305 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001306 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001307}
1308
Fred Drakef269e592001-07-17 23:05:57 +00001309
Fred Drake42b31a51998-03-27 05:16:10 +00001310sub do_env_memberdescni{
1311 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001312 next_optional_argument();
1313 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001314 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001315 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001316 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001317}
1318
1319
Fred Drake5ccf3301998-04-17 20:04:09 +00001320sub do_cmd_memberlineni{
1321 local($_) = @_;
1322 next_optional_argument();
1323 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001324 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001325}
1326
Fred Drakef269e592001-07-17 23:05:57 +00001327
1328@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001329
Fred Drakecb199762001-08-16 21:56:24 +00001330%FontConversions = ('cdata' => 'tt class="cdata"',
1331 'character' => 'tt class="character"',
1332 'class' => 'tt class="class"',
1333 'command' => 'code',
1334 'constant' => 'tt class="constant"',
1335 'exception' => 'tt class="exception"',
1336 'file' => 'tt class="file"',
1337 'filenq' => 'tt class="file"',
1338 'kbd' => 'kbd',
1339 'member' => 'tt class="member"',
1340 'programopt' => 'b',
1341 'textrm' => '',
1342 );
1343
Fred Drakef5478632002-05-23 17:59:16 +00001344sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001345 # do a little magic on a font name to get the right behavior in the first
1346 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001347 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001348 if (defined $FontConversions{$font}) {
1349 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001350 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001351 return $font;
1352}
1353
Fred Drakef5478632002-05-23 17:59:16 +00001354sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001355 my $a = $_[0];
1356 if (!defined $a) {
1357 return '';
1358 }
Fred Drakee15956b2000-04-03 04:51:13 +00001359 my $mark = substr($a, 0, 1);
1360 my $r = '';
1361 if ($mark eq 'c')
1362 { $r = ' align="center"'; }
1363 elsif ($mark eq 'r')
1364 { $r = ' align="right"'; }
1365 elsif ($mark eq 'l')
1366 { $r = ' align="left"'; }
1367 elsif ($mark eq 'p')
1368 { $r = ' align="left"'; }
1369 return $r;
1370}
1371
Fred Drakef5478632002-05-23 17:59:16 +00001372sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001373 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001374 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001375 my $a1 = figure_column_alignment($s1);
1376 my $a2 = figure_column_alignment($s2);
1377 my $a3 = figure_column_alignment($s3);
1378 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001379 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001380 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1381 $col_aligns[1] = "<td$a2>";
1382 $col_aligns[2] = "<td$a3>";
1383 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001384 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001385 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001386 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001387}
1388
Fred Drakef5478632002-05-23 17:59:16 +00001389sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001390 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001391 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001392 if ($font) {
1393 $sfont = "<$font>";
1394 $efont = "</$font>";
1395 $efont =~ s/ .*>/>/;
1396 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001397 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001398}
1399
1400sub do_env_tableii{
1401 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001402 my $arg = next_argument();
1403 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001404 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001405 my $h1 = next_argument();
1406 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001407 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001408 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001409 my $a1 = $col_aligns[0];
1410 my $a2 = $col_aligns[1];
1411 s/\\lineii</\\lineii[$a1|$a2]</g;
1412 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001413 . "\n <thead>"
1414 . "\n <tr class=\"tableheader\">"
1415 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1416 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1417 . "\n </tr>"
1418 . "\n </thead>"
1419 . "\n <tbody valign=\"baseline\">"
1420 . $_
1421 . "\n </tbody>"
1422 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001423}
1424
Fred Drakeda72b932000-09-21 15:58:02 +00001425sub do_env_longtableii{
1426 return do_env_tableii(@_);
1427}
1428
Fred Drake6659c301998-03-03 22:02:19 +00001429sub do_cmd_lineii{
1430 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001431 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001432 my $c1 = next_argument();
1433 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001434 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001435 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001436 $c1 = '&nbsp;' if ($c1 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001437 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001438 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001439 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001440 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001441 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001442 }
Fred Drakee15956b2000-04-03 04:51:13 +00001443 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1444 . " $c2align$c2</td>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001445 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001446}
1447
1448sub do_env_tableiii{
1449 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001450 my $arg = next_argument();
1451 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001452 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001453 my $h1 = next_argument();
1454 my $h2 = next_argument();
1455 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001456 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001457 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001458 my $a1 = $col_aligns[0];
1459 my $a2 = $col_aligns[1];
1460 my $a3 = $col_aligns[2];
1461 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1462 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001463 . "\n <thead>"
1464 . "\n <tr class=\"tableheader\">"
1465 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1466 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1467 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1468 . "\n </tr>"
1469 . "\n </thead>"
1470 . "\n <tbody valign=\"baseline\">"
1471 . $_
1472 . "\n </tbody>"
1473 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001474}
1475
Fred Drakeda72b932000-09-21 15:58:02 +00001476sub do_env_longtableiii{
1477 return do_env_tableiii(@_);
1478}
1479
Fred Drake6659c301998-03-03 22:02:19 +00001480sub do_cmd_lineiii{
1481 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001482 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001483 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001484 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001485 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001486 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001487 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001488 $c1 = '&nbsp;' if ($c1 eq '');
1489 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001490 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001491 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001492 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001493 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001494 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001495 }
Fred Drakee15956b2000-04-03 04:51:13 +00001496 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001497 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001498 . " $c3align$c3</td>"
1499 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001500}
1501
Fred Drakea0f4c941998-07-24 22:16:04 +00001502sub do_env_tableiv{
1503 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001504 my $arg = next_argument();
1505 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001506 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001507 my $h1 = next_argument();
1508 my $h2 = next_argument();
1509 my $h3 = next_argument();
1510 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001511 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001512 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001513 my $a1 = $col_aligns[0];
1514 my $a2 = $col_aligns[1];
1515 my $a3 = $col_aligns[2];
1516 my $a4 = $col_aligns[3];
1517 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1518 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001519 . "\n <thead>"
1520 . "\n <tr class=\"tableheader\">"
1521 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1522 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1523 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1524 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1525 . "\n </tr>"
1526 . "\n </thead>"
1527 . "\n <tbody valign=\"baseline\">"
1528 . $_
1529 . "\n </tbody>"
1530 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001531}
1532
Fred Drakeda72b932000-09-21 15:58:02 +00001533sub do_env_longtableiv{
1534 return do_env_tableiv(@_);
1535}
1536
Fred Drakea0f4c941998-07-24 22:16:04 +00001537sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001538 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001539 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001540 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001541 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001542 my $c3 = next_argument();
1543 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001544 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001545 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001546 $c1 = '&nbsp;' if ($c1 eq '');
1547 $c2 = '&nbsp;' if ($c2 eq '');
1548 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001549 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001550 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001551 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001552 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001553 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001554 }
Fred Drakee15956b2000-04-03 04:51:13 +00001555 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001556 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001557 . " $c3align$c3</td>\n"
1558 . " $c4align$c4</td>"
1559 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001560}
1561
Fred Drakef269e592001-07-17 23:05:57 +00001562sub do_env_tablev{
1563 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001564 my $arg = next_argument();
1565 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001566 my $font = fix_font(next_argument());
1567 my $h1 = next_argument();
1568 my $h2 = next_argument();
1569 my $h3 = next_argument();
1570 my $h4 = next_argument();
1571 my $h5 = next_argument();
1572 s/[\s\n]+//;
1573 $globals{'lineifont'} = $font;
1574 my $a1 = $col_aligns[0];
1575 my $a2 = $col_aligns[1];
1576 my $a3 = $col_aligns[2];
1577 my $a4 = $col_aligns[3];
1578 my $a5 = $col_aligns[4];
1579 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1580 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001581 . "\n <thead>"
1582 . "\n <tr class=\"tableheader\">"
1583 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1584 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1585 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1586 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1587 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1588 . "\n </tr>"
1589 . "\n </thead>"
1590 . "\n <tbody valign=\"baseline\">"
1591 . $_
1592 . "\n </tbody>"
1593 . "\n</table>";
Fred Drakef269e592001-07-17 23:05:57 +00001594}
1595
1596sub do_env_longtablev{
1597 return do_env_tablev(@_);
1598}
1599
1600sub do_cmd_linev{
1601 local($_) = @_;
1602 my $aligns = next_optional_argument();
1603 my $c1 = next_argument();
1604 my $c2 = next_argument();
1605 my $c3 = next_argument();
1606 my $c4 = next_argument();
1607 my $c5 = next_argument();
1608 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001609 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001610 $c1 = '&nbsp;' if ($c1 eq '');
1611 $c2 = '&nbsp;' if ($c2 eq '');
1612 $c3 = '&nbsp;' if ($c3 eq '');
1613 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef269e592001-07-17 23:05:57 +00001614 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001615 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001616 my $padding = '';
1617 if ($c1align =~ /align="right"/ || $c1 eq '') {
1618 $padding = '&nbsp;';
1619 }
1620 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1621 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001622 . " $c3align$c3</td>\n"
1623 . " $c4align$c4</td>\n"
1624 . " $c5align$c5</td>"
1625 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001626}
1627
Fred Drake3be20742000-08-31 06:22:54 +00001628
1629# These can be used to control the title page appearance;
1630# they need a little bit of documentation.
1631#
1632# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1633# $ICONSERVER directory, or include path information (other than "./"). The
1634# default image type will be assumed if an extension is not provided.
1635#
1636# If specified, the "title page" will contain two colums: one containing the
1637# title/author/etc., and the other containing the graphic. Use the other
1638# four variables listed here to control specific details of the layout; all
1639# are optional.
1640#
1641# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1642# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1643# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1644# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1645# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1646
Fred Drakef5478632002-05-23 17:59:16 +00001647sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001648 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001649 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001650 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001651 }
1652 else {
1653 write_warnings("\nThis document has no title.");
1654 }
Fred Drake6659c301998-03-03 22:02:19 +00001655 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001656 if ($t_authorURL) {
1657 my $href = translate_commands($t_authorURL);
1658 $href = make_named_href('author', $href,
1659 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001660 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001661 $the_title .= "\n<p>$href</p>";
1662 }
Fred Drake3be20742000-08-31 06:22:54 +00001663 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001664 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001665 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001666 }
Fred Drake3be20742000-08-31 06:22:54 +00001667 }
1668 else {
1669 write_warnings("\nThere is no author for this document.");
1670 }
Fred Drake6659c301998-03-03 22:02:19 +00001671 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001672 $the_title .= "\n<p>$t_institute</p>";
1673 }
Fred Draked07868a1998-05-14 21:00:28 +00001674 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001675 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1676 }
Fred Drake6659c301998-03-03 22:02:19 +00001677 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001678 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001679 }
Fred Drake6659c301998-03-03 22:02:19 +00001680 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001681 $the_title .= "\n<p>";
1682 if ($PACKAGE_VERSION) {
1683 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001684 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001685 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001686 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001687 }
1688 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001689 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001690 }
1691 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001692 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001693 }
Fred Drake6659c301998-03-03 22:02:19 +00001694 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001695 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001696 }
1697 return $the_title;
1698}
1699
Fred Drakef5478632002-05-23 17:59:16 +00001700sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001701 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001702 my $graphic = "<td class=\"titlegraphic\"";
1703 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1704 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1705 $graphic .= "><img";
1706 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1707 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1708 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1709 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001710 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001711 return $graphic;
1712}
1713
Fred Drakef5478632002-05-23 17:59:16 +00001714sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001715 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001716 my $the_title = "\n";
1717 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001718 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001719 # body), but I don't see any other way to get this generated
1720 # at all. Browsers like Mozilla, that support navigation
1721 # links, can make use of this.
1722 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1723 . ($EXTERNAL_UP_TITLE
1724 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001725 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001726 }
1727 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001728 if ($TITLE_PAGE_GRAPHIC) {
1729 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1730 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1731 . "<tr align=\"right\">\n<td>"
1732 . make_my_titlepage()
1733 . "</td>\n"
1734 . make_my_titlegraphic()
1735 . "</tr>\n</table>");
1736 }
1737 else {
1738 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1739 . make_my_titlegraphic()
1740 . "<td>"
1741 . make_my_titlepage()
1742 . "</td></tr>\n</table>");
1743 }
1744 }
1745 else {
1746 $the_title .= ("\n<center>"
1747 . make_my_titlepage()
1748 . "\n</center>");
1749 }
1750 $the_title .= "\n</div>";
1751 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001752 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001753 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001754}
1755
1756
Fred Drake885215c1998-05-20 21:32:09 +00001757#
Fred Drakea0f4c941998-07-24 22:16:04 +00001758# Module synopsis support
1759#
1760
1761require SynopsisTable;
1762
Fred Drakef7685d71998-07-25 03:31:46 +00001763sub get_chapter_id(){
1764 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001765 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001766 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001767 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001768}
1769
Fred Drake643d76d2000-09-09 06:07:37 +00001770# 'chapter' => 'SynopsisTable instance'
1771%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001772
1773sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001774 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001775 my $key;
1776 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001777 if ($key eq $chap) {
1778 return $ModuleSynopses{$chap};
1779 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001780 }
Fred Drake643d76d2000-09-09 06:07:37 +00001781 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001782 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001783 return $st;
1784}
1785
Fred Drake62e43691998-08-10 19:40:44 +00001786sub do_cmd_moduleauthor{
1787 local($_) = @_;
1788 next_argument();
1789 next_argument();
1790 return $_;
1791}
1792
1793sub do_cmd_sectionauthor{
1794 local($_) = @_;
1795 next_argument();
1796 next_argument();
1797 return $_;
1798}
1799
Fred Drakea0f4c941998-07-24 22:16:04 +00001800sub do_cmd_declaremodule{
1801 local($_) = @_;
1802 my $key = next_optional_argument();
1803 my $type = next_argument();
1804 my $name = next_argument();
1805 my $st = get_synopsis_table(get_chapter_id());
1806 #
1807 $key = $name unless $key;
1808 $type = 'built-in' if $type eq 'builtin';
1809 $st->declare($name, $key, $type);
1810 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001811 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001812}
1813
1814sub do_cmd_modulesynopsis{
1815 local($_) = @_;
1816 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001817 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001818 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001819}
1820
1821sub do_cmd_localmoduletable{
1822 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001823 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001824 my $st = get_synopsis_table($chap);
1825 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001826 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001827}
1828
Fred Drakef5478632002-05-23 17:59:16 +00001829sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001830 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001831 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001832 my $st = $ModuleSynopses{$key};
1833 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001834 if ($file) {
1835 process_localmoduletables_in_file($file);
1836 }
1837 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001838 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001839 }
1840 }
1841}
1842
Fred Drakef5478632002-05-23 17:59:16 +00001843sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001844 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001845 open(MYFILE, "<$file");
1846 local($_);
1847 sysread(MYFILE, $_, 1024*1024);
1848 close(MYFILE);
1849 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001850 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001851 my $match = $&;
1852 my $chap = $1;
1853 my $st = get_synopsis_table($chap);
1854 my $data = $st->tohtml();
1855 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001856 }
Fred Drake643d76d2000-09-09 06:07:37 +00001857 open(MYFILE,">$file");
1858 print MYFILE $_;
1859 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001860}
Fred Drakef5478632002-05-23 17:59:16 +00001861sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001862 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001863 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001864}
Fred Drakea0f4c941998-07-24 22:16:04 +00001865
1866
1867#
1868# "See also:" -- references placed at the end of a \section
1869#
1870
1871sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001872 return ("<div class=\"seealso\">\n "
1873 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001874 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001875 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001876}
1877
Fred Drake5ed35fd2001-11-30 18:09:54 +00001878sub do_env_seealsostar{
1879 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001880 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001881 . '</div>');
1882}
1883
Fred Drakea0f4c941998-07-24 22:16:04 +00001884sub do_cmd_seemodule{
1885 # Insert the right magic to jump to the module definition. This should
1886 # work most of the time, at least for repeat builds....
1887 local($_) = @_;
1888 my $key = next_optional_argument();
1889 my $module = next_argument();
1890 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001891 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001892 $key = $module
1893 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001894 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001895 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001896 }
Fred Drakef1927a62001-06-20 21:29:30 +00001897 return ('<dl compact class="seemodule">'
1898 . "\n <dt>Module <b><tt class=\"module\">"
1899 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1900 . "\n <dd>$text$period\n </dl>"
1901 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001902}
1903
Fred Drakee0197bf2001-04-12 04:03:22 +00001904sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001905 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001906 my $s = "$str";
1907 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1908 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1909 return $s;
1910}
1911
Fred Drakef5478632002-05-23 17:59:16 +00001912sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001913 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001914 my $rfcnum = next_argument();
1915 my $title = next_argument();
1916 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001917 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001918 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001919 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001920 return '<dl compact class="seerfc">'
1921 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001922 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001923 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001924 . "\n <dd>$text\n </dl>"
1925 . $_;
1926}
1927
Fred Drake643d76d2000-09-09 06:07:37 +00001928sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001929 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001930}
1931
1932sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001933 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001934 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001935}
1936
Fred Drake48449982000-09-12 17:52:33 +00001937sub do_cmd_seetitle{
1938 local($_) = @_;
1939 my $url = next_optional_argument();
1940 my $title = next_argument();
1941 my $text = next_argument();
1942 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001943 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001944 return '<dl compact class="seetitle">'
1945 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001946 . "\n >$title$icon</a></em></dt>"
1947 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001948 . $_;
1949 }
1950 return '<dl compact class="seetitle">'
1951 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001952 . "\n >$title</em></dt>"
1953 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001954 . $_;
1955}
1956
Fred Drake4f687b32004-01-08 14:57:27 +00001957sub do_cmd_seelink{
1958 local($_) = @_;
1959 my $url = next_argument();
1960 my $linktext = next_argument();
1961 my $text = next_argument();
1962 my $icon = get_link_icon($url);
1963 return '<dl compact class="seeurl">'
1964 . "\n <dt><a href='$url'"
1965 . "\n >$linktext$icon</a></dt>"
1966 . "\n <dd>$text</dd>\n </dl>"
1967 . $_;
1968}
1969
Fred Drakeef4d1112000-05-09 16:17:51 +00001970sub do_cmd_seeurl{
1971 local($_) = @_;
1972 my $url = next_argument();
1973 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001974 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001975 return '<dl compact class="seeurl">'
1976 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001977 . "\n class=\"url\">$url$icon</a></dt>"
1978 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001979 . $_;
1980}
1981
Fred Drakea0f4c941998-07-24 22:16:04 +00001982sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001983 local($_) = @_;
1984 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001985 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001986}
1987
1988
1989#
Fred Drake885215c1998-05-20 21:32:09 +00001990# Definition list support.
1991#
1992
1993sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001994 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001995}
1996
1997sub do_cmd_term{
1998 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001999 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00002000 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00002001 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00002002 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00002003}
2004
2005
Fred Drake4e72e052003-07-15 22:00:36 +00002006# Commands listed here have process-order dependencies; these often
2007# are related to indexing operations.
2008# XXX Not sure why funclineni, methodlineni, and samp are here.
2009#
Fred Drake2ff880e1999-02-05 18:31:29 +00002010process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002011declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002012funcline # {} # {}
2013funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002014memberline # [] # {}
2015methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002016methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002017modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00002018bifuncindex # {}
2019exindex # {}
2020indexii # {} # {}
2021indexiii # {} # {} # {}
2022indexiv # {} # {} # {} # {}
2023kwindex # {}
2024obindex # {}
2025opindex # {}
2026stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002027platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002028samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002029setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002030withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002031_RAW_ARG_DEFERRED_CMDS_
2032
2033
Fred Drake8a5e6792002-04-15 18:41:31 +00002034$alltt_start = '<div class="verbatim"><pre>';
2035$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002036
Fred Drakef5478632002-05-23 17:59:16 +00002037sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002038 local ($_) = @_;
2039 local($closures,$reopens,@open_block_tags);
2040
2041 # get the tag-strings for all open tags
2042 local(@keep_open_tags) = @$open_tags_R;
2043 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2044
2045 # get the tags for text-level tags only
2046 $open_tags_R = [ @keep_open_tags ];
2047 local($local_closures, $local_reopens);
2048 ($local_closures, $local_reopens,@open_block_tags)
2049 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002050 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002051
2052 $open_tags_R = [ @open_block_tags ];
2053
2054 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002055 local($open_tags_R) = [ @open_block_tags ];
2056 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002057
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002058 local($cnt) = ++$global{'max_id'};
2059 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2060 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002061
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002062 $_ = &translate_environments($_);
2063 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002064
Fred Drake41aa0182003-09-05 15:43:00 +00002065 # remove spurious <BR> someone sticks in; not sure where they
2066 # actually come from
2067 # XXX the replacement space is there to accomodate something
2068 # broken that inserts a space in front of the first line of
2069 # the environment
2070 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002071
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002072 $_ = join('', $closures, $alltt_start, $local_reopens
2073 , $_
2074 , &balance_tags() #, $local_closures
2075 , $alltt_end, $reopens);
2076 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002077 };
2078 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002079 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002080}
2081
Fred Drake8effa012004-04-01 04:30:29 +00002082# List of all filenames produced by do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002083%VerbatimFiles = ();
2084@VerbatimOutputs = ();
2085
2086sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002087 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002088 #
2089 # Re-write the source filename to always use a .txt extension
2090 # so that Web servers will present it as text/plain. This is
2091 # needed since there is no other even moderately reliable way
2092 # to get the right Content-Type header on text files for
2093 # servers which we can't configure (like python.org mirrors).
2094 #
2095 if (defined $VerbatimFiles{$file}) {
2096 # We've seen this one before; re-use the same output file.
2097 return $VerbatimFiles{$file};
2098 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002099 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002100 $filename = "$srcname.txt";
2101 #
2102 # We need to determine if our default filename is already
2103 # being used, and find a new one it it is. If the name is in
2104 # used, this algorithm will first attempt to include the
2105 # source extension as part of the name, and if that is also in
2106 # use (if the same file is included multiple times, or if
2107 # another source file has that as the base name), a counter is
2108 # used instead.
2109 #
2110 my $found = 1;
2111 FIND:
2112 while ($found) {
2113 foreach $fn (@VerbatimOutputs) {
2114 if ($fn eq $filename) {
2115 if ($found == 1) {
2116 $srcext =~ s/^[.]//; # Remove '.' from extension
2117 $filename = "$srcname-$srcext.txt";
2118 }
2119 else {
2120 $filename = "$srcname-$found.txt";
2121 }
2122 ++$found;
2123 next FIND;
2124 }
2125 }
2126 $found = 0;
2127 }
2128 push @VerbatimOutputs, $filename;
2129 $VerbatimFiles{$file} = $filename;
2130 return $filename;
2131}
2132
Fred Drake57e52ef2001-06-15 21:31:57 +00002133sub do_cmd_verbatiminput{
2134 local($_) = @_;
2135 my $fname = next_argument();
2136 my $file;
2137 my $found = 0;
2138 my $texpath;
2139 # Search TEXINPUTS for the input file, the way we're supposed to:
2140 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2141 $file = "$texpath$dd$fname";
2142 last if ($found = (-f $file));
2143 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002144 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002145 my $text;
2146 if ($found) {
2147 open(MYFILE, "<$file") || die "\n$!\n";
2148 read(MYFILE, $text, 1024*1024);
2149 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002150 $filename = get_verbatim_output_name($file);
2151 # Now that we have a filename, write it out.
2152 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002153 print MYFILE $text;
2154 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002155 #
2156 # These rewrites convert the raw text to something that will
2157 # be properly visible as HTML and also will pass through the
2158 # vagaries of conversion through LaTeX2HTML. The order in
2159 # which the specific rewrites are performed is significant.
2160 #
2161 $text =~ s/\&/\&amp;/g;
2162 # These need to happen before the normal < and > re-writes,
2163 # since we need to avoid LaTeX2HTML's attempt to perform
2164 # ligature processing without regard to context (since it
2165 # doesn't have font information).
2166 $text =~ s/--/-&\#45;/g;
2167 $text =~ s/<</\&lt;\&\#60;/g;
2168 $text =~ s/>>/\&gt;\&\#62;/g;
2169 # Just normal re-writes...
2170 $text =~ s/</\&lt;/g;
2171 $text =~ s/>/\&gt;/g;
2172 # These last isn't needed for the HTML, but is needed to get
2173 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2174 # of &sol; since many browsers don't support that.
2175 $text =~ s/\\/\&\#92;/g;
2176 }
2177 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002178 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2179 }
2180 my $note = 'Download as text.';
2181 if ($file ne $filename) {
2182 $note = ('Download as text (original file name: <span class="file">'
2183 . $fname
2184 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002185 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002186 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002187 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002188 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002189 . "<a href=\"$filename\" type=\"text/plain\""
2190 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002191 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002192 . $_);
2193}
Fred Drake86333602001-04-10 17:13:39 +00002194
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021951; # This must be the last line