blob: 48e311563fd706460444d9e76bf1f3b41e0f46e7 [file] [log] [blame]
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
Fred Drake6659c301998-03-03 22:02:19 +00002#
3# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
4#
5# Extension to LaTeX2HTML for documents using myformat.sty.
6# Subroutines of the form do_cmd_<name> here define translations
7# for LaTeX commands \<name> defined in the corresponding .sty file.
8
9package main;
10
Fred Drake49b33fa2002-11-15 19:04:10 +000011use warnings;
Fred Drake7a40c072000-10-02 14:43:38 +000012use File::Basename;
13
Fred Drake6659c301998-03-03 22:02:19 +000014
Fred Drake08932051998-04-17 02:15:42 +000015sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000016 my $param;
17 $param = missing_braces()
18 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
Fred Drake1b1ca0c2003-09-05 15:43:58 +000019 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000020 return $param;
Fred Drake08932051998-04-17 02:15:42 +000021}
22
23sub next_optional_argument{
Fred Drakef5478632002-05-23 17:59:16 +000024 my($param, $rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000025 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000026 return $param;
Fred Drake08932051998-04-17 02:15:42 +000027}
28
Fred Drake7a40c072000-10-02 14:43:38 +000029sub make_icon_filename($){
Fred Drake49b33fa2002-11-15 19:04:10 +000030 my($myname, $mydir, $myext) = fileparse($_[0], '\..*');
Fred Drake7a40c072000-10-02 14:43:38 +000031 chop $mydir;
32 if ($mydir eq '.') {
33 $mydir = $ICONSERVER;
34 }
35 $myext = ".$IMAGE_TYPE"
36 unless $myext;
37 return "$mydir$dd$myname$myext";
38}
39
Fred Drake7a40c072000-10-02 14:43:38 +000040sub get_link_icon($){
Fred Drake49b33fa2002-11-15 19:04:10 +000041 my $url = $_[0];
Fred Drake7a40c072000-10-02 14:43:38 +000042 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
43 # absolute URL; assume it points off-site
44 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
Fred Drakef1927a62001-06-20 21:29:30 +000045 return (" <img src=\"$icon\"\n"
46 . ' border="0" class="offsitelink"'
Fred Drake5f84c9b2000-10-03 06:05:25 +000047 . ($OFF_SITE_LINK_ICON_HEIGHT
Fred Drakef1927a62001-06-20 21:29:30 +000048 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000049 : '')
50 . ($OFF_SITE_LINK_ICON_WIDTH
Fred Drakef1927a62001-06-20 21:29:30 +000051 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000052 : '')
Fred Drakef1927a62001-06-20 21:29:30 +000053 . " alt=\"[off-site link]\"\n"
Fred Drake2fc88a62003-08-05 03:45:37 +000054 . " />");
Fred Drake7a40c072000-10-02 14:43:38 +000055 }
56 return '';
57}
Fred Drakee16f6791998-05-15 04:28:37 +000058
59# This is a fairly simple hack; it supports \let when it is used to create
60# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000061# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000062#
63sub do_cmd_let{
64 local($_) = @_;
65 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000066 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000067 if ($matched) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +000068 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
Fred Drakee16f6791998-05-15 04:28:37 +000071 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000072 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +000073 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
74 if ($matched) {
75 my($new, $char) = ($1, $3);
76 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
77 print "\ndefining handler for \\$new to insert '$char'\n";
78 }
79 else {
80 write_warnings("Could not interpret \\let construct...");
81 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000082 }
Fred Drake62e43691998-08-10 19:40:44 +000083 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000084}
85
86
Fred Drakec3fd45f2000-06-15 22:41:48 +000087# the older version of LaTeX2HTML we use doesn't support this, but we use it:
88
Fred Drake49b33fa2002-11-15 19:04:10 +000089sub do_cmd_textasciitilde{ '&#126;' . $_[0]; }
90sub do_cmd_textasciicircum{ '^' . $_[0]; }
91sub do_cmd_textbar{ '|' . $_[0]; }
Fred Drake7adcfad2003-07-10 17:04:45 +000092sub do_cmd_texteuro { '&#8364;' . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +000093sub do_cmd_textgreater{ '&gt;' . $_[0]; }
94sub do_cmd_textless{ '&lt;' . $_[0]; }
95sub do_cmd_textunderscore{ '_' . $_[0]; }
96sub do_cmd_infinity{ '&infin;' . $_[0]; }
97sub do_cmd_plusminus{ '&plusmn;' . $_[0]; }
Fred Drakef0f6d122004-01-23 08:52:28 +000098sub do_cmd_guilabel{
99 return use_wrappers($_[0]. '<span class="guilabel">', '</span>'); }
Fred Drakebd5fdd92003-07-16 14:01:56 +0000100sub do_cmd_menuselection{
Fred Drakef0f6d122004-01-23 08:52:28 +0000101 return use_wrappers($_[0], '<span class="guilabel">', '</span>'); }
102sub do_cmd_sub{
103 return '</span> &gt; <span class="guilabel">' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +0000104
105
Fred Drake6659c301998-03-03 22:02:19 +0000106# words typeset in a special way (not in HTML though)
107
Fred Drake49b33fa2002-11-15 19:04:10 +0000108sub do_cmd_ABC{ 'ABC' . $_[0]; }
Fred Drake9c8149a2004-11-10 17:56:29 +0000109sub do_cmd_UNIX{ '<span class="Unix">Unix</span>'
Fred Drake5bbeb8d2003-02-04 15:01:37 +0000110 . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000111sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
112sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
113sub do_cmd_C{ 'C' . $_[0]; }
114sub do_cmd_Cpp{ 'C++' . $_[0]; }
115sub do_cmd_EOF{ 'EOF' . $_[0]; }
116sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000117
Fred Drake49b33fa2002-11-15 19:04:10 +0000118sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000119
Fred Draked07868a1998-05-14 21:00:28 +0000120$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000121$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000122$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000123$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000124
Fred Drake49b33fa2002-11-15 19:04:10 +0000125sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
126sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000127sub do_cmd_release{
128 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000129 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000130 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000131}
132
Fred Drakef1927a62001-06-20 21:29:30 +0000133sub do_cmd_setreleaseinfo{
134 local($_) = @_;
135 $RELEASE_INFO = next_argument();
136 return $_;
137}
138
Fred Drake3cdb89d2000-09-14 20:17:23 +0000139sub do_cmd_setshortversion{
140 local($_) = @_;
141 $SHORT_VERSION = next_argument();
142 return $_;
143}
144
Fred Drake6659c301998-03-03 22:02:19 +0000145sub do_cmd_authoraddress{
146 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000147 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000148 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000149}
150
151sub do_cmd_hackscore{
152 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000153 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000154 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000155}
156
Fred Drake345555d2003-12-30 16:19:28 +0000157# Helper used in many places that arbitrary code-like text appears:
158
159sub codetext($){
160 my $text = "$_[0]";
Fred Drakec6864832004-11-11 05:42:13 +0000161 # Make sure that "---" is not converted to "--" later when
162 # LaTeX2HTML tries converting em-dashes based on the conventional
163 # TeX font ligatures:
Fred Drake345555d2003-12-30 16:19:28 +0000164 $text =~ s/--/-\&#45;/go;
165 return $text;
166}
167
Fred Drakef5478632002-05-23 17:59:16 +0000168sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000169 local($_,$before,$after) = @_;
170 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000171 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000172}
173
Fred Drake345555d2003-12-30 16:19:28 +0000174sub use_code_wrappers($$$){
175 local($_,$before,$after) = @_;
176 my $stuff = codetext(next_argument());
177 return $before . $stuff . $after . $_;
178}
179
Fred Drake3cdb89d2000-09-14 20:17:23 +0000180$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000181sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000182 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000183 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000184 "</var><big>\]</big><var>");
185 }
186 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000187 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000188 }
Fred Drake6659c301998-03-03 22:02:19 +0000189}
190
Fred Drakec9a44381998-03-17 06:29:13 +0000191# Logical formatting (some based on texinfo), needs to be converted to
192# minimalist HTML. The "minimalist" is primarily to reduce the size of
193# output files for users that read them over the network rather than
194# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000195
Fred Drake49b33fa2002-11-15 19:04:10 +0000196sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000197sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000198 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000199sub do_cmd_code{
Fred Drake345555d2003-12-30 16:19:28 +0000200 return use_code_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000201sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000202 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000203sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000204 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000205sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000206 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000207sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000208 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000209sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000210 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000211sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000212 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000213sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000214 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000215sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000216 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000217sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000218 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000220 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000221sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000222 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_regexp{
Fred Drake345555d2003-12-30 16:19:28 +0000224 return use_code_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_character{
Fred Drake345555d2003-12-30 16:19:28 +0000226 return use_code_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000227sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000228 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000229sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000230 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000231sub do_cmd_longprogramopt{
232 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000233 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000234sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000235 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000236sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000237 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000238sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000239 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000240sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000241 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000242sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000243 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000244sub do_cmd_emph{
Fred Drake9c8149a2004-11-10 17:56:29 +0000245 return use_wrappers($_[0], '<em>', '</em>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000246sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000247 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000248sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000249 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000250sub do_cmd_samp{
Fred Drake345555d2003-12-30 16:19:28 +0000251 return use_code_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000252sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000253 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000254sub do_cmd_strong{
Fred Drake9c8149a2004-11-10 17:56:29 +0000255 return use_wrappers($_[0], '<strong>', '</strong>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000256sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000257 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000258sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000259 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000260# This can be changed/overridden for translations:
261%NoticeNames = ('note' => 'Note:',
262 'warning' => 'Warning:',
263 );
264
Fred Drake92350b32001-10-09 18:01:23 +0000265sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000266 my $label = $NoticeNames{'note'};
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=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000270 '</span>'); }
271sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000272 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000273 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000274 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000275 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000276 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000277
Fred Drake6ca33772001-12-14 22:50:06 +0000278sub do_env_notice{
279 local($_) = @_;
280 my $notice = next_optional_argument();
281 if (!$notice) {
282 $notice = 'note';
283 }
284 my $label = $NoticeNames{$notice};
285 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
286 . $_
287 . '</div>');
288}
289
Fred Drake3d5a04a2000-08-03 17:25:44 +0000290sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000291 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000292sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000293 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000294
Fred Drakec9a44381998-03-17 06:29:13 +0000295
Fred Drake25817041999-01-13 17:06:34 +0000296sub do_cmd_refmodule{
297 # Insert the right magic to jump to the module definition.
298 local($_) = @_;
299 my $key = next_optional_argument();
300 my $module = next_argument();
301 $key = $module
302 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000303 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000304 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000305}
306
Fred Drake1a7af391998-04-01 22:44:56 +0000307sub do_cmd_newsgroup{
308 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000309 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000310 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000311 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
312 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000313 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000314}
Fred Drakefc16e781998-03-12 21:03:26 +0000315
316sub do_cmd_envvar{
317 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000318 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000319 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000320 # The <tt> here is really to keep buildindex.py from making
321 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000322 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000323 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000324 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000325 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000326 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000327}
328
Fred Drake6659c301998-03-03 22:02:19 +0000329sub do_cmd_url{
330 # use the URL as both text and hyperlink
331 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000332 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000333 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000334 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000335 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000336}
337
338sub do_cmd_manpage{
339 # two parameters: \manpage{name}{section}
340 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000341 my $page = next_argument();
342 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000343 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000344}
345
Fred Drakedbfe7682002-04-03 02:47:14 +0000346$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000347#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
348$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000349
350sub get_rfc_url($$){
351 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000352 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000353}
354
355sub do_cmd_pep{
356 local($_) = @_;
357 my $rfcnumber = next_argument();
358 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000359 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000360 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000361 # Save the reference
362 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
363 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake0c1b2532004-10-29 19:47:52 +0000364 return ("<a class=\"rfc\" id='$id' xml:id='$id'\n"
Fred Drake2fc88a62003-08-05 03:45:37 +0000365 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000366}
367
Fred Drake6659c301998-03-03 22:02:19 +0000368sub do_cmd_rfc{
369 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000370 my $rfcnumber = next_argument();
371 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000372 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000373 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000374 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000375 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000376 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake0c1b2532004-10-29 19:47:52 +0000377 return ("<a class=\"rfc\" id='$id' xml:id='$id'\nhref=\"$href\">"
Fred Drake2fc88a62003-08-05 03:45:37 +0000378 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000379}
380
Fred Drake77602f22001-07-06 22:43:02 +0000381sub do_cmd_ulink{
382 local($_) = @_;
383 my $text = next_argument();
384 my $url = next_argument();
385 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
386}
387
Fred Drakec9f5fe01999-11-09 16:59:42 +0000388sub do_cmd_citetitle{
389 local($_) = @_;
390 my $url = next_optional_argument();
391 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000392 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000393 my $repl = '';
394 if ($url) {
Fred Drakeed306292004-11-04 03:23:04 +0000395 my $titletext = strip_html_markup("$title");
Fred Drakef1927a62001-06-20 21:29:30 +0000396 $repl = ("<em class=\"citetitle\"><a\n"
397 . " href=\"$url\"\n"
Fred Drakeed306292004-11-04 03:23:04 +0000398 . " title=\"$titletext\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000399 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000400 }
401 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000402 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000403 }
404 return $repl . $_;
405}
406
Fred Drake6659c301998-03-03 22:02:19 +0000407sub do_cmd_deprecated{
408 # two parameters: \deprecated{version}{whattodo}
409 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000410 my $release = next_argument();
411 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000412 return ('<div class="versionnote">'
413 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000414 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000415 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000416}
417
Fred Drakef5478632002-05-23 17:59:16 +0000418sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000419 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000420 my $type = $_[0];
421 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000422 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000423 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000424 my $text = "$type in version $release.";
425 if ($explanation) {
426 $text = "$type in version $release:\n$explanation.";
427 }
Fred Drakef1927a62001-06-20 21:29:30 +0000428 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000429}
430
431sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000432 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000433}
434
435sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000436 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000437}
438
Fred Drake557460c1999-03-02 16:05:35 +0000439#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000440# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000441#
442sub do_cmd_platform{
443 local($_) = @_;
444 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000445 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000446 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000447 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000448 return "\n<p class=\"availability\">Availability: <span"
449 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000450}
451
Fred Drake557460c1999-03-02 16:05:35 +0000452$IGNORE_PLATFORM_ANNOTATION = '';
453sub do_cmd_ignorePlatformAnnotation{
454 local($_) = @_;
455 $IGNORE_PLATFORM_ANNOTATION = next_argument();
456 return $_;
457}
458
Fred Drake6659c301998-03-03 22:02:19 +0000459
460# index commands
461
462$INDEX_SUBITEM = "";
463
Fred Drakef5478632002-05-23 17:59:16 +0000464sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000465 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000466}
467
468sub do_cmd_setindexsubitem{
469 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000470 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000471 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000472}
473
Fred Drakefc16e781998-03-12 21:03:26 +0000474sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000475 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000476 # do things in the right order, but we need to at least strip this stuff
477 # out, and leave anything that the second argument expanded out to.
478 #
479 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000480 my $oldsubitem = $INDEX_SUBITEM;
481 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000482 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000483 my $br_id = ++$globals{'max_id'};
484 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000485 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000486 return
487 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000488 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000489 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000490}
491
Fred Drake08932051998-04-17 02:15:42 +0000492# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000493# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
494# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000495#
Fred Drake49b33fa2002-11-15 19:04:10 +0000496sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000497
Fred Drake42b31a51998-03-27 05:16:10 +0000498# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000499#
Fred Drake08932051998-04-17 02:15:42 +0000500open(IDXFILE, '>index.dat') || die "\n$!\n";
501open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000502print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000503print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000504
505# Using \0 for this is bad because we can't use common tools to work with the
506# resulting files. Things like grep can be useful with this stuff!
507#
508$IDXFILE_FIELD_SEP = "\1";
509
Fred Drakef5478632002-05-23 17:59:16 +0000510sub write_idxfile($$){
511 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000512 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000513}
514
Fred Drake42b31a51998-03-27 05:16:10 +0000515
Fred Drakef5478632002-05-23 17:59:16 +0000516sub gen_link($$){
517 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000518 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000519 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000520}
521
Fred Drakef5478632002-05-23 17:59:16 +0000522sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000523 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000524 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000525 $str = gen_index_id($str, '');
526 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000527 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000528}
529
Fred Drake04bf7242003-11-26 20:55:49 +0000530sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000531 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake0c1b2532004-10-29 19:47:52 +0000532 my $aname = "<a id='$name' xml:id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000533 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000534 return ($name, $ahref);
535}
536
537sub new_link_info(){
538 my($name, $ahref) = new_link_name_info();
Fred Drake0c1b2532004-10-29 19:47:52 +0000539 my $aname = "<a id='$name' xml:id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000540 return ($name, $aname, $ahref);
541}
542
Fred Drakeab032151999-05-13 18:36:54 +0000543$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000544sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000545 my $count = @_;
546 my $i = 0;
547 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000548 my $name = $_[$i];
549 my $cmd = "idx_cmd_$name";
550 die "\nNo function $cmd() defined!\n"
551 if (!defined &$cmd);
552 eval ("sub do_cmd_$name { return process_index_macros("
553 . "\$_[0], '$name'); }");
554 if (length($IndexMacroPattern) == 0) {
555 $IndexMacroPattern = "$name";
556 }
557 else {
558 $IndexMacroPattern .= "|$name";
559 }
Fred Drakeab032151999-05-13 18:36:54 +0000560 }
561}
562
563$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000564sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000565 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000566 my $cmdname = $_[1]; # This is what triggered us in the first place;
567 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000568 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000569 my $cmd = "idx_cmd_$cmdname";
570 print "\nIndexing: \\$cmdname"
571 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000572 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000573 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000574 $cmdname = "$1";
575 print " \\$cmdname"
576 if $DEBUG_INDEXING;
577 $cmd = "idx_cmd_$cmdname";
578 if (!defined &$cmd) {
579 last;
580 }
581 else {
582 s/^[\s\n]*\\$cmdname//;
583 &$cmd($ahref);
584 }
Fred Drakeab032151999-05-13 18:36:54 +0000585 }
Fred Drake899072a2004-04-08 15:30:12 +0000586# XXX I don't remember why I added this to begin with.
587# if (/^[ \t\r\n]/) {
588# $_ = substr($_, 1);
589# }
Fred Drake62e43691998-08-10 19:40:44 +0000590 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000591}
592
Fred Drakeab032151999-05-13 18:36:54 +0000593define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000594sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000595 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000596 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000597}
598
Fred Drakeab032151999-05-13 18:36:54 +0000599define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000600sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000601 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000602 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
603 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000604}
605
606define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000607sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000608 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000609 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000610 add_index_entry("$str1!$str2", $_[0]);
611 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000612}
613
Fred Drakeab032151999-05-13 18:36:54 +0000614define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000615sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000616 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000617 my $str2 = next_argument();
618 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000619 add_index_entry("$str1!$str2 $str3", $_[0]);
620 add_index_entry("$str2!$str3, $str1", $_[0]);
621 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000622}
623
Fred Drakeab032151999-05-13 18:36:54 +0000624define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000625sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000626 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000627 my $str2 = next_argument();
628 my $str3 = next_argument();
629 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000630 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
631 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
632 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
633 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000634}
635
Fred Drakeab032151999-05-13 18:36:54 +0000636define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000637sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000638 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000639 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000640 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000641}
Fred Drake6659c301998-03-03 22:02:19 +0000642
Fred Drakef5478632002-05-23 17:59:16 +0000643sub my_typed_index_helper($$){
644 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000645 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000646 add_index_entry("$str $word", $ahref);
647 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000648}
649
Fred Drakeab032151999-05-13 18:36:54 +0000650define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000651sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
652sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
653sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
654sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000655
Fred Drakeab032151999-05-13 18:36:54 +0000656define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000657sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000658 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000659 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000660 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000661}
662
663
Fred Drakef5478632002-05-23 17:59:16 +0000664sub make_mod_index_entry($$){
665 my($str, $define) = @_;
666 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000667 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000668 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
669 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000670 $str = gen_index_id($str, $define);
671 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000672 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000673
Fred Drakec9a44381998-03-17 06:29:13 +0000674 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000675 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000676 $str =~ /(<tt.*<\/tt>)/;
677 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000678 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000679 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000680 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000681}
682
Fred Drake557460c1999-03-02 16:05:35 +0000683
Fred Drakec9a44381998-03-17 06:29:13 +0000684$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000685$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000686
Fred Drakef5478632002-05-23 17:59:16 +0000687sub define_module($$){
688 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000689 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000690 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000691 && $word ne "standard" && $word ne "") {
692 write_warnings("Bad module type '$word'"
693 . " for \\declaremodule (module $name)");
694 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000695 }
Fred Drake6659c301998-03-03 22:02:19 +0000696 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000697 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000698 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000699 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000700 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000701 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000702}
703
Fred Drakef5478632002-05-23 17:59:16 +0000704sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000705 local($word, $_) = @_;
706 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000707 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000708}
709
Fred Drake49b33fa2002-11-15 19:04:10 +0000710sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
711sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
712sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
713sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
714# local($_) = @_;
715# my $name = next_argument();
716# return define_module('standard', $name) . $_;
717# }
Fred Drake6659c301998-03-03 22:02:19 +0000718
Fred Drakef5478632002-05-23 17:59:16 +0000719sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000720 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000721 my $str = next_argument();
722 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000723 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000724 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
725 # just inline it all here
726 $str = gen_index_id($str, 'REF');
727 $index{$str} .= $ahref;
728 write_idxfile($ahref, $str);
729}
730
Fred Drake6659c301998-03-03 22:02:19 +0000731# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000732define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000733 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000734sub idx_cmd_refmodindex($){
735 return ref_module_index_helper('', $_[0]); }
736sub idx_cmd_refbimodindex($){
737 return ref_module_index_helper('built-in', $_[0]); }
738sub idx_cmd_refexmodindex($){
739 return ref_module_index_helper('extension', $_[0]);}
740sub idx_cmd_refstmodindex($){
741 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000742
Fred Drake49b33fa2002-11-15 19:04:10 +0000743sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000744
Fred Drakef5478632002-05-23 17:59:16 +0000745sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000746 # These markers must be non-empty or the main latex2html script
747 # may remove a surrounding element that has not other content as
748 # "extraneous"; this ensures these elements (usually hyperlink
749 # targets) are not removed improperly. We use comments since
750 # there's no meaningful actual content.
751 # Thanks to Dave Kuhlman for figuring why some named anchors were
752 # being lost.
753 $anchor_invisible_mark = '<!--x-->';
754 $anchor_invisible_mark2 = '<!--y-->';
755 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000756 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000757}
Fred Drake42b31a51998-03-27 05:16:10 +0000758init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000759
Fred Drakeab032151999-05-13 18:36:54 +0000760# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000761# instead of the dummy filler.
762#
Fred Drakef5478632002-05-23 17:59:16 +0000763sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000764 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000765 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000766 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000767 if ($str =~ /^<[a-z]+\b/) {
768 my $s = "$str";
Fred Drake0c1b2532004-10-29 19:47:52 +0000769 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
Fred Drake04bf7242003-11-26 20:55:49 +0000770 return $s;
771 }
772 else {
Fred Drake0c1b2532004-10-29 19:47:52 +0000773 return "<a id='$name' xml:id='$name'>$str</a>";
Fred Drake04bf7242003-11-26 20:55:49 +0000774 }
Fred Drake6659c301998-03-03 22:02:19 +0000775}
776
Fred Drake77602f22001-07-06 22:43:02 +0000777
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000778%TokenToTargetMapping = (); # language:token -> link target
779%DefinedGrammars = (); # language -> full grammar text
780%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000781
782sub do_cmd_token{
783 local($_) = @_;
784 my $token = next_argument();
785 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
786 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
787 # recursive definition or display-only productionlist
788 return "$token";
789 }
790 if ($target eq '') {
791 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
792 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
793 print "Adding '$CURRENT_FILE' to back-patch list.\n";
794 }
795 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
796 }
Fred Drake5d93eef2004-11-10 17:02:43 +0000797 return "<a class='grammartoken' href=\"$target\">$token</a>" . $_;
Fred Drake77602f22001-07-06 22:43:02 +0000798}
799
Fred Drake16bb4192001-08-20 21:36:38 +0000800sub do_cmd_grammartoken{
801 return do_cmd_token(@_);
802}
803
Fred Drake77602f22001-07-06 22:43:02 +0000804sub do_env_productionlist{
805 local($_) = @_;
806 my $lang = next_optional_argument();
807 my $filename = "grammar-$lang.txt";
808 if ($lang eq '') {
809 $filename = 'grammar.txt';
810 }
811 local($CURRENT_GRAMMAR) = $lang;
812 $DefinedGrammars{$lang} .= $_;
813 return ("<dl><dd class=\"grammar\">\n"
814 . "<div class=\"productions\">\n"
Fred Drake5d93eef2004-11-10 17:02:43 +0000815 . "<table>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000816 . translate_commands(translate_environments($_))
817 . "</table>\n"
818 . "</div>\n"
819 . (($lang eq '*')
820 ? ''
821 : ("<a class=\"grammar-footer\"\n"
822 . " href=\"$filename\" type=\"text/plain\"\n"
823 . " >Download entire grammar as text.</a>\n"))
824 . "</dd></dl>");
825}
826
827sub do_cmd_production{
828 local($_) = @_;
829 my $token = next_argument();
830 my $defn = next_argument();
831 my $lang = $CURRENT_GRAMMAR;
832 local($CURRENT_TOKEN) = $token;
833 if ($lang eq '*') {
Fred Drake5d93eef2004-11-10 17:02:43 +0000834 return ("<tr>\n"
835 . " <td>$token</td>\n"
836 . " <td>::=</td>\n"
837 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000838 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000839 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000840 . $_);
841 }
842 my $target;
843 if ($lang eq '') {
844 $target = "$CURRENT_FILE\#tok-$token";
845 }
846 else {
847 $target = "$CURRENT_FILE\#tok-$lang-$token";
848 }
849 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drake5d93eef2004-11-10 17:02:43 +0000850 return ("<tr>\n"
851 . " <td><a id='tok-$token' xml:id='tok-$token'>"
852 . "$token</a></td>\n"
853 . " <td>::=</td>\n"
854 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000855 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000856 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000857 . $_);
858}
859
Fred Drake53815882002-03-15 23:21:37 +0000860sub do_cmd_productioncont{
861 local($_) = @_;
862 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000863 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake5d93eef2004-11-10 17:02:43 +0000864 return ("<tr>\n"
865 . " <td></td>\n"
866 . " <td></td>\n"
Fred Drake53815882002-03-15 23:21:37 +0000867 . " <td><code>"
868 . translate_commands($defn)
869 . "</code></td></tr>"
870 . $_);
871}
872
Fred Drakef5478632002-05-23 17:59:16 +0000873sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000874 my $lang;
875 my $filename;
876 local($_);
877 print "process_grammar_files()\n";
878 foreach $lang (keys %DefinedGrammars) {
879 $filename = "grammar-$lang.txt";
880 if ($lang eq '*') {
881 next;
882 }
883 if ($lang eq '') {
884 $filename = 'grammar.txt';
885 }
886 open(GRAMMAR, ">$filename") || die "\n$!\n";
887 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
888 close(GRAMMAR);
889 print "Wrote grammar file $filename\n";
890 }
891 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
892 foreach $filename (keys %BackpatchGrammarFiles) {
893 print "\nBack-patching grammar links in $filename\n";
894 my $buffer;
895 open(GRAMMAR, "<$filename") || die "\n$!\n";
896 # read all of the file into the buffer
897 sysread(GRAMMAR, $buffer, 1024*1024);
898 close(GRAMMAR);
899 while ($buffer =~ /$PATTERN/) {
900 my($lang, $token) = ($1, $2);
901 my $target = $TokenToTargetMapping{"$lang:$token"};
902 my $source = "<pyGrammarToken><$lang><$token>";
903 $buffer =~ s/$source/$target/g;
904 }
905 open(GRAMMAR, ">$filename") || die "\n$!\n";
906 print GRAMMAR $buffer;
907 close(GRAMMAR);
908 }
909}
910
Fred Drakef5478632002-05-23 17:59:16 +0000911sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000912 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000913 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000914 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
915 s/\\token(<<\d+>>)(.+)\1/$2/g;
916 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000917 s/<<\d+>>//g;
918 s/;SPMgt;/>/g;
919 s/;SPMlt;/</g;
920 s/;SPMquot;/\"/g;
921 return $_;
922}
923
924
Fred Drakee15956b2000-04-03 04:51:13 +0000925$REFCOUNTS_LOADED = 0;
926
Fred Drakef5478632002-05-23 17:59:16 +0000927sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000928 $REFCOUNTS_LOADED = 1;
929
Fred Drake49b33fa2002-11-15 19:04:10 +0000930 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000931 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000932 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000933 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000934 $mydir = getcwd() . "$dd$mydir"
935 unless $mydir =~ s|^/|/|;
936 local $_;
937 my $filename = "$mydir${dd}api${dd}refcounts.dat";
938 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
939 print "[loading API refcount data]";
940 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000941 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000942 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
943 #print "\n$func($param) --> $count";
944 $REFCOUNTS{"$func:$param"} = $count;
945 }
946 }
947}
948
Fred Drakef5478632002-05-23 17:59:16 +0000949sub get_refcount($$){
950 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000951 load_refcounts()
952 unless $REFCOUNTS_LOADED;
953 return $REFCOUNTS{"$func:$param"};
954}
955
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000956
957$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000958$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000959
Fred Drakef5478632002-05-23 17:59:16 +0000960sub cfuncline_helper($$$){
961 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000962 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000963 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000964 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000965 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000966 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
967 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000968 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
969 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
970 . "<td>$args)</td>"
971 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000972}
973sub do_cmd_cfuncline{
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 return "<dt>$siginfo\n<dd>" . $_;
980}
981sub do_env_cfuncdesc{
982 local($_) = @_;
983 my $type = next_argument();
984 my $name = next_argument();
985 my $args = next_argument();
986 my $siginfo = cfuncline_helper($type, $name, $args);
987 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000988 my $rcinfo = '';
989 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000990 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000991 }
992 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000993 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000994 }
Fred Drakec2578c52000-04-10 18:26:45 +0000995 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000996 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000997 }
Fred Drakee15956b2000-04-03 04:51:13 +0000998 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000999 $rcinfo = ( "\n<div class=\"refcount-info\">"
1000 . "\n <span class=\"label\">Return value:</span>"
1001 . "\n <span class=\"value\">$rcinfo.</span>"
1002 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +00001003 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001004 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001005 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001006 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001007 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001008}
1009
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001010sub do_cmd_cmemberline{
1011 local($_) = @_;
1012 my $container = next_argument();
1013 my $type = next_argument();
1014 my $name = next_argument();
1015 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001016 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001017 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001018 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001019 . $_;
1020}
1021sub do_env_cmemberdesc{
1022 local($_) = @_;
1023 my $container = next_argument();
1024 my $type = next_argument();
1025 my $name = next_argument();
1026 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001027 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001028 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001029 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001030 . $_
1031 . '</dl>';
1032}
1033
Fred Drakee15956b2000-04-03 04:51:13 +00001034sub do_env_csimplemacrodesc{
1035 local($_) = @_;
1036 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001037 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001038 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001039 . $_
1040 . '</dl>'
1041}
1042
Fred Drake6659c301998-03-03 22:02:19 +00001043sub do_env_ctypedesc{
1044 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001045 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001046 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001047 $index_name = $type_name
1048 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001049 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001050 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001051 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1052 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001053 . $_
1054 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001055}
1056
1057sub do_env_cvardesc{
1058 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001059 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001060 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001061 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001062 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001063 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001064 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001065 . '<dd>'
1066 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001067 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001068}
1069
Fred Drake3cdb89d2000-09-14 20:17:23 +00001070sub convert_args($){
1071 local($IN_DESC_HANDLER) = 1;
1072 local($_) = @_;
1073 return translate_commands($_);
1074}
1075
Fred Drakef6e90272002-06-18 18:24:16 +00001076sub funcline_helper($$$){
1077 my($first, $idxitem, $arglist) = @_;
1078 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001079 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1080 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001081 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001082}
1083
Fred Drake6659c301998-03-03 22:02:19 +00001084sub do_env_funcdesc{
1085 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001086 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001087 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001088 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1089 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001090 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001091 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001092 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001093 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001094}
1095
1096sub do_env_funcdescni{
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 Drakef6e90272002-06-18 18:24:16 +00001100 my $prefix = "<tt class=\"function\">$function_name</tt>";
1101 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001102}
1103
1104sub do_cmd_funcline{
1105 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001106 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001107 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001108 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001109 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1110 $prefix =~ s/\(\)//;
1111
Fred Drakef6e90272002-06-18 18:24:16 +00001112 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001113}
1114
Fred Drake6b3fb781999-07-12 16:50:09 +00001115sub do_cmd_funclineni{
1116 local($_) = @_;
1117 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001118 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001119 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001120
Fred Drakef6e90272002-06-18 18:24:16 +00001121 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001122}
1123
Fred Drake6659c301998-03-03 22:02:19 +00001124# Change this flag to index the opcode entries. I don't think it's very
1125# useful to index them, since they're only presented to describe the dis
1126# module.
1127#
1128$INDEX_OPCODES = 0;
1129
1130sub do_env_opcodedesc{
1131 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001132 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001133 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001134 my $idx;
1135 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001136 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001137 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001138 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001139 }
1140 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001141 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001142 }
1143 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001144 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001145 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001146 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001147 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001148}
1149
1150sub do_env_datadesc{
1151 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001152 my $dataname = next_argument();
1153 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001154 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001155 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001156 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001157 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001158}
1159
1160sub do_env_datadescni{
1161 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001162 my $idx = next_argument();
1163 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001164 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001165 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001166 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001167}
1168
1169sub do_cmd_dataline{
1170 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001171 my $data_name = next_argument();
1172 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001173 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001174 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001175}
1176
Fred Drakeadb272c2000-04-10 17:47:14 +00001177sub do_cmd_datalineni{
1178 local($_) = @_;
1179 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001180 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001181}
1182
Fred Drake42b31a51998-03-27 05:16:10 +00001183sub do_env_excdesc{
1184 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001185 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001186 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001187 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001188 . "\n<dd>"
1189 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001190 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001191}
1192
Fred Drake62e43691998-08-10 19:40:44 +00001193sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001194
1195
Fred Drakef5478632002-05-23 17:59:16 +00001196sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001197 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001198 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001199 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001200 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001201 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001202 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001203 my $prefix = "$TLSTART$what$TLEND$idx";
1204 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001205}
1206
Fred Drake643d76d2000-09-09 06:07:37 +00001207sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001208 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001209}
1210
Fred Drake06a01e82001-05-11 01:00:30 +00001211sub do_env_classdescstar{
1212 local($_) = @_;
1213 $THIS_CLASS = next_argument();
1214 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001215 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001216 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001217 my $prefix = "${TLSTART}class$TLEND$idx";
1218 # Can't use funcline_helper() since there is no args list.
1219 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001220}
1221
Fred Drake643d76d2000-09-09 06:07:37 +00001222sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001223 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001224}
1225
Fred Drake42b31a51998-03-27 05:16:10 +00001226
1227sub do_env_methoddesc{
1228 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001229 my $class_name = next_optional_argument();
1230 $class_name = $THIS_CLASS
1231 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001232 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001233 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001234 my $extra = '';
1235 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001236 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001237 }
Fred Drakef1927a62001-06-20 21:29:30 +00001238 my $idx = make_str_index_entry(
1239 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001240 $idx =~ s/ \(.*\)//;
1241 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001242 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001243}
1244
1245
Fred Drake7d45f6d1999-01-05 14:39:27 +00001246sub do_cmd_methodline{
1247 local($_) = @_;
1248 my $class_name = next_optional_argument();
1249 $class_name = $THIS_CLASS
1250 unless $class_name;
1251 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001252 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001253 my $extra = '';
1254 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001255 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001256 }
Fred Drakef1927a62001-06-20 21:29:30 +00001257 my $idx = make_str_index_entry(
1258 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001259 $idx =~ s/ \(.*\)//;
1260 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001261 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001262}
1263
1264
Fred Draked64a40d1998-09-10 18:59:13 +00001265sub do_cmd_methodlineni{
1266 local($_) = @_;
1267 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(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001271}
1272
Fred Drake42b31a51998-03-27 05:16:10 +00001273sub do_env_methoddescni{
1274 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001275 next_optional_argument();
1276 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001277 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001278 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001279}
1280
1281
1282sub do_env_memberdesc{
1283 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001284 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001285 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001286 $class = $THIS_CLASS
1287 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001288 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001289 $extra = " ($class attribute)"
1290 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001291 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001292 $idx =~ s/ \(.*\)//;
1293 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001294 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001295}
1296
1297
Fred Drake5ccf3301998-04-17 20:04:09 +00001298sub do_cmd_memberline{
1299 local($_) = @_;
1300 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001301 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001302 $class = $THIS_CLASS
1303 unless $class;
1304 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001305 $extra = " ($class attribute)"
1306 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001307 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001308 $idx =~ s/ \(.*\)//;
1309 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001310 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001311}
1312
Fred Drakef269e592001-07-17 23:05:57 +00001313
Fred Drake42b31a51998-03-27 05:16:10 +00001314sub do_env_memberdescni{
1315 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001316 next_optional_argument();
1317 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001318 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001319 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001320 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001321}
1322
1323
Fred Drake5ccf3301998-04-17 20:04:09 +00001324sub do_cmd_memberlineni{
1325 local($_) = @_;
1326 next_optional_argument();
1327 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001328 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001329}
1330
Fred Drakef269e592001-07-17 23:05:57 +00001331
Fred Drake9e927f12004-11-10 15:49:25 +00001332# For tables, we include a class on every cell to allow the CSS to set
1333# the text-align property; this is because support for styling columns
1334# via the <col> element appears nearly non-existant on even the latest
1335# browsers (Mozilla 1.7 is stable at the time of this writing).
1336# Hopefully this can be improved as browsers evolve.
1337
Fred Drakef269e592001-07-17 23:05:57 +00001338@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001339
Fred Drakecb199762001-08-16 21:56:24 +00001340%FontConversions = ('cdata' => 'tt class="cdata"',
1341 'character' => 'tt class="character"',
1342 'class' => 'tt class="class"',
1343 'command' => 'code',
1344 'constant' => 'tt class="constant"',
1345 'exception' => 'tt class="exception"',
1346 'file' => 'tt class="file"',
1347 'filenq' => 'tt class="file"',
1348 'kbd' => 'kbd',
1349 'member' => 'tt class="member"',
1350 'programopt' => 'b',
1351 'textrm' => '',
1352 );
1353
Fred Drakef5478632002-05-23 17:59:16 +00001354sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001355 # do a little magic on a font name to get the right behavior in the first
1356 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001357 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001358 if (defined $FontConversions{$font}) {
1359 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001360 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001361 return $font;
1362}
1363
Fred Drakef5478632002-05-23 17:59:16 +00001364sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001365 my $a = $_[0];
1366 if (!defined $a) {
1367 return '';
1368 }
Fred Drakee15956b2000-04-03 04:51:13 +00001369 my $mark = substr($a, 0, 1);
1370 my $r = '';
1371 if ($mark eq 'c')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001372 { $r = ' class="center"'; }
Fred Drakee15956b2000-04-03 04:51:13 +00001373 elsif ($mark eq 'r')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001374 { $r = ' class="right" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001375 elsif ($mark eq 'l')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001376 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001377 elsif ($mark eq 'p')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001378 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001379 return $r;
1380}
1381
Fred Drakef5478632002-05-23 17:59:16 +00001382sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001383 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001384 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001385 my $a1 = figure_column_alignment($s1);
1386 my $a2 = figure_column_alignment($s2);
1387 my $a3 = figure_column_alignment($s3);
1388 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001389 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001390 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1391 $col_aligns[1] = "<td$a2>";
1392 $col_aligns[2] = "<td$a3>";
1393 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001394 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001395 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001396 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001397}
1398
Fred Drakef5478632002-05-23 17:59:16 +00001399sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001400 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001401 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001402 if ($font) {
1403 $sfont = "<$font>";
1404 $efont = "</$font>";
1405 $efont =~ s/ .*>/>/;
1406 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001407 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001408}
1409
1410sub do_env_tableii{
1411 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001412 my $arg = next_argument();
1413 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001414 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001415 my $h1 = next_argument();
1416 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001417 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001418 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001419 my $a1 = $col_aligns[0];
1420 my $a2 = $col_aligns[1];
1421 s/\\lineii</\\lineii[$a1|$a2]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001422 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001423 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001424 . "\n <tr>"
1425 . "\n $th1$h1</th>"
1426 . "\n $th2$h2</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001427 . "\n </tr>"
1428 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001429 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001430 . $_
1431 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001432 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001433}
1434
Fred Drakeda72b932000-09-21 15:58:02 +00001435sub do_env_longtableii{
1436 return do_env_tableii(@_);
1437}
1438
Fred Drake6659c301998-03-03 22:02:19 +00001439sub do_cmd_lineii{
1440 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001441 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001442 my $c1 = next_argument();
1443 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001444 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001445 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001446 my($c1align, $c2align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001447 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1448 . " $c2align$c2</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001449 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001450}
1451
1452sub do_env_tableiii{
1453 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001454 my $arg = next_argument();
1455 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001456 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001457 my $h1 = next_argument();
1458 my $h2 = next_argument();
1459 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001460 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001461 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001462 my $a1 = $col_aligns[0];
1463 my $a2 = $col_aligns[1];
1464 my $a3 = $col_aligns[2];
1465 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001466 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001467 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001468 . "\n <tr>"
1469 . "\n $th1$h1</th>"
1470 . "\n $th2$h2</th>"
1471 . "\n $th3$h3</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001472 . "\n </tr>"
1473 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001474 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001475 . $_
1476 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001477 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001478}
1479
Fred Drakeda72b932000-09-21 15:58:02 +00001480sub do_env_longtableiii{
1481 return do_env_tableiii(@_);
1482}
1483
Fred Drake6659c301998-03-03 22:02:19 +00001484sub do_cmd_lineiii{
1485 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001486 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001487 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001488 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001489 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001490 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001491 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001492 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001493 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001494 . " $c2align$c2</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001495 . " $c3align$c3</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001496 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001497}
1498
Fred Drakea0f4c941998-07-24 22:16:04 +00001499sub do_env_tableiv{
1500 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001501 my $arg = next_argument();
1502 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001503 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001504 my $h1 = next_argument();
1505 my $h2 = next_argument();
1506 my $h3 = next_argument();
1507 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001508 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001509 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001510 my $a1 = $col_aligns[0];
1511 my $a2 = $col_aligns[1];
1512 my $a3 = $col_aligns[2];
1513 my $a4 = $col_aligns[3];
1514 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001515 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001516 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001517 . "\n <tr>"
1518 . "\n $th1$h1</th>"
1519 . "\n $th2$h2</th>"
1520 . "\n $th3$h3</th>"
1521 . "\n $th4$h4</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001522 . "\n </tr>"
1523 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001524 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001525 . $_
1526 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001527 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001528}
1529
Fred Drakeda72b932000-09-21 15:58:02 +00001530sub do_env_longtableiv{
1531 return do_env_tableiv(@_);
1532}
1533
Fred Drakea0f4c941998-07-24 22:16:04 +00001534sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001535 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001536 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001537 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001538 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001539 my $c3 = next_argument();
1540 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001541 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001542 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001543 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001544 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001545 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001546 . " $c3align$c3</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001547 . " $c4align$c4</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001548 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001549}
1550
Fred Drakef269e592001-07-17 23:05:57 +00001551sub do_env_tablev{
1552 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001553 my $arg = next_argument();
1554 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001555 my $font = fix_font(next_argument());
1556 my $h1 = next_argument();
1557 my $h2 = next_argument();
1558 my $h3 = next_argument();
1559 my $h4 = next_argument();
1560 my $h5 = next_argument();
1561 s/[\s\n]+//;
1562 $globals{'lineifont'} = $font;
1563 my $a1 = $col_aligns[0];
1564 my $a2 = $col_aligns[1];
1565 my $a3 = $col_aligns[2];
1566 my $a4 = $col_aligns[3];
1567 my $a5 = $col_aligns[4];
1568 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001569 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001570 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001571 . "\n <tr>"
1572 . "\n $th1$h1</th>"
1573 . "\n $th2$h2</th>"
1574 . "\n $th3$h3</th>"
1575 . "\n $th4$h4</th>"
1576 . "\n $th5$h5</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001577 . "\n </tr>"
1578 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001579 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001580 . $_
1581 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001582 . "\n</table></div>";
Fred Drakef269e592001-07-17 23:05:57 +00001583}
1584
1585sub do_env_longtablev{
1586 return do_env_tablev(@_);
1587}
1588
1589sub do_cmd_linev{
1590 local($_) = @_;
1591 my $aligns = next_optional_argument();
1592 my $c1 = next_argument();
1593 my $c2 = next_argument();
1594 my $c3 = next_argument();
1595 my $c4 = next_argument();
1596 my $c5 = next_argument();
1597 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001598 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001599 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001600 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef269e592001-07-17 23:05:57 +00001601 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001602 . " $c3align$c3</td>\n"
1603 . " $c4align$c4</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001604 . " $c5align$c5</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001605 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001606}
1607
Fred Drake3be20742000-08-31 06:22:54 +00001608
1609# These can be used to control the title page appearance;
1610# they need a little bit of documentation.
1611#
1612# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1613# $ICONSERVER directory, or include path information (other than "./"). The
1614# default image type will be assumed if an extension is not provided.
1615#
1616# If specified, the "title page" will contain two colums: one containing the
1617# title/author/etc., and the other containing the graphic. Use the other
1618# four variables listed here to control specific details of the layout; all
1619# are optional.
1620#
1621# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1622# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1623# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1624# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1625# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1626
Fred Drakef5478632002-05-23 17:59:16 +00001627sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001628 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001629 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001630 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001631 }
1632 else {
1633 write_warnings("\nThis document has no title.");
1634 }
Fred Drake6659c301998-03-03 22:02:19 +00001635 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001636 if ($t_authorURL) {
1637 my $href = translate_commands($t_authorURL);
1638 $href = make_named_href('author', $href,
1639 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001640 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001641 $the_title .= "\n<p>$href</p>";
1642 }
Fred Drake3be20742000-08-31 06:22:54 +00001643 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001644 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001645 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001646 }
Fred Drake3be20742000-08-31 06:22:54 +00001647 }
1648 else {
1649 write_warnings("\nThere is no author for this document.");
1650 }
Fred Drake6659c301998-03-03 22:02:19 +00001651 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001652 $the_title .= "\n<p>$t_institute</p>";
1653 }
Fred Draked07868a1998-05-14 21:00:28 +00001654 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001655 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1656 }
Fred Drake6659c301998-03-03 22:02:19 +00001657 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001658 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001659 }
Fred Drake6659c301998-03-03 22:02:19 +00001660 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001661 $the_title .= "\n<p>";
1662 if ($PACKAGE_VERSION) {
1663 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001664 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001665 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001666 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001667 }
1668 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001669 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001670 }
1671 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001672 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001673 }
Fred Drake6659c301998-03-03 22:02:19 +00001674 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001675 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001676 }
1677 return $the_title;
1678}
1679
Fred Drakef5478632002-05-23 17:59:16 +00001680sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001681 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001682 my $graphic = "<td class=\"titlegraphic\"";
1683 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1684 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1685 $graphic .= "><img";
1686 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1687 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1688 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1689 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001690 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001691 return $graphic;
1692}
1693
Fred Drakef5478632002-05-23 17:59:16 +00001694sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001695 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001696 my $the_title = "\n";
1697 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001698 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001699 # body), but I don't see any other way to get this generated
1700 # at all. Browsers like Mozilla, that support navigation
1701 # links, can make use of this.
1702 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1703 . ($EXTERNAL_UP_TITLE
1704 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001705 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001706 }
1707 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001708 if ($TITLE_PAGE_GRAPHIC) {
1709 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1710 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1711 . "<tr align=\"right\">\n<td>"
1712 . make_my_titlepage()
1713 . "</td>\n"
1714 . make_my_titlegraphic()
1715 . "</tr>\n</table>");
1716 }
1717 else {
1718 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1719 . make_my_titlegraphic()
1720 . "<td>"
1721 . make_my_titlepage()
1722 . "</td></tr>\n</table>");
1723 }
1724 }
1725 else {
Fred Drake0a3c8182004-11-10 19:22:05 +00001726 $the_title .= ("\n<div class='center'>"
Fred Drake3be20742000-08-31 06:22:54 +00001727 . make_my_titlepage()
Fred Drake0a3c8182004-11-10 19:22:05 +00001728 . "\n</div>");
Fred Drake3be20742000-08-31 06:22:54 +00001729 }
1730 $the_title .= "\n</div>";
1731 return $the_title . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001732}
1733
1734
Fred Drake885215c1998-05-20 21:32:09 +00001735#
Fred Drakea0f4c941998-07-24 22:16:04 +00001736# Module synopsis support
1737#
1738
1739require SynopsisTable;
1740
Fred Drakef7685d71998-07-25 03:31:46 +00001741sub get_chapter_id(){
1742 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001743 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001744 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001745 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001746}
1747
Fred Drake643d76d2000-09-09 06:07:37 +00001748# 'chapter' => 'SynopsisTable instance'
1749%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001750
1751sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001752 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001753 my $key;
1754 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001755 if ($key eq $chap) {
1756 return $ModuleSynopses{$chap};
1757 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001758 }
Fred Drake643d76d2000-09-09 06:07:37 +00001759 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001760 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001761 return $st;
1762}
1763
Fred Drake62e43691998-08-10 19:40:44 +00001764sub do_cmd_moduleauthor{
1765 local($_) = @_;
1766 next_argument();
1767 next_argument();
1768 return $_;
1769}
1770
1771sub do_cmd_sectionauthor{
1772 local($_) = @_;
1773 next_argument();
1774 next_argument();
1775 return $_;
1776}
1777
Fred Drakea0f4c941998-07-24 22:16:04 +00001778sub do_cmd_declaremodule{
1779 local($_) = @_;
1780 my $key = next_optional_argument();
1781 my $type = next_argument();
1782 my $name = next_argument();
1783 my $st = get_synopsis_table(get_chapter_id());
1784 #
1785 $key = $name unless $key;
1786 $type = 'built-in' if $type eq 'builtin';
1787 $st->declare($name, $key, $type);
1788 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001789 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001790}
1791
1792sub do_cmd_modulesynopsis{
1793 local($_) = @_;
1794 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001795 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001796 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001797}
1798
1799sub do_cmd_localmoduletable{
1800 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001801 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001802 my $st = get_synopsis_table($chap);
1803 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001804 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001805}
1806
Fred Drakef5478632002-05-23 17:59:16 +00001807sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001808 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001809 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001810 my $st = $ModuleSynopses{$key};
1811 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001812 if ($file) {
1813 process_localmoduletables_in_file($file);
1814 }
1815 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001816 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001817 }
1818 }
1819}
1820
Fred Drakef5478632002-05-23 17:59:16 +00001821sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001822 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001823 open(MYFILE, "<$file");
1824 local($_);
1825 sysread(MYFILE, $_, 1024*1024);
1826 close(MYFILE);
1827 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001828 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001829 my $match = $&;
1830 my $chap = $1;
1831 my $st = get_synopsis_table($chap);
1832 my $data = $st->tohtml();
1833 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001834 }
Fred Drake643d76d2000-09-09 06:07:37 +00001835 open(MYFILE,">$file");
1836 print MYFILE $_;
1837 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001838}
Fred Drakef5478632002-05-23 17:59:16 +00001839sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001840 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001841 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001842}
Fred Drakea0f4c941998-07-24 22:16:04 +00001843
1844
1845#
1846# "See also:" -- references placed at the end of a \section
1847#
1848
1849sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001850 return ("<div class=\"seealso\">\n "
Fred Drake0cf87be2004-11-10 08:08:26 +00001851 . "<p class=\"heading\">See Also:</p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001852 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001853 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001854}
1855
Fred Drake5ed35fd2001-11-30 18:09:54 +00001856sub do_env_seealsostar{
1857 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001858 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001859 . '</div>');
1860}
1861
Fred Drakea0f4c941998-07-24 22:16:04 +00001862sub do_cmd_seemodule{
1863 # Insert the right magic to jump to the module definition. This should
1864 # work most of the time, at least for repeat builds....
1865 local($_) = @_;
1866 my $key = next_optional_argument();
1867 my $module = next_argument();
1868 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001869 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001870 $key = $module
1871 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001872 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001873 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001874 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001875 return ('<dl compact="compact" class="seemodule">'
Fred Drakef1927a62001-06-20 21:29:30 +00001876 . "\n <dt>Module <b><tt class=\"module\">"
1877 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1878 . "\n <dd>$text$period\n </dl>"
1879 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001880}
1881
Fred Drakee0197bf2001-04-12 04:03:22 +00001882sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001883 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001884 my $s = "$str";
1885 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1886 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1887 return $s;
1888}
1889
Fred Drakef5478632002-05-23 17:59:16 +00001890sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001891 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001892 my $rfcnum = next_argument();
1893 my $title = next_argument();
1894 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001895 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001896 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001897 my $attrtitle = strip_html_markup($title);
Fred Draked7a5bca2004-11-10 08:07:00 +00001898 return '<dl compact="compact" class="seerfc">'
Fred Drake37cc0c02000-04-26 18:05:24 +00001899 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001900 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001901 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001902 . "\n <dd>$text\n </dl>"
1903 . $_;
1904}
1905
Fred Drake643d76d2000-09-09 06:07:37 +00001906sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001907 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001908}
1909
1910sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001911 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001912 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001913}
1914
Fred Drake48449982000-09-12 17:52:33 +00001915sub do_cmd_seetitle{
1916 local($_) = @_;
1917 my $url = next_optional_argument();
1918 my $title = next_argument();
1919 my $text = next_argument();
1920 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001921 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001922 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001923 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001924 . "\n >$title$icon</a></em></dt>"
1925 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001926 . $_;
1927 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001928 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001929 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001930 . "\n >$title</em></dt>"
1931 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001932 . $_;
1933}
1934
Fred Drake4f687b32004-01-08 14:57:27 +00001935sub do_cmd_seelink{
1936 local($_) = @_;
1937 my $url = next_argument();
1938 my $linktext = next_argument();
1939 my $text = next_argument();
1940 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001941 return '<dl compact="compact" class="seeurl">'
Fred Drake4f687b32004-01-08 14:57:27 +00001942 . "\n <dt><a href='$url'"
1943 . "\n >$linktext$icon</a></dt>"
1944 . "\n <dd>$text</dd>\n </dl>"
1945 . $_;
1946}
1947
Fred Drakeef4d1112000-05-09 16:17:51 +00001948sub do_cmd_seeurl{
1949 local($_) = @_;
1950 my $url = next_argument();
1951 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001952 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001953 return '<dl compact="compact" class="seeurl">'
Fred Drakeef4d1112000-05-09 16:17:51 +00001954 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001955 . "\n class=\"url\">$url$icon</a></dt>"
1956 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001957 . $_;
1958}
1959
Fred Drakea0f4c941998-07-24 22:16:04 +00001960sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001961 local($_) = @_;
1962 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001963 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001964}
1965
1966
1967#
Fred Drake885215c1998-05-20 21:32:09 +00001968# Definition list support.
1969#
1970
1971sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001972 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001973}
1974
1975sub do_cmd_term{
1976 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001977 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001978 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001979 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001980 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001981}
1982
1983
Fred Drake4e72e052003-07-15 22:00:36 +00001984# Commands listed here have process-order dependencies; these often
1985# are related to indexing operations.
1986# XXX Not sure why funclineni, methodlineni, and samp are here.
1987#
Fred Drake2ff880e1999-02-05 18:31:29 +00001988process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001989declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001990funcline # {} # {}
1991funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001992memberline # [] # {}
1993methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001994methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001995modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001996bifuncindex # {}
1997exindex # {}
1998indexii # {} # {}
1999indexiii # {} # {} # {}
2000indexiv # {} # {} # {} # {}
2001kwindex # {}
2002obindex # {}
2003opindex # {}
2004stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002005platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002006samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002007setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002008withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002009_RAW_ARG_DEFERRED_CMDS_
2010
2011
Fred Drake8a5e6792002-04-15 18:41:31 +00002012$alltt_start = '<div class="verbatim"><pre>';
2013$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002014
Fred Drakef5478632002-05-23 17:59:16 +00002015sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002016 local ($_) = @_;
2017 local($closures,$reopens,@open_block_tags);
2018
2019 # get the tag-strings for all open tags
2020 local(@keep_open_tags) = @$open_tags_R;
2021 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2022
2023 # get the tags for text-level tags only
2024 $open_tags_R = [ @keep_open_tags ];
2025 local($local_closures, $local_reopens);
2026 ($local_closures, $local_reopens,@open_block_tags)
2027 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002028 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002029
2030 $open_tags_R = [ @open_block_tags ];
2031
2032 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002033 local($open_tags_R) = [ @open_block_tags ];
2034 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002035
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002036 local($cnt) = ++$global{'max_id'};
2037 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2038 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002039
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002040 $_ = &translate_environments($_);
2041 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002042
Fred Drake41aa0182003-09-05 15:43:00 +00002043 # remove spurious <BR> someone sticks in; not sure where they
2044 # actually come from
2045 # XXX the replacement space is there to accomodate something
2046 # broken that inserts a space in front of the first line of
2047 # the environment
2048 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002049
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002050 $_ = join('', $closures, $alltt_start, $local_reopens
2051 , $_
2052 , &balance_tags() #, $local_closures
2053 , $alltt_end, $reopens);
2054 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002055 };
2056 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002057 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002058}
2059
Fred Drake8effa012004-04-01 04:30:29 +00002060# List of all filenames produced by do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002061%VerbatimFiles = ();
2062@VerbatimOutputs = ();
2063
2064sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002065 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002066 #
2067 # Re-write the source filename to always use a .txt extension
2068 # so that Web servers will present it as text/plain. This is
2069 # needed since there is no other even moderately reliable way
2070 # to get the right Content-Type header on text files for
2071 # servers which we can't configure (like python.org mirrors).
2072 #
2073 if (defined $VerbatimFiles{$file}) {
2074 # We've seen this one before; re-use the same output file.
2075 return $VerbatimFiles{$file};
2076 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002077 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002078 $filename = "$srcname.txt";
2079 #
2080 # We need to determine if our default filename is already
2081 # being used, and find a new one it it is. If the name is in
2082 # used, this algorithm will first attempt to include the
2083 # source extension as part of the name, and if that is also in
2084 # use (if the same file is included multiple times, or if
2085 # another source file has that as the base name), a counter is
2086 # used instead.
2087 #
2088 my $found = 1;
2089 FIND:
2090 while ($found) {
2091 foreach $fn (@VerbatimOutputs) {
2092 if ($fn eq $filename) {
2093 if ($found == 1) {
2094 $srcext =~ s/^[.]//; # Remove '.' from extension
2095 $filename = "$srcname-$srcext.txt";
2096 }
2097 else {
2098 $filename = "$srcname-$found.txt";
2099 }
2100 ++$found;
2101 next FIND;
2102 }
2103 }
2104 $found = 0;
2105 }
2106 push @VerbatimOutputs, $filename;
2107 $VerbatimFiles{$file} = $filename;
2108 return $filename;
2109}
2110
Fred Drake57e52ef2001-06-15 21:31:57 +00002111sub do_cmd_verbatiminput{
2112 local($_) = @_;
2113 my $fname = next_argument();
2114 my $file;
2115 my $found = 0;
2116 my $texpath;
2117 # Search TEXINPUTS for the input file, the way we're supposed to:
2118 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2119 $file = "$texpath$dd$fname";
2120 last if ($found = (-f $file));
2121 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002122 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002123 my $text;
2124 if ($found) {
2125 open(MYFILE, "<$file") || die "\n$!\n";
2126 read(MYFILE, $text, 1024*1024);
2127 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002128 $filename = get_verbatim_output_name($file);
2129 # Now that we have a filename, write it out.
2130 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002131 print MYFILE $text;
2132 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002133 #
2134 # These rewrites convert the raw text to something that will
2135 # be properly visible as HTML and also will pass through the
2136 # vagaries of conversion through LaTeX2HTML. The order in
2137 # which the specific rewrites are performed is significant.
2138 #
2139 $text =~ s/\&/\&amp;/g;
2140 # These need to happen before the normal < and > re-writes,
2141 # since we need to avoid LaTeX2HTML's attempt to perform
2142 # ligature processing without regard to context (since it
2143 # doesn't have font information).
2144 $text =~ s/--/-&\#45;/g;
2145 $text =~ s/<</\&lt;\&\#60;/g;
2146 $text =~ s/>>/\&gt;\&\#62;/g;
2147 # Just normal re-writes...
2148 $text =~ s/</\&lt;/g;
2149 $text =~ s/>/\&gt;/g;
2150 # These last isn't needed for the HTML, but is needed to get
2151 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2152 # of &sol; since many browsers don't support that.
2153 $text =~ s/\\/\&\#92;/g;
2154 }
2155 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002156 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2157 }
2158 my $note = 'Download as text.';
2159 if ($file ne $filename) {
2160 $note = ('Download as text (original file name: <span class="file">'
2161 . $fname
2162 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002163 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002164 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002165 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002166 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002167 . "<a href=\"$filename\" type=\"text/plain\""
2168 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002169 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002170 . $_);
2171}
Fred Drake86333602001-04-10 17:13:39 +00002172
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021731; # This must be the last line