blob: c1ebd196649d2308e8d2b751f1db5ef3c61cd320 [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 Drakebd5fdd92003-07-16 14:01:56 +000098sub do_cmd_menuselection{
99 return use_wrappers($_[0], '<span class="menuselection">', '</span>'); }
Fred Drake49b33fa2002-11-15 19:04:10 +0000100sub do_cmd_sub{ ' > ' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +0000101
102
Fred Drake6659c301998-03-03 22:02:19 +0000103# words typeset in a special way (not in HTML though)
104
Fred Drake49b33fa2002-11-15 19:04:10 +0000105sub do_cmd_ABC{ 'ABC' . $_[0]; }
Fred Drake5bbeb8d2003-02-04 15:01:37 +0000106sub do_cmd_UNIX{ '<font style="font-variant: small-caps;">Unix</font>'
107 . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000108sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
109sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
110sub do_cmd_C{ 'C' . $_[0]; }
111sub do_cmd_Cpp{ 'C++' . $_[0]; }
112sub do_cmd_EOF{ 'EOF' . $_[0]; }
113sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000114
Fred Drake49b33fa2002-11-15 19:04:10 +0000115sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000116
Fred Draked07868a1998-05-14 21:00:28 +0000117$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000118$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000119$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000120$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000121
Fred Drake49b33fa2002-11-15 19:04:10 +0000122sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
123sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000124sub do_cmd_release{
125 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000126 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000127 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000128}
129
Fred Drakef1927a62001-06-20 21:29:30 +0000130sub do_cmd_setreleaseinfo{
131 local($_) = @_;
132 $RELEASE_INFO = next_argument();
133 return $_;
134}
135
Fred Drake3cdb89d2000-09-14 20:17:23 +0000136sub do_cmd_setshortversion{
137 local($_) = @_;
138 $SHORT_VERSION = next_argument();
139 return $_;
140}
141
Fred Drake6659c301998-03-03 22:02:19 +0000142sub do_cmd_authoraddress{
143 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000144 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000145 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000146}
147
Fred Drake49b33fa2002-11-15 19:04:10 +0000148#sub do_cmd_developer{ do_cmd_author($_[0]); }
149#sub do_cmd_developers{ do_cmd_author($_[0]); }
150#sub do_cmd_developersaddress{ do_cmd_authoraddress($_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000151
Fred Drake6659c301998-03-03 22:02:19 +0000152sub do_cmd_hackscore{
153 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000154 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000155 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000156}
157
Fred Drakef5478632002-05-23 17:59:16 +0000158sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000159 local($_,$before,$after) = @_;
160 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000161 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000162}
163
Fred Drake3cdb89d2000-09-14 20:17:23 +0000164$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000165sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000166 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000167 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000168 "</var><big>\]</big><var>");
169 }
170 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000171 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000172 }
Fred Drake6659c301998-03-03 22:02:19 +0000173}
174
Fred Drakec9a44381998-03-17 06:29:13 +0000175# Logical formatting (some based on texinfo), needs to be converted to
176# minimalist HTML. The "minimalist" is primarily to reduce the size of
177# output files for users that read them over the network rather than
178# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000179
Fred Drake49b33fa2002-11-15 19:04:10 +0000180sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000181sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000182 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000183sub do_cmd_code{
Fred Drake49b33fa2002-11-15 19:04:10 +0000184 return use_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000185sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000186 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000187sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000188 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000189sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000190 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000191sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000192 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000193sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000194 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000195sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000196 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000197sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000198 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000199sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000200 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000201sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000202 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000203sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000204 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000205sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000206 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000207sub do_cmd_regexp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000208 return use_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000209sub do_cmd_character{
Fred Drake49b33fa2002-11-15 19:04:10 +0000210 return use_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000211sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000212 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000213sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000214 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000215sub do_cmd_longprogramopt{
216 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000217 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000218sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000219 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000220sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000221 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000222sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000223 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000224sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000225 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000226sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000227 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000228sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000229 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000230sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000231 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000232sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000233 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000234sub do_cmd_samp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000235 return use_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000236sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000237 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000238sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000239 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000240sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000241 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000242sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000243 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000244# This can be changed/overridden for translations:
245%NoticeNames = ('note' => 'Note:',
246 'warning' => 'Warning:',
247 );
248
Fred Drake92350b32001-10-09 18:01:23 +0000249sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000250 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000251 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000252 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000253 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000254 '</span>'); }
255sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000256 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000257 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000258 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000259 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000260 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000261
Fred Drake6ca33772001-12-14 22:50:06 +0000262sub do_env_notice{
263 local($_) = @_;
264 my $notice = next_optional_argument();
265 if (!$notice) {
266 $notice = 'note';
267 }
268 my $label = $NoticeNames{$notice};
269 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
270 . $_
271 . '</div>');
272}
273
Fred Drake3d5a04a2000-08-03 17:25:44 +0000274sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000275 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000276sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000277 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000278
Fred Drakec9a44381998-03-17 06:29:13 +0000279
Fred Drake25817041999-01-13 17:06:34 +0000280sub do_cmd_refmodule{
281 # Insert the right magic to jump to the module definition.
282 local($_) = @_;
283 my $key = next_optional_argument();
284 my $module = next_argument();
285 $key = $module
286 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000287 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000288 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000289}
290
Fred Drake1a7af391998-04-01 22:44:56 +0000291sub do_cmd_newsgroup{
292 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000293 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000294 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000295 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
296 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000297 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000298}
Fred Drakefc16e781998-03-12 21:03:26 +0000299
300sub do_cmd_envvar{
301 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000302 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000303 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000304 # The <tt> here is really to keep buildindex.py from making
305 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000306 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000307 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000308 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000309 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000310 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000311}
312
Fred Drake6659c301998-03-03 22:02:19 +0000313sub do_cmd_url{
314 # use the URL as both text and hyperlink
315 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000316 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000317 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000318 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000319 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000320}
321
322sub do_cmd_manpage{
323 # two parameters: \manpage{name}{section}
324 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000325 my $page = next_argument();
326 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000327 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000328}
329
Fred Drakedbfe7682002-04-03 02:47:14 +0000330$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000331#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
332$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000333
334sub get_rfc_url($$){
335 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000336 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000337}
338
339sub do_cmd_pep{
340 local($_) = @_;
341 my $rfcnumber = next_argument();
342 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000343 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000344 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000345 # Save the reference
346 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
347 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake2fc88a62003-08-05 03:45:37 +0000348 return ("<a class=\"rfc\" name=\"$id\" id='$id'\n"
349 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000350}
351
Fred Drake6659c301998-03-03 22:02:19 +0000352sub do_cmd_rfc{
353 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000354 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, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000357 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000358 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000359 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000360 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake2fc88a62003-08-05 03:45:37 +0000361 return ("<a class=\"rfc\" name=\"$id\" id='$id'\nhref=\"$href\">"
362 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000363}
364
Fred Drake77602f22001-07-06 22:43:02 +0000365sub do_cmd_ulink{
366 local($_) = @_;
367 my $text = next_argument();
368 my $url = next_argument();
369 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
370}
371
Fred Drakec9f5fe01999-11-09 16:59:42 +0000372sub do_cmd_citetitle{
373 local($_) = @_;
374 my $url = next_optional_argument();
375 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000376 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000377 my $repl = '';
378 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000379 $repl = ("<em class=\"citetitle\"><a\n"
380 . " href=\"$url\"\n"
381 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000382 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000383 }
384 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000385 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000386 }
387 return $repl . $_;
388}
389
Fred Drake6659c301998-03-03 22:02:19 +0000390sub do_cmd_deprecated{
391 # two parameters: \deprecated{version}{whattodo}
392 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000393 my $release = next_argument();
394 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000395 return ('<div class="versionnote">'
396 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000397 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000398 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000399}
400
Fred Drakef5478632002-05-23 17:59:16 +0000401sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000402 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000403 my $type = $_[0];
404 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000405 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000406 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000407 my $text = "$type in version $release.";
408 if ($explanation) {
409 $text = "$type in version $release:\n$explanation.";
410 }
Fred Drakef1927a62001-06-20 21:29:30 +0000411 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000412}
413
414sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000415 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000416}
417
418sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000419 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000420}
421
Fred Drake557460c1999-03-02 16:05:35 +0000422#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000423# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000424#
425sub do_cmd_platform{
426 local($_) = @_;
427 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000428 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000429 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000430 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000431 return "\n<p class=\"availability\">Availability: <span"
432 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000433}
434
Fred Drake557460c1999-03-02 16:05:35 +0000435$IGNORE_PLATFORM_ANNOTATION = '';
436sub do_cmd_ignorePlatformAnnotation{
437 local($_) = @_;
438 $IGNORE_PLATFORM_ANNOTATION = next_argument();
439 return $_;
440}
441
Fred Drake6659c301998-03-03 22:02:19 +0000442
443# index commands
444
445$INDEX_SUBITEM = "";
446
Fred Drakef5478632002-05-23 17:59:16 +0000447sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000448 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000449}
450
451sub do_cmd_setindexsubitem{
452 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000453 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000454 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000455}
456
Fred Drakefc16e781998-03-12 21:03:26 +0000457sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000458 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000459 # do things in the right order, but we need to at least strip this stuff
460 # out, and leave anything that the second argument expanded out to.
461 #
462 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000463 my $oldsubitem = $INDEX_SUBITEM;
464 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000465 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000466 my $br_id = ++$globals{'max_id'};
467 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000468 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000469 return
470 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000471 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000472 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000473}
474
Fred Drake08932051998-04-17 02:15:42 +0000475# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000476# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
477# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000478#
Fred Drake49b33fa2002-11-15 19:04:10 +0000479sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000480
Fred Drake42b31a51998-03-27 05:16:10 +0000481# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000482#
Fred Drake08932051998-04-17 02:15:42 +0000483open(IDXFILE, '>index.dat') || die "\n$!\n";
484open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000485print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000486print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000487
488# Using \0 for this is bad because we can't use common tools to work with the
489# resulting files. Things like grep can be useful with this stuff!
490#
491$IDXFILE_FIELD_SEP = "\1";
492
Fred Drakef5478632002-05-23 17:59:16 +0000493sub write_idxfile($$){
494 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000495 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000496}
497
Fred Drake42b31a51998-03-27 05:16:10 +0000498
Fred Drakef5478632002-05-23 17:59:16 +0000499sub gen_link($$){
500 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000501 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000502 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000503}
504
Fred Drakef5478632002-05-23 17:59:16 +0000505sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000506 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000507 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000508 $str = gen_index_id($str, '');
509 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000510 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000511}
512
Fred Drakef5478632002-05-23 17:59:16 +0000513sub new_link_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000514 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake2fc88a62003-08-05 03:45:37 +0000515 my $aname = "<a name=\"$name\" id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000516 my $ahref = gen_link($CURRENT_FILE, $name);
517 return ($name, $aname, $ahref);
518}
519
Fred Drakeab032151999-05-13 18:36:54 +0000520$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000521sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000522 my $count = @_;
523 my $i = 0;
524 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000525 my $name = $_[$i];
526 my $cmd = "idx_cmd_$name";
527 die "\nNo function $cmd() defined!\n"
528 if (!defined &$cmd);
529 eval ("sub do_cmd_$name { return process_index_macros("
530 . "\$_[0], '$name'); }");
531 if (length($IndexMacroPattern) == 0) {
532 $IndexMacroPattern = "$name";
533 }
534 else {
535 $IndexMacroPattern .= "|$name";
536 }
Fred Drakeab032151999-05-13 18:36:54 +0000537 }
538}
539
540$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000541sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000542 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000543 my $cmdname = $_[1]; # This is what triggered us in the first place;
544 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000545 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000546 my $cmd = "idx_cmd_$cmdname";
547 print "\nIndexing: \\$cmdname"
548 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000549 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000550 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000551 $cmdname = "$1";
552 print " \\$cmdname"
553 if $DEBUG_INDEXING;
554 $cmd = "idx_cmd_$cmdname";
555 if (!defined &$cmd) {
556 last;
557 }
558 else {
559 s/^[\s\n]*\\$cmdname//;
560 &$cmd($ahref);
561 }
Fred Drakeab032151999-05-13 18:36:54 +0000562 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000563 if (/^[ \t\r\n]/) {
564 $_ = substr($_, 1);
565 }
Fred Drake62e43691998-08-10 19:40:44 +0000566 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000567}
568
Fred Drakeab032151999-05-13 18:36:54 +0000569define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000570sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000571 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000572 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000573}
574
Fred Drakeab032151999-05-13 18:36:54 +0000575define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000576sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000577 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000578 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
579 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000580}
581
582define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000583sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000584 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000585 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000586 add_index_entry("$str1!$str2", $_[0]);
587 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000588}
589
Fred Drakeab032151999-05-13 18:36:54 +0000590define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000591sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000592 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000593 my $str2 = next_argument();
594 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000595 add_index_entry("$str1!$str2 $str3", $_[0]);
596 add_index_entry("$str2!$str3, $str1", $_[0]);
597 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000598}
599
Fred Drakeab032151999-05-13 18:36:54 +0000600define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000601sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000602 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000603 my $str2 = next_argument();
604 my $str3 = next_argument();
605 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000606 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
607 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
608 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
609 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000610}
611
Fred Drakeab032151999-05-13 18:36:54 +0000612define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000613sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000614 my $str = next_argument();
615 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000616 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000617}
Fred Drake6659c301998-03-03 22:02:19 +0000618
Fred Drakef5478632002-05-23 17:59:16 +0000619sub my_typed_index_helper($$){
620 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000621 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000622 add_index_entry("$str $word", $ahref);
623 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000624}
625
Fred Drakeab032151999-05-13 18:36:54 +0000626define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000627sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
628sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
629sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
630sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000631
Fred Drakeab032151999-05-13 18:36:54 +0000632define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000633sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000634 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000635 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000636 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000637}
638
639
Fred Drakef5478632002-05-23 17:59:16 +0000640sub make_mod_index_entry($$){
641 my($str, $define) = @_;
642 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000643 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000644 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
645 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000646 $str = gen_index_id($str, $define);
647 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000648 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000649
Fred Drakec9a44381998-03-17 06:29:13 +0000650 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000651 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000652 $str =~ /(<tt.*<\/tt>)/;
653 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000654 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000655 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000656 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000657}
658
Fred Drake557460c1999-03-02 16:05:35 +0000659
Fred Drakec9a44381998-03-17 06:29:13 +0000660$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000661$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000662
Fred Drakef5478632002-05-23 17:59:16 +0000663sub define_module($$){
664 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000665 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000666 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000667 && $word ne "standard" && $word ne "") {
668 write_warnings("Bad module type '$word'"
669 . " for \\declaremodule (module $name)");
670 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000671 }
Fred Drake6659c301998-03-03 22:02:19 +0000672 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000673 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000674 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000675 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000676 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000677 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000678}
679
Fred Drakef5478632002-05-23 17:59:16 +0000680sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000681 local($word, $_) = @_;
682 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000683 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000684}
685
Fred Drake49b33fa2002-11-15 19:04:10 +0000686sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
687sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
688sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
689sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
690# local($_) = @_;
691# my $name = next_argument();
692# return define_module('standard', $name) . $_;
693# }
Fred Drake6659c301998-03-03 22:02:19 +0000694
Fred Drakef5478632002-05-23 17:59:16 +0000695sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000696 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000697 my $str = next_argument();
698 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000699 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000700 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
701 # just inline it all here
702 $str = gen_index_id($str, 'REF');
703 $index{$str} .= $ahref;
704 write_idxfile($ahref, $str);
705}
706
Fred Drake6659c301998-03-03 22:02:19 +0000707# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000708define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000709 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000710sub idx_cmd_refmodindex($){
711 return ref_module_index_helper('', $_[0]); }
712sub idx_cmd_refbimodindex($){
713 return ref_module_index_helper('built-in', $_[0]); }
714sub idx_cmd_refexmodindex($){
715 return ref_module_index_helper('extension', $_[0]);}
716sub idx_cmd_refstmodindex($){
717 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000718
Fred Drake49b33fa2002-11-15 19:04:10 +0000719sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000720
Fred Drakef5478632002-05-23 17:59:16 +0000721sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000722 # These markers must be non-empty or the main latex2html script
723 # may remove a surrounding element that has not other content as
724 # "extraneous"; this ensures these elements (usually hyperlink
725 # targets) are not removed improperly. We use comments since
726 # there's no meaningful actual content.
727 # Thanks to Dave Kuhlman for figuring why some named anchors were
728 # being lost.
729 $anchor_invisible_mark = '<!--x-->';
730 $anchor_invisible_mark2 = '<!--y-->';
731 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000732 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000733}
Fred Drake42b31a51998-03-27 05:16:10 +0000734init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000735
Fred Drakeab032151999-05-13 18:36:54 +0000736# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000737# instead of the dummy filler.
738#
Fred Drakef5478632002-05-23 17:59:16 +0000739sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000740 my $str = $_[0];
Fred Drakef5478632002-05-23 17:59:16 +0000741 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000742 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000743 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000744}
745
Fred Drake77602f22001-07-06 22:43:02 +0000746
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000747%TokenToTargetMapping = (); # language:token -> link target
748%DefinedGrammars = (); # language -> full grammar text
749%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000750
751sub do_cmd_token{
752 local($_) = @_;
753 my $token = next_argument();
754 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
755 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
756 # recursive definition or display-only productionlist
757 return "$token";
758 }
759 if ($target eq '') {
760 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
761 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
762 print "Adding '$CURRENT_FILE' to back-patch list.\n";
763 }
764 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
765 }
766 return "<a href=\"$target\">$token</a>" . $_;
767}
768
Fred Drake16bb4192001-08-20 21:36:38 +0000769sub do_cmd_grammartoken{
770 return do_cmd_token(@_);
771}
772
Fred Drake77602f22001-07-06 22:43:02 +0000773sub do_env_productionlist{
774 local($_) = @_;
775 my $lang = next_optional_argument();
776 my $filename = "grammar-$lang.txt";
777 if ($lang eq '') {
778 $filename = 'grammar.txt';
779 }
780 local($CURRENT_GRAMMAR) = $lang;
781 $DefinedGrammars{$lang} .= $_;
782 return ("<dl><dd class=\"grammar\">\n"
783 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000784 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000785 . translate_commands(translate_environments($_))
786 . "</table>\n"
787 . "</div>\n"
788 . (($lang eq '*')
789 ? ''
790 : ("<a class=\"grammar-footer\"\n"
791 . " href=\"$filename\" type=\"text/plain\"\n"
792 . " >Download entire grammar as text.</a>\n"))
793 . "</dd></dl>");
794}
795
796sub do_cmd_production{
797 local($_) = @_;
798 my $token = next_argument();
799 my $defn = next_argument();
800 my $lang = $CURRENT_GRAMMAR;
801 local($CURRENT_TOKEN) = $token;
802 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000803 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000804 . " <td><code>$token</code></td>\n"
805 . " <td>&nbsp;::=&nbsp;</td>\n"
806 . " <td><code>"
807 . translate_commands($defn)
808 . "</code></td></tr>"
809 . $_);
810 }
811 my $target;
812 if ($lang eq '') {
813 $target = "$CURRENT_FILE\#tok-$token";
814 }
815 else {
816 $target = "$CURRENT_FILE\#tok-$lang-$token";
817 }
818 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000819 return ("<tr valign=\"baseline\">\n"
Fred Drake2fc88a62003-08-05 03:45:37 +0000820 . " <td><code><a name=\"tok-$token\" id='tok-$token'>"
821 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000822 . " <td>&nbsp;::=&nbsp;</td>\n"
823 . " <td><code>"
824 . translate_commands($defn)
825 . "</code></td></tr>"
826 . $_);
827}
828
Fred Drake53815882002-03-15 23:21:37 +0000829sub do_cmd_productioncont{
830 local($_) = @_;
831 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000832 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000833 return ("<tr valign=\"baseline\">\n"
834 . " <td>&nbsp;</td>\n"
835 . " <td>&nbsp;</td>\n"
836 . " <td><code>"
837 . translate_commands($defn)
838 . "</code></td></tr>"
839 . $_);
840}
841
Fred Drakef5478632002-05-23 17:59:16 +0000842sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000843 my $lang;
844 my $filename;
845 local($_);
846 print "process_grammar_files()\n";
847 foreach $lang (keys %DefinedGrammars) {
848 $filename = "grammar-$lang.txt";
849 if ($lang eq '*') {
850 next;
851 }
852 if ($lang eq '') {
853 $filename = 'grammar.txt';
854 }
855 open(GRAMMAR, ">$filename") || die "\n$!\n";
856 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
857 close(GRAMMAR);
858 print "Wrote grammar file $filename\n";
859 }
860 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
861 foreach $filename (keys %BackpatchGrammarFiles) {
862 print "\nBack-patching grammar links in $filename\n";
863 my $buffer;
864 open(GRAMMAR, "<$filename") || die "\n$!\n";
865 # read all of the file into the buffer
866 sysread(GRAMMAR, $buffer, 1024*1024);
867 close(GRAMMAR);
868 while ($buffer =~ /$PATTERN/) {
869 my($lang, $token) = ($1, $2);
870 my $target = $TokenToTargetMapping{"$lang:$token"};
871 my $source = "<pyGrammarToken><$lang><$token>";
872 $buffer =~ s/$source/$target/g;
873 }
874 open(GRAMMAR, ">$filename") || die "\n$!\n";
875 print GRAMMAR $buffer;
876 close(GRAMMAR);
877 }
878}
879
Fred Drakef5478632002-05-23 17:59:16 +0000880sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000881 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000882 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000883 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
884 s/\\token(<<\d+>>)(.+)\1/$2/g;
885 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000886 s/<<\d+>>//g;
887 s/;SPMgt;/>/g;
888 s/;SPMlt;/</g;
889 s/;SPMquot;/\"/g;
890 return $_;
891}
892
893
Fred Drakee15956b2000-04-03 04:51:13 +0000894$REFCOUNTS_LOADED = 0;
895
Fred Drakef5478632002-05-23 17:59:16 +0000896sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000897 $REFCOUNTS_LOADED = 1;
898
Fred Drake49b33fa2002-11-15 19:04:10 +0000899 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000900 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000901 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000902 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000903 $mydir = getcwd() . "$dd$mydir"
904 unless $mydir =~ s|^/|/|;
905 local $_;
906 my $filename = "$mydir${dd}api${dd}refcounts.dat";
907 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
908 print "[loading API refcount data]";
909 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000910 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000911 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
912 #print "\n$func($param) --> $count";
913 $REFCOUNTS{"$func:$param"} = $count;
914 }
915 }
916}
917
Fred Drakef5478632002-05-23 17:59:16 +0000918sub get_refcount($$){
919 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000920 load_refcounts()
921 unless $REFCOUNTS_LOADED;
922 return $REFCOUNTS{"$func:$param"};
923}
924
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000925
926$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000927$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000928
Fred Drakef5478632002-05-23 17:59:16 +0000929sub cfuncline_helper($$$){
930 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000931 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000932 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000933 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000934 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000935 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
936 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000937 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
938 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
939 . "<td>$args)</td>"
940 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000941}
942sub do_cmd_cfuncline{
943 local($_) = @_;
944 my $type = next_argument();
945 my $name = next_argument();
946 my $args = next_argument();
947 my $siginfo = cfuncline_helper($type, $name, $args);
948 return "<dt>$siginfo\n<dd>" . $_;
949}
950sub do_env_cfuncdesc{
951 local($_) = @_;
952 my $type = next_argument();
953 my $name = next_argument();
954 my $args = next_argument();
955 my $siginfo = cfuncline_helper($type, $name, $args);
956 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000957 my $rcinfo = '';
958 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000959 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000960 }
961 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000962 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000963 }
Fred Drakec2578c52000-04-10 18:26:45 +0000964 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000965 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000966 }
Fred Drakee15956b2000-04-03 04:51:13 +0000967 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000968 $rcinfo = ( "\n<div class=\"refcount-info\">"
969 . "\n <span class=\"label\">Return value:</span>"
970 . "\n <span class=\"value\">$rcinfo.</span>"
971 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000972 }
Fred Drake2fc88a62003-08-05 03:45:37 +0000973 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000974 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000975 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +0000976 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000977}
978
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000979sub do_cmd_cmemberline{
980 local($_) = @_;
981 my $container = next_argument();
982 my $type = next_argument();
983 my $name = next_argument();
984 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000985 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000986 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +0000987 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000988 . $_;
989}
990sub do_env_cmemberdesc{
991 local($_) = @_;
992 my $container = next_argument();
993 my $type = next_argument();
994 my $name = next_argument();
995 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000996 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000997 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +0000998 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000999 . $_
1000 . '</dl>';
1001}
1002
Fred Drakee15956b2000-04-03 04:51:13 +00001003sub do_env_csimplemacrodesc{
1004 local($_) = @_;
1005 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001006 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001007 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001008 . $_
1009 . '</dl>'
1010}
1011
Fred Drake6659c301998-03-03 22:02:19 +00001012sub do_env_ctypedesc{
1013 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001014 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001015 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001016 $index_name = $type_name
1017 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001018 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001019 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001020 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1021 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001022 . $_
1023 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001024}
1025
1026sub do_env_cvardesc{
1027 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001028 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001029 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001030 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001031 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001032 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001033 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001034 . '<dd>'
1035 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001036 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001037}
1038
Fred Drake3cdb89d2000-09-14 20:17:23 +00001039sub convert_args($){
1040 local($IN_DESC_HANDLER) = 1;
1041 local($_) = @_;
1042 return translate_commands($_);
1043}
1044
Fred Drakef6e90272002-06-18 18:24:16 +00001045sub funcline_helper($$$){
1046 my($first, $idxitem, $arglist) = @_;
1047 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001048 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1049 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001050 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001051}
1052
Fred Drake6659c301998-03-03 22:02:19 +00001053sub do_env_funcdesc{
1054 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001055 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001056 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001057 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1058 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001059 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001060 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001061 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001062 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001063}
1064
1065sub do_env_funcdescni{
1066 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001067 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001068 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001069 my $prefix = "<tt class=\"function\">$function_name</tt>";
1070 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001071}
1072
1073sub do_cmd_funcline{
1074 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001075 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001076 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001077 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001078 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1079 $prefix =~ s/\(\)//;
1080
Fred Drakef6e90272002-06-18 18:24:16 +00001081 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001082}
1083
Fred Drake6b3fb781999-07-12 16:50:09 +00001084sub do_cmd_funclineni{
1085 local($_) = @_;
1086 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001087 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001088 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001089
Fred Drakef6e90272002-06-18 18:24:16 +00001090 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001091}
1092
Fred Drake6659c301998-03-03 22:02:19 +00001093# Change this flag to index the opcode entries. I don't think it's very
1094# useful to index them, since they're only presented to describe the dis
1095# module.
1096#
1097$INDEX_OPCODES = 0;
1098
1099sub do_env_opcodedesc{
1100 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001101 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001102 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001103 my $idx;
1104 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001105 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001106 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001107 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001108 }
1109 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001110 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001111 }
1112 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001113 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001114 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001115 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001116 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001117}
1118
1119sub do_env_datadesc{
1120 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001121 my $dataname = next_argument();
1122 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001123 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001124 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001125 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001126 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001127}
1128
1129sub do_env_datadescni{
1130 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001131 my $idx = next_argument();
1132 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001133 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001134 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001135 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001136}
1137
1138sub do_cmd_dataline{
1139 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001140 my $data_name = next_argument();
1141 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001142 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001143 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001144}
1145
Fred Drakeadb272c2000-04-10 17:47:14 +00001146sub do_cmd_datalineni{
1147 local($_) = @_;
1148 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001149 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001150}
1151
Fred Drake42b31a51998-03-27 05:16:10 +00001152sub do_env_excdesc{
1153 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001154 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001155 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001156 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001157 . "\n<dd>"
1158 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001159 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001160}
1161
Fred Drake62e43691998-08-10 19:40:44 +00001162sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001163
1164
Fred Drakef5478632002-05-23 17:59:16 +00001165sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001166 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001167 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001168 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001169 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001170 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001171 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001172 my $prefix = "$TLSTART$what$TLEND$idx";
1173 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001174}
1175
Fred Drake643d76d2000-09-09 06:07:37 +00001176sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001177 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001178}
1179
Fred Drake06a01e82001-05-11 01:00:30 +00001180sub do_env_classdescstar{
1181 local($_) = @_;
1182 $THIS_CLASS = next_argument();
1183 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001184 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001185 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001186 my $prefix = "${TLSTART}class$TLEND$idx";
1187 # Can't use funcline_helper() since there is no args list.
1188 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001189}
1190
Fred Drake643d76d2000-09-09 06:07:37 +00001191sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001192 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001193}
1194
Fred Drake42b31a51998-03-27 05:16:10 +00001195
1196sub do_env_methoddesc{
1197 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001198 my $class_name = next_optional_argument();
1199 $class_name = $THIS_CLASS
1200 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001201 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001202 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001203 my $extra = '';
1204 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001205 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001206 }
Fred Drakef1927a62001-06-20 21:29:30 +00001207 my $idx = make_str_index_entry(
1208 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001209 $idx =~ s/ \(.*\)//;
1210 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001211 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001212}
1213
1214
Fred Drake7d45f6d1999-01-05 14:39:27 +00001215sub do_cmd_methodline{
1216 local($_) = @_;
1217 my $class_name = next_optional_argument();
1218 $class_name = $THIS_CLASS
1219 unless $class_name;
1220 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001221 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001222 my $extra = '';
1223 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001224 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001225 }
Fred Drakef1927a62001-06-20 21:29:30 +00001226 my $idx = make_str_index_entry(
1227 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001228 $idx =~ s/ \(.*\)//;
1229 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001230 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001231}
1232
1233
Fred Draked64a40d1998-09-10 18:59:13 +00001234sub do_cmd_methodlineni{
1235 local($_) = @_;
1236 next_optional_argument();
1237 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001238 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001239 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001240}
1241
Fred Drake42b31a51998-03-27 05:16:10 +00001242sub do_env_methoddescni{
1243 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001244 next_optional_argument();
1245 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001246 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001247 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001248}
1249
1250
1251sub do_env_memberdesc{
1252 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001253 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001254 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001255 $class = $THIS_CLASS
1256 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001257 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001258 $extra = " ($class attribute)"
1259 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001260 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001261 $idx =~ s/ \(.*\)//;
1262 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001263 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001264}
1265
1266
Fred Drake5ccf3301998-04-17 20:04:09 +00001267sub do_cmd_memberline{
1268 local($_) = @_;
1269 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001270 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001271 $class = $THIS_CLASS
1272 unless $class;
1273 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001274 $extra = " ($class attribute)"
1275 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001276 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001277 $idx =~ s/ \(.*\)//;
1278 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001279 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001280}
1281
Fred Drakef269e592001-07-17 23:05:57 +00001282
Fred Drake42b31a51998-03-27 05:16:10 +00001283sub do_env_memberdescni{
1284 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001285 next_optional_argument();
1286 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001287 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001288 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001289 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001290}
1291
1292
Fred Drake5ccf3301998-04-17 20:04:09 +00001293sub do_cmd_memberlineni{
1294 local($_) = @_;
1295 next_optional_argument();
1296 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001297 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001298}
1299
Fred Drakef269e592001-07-17 23:05:57 +00001300
1301@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001302
Fred Drakecb199762001-08-16 21:56:24 +00001303%FontConversions = ('cdata' => 'tt class="cdata"',
1304 'character' => 'tt class="character"',
1305 'class' => 'tt class="class"',
1306 'command' => 'code',
1307 'constant' => 'tt class="constant"',
1308 'exception' => 'tt class="exception"',
1309 'file' => 'tt class="file"',
1310 'filenq' => 'tt class="file"',
1311 'kbd' => 'kbd',
1312 'member' => 'tt class="member"',
1313 'programopt' => 'b',
1314 'textrm' => '',
1315 );
1316
Fred Drakef5478632002-05-23 17:59:16 +00001317sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001318 # do a little magic on a font name to get the right behavior in the first
1319 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001320 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001321 if (defined $FontConversions{$font}) {
1322 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001323 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001324 return $font;
1325}
1326
Fred Drakef5478632002-05-23 17:59:16 +00001327sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001328 my $a = $_[0];
1329 if (!defined $a) {
1330 return '';
1331 }
Fred Drakee15956b2000-04-03 04:51:13 +00001332 my $mark = substr($a, 0, 1);
1333 my $r = '';
1334 if ($mark eq 'c')
1335 { $r = ' align="center"'; }
1336 elsif ($mark eq 'r')
1337 { $r = ' align="right"'; }
1338 elsif ($mark eq 'l')
1339 { $r = ' align="left"'; }
1340 elsif ($mark eq 'p')
1341 { $r = ' align="left"'; }
1342 return $r;
1343}
1344
Fred Drakef5478632002-05-23 17:59:16 +00001345sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001346 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001347 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001348 my $a1 = figure_column_alignment($s1);
1349 my $a2 = figure_column_alignment($s2);
1350 my $a3 = figure_column_alignment($s3);
1351 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001352 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001353 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1354 $col_aligns[1] = "<td$a2>";
1355 $col_aligns[2] = "<td$a3>";
1356 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001357 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001358 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001359 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001360}
1361
Fred Drakef5478632002-05-23 17:59:16 +00001362sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001363 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001364 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001365 if ($font) {
1366 $sfont = "<$font>";
1367 $efont = "</$font>";
1368 $efont =~ s/ .*>/>/;
1369 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001370 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001371}
1372
1373sub do_env_tableii{
1374 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001375 my $arg = next_argument();
1376 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001377 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001378 my $h1 = next_argument();
1379 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001380 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001381 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001382 my $a1 = $col_aligns[0];
1383 my $a2 = $col_aligns[1];
1384 s/\\lineii</\\lineii[$a1|$a2]</g;
1385 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001386 . "\n <thead>"
1387 . "\n <tr class=\"tableheader\">"
1388 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1389 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1390 . "\n </tr>"
1391 . "\n </thead>"
1392 . "\n <tbody valign=\"baseline\">"
1393 . $_
1394 . "\n </tbody>"
1395 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001396}
1397
Fred Drakeda72b932000-09-21 15:58:02 +00001398sub do_env_longtableii{
1399 return do_env_tableii(@_);
1400}
1401
Fred Drake6659c301998-03-03 22:02:19 +00001402sub do_cmd_lineii{
1403 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001404 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001405 my $c1 = next_argument();
1406 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001407 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001408 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001409 $c1 = '&nbsp;' if ($c1 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001410 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001411 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001412 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001413 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001414 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001415 }
Fred Drakee15956b2000-04-03 04:51:13 +00001416 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1417 . " $c2align$c2</td>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001418 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001419}
1420
1421sub do_env_tableiii{
1422 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001423 my $arg = next_argument();
1424 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001425 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001426 my $h1 = next_argument();
1427 my $h2 = next_argument();
1428 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001429 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001430 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001431 my $a1 = $col_aligns[0];
1432 my $a2 = $col_aligns[1];
1433 my $a3 = $col_aligns[2];
1434 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1435 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001436 . "\n <thead>"
1437 . "\n <tr class=\"tableheader\">"
1438 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1439 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1440 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1441 . "\n </tr>"
1442 . "\n </thead>"
1443 . "\n <tbody valign=\"baseline\">"
1444 . $_
1445 . "\n </tbody>"
1446 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001447}
1448
Fred Drakeda72b932000-09-21 15:58:02 +00001449sub do_env_longtableiii{
1450 return do_env_tableiii(@_);
1451}
1452
Fred Drake6659c301998-03-03 22:02:19 +00001453sub do_cmd_lineiii{
1454 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001455 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001456 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001457 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001458 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001459 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001460 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001461 $c1 = '&nbsp;' if ($c1 eq '');
1462 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001463 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001464 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001465 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001466 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001467 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001468 }
Fred Drakee15956b2000-04-03 04:51:13 +00001469 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001470 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001471 . " $c3align$c3</td>"
1472 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001473}
1474
Fred Drakea0f4c941998-07-24 22:16:04 +00001475sub do_env_tableiv{
1476 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001477 my $arg = next_argument();
1478 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001479 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001480 my $h1 = next_argument();
1481 my $h2 = next_argument();
1482 my $h3 = next_argument();
1483 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001484 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001485 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001486 my $a1 = $col_aligns[0];
1487 my $a2 = $col_aligns[1];
1488 my $a3 = $col_aligns[2];
1489 my $a4 = $col_aligns[3];
1490 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1491 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001492 . "\n <thead>"
1493 . "\n <tr class=\"tableheader\">"
1494 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1495 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1496 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1497 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1498 . "\n </tr>"
1499 . "\n </thead>"
1500 . "\n <tbody valign=\"baseline\">"
1501 . $_
1502 . "\n </tbody>"
1503 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001504}
1505
Fred Drakeda72b932000-09-21 15:58:02 +00001506sub do_env_longtableiv{
1507 return do_env_tableiv(@_);
1508}
1509
Fred Drakea0f4c941998-07-24 22:16:04 +00001510sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001511 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001512 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001513 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001514 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001515 my $c3 = next_argument();
1516 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001517 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001518 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001519 $c1 = '&nbsp;' if ($c1 eq '');
1520 $c2 = '&nbsp;' if ($c2 eq '');
1521 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001522 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001523 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001524 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001525 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001526 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001527 }
Fred Drakee15956b2000-04-03 04:51:13 +00001528 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001529 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001530 . " $c3align$c3</td>\n"
1531 . " $c4align$c4</td>"
1532 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001533}
1534
Fred Drakef269e592001-07-17 23:05:57 +00001535sub do_env_tablev{
1536 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001537 my $arg = next_argument();
1538 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001539 my $font = fix_font(next_argument());
1540 my $h1 = next_argument();
1541 my $h2 = next_argument();
1542 my $h3 = next_argument();
1543 my $h4 = next_argument();
1544 my $h5 = next_argument();
1545 s/[\s\n]+//;
1546 $globals{'lineifont'} = $font;
1547 my $a1 = $col_aligns[0];
1548 my $a2 = $col_aligns[1];
1549 my $a3 = $col_aligns[2];
1550 my $a4 = $col_aligns[3];
1551 my $a5 = $col_aligns[4];
1552 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1553 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001554 . "\n <thead>"
1555 . "\n <tr class=\"tableheader\">"
1556 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1557 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1558 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1559 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1560 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1561 . "\n </tr>"
1562 . "\n </thead>"
1563 . "\n <tbody valign=\"baseline\">"
1564 . $_
1565 . "\n </tbody>"
1566 . "\n</table>";
Fred Drakef269e592001-07-17 23:05:57 +00001567}
1568
1569sub do_env_longtablev{
1570 return do_env_tablev(@_);
1571}
1572
1573sub do_cmd_linev{
1574 local($_) = @_;
1575 my $aligns = next_optional_argument();
1576 my $c1 = next_argument();
1577 my $c2 = next_argument();
1578 my $c3 = next_argument();
1579 my $c4 = next_argument();
1580 my $c5 = next_argument();
1581 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001582 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001583 $c1 = '&nbsp;' if ($c1 eq '');
1584 $c2 = '&nbsp;' if ($c2 eq '');
1585 $c3 = '&nbsp;' if ($c3 eq '');
1586 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef269e592001-07-17 23:05:57 +00001587 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001588 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001589 my $padding = '';
1590 if ($c1align =~ /align="right"/ || $c1 eq '') {
1591 $padding = '&nbsp;';
1592 }
1593 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1594 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001595 . " $c3align$c3</td>\n"
1596 . " $c4align$c4</td>\n"
1597 . " $c5align$c5</td>"
1598 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001599}
1600
Fred Drake3be20742000-08-31 06:22:54 +00001601
1602# These can be used to control the title page appearance;
1603# they need a little bit of documentation.
1604#
1605# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1606# $ICONSERVER directory, or include path information (other than "./"). The
1607# default image type will be assumed if an extension is not provided.
1608#
1609# If specified, the "title page" will contain two colums: one containing the
1610# title/author/etc., and the other containing the graphic. Use the other
1611# four variables listed here to control specific details of the layout; all
1612# are optional.
1613#
1614# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1615# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1616# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1617# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1618# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1619
Fred Drakef5478632002-05-23 17:59:16 +00001620sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001621 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001622 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001623 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001624 }
1625 else {
1626 write_warnings("\nThis document has no title.");
1627 }
Fred Drake6659c301998-03-03 22:02:19 +00001628 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001629 if ($t_authorURL) {
1630 my $href = translate_commands($t_authorURL);
1631 $href = make_named_href('author', $href,
1632 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001633 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001634 $the_title .= "\n<p>$href</p>";
1635 }
Fred Drake3be20742000-08-31 06:22:54 +00001636 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001637 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001638 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001639 }
Fred Drake3be20742000-08-31 06:22:54 +00001640 }
1641 else {
1642 write_warnings("\nThere is no author for this document.");
1643 }
Fred Drake6659c301998-03-03 22:02:19 +00001644 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001645 $the_title .= "\n<p>$t_institute</p>";
1646 }
Fred Draked07868a1998-05-14 21:00:28 +00001647 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001648 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1649 }
Fred Drake6659c301998-03-03 22:02:19 +00001650 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001651 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001652 }
Fred Drake6659c301998-03-03 22:02:19 +00001653 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001654 $the_title .= "\n<p>";
1655 if ($PACKAGE_VERSION) {
1656 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001657 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001658 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001659 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001660 }
1661 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001662 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001663 }
1664 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001665 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001666 }
Fred Drake6659c301998-03-03 22:02:19 +00001667 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001668 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001669 }
1670 return $the_title;
1671}
1672
Fred Drakef5478632002-05-23 17:59:16 +00001673sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001674 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001675 my $graphic = "<td class=\"titlegraphic\"";
1676 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1677 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1678 $graphic .= "><img";
1679 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1680 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1681 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1682 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001683 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001684 return $graphic;
1685}
1686
Fred Drakef5478632002-05-23 17:59:16 +00001687sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001688 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001689 my $the_title = "\n";
1690 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001691 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001692 # body), but I don't see any other way to get this generated
1693 # at all. Browsers like Mozilla, that support navigation
1694 # links, can make use of this.
1695 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1696 . ($EXTERNAL_UP_TITLE
1697 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001698 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001699 }
1700 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001701 if ($TITLE_PAGE_GRAPHIC) {
1702 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1703 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1704 . "<tr align=\"right\">\n<td>"
1705 . make_my_titlepage()
1706 . "</td>\n"
1707 . make_my_titlegraphic()
1708 . "</tr>\n</table>");
1709 }
1710 else {
1711 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1712 . make_my_titlegraphic()
1713 . "<td>"
1714 . make_my_titlepage()
1715 . "</td></tr>\n</table>");
1716 }
1717 }
1718 else {
1719 $the_title .= ("\n<center>"
1720 . make_my_titlepage()
1721 . "\n</center>");
1722 }
1723 $the_title .= "\n</div>";
1724 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001725 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001726 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001727}
1728
1729
Fred Drake885215c1998-05-20 21:32:09 +00001730#
Fred Drakea0f4c941998-07-24 22:16:04 +00001731# Module synopsis support
1732#
1733
1734require SynopsisTable;
1735
Fred Drakef7685d71998-07-25 03:31:46 +00001736sub get_chapter_id(){
1737 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001738 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001739 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001740 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001741}
1742
Fred Drake643d76d2000-09-09 06:07:37 +00001743# 'chapter' => 'SynopsisTable instance'
1744%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001745
1746sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001747 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001748 my $key;
1749 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001750 if ($key eq $chap) {
1751 return $ModuleSynopses{$chap};
1752 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001753 }
Fred Drake643d76d2000-09-09 06:07:37 +00001754 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001755 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001756 return $st;
1757}
1758
Fred Drake62e43691998-08-10 19:40:44 +00001759sub do_cmd_moduleauthor{
1760 local($_) = @_;
1761 next_argument();
1762 next_argument();
1763 return $_;
1764}
1765
1766sub do_cmd_sectionauthor{
1767 local($_) = @_;
1768 next_argument();
1769 next_argument();
1770 return $_;
1771}
1772
Fred Drakea0f4c941998-07-24 22:16:04 +00001773sub do_cmd_declaremodule{
1774 local($_) = @_;
1775 my $key = next_optional_argument();
1776 my $type = next_argument();
1777 my $name = next_argument();
1778 my $st = get_synopsis_table(get_chapter_id());
1779 #
1780 $key = $name unless $key;
1781 $type = 'built-in' if $type eq 'builtin';
1782 $st->declare($name, $key, $type);
1783 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001784 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001785}
1786
1787sub do_cmd_modulesynopsis{
1788 local($_) = @_;
1789 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001790 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001791 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001792}
1793
1794sub do_cmd_localmoduletable{
1795 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001796 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001797 my $st = get_synopsis_table($chap);
1798 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001799 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001800}
1801
Fred Drakef5478632002-05-23 17:59:16 +00001802sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001803 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001804 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001805 my $st = $ModuleSynopses{$key};
1806 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001807 if ($file) {
1808 process_localmoduletables_in_file($file);
1809 }
1810 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001811 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001812 }
1813 }
1814}
1815
Fred Drakef5478632002-05-23 17:59:16 +00001816sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001817 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001818 open(MYFILE, "<$file");
1819 local($_);
1820 sysread(MYFILE, $_, 1024*1024);
1821 close(MYFILE);
1822 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001823 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001824 my $match = $&;
1825 my $chap = $1;
1826 my $st = get_synopsis_table($chap);
1827 my $data = $st->tohtml();
1828 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001829 }
Fred Drake643d76d2000-09-09 06:07:37 +00001830 open(MYFILE,">$file");
1831 print MYFILE $_;
1832 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001833}
Fred Drakef5478632002-05-23 17:59:16 +00001834sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001835 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001836 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001837}
Fred Drakea0f4c941998-07-24 22:16:04 +00001838
1839
1840#
1841# "See also:" -- references placed at the end of a \section
1842#
1843
1844sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001845 return ("<div class=\"seealso\">\n "
1846 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001847 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001848 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001849}
1850
Fred Drake5ed35fd2001-11-30 18:09:54 +00001851sub do_env_seealsostar{
1852 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001853 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001854 . '</div>');
1855}
1856
Fred Drakea0f4c941998-07-24 22:16:04 +00001857sub do_cmd_seemodule{
1858 # Insert the right magic to jump to the module definition. This should
1859 # work most of the time, at least for repeat builds....
1860 local($_) = @_;
1861 my $key = next_optional_argument();
1862 my $module = next_argument();
1863 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001864 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001865 $key = $module
1866 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001867 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001868 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001869 }
Fred Drakef1927a62001-06-20 21:29:30 +00001870 return ('<dl compact class="seemodule">'
1871 . "\n <dt>Module <b><tt class=\"module\">"
1872 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1873 . "\n <dd>$text$period\n </dl>"
1874 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001875}
1876
Fred Drakee0197bf2001-04-12 04:03:22 +00001877sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001878 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001879 my $s = "$str";
1880 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1881 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1882 return $s;
1883}
1884
Fred Drakef5478632002-05-23 17:59:16 +00001885sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001886 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001887 my $rfcnum = next_argument();
1888 my $title = next_argument();
1889 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001890 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001891 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001892 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001893 return '<dl compact class="seerfc">'
1894 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001895 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001896 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001897 . "\n <dd>$text\n </dl>"
1898 . $_;
1899}
1900
Fred Drake643d76d2000-09-09 06:07:37 +00001901sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001902 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001903}
1904
1905sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001906 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001907 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001908}
1909
Fred Drake48449982000-09-12 17:52:33 +00001910sub do_cmd_seetitle{
1911 local($_) = @_;
1912 my $url = next_optional_argument();
1913 my $title = next_argument();
1914 my $text = next_argument();
1915 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001916 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001917 return '<dl compact class="seetitle">'
1918 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001919 . "\n >$title$icon</a></em></dt>"
1920 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001921 . $_;
1922 }
1923 return '<dl compact class="seetitle">'
1924 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001925 . "\n >$title</em></dt>"
1926 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001927 . $_;
1928}
1929
Fred Drakeef4d1112000-05-09 16:17:51 +00001930sub do_cmd_seeurl{
1931 local($_) = @_;
1932 my $url = next_argument();
1933 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001934 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001935 return '<dl compact class="seeurl">'
1936 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001937 . "\n class=\"url\">$url$icon</a></dt>"
1938 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001939 . $_;
1940}
1941
Fred Drakea0f4c941998-07-24 22:16:04 +00001942sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001943 local($_) = @_;
1944 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001945 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001946}
1947
1948
1949#
Fred Drake885215c1998-05-20 21:32:09 +00001950# Definition list support.
1951#
1952
1953sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001954 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001955}
1956
1957sub do_cmd_term{
1958 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001959 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001960 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001961 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001962 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001963}
1964
1965
Fred Drake4e72e052003-07-15 22:00:36 +00001966# Commands listed here have process-order dependencies; these often
1967# are related to indexing operations.
1968# XXX Not sure why funclineni, methodlineni, and samp are here.
1969#
Fred Drake2ff880e1999-02-05 18:31:29 +00001970process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001971declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001972funcline # {} # {}
1973funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001974memberline # [] # {}
1975methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001976methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001977modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001978bifuncindex # {}
1979exindex # {}
1980indexii # {} # {}
1981indexiii # {} # {} # {}
1982indexiv # {} # {} # {} # {}
1983kwindex # {}
1984obindex # {}
1985opindex # {}
1986stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00001987platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001988samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001989setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001990withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001991_RAW_ARG_DEFERRED_CMDS_
1992
1993
Fred Drake8a5e6792002-04-15 18:41:31 +00001994$alltt_start = '<div class="verbatim"><pre>';
1995$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001996
Fred Drakef5478632002-05-23 17:59:16 +00001997sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001998 local ($_) = @_;
1999 local($closures,$reopens,@open_block_tags);
2000
2001 # get the tag-strings for all open tags
2002 local(@keep_open_tags) = @$open_tags_R;
2003 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2004
2005 # get the tags for text-level tags only
2006 $open_tags_R = [ @keep_open_tags ];
2007 local($local_closures, $local_reopens);
2008 ($local_closures, $local_reopens,@open_block_tags)
2009 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002010 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002011
2012 $open_tags_R = [ @open_block_tags ];
2013
2014 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002015 local($open_tags_R) = [ @open_block_tags ];
2016 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002017
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002018 local($cnt) = ++$global{'max_id'};
2019 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2020 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002021
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002022 $_ = &translate_environments($_);
2023 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002024
Fred Drake41aa0182003-09-05 15:43:00 +00002025 # remove spurious <BR> someone sticks in; not sure where they
2026 # actually come from
2027 # XXX the replacement space is there to accomodate something
2028 # broken that inserts a space in front of the first line of
2029 # the environment
2030 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002031
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002032 $_ = join('', $closures, $alltt_start, $local_reopens
2033 , $_
2034 , &balance_tags() #, $local_closures
2035 , $alltt_end, $reopens);
2036 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002037 };
2038 $open_tags_R = [ @keep_open_tags ];
2039 $_;
2040}
2041
Fred Drake6fc22f62002-06-17 15:01:05 +00002042# List of all filenames produced ny do_cmd_verbatiminput()
2043%VerbatimFiles = ();
2044@VerbatimOutputs = ();
2045
2046sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002047 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002048 #
2049 # Re-write the source filename to always use a .txt extension
2050 # so that Web servers will present it as text/plain. This is
2051 # needed since there is no other even moderately reliable way
2052 # to get the right Content-Type header on text files for
2053 # servers which we can't configure (like python.org mirrors).
2054 #
2055 if (defined $VerbatimFiles{$file}) {
2056 # We've seen this one before; re-use the same output file.
2057 return $VerbatimFiles{$file};
2058 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002059 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002060 $filename = "$srcname.txt";
2061 #
2062 # We need to determine if our default filename is already
2063 # being used, and find a new one it it is. If the name is in
2064 # used, this algorithm will first attempt to include the
2065 # source extension as part of the name, and if that is also in
2066 # use (if the same file is included multiple times, or if
2067 # another source file has that as the base name), a counter is
2068 # used instead.
2069 #
2070 my $found = 1;
2071 FIND:
2072 while ($found) {
2073 foreach $fn (@VerbatimOutputs) {
2074 if ($fn eq $filename) {
2075 if ($found == 1) {
2076 $srcext =~ s/^[.]//; # Remove '.' from extension
2077 $filename = "$srcname-$srcext.txt";
2078 }
2079 else {
2080 $filename = "$srcname-$found.txt";
2081 }
2082 ++$found;
2083 next FIND;
2084 }
2085 }
2086 $found = 0;
2087 }
2088 push @VerbatimOutputs, $filename;
2089 $VerbatimFiles{$file} = $filename;
2090 return $filename;
2091}
2092
Fred Drake57e52ef2001-06-15 21:31:57 +00002093sub do_cmd_verbatiminput{
2094 local($_) = @_;
2095 my $fname = next_argument();
2096 my $file;
2097 my $found = 0;
2098 my $texpath;
2099 # Search TEXINPUTS for the input file, the way we're supposed to:
2100 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2101 $file = "$texpath$dd$fname";
2102 last if ($found = (-f $file));
2103 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002104 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002105 my $text;
2106 if ($found) {
2107 open(MYFILE, "<$file") || die "\n$!\n";
2108 read(MYFILE, $text, 1024*1024);
2109 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002110 $filename = get_verbatim_output_name($file);
2111 # Now that we have a filename, write it out.
2112 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002113 print MYFILE $text;
2114 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002115 #
2116 # These rewrites convert the raw text to something that will
2117 # be properly visible as HTML and also will pass through the
2118 # vagaries of conversion through LaTeX2HTML. The order in
2119 # which the specific rewrites are performed is significant.
2120 #
2121 $text =~ s/\&/\&amp;/g;
2122 # These need to happen before the normal < and > re-writes,
2123 # since we need to avoid LaTeX2HTML's attempt to perform
2124 # ligature processing without regard to context (since it
2125 # doesn't have font information).
2126 $text =~ s/--/-&\#45;/g;
2127 $text =~ s/<</\&lt;\&\#60;/g;
2128 $text =~ s/>>/\&gt;\&\#62;/g;
2129 # Just normal re-writes...
2130 $text =~ s/</\&lt;/g;
2131 $text =~ s/>/\&gt;/g;
2132 # These last isn't needed for the HTML, but is needed to get
2133 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2134 # of &sol; since many browsers don't support that.
2135 $text =~ s/\\/\&\#92;/g;
2136 }
2137 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002138 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2139 }
2140 my $note = 'Download as text.';
2141 if ($file ne $filename) {
2142 $note = ('Download as text (original file name: <span class="file">'
2143 . $fname
2144 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002145 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002146 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002147 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002148 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002149 . "<a href=\"$filename\" type=\"text/plain\""
2150 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002151 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002152 . $_);
2153}
Fred Drake86333602001-04-10 17:13:39 +00002154
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021551; # This must be the last line