blob: 89e12d58285c24309fe0974ccfee505d422bc59d [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
148sub do_cmd_hackscore{
149 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000150 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000151 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000152}
153
Fred Drake345555d2003-12-30 16:19:28 +0000154# Helper used in many places that arbitrary code-like text appears:
155
156sub codetext($){
157 my $text = "$_[0]";
158 $text =~ s/--/-\&#45;/go;
159 return $text;
160}
161
Fred Drakef5478632002-05-23 17:59:16 +0000162sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000163 local($_,$before,$after) = @_;
164 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000165 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000166}
167
Fred Drake345555d2003-12-30 16:19:28 +0000168sub use_code_wrappers($$$){
169 local($_,$before,$after) = @_;
170 my $stuff = codetext(next_argument());
171 return $before . $stuff . $after . $_;
172}
173
Fred Drake3cdb89d2000-09-14 20:17:23 +0000174$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000175sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000176 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000177 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000178 "</var><big>\]</big><var>");
179 }
180 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000181 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000182 }
Fred Drake6659c301998-03-03 22:02:19 +0000183}
184
Fred Drakec9a44381998-03-17 06:29:13 +0000185# Logical formatting (some based on texinfo), needs to be converted to
186# minimalist HTML. The "minimalist" is primarily to reduce the size of
187# output files for users that read them over the network rather than
188# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000189
Fred Drake49b33fa2002-11-15 19:04:10 +0000190sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000191sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000192 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000193sub do_cmd_code{
Fred Drake345555d2003-12-30 16:19:28 +0000194 return use_code_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000195sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000196 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000197sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000198 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000199sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000200 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000201sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000202 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000203sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000204 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000205sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000206 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000207sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000208 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000209sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000210 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000211sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000212 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000213sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000214 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000215sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000216 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_regexp{
Fred Drake345555d2003-12-30 16:19:28 +0000218 return use_code_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_character{
Fred Drake345555d2003-12-30 16:19:28 +0000220 return use_code_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000221sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000222 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000223sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000224 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000225sub do_cmd_longprogramopt{
226 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000227 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000228sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000229 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000230sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000231 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000232sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000233 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000234sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000235 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000236sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000237 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000238sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000239 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000240sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000241 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000242sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000243 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000244sub do_cmd_samp{
Fred Drake345555d2003-12-30 16:19:28 +0000245 return use_code_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000246sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000247 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000248sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000249 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000250sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000251 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000252sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000253 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000254# This can be changed/overridden for translations:
255%NoticeNames = ('note' => 'Note:',
256 'warning' => 'Warning:',
257 );
258
Fred Drake92350b32001-10-09 18:01:23 +0000259sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000260 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000261 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000262 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000263 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000264 '</span>'); }
265sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000266 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000267 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000268 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000269 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000270 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000271
Fred Drake6ca33772001-12-14 22:50:06 +0000272sub do_env_notice{
273 local($_) = @_;
274 my $notice = next_optional_argument();
275 if (!$notice) {
276 $notice = 'note';
277 }
278 my $label = $NoticeNames{$notice};
279 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
280 . $_
281 . '</div>');
282}
283
Fred Drake3d5a04a2000-08-03 17:25:44 +0000284sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000285 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000286sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000287 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000288
Fred Drakec9a44381998-03-17 06:29:13 +0000289
Fred Drake25817041999-01-13 17:06:34 +0000290sub do_cmd_refmodule{
291 # Insert the right magic to jump to the module definition.
292 local($_) = @_;
293 my $key = next_optional_argument();
294 my $module = next_argument();
295 $key = $module
296 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000297 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000298 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000299}
300
Fred Drake1a7af391998-04-01 22:44:56 +0000301sub do_cmd_newsgroup{
302 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000303 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000304 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000305 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
306 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000307 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000308}
Fred Drakefc16e781998-03-12 21:03:26 +0000309
310sub do_cmd_envvar{
311 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000312 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000313 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000314 # The <tt> here is really to keep buildindex.py from making
315 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000316 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000317 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000318 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000319 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000320 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000321}
322
Fred Drake6659c301998-03-03 22:02:19 +0000323sub do_cmd_url{
324 # use the URL as both text and hyperlink
325 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000326 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000327 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000328 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000329 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000330}
331
332sub do_cmd_manpage{
333 # two parameters: \manpage{name}{section}
334 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000335 my $page = next_argument();
336 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000337 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000338}
339
Fred Drakedbfe7682002-04-03 02:47:14 +0000340$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000341#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
342$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000343
344sub get_rfc_url($$){
345 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000346 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000347}
348
349sub do_cmd_pep{
350 local($_) = @_;
351 my $rfcnumber = next_argument();
352 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000353 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000354 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000355 # Save the reference
356 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
357 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake04bf7242003-11-26 20:55:49 +0000358 return ("<a class=\"rfc\" id='$id'\n"
Fred Drake2fc88a62003-08-05 03:45:37 +0000359 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000360}
361
Fred Drake6659c301998-03-03 22:02:19 +0000362sub do_cmd_rfc{
363 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000364 my $rfcnumber = next_argument();
365 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000366 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000367 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000368 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000369 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000370 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake04bf7242003-11-26 20:55:49 +0000371 return ("<a class=\"rfc\" id='$id'\nhref=\"$href\">"
Fred Drake2fc88a62003-08-05 03:45:37 +0000372 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000373}
374
Fred Drake77602f22001-07-06 22:43:02 +0000375sub do_cmd_ulink{
376 local($_) = @_;
377 my $text = next_argument();
378 my $url = next_argument();
379 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
380}
381
Fred Drakec9f5fe01999-11-09 16:59:42 +0000382sub do_cmd_citetitle{
383 local($_) = @_;
384 my $url = next_optional_argument();
385 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000386 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000387 my $repl = '';
388 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000389 $repl = ("<em class=\"citetitle\"><a\n"
390 . " href=\"$url\"\n"
391 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000392 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000393 }
394 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000395 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000396 }
397 return $repl . $_;
398}
399
Fred Drake6659c301998-03-03 22:02:19 +0000400sub do_cmd_deprecated{
401 # two parameters: \deprecated{version}{whattodo}
402 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000403 my $release = next_argument();
404 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000405 return ('<div class="versionnote">'
406 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000407 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000408 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000409}
410
Fred Drakef5478632002-05-23 17:59:16 +0000411sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000412 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000413 my $type = $_[0];
414 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000415 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000416 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000417 my $text = "$type in version $release.";
418 if ($explanation) {
419 $text = "$type in version $release:\n$explanation.";
420 }
Fred Drakef1927a62001-06-20 21:29:30 +0000421 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000422}
423
424sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000425 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000426}
427
428sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000429 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000430}
431
Fred Drake557460c1999-03-02 16:05:35 +0000432#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000433# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000434#
435sub do_cmd_platform{
436 local($_) = @_;
437 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000438 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000439 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000440 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000441 return "\n<p class=\"availability\">Availability: <span"
442 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000443}
444
Fred Drake557460c1999-03-02 16:05:35 +0000445$IGNORE_PLATFORM_ANNOTATION = '';
446sub do_cmd_ignorePlatformAnnotation{
447 local($_) = @_;
448 $IGNORE_PLATFORM_ANNOTATION = next_argument();
449 return $_;
450}
451
Fred Drake6659c301998-03-03 22:02:19 +0000452
453# index commands
454
455$INDEX_SUBITEM = "";
456
Fred Drakef5478632002-05-23 17:59:16 +0000457sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000458 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000459}
460
461sub do_cmd_setindexsubitem{
462 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000463 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000464 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000465}
466
Fred Drakefc16e781998-03-12 21:03:26 +0000467sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000468 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000469 # do things in the right order, but we need to at least strip this stuff
470 # out, and leave anything that the second argument expanded out to.
471 #
472 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000473 my $oldsubitem = $INDEX_SUBITEM;
474 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000475 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000476 my $br_id = ++$globals{'max_id'};
477 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000478 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000479 return
480 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000481 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000482 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000483}
484
Fred Drake08932051998-04-17 02:15:42 +0000485# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000486# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
487# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000488#
Fred Drake49b33fa2002-11-15 19:04:10 +0000489sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000490
Fred Drake42b31a51998-03-27 05:16:10 +0000491# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000492#
Fred Drake08932051998-04-17 02:15:42 +0000493open(IDXFILE, '>index.dat') || die "\n$!\n";
494open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000495print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000496print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000497
498# Using \0 for this is bad because we can't use common tools to work with the
499# resulting files. Things like grep can be useful with this stuff!
500#
501$IDXFILE_FIELD_SEP = "\1";
502
Fred Drakef5478632002-05-23 17:59:16 +0000503sub write_idxfile($$){
504 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000505 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000506}
507
Fred Drake42b31a51998-03-27 05:16:10 +0000508
Fred Drakef5478632002-05-23 17:59:16 +0000509sub gen_link($$){
510 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000511 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000512 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000513}
514
Fred Drakef5478632002-05-23 17:59:16 +0000515sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000516 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000517 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000518 $str = gen_index_id($str, '');
519 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000520 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000521}
522
Fred Drake04bf7242003-11-26 20:55:49 +0000523sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000524 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake04bf7242003-11-26 20:55:49 +0000525 my $aname = "<a id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000526 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000527 return ($name, $ahref);
528}
529
530sub new_link_info(){
531 my($name, $ahref) = new_link_name_info();
532 my $aname = "<a id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000533 return ($name, $aname, $ahref);
534}
535
Fred Drakeab032151999-05-13 18:36:54 +0000536$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000537sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000538 my $count = @_;
539 my $i = 0;
540 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000541 my $name = $_[$i];
542 my $cmd = "idx_cmd_$name";
543 die "\nNo function $cmd() defined!\n"
544 if (!defined &$cmd);
545 eval ("sub do_cmd_$name { return process_index_macros("
546 . "\$_[0], '$name'); }");
547 if (length($IndexMacroPattern) == 0) {
548 $IndexMacroPattern = "$name";
549 }
550 else {
551 $IndexMacroPattern .= "|$name";
552 }
Fred Drakeab032151999-05-13 18:36:54 +0000553 }
554}
555
556$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000557sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000558 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000559 my $cmdname = $_[1]; # This is what triggered us in the first place;
560 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000561 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000562 my $cmd = "idx_cmd_$cmdname";
563 print "\nIndexing: \\$cmdname"
564 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000565 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000566 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000567 $cmdname = "$1";
568 print " \\$cmdname"
569 if $DEBUG_INDEXING;
570 $cmd = "idx_cmd_$cmdname";
571 if (!defined &$cmd) {
572 last;
573 }
574 else {
575 s/^[\s\n]*\\$cmdname//;
576 &$cmd($ahref);
577 }
Fred Drakeab032151999-05-13 18:36:54 +0000578 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000579 if (/^[ \t\r\n]/) {
580 $_ = substr($_, 1);
581 }
Fred Drake62e43691998-08-10 19:40:44 +0000582 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000583}
584
Fred Drakeab032151999-05-13 18:36:54 +0000585define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000586sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000587 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000588 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000589}
590
Fred Drakeab032151999-05-13 18:36:54 +0000591define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000592sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000593 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000594 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
595 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000596}
597
598define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000599sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000600 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000601 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000602 add_index_entry("$str1!$str2", $_[0]);
603 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000604}
605
Fred Drakeab032151999-05-13 18:36:54 +0000606define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000607sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000608 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000609 my $str2 = next_argument();
610 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000611 add_index_entry("$str1!$str2 $str3", $_[0]);
612 add_index_entry("$str2!$str3, $str1", $_[0]);
613 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000614}
615
Fred Drakeab032151999-05-13 18:36:54 +0000616define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000617sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000618 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000619 my $str2 = next_argument();
620 my $str3 = next_argument();
621 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000622 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
623 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
624 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
625 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000626}
627
Fred Drakeab032151999-05-13 18:36:54 +0000628define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000629sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000630 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000631 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000632 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000633}
Fred Drake6659c301998-03-03 22:02:19 +0000634
Fred Drakef5478632002-05-23 17:59:16 +0000635sub my_typed_index_helper($$){
636 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000637 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000638 add_index_entry("$str $word", $ahref);
639 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000640}
641
Fred Drakeab032151999-05-13 18:36:54 +0000642define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000643sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
644sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
645sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
646sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000647
Fred Drakeab032151999-05-13 18:36:54 +0000648define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000649sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000650 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000651 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000652 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000653}
654
655
Fred Drakef5478632002-05-23 17:59:16 +0000656sub make_mod_index_entry($$){
657 my($str, $define) = @_;
658 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000659 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000660 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
661 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000662 $str = gen_index_id($str, $define);
663 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000664 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000665
Fred Drakec9a44381998-03-17 06:29:13 +0000666 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000667 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000668 $str =~ /(<tt.*<\/tt>)/;
669 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000670 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000671 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000672 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000673}
674
Fred Drake557460c1999-03-02 16:05:35 +0000675
Fred Drakec9a44381998-03-17 06:29:13 +0000676$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000677$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000678
Fred Drakef5478632002-05-23 17:59:16 +0000679sub define_module($$){
680 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000681 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000682 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000683 && $word ne "standard" && $word ne "") {
684 write_warnings("Bad module type '$word'"
685 . " for \\declaremodule (module $name)");
686 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000687 }
Fred Drake6659c301998-03-03 22:02:19 +0000688 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000689 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000690 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000691 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000692 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000693 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000694}
695
Fred Drakef5478632002-05-23 17:59:16 +0000696sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000697 local($word, $_) = @_;
698 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000699 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000700}
701
Fred Drake49b33fa2002-11-15 19:04:10 +0000702sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
703sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
704sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
705sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
706# local($_) = @_;
707# my $name = next_argument();
708# return define_module('standard', $name) . $_;
709# }
Fred Drake6659c301998-03-03 22:02:19 +0000710
Fred Drakef5478632002-05-23 17:59:16 +0000711sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000712 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000713 my $str = next_argument();
714 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000715 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000716 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
717 # just inline it all here
718 $str = gen_index_id($str, 'REF');
719 $index{$str} .= $ahref;
720 write_idxfile($ahref, $str);
721}
722
Fred Drake6659c301998-03-03 22:02:19 +0000723# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000724define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000725 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000726sub idx_cmd_refmodindex($){
727 return ref_module_index_helper('', $_[0]); }
728sub idx_cmd_refbimodindex($){
729 return ref_module_index_helper('built-in', $_[0]); }
730sub idx_cmd_refexmodindex($){
731 return ref_module_index_helper('extension', $_[0]);}
732sub idx_cmd_refstmodindex($){
733 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000734
Fred Drake49b33fa2002-11-15 19:04:10 +0000735sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000736
Fred Drakef5478632002-05-23 17:59:16 +0000737sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000738 # These markers must be non-empty or the main latex2html script
739 # may remove a surrounding element that has not other content as
740 # "extraneous"; this ensures these elements (usually hyperlink
741 # targets) are not removed improperly. We use comments since
742 # there's no meaningful actual content.
743 # Thanks to Dave Kuhlman for figuring why some named anchors were
744 # being lost.
745 $anchor_invisible_mark = '<!--x-->';
746 $anchor_invisible_mark2 = '<!--y-->';
747 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000748 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000749}
Fred Drake42b31a51998-03-27 05:16:10 +0000750init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000751
Fred Drakeab032151999-05-13 18:36:54 +0000752# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000753# instead of the dummy filler.
754#
Fred Drakef5478632002-05-23 17:59:16 +0000755sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000756 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000757 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000758 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000759 if ($str =~ /^<[a-z]+\b/) {
760 my $s = "$str";
761 $s =~ s/^<([a-z]+)\b/<$1 id='$name'/;
762 return $s;
763 }
764 else {
765 return "<a id='$name'>$str</a>";
766 }
Fred Drake6659c301998-03-03 22:02:19 +0000767}
768
Fred Drake77602f22001-07-06 22:43:02 +0000769
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000770%TokenToTargetMapping = (); # language:token -> link target
771%DefinedGrammars = (); # language -> full grammar text
772%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000773
774sub do_cmd_token{
775 local($_) = @_;
776 my $token = next_argument();
777 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
778 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
779 # recursive definition or display-only productionlist
780 return "$token";
781 }
782 if ($target eq '') {
783 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
784 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
785 print "Adding '$CURRENT_FILE' to back-patch list.\n";
786 }
787 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
788 }
789 return "<a href=\"$target\">$token</a>" . $_;
790}
791
Fred Drake16bb4192001-08-20 21:36:38 +0000792sub do_cmd_grammartoken{
793 return do_cmd_token(@_);
794}
795
Fred Drake77602f22001-07-06 22:43:02 +0000796sub do_env_productionlist{
797 local($_) = @_;
798 my $lang = next_optional_argument();
799 my $filename = "grammar-$lang.txt";
800 if ($lang eq '') {
801 $filename = 'grammar.txt';
802 }
803 local($CURRENT_GRAMMAR) = $lang;
804 $DefinedGrammars{$lang} .= $_;
805 return ("<dl><dd class=\"grammar\">\n"
806 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000807 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000808 . translate_commands(translate_environments($_))
809 . "</table>\n"
810 . "</div>\n"
811 . (($lang eq '*')
812 ? ''
813 : ("<a class=\"grammar-footer\"\n"
814 . " href=\"$filename\" type=\"text/plain\"\n"
815 . " >Download entire grammar as text.</a>\n"))
816 . "</dd></dl>");
817}
818
819sub do_cmd_production{
820 local($_) = @_;
821 my $token = next_argument();
822 my $defn = next_argument();
823 my $lang = $CURRENT_GRAMMAR;
824 local($CURRENT_TOKEN) = $token;
825 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000826 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000827 . " <td><code>$token</code></td>\n"
828 . " <td>&nbsp;::=&nbsp;</td>\n"
829 . " <td><code>"
830 . translate_commands($defn)
831 . "</code></td></tr>"
832 . $_);
833 }
834 my $target;
835 if ($lang eq '') {
836 $target = "$CURRENT_FILE\#tok-$token";
837 }
838 else {
839 $target = "$CURRENT_FILE\#tok-$lang-$token";
840 }
841 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000842 return ("<tr valign=\"baseline\">\n"
Fred Drake04bf7242003-11-26 20:55:49 +0000843 . " <td><code><a id='tok-$token'>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000844 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000845 . " <td>&nbsp;::=&nbsp;</td>\n"
846 . " <td><code>"
847 . translate_commands($defn)
848 . "</code></td></tr>"
849 . $_);
850}
851
Fred Drake53815882002-03-15 23:21:37 +0000852sub do_cmd_productioncont{
853 local($_) = @_;
854 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000855 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000856 return ("<tr valign=\"baseline\">\n"
857 . " <td>&nbsp;</td>\n"
858 . " <td>&nbsp;</td>\n"
859 . " <td><code>"
860 . translate_commands($defn)
861 . "</code></td></tr>"
862 . $_);
863}
864
Fred Drakef5478632002-05-23 17:59:16 +0000865sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000866 my $lang;
867 my $filename;
868 local($_);
869 print "process_grammar_files()\n";
870 foreach $lang (keys %DefinedGrammars) {
871 $filename = "grammar-$lang.txt";
872 if ($lang eq '*') {
873 next;
874 }
875 if ($lang eq '') {
876 $filename = 'grammar.txt';
877 }
878 open(GRAMMAR, ">$filename") || die "\n$!\n";
879 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
880 close(GRAMMAR);
881 print "Wrote grammar file $filename\n";
882 }
883 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
884 foreach $filename (keys %BackpatchGrammarFiles) {
885 print "\nBack-patching grammar links in $filename\n";
886 my $buffer;
887 open(GRAMMAR, "<$filename") || die "\n$!\n";
888 # read all of the file into the buffer
889 sysread(GRAMMAR, $buffer, 1024*1024);
890 close(GRAMMAR);
891 while ($buffer =~ /$PATTERN/) {
892 my($lang, $token) = ($1, $2);
893 my $target = $TokenToTargetMapping{"$lang:$token"};
894 my $source = "<pyGrammarToken><$lang><$token>";
895 $buffer =~ s/$source/$target/g;
896 }
897 open(GRAMMAR, ">$filename") || die "\n$!\n";
898 print GRAMMAR $buffer;
899 close(GRAMMAR);
900 }
901}
902
Fred Drakef5478632002-05-23 17:59:16 +0000903sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000904 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000905 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000906 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
907 s/\\token(<<\d+>>)(.+)\1/$2/g;
908 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000909 s/<<\d+>>//g;
910 s/;SPMgt;/>/g;
911 s/;SPMlt;/</g;
912 s/;SPMquot;/\"/g;
913 return $_;
914}
915
916
Fred Drakee15956b2000-04-03 04:51:13 +0000917$REFCOUNTS_LOADED = 0;
918
Fred Drakef5478632002-05-23 17:59:16 +0000919sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000920 $REFCOUNTS_LOADED = 1;
921
Fred Drake49b33fa2002-11-15 19:04:10 +0000922 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000923 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000924 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000925 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000926 $mydir = getcwd() . "$dd$mydir"
927 unless $mydir =~ s|^/|/|;
928 local $_;
929 my $filename = "$mydir${dd}api${dd}refcounts.dat";
930 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
931 print "[loading API refcount data]";
932 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000933 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000934 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
935 #print "\n$func($param) --> $count";
936 $REFCOUNTS{"$func:$param"} = $count;
937 }
938 }
939}
940
Fred Drakef5478632002-05-23 17:59:16 +0000941sub get_refcount($$){
942 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000943 load_refcounts()
944 unless $REFCOUNTS_LOADED;
945 return $REFCOUNTS{"$func:$param"};
946}
947
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000948
949$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000950$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000951
Fred Drakef5478632002-05-23 17:59:16 +0000952sub cfuncline_helper($$$){
953 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000954 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000955 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000956 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000957 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000958 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
959 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000960 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
961 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
962 . "<td>$args)</td>"
963 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000964}
965sub do_cmd_cfuncline{
966 local($_) = @_;
967 my $type = next_argument();
968 my $name = next_argument();
969 my $args = next_argument();
970 my $siginfo = cfuncline_helper($type, $name, $args);
971 return "<dt>$siginfo\n<dd>" . $_;
972}
973sub do_env_cfuncdesc{
974 local($_) = @_;
975 my $type = next_argument();
976 my $name = next_argument();
977 my $args = next_argument();
978 my $siginfo = cfuncline_helper($type, $name, $args);
979 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000980 my $rcinfo = '';
981 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000982 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000983 }
984 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000985 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000986 }
Fred Drakec2578c52000-04-10 18:26:45 +0000987 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000988 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000989 }
Fred Drakee15956b2000-04-03 04:51:13 +0000990 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000991 $rcinfo = ( "\n<div class=\"refcount-info\">"
992 . "\n <span class=\"label\">Return value:</span>"
993 . "\n <span class=\"value\">$rcinfo.</span>"
994 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000995 }
Fred Drake2fc88a62003-08-05 03:45:37 +0000996 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000997 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000998 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +0000999 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001000}
1001
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001002sub do_cmd_cmemberline{
1003 local($_) = @_;
1004 my $container = next_argument();
1005 my $type = next_argument();
1006 my $name = next_argument();
1007 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001008 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001009 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001010 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001011 . $_;
1012}
1013sub do_env_cmemberdesc{
1014 local($_) = @_;
1015 my $container = next_argument();
1016 my $type = next_argument();
1017 my $name = next_argument();
1018 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001019 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001020 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001021 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001022 . $_
1023 . '</dl>';
1024}
1025
Fred Drakee15956b2000-04-03 04:51:13 +00001026sub do_env_csimplemacrodesc{
1027 local($_) = @_;
1028 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001029 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001030 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001031 . $_
1032 . '</dl>'
1033}
1034
Fred Drake6659c301998-03-03 22:02:19 +00001035sub do_env_ctypedesc{
1036 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001037 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001038 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001039 $index_name = $type_name
1040 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001041 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001042 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001043 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1044 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001045 . $_
1046 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001047}
1048
1049sub do_env_cvardesc{
1050 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001051 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001052 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001053 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001054 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001055 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001056 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001057 . '<dd>'
1058 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001059 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001060}
1061
Fred Drake3cdb89d2000-09-14 20:17:23 +00001062sub convert_args($){
1063 local($IN_DESC_HANDLER) = 1;
1064 local($_) = @_;
1065 return translate_commands($_);
1066}
1067
Fred Drakef6e90272002-06-18 18:24:16 +00001068sub funcline_helper($$$){
1069 my($first, $idxitem, $arglist) = @_;
1070 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001071 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1072 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001073 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001074}
1075
Fred Drake6659c301998-03-03 22:02:19 +00001076sub do_env_funcdesc{
1077 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001078 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001079 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001080 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1081 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001082 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001083 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001084 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001085 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001086}
1087
1088sub do_env_funcdescni{
1089 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001090 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001091 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001092 my $prefix = "<tt class=\"function\">$function_name</tt>";
1093 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001094}
1095
1096sub do_cmd_funcline{
1097 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001098 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001099 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001100 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001101 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1102 $prefix =~ s/\(\)//;
1103
Fred Drakef6e90272002-06-18 18:24:16 +00001104 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001105}
1106
Fred Drake6b3fb781999-07-12 16:50:09 +00001107sub do_cmd_funclineni{
1108 local($_) = @_;
1109 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001110 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001111 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001112
Fred Drakef6e90272002-06-18 18:24:16 +00001113 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001114}
1115
Fred Drake6659c301998-03-03 22:02:19 +00001116# Change this flag to index the opcode entries. I don't think it's very
1117# useful to index them, since they're only presented to describe the dis
1118# module.
1119#
1120$INDEX_OPCODES = 0;
1121
1122sub do_env_opcodedesc{
1123 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001124 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001125 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001126 my $idx;
1127 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001128 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001129 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001130 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001131 }
1132 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001133 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001134 }
1135 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001136 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001137 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001138 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001139 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001140}
1141
1142sub do_env_datadesc{
1143 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001144 my $dataname = next_argument();
1145 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001146 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001147 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001148 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001149 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001150}
1151
1152sub do_env_datadescni{
1153 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001154 my $idx = next_argument();
1155 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001156 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001157 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001158 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001159}
1160
1161sub do_cmd_dataline{
1162 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001163 my $data_name = next_argument();
1164 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001165 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001166 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001167}
1168
Fred Drakeadb272c2000-04-10 17:47:14 +00001169sub do_cmd_datalineni{
1170 local($_) = @_;
1171 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001172 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001173}
1174
Fred Drake42b31a51998-03-27 05:16:10 +00001175sub do_env_excdesc{
1176 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001177 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001178 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001179 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001180 . "\n<dd>"
1181 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001182 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001183}
1184
Fred Drake62e43691998-08-10 19:40:44 +00001185sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001186
1187
Fred Drakef5478632002-05-23 17:59:16 +00001188sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001189 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001190 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001191 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001192 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001193 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001194 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001195 my $prefix = "$TLSTART$what$TLEND$idx";
1196 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001197}
1198
Fred Drake643d76d2000-09-09 06:07:37 +00001199sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001200 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001201}
1202
Fred Drake06a01e82001-05-11 01:00:30 +00001203sub do_env_classdescstar{
1204 local($_) = @_;
1205 $THIS_CLASS = next_argument();
1206 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001207 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001208 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001209 my $prefix = "${TLSTART}class$TLEND$idx";
1210 # Can't use funcline_helper() since there is no args list.
1211 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001212}
1213
Fred Drake643d76d2000-09-09 06:07:37 +00001214sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001215 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001216}
1217
Fred Drake42b31a51998-03-27 05:16:10 +00001218
1219sub do_env_methoddesc{
1220 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001221 my $class_name = next_optional_argument();
1222 $class_name = $THIS_CLASS
1223 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001224 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001225 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001226 my $extra = '';
1227 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001228 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001229 }
Fred Drakef1927a62001-06-20 21:29:30 +00001230 my $idx = make_str_index_entry(
1231 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001232 $idx =~ s/ \(.*\)//;
1233 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001234 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001235}
1236
1237
Fred Drake7d45f6d1999-01-05 14:39:27 +00001238sub do_cmd_methodline{
1239 local($_) = @_;
1240 my $class_name = next_optional_argument();
1241 $class_name = $THIS_CLASS
1242 unless $class_name;
1243 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001244 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001245 my $extra = '';
1246 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001247 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001248 }
Fred Drakef1927a62001-06-20 21:29:30 +00001249 my $idx = make_str_index_entry(
1250 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001251 $idx =~ s/ \(.*\)//;
1252 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001253 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001254}
1255
1256
Fred Draked64a40d1998-09-10 18:59:13 +00001257sub do_cmd_methodlineni{
1258 local($_) = @_;
1259 next_optional_argument();
1260 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001261 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001262 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001263}
1264
Fred Drake42b31a51998-03-27 05:16:10 +00001265sub do_env_methoddescni{
1266 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001267 next_optional_argument();
1268 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001269 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001270 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001271}
1272
1273
1274sub do_env_memberdesc{
1275 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001276 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001277 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001278 $class = $THIS_CLASS
1279 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001280 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001281 $extra = " ($class attribute)"
1282 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001283 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001284 $idx =~ s/ \(.*\)//;
1285 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001286 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001287}
1288
1289
Fred Drake5ccf3301998-04-17 20:04:09 +00001290sub do_cmd_memberline{
1291 local($_) = @_;
1292 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001293 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001294 $class = $THIS_CLASS
1295 unless $class;
1296 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001297 $extra = " ($class attribute)"
1298 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001299 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001300 $idx =~ s/ \(.*\)//;
1301 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001302 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001303}
1304
Fred Drakef269e592001-07-17 23:05:57 +00001305
Fred Drake42b31a51998-03-27 05:16:10 +00001306sub do_env_memberdescni{
1307 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001308 next_optional_argument();
1309 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001310 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001311 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001312 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001313}
1314
1315
Fred Drake5ccf3301998-04-17 20:04:09 +00001316sub do_cmd_memberlineni{
1317 local($_) = @_;
1318 next_optional_argument();
1319 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001320 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001321}
1322
Fred Drakef269e592001-07-17 23:05:57 +00001323
1324@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001325
Fred Drakecb199762001-08-16 21:56:24 +00001326%FontConversions = ('cdata' => 'tt class="cdata"',
1327 'character' => 'tt class="character"',
1328 'class' => 'tt class="class"',
1329 'command' => 'code',
1330 'constant' => 'tt class="constant"',
1331 'exception' => 'tt class="exception"',
1332 'file' => 'tt class="file"',
1333 'filenq' => 'tt class="file"',
1334 'kbd' => 'kbd',
1335 'member' => 'tt class="member"',
1336 'programopt' => 'b',
1337 'textrm' => '',
1338 );
1339
Fred Drakef5478632002-05-23 17:59:16 +00001340sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001341 # do a little magic on a font name to get the right behavior in the first
1342 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001343 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001344 if (defined $FontConversions{$font}) {
1345 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001346 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001347 return $font;
1348}
1349
Fred Drakef5478632002-05-23 17:59:16 +00001350sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001351 my $a = $_[0];
1352 if (!defined $a) {
1353 return '';
1354 }
Fred Drakee15956b2000-04-03 04:51:13 +00001355 my $mark = substr($a, 0, 1);
1356 my $r = '';
1357 if ($mark eq 'c')
1358 { $r = ' align="center"'; }
1359 elsif ($mark eq 'r')
1360 { $r = ' align="right"'; }
1361 elsif ($mark eq 'l')
1362 { $r = ' align="left"'; }
1363 elsif ($mark eq 'p')
1364 { $r = ' align="left"'; }
1365 return $r;
1366}
1367
Fred Drakef5478632002-05-23 17:59:16 +00001368sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001369 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001370 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001371 my $a1 = figure_column_alignment($s1);
1372 my $a2 = figure_column_alignment($s2);
1373 my $a3 = figure_column_alignment($s3);
1374 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001375 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001376 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1377 $col_aligns[1] = "<td$a2>";
1378 $col_aligns[2] = "<td$a3>";
1379 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001380 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001381 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001382 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001383}
1384
Fred Drakef5478632002-05-23 17:59:16 +00001385sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001386 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001387 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001388 if ($font) {
1389 $sfont = "<$font>";
1390 $efont = "</$font>";
1391 $efont =~ s/ .*>/>/;
1392 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001393 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001394}
1395
1396sub do_env_tableii{
1397 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001398 my $arg = next_argument();
1399 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001400 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001401 my $h1 = next_argument();
1402 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001403 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001404 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001405 my $a1 = $col_aligns[0];
1406 my $a2 = $col_aligns[1];
1407 s/\\lineii</\\lineii[$a1|$a2]</g;
1408 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001409 . "\n <thead>"
1410 . "\n <tr class=\"tableheader\">"
1411 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1412 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1413 . "\n </tr>"
1414 . "\n </thead>"
1415 . "\n <tbody valign=\"baseline\">"
1416 . $_
1417 . "\n </tbody>"
1418 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001419}
1420
Fred Drakeda72b932000-09-21 15:58:02 +00001421sub do_env_longtableii{
1422 return do_env_tableii(@_);
1423}
1424
Fred Drake6659c301998-03-03 22:02:19 +00001425sub do_cmd_lineii{
1426 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001427 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001428 my $c1 = next_argument();
1429 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001430 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001431 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001432 $c1 = '&nbsp;' if ($c1 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001433 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001434 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001435 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001436 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001437 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001438 }
Fred Drakee15956b2000-04-03 04:51:13 +00001439 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1440 . " $c2align$c2</td>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001441 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001442}
1443
1444sub do_env_tableiii{
1445 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001446 my $arg = next_argument();
1447 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001448 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001449 my $h1 = next_argument();
1450 my $h2 = next_argument();
1451 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001452 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001453 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001454 my $a1 = $col_aligns[0];
1455 my $a2 = $col_aligns[1];
1456 my $a3 = $col_aligns[2];
1457 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1458 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001459 . "\n <thead>"
1460 . "\n <tr class=\"tableheader\">"
1461 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1462 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1463 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1464 . "\n </tr>"
1465 . "\n </thead>"
1466 . "\n <tbody valign=\"baseline\">"
1467 . $_
1468 . "\n </tbody>"
1469 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001470}
1471
Fred Drakeda72b932000-09-21 15:58:02 +00001472sub do_env_longtableiii{
1473 return do_env_tableiii(@_);
1474}
1475
Fred Drake6659c301998-03-03 22:02:19 +00001476sub do_cmd_lineiii{
1477 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001478 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001479 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001480 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001481 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001482 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001483 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001484 $c1 = '&nbsp;' if ($c1 eq '');
1485 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001486 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001487 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001488 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001489 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001490 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001491 }
Fred Drakee15956b2000-04-03 04:51:13 +00001492 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001493 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001494 . " $c3align$c3</td>"
1495 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001496}
1497
Fred Drakea0f4c941998-07-24 22:16:04 +00001498sub do_env_tableiv{
1499 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001500 my $arg = next_argument();
1501 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001502 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001503 my $h1 = next_argument();
1504 my $h2 = next_argument();
1505 my $h3 = next_argument();
1506 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001507 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001508 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001509 my $a1 = $col_aligns[0];
1510 my $a2 = $col_aligns[1];
1511 my $a3 = $col_aligns[2];
1512 my $a4 = $col_aligns[3];
1513 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1514 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001515 . "\n <thead>"
1516 . "\n <tr class=\"tableheader\">"
1517 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1518 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1519 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1520 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1521 . "\n </tr>"
1522 . "\n </thead>"
1523 . "\n <tbody valign=\"baseline\">"
1524 . $_
1525 . "\n </tbody>"
1526 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001527}
1528
Fred Drakeda72b932000-09-21 15:58:02 +00001529sub do_env_longtableiv{
1530 return do_env_tableiv(@_);
1531}
1532
Fred Drakea0f4c941998-07-24 22:16:04 +00001533sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001534 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001535 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001536 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001537 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001538 my $c3 = next_argument();
1539 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001540 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001541 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001542 $c1 = '&nbsp;' if ($c1 eq '');
1543 $c2 = '&nbsp;' if ($c2 eq '');
1544 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001545 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001546 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001547 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001548 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001549 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001550 }
Fred Drakee15956b2000-04-03 04:51:13 +00001551 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001552 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001553 . " $c3align$c3</td>\n"
1554 . " $c4align$c4</td>"
1555 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001556}
1557
Fred Drakef269e592001-07-17 23:05:57 +00001558sub do_env_tablev{
1559 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001560 my $arg = next_argument();
1561 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001562 my $font = fix_font(next_argument());
1563 my $h1 = next_argument();
1564 my $h2 = next_argument();
1565 my $h3 = next_argument();
1566 my $h4 = next_argument();
1567 my $h5 = next_argument();
1568 s/[\s\n]+//;
1569 $globals{'lineifont'} = $font;
1570 my $a1 = $col_aligns[0];
1571 my $a2 = $col_aligns[1];
1572 my $a3 = $col_aligns[2];
1573 my $a4 = $col_aligns[3];
1574 my $a5 = $col_aligns[4];
1575 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1576 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001577 . "\n <thead>"
1578 . "\n <tr class=\"tableheader\">"
1579 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1580 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1581 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1582 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1583 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1584 . "\n </tr>"
1585 . "\n </thead>"
1586 . "\n <tbody valign=\"baseline\">"
1587 . $_
1588 . "\n </tbody>"
1589 . "\n</table>";
Fred Drakef269e592001-07-17 23:05:57 +00001590}
1591
1592sub do_env_longtablev{
1593 return do_env_tablev(@_);
1594}
1595
1596sub do_cmd_linev{
1597 local($_) = @_;
1598 my $aligns = next_optional_argument();
1599 my $c1 = next_argument();
1600 my $c2 = next_argument();
1601 my $c3 = next_argument();
1602 my $c4 = next_argument();
1603 my $c5 = next_argument();
1604 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001605 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001606 $c1 = '&nbsp;' if ($c1 eq '');
1607 $c2 = '&nbsp;' if ($c2 eq '');
1608 $c3 = '&nbsp;' if ($c3 eq '');
1609 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef269e592001-07-17 23:05:57 +00001610 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001611 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001612 my $padding = '';
1613 if ($c1align =~ /align="right"/ || $c1 eq '') {
1614 $padding = '&nbsp;';
1615 }
1616 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1617 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001618 . " $c3align$c3</td>\n"
1619 . " $c4align$c4</td>\n"
1620 . " $c5align$c5</td>"
1621 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001622}
1623
Fred Drake3be20742000-08-31 06:22:54 +00001624
1625# These can be used to control the title page appearance;
1626# they need a little bit of documentation.
1627#
1628# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1629# $ICONSERVER directory, or include path information (other than "./"). The
1630# default image type will be assumed if an extension is not provided.
1631#
1632# If specified, the "title page" will contain two colums: one containing the
1633# title/author/etc., and the other containing the graphic. Use the other
1634# four variables listed here to control specific details of the layout; all
1635# are optional.
1636#
1637# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1638# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1639# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1640# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1641# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1642
Fred Drakef5478632002-05-23 17:59:16 +00001643sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001644 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001645 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001646 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001647 }
1648 else {
1649 write_warnings("\nThis document has no title.");
1650 }
Fred Drake6659c301998-03-03 22:02:19 +00001651 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001652 if ($t_authorURL) {
1653 my $href = translate_commands($t_authorURL);
1654 $href = make_named_href('author', $href,
1655 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001656 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001657 $the_title .= "\n<p>$href</p>";
1658 }
Fred Drake3be20742000-08-31 06:22:54 +00001659 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001660 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001661 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001662 }
Fred Drake3be20742000-08-31 06:22:54 +00001663 }
1664 else {
1665 write_warnings("\nThere is no author for this document.");
1666 }
Fred Drake6659c301998-03-03 22:02:19 +00001667 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001668 $the_title .= "\n<p>$t_institute</p>";
1669 }
Fred Draked07868a1998-05-14 21:00:28 +00001670 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001671 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1672 }
Fred Drake6659c301998-03-03 22:02:19 +00001673 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001674 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001675 }
Fred Drake6659c301998-03-03 22:02:19 +00001676 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001677 $the_title .= "\n<p>";
1678 if ($PACKAGE_VERSION) {
1679 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001680 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001681 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001682 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001683 }
1684 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001685 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001686 }
1687 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001688 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001689 }
Fred Drake6659c301998-03-03 22:02:19 +00001690 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001691 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001692 }
1693 return $the_title;
1694}
1695
Fred Drakef5478632002-05-23 17:59:16 +00001696sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001697 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001698 my $graphic = "<td class=\"titlegraphic\"";
1699 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1700 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1701 $graphic .= "><img";
1702 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1703 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1704 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1705 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001706 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001707 return $graphic;
1708}
1709
Fred Drakef5478632002-05-23 17:59:16 +00001710sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001711 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001712 my $the_title = "\n";
1713 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001714 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001715 # body), but I don't see any other way to get this generated
1716 # at all. Browsers like Mozilla, that support navigation
1717 # links, can make use of this.
1718 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1719 . ($EXTERNAL_UP_TITLE
1720 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001721 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001722 }
1723 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001724 if ($TITLE_PAGE_GRAPHIC) {
1725 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1726 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1727 . "<tr align=\"right\">\n<td>"
1728 . make_my_titlepage()
1729 . "</td>\n"
1730 . make_my_titlegraphic()
1731 . "</tr>\n</table>");
1732 }
1733 else {
1734 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1735 . make_my_titlegraphic()
1736 . "<td>"
1737 . make_my_titlepage()
1738 . "</td></tr>\n</table>");
1739 }
1740 }
1741 else {
1742 $the_title .= ("\n<center>"
1743 . make_my_titlepage()
1744 . "\n</center>");
1745 }
1746 $the_title .= "\n</div>";
1747 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001748 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001749 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001750}
1751
1752
Fred Drake885215c1998-05-20 21:32:09 +00001753#
Fred Drakea0f4c941998-07-24 22:16:04 +00001754# Module synopsis support
1755#
1756
1757require SynopsisTable;
1758
Fred Drakef7685d71998-07-25 03:31:46 +00001759sub get_chapter_id(){
1760 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001761 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001762 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001763 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001764}
1765
Fred Drake643d76d2000-09-09 06:07:37 +00001766# 'chapter' => 'SynopsisTable instance'
1767%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001768
1769sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001770 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001771 my $key;
1772 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001773 if ($key eq $chap) {
1774 return $ModuleSynopses{$chap};
1775 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001776 }
Fred Drake643d76d2000-09-09 06:07:37 +00001777 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001778 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001779 return $st;
1780}
1781
Fred Drake62e43691998-08-10 19:40:44 +00001782sub do_cmd_moduleauthor{
1783 local($_) = @_;
1784 next_argument();
1785 next_argument();
1786 return $_;
1787}
1788
1789sub do_cmd_sectionauthor{
1790 local($_) = @_;
1791 next_argument();
1792 next_argument();
1793 return $_;
1794}
1795
Fred Drakea0f4c941998-07-24 22:16:04 +00001796sub do_cmd_declaremodule{
1797 local($_) = @_;
1798 my $key = next_optional_argument();
1799 my $type = next_argument();
1800 my $name = next_argument();
1801 my $st = get_synopsis_table(get_chapter_id());
1802 #
1803 $key = $name unless $key;
1804 $type = 'built-in' if $type eq 'builtin';
1805 $st->declare($name, $key, $type);
1806 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001807 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001808}
1809
1810sub do_cmd_modulesynopsis{
1811 local($_) = @_;
1812 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001813 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001814 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001815}
1816
1817sub do_cmd_localmoduletable{
1818 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001819 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001820 my $st = get_synopsis_table($chap);
1821 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001822 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001823}
1824
Fred Drakef5478632002-05-23 17:59:16 +00001825sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001826 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001827 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001828 my $st = $ModuleSynopses{$key};
1829 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001830 if ($file) {
1831 process_localmoduletables_in_file($file);
1832 }
1833 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001834 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001835 }
1836 }
1837}
1838
Fred Drakef5478632002-05-23 17:59:16 +00001839sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001840 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001841 open(MYFILE, "<$file");
1842 local($_);
1843 sysread(MYFILE, $_, 1024*1024);
1844 close(MYFILE);
1845 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001846 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001847 my $match = $&;
1848 my $chap = $1;
1849 my $st = get_synopsis_table($chap);
1850 my $data = $st->tohtml();
1851 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001852 }
Fred Drake643d76d2000-09-09 06:07:37 +00001853 open(MYFILE,">$file");
1854 print MYFILE $_;
1855 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001856}
Fred Drakef5478632002-05-23 17:59:16 +00001857sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001858 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001859 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001860}
Fred Drakea0f4c941998-07-24 22:16:04 +00001861
1862
1863#
1864# "See also:" -- references placed at the end of a \section
1865#
1866
1867sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001868 return ("<div class=\"seealso\">\n "
1869 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001870 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001871 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001872}
1873
Fred Drake5ed35fd2001-11-30 18:09:54 +00001874sub do_env_seealsostar{
1875 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001876 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001877 . '</div>');
1878}
1879
Fred Drakea0f4c941998-07-24 22:16:04 +00001880sub do_cmd_seemodule{
1881 # Insert the right magic to jump to the module definition. This should
1882 # work most of the time, at least for repeat builds....
1883 local($_) = @_;
1884 my $key = next_optional_argument();
1885 my $module = next_argument();
1886 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001887 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001888 $key = $module
1889 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001890 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001891 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001892 }
Fred Drakef1927a62001-06-20 21:29:30 +00001893 return ('<dl compact class="seemodule">'
1894 . "\n <dt>Module <b><tt class=\"module\">"
1895 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1896 . "\n <dd>$text$period\n </dl>"
1897 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001898}
1899
Fred Drakee0197bf2001-04-12 04:03:22 +00001900sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001901 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001902 my $s = "$str";
1903 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1904 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1905 return $s;
1906}
1907
Fred Drakef5478632002-05-23 17:59:16 +00001908sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001909 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001910 my $rfcnum = next_argument();
1911 my $title = next_argument();
1912 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001913 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001914 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001915 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001916 return '<dl compact class="seerfc">'
1917 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001918 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001919 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001920 . "\n <dd>$text\n </dl>"
1921 . $_;
1922}
1923
Fred Drake643d76d2000-09-09 06:07:37 +00001924sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001925 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001926}
1927
1928sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001929 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001930 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001931}
1932
Fred Drake48449982000-09-12 17:52:33 +00001933sub do_cmd_seetitle{
1934 local($_) = @_;
1935 my $url = next_optional_argument();
1936 my $title = next_argument();
1937 my $text = next_argument();
1938 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001939 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001940 return '<dl compact class="seetitle">'
1941 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001942 . "\n >$title$icon</a></em></dt>"
1943 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001944 . $_;
1945 }
1946 return '<dl compact class="seetitle">'
1947 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001948 . "\n >$title</em></dt>"
1949 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001950 . $_;
1951}
1952
Fred Drake4f687b32004-01-08 14:57:27 +00001953sub do_cmd_seelink{
1954 local($_) = @_;
1955 my $url = next_argument();
1956 my $linktext = next_argument();
1957 my $text = next_argument();
1958 my $icon = get_link_icon($url);
1959 return '<dl compact class="seeurl">'
1960 . "\n <dt><a href='$url'"
1961 . "\n >$linktext$icon</a></dt>"
1962 . "\n <dd>$text</dd>\n </dl>"
1963 . $_;
1964}
1965
Fred Drakeef4d1112000-05-09 16:17:51 +00001966sub do_cmd_seeurl{
1967 local($_) = @_;
1968 my $url = next_argument();
1969 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001970 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001971 return '<dl compact class="seeurl">'
1972 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001973 . "\n class=\"url\">$url$icon</a></dt>"
1974 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001975 . $_;
1976}
1977
Fred Drakea0f4c941998-07-24 22:16:04 +00001978sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001979 local($_) = @_;
1980 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001981 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001982}
1983
1984
1985#
Fred Drake885215c1998-05-20 21:32:09 +00001986# Definition list support.
1987#
1988
1989sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001990 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001991}
1992
1993sub do_cmd_term{
1994 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001995 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001996 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001997 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001998 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001999}
2000
2001
Fred Drake4e72e052003-07-15 22:00:36 +00002002# Commands listed here have process-order dependencies; these often
2003# are related to indexing operations.
2004# XXX Not sure why funclineni, methodlineni, and samp are here.
2005#
Fred Drake2ff880e1999-02-05 18:31:29 +00002006process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002007declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002008funcline # {} # {}
2009funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002010memberline # [] # {}
2011methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002012methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002013modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00002014bifuncindex # {}
2015exindex # {}
2016indexii # {} # {}
2017indexiii # {} # {} # {}
2018indexiv # {} # {} # {} # {}
2019kwindex # {}
2020obindex # {}
2021opindex # {}
2022stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002023platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002024samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002025setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002026withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002027_RAW_ARG_DEFERRED_CMDS_
2028
2029
Fred Drake8a5e6792002-04-15 18:41:31 +00002030$alltt_start = '<div class="verbatim"><pre>';
2031$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002032
Fred Drakef5478632002-05-23 17:59:16 +00002033sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002034 local ($_) = @_;
2035 local($closures,$reopens,@open_block_tags);
2036
2037 # get the tag-strings for all open tags
2038 local(@keep_open_tags) = @$open_tags_R;
2039 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2040
2041 # get the tags for text-level tags only
2042 $open_tags_R = [ @keep_open_tags ];
2043 local($local_closures, $local_reopens);
2044 ($local_closures, $local_reopens,@open_block_tags)
2045 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002046 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002047
2048 $open_tags_R = [ @open_block_tags ];
2049
2050 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002051 local($open_tags_R) = [ @open_block_tags ];
2052 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002053
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002054 local($cnt) = ++$global{'max_id'};
2055 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2056 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002057
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002058 $_ = &translate_environments($_);
2059 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002060
Fred Drake41aa0182003-09-05 15:43:00 +00002061 # remove spurious <BR> someone sticks in; not sure where they
2062 # actually come from
2063 # XXX the replacement space is there to accomodate something
2064 # broken that inserts a space in front of the first line of
2065 # the environment
2066 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002067
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002068 $_ = join('', $closures, $alltt_start, $local_reopens
2069 , $_
2070 , &balance_tags() #, $local_closures
2071 , $alltt_end, $reopens);
2072 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002073 };
2074 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002075 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002076}
2077
Fred Drake345555d2003-12-30 16:19:28 +00002078# List of all filenames produced my do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002079%VerbatimFiles = ();
2080@VerbatimOutputs = ();
2081
2082sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002083 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002084 #
2085 # Re-write the source filename to always use a .txt extension
2086 # so that Web servers will present it as text/plain. This is
2087 # needed since there is no other even moderately reliable way
2088 # to get the right Content-Type header on text files for
2089 # servers which we can't configure (like python.org mirrors).
2090 #
2091 if (defined $VerbatimFiles{$file}) {
2092 # We've seen this one before; re-use the same output file.
2093 return $VerbatimFiles{$file};
2094 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002095 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002096 $filename = "$srcname.txt";
2097 #
2098 # We need to determine if our default filename is already
2099 # being used, and find a new one it it is. If the name is in
2100 # used, this algorithm will first attempt to include the
2101 # source extension as part of the name, and if that is also in
2102 # use (if the same file is included multiple times, or if
2103 # another source file has that as the base name), a counter is
2104 # used instead.
2105 #
2106 my $found = 1;
2107 FIND:
2108 while ($found) {
2109 foreach $fn (@VerbatimOutputs) {
2110 if ($fn eq $filename) {
2111 if ($found == 1) {
2112 $srcext =~ s/^[.]//; # Remove '.' from extension
2113 $filename = "$srcname-$srcext.txt";
2114 }
2115 else {
2116 $filename = "$srcname-$found.txt";
2117 }
2118 ++$found;
2119 next FIND;
2120 }
2121 }
2122 $found = 0;
2123 }
2124 push @VerbatimOutputs, $filename;
2125 $VerbatimFiles{$file} = $filename;
2126 return $filename;
2127}
2128
Fred Drake57e52ef2001-06-15 21:31:57 +00002129sub do_cmd_verbatiminput{
2130 local($_) = @_;
2131 my $fname = next_argument();
2132 my $file;
2133 my $found = 0;
2134 my $texpath;
2135 # Search TEXINPUTS for the input file, the way we're supposed to:
2136 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2137 $file = "$texpath$dd$fname";
2138 last if ($found = (-f $file));
2139 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002140 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002141 my $text;
2142 if ($found) {
2143 open(MYFILE, "<$file") || die "\n$!\n";
2144 read(MYFILE, $text, 1024*1024);
2145 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002146 $filename = get_verbatim_output_name($file);
2147 # Now that we have a filename, write it out.
2148 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002149 print MYFILE $text;
2150 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002151 #
2152 # These rewrites convert the raw text to something that will
2153 # be properly visible as HTML and also will pass through the
2154 # vagaries of conversion through LaTeX2HTML. The order in
2155 # which the specific rewrites are performed is significant.
2156 #
2157 $text =~ s/\&/\&amp;/g;
2158 # These need to happen before the normal < and > re-writes,
2159 # since we need to avoid LaTeX2HTML's attempt to perform
2160 # ligature processing without regard to context (since it
2161 # doesn't have font information).
2162 $text =~ s/--/-&\#45;/g;
2163 $text =~ s/<</\&lt;\&\#60;/g;
2164 $text =~ s/>>/\&gt;\&\#62;/g;
2165 # Just normal re-writes...
2166 $text =~ s/</\&lt;/g;
2167 $text =~ s/>/\&gt;/g;
2168 # These last isn't needed for the HTML, but is needed to get
2169 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2170 # of &sol; since many browsers don't support that.
2171 $text =~ s/\\/\&\#92;/g;
2172 }
2173 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002174 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2175 }
2176 my $note = 'Download as text.';
2177 if ($file ne $filename) {
2178 $note = ('Download as text (original file name: <span class="file">'
2179 . $fname
2180 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002181 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002182 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002183 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002184 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002185 . "<a href=\"$filename\" type=\"text/plain\""
2186 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002187 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002188 . $_);
2189}
Fred Drake86333602001-04-10 17:13:39 +00002190
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021911; # This must be the last line