blob: e144fa4409521af28a7a5344370efb4ef2346c2a [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 Drakeed306292004-11-04 03:23:04 +0000392 my $titletext = strip_html_markup("$title");
Fred Drakef1927a62001-06-20 21:29:30 +0000393 $repl = ("<em class=\"citetitle\"><a\n"
394 . " href=\"$url\"\n"
Fred Drakeed306292004-11-04 03:23:04 +0000395 . " title=\"$titletext\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000396 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000397 }
398 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000399 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000400 }
401 return $repl . $_;
402}
403
Fred Drake6659c301998-03-03 22:02:19 +0000404sub do_cmd_deprecated{
405 # two parameters: \deprecated{version}{whattodo}
406 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000407 my $release = next_argument();
408 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000409 return ('<div class="versionnote">'
410 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000411 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000412 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000413}
414
Fred Drakef5478632002-05-23 17:59:16 +0000415sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000416 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000417 my $type = $_[0];
418 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000419 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000420 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000421 my $text = "$type in version $release.";
422 if ($explanation) {
423 $text = "$type in version $release:\n$explanation.";
424 }
Fred Drakef1927a62001-06-20 21:29:30 +0000425 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000426}
427
428sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000429 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000430}
431
432sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000433 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000434}
435
Fred Drake557460c1999-03-02 16:05:35 +0000436#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000437# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000438#
439sub do_cmd_platform{
440 local($_) = @_;
441 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000442 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000443 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000444 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000445 return "\n<p class=\"availability\">Availability: <span"
446 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000447}
448
Fred Drake557460c1999-03-02 16:05:35 +0000449$IGNORE_PLATFORM_ANNOTATION = '';
450sub do_cmd_ignorePlatformAnnotation{
451 local($_) = @_;
452 $IGNORE_PLATFORM_ANNOTATION = next_argument();
453 return $_;
454}
455
Fred Drake6659c301998-03-03 22:02:19 +0000456
457# index commands
458
459$INDEX_SUBITEM = "";
460
Fred Drakef5478632002-05-23 17:59:16 +0000461sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000462 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000463}
464
465sub do_cmd_setindexsubitem{
466 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000467 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000468 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000469}
470
Fred Drakefc16e781998-03-12 21:03:26 +0000471sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000472 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000473 # do things in the right order, but we need to at least strip this stuff
474 # out, and leave anything that the second argument expanded out to.
475 #
476 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000477 my $oldsubitem = $INDEX_SUBITEM;
478 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000479 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000480 my $br_id = ++$globals{'max_id'};
481 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000482 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000483 return
484 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000485 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000486 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000487}
488
Fred Drake08932051998-04-17 02:15:42 +0000489# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000490# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
491# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000492#
Fred Drake49b33fa2002-11-15 19:04:10 +0000493sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000494
Fred Drake42b31a51998-03-27 05:16:10 +0000495# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000496#
Fred Drake08932051998-04-17 02:15:42 +0000497open(IDXFILE, '>index.dat') || die "\n$!\n";
498open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000499print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000500print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000501
502# Using \0 for this is bad because we can't use common tools to work with the
503# resulting files. Things like grep can be useful with this stuff!
504#
505$IDXFILE_FIELD_SEP = "\1";
506
Fred Drakef5478632002-05-23 17:59:16 +0000507sub write_idxfile($$){
508 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000509 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000510}
511
Fred Drake42b31a51998-03-27 05:16:10 +0000512
Fred Drakef5478632002-05-23 17:59:16 +0000513sub gen_link($$){
514 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000515 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000516 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000517}
518
Fred Drakef5478632002-05-23 17:59:16 +0000519sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000520 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000521 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000522 $str = gen_index_id($str, '');
523 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000524 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000525}
526
Fred Drake04bf7242003-11-26 20:55:49 +0000527sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000528 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake0c1b2532004-10-29 19:47:52 +0000529 my $aname = "<a id='$name' xml:id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000530 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000531 return ($name, $ahref);
532}
533
534sub new_link_info(){
535 my($name, $ahref) = new_link_name_info();
Fred Drake0c1b2532004-10-29 19:47:52 +0000536 my $aname = "<a id='$name' xml:id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000537 return ($name, $aname, $ahref);
538}
539
Fred Drakeab032151999-05-13 18:36:54 +0000540$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000541sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000542 my $count = @_;
543 my $i = 0;
544 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000545 my $name = $_[$i];
546 my $cmd = "idx_cmd_$name";
547 die "\nNo function $cmd() defined!\n"
548 if (!defined &$cmd);
549 eval ("sub do_cmd_$name { return process_index_macros("
550 . "\$_[0], '$name'); }");
551 if (length($IndexMacroPattern) == 0) {
552 $IndexMacroPattern = "$name";
553 }
554 else {
555 $IndexMacroPattern .= "|$name";
556 }
Fred Drakeab032151999-05-13 18:36:54 +0000557 }
558}
559
560$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000561sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000562 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000563 my $cmdname = $_[1]; # This is what triggered us in the first place;
564 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000565 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000566 my $cmd = "idx_cmd_$cmdname";
567 print "\nIndexing: \\$cmdname"
568 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000569 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000570 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000571 $cmdname = "$1";
572 print " \\$cmdname"
573 if $DEBUG_INDEXING;
574 $cmd = "idx_cmd_$cmdname";
575 if (!defined &$cmd) {
576 last;
577 }
578 else {
579 s/^[\s\n]*\\$cmdname//;
580 &$cmd($ahref);
581 }
Fred Drakeab032151999-05-13 18:36:54 +0000582 }
Fred Drake899072a2004-04-08 15:30:12 +0000583# XXX I don't remember why I added this to begin with.
584# if (/^[ \t\r\n]/) {
585# $_ = substr($_, 1);
586# }
Fred Drake62e43691998-08-10 19:40:44 +0000587 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000588}
589
Fred Drakeab032151999-05-13 18:36:54 +0000590define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000591sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000592 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000593 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000594}
595
Fred Drakeab032151999-05-13 18:36:54 +0000596define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000597sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000598 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000599 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
600 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000601}
602
603define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000604sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000605 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000606 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000607 add_index_entry("$str1!$str2", $_[0]);
608 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000609}
610
Fred Drakeab032151999-05-13 18:36:54 +0000611define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000612sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000613 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000614 my $str2 = next_argument();
615 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000616 add_index_entry("$str1!$str2 $str3", $_[0]);
617 add_index_entry("$str2!$str3, $str1", $_[0]);
618 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000619}
620
Fred Drakeab032151999-05-13 18:36:54 +0000621define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000622sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000623 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000624 my $str2 = next_argument();
625 my $str3 = next_argument();
626 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000627 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
628 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
629 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
630 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000631}
632
Fred Drakeab032151999-05-13 18:36:54 +0000633define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000634sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000635 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000636 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000637 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000638}
Fred Drake6659c301998-03-03 22:02:19 +0000639
Fred Drakef5478632002-05-23 17:59:16 +0000640sub my_typed_index_helper($$){
641 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000642 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000643 add_index_entry("$str $word", $ahref);
644 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000645}
646
Fred Drakeab032151999-05-13 18:36:54 +0000647define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000648sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
649sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
650sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
651sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000652
Fred Drakeab032151999-05-13 18:36:54 +0000653define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000654sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000655 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000656 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000657 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000658}
659
660
Fred Drakef5478632002-05-23 17:59:16 +0000661sub make_mod_index_entry($$){
662 my($str, $define) = @_;
663 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000664 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000665 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
666 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000667 $str = gen_index_id($str, $define);
668 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000669 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000670
Fred Drakec9a44381998-03-17 06:29:13 +0000671 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000672 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000673 $str =~ /(<tt.*<\/tt>)/;
674 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000675 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000676 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000677 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000678}
679
Fred Drake557460c1999-03-02 16:05:35 +0000680
Fred Drakec9a44381998-03-17 06:29:13 +0000681$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000682$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000683
Fred Drakef5478632002-05-23 17:59:16 +0000684sub define_module($$){
685 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000686 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000687 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000688 && $word ne "standard" && $word ne "") {
689 write_warnings("Bad module type '$word'"
690 . " for \\declaremodule (module $name)");
691 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000692 }
Fred Drake6659c301998-03-03 22:02:19 +0000693 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000694 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000695 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000696 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000697 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000698 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000699}
700
Fred Drakef5478632002-05-23 17:59:16 +0000701sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000702 local($word, $_) = @_;
703 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000704 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000705}
706
Fred Drake49b33fa2002-11-15 19:04:10 +0000707sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
708sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
709sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
710sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
711# local($_) = @_;
712# my $name = next_argument();
713# return define_module('standard', $name) . $_;
714# }
Fred Drake6659c301998-03-03 22:02:19 +0000715
Fred Drakef5478632002-05-23 17:59:16 +0000716sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000717 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000718 my $str = next_argument();
719 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000720 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000721 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
722 # just inline it all here
723 $str = gen_index_id($str, 'REF');
724 $index{$str} .= $ahref;
725 write_idxfile($ahref, $str);
726}
727
Fred Drake6659c301998-03-03 22:02:19 +0000728# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000729define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000730 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000731sub idx_cmd_refmodindex($){
732 return ref_module_index_helper('', $_[0]); }
733sub idx_cmd_refbimodindex($){
734 return ref_module_index_helper('built-in', $_[0]); }
735sub idx_cmd_refexmodindex($){
736 return ref_module_index_helper('extension', $_[0]);}
737sub idx_cmd_refstmodindex($){
738 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000739
Fred Drake49b33fa2002-11-15 19:04:10 +0000740sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000741
Fred Drakef5478632002-05-23 17:59:16 +0000742sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000743 # These markers must be non-empty or the main latex2html script
744 # may remove a surrounding element that has not other content as
745 # "extraneous"; this ensures these elements (usually hyperlink
746 # targets) are not removed improperly. We use comments since
747 # there's no meaningful actual content.
748 # Thanks to Dave Kuhlman for figuring why some named anchors were
749 # being lost.
750 $anchor_invisible_mark = '<!--x-->';
751 $anchor_invisible_mark2 = '<!--y-->';
752 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000753 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000754}
Fred Drake42b31a51998-03-27 05:16:10 +0000755init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000756
Fred Drakeab032151999-05-13 18:36:54 +0000757# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000758# instead of the dummy filler.
759#
Fred Drakef5478632002-05-23 17:59:16 +0000760sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000761 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000762 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000763 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000764 if ($str =~ /^<[a-z]+\b/) {
765 my $s = "$str";
Fred Drake0c1b2532004-10-29 19:47:52 +0000766 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
Fred Drake04bf7242003-11-26 20:55:49 +0000767 return $s;
768 }
769 else {
Fred Drake0c1b2532004-10-29 19:47:52 +0000770 return "<a id='$name' xml:id='$name'>$str</a>";
Fred Drake04bf7242003-11-26 20:55:49 +0000771 }
Fred Drake6659c301998-03-03 22:02:19 +0000772}
773
Fred Drake77602f22001-07-06 22:43:02 +0000774
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000775%TokenToTargetMapping = (); # language:token -> link target
776%DefinedGrammars = (); # language -> full grammar text
777%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000778
779sub do_cmd_token{
780 local($_) = @_;
781 my $token = next_argument();
782 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
783 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
784 # recursive definition or display-only productionlist
785 return "$token";
786 }
787 if ($target eq '') {
788 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
789 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
790 print "Adding '$CURRENT_FILE' to back-patch list.\n";
791 }
792 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
793 }
794 return "<a href=\"$target\">$token</a>" . $_;
795}
796
Fred Drake16bb4192001-08-20 21:36:38 +0000797sub do_cmd_grammartoken{
798 return do_cmd_token(@_);
799}
800
Fred Drake77602f22001-07-06 22:43:02 +0000801sub do_env_productionlist{
802 local($_) = @_;
803 my $lang = next_optional_argument();
804 my $filename = "grammar-$lang.txt";
805 if ($lang eq '') {
806 $filename = 'grammar.txt';
807 }
808 local($CURRENT_GRAMMAR) = $lang;
809 $DefinedGrammars{$lang} .= $_;
810 return ("<dl><dd class=\"grammar\">\n"
811 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000812 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000813 . translate_commands(translate_environments($_))
814 . "</table>\n"
815 . "</div>\n"
816 . (($lang eq '*')
817 ? ''
818 : ("<a class=\"grammar-footer\"\n"
819 . " href=\"$filename\" type=\"text/plain\"\n"
820 . " >Download entire grammar as text.</a>\n"))
821 . "</dd></dl>");
822}
823
824sub do_cmd_production{
825 local($_) = @_;
826 my $token = next_argument();
827 my $defn = next_argument();
828 my $lang = $CURRENT_GRAMMAR;
829 local($CURRENT_TOKEN) = $token;
830 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000831 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000832 . " <td><code>$token</code></td>\n"
833 . " <td>&nbsp;::=&nbsp;</td>\n"
834 . " <td><code>"
835 . translate_commands($defn)
836 . "</code></td></tr>"
837 . $_);
838 }
839 my $target;
840 if ($lang eq '') {
841 $target = "$CURRENT_FILE\#tok-$token";
842 }
843 else {
844 $target = "$CURRENT_FILE\#tok-$lang-$token";
845 }
846 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000847 return ("<tr valign=\"baseline\">\n"
Fred Drake0c1b2532004-10-29 19:47:52 +0000848 . " <td><code><a id='tok-$token' xml:id='tok-$token'>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000849 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000850 . " <td>&nbsp;::=&nbsp;</td>\n"
851 . " <td><code>"
852 . translate_commands($defn)
853 . "</code></td></tr>"
854 . $_);
855}
856
Fred Drake53815882002-03-15 23:21:37 +0000857sub do_cmd_productioncont{
858 local($_) = @_;
859 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000860 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000861 return ("<tr valign=\"baseline\">\n"
862 . " <td>&nbsp;</td>\n"
863 . " <td>&nbsp;</td>\n"
864 . " <td><code>"
865 . translate_commands($defn)
866 . "</code></td></tr>"
867 . $_);
868}
869
Fred Drakef5478632002-05-23 17:59:16 +0000870sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000871 my $lang;
872 my $filename;
873 local($_);
874 print "process_grammar_files()\n";
875 foreach $lang (keys %DefinedGrammars) {
876 $filename = "grammar-$lang.txt";
877 if ($lang eq '*') {
878 next;
879 }
880 if ($lang eq '') {
881 $filename = 'grammar.txt';
882 }
883 open(GRAMMAR, ">$filename") || die "\n$!\n";
884 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
885 close(GRAMMAR);
886 print "Wrote grammar file $filename\n";
887 }
888 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
889 foreach $filename (keys %BackpatchGrammarFiles) {
890 print "\nBack-patching grammar links in $filename\n";
891 my $buffer;
892 open(GRAMMAR, "<$filename") || die "\n$!\n";
893 # read all of the file into the buffer
894 sysread(GRAMMAR, $buffer, 1024*1024);
895 close(GRAMMAR);
896 while ($buffer =~ /$PATTERN/) {
897 my($lang, $token) = ($1, $2);
898 my $target = $TokenToTargetMapping{"$lang:$token"};
899 my $source = "<pyGrammarToken><$lang><$token>";
900 $buffer =~ s/$source/$target/g;
901 }
902 open(GRAMMAR, ">$filename") || die "\n$!\n";
903 print GRAMMAR $buffer;
904 close(GRAMMAR);
905 }
906}
907
Fred Drakef5478632002-05-23 17:59:16 +0000908sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000909 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000910 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000911 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
912 s/\\token(<<\d+>>)(.+)\1/$2/g;
913 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000914 s/<<\d+>>//g;
915 s/;SPMgt;/>/g;
916 s/;SPMlt;/</g;
917 s/;SPMquot;/\"/g;
918 return $_;
919}
920
921
Fred Drakee15956b2000-04-03 04:51:13 +0000922$REFCOUNTS_LOADED = 0;
923
Fred Drakef5478632002-05-23 17:59:16 +0000924sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000925 $REFCOUNTS_LOADED = 1;
926
Fred Drake49b33fa2002-11-15 19:04:10 +0000927 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000928 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000929 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000930 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000931 $mydir = getcwd() . "$dd$mydir"
932 unless $mydir =~ s|^/|/|;
933 local $_;
934 my $filename = "$mydir${dd}api${dd}refcounts.dat";
935 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
936 print "[loading API refcount data]";
937 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000938 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000939 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
940 #print "\n$func($param) --> $count";
941 $REFCOUNTS{"$func:$param"} = $count;
942 }
943 }
944}
945
Fred Drakef5478632002-05-23 17:59:16 +0000946sub get_refcount($$){
947 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000948 load_refcounts()
949 unless $REFCOUNTS_LOADED;
950 return $REFCOUNTS{"$func:$param"};
951}
952
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000953
954$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000955$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000956
Fred Drakef5478632002-05-23 17:59:16 +0000957sub cfuncline_helper($$$){
958 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000959 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000960 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000961 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000962 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000963 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
964 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000965 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
966 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
967 . "<td>$args)</td>"
968 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000969}
970sub do_cmd_cfuncline{
971 local($_) = @_;
972 my $type = next_argument();
973 my $name = next_argument();
974 my $args = next_argument();
975 my $siginfo = cfuncline_helper($type, $name, $args);
976 return "<dt>$siginfo\n<dd>" . $_;
977}
978sub do_env_cfuncdesc{
979 local($_) = @_;
980 my $type = next_argument();
981 my $name = next_argument();
982 my $args = next_argument();
983 my $siginfo = cfuncline_helper($type, $name, $args);
984 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000985 my $rcinfo = '';
986 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000987 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000988 }
989 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000990 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000991 }
Fred Drakec2578c52000-04-10 18:26:45 +0000992 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000993 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000994 }
Fred Drakee15956b2000-04-03 04:51:13 +0000995 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000996 $rcinfo = ( "\n<div class=\"refcount-info\">"
997 . "\n <span class=\"label\">Return value:</span>"
998 . "\n <span class=\"value\">$rcinfo.</span>"
999 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +00001000 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001001 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001002 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001003 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001004 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001005}
1006
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001007sub do_cmd_cmemberline{
1008 local($_) = @_;
1009 my $container = next_argument();
1010 my $type = next_argument();
1011 my $name = next_argument();
1012 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001013 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001014 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001015 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001016 . $_;
1017}
1018sub do_env_cmemberdesc{
1019 local($_) = @_;
1020 my $container = next_argument();
1021 my $type = next_argument();
1022 my $name = next_argument();
1023 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001024 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001025 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001026 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001027 . $_
1028 . '</dl>';
1029}
1030
Fred Drakee15956b2000-04-03 04:51:13 +00001031sub do_env_csimplemacrodesc{
1032 local($_) = @_;
1033 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001034 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001035 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001036 . $_
1037 . '</dl>'
1038}
1039
Fred Drake6659c301998-03-03 22:02:19 +00001040sub do_env_ctypedesc{
1041 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001042 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001043 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001044 $index_name = $type_name
1045 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001046 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001047 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001048 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1049 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001050 . $_
1051 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001052}
1053
1054sub do_env_cvardesc{
1055 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001056 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001057 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001058 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001059 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001060 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001061 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001062 . '<dd>'
1063 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001064 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001065}
1066
Fred Drake3cdb89d2000-09-14 20:17:23 +00001067sub convert_args($){
1068 local($IN_DESC_HANDLER) = 1;
1069 local($_) = @_;
1070 return translate_commands($_);
1071}
1072
Fred Drakef6e90272002-06-18 18:24:16 +00001073sub funcline_helper($$$){
1074 my($first, $idxitem, $arglist) = @_;
1075 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001076 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1077 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001078 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001079}
1080
Fred Drake6659c301998-03-03 22:02:19 +00001081sub do_env_funcdesc{
1082 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001083 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001084 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001085 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1086 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001087 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001088 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001089 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001090 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001091}
1092
1093sub do_env_funcdescni{
1094 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001095 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001096 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001097 my $prefix = "<tt class=\"function\">$function_name</tt>";
1098 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001099}
1100
1101sub do_cmd_funcline{
1102 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001103 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001104 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001105 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001106 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1107 $prefix =~ s/\(\)//;
1108
Fred Drakef6e90272002-06-18 18:24:16 +00001109 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001110}
1111
Fred Drake6b3fb781999-07-12 16:50:09 +00001112sub do_cmd_funclineni{
1113 local($_) = @_;
1114 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001115 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001116 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001117
Fred Drakef6e90272002-06-18 18:24:16 +00001118 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001119}
1120
Fred Drake6659c301998-03-03 22:02:19 +00001121# Change this flag to index the opcode entries. I don't think it's very
1122# useful to index them, since they're only presented to describe the dis
1123# module.
1124#
1125$INDEX_OPCODES = 0;
1126
1127sub do_env_opcodedesc{
1128 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001129 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001130 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001131 my $idx;
1132 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001133 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001134 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001135 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001136 }
1137 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001138 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001139 }
1140 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001141 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001142 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001143 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001144 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001145}
1146
1147sub do_env_datadesc{
1148 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001149 my $dataname = next_argument();
1150 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001151 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001152 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001153 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001154 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001155}
1156
1157sub do_env_datadescni{
1158 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001159 my $idx = next_argument();
1160 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001161 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001162 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001163 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001164}
1165
1166sub do_cmd_dataline{
1167 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001168 my $data_name = next_argument();
1169 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001170 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001171 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001172}
1173
Fred Drakeadb272c2000-04-10 17:47:14 +00001174sub do_cmd_datalineni{
1175 local($_) = @_;
1176 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001177 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001178}
1179
Fred Drake42b31a51998-03-27 05:16:10 +00001180sub do_env_excdesc{
1181 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001182 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001183 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001184 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001185 . "\n<dd>"
1186 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001187 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001188}
1189
Fred Drake62e43691998-08-10 19:40:44 +00001190sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001191
1192
Fred Drakef5478632002-05-23 17:59:16 +00001193sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001194 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001195 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001196 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001197 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001198 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001199 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001200 my $prefix = "$TLSTART$what$TLEND$idx";
1201 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001202}
1203
Fred Drake643d76d2000-09-09 06:07:37 +00001204sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001205 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001206}
1207
Fred Drake06a01e82001-05-11 01:00:30 +00001208sub do_env_classdescstar{
1209 local($_) = @_;
1210 $THIS_CLASS = next_argument();
1211 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001212 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001213 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001214 my $prefix = "${TLSTART}class$TLEND$idx";
1215 # Can't use funcline_helper() since there is no args list.
1216 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001217}
1218
Fred Drake643d76d2000-09-09 06:07:37 +00001219sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001220 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001221}
1222
Fred Drake42b31a51998-03-27 05:16:10 +00001223
1224sub do_env_methoddesc{
1225 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001226 my $class_name = next_optional_argument();
1227 $class_name = $THIS_CLASS
1228 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001229 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001230 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001231 my $extra = '';
1232 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001233 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001234 }
Fred Drakef1927a62001-06-20 21:29:30 +00001235 my $idx = make_str_index_entry(
1236 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001237 $idx =~ s/ \(.*\)//;
1238 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001239 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001240}
1241
1242
Fred Drake7d45f6d1999-01-05 14:39:27 +00001243sub do_cmd_methodline{
1244 local($_) = @_;
1245 my $class_name = next_optional_argument();
1246 $class_name = $THIS_CLASS
1247 unless $class_name;
1248 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001249 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001250 my $extra = '';
1251 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001252 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001253 }
Fred Drakef1927a62001-06-20 21:29:30 +00001254 my $idx = make_str_index_entry(
1255 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001256 $idx =~ s/ \(.*\)//;
1257 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001258 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001259}
1260
1261
Fred Draked64a40d1998-09-10 18:59:13 +00001262sub do_cmd_methodlineni{
1263 local($_) = @_;
1264 next_optional_argument();
1265 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001266 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001267 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001268}
1269
Fred Drake42b31a51998-03-27 05:16:10 +00001270sub do_env_methoddescni{
1271 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001272 next_optional_argument();
1273 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001274 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001275 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001276}
1277
1278
1279sub do_env_memberdesc{
1280 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001281 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001282 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001283 $class = $THIS_CLASS
1284 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001285 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001286 $extra = " ($class attribute)"
1287 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001288 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001289 $idx =~ s/ \(.*\)//;
1290 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001291 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001292}
1293
1294
Fred Drake5ccf3301998-04-17 20:04:09 +00001295sub do_cmd_memberline{
1296 local($_) = @_;
1297 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001298 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001299 $class = $THIS_CLASS
1300 unless $class;
1301 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001302 $extra = " ($class attribute)"
1303 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001304 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001305 $idx =~ s/ \(.*\)//;
1306 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001307 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001308}
1309
Fred Drakef269e592001-07-17 23:05:57 +00001310
Fred Drake42b31a51998-03-27 05:16:10 +00001311sub do_env_memberdescni{
1312 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001313 next_optional_argument();
1314 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001315 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001316 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001317 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001318}
1319
1320
Fred Drake5ccf3301998-04-17 20:04:09 +00001321sub do_cmd_memberlineni{
1322 local($_) = @_;
1323 next_optional_argument();
1324 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001325 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001326}
1327
Fred Drakef269e592001-07-17 23:05:57 +00001328
Fred Drake9e927f12004-11-10 15:49:25 +00001329# For tables, we include a class on every cell to allow the CSS to set
1330# the text-align property; this is because support for styling columns
1331# via the <col> element appears nearly non-existant on even the latest
1332# browsers (Mozilla 1.7 is stable at the time of this writing).
1333# Hopefully this can be improved as browsers evolve.
1334
Fred Drakef269e592001-07-17 23:05:57 +00001335@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001336
Fred Drakecb199762001-08-16 21:56:24 +00001337%FontConversions = ('cdata' => 'tt class="cdata"',
1338 'character' => 'tt class="character"',
1339 'class' => 'tt class="class"',
1340 'command' => 'code',
1341 'constant' => 'tt class="constant"',
1342 'exception' => 'tt class="exception"',
1343 'file' => 'tt class="file"',
1344 'filenq' => 'tt class="file"',
1345 'kbd' => 'kbd',
1346 'member' => 'tt class="member"',
1347 'programopt' => 'b',
1348 'textrm' => '',
1349 );
1350
Fred Drakef5478632002-05-23 17:59:16 +00001351sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001352 # do a little magic on a font name to get the right behavior in the first
1353 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001354 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001355 if (defined $FontConversions{$font}) {
1356 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001357 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001358 return $font;
1359}
1360
Fred Drakef5478632002-05-23 17:59:16 +00001361sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001362 my $a = $_[0];
1363 if (!defined $a) {
1364 return '';
1365 }
Fred Drakee15956b2000-04-03 04:51:13 +00001366 my $mark = substr($a, 0, 1);
1367 my $r = '';
1368 if ($mark eq 'c')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001369 { $r = ' class="center"'; }
Fred Drakee15956b2000-04-03 04:51:13 +00001370 elsif ($mark eq 'r')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001371 { $r = ' class="right" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001372 elsif ($mark eq 'l')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001373 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001374 elsif ($mark eq 'p')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001375 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001376 return $r;
1377}
1378
Fred Drakef5478632002-05-23 17:59:16 +00001379sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001380 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001381 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001382 my $a1 = figure_column_alignment($s1);
1383 my $a2 = figure_column_alignment($s2);
1384 my $a3 = figure_column_alignment($s3);
1385 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001386 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001387 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1388 $col_aligns[1] = "<td$a2>";
1389 $col_aligns[2] = "<td$a3>";
1390 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001391 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001392 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001393 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001394}
1395
Fred Drakef5478632002-05-23 17:59:16 +00001396sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001397 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001398 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001399 if ($font) {
1400 $sfont = "<$font>";
1401 $efont = "</$font>";
1402 $efont =~ s/ .*>/>/;
1403 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001404 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001405}
1406
1407sub do_env_tableii{
1408 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001409 my $arg = next_argument();
1410 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001411 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001412 my $h1 = next_argument();
1413 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001414 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001415 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001416 my $a1 = $col_aligns[0];
1417 my $a2 = $col_aligns[1];
1418 s/\\lineii</\\lineii[$a1|$a2]</g;
Fred Drake39a6a6d2004-11-10 15:37:54 +00001419 return '<table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001420 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001421 . "\n <tr>"
1422 . "\n $th1$h1</th>"
1423 . "\n $th2$h2</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001424 . "\n </tr>"
1425 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001426 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001427 . $_
1428 . "\n </tbody>"
1429 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001430}
1431
Fred Drakeda72b932000-09-21 15:58:02 +00001432sub do_env_longtableii{
1433 return do_env_tableii(@_);
1434}
1435
Fred Drake6659c301998-03-03 22:02:19 +00001436sub do_cmd_lineii{
1437 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001438 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001439 my $c1 = next_argument();
1440 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001441 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001442 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001443 my($c1align, $c2align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001444 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1445 . " $c2align$c2</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001446 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001447}
1448
1449sub do_env_tableiii{
1450 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001451 my $arg = next_argument();
1452 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001453 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001454 my $h1 = next_argument();
1455 my $h2 = next_argument();
1456 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001457 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001458 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001459 my $a1 = $col_aligns[0];
1460 my $a2 = $col_aligns[1];
1461 my $a3 = $col_aligns[2];
1462 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
Fred Drake39a6a6d2004-11-10 15:37:54 +00001463 return '<table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001464 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001465 . "\n <tr>"
1466 . "\n $th1$h1</th>"
1467 . "\n $th2$h2</th>"
1468 . "\n $th3$h3</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001469 . "\n </tr>"
1470 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001471 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001472 . $_
1473 . "\n </tbody>"
1474 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001475}
1476
Fred Drakeda72b932000-09-21 15:58:02 +00001477sub do_env_longtableiii{
1478 return do_env_tableiii(@_);
1479}
1480
Fred Drake6659c301998-03-03 22:02:19 +00001481sub do_cmd_lineiii{
1482 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001483 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001484 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001485 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001486 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001487 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001488 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001489 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001490 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001491 . " $c2align$c2</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001492 . " $c3align$c3</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001493 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001494}
1495
Fred Drakea0f4c941998-07-24 22:16:04 +00001496sub do_env_tableiv{
1497 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001498 my $arg = next_argument();
1499 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001500 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001501 my $h1 = next_argument();
1502 my $h2 = next_argument();
1503 my $h3 = next_argument();
1504 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001505 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001506 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001507 my $a1 = $col_aligns[0];
1508 my $a2 = $col_aligns[1];
1509 my $a3 = $col_aligns[2];
1510 my $a4 = $col_aligns[3];
1511 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
Fred Drake39a6a6d2004-11-10 15:37:54 +00001512 return '<table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001513 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001514 . "\n <tr>"
1515 . "\n $th1$h1</th>"
1516 . "\n $th2$h2</th>"
1517 . "\n $th3$h3</th>"
1518 . "\n $th4$h4</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001519 . "\n </tr>"
1520 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001521 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001522 . $_
1523 . "\n </tbody>"
1524 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001525}
1526
Fred Drakeda72b932000-09-21 15:58:02 +00001527sub do_env_longtableiv{
1528 return do_env_tableiv(@_);
1529}
1530
Fred Drakea0f4c941998-07-24 22:16:04 +00001531sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001532 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001533 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001534 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001535 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001536 my $c3 = next_argument();
1537 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001538 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001539 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001540 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001541 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001542 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001543 . " $c3align$c3</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001544 . " $c4align$c4</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001545 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001546}
1547
Fred Drakef269e592001-07-17 23:05:57 +00001548sub do_env_tablev{
1549 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001550 my $arg = next_argument();
1551 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001552 my $font = fix_font(next_argument());
1553 my $h1 = next_argument();
1554 my $h2 = next_argument();
1555 my $h3 = next_argument();
1556 my $h4 = next_argument();
1557 my $h5 = next_argument();
1558 s/[\s\n]+//;
1559 $globals{'lineifont'} = $font;
1560 my $a1 = $col_aligns[0];
1561 my $a2 = $col_aligns[1];
1562 my $a3 = $col_aligns[2];
1563 my $a4 = $col_aligns[3];
1564 my $a5 = $col_aligns[4];
1565 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
Fred Drake39a6a6d2004-11-10 15:37:54 +00001566 return '<table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001567 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001568 . "\n <tr>"
1569 . "\n $th1$h1</th>"
1570 . "\n $th2$h2</th>"
1571 . "\n $th3$h3</th>"
1572 . "\n $th4$h4</th>"
1573 . "\n $th5$h5</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001574 . "\n </tr>"
1575 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001576 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001577 . $_
1578 . "\n </tbody>"
1579 . "\n</table>";
Fred Drakef269e592001-07-17 23:05:57 +00001580}
1581
1582sub do_env_longtablev{
1583 return do_env_tablev(@_);
1584}
1585
1586sub do_cmd_linev{
1587 local($_) = @_;
1588 my $aligns = next_optional_argument();
1589 my $c1 = next_argument();
1590 my $c2 = next_argument();
1591 my $c3 = next_argument();
1592 my $c4 = next_argument();
1593 my $c5 = next_argument();
1594 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001595 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001596 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001597 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef269e592001-07-17 23:05:57 +00001598 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001599 . " $c3align$c3</td>\n"
1600 . " $c4align$c4</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001601 . " $c5align$c5</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001602 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001603}
1604
Fred Drake3be20742000-08-31 06:22:54 +00001605
1606# These can be used to control the title page appearance;
1607# they need a little bit of documentation.
1608#
1609# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1610# $ICONSERVER directory, or include path information (other than "./"). The
1611# default image type will be assumed if an extension is not provided.
1612#
1613# If specified, the "title page" will contain two colums: one containing the
1614# title/author/etc., and the other containing the graphic. Use the other
1615# four variables listed here to control specific details of the layout; all
1616# are optional.
1617#
1618# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1619# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1620# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1621# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1622# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1623
Fred Drakef5478632002-05-23 17:59:16 +00001624sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001625 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001626 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001627 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001628 }
1629 else {
1630 write_warnings("\nThis document has no title.");
1631 }
Fred Drake6659c301998-03-03 22:02:19 +00001632 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001633 if ($t_authorURL) {
1634 my $href = translate_commands($t_authorURL);
1635 $href = make_named_href('author', $href,
1636 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001637 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001638 $the_title .= "\n<p>$href</p>";
1639 }
Fred Drake3be20742000-08-31 06:22:54 +00001640 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001641 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001642 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001643 }
Fred Drake3be20742000-08-31 06:22:54 +00001644 }
1645 else {
1646 write_warnings("\nThere is no author for this document.");
1647 }
Fred Drake6659c301998-03-03 22:02:19 +00001648 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001649 $the_title .= "\n<p>$t_institute</p>";
1650 }
Fred Draked07868a1998-05-14 21:00:28 +00001651 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001652 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1653 }
Fred Drake6659c301998-03-03 22:02:19 +00001654 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001655 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001656 }
Fred Drake6659c301998-03-03 22:02:19 +00001657 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001658 $the_title .= "\n<p>";
1659 if ($PACKAGE_VERSION) {
1660 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001661 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001662 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001663 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001664 }
1665 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001666 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001667 }
1668 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001669 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001670 }
Fred Drake6659c301998-03-03 22:02:19 +00001671 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001672 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001673 }
1674 return $the_title;
1675}
1676
Fred Drakef5478632002-05-23 17:59:16 +00001677sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001678 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001679 my $graphic = "<td class=\"titlegraphic\"";
1680 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1681 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1682 $graphic .= "><img";
1683 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1684 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1685 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1686 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001687 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001688 return $graphic;
1689}
1690
Fred Drakef5478632002-05-23 17:59:16 +00001691sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001692 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001693 my $the_title = "\n";
1694 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001695 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001696 # body), but I don't see any other way to get this generated
1697 # at all. Browsers like Mozilla, that support navigation
1698 # links, can make use of this.
1699 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1700 . ($EXTERNAL_UP_TITLE
1701 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001702 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001703 }
1704 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001705 if ($TITLE_PAGE_GRAPHIC) {
1706 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1707 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1708 . "<tr align=\"right\">\n<td>"
1709 . make_my_titlepage()
1710 . "</td>\n"
1711 . make_my_titlegraphic()
1712 . "</tr>\n</table>");
1713 }
1714 else {
1715 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1716 . make_my_titlegraphic()
1717 . "<td>"
1718 . make_my_titlepage()
1719 . "</td></tr>\n</table>");
1720 }
1721 }
1722 else {
1723 $the_title .= ("\n<center>"
1724 . make_my_titlepage()
1725 . "\n</center>");
1726 }
1727 $the_title .= "\n</div>";
1728 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001729 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001730 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001731}
1732
1733
Fred Drake885215c1998-05-20 21:32:09 +00001734#
Fred Drakea0f4c941998-07-24 22:16:04 +00001735# Module synopsis support
1736#
1737
1738require SynopsisTable;
1739
Fred Drakef7685d71998-07-25 03:31:46 +00001740sub get_chapter_id(){
1741 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001742 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001743 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001744 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001745}
1746
Fred Drake643d76d2000-09-09 06:07:37 +00001747# 'chapter' => 'SynopsisTable instance'
1748%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001749
1750sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001751 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001752 my $key;
1753 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001754 if ($key eq $chap) {
1755 return $ModuleSynopses{$chap};
1756 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001757 }
Fred Drake643d76d2000-09-09 06:07:37 +00001758 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001759 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001760 return $st;
1761}
1762
Fred Drake62e43691998-08-10 19:40:44 +00001763sub do_cmd_moduleauthor{
1764 local($_) = @_;
1765 next_argument();
1766 next_argument();
1767 return $_;
1768}
1769
1770sub do_cmd_sectionauthor{
1771 local($_) = @_;
1772 next_argument();
1773 next_argument();
1774 return $_;
1775}
1776
Fred Drakea0f4c941998-07-24 22:16:04 +00001777sub do_cmd_declaremodule{
1778 local($_) = @_;
1779 my $key = next_optional_argument();
1780 my $type = next_argument();
1781 my $name = next_argument();
1782 my $st = get_synopsis_table(get_chapter_id());
1783 #
1784 $key = $name unless $key;
1785 $type = 'built-in' if $type eq 'builtin';
1786 $st->declare($name, $key, $type);
1787 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001788 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001789}
1790
1791sub do_cmd_modulesynopsis{
1792 local($_) = @_;
1793 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001794 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001795 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001796}
1797
1798sub do_cmd_localmoduletable{
1799 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001800 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001801 my $st = get_synopsis_table($chap);
1802 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001803 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001804}
1805
Fred Drakef5478632002-05-23 17:59:16 +00001806sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001807 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001808 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001809 my $st = $ModuleSynopses{$key};
1810 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001811 if ($file) {
1812 process_localmoduletables_in_file($file);
1813 }
1814 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001815 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001816 }
1817 }
1818}
1819
Fred Drakef5478632002-05-23 17:59:16 +00001820sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001821 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001822 open(MYFILE, "<$file");
1823 local($_);
1824 sysread(MYFILE, $_, 1024*1024);
1825 close(MYFILE);
1826 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001827 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001828 my $match = $&;
1829 my $chap = $1;
1830 my $st = get_synopsis_table($chap);
1831 my $data = $st->tohtml();
1832 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001833 }
Fred Drake643d76d2000-09-09 06:07:37 +00001834 open(MYFILE,">$file");
1835 print MYFILE $_;
1836 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001837}
Fred Drakef5478632002-05-23 17:59:16 +00001838sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001839 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001840 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001841}
Fred Drakea0f4c941998-07-24 22:16:04 +00001842
1843
1844#
1845# "See also:" -- references placed at the end of a \section
1846#
1847
1848sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001849 return ("<div class=\"seealso\">\n "
Fred Drake0cf87be2004-11-10 08:08:26 +00001850 . "<p class=\"heading\">See Also:</p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001851 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001852 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001853}
1854
Fred Drake5ed35fd2001-11-30 18:09:54 +00001855sub do_env_seealsostar{
1856 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001857 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001858 . '</div>');
1859}
1860
Fred Drakea0f4c941998-07-24 22:16:04 +00001861sub do_cmd_seemodule{
1862 # Insert the right magic to jump to the module definition. This should
1863 # work most of the time, at least for repeat builds....
1864 local($_) = @_;
1865 my $key = next_optional_argument();
1866 my $module = next_argument();
1867 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001868 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001869 $key = $module
1870 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001871 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001872 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001873 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001874 return ('<dl compact="compact" class="seemodule">'
Fred Drakef1927a62001-06-20 21:29:30 +00001875 . "\n <dt>Module <b><tt class=\"module\">"
1876 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1877 . "\n <dd>$text$period\n </dl>"
1878 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001879}
1880
Fred Drakee0197bf2001-04-12 04:03:22 +00001881sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001882 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001883 my $s = "$str";
1884 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1885 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1886 return $s;
1887}
1888
Fred Drakef5478632002-05-23 17:59:16 +00001889sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001890 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001891 my $rfcnum = next_argument();
1892 my $title = next_argument();
1893 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001894 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001895 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001896 my $attrtitle = strip_html_markup($title);
Fred Draked7a5bca2004-11-10 08:07:00 +00001897 return '<dl compact="compact" class="seerfc">'
Fred Drake37cc0c02000-04-26 18:05:24 +00001898 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001899 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001900 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001901 . "\n <dd>$text\n </dl>"
1902 . $_;
1903}
1904
Fred Drake643d76d2000-09-09 06:07:37 +00001905sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001906 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001907}
1908
1909sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001910 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001911 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001912}
1913
Fred Drake48449982000-09-12 17:52:33 +00001914sub do_cmd_seetitle{
1915 local($_) = @_;
1916 my $url = next_optional_argument();
1917 my $title = next_argument();
1918 my $text = next_argument();
1919 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001920 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001921 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001922 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001923 . "\n >$title$icon</a></em></dt>"
1924 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001925 . $_;
1926 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001927 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001928 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001929 . "\n >$title</em></dt>"
1930 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001931 . $_;
1932}
1933
Fred Drake4f687b32004-01-08 14:57:27 +00001934sub do_cmd_seelink{
1935 local($_) = @_;
1936 my $url = next_argument();
1937 my $linktext = next_argument();
1938 my $text = next_argument();
1939 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001940 return '<dl compact="compact" class="seeurl">'
Fred Drake4f687b32004-01-08 14:57:27 +00001941 . "\n <dt><a href='$url'"
1942 . "\n >$linktext$icon</a></dt>"
1943 . "\n <dd>$text</dd>\n </dl>"
1944 . $_;
1945}
1946
Fred Drakeef4d1112000-05-09 16:17:51 +00001947sub do_cmd_seeurl{
1948 local($_) = @_;
1949 my $url = next_argument();
1950 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001951 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001952 return '<dl compact="compact" class="seeurl">'
Fred Drakeef4d1112000-05-09 16:17:51 +00001953 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001954 . "\n class=\"url\">$url$icon</a></dt>"
1955 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001956 . $_;
1957}
1958
Fred Drakea0f4c941998-07-24 22:16:04 +00001959sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001960 local($_) = @_;
1961 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001962 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001963}
1964
1965
1966#
Fred Drake885215c1998-05-20 21:32:09 +00001967# Definition list support.
1968#
1969
1970sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001971 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001972}
1973
1974sub do_cmd_term{
1975 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001976 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001977 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001978 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001979 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001980}
1981
1982
Fred Drake4e72e052003-07-15 22:00:36 +00001983# Commands listed here have process-order dependencies; these often
1984# are related to indexing operations.
1985# XXX Not sure why funclineni, methodlineni, and samp are here.
1986#
Fred Drake2ff880e1999-02-05 18:31:29 +00001987process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001988declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001989funcline # {} # {}
1990funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001991memberline # [] # {}
1992methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001993methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001994modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001995bifuncindex # {}
1996exindex # {}
1997indexii # {} # {}
1998indexiii # {} # {} # {}
1999indexiv # {} # {} # {} # {}
2000kwindex # {}
2001obindex # {}
2002opindex # {}
2003stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002004platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002005samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002006setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002007withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002008_RAW_ARG_DEFERRED_CMDS_
2009
2010
Fred Drake8a5e6792002-04-15 18:41:31 +00002011$alltt_start = '<div class="verbatim"><pre>';
2012$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002013
Fred Drakef5478632002-05-23 17:59:16 +00002014sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002015 local ($_) = @_;
2016 local($closures,$reopens,@open_block_tags);
2017
2018 # get the tag-strings for all open tags
2019 local(@keep_open_tags) = @$open_tags_R;
2020 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2021
2022 # get the tags for text-level tags only
2023 $open_tags_R = [ @keep_open_tags ];
2024 local($local_closures, $local_reopens);
2025 ($local_closures, $local_reopens,@open_block_tags)
2026 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002027 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002028
2029 $open_tags_R = [ @open_block_tags ];
2030
2031 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002032 local($open_tags_R) = [ @open_block_tags ];
2033 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002034
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002035 local($cnt) = ++$global{'max_id'};
2036 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2037 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002038
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002039 $_ = &translate_environments($_);
2040 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002041
Fred Drake41aa0182003-09-05 15:43:00 +00002042 # remove spurious <BR> someone sticks in; not sure where they
2043 # actually come from
2044 # XXX the replacement space is there to accomodate something
2045 # broken that inserts a space in front of the first line of
2046 # the environment
2047 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002048
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002049 $_ = join('', $closures, $alltt_start, $local_reopens
2050 , $_
2051 , &balance_tags() #, $local_closures
2052 , $alltt_end, $reopens);
2053 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002054 };
2055 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002056 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002057}
2058
Fred Drake8effa012004-04-01 04:30:29 +00002059# List of all filenames produced by do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002060%VerbatimFiles = ();
2061@VerbatimOutputs = ();
2062
2063sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002064 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002065 #
2066 # Re-write the source filename to always use a .txt extension
2067 # so that Web servers will present it as text/plain. This is
2068 # needed since there is no other even moderately reliable way
2069 # to get the right Content-Type header on text files for
2070 # servers which we can't configure (like python.org mirrors).
2071 #
2072 if (defined $VerbatimFiles{$file}) {
2073 # We've seen this one before; re-use the same output file.
2074 return $VerbatimFiles{$file};
2075 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002076 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002077 $filename = "$srcname.txt";
2078 #
2079 # We need to determine if our default filename is already
2080 # being used, and find a new one it it is. If the name is in
2081 # used, this algorithm will first attempt to include the
2082 # source extension as part of the name, and if that is also in
2083 # use (if the same file is included multiple times, or if
2084 # another source file has that as the base name), a counter is
2085 # used instead.
2086 #
2087 my $found = 1;
2088 FIND:
2089 while ($found) {
2090 foreach $fn (@VerbatimOutputs) {
2091 if ($fn eq $filename) {
2092 if ($found == 1) {
2093 $srcext =~ s/^[.]//; # Remove '.' from extension
2094 $filename = "$srcname-$srcext.txt";
2095 }
2096 else {
2097 $filename = "$srcname-$found.txt";
2098 }
2099 ++$found;
2100 next FIND;
2101 }
2102 }
2103 $found = 0;
2104 }
2105 push @VerbatimOutputs, $filename;
2106 $VerbatimFiles{$file} = $filename;
2107 return $filename;
2108}
2109
Fred Drake57e52ef2001-06-15 21:31:57 +00002110sub do_cmd_verbatiminput{
2111 local($_) = @_;
2112 my $fname = next_argument();
2113 my $file;
2114 my $found = 0;
2115 my $texpath;
2116 # Search TEXINPUTS for the input file, the way we're supposed to:
2117 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2118 $file = "$texpath$dd$fname";
2119 last if ($found = (-f $file));
2120 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002121 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002122 my $text;
2123 if ($found) {
2124 open(MYFILE, "<$file") || die "\n$!\n";
2125 read(MYFILE, $text, 1024*1024);
2126 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002127 $filename = get_verbatim_output_name($file);
2128 # Now that we have a filename, write it out.
2129 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002130 print MYFILE $text;
2131 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002132 #
2133 # These rewrites convert the raw text to something that will
2134 # be properly visible as HTML and also will pass through the
2135 # vagaries of conversion through LaTeX2HTML. The order in
2136 # which the specific rewrites are performed is significant.
2137 #
2138 $text =~ s/\&/\&amp;/g;
2139 # These need to happen before the normal < and > re-writes,
2140 # since we need to avoid LaTeX2HTML's attempt to perform
2141 # ligature processing without regard to context (since it
2142 # doesn't have font information).
2143 $text =~ s/--/-&\#45;/g;
2144 $text =~ s/<</\&lt;\&\#60;/g;
2145 $text =~ s/>>/\&gt;\&\#62;/g;
2146 # Just normal re-writes...
2147 $text =~ s/</\&lt;/g;
2148 $text =~ s/>/\&gt;/g;
2149 # These last isn't needed for the HTML, but is needed to get
2150 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2151 # of &sol; since many browsers don't support that.
2152 $text =~ s/\\/\&\#92;/g;
2153 }
2154 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002155 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2156 }
2157 my $note = 'Download as text.';
2158 if ($file ne $filename) {
2159 $note = ('Download as text (original file name: <span class="file">'
2160 . $fname
2161 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002162 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002163 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002164 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002165 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002166 . "<a href=\"$filename\" type=\"text/plain\""
2167 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002168 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002169 . $_);
2170}
Fred Drake86333602001-04-10 17:13:39 +00002171
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021721; # This must be the last line