blob: e956e15f1da6c2588c5a7d4efbcf041c093a6259 [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 Drakeaf305b12004-11-11 08:05:34 +0000746 # This depends on the override of text_cleanup() in l2hinit.perl;
747 # if that function cleans out empty tags, the first three of these
748 # variables must be set to comments.
749 #
Fred Drake5d9c636f2003-08-05 05:00:23 +0000750 # Thanks to Dave Kuhlman for figuring why some named anchors were
751 # being lost.
Fred Drakeaf305b12004-11-11 08:05:34 +0000752 $anchor_invisible_mark = '';
753 $anchor_invisible_mark2 = '';
754 $anchor_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000755 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000756}
Fred Drake42b31a51998-03-27 05:16:10 +0000757init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000758
Fred Drakeab032151999-05-13 18:36:54 +0000759# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000760# instead of the dummy filler.
761#
Fred Drakef5478632002-05-23 17:59:16 +0000762sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000763 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000764 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000765 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000766 if ($str =~ /^<[a-z]+\b/) {
767 my $s = "$str";
Fred Drake0c1b2532004-10-29 19:47:52 +0000768 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
Fred Drake04bf7242003-11-26 20:55:49 +0000769 return $s;
770 }
771 else {
Fred Drake0c1b2532004-10-29 19:47:52 +0000772 return "<a id='$name' xml:id='$name'>$str</a>";
Fred Drake04bf7242003-11-26 20:55:49 +0000773 }
Fred Drake6659c301998-03-03 22:02:19 +0000774}
775
Fred Drake77602f22001-07-06 22:43:02 +0000776
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000777%TokenToTargetMapping = (); # language:token -> link target
778%DefinedGrammars = (); # language -> full grammar text
779%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000780
781sub do_cmd_token{
782 local($_) = @_;
783 my $token = next_argument();
784 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
785 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
786 # recursive definition or display-only productionlist
787 return "$token";
788 }
789 if ($target eq '') {
790 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
791 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
792 print "Adding '$CURRENT_FILE' to back-patch list.\n";
793 }
794 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
795 }
Fred Drake5d93eef2004-11-10 17:02:43 +0000796 return "<a class='grammartoken' href=\"$target\">$token</a>" . $_;
Fred Drake77602f22001-07-06 22:43:02 +0000797}
798
Fred Drake16bb4192001-08-20 21:36:38 +0000799sub do_cmd_grammartoken{
800 return do_cmd_token(@_);
801}
802
Fred Drake77602f22001-07-06 22:43:02 +0000803sub do_env_productionlist{
804 local($_) = @_;
805 my $lang = next_optional_argument();
806 my $filename = "grammar-$lang.txt";
807 if ($lang eq '') {
808 $filename = 'grammar.txt';
809 }
810 local($CURRENT_GRAMMAR) = $lang;
811 $DefinedGrammars{$lang} .= $_;
812 return ("<dl><dd class=\"grammar\">\n"
813 . "<div class=\"productions\">\n"
Fred Drake5d93eef2004-11-10 17:02:43 +0000814 . "<table>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000815 . translate_commands(translate_environments($_))
816 . "</table>\n"
817 . "</div>\n"
818 . (($lang eq '*')
819 ? ''
820 : ("<a class=\"grammar-footer\"\n"
821 . " href=\"$filename\" type=\"text/plain\"\n"
822 . " >Download entire grammar as text.</a>\n"))
823 . "</dd></dl>");
824}
825
826sub do_cmd_production{
827 local($_) = @_;
828 my $token = next_argument();
829 my $defn = next_argument();
830 my $lang = $CURRENT_GRAMMAR;
831 local($CURRENT_TOKEN) = $token;
832 if ($lang eq '*') {
Fred Drake5d93eef2004-11-10 17:02:43 +0000833 return ("<tr>\n"
834 . " <td>$token</td>\n"
835 . " <td>::=</td>\n"
836 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000837 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000838 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000839 . $_);
840 }
841 my $target;
842 if ($lang eq '') {
843 $target = "$CURRENT_FILE\#tok-$token";
844 }
845 else {
846 $target = "$CURRENT_FILE\#tok-$lang-$token";
847 }
848 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drake5d93eef2004-11-10 17:02:43 +0000849 return ("<tr>\n"
850 . " <td><a id='tok-$token' xml:id='tok-$token'>"
851 . "$token</a></td>\n"
852 . " <td>::=</td>\n"
853 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000854 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000855 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000856 . $_);
857}
858
Fred Drake53815882002-03-15 23:21:37 +0000859sub do_cmd_productioncont{
860 local($_) = @_;
861 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000862 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake5d93eef2004-11-10 17:02:43 +0000863 return ("<tr>\n"
864 . " <td></td>\n"
865 . " <td></td>\n"
Fred Drake53815882002-03-15 23:21:37 +0000866 . " <td><code>"
867 . translate_commands($defn)
868 . "</code></td></tr>"
869 . $_);
870}
871
Fred Drakef5478632002-05-23 17:59:16 +0000872sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000873 my $lang;
874 my $filename;
875 local($_);
876 print "process_grammar_files()\n";
877 foreach $lang (keys %DefinedGrammars) {
878 $filename = "grammar-$lang.txt";
879 if ($lang eq '*') {
880 next;
881 }
882 if ($lang eq '') {
883 $filename = 'grammar.txt';
884 }
885 open(GRAMMAR, ">$filename") || die "\n$!\n";
886 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
887 close(GRAMMAR);
888 print "Wrote grammar file $filename\n";
889 }
890 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
891 foreach $filename (keys %BackpatchGrammarFiles) {
892 print "\nBack-patching grammar links in $filename\n";
893 my $buffer;
894 open(GRAMMAR, "<$filename") || die "\n$!\n";
895 # read all of the file into the buffer
896 sysread(GRAMMAR, $buffer, 1024*1024);
897 close(GRAMMAR);
898 while ($buffer =~ /$PATTERN/) {
899 my($lang, $token) = ($1, $2);
900 my $target = $TokenToTargetMapping{"$lang:$token"};
901 my $source = "<pyGrammarToken><$lang><$token>";
902 $buffer =~ s/$source/$target/g;
903 }
904 open(GRAMMAR, ">$filename") || die "\n$!\n";
905 print GRAMMAR $buffer;
906 close(GRAMMAR);
907 }
908}
909
Fred Drakef5478632002-05-23 17:59:16 +0000910sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000911 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000912 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000913 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
914 s/\\token(<<\d+>>)(.+)\1/$2/g;
915 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000916 s/<<\d+>>//g;
917 s/;SPMgt;/>/g;
918 s/;SPMlt;/</g;
919 s/;SPMquot;/\"/g;
920 return $_;
921}
922
923
Fred Drakee15956b2000-04-03 04:51:13 +0000924$REFCOUNTS_LOADED = 0;
925
Fred Drakef5478632002-05-23 17:59:16 +0000926sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000927 $REFCOUNTS_LOADED = 1;
928
Fred Drake49b33fa2002-11-15 19:04:10 +0000929 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000930 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000931 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000932 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000933 $mydir = getcwd() . "$dd$mydir"
934 unless $mydir =~ s|^/|/|;
935 local $_;
936 my $filename = "$mydir${dd}api${dd}refcounts.dat";
937 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
938 print "[loading API refcount data]";
939 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000940 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000941 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
942 #print "\n$func($param) --> $count";
943 $REFCOUNTS{"$func:$param"} = $count;
944 }
945 }
946}
947
Fred Drakef5478632002-05-23 17:59:16 +0000948sub get_refcount($$){
949 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000950 load_refcounts()
951 unless $REFCOUNTS_LOADED;
952 return $REFCOUNTS{"$func:$param"};
953}
954
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000955
956$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000957$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000958
Fred Drakef5478632002-05-23 17:59:16 +0000959sub cfuncline_helper($$$){
960 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000961 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000962 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000963 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000964 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000965 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
966 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000967 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
968 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
969 . "<td>$args)</td>"
970 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000971}
972sub do_cmd_cfuncline{
973 local($_) = @_;
974 my $type = next_argument();
975 my $name = next_argument();
976 my $args = next_argument();
977 my $siginfo = cfuncline_helper($type, $name, $args);
978 return "<dt>$siginfo\n<dd>" . $_;
979}
980sub do_env_cfuncdesc{
981 local($_) = @_;
982 my $type = next_argument();
983 my $name = next_argument();
984 my $args = next_argument();
985 my $siginfo = cfuncline_helper($type, $name, $args);
986 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000987 my $rcinfo = '';
988 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000989 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000990 }
991 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000992 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000993 }
Fred Drakec2578c52000-04-10 18:26:45 +0000994 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000995 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000996 }
Fred Drakee15956b2000-04-03 04:51:13 +0000997 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000998 $rcinfo = ( "\n<div class=\"refcount-info\">"
999 . "\n <span class=\"label\">Return value:</span>"
1000 . "\n <span class=\"value\">$rcinfo.</span>"
1001 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +00001002 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001003 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001004 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001005 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001006 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001007}
1008
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001009sub do_cmd_cmemberline{
1010 local($_) = @_;
1011 my $container = next_argument();
1012 my $type = next_argument();
1013 my $name = next_argument();
1014 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001015 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001016 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001017 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001018 . $_;
1019}
1020sub do_env_cmemberdesc{
1021 local($_) = @_;
1022 my $container = next_argument();
1023 my $type = next_argument();
1024 my $name = next_argument();
1025 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001026 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001027 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001028 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001029 . $_
1030 . '</dl>';
1031}
1032
Fred Drakee15956b2000-04-03 04:51:13 +00001033sub do_env_csimplemacrodesc{
1034 local($_) = @_;
1035 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001036 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001037 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001038 . $_
1039 . '</dl>'
1040}
1041
Fred Drake6659c301998-03-03 22:02:19 +00001042sub do_env_ctypedesc{
1043 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001044 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001045 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001046 $index_name = $type_name
1047 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001048 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001049 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001050 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1051 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001052 . $_
1053 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001054}
1055
1056sub do_env_cvardesc{
1057 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001058 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001059 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001060 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001061 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001062 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001063 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001064 . '<dd>'
1065 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001066 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001067}
1068
Fred Drake3cdb89d2000-09-14 20:17:23 +00001069sub convert_args($){
1070 local($IN_DESC_HANDLER) = 1;
1071 local($_) = @_;
1072 return translate_commands($_);
1073}
1074
Fred Drakef6e90272002-06-18 18:24:16 +00001075sub funcline_helper($$$){
1076 my($first, $idxitem, $arglist) = @_;
1077 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001078 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1079 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001080 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001081}
1082
Fred Drake6659c301998-03-03 22:02:19 +00001083sub do_env_funcdesc{
1084 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001085 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001086 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001087 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1088 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001089 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001090 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001091 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001092 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001093}
1094
1095sub do_env_funcdescni{
1096 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001097 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001098 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001099 my $prefix = "<tt class=\"function\">$function_name</tt>";
1100 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001101}
1102
1103sub do_cmd_funcline{
1104 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001105 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001106 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001107 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001108 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1109 $prefix =~ s/\(\)//;
1110
Fred Drakef6e90272002-06-18 18:24:16 +00001111 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001112}
1113
Fred Drake6b3fb781999-07-12 16:50:09 +00001114sub do_cmd_funclineni{
1115 local($_) = @_;
1116 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001117 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001118 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001119
Fred Drakef6e90272002-06-18 18:24:16 +00001120 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001121}
1122
Fred Drake6659c301998-03-03 22:02:19 +00001123# Change this flag to index the opcode entries. I don't think it's very
1124# useful to index them, since they're only presented to describe the dis
1125# module.
1126#
1127$INDEX_OPCODES = 0;
1128
1129sub do_env_opcodedesc{
1130 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001131 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001132 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001133 my $idx;
1134 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001135 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001136 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001137 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001138 }
1139 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001140 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001141 }
1142 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001143 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001144 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001145 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001146 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001147}
1148
1149sub do_env_datadesc{
1150 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001151 my $dataname = next_argument();
1152 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001153 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001154 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001155 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001156 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001157}
1158
1159sub do_env_datadescni{
1160 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001161 my $idx = next_argument();
1162 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001163 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001164 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001165 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001166}
1167
1168sub do_cmd_dataline{
1169 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001170 my $data_name = next_argument();
1171 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001172 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001173 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001174}
1175
Fred Drakeadb272c2000-04-10 17:47:14 +00001176sub do_cmd_datalineni{
1177 local($_) = @_;
1178 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001179 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001180}
1181
Fred Drake42b31a51998-03-27 05:16:10 +00001182sub do_env_excdesc{
1183 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001184 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001185 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001186 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001187 . "\n<dd>"
1188 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001189 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001190}
1191
Fred Drake62e43691998-08-10 19:40:44 +00001192sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001193
1194
Fred Drakef5478632002-05-23 17:59:16 +00001195sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001196 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001197 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001198 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001199 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001200 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001201 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001202 my $prefix = "$TLSTART$what$TLEND$idx";
1203 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001204}
1205
Fred Drake643d76d2000-09-09 06:07:37 +00001206sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001207 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001208}
1209
Fred Drake06a01e82001-05-11 01:00:30 +00001210sub do_env_classdescstar{
1211 local($_) = @_;
1212 $THIS_CLASS = next_argument();
1213 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001214 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001215 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001216 my $prefix = "${TLSTART}class$TLEND$idx";
1217 # Can't use funcline_helper() since there is no args list.
1218 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001219}
1220
Fred Drake643d76d2000-09-09 06:07:37 +00001221sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001222 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001223}
1224
Fred Drake42b31a51998-03-27 05:16:10 +00001225
1226sub do_env_methoddesc{
1227 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001228 my $class_name = next_optional_argument();
1229 $class_name = $THIS_CLASS
1230 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001231 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001232 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001233 my $extra = '';
1234 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001235 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001236 }
Fred Drakef1927a62001-06-20 21:29:30 +00001237 my $idx = make_str_index_entry(
1238 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001239 $idx =~ s/ \(.*\)//;
1240 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001241 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001242}
1243
1244
Fred Drake7d45f6d1999-01-05 14:39:27 +00001245sub do_cmd_methodline{
1246 local($_) = @_;
1247 my $class_name = next_optional_argument();
1248 $class_name = $THIS_CLASS
1249 unless $class_name;
1250 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001251 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001252 my $extra = '';
1253 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001254 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001255 }
Fred Drakef1927a62001-06-20 21:29:30 +00001256 my $idx = make_str_index_entry(
1257 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001258 $idx =~ s/ \(.*\)//;
1259 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001260 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001261}
1262
1263
Fred Draked64a40d1998-09-10 18:59:13 +00001264sub do_cmd_methodlineni{
1265 local($_) = @_;
1266 next_optional_argument();
1267 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001268 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001269 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001270}
1271
Fred Drake42b31a51998-03-27 05:16:10 +00001272sub do_env_methoddescni{
1273 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001274 next_optional_argument();
1275 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001276 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001277 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001278}
1279
1280
1281sub do_env_memberdesc{
1282 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001283 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001284 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001285 $class = $THIS_CLASS
1286 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001287 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001288 $extra = " ($class attribute)"
1289 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001290 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001291 $idx =~ s/ \(.*\)//;
1292 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001293 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001294}
1295
1296
Fred Drake5ccf3301998-04-17 20:04:09 +00001297sub do_cmd_memberline{
1298 local($_) = @_;
1299 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001300 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001301 $class = $THIS_CLASS
1302 unless $class;
1303 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001304 $extra = " ($class attribute)"
1305 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001306 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001307 $idx =~ s/ \(.*\)//;
1308 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001309 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001310}
1311
Fred Drakef269e592001-07-17 23:05:57 +00001312
Fred Drake42b31a51998-03-27 05:16:10 +00001313sub do_env_memberdescni{
1314 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001315 next_optional_argument();
1316 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001317 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001318 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001319 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001320}
1321
1322
Fred Drake5ccf3301998-04-17 20:04:09 +00001323sub do_cmd_memberlineni{
1324 local($_) = @_;
1325 next_optional_argument();
1326 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001327 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001328}
1329
Fred Drakef269e592001-07-17 23:05:57 +00001330
Fred Drake9e927f12004-11-10 15:49:25 +00001331# For tables, we include a class on every cell to allow the CSS to set
1332# the text-align property; this is because support for styling columns
1333# via the <col> element appears nearly non-existant on even the latest
1334# browsers (Mozilla 1.7 is stable at the time of this writing).
1335# Hopefully this can be improved as browsers evolve.
1336
Fred Drakef269e592001-07-17 23:05:57 +00001337@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001338
Fred Drakecb199762001-08-16 21:56:24 +00001339%FontConversions = ('cdata' => 'tt class="cdata"',
1340 'character' => 'tt class="character"',
1341 'class' => 'tt class="class"',
1342 'command' => 'code',
1343 'constant' => 'tt class="constant"',
1344 'exception' => 'tt class="exception"',
1345 'file' => 'tt class="file"',
1346 'filenq' => 'tt class="file"',
1347 'kbd' => 'kbd',
1348 'member' => 'tt class="member"',
1349 'programopt' => 'b',
1350 'textrm' => '',
1351 );
1352
Fred Drakef5478632002-05-23 17:59:16 +00001353sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001354 # do a little magic on a font name to get the right behavior in the first
1355 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001356 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001357 if (defined $FontConversions{$font}) {
1358 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001359 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001360 return $font;
1361}
1362
Fred Drakef5478632002-05-23 17:59:16 +00001363sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001364 my $a = $_[0];
1365 if (!defined $a) {
1366 return '';
1367 }
Fred Drakee15956b2000-04-03 04:51:13 +00001368 my $mark = substr($a, 0, 1);
1369 my $r = '';
1370 if ($mark eq 'c')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001371 { $r = ' class="center"'; }
Fred Drakee15956b2000-04-03 04:51:13 +00001372 elsif ($mark eq 'r')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001373 { $r = ' class="right" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001374 elsif ($mark eq 'l')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001375 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001376 elsif ($mark eq 'p')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001377 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001378 return $r;
1379}
1380
Fred Drakef5478632002-05-23 17:59:16 +00001381sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001382 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001383 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001384 my $a1 = figure_column_alignment($s1);
1385 my $a2 = figure_column_alignment($s2);
1386 my $a3 = figure_column_alignment($s3);
1387 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001388 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001389 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1390 $col_aligns[1] = "<td$a2>";
1391 $col_aligns[2] = "<td$a3>";
1392 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001393 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001394 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001395 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001396}
1397
Fred Drakef5478632002-05-23 17:59:16 +00001398sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001399 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001400 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001401 if ($font) {
1402 $sfont = "<$font>";
1403 $efont = "</$font>";
1404 $efont =~ s/ .*>/>/;
1405 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001406 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001407}
1408
1409sub do_env_tableii{
1410 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001411 my $arg = next_argument();
1412 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001413 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001414 my $h1 = next_argument();
1415 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001416 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001417 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001418 my $a1 = $col_aligns[0];
1419 my $a2 = $col_aligns[1];
1420 s/\\lineii</\\lineii[$a1|$a2]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001421 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001422 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001423 . "\n <tr>"
1424 . "\n $th1$h1</th>"
1425 . "\n $th2$h2</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001426 . "\n </tr>"
1427 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001428 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001429 . $_
1430 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001431 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001432}
1433
Fred Drakeda72b932000-09-21 15:58:02 +00001434sub do_env_longtableii{
1435 return do_env_tableii(@_);
1436}
1437
Fred Drake6659c301998-03-03 22:02:19 +00001438sub do_cmd_lineii{
1439 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001440 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001441 my $c1 = next_argument();
1442 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001443 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001444 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001445 my($c1align, $c2align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001446 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1447 . " $c2align$c2</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001448 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001449}
1450
1451sub do_env_tableiii{
1452 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001453 my $arg = next_argument();
1454 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001455 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001456 my $h1 = next_argument();
1457 my $h2 = next_argument();
1458 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001459 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001460 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001461 my $a1 = $col_aligns[0];
1462 my $a2 = $col_aligns[1];
1463 my $a3 = $col_aligns[2];
1464 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001465 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001466 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001467 . "\n <tr>"
1468 . "\n $th1$h1</th>"
1469 . "\n $th2$h2</th>"
1470 . "\n $th3$h3</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001471 . "\n </tr>"
1472 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001473 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001474 . $_
1475 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001476 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001477}
1478
Fred Drakeda72b932000-09-21 15:58:02 +00001479sub do_env_longtableiii{
1480 return do_env_tableiii(@_);
1481}
1482
Fred Drake6659c301998-03-03 22:02:19 +00001483sub do_cmd_lineiii{
1484 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001485 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001486 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001487 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001488 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001489 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001490 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001491 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001492 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001493 . " $c2align$c2</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001494 . " $c3align$c3</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001495 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001496}
1497
Fred Drakea0f4c941998-07-24 22:16:04 +00001498sub do_env_tableiv{
1499 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001500 my $arg = next_argument();
1501 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001502 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001503 my $h1 = next_argument();
1504 my $h2 = next_argument();
1505 my $h3 = next_argument();
1506 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001507 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001508 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001509 my $a1 = $col_aligns[0];
1510 my $a2 = $col_aligns[1];
1511 my $a3 = $col_aligns[2];
1512 my $a4 = $col_aligns[3];
1513 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001514 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001515 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001516 . "\n <tr>"
1517 . "\n $th1$h1</th>"
1518 . "\n $th2$h2</th>"
1519 . "\n $th3$h3</th>"
1520 . "\n $th4$h4</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001521 . "\n </tr>"
1522 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001523 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001524 . $_
1525 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001526 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001527}
1528
Fred Drakeda72b932000-09-21 15:58:02 +00001529sub do_env_longtableiv{
1530 return do_env_tableiv(@_);
1531}
1532
Fred Drakea0f4c941998-07-24 22:16:04 +00001533sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001534 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001535 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001536 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001537 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001538 my $c3 = next_argument();
1539 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001540 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001541 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001542 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001543 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001544 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001545 . " $c3align$c3</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001546 . " $c4align$c4</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001547 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001548}
1549
Fred Drakef269e592001-07-17 23:05:57 +00001550sub do_env_tablev{
1551 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001552 my $arg = next_argument();
1553 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001554 my $font = fix_font(next_argument());
1555 my $h1 = next_argument();
1556 my $h2 = next_argument();
1557 my $h3 = next_argument();
1558 my $h4 = next_argument();
1559 my $h5 = next_argument();
1560 s/[\s\n]+//;
1561 $globals{'lineifont'} = $font;
1562 my $a1 = $col_aligns[0];
1563 my $a2 = $col_aligns[1];
1564 my $a3 = $col_aligns[2];
1565 my $a4 = $col_aligns[3];
1566 my $a5 = $col_aligns[4];
1567 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001568 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001569 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001570 . "\n <tr>"
1571 . "\n $th1$h1</th>"
1572 . "\n $th2$h2</th>"
1573 . "\n $th3$h3</th>"
1574 . "\n $th4$h4</th>"
1575 . "\n $th5$h5</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001576 . "\n </tr>"
1577 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001578 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001579 . $_
1580 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001581 . "\n</table></div>";
Fred Drakef269e592001-07-17 23:05:57 +00001582}
1583
1584sub do_env_longtablev{
1585 return do_env_tablev(@_);
1586}
1587
1588sub do_cmd_linev{
1589 local($_) = @_;
1590 my $aligns = next_optional_argument();
1591 my $c1 = next_argument();
1592 my $c2 = next_argument();
1593 my $c3 = next_argument();
1594 my $c4 = next_argument();
1595 my $c5 = next_argument();
1596 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001597 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001598 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001599 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef269e592001-07-17 23:05:57 +00001600 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001601 . " $c3align$c3</td>\n"
1602 . " $c4align$c4</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001603 . " $c5align$c5</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001604 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001605}
1606
Fred Drake3be20742000-08-31 06:22:54 +00001607
1608# These can be used to control the title page appearance;
1609# they need a little bit of documentation.
1610#
1611# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1612# $ICONSERVER directory, or include path information (other than "./"). The
1613# default image type will be assumed if an extension is not provided.
1614#
1615# If specified, the "title page" will contain two colums: one containing the
1616# title/author/etc., and the other containing the graphic. Use the other
1617# four variables listed here to control specific details of the layout; all
1618# are optional.
1619#
1620# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1621# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1622# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1623# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1624# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1625
Fred Drakef5478632002-05-23 17:59:16 +00001626sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001627 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001628 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001629 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001630 }
1631 else {
1632 write_warnings("\nThis document has no title.");
1633 }
Fred Drake6659c301998-03-03 22:02:19 +00001634 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001635 if ($t_authorURL) {
1636 my $href = translate_commands($t_authorURL);
1637 $href = make_named_href('author', $href,
1638 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001639 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001640 $the_title .= "\n<p>$href</p>";
1641 }
Fred Drake3be20742000-08-31 06:22:54 +00001642 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001643 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001644 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001645 }
Fred Drake3be20742000-08-31 06:22:54 +00001646 }
1647 else {
1648 write_warnings("\nThere is no author for this document.");
1649 }
Fred Drake6659c301998-03-03 22:02:19 +00001650 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001651 $the_title .= "\n<p>$t_institute</p>";
1652 }
Fred Draked07868a1998-05-14 21:00:28 +00001653 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001654 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1655 }
Fred Drake6659c301998-03-03 22:02:19 +00001656 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001657 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001658 }
Fred Drake6659c301998-03-03 22:02:19 +00001659 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001660 $the_title .= "\n<p>";
1661 if ($PACKAGE_VERSION) {
1662 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001663 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001664 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001665 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001666 }
1667 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001668 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001669 }
1670 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001671 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001672 }
Fred Drake6659c301998-03-03 22:02:19 +00001673 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001674 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001675 }
1676 return $the_title;
1677}
1678
Fred Drakef5478632002-05-23 17:59:16 +00001679sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001680 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001681 my $graphic = "<td class=\"titlegraphic\"";
1682 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1683 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1684 $graphic .= "><img";
1685 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1686 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1687 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1688 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001689 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001690 return $graphic;
1691}
1692
Fred Drakef5478632002-05-23 17:59:16 +00001693sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001694 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001695 my $the_title = "\n";
1696 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001697 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001698 # body), but I don't see any other way to get this generated
1699 # at all. Browsers like Mozilla, that support navigation
1700 # links, can make use of this.
1701 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1702 . ($EXTERNAL_UP_TITLE
1703 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001704 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001705 }
1706 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001707 if ($TITLE_PAGE_GRAPHIC) {
1708 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1709 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1710 . "<tr align=\"right\">\n<td>"
1711 . make_my_titlepage()
1712 . "</td>\n"
1713 . make_my_titlegraphic()
1714 . "</tr>\n</table>");
1715 }
1716 else {
1717 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1718 . make_my_titlegraphic()
1719 . "<td>"
1720 . make_my_titlepage()
1721 . "</td></tr>\n</table>");
1722 }
1723 }
1724 else {
Fred Drake0a3c8182004-11-10 19:22:05 +00001725 $the_title .= ("\n<div class='center'>"
Fred Drake3be20742000-08-31 06:22:54 +00001726 . make_my_titlepage()
Fred Drake0a3c8182004-11-10 19:22:05 +00001727 . "\n</div>");
Fred Drake3be20742000-08-31 06:22:54 +00001728 }
1729 $the_title .= "\n</div>";
1730 return $the_title . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001731}
1732
1733
Fred Drake885215c1998-05-20 21:32:09 +00001734#
Fred Drakea0f4c941998-07-24 22:16:04 +00001735# Module synopsis support
1736#
1737
1738require SynopsisTable;
1739
Fred Drakef7685d71998-07-25 03:31:46 +00001740sub get_chapter_id(){
1741 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001742 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001743 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001744 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001745}
1746
Fred Drake643d76d2000-09-09 06:07:37 +00001747# 'chapter' => 'SynopsisTable instance'
1748%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001749
1750sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001751 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001752 my $key;
1753 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001754 if ($key eq $chap) {
1755 return $ModuleSynopses{$chap};
1756 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001757 }
Fred Drake643d76d2000-09-09 06:07:37 +00001758 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001759 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001760 return $st;
1761}
1762
Fred Drake62e43691998-08-10 19:40:44 +00001763sub do_cmd_moduleauthor{
1764 local($_) = @_;
1765 next_argument();
1766 next_argument();
1767 return $_;
1768}
1769
1770sub do_cmd_sectionauthor{
1771 local($_) = @_;
1772 next_argument();
1773 next_argument();
1774 return $_;
1775}
1776
Fred Drakea0f4c941998-07-24 22:16:04 +00001777sub do_cmd_declaremodule{
1778 local($_) = @_;
1779 my $key = next_optional_argument();
1780 my $type = next_argument();
1781 my $name = next_argument();
1782 my $st = get_synopsis_table(get_chapter_id());
1783 #
1784 $key = $name unless $key;
1785 $type = 'built-in' if $type eq 'builtin';
1786 $st->declare($name, $key, $type);
1787 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001788 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001789}
1790
1791sub do_cmd_modulesynopsis{
1792 local($_) = @_;
1793 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001794 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001795 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001796}
1797
1798sub do_cmd_localmoduletable{
1799 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001800 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001801 my $st = get_synopsis_table($chap);
1802 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001803 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001804}
1805
Fred Drakef5478632002-05-23 17:59:16 +00001806sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001807 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001808 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001809 my $st = $ModuleSynopses{$key};
1810 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001811 if ($file) {
1812 process_localmoduletables_in_file($file);
1813 }
1814 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001815 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001816 }
1817 }
1818}
1819
Fred Drakef5478632002-05-23 17:59:16 +00001820sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001821 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001822 open(MYFILE, "<$file");
1823 local($_);
1824 sysread(MYFILE, $_, 1024*1024);
1825 close(MYFILE);
1826 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001827 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001828 my $match = $&;
1829 my $chap = $1;
1830 my $st = get_synopsis_table($chap);
1831 my $data = $st->tohtml();
1832 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001833 }
Fred Drake643d76d2000-09-09 06:07:37 +00001834 open(MYFILE,">$file");
1835 print MYFILE $_;
1836 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001837}
Fred Drakef5478632002-05-23 17:59:16 +00001838sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001839 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001840 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001841}
Fred Drakea0f4c941998-07-24 22:16:04 +00001842
1843
1844#
1845# "See also:" -- references placed at the end of a \section
1846#
1847
1848sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001849 return ("<div class=\"seealso\">\n "
Fred Drake0cf87be2004-11-10 08:08:26 +00001850 . "<p class=\"heading\">See Also:</p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001851 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001852 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001853}
1854
Fred Drake5ed35fd2001-11-30 18:09:54 +00001855sub do_env_seealsostar{
1856 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001857 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001858 . '</div>');
1859}
1860
Fred Drakea0f4c941998-07-24 22:16:04 +00001861sub do_cmd_seemodule{
1862 # Insert the right magic to jump to the module definition. This should
1863 # work most of the time, at least for repeat builds....
1864 local($_) = @_;
1865 my $key = next_optional_argument();
1866 my $module = next_argument();
1867 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001868 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001869 $key = $module
1870 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001871 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001872 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001873 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001874 return ('<dl compact="compact" class="seemodule">'
Fred Drakef1927a62001-06-20 21:29:30 +00001875 . "\n <dt>Module <b><tt class=\"module\">"
1876 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1877 . "\n <dd>$text$period\n </dl>"
1878 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001879}
1880
Fred Drakee0197bf2001-04-12 04:03:22 +00001881sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001882 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001883 my $s = "$str";
1884 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1885 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1886 return $s;
1887}
1888
Fred Drakef5478632002-05-23 17:59:16 +00001889sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001890 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001891 my $rfcnum = next_argument();
1892 my $title = next_argument();
1893 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001894 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001895 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001896 my $attrtitle = strip_html_markup($title);
Fred Draked7a5bca2004-11-10 08:07:00 +00001897 return '<dl compact="compact" class="seerfc">'
Fred Drake37cc0c02000-04-26 18:05:24 +00001898 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001899 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001900 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001901 . "\n <dd>$text\n </dl>"
1902 . $_;
1903}
1904
Fred Drake643d76d2000-09-09 06:07:37 +00001905sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001906 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001907}
1908
1909sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001910 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001911 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001912}
1913
Fred Drake48449982000-09-12 17:52:33 +00001914sub do_cmd_seetitle{
1915 local($_) = @_;
1916 my $url = next_optional_argument();
1917 my $title = next_argument();
1918 my $text = next_argument();
1919 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001920 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001921 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001922 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001923 . "\n >$title$icon</a></em></dt>"
1924 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001925 . $_;
1926 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001927 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001928 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001929 . "\n >$title</em></dt>"
1930 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001931 . $_;
1932}
1933
Fred Drake4f687b32004-01-08 14:57:27 +00001934sub do_cmd_seelink{
1935 local($_) = @_;
1936 my $url = next_argument();
1937 my $linktext = next_argument();
1938 my $text = next_argument();
1939 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001940 return '<dl compact="compact" class="seeurl">'
Fred Drake4f687b32004-01-08 14:57:27 +00001941 . "\n <dt><a href='$url'"
1942 . "\n >$linktext$icon</a></dt>"
1943 . "\n <dd>$text</dd>\n </dl>"
1944 . $_;
1945}
1946
Fred Drakeef4d1112000-05-09 16:17:51 +00001947sub do_cmd_seeurl{
1948 local($_) = @_;
1949 my $url = next_argument();
1950 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001951 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001952 return '<dl compact="compact" class="seeurl">'
Fred Drakeef4d1112000-05-09 16:17:51 +00001953 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001954 . "\n class=\"url\">$url$icon</a></dt>"
1955 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001956 . $_;
1957}
1958
Fred Drakea0f4c941998-07-24 22:16:04 +00001959sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001960 local($_) = @_;
1961 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001962 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001963}
1964
1965
1966#
Fred Drake885215c1998-05-20 21:32:09 +00001967# Definition list support.
1968#
1969
1970sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001971 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001972}
1973
1974sub do_cmd_term{
1975 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001976 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001977 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001978 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001979 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001980}
1981
1982
Fred Drake4e72e052003-07-15 22:00:36 +00001983# Commands listed here have process-order dependencies; these often
1984# are related to indexing operations.
1985# XXX Not sure why funclineni, methodlineni, and samp are here.
1986#
Fred Drake2ff880e1999-02-05 18:31:29 +00001987process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001988declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001989funcline # {} # {}
1990funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001991memberline # [] # {}
1992methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001993methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001994modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001995bifuncindex # {}
1996exindex # {}
1997indexii # {} # {}
1998indexiii # {} # {} # {}
1999indexiv # {} # {} # {} # {}
2000kwindex # {}
2001obindex # {}
2002opindex # {}
2003stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002004platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002005samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002006setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002007withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002008_RAW_ARG_DEFERRED_CMDS_
2009
2010
Fred Drake8a5e6792002-04-15 18:41:31 +00002011$alltt_start = '<div class="verbatim"><pre>';
2012$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002013
Fred Drakef5478632002-05-23 17:59:16 +00002014sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002015 local ($_) = @_;
2016 local($closures,$reopens,@open_block_tags);
2017
2018 # get the tag-strings for all open tags
2019 local(@keep_open_tags) = @$open_tags_R;
2020 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2021
2022 # get the tags for text-level tags only
2023 $open_tags_R = [ @keep_open_tags ];
2024 local($local_closures, $local_reopens);
2025 ($local_closures, $local_reopens,@open_block_tags)
2026 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002027 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002028
2029 $open_tags_R = [ @open_block_tags ];
2030
2031 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002032 local($open_tags_R) = [ @open_block_tags ];
2033 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002034
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002035 local($cnt) = ++$global{'max_id'};
2036 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2037 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002038
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002039 $_ = &translate_environments($_);
2040 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002041
Fred Drake41aa0182003-09-05 15:43:00 +00002042 # remove spurious <BR> someone sticks in; not sure where they
2043 # actually come from
2044 # XXX the replacement space is there to accomodate something
2045 # broken that inserts a space in front of the first line of
2046 # the environment
2047 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002048
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002049 $_ = join('', $closures, $alltt_start, $local_reopens
2050 , $_
2051 , &balance_tags() #, $local_closures
2052 , $alltt_end, $reopens);
2053 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002054 };
2055 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002056 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002057}
2058
Fred Drake8effa012004-04-01 04:30:29 +00002059# List of all filenames produced by do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002060%VerbatimFiles = ();
2061@VerbatimOutputs = ();
2062
2063sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002064 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002065 #
2066 # Re-write the source filename to always use a .txt extension
2067 # so that Web servers will present it as text/plain. This is
2068 # needed since there is no other even moderately reliable way
2069 # to get the right Content-Type header on text files for
2070 # servers which we can't configure (like python.org mirrors).
2071 #
2072 if (defined $VerbatimFiles{$file}) {
2073 # We've seen this one before; re-use the same output file.
2074 return $VerbatimFiles{$file};
2075 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002076 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002077 $filename = "$srcname.txt";
2078 #
2079 # We need to determine if our default filename is already
2080 # being used, and find a new one it it is. If the name is in
2081 # used, this algorithm will first attempt to include the
2082 # source extension as part of the name, and if that is also in
2083 # use (if the same file is included multiple times, or if
2084 # another source file has that as the base name), a counter is
2085 # used instead.
2086 #
2087 my $found = 1;
2088 FIND:
2089 while ($found) {
2090 foreach $fn (@VerbatimOutputs) {
2091 if ($fn eq $filename) {
2092 if ($found == 1) {
2093 $srcext =~ s/^[.]//; # Remove '.' from extension
2094 $filename = "$srcname-$srcext.txt";
2095 }
2096 else {
2097 $filename = "$srcname-$found.txt";
2098 }
2099 ++$found;
2100 next FIND;
2101 }
2102 }
2103 $found = 0;
2104 }
2105 push @VerbatimOutputs, $filename;
2106 $VerbatimFiles{$file} = $filename;
2107 return $filename;
2108}
2109
Fred Drake57e52ef2001-06-15 21:31:57 +00002110sub do_cmd_verbatiminput{
2111 local($_) = @_;
2112 my $fname = next_argument();
2113 my $file;
2114 my $found = 0;
2115 my $texpath;
2116 # Search TEXINPUTS for the input file, the way we're supposed to:
2117 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2118 $file = "$texpath$dd$fname";
2119 last if ($found = (-f $file));
2120 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002121 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002122 my $text;
2123 if ($found) {
2124 open(MYFILE, "<$file") || die "\n$!\n";
2125 read(MYFILE, $text, 1024*1024);
2126 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002127 $filename = get_verbatim_output_name($file);
2128 # Now that we have a filename, write it out.
2129 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002130 print MYFILE $text;
2131 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002132 #
2133 # These rewrites convert the raw text to something that will
2134 # be properly visible as HTML and also will pass through the
2135 # vagaries of conversion through LaTeX2HTML. The order in
2136 # which the specific rewrites are performed is significant.
2137 #
2138 $text =~ s/\&/\&amp;/g;
2139 # These need to happen before the normal < and > re-writes,
2140 # since we need to avoid LaTeX2HTML's attempt to perform
2141 # ligature processing without regard to context (since it
2142 # doesn't have font information).
2143 $text =~ s/--/-&\#45;/g;
2144 $text =~ s/<</\&lt;\&\#60;/g;
2145 $text =~ s/>>/\&gt;\&\#62;/g;
2146 # Just normal re-writes...
2147 $text =~ s/</\&lt;/g;
2148 $text =~ s/>/\&gt;/g;
2149 # These last isn't needed for the HTML, but is needed to get
2150 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2151 # of &sol; since many browsers don't support that.
2152 $text =~ s/\\/\&\#92;/g;
2153 }
2154 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002155 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2156 }
2157 my $note = 'Download as text.';
2158 if ($file ne $filename) {
2159 $note = ('Download as text (original file name: <span class="file">'
2160 . $fname
2161 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002162 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002163 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002164 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002165 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002166 . "<a href=\"$filename\" type=\"text/plain\""
2167 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002168 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002169 . $_);
2170}
Fred Drake86333602001-04-10 17:13:39 +00002171
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021721; # This must be the last line