blob: 5e940e63ea2b6e3cc74feec56101a32ab0b6429d [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 Drake9103ec52004-11-13 01:20:24 +0000109sub do_cmd_UNIX{ '<span class="Unix">Unix</span>' . $_[0]; }
110sub do_cmd_LaTeX{ '<span class="LaTeX">LaTeX</span>' . $_[0]; }
Fred Drakedeb39b52004-11-13 05:46:18 +0000111sub do_cmd_TeX{ '<span class="TeX">TeX</span>' . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000112sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
113sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
114sub do_cmd_C{ 'C' . $_[0]; }
115sub do_cmd_Cpp{ 'C++' . $_[0]; }
116sub do_cmd_EOF{ 'EOF' . $_[0]; }
117sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000118
Fred Drake49b33fa2002-11-15 19:04:10 +0000119sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000120
Fred Draked07868a1998-05-14 21:00:28 +0000121$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000122$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000123$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000124$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000125
Fred Drake49b33fa2002-11-15 19:04:10 +0000126sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
127sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000128sub do_cmd_release{
129 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000130 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000131 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000132}
133
Fred Drakef1927a62001-06-20 21:29:30 +0000134sub do_cmd_setreleaseinfo{
135 local($_) = @_;
136 $RELEASE_INFO = next_argument();
137 return $_;
138}
139
Fred Drake3cdb89d2000-09-14 20:17:23 +0000140sub do_cmd_setshortversion{
141 local($_) = @_;
142 $SHORT_VERSION = next_argument();
143 return $_;
144}
145
Fred Drake6659c301998-03-03 22:02:19 +0000146sub do_cmd_authoraddress{
147 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000148 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000149 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000150}
151
152sub do_cmd_hackscore{
153 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000154 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000155 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000156}
157
Fred Drake345555d2003-12-30 16:19:28 +0000158# Helper used in many places that arbitrary code-like text appears:
159
160sub codetext($){
161 my $text = "$_[0]";
Fred Drakec6864832004-11-11 05:42:13 +0000162 # Make sure that "---" is not converted to "--" later when
163 # LaTeX2HTML tries converting em-dashes based on the conventional
164 # TeX font ligatures:
Fred Drake345555d2003-12-30 16:19:28 +0000165 $text =~ s/--/-\&#45;/go;
166 return $text;
167}
168
Fred Drakef5478632002-05-23 17:59:16 +0000169sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000170 local($_,$before,$after) = @_;
171 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000172 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000173}
174
Fred Drake345555d2003-12-30 16:19:28 +0000175sub use_code_wrappers($$$){
176 local($_,$before,$after) = @_;
177 my $stuff = codetext(next_argument());
178 return $before . $stuff . $after . $_;
179}
180
Fred Drake3cdb89d2000-09-14 20:17:23 +0000181$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000182sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000183 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000184 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000185 "</var><big>\]</big><var>");
186 }
187 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000188 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000189 }
Fred Drake6659c301998-03-03 22:02:19 +0000190}
191
Fred Drakec9a44381998-03-17 06:29:13 +0000192# Logical formatting (some based on texinfo), needs to be converted to
193# minimalist HTML. The "minimalist" is primarily to reduce the size of
194# output files for users that read them over the network rather than
195# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000196
Fred Drake49b33fa2002-11-15 19:04:10 +0000197sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000198sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000199 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_code{
Fred Drake345555d2003-12-30 16:19:28 +0000201 return use_code_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000203 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000205 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000207 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000208sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000209 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000210sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000211 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000212sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000213 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000214sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000215 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000216sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000217 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000218sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000219 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000220sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000221 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000222sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000223 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000224sub do_cmd_regexp{
Fred Drake345555d2003-12-30 16:19:28 +0000225 return use_code_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000226sub do_cmd_character{
Fred Drake345555d2003-12-30 16:19:28 +0000227 return use_code_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000228sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000229 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000230sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000231 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000232sub do_cmd_longprogramopt{
233 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000234 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000235sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000236 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000237sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000238 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000239sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000240 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000241sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000242 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000243sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000244 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000245sub do_cmd_emph{
Fred Drake9c8149a2004-11-10 17:56:29 +0000246 return use_wrappers($_[0], '<em>', '</em>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000247sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000248 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000249sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000250 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000251sub do_cmd_samp{
Fred Drake345555d2003-12-30 16:19:28 +0000252 return use_code_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000253sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000254 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000255sub do_cmd_strong{
Fred Drake9c8149a2004-11-10 17:56:29 +0000256 return use_wrappers($_[0], '<strong>', '</strong>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000257sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000258 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000259sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000260 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000261# This can be changed/overridden for translations:
262%NoticeNames = ('note' => 'Note:',
263 'warning' => 'Warning:',
264 );
265
Fred Drake92350b32001-10-09 18:01:23 +0000266sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000267 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000268 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000269 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000270 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000271 '</span>'); }
272sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000273 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000274 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000275 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000276 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000277 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000278
Fred Drake6ca33772001-12-14 22:50:06 +0000279sub do_env_notice{
280 local($_) = @_;
281 my $notice = next_optional_argument();
282 if (!$notice) {
283 $notice = 'note';
284 }
285 my $label = $NoticeNames{$notice};
286 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
287 . $_
288 . '</div>');
289}
290
Fred Drake3d5a04a2000-08-03 17:25:44 +0000291sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000292 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000293sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000294 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000295
Fred Drakec9a44381998-03-17 06:29:13 +0000296
Fred Drake25817041999-01-13 17:06:34 +0000297sub do_cmd_refmodule{
298 # Insert the right magic to jump to the module definition.
299 local($_) = @_;
300 my $key = next_optional_argument();
301 my $module = next_argument();
302 $key = $module
303 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000304 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000305 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000306}
307
Fred Drake1a7af391998-04-01 22:44:56 +0000308sub do_cmd_newsgroup{
309 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000310 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000311 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000312 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
313 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000314 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000315}
Fred Drakefc16e781998-03-12 21:03:26 +0000316
317sub do_cmd_envvar{
318 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000319 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000320 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000321 # The <tt> here is really to keep buildindex.py from making
322 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000323 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000324 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000325 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000326 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000327 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000328}
329
Fred Drake6659c301998-03-03 22:02:19 +0000330sub do_cmd_url{
331 # use the URL as both text and hyperlink
332 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000333 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000334 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000335 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000336 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000337}
338
339sub do_cmd_manpage{
340 # two parameters: \manpage{name}{section}
341 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000342 my $page = next_argument();
343 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000344 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000345}
346
Fred Drakedbfe7682002-04-03 02:47:14 +0000347$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000348#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
349$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000350
351sub get_rfc_url($$){
352 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000353 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000354}
355
356sub do_cmd_pep{
357 local($_) = @_;
358 my $rfcnumber = next_argument();
359 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000360 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000361 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000362 # Save the reference
363 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
364 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake0c1b2532004-10-29 19:47:52 +0000365 return ("<a class=\"rfc\" id='$id' xml:id='$id'\n"
Fred Drake2fc88a62003-08-05 03:45:37 +0000366 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000367}
368
Fred Drake6659c301998-03-03 22:02:19 +0000369sub do_cmd_rfc{
370 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000371 my $rfcnumber = next_argument();
372 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000373 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000374 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000375 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000376 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000377 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake0c1b2532004-10-29 19:47:52 +0000378 return ("<a class=\"rfc\" id='$id' xml:id='$id'\nhref=\"$href\">"
Fred Drake2fc88a62003-08-05 03:45:37 +0000379 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000380}
381
Fred Drake77602f22001-07-06 22:43:02 +0000382sub do_cmd_ulink{
383 local($_) = @_;
384 my $text = next_argument();
385 my $url = next_argument();
386 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
387}
388
Fred Drakec9f5fe01999-11-09 16:59:42 +0000389sub do_cmd_citetitle{
390 local($_) = @_;
391 my $url = next_optional_argument();
392 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000393 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000394 my $repl = '';
395 if ($url) {
Fred Drakeed306292004-11-04 03:23:04 +0000396 my $titletext = strip_html_markup("$title");
Fred Drakef1927a62001-06-20 21:29:30 +0000397 $repl = ("<em class=\"citetitle\"><a\n"
398 . " href=\"$url\"\n"
Fred Drakeed306292004-11-04 03:23:04 +0000399 . " title=\"$titletext\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000400 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000401 }
402 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000403 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000404 }
405 return $repl . $_;
406}
407
Fred Drake6659c301998-03-03 22:02:19 +0000408sub do_cmd_deprecated{
409 # two parameters: \deprecated{version}{whattodo}
410 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000411 my $release = next_argument();
412 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000413 return ('<div class="versionnote">'
414 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000415 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000416 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000417}
418
Fred Drakef5478632002-05-23 17:59:16 +0000419sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000420 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000421 my $type = $_[0];
422 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000423 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000424 my $release = next_argument();
Fred Drake51d00222006-12-19 22:06:09 +0000425 my $classes = "versionnote";
426 if ($release =~ /^(\d+)\./) {
427 $classes .= " versionnote$1";
428 }
Fred Drakec2b29d02001-04-18 03:11:04 +0000429 my $text = "$type in version $release.";
430 if ($explanation) {
431 $text = "$type in version $release:\n$explanation.";
432 }
Fred Drake51d00222006-12-19 22:06:09 +0000433 return "\n<span class=\"$classes\" \n>$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000434}
435
436sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000437 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000438}
439
440sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000441 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000442}
443
Fred Drake557460c1999-03-02 16:05:35 +0000444#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000445# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000446#
447sub do_cmd_platform{
448 local($_) = @_;
449 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000450 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000451 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000452 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000453 return "\n<p class=\"availability\">Availability: <span"
454 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000455}
456
Fred Drake557460c1999-03-02 16:05:35 +0000457$IGNORE_PLATFORM_ANNOTATION = '';
458sub do_cmd_ignorePlatformAnnotation{
459 local($_) = @_;
460 $IGNORE_PLATFORM_ANNOTATION = next_argument();
461 return $_;
462}
463
Fred Drake6659c301998-03-03 22:02:19 +0000464
465# index commands
466
467$INDEX_SUBITEM = "";
468
Fred Drakef5478632002-05-23 17:59:16 +0000469sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000470 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000471}
472
473sub do_cmd_setindexsubitem{
474 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000475 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000476 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000477}
478
Fred Drakefc16e781998-03-12 21:03:26 +0000479sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000480 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000481 # do things in the right order, but we need to at least strip this stuff
482 # out, and leave anything that the second argument expanded out to.
483 #
484 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000485 my $oldsubitem = $INDEX_SUBITEM;
486 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000487 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000488 my $br_id = ++$globals{'max_id'};
489 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000490 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000491 return
492 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000493 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000494 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000495}
496
Fred Drake08932051998-04-17 02:15:42 +0000497# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000498# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
499# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000500#
Fred Drake49b33fa2002-11-15 19:04:10 +0000501sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000502
Fred Drake42b31a51998-03-27 05:16:10 +0000503# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000504#
Fred Drake08932051998-04-17 02:15:42 +0000505open(IDXFILE, '>index.dat') || die "\n$!\n";
506open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000507print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000508print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000509
510# Using \0 for this is bad because we can't use common tools to work with the
511# resulting files. Things like grep can be useful with this stuff!
512#
513$IDXFILE_FIELD_SEP = "\1";
514
Fred Drakef5478632002-05-23 17:59:16 +0000515sub write_idxfile($$){
516 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000517 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000518}
519
Fred Drake42b31a51998-03-27 05:16:10 +0000520
Fred Drakef5478632002-05-23 17:59:16 +0000521sub gen_link($$){
522 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000523 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000524 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000525}
526
Fred Drakef5478632002-05-23 17:59:16 +0000527sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000528 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000529 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000530 $str = gen_index_id($str, '');
531 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000532 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000533}
534
Fred Drake04bf7242003-11-26 20:55:49 +0000535sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000536 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake42b31a51998-03-27 05:16:10 +0000537 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000538 return ($name, $ahref);
539}
540
541sub new_link_info(){
542 my($name, $ahref) = new_link_name_info();
Fred Drake0c1b2532004-10-29 19:47:52 +0000543 my $aname = "<a id='$name' xml:id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000544 return ($name, $aname, $ahref);
545}
546
Fred Drakeab032151999-05-13 18:36:54 +0000547$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000548sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000549 my $count = @_;
550 my $i = 0;
551 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000552 my $name = $_[$i];
553 my $cmd = "idx_cmd_$name";
554 die "\nNo function $cmd() defined!\n"
555 if (!defined &$cmd);
556 eval ("sub do_cmd_$name { return process_index_macros("
557 . "\$_[0], '$name'); }");
558 if (length($IndexMacroPattern) == 0) {
559 $IndexMacroPattern = "$name";
560 }
561 else {
562 $IndexMacroPattern .= "|$name";
563 }
Fred Drakeab032151999-05-13 18:36:54 +0000564 }
565}
566
567$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000568sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000569 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000570 my $cmdname = $_[1]; # This is what triggered us in the first place;
571 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000572 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000573 my $cmd = "idx_cmd_$cmdname";
574 print "\nIndexing: \\$cmdname"
575 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000576 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000577 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000578 $cmdname = "$1";
579 print " \\$cmdname"
580 if $DEBUG_INDEXING;
581 $cmd = "idx_cmd_$cmdname";
582 if (!defined &$cmd) {
583 last;
584 }
585 else {
586 s/^[\s\n]*\\$cmdname//;
587 &$cmd($ahref);
588 }
Fred Drakeab032151999-05-13 18:36:54 +0000589 }
Fred Drake899072a2004-04-08 15:30:12 +0000590# XXX I don't remember why I added this to begin with.
591# if (/^[ \t\r\n]/) {
592# $_ = substr($_, 1);
593# }
Fred Drake62e43691998-08-10 19:40:44 +0000594 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000595}
596
Fred Drakeab032151999-05-13 18:36:54 +0000597define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000598sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000599 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000600 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000601}
602
Fred Drakeab032151999-05-13 18:36:54 +0000603define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000604sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000605 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000606 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
607 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000608}
609
610define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000611sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000612 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000613 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000614 add_index_entry("$str1!$str2", $_[0]);
615 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000616}
617
Fred Drakeab032151999-05-13 18:36:54 +0000618define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000619sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000620 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000621 my $str2 = next_argument();
622 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000623 add_index_entry("$str1!$str2 $str3", $_[0]);
624 add_index_entry("$str2!$str3, $str1", $_[0]);
625 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000626}
627
Fred Drakeab032151999-05-13 18:36:54 +0000628define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000629sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000630 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000631 my $str2 = next_argument();
632 my $str3 = next_argument();
633 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000634 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
635 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
636 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
637 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000638}
639
Fred Drakeab032151999-05-13 18:36:54 +0000640define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000641sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000642 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000643 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000644 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000645}
Fred Drake6659c301998-03-03 22:02:19 +0000646
Fred Drakef5478632002-05-23 17:59:16 +0000647sub my_typed_index_helper($$){
648 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000649 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000650 add_index_entry("$str $word", $ahref);
651 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000652}
653
Fred Drakeab032151999-05-13 18:36:54 +0000654define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000655sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
656sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
657sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
658sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000659
Fred Drakeab032151999-05-13 18:36:54 +0000660define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000661sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000662 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000663 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000664 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000665}
666
667
Fred Drakef5478632002-05-23 17:59:16 +0000668sub make_mod_index_entry($$){
669 my($str, $define) = @_;
670 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000671 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000672 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
673 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000674 $str = gen_index_id($str, $define);
675 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000676 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000677
Fred Drakec9a44381998-03-17 06:29:13 +0000678 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000679 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000680 $str =~ /(<tt.*<\/tt>)/;
681 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000682 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000683 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000684 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000685}
686
Fred Drake557460c1999-03-02 16:05:35 +0000687
Fred Drakec9a44381998-03-17 06:29:13 +0000688$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000689$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000690
Fred Drakef5478632002-05-23 17:59:16 +0000691sub define_module($$){
692 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000693 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000694 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000695 && $word ne "standard" && $word ne "") {
696 write_warnings("Bad module type '$word'"
697 . " for \\declaremodule (module $name)");
698 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000699 }
Fred Drake6659c301998-03-03 22:02:19 +0000700 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000701 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000702 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000703 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000704 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000705 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000706}
707
Fred Drakef5478632002-05-23 17:59:16 +0000708sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000709 local($word, $_) = @_;
710 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000711 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000712}
713
Fred Drake49b33fa2002-11-15 19:04:10 +0000714sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
715sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
716sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
717sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
718# local($_) = @_;
719# my $name = next_argument();
720# return define_module('standard', $name) . $_;
721# }
Fred Drake6659c301998-03-03 22:02:19 +0000722
Fred Drakef5478632002-05-23 17:59:16 +0000723sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000724 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000725 my $str = next_argument();
726 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000727 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000728 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
729 # just inline it all here
730 $str = gen_index_id($str, 'REF');
731 $index{$str} .= $ahref;
732 write_idxfile($ahref, $str);
733}
734
Fred Drake6659c301998-03-03 22:02:19 +0000735# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000736define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000737 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000738sub idx_cmd_refmodindex($){
739 return ref_module_index_helper('', $_[0]); }
740sub idx_cmd_refbimodindex($){
741 return ref_module_index_helper('built-in', $_[0]); }
742sub idx_cmd_refexmodindex($){
743 return ref_module_index_helper('extension', $_[0]);}
744sub idx_cmd_refstmodindex($){
745 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000746
Fred Drake49b33fa2002-11-15 19:04:10 +0000747sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000748
Fred Drakef5478632002-05-23 17:59:16 +0000749sub init_myformat(){
Fred Drakeaf305b12004-11-11 08:05:34 +0000750 # This depends on the override of text_cleanup() in l2hinit.perl;
751 # if that function cleans out empty tags, the first three of these
752 # variables must be set to comments.
753 #
Fred Drake5d9c636f2003-08-05 05:00:23 +0000754 # Thanks to Dave Kuhlman for figuring why some named anchors were
755 # being lost.
Fred Drakeaf305b12004-11-11 08:05:34 +0000756 $anchor_invisible_mark = '';
757 $anchor_invisible_mark2 = '';
758 $anchor_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000759 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000760}
Fred Drake42b31a51998-03-27 05:16:10 +0000761init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000762
Fred Drakeab032151999-05-13 18:36:54 +0000763# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000764# instead of the dummy filler.
765#
Fred Drakef5478632002-05-23 17:59:16 +0000766sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000767 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000768 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000769 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000770 if ($str =~ /^<[a-z]+\b/) {
771 my $s = "$str";
Fred Drake0c1b2532004-10-29 19:47:52 +0000772 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
Fred Drake04bf7242003-11-26 20:55:49 +0000773 return $s;
774 }
775 else {
Fred Drake0c1b2532004-10-29 19:47:52 +0000776 return "<a id='$name' xml:id='$name'>$str</a>";
Fred Drake04bf7242003-11-26 20:55:49 +0000777 }
Fred Drake6659c301998-03-03 22:02:19 +0000778}
779
Fred Drake77602f22001-07-06 22:43:02 +0000780
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000781%TokenToTargetMapping = (); # language:token -> link target
782%DefinedGrammars = (); # language -> full grammar text
783%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000784
785sub do_cmd_token{
786 local($_) = @_;
787 my $token = next_argument();
788 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
789 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
790 # recursive definition or display-only productionlist
791 return "$token";
792 }
793 if ($target eq '') {
794 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
795 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
796 print "Adding '$CURRENT_FILE' to back-patch list.\n";
797 }
798 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
799 }
Fred Drake5d93eef2004-11-10 17:02:43 +0000800 return "<a class='grammartoken' href=\"$target\">$token</a>" . $_;
Fred Drake77602f22001-07-06 22:43:02 +0000801}
802
Fred Drake16bb4192001-08-20 21:36:38 +0000803sub do_cmd_grammartoken{
804 return do_cmd_token(@_);
805}
806
Fred Drake77602f22001-07-06 22:43:02 +0000807sub do_env_productionlist{
808 local($_) = @_;
809 my $lang = next_optional_argument();
810 my $filename = "grammar-$lang.txt";
811 if ($lang eq '') {
812 $filename = 'grammar.txt';
813 }
814 local($CURRENT_GRAMMAR) = $lang;
815 $DefinedGrammars{$lang} .= $_;
816 return ("<dl><dd class=\"grammar\">\n"
817 . "<div class=\"productions\">\n"
Fred Drake5d93eef2004-11-10 17:02:43 +0000818 . "<table>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000819 . translate_commands(translate_environments($_))
820 . "</table>\n"
821 . "</div>\n"
822 . (($lang eq '*')
823 ? ''
824 : ("<a class=\"grammar-footer\"\n"
825 . " href=\"$filename\" type=\"text/plain\"\n"
826 . " >Download entire grammar as text.</a>\n"))
827 . "</dd></dl>");
828}
829
830sub do_cmd_production{
831 local($_) = @_;
832 my $token = next_argument();
833 my $defn = next_argument();
834 my $lang = $CURRENT_GRAMMAR;
835 local($CURRENT_TOKEN) = $token;
836 if ($lang eq '*') {
Fred Drake5d93eef2004-11-10 17:02:43 +0000837 return ("<tr>\n"
838 . " <td>$token</td>\n"
839 . " <td>::=</td>\n"
840 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000841 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000842 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000843 . $_);
844 }
845 my $target;
846 if ($lang eq '') {
847 $target = "$CURRENT_FILE\#tok-$token";
848 }
849 else {
850 $target = "$CURRENT_FILE\#tok-$lang-$token";
851 }
852 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drake5d93eef2004-11-10 17:02:43 +0000853 return ("<tr>\n"
854 . " <td><a id='tok-$token' xml:id='tok-$token'>"
855 . "$token</a></td>\n"
856 . " <td>::=</td>\n"
857 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000858 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000859 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000860 . $_);
861}
862
Fred Drake53815882002-03-15 23:21:37 +0000863sub do_cmd_productioncont{
864 local($_) = @_;
865 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000866 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake5d93eef2004-11-10 17:02:43 +0000867 return ("<tr>\n"
868 . " <td></td>\n"
869 . " <td></td>\n"
Fred Drake53815882002-03-15 23:21:37 +0000870 . " <td><code>"
871 . translate_commands($defn)
872 . "</code></td></tr>"
873 . $_);
874}
875
Fred Drakef5478632002-05-23 17:59:16 +0000876sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000877 my $lang;
878 my $filename;
879 local($_);
880 print "process_grammar_files()\n";
881 foreach $lang (keys %DefinedGrammars) {
882 $filename = "grammar-$lang.txt";
883 if ($lang eq '*') {
884 next;
885 }
886 if ($lang eq '') {
887 $filename = 'grammar.txt';
888 }
889 open(GRAMMAR, ">$filename") || die "\n$!\n";
Thomas Wouters89f507f2006-12-13 04:49:30 +0000890 print GRAMMAR "##################################################\n";
891 print GRAMMAR "# This file is only meant to be a guide, #\n";
892 print GRAMMAR "# and differs in small ways from the real #\n";
893 print GRAMMAR "# grammar. The exact reference is the file #\n";
894 print GRAMMAR "# Grammar/Grammar distributed with the source. #\n";
895 print GRAMMAR "##################################################\n";
Fred Drake77602f22001-07-06 22:43:02 +0000896 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
897 close(GRAMMAR);
898 print "Wrote grammar file $filename\n";
899 }
900 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
901 foreach $filename (keys %BackpatchGrammarFiles) {
902 print "\nBack-patching grammar links in $filename\n";
903 my $buffer;
904 open(GRAMMAR, "<$filename") || die "\n$!\n";
905 # read all of the file into the buffer
906 sysread(GRAMMAR, $buffer, 1024*1024);
907 close(GRAMMAR);
908 while ($buffer =~ /$PATTERN/) {
909 my($lang, $token) = ($1, $2);
910 my $target = $TokenToTargetMapping{"$lang:$token"};
911 my $source = "<pyGrammarToken><$lang><$token>";
912 $buffer =~ s/$source/$target/g;
913 }
914 open(GRAMMAR, ">$filename") || die "\n$!\n";
915 print GRAMMAR $buffer;
916 close(GRAMMAR);
917 }
918}
919
Fred Drakef5478632002-05-23 17:59:16 +0000920sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000921 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000922 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000923 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
924 s/\\token(<<\d+>>)(.+)\1/$2/g;
925 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000926 s/<<\d+>>//g;
927 s/;SPMgt;/>/g;
928 s/;SPMlt;/</g;
929 s/;SPMquot;/\"/g;
930 return $_;
931}
932
933
Fred Drakee15956b2000-04-03 04:51:13 +0000934$REFCOUNTS_LOADED = 0;
935
Fred Drakef5478632002-05-23 17:59:16 +0000936sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000937 $REFCOUNTS_LOADED = 1;
938
Fred Drake49b33fa2002-11-15 19:04:10 +0000939 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000940 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000941 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000942 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000943 $mydir = getcwd() . "$dd$mydir"
944 unless $mydir =~ s|^/|/|;
945 local $_;
946 my $filename = "$mydir${dd}api${dd}refcounts.dat";
947 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
948 print "[loading API refcount data]";
949 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000950 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000951 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
952 #print "\n$func($param) --> $count";
953 $REFCOUNTS{"$func:$param"} = $count;
954 }
955 }
956}
957
Fred Drakef5478632002-05-23 17:59:16 +0000958sub get_refcount($$){
959 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000960 load_refcounts()
961 unless $REFCOUNTS_LOADED;
962 return $REFCOUNTS{"$func:$param"};
963}
964
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000965
966$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000967$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000968
Fred Drakef5478632002-05-23 17:59:16 +0000969sub cfuncline_helper($$$){
970 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000971 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000972 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000973 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000974 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000975 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
976 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000977 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
978 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
979 . "<td>$args)</td>"
980 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000981}
982sub do_cmd_cfuncline{
983 local($_) = @_;
984 my $type = next_argument();
985 my $name = next_argument();
986 my $args = next_argument();
987 my $siginfo = cfuncline_helper($type, $name, $args);
988 return "<dt>$siginfo\n<dd>" . $_;
989}
990sub do_env_cfuncdesc{
991 local($_) = @_;
992 my $type = next_argument();
993 my $name = next_argument();
994 my $args = next_argument();
995 my $siginfo = cfuncline_helper($type, $name, $args);
996 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000997 my $rcinfo = '';
998 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000999 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +00001000 }
1001 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +00001002 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +00001003 }
Fred Drakec2578c52000-04-10 18:26:45 +00001004 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +00001005 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +00001006 }
Fred Drakee15956b2000-04-03 04:51:13 +00001007 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +00001008 $rcinfo = ( "\n<div class=\"refcount-info\">"
1009 . "\n <span class=\"label\">Return value:</span>"
1010 . "\n <span class=\"value\">$rcinfo.</span>"
1011 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +00001012 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001013 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001014 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001015 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001016 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001017}
1018
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001019sub do_cmd_cmemberline{
1020 local($_) = @_;
1021 my $container = next_argument();
1022 my $type = next_argument();
1023 my $name = next_argument();
1024 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001025 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001026 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001027 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001028 . $_;
1029}
1030sub do_env_cmemberdesc{
1031 local($_) = @_;
1032 my $container = next_argument();
1033 my $type = next_argument();
1034 my $name = next_argument();
1035 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001036 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001037 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001038 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001039 . $_
1040 . '</dl>';
1041}
1042
Fred Drakee15956b2000-04-03 04:51:13 +00001043sub do_env_csimplemacrodesc{
1044 local($_) = @_;
1045 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001046 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001047 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001048 . $_
1049 . '</dl>'
1050}
1051
Fred Drake6659c301998-03-03 22:02:19 +00001052sub do_env_ctypedesc{
1053 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001054 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001055 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001056 $index_name = $type_name
1057 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001058 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001059 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001060 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1061 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001062 . $_
1063 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001064}
1065
1066sub do_env_cvardesc{
1067 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001068 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001069 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001070 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001071 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001072 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001073 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001074 . '<dd>'
1075 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001076 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001077}
1078
Fred Drake3cdb89d2000-09-14 20:17:23 +00001079sub convert_args($){
1080 local($IN_DESC_HANDLER) = 1;
1081 local($_) = @_;
1082 return translate_commands($_);
1083}
1084
Fred Drakef6e90272002-06-18 18:24:16 +00001085sub funcline_helper($$$){
1086 my($first, $idxitem, $arglist) = @_;
1087 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001088 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1089 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001090 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001091}
1092
Fred Drake6659c301998-03-03 22:02:19 +00001093sub do_env_funcdesc{
1094 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001095 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001096 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001097 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1098 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001099 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001100 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001101 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001102 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001103}
1104
1105sub do_env_funcdescni{
1106 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001107 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001108 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001109 my $prefix = "<tt class=\"function\">$function_name</tt>";
1110 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001111}
1112
1113sub do_cmd_funcline{
1114 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001115 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001116 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001117 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001118 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1119 $prefix =~ s/\(\)//;
1120
Fred Drakef6e90272002-06-18 18:24:16 +00001121 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001122}
1123
Fred Drake6b3fb781999-07-12 16:50:09 +00001124sub do_cmd_funclineni{
1125 local($_) = @_;
1126 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001127 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001128 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001129
Fred Drakef6e90272002-06-18 18:24:16 +00001130 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001131}
1132
Fred Drake6659c301998-03-03 22:02:19 +00001133# Change this flag to index the opcode entries. I don't think it's very
1134# useful to index them, since they're only presented to describe the dis
1135# module.
1136#
1137$INDEX_OPCODES = 0;
1138
1139sub do_env_opcodedesc{
1140 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001141 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001142 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001143 my $idx;
1144 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001145 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001146 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001147 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001148 }
1149 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001150 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001151 }
1152 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001153 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001154 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001155 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001156 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001157}
1158
1159sub do_env_datadesc{
1160 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001161 my $dataname = next_argument();
1162 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001163 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001164 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001165 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001166 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001167}
1168
1169sub do_env_datadescni{
1170 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001171 my $idx = next_argument();
1172 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001173 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001174 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001175 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001176}
1177
1178sub do_cmd_dataline{
1179 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001180 my $data_name = next_argument();
1181 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001182 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001183 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001184}
1185
Fred Drakeadb272c2000-04-10 17:47:14 +00001186sub do_cmd_datalineni{
1187 local($_) = @_;
1188 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001189 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001190}
1191
Fred Drake42b31a51998-03-27 05:16:10 +00001192sub do_env_excdesc{
1193 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001194 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001195 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001196 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001197 . "\n<dd>"
1198 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001199 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001200}
1201
Fred Drake62e43691998-08-10 19:40:44 +00001202sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001203
1204
Fred Drakef5478632002-05-23 17:59:16 +00001205sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001206 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001207 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001208 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001209 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001210 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001211 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001212 my $prefix = "$TLSTART$what$TLEND$idx";
1213 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001214}
1215
Fred Drake643d76d2000-09-09 06:07:37 +00001216sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001217 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001218}
1219
Fred Drake06a01e82001-05-11 01:00:30 +00001220sub do_env_classdescstar{
1221 local($_) = @_;
1222 $THIS_CLASS = next_argument();
1223 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001224 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001225 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001226 my $prefix = "${TLSTART}class$TLEND$idx";
1227 # Can't use funcline_helper() since there is no args list.
1228 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001229}
1230
Fred Drake643d76d2000-09-09 06:07:37 +00001231sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001232 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001233}
1234
Fred Drake42b31a51998-03-27 05:16:10 +00001235
1236sub do_env_methoddesc{
1237 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001238 my $class_name = next_optional_argument();
1239 $class_name = $THIS_CLASS
1240 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001241 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001242 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001243 my $extra = '';
1244 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001245 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001246 }
Fred Drakef1927a62001-06-20 21:29:30 +00001247 my $idx = make_str_index_entry(
1248 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001249 $idx =~ s/ \(.*\)//;
1250 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001251 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001252}
1253
1254
Fred Drake7d45f6d1999-01-05 14:39:27 +00001255sub do_cmd_methodline{
1256 local($_) = @_;
1257 my $class_name = next_optional_argument();
1258 $class_name = $THIS_CLASS
1259 unless $class_name;
1260 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001261 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001262 my $extra = '';
1263 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001264 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001265 }
Fred Drakef1927a62001-06-20 21:29:30 +00001266 my $idx = make_str_index_entry(
1267 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001268 $idx =~ s/ \(.*\)//;
1269 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001270 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001271}
1272
1273
Fred Draked64a40d1998-09-10 18:59:13 +00001274sub do_cmd_methodlineni{
1275 local($_) = @_;
1276 next_optional_argument();
1277 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001278 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001279 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001280}
1281
Fred Drake42b31a51998-03-27 05:16:10 +00001282sub do_env_methoddescni{
1283 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001284 next_optional_argument();
1285 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001286 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001287 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001288}
1289
1290
1291sub do_env_memberdesc{
1292 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001293 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001294 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001295 $class = $THIS_CLASS
1296 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001297 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001298 $extra = " ($class attribute)"
1299 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001300 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001301 $idx =~ s/ \(.*\)//;
1302 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001303 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001304}
1305
1306
Fred Drake5ccf3301998-04-17 20:04:09 +00001307sub do_cmd_memberline{
1308 local($_) = @_;
1309 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001310 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001311 $class = $THIS_CLASS
1312 unless $class;
1313 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001314 $extra = " ($class attribute)"
1315 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001316 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001317 $idx =~ s/ \(.*\)//;
1318 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001319 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001320}
1321
Fred Drakef269e592001-07-17 23:05:57 +00001322
Fred Drake42b31a51998-03-27 05:16:10 +00001323sub do_env_memberdescni{
1324 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001325 next_optional_argument();
1326 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001327 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001328 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001329 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001330}
1331
1332
Fred Drake5ccf3301998-04-17 20:04:09 +00001333sub do_cmd_memberlineni{
1334 local($_) = @_;
1335 next_optional_argument();
1336 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001337 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001338}
1339
Fred Drakef269e592001-07-17 23:05:57 +00001340
Fred Drake9e927f12004-11-10 15:49:25 +00001341# For tables, we include a class on every cell to allow the CSS to set
1342# the text-align property; this is because support for styling columns
1343# via the <col> element appears nearly non-existant on even the latest
1344# browsers (Mozilla 1.7 is stable at the time of this writing).
1345# Hopefully this can be improved as browsers evolve.
1346
Fred Drakef269e592001-07-17 23:05:57 +00001347@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001348
Fred Drakecb199762001-08-16 21:56:24 +00001349%FontConversions = ('cdata' => 'tt class="cdata"',
1350 'character' => 'tt class="character"',
1351 'class' => 'tt class="class"',
1352 'command' => 'code',
1353 'constant' => 'tt class="constant"',
1354 'exception' => 'tt class="exception"',
1355 'file' => 'tt class="file"',
1356 'filenq' => 'tt class="file"',
1357 'kbd' => 'kbd',
1358 'member' => 'tt class="member"',
1359 'programopt' => 'b',
1360 'textrm' => '',
1361 );
1362
Fred Drakef5478632002-05-23 17:59:16 +00001363sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001364 # do a little magic on a font name to get the right behavior in the first
1365 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001366 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001367 if (defined $FontConversions{$font}) {
1368 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001369 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001370 return $font;
1371}
1372
Fred Drakef5478632002-05-23 17:59:16 +00001373sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001374 my $a = $_[0];
1375 if (!defined $a) {
1376 return '';
1377 }
Fred Drakee15956b2000-04-03 04:51:13 +00001378 my $mark = substr($a, 0, 1);
1379 my $r = '';
1380 if ($mark eq 'c')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001381 { $r = ' class="center"'; }
Fred Drakee15956b2000-04-03 04:51:13 +00001382 elsif ($mark eq 'r')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001383 { $r = ' class="right" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001384 elsif ($mark eq 'l')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001385 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001386 elsif ($mark eq 'p')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001387 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001388 return $r;
1389}
1390
Fred Drakef5478632002-05-23 17:59:16 +00001391sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001392 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001393 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001394 my $a1 = figure_column_alignment($s1);
1395 my $a2 = figure_column_alignment($s2);
1396 my $a3 = figure_column_alignment($s3);
1397 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001398 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001399 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1400 $col_aligns[1] = "<td$a2>";
1401 $col_aligns[2] = "<td$a3>";
1402 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001403 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001404 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001405 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001406}
1407
Fred Drakef5478632002-05-23 17:59:16 +00001408sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001409 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001410 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001411 if ($font) {
1412 $sfont = "<$font>";
1413 $efont = "</$font>";
1414 $efont =~ s/ .*>/>/;
1415 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001416 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001417}
1418
1419sub do_env_tableii{
1420 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001421 my $arg = next_argument();
1422 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001423 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001424 my $h1 = next_argument();
1425 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001426 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001427 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001428 my $a1 = $col_aligns[0];
1429 my $a2 = $col_aligns[1];
1430 s/\\lineii</\\lineii[$a1|$a2]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001431 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001432 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001433 . "\n <tr>"
1434 . "\n $th1$h1</th>"
1435 . "\n $th2$h2</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001436 . "\n </tr>"
1437 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001438 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001439 . $_
1440 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001441 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001442}
1443
Fred Drakeda72b932000-09-21 15:58:02 +00001444sub do_env_longtableii{
1445 return do_env_tableii(@_);
1446}
1447
Fred Drake6659c301998-03-03 22:02:19 +00001448sub do_cmd_lineii{
1449 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001450 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001451 my $c1 = next_argument();
1452 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001453 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001454 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001455 my($c1align, $c2align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001456 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1457 . " $c2align$c2</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001458 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001459}
1460
1461sub do_env_tableiii{
1462 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001463 my $arg = next_argument();
1464 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001465 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001466 my $h1 = next_argument();
1467 my $h2 = next_argument();
1468 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001469 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001470 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001471 my $a1 = $col_aligns[0];
1472 my $a2 = $col_aligns[1];
1473 my $a3 = $col_aligns[2];
1474 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001475 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001476 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001477 . "\n <tr>"
1478 . "\n $th1$h1</th>"
1479 . "\n $th2$h2</th>"
1480 . "\n $th3$h3</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001481 . "\n </tr>"
1482 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001483 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001484 . $_
1485 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001486 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001487}
1488
Fred Drakeda72b932000-09-21 15:58:02 +00001489sub do_env_longtableiii{
1490 return do_env_tableiii(@_);
1491}
1492
Fred Drake6659c301998-03-03 22:02:19 +00001493sub do_cmd_lineiii{
1494 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001495 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001496 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001497 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001498 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001499 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001500 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001501 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001502 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001503 . " $c2align$c2</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001504 . " $c3align$c3</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001505 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001506}
1507
Fred Drakea0f4c941998-07-24 22:16:04 +00001508sub do_env_tableiv{
1509 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001510 my $arg = next_argument();
1511 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001512 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001513 my $h1 = next_argument();
1514 my $h2 = next_argument();
1515 my $h3 = next_argument();
1516 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001517 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001518 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001519 my $a1 = $col_aligns[0];
1520 my $a2 = $col_aligns[1];
1521 my $a3 = $col_aligns[2];
1522 my $a4 = $col_aligns[3];
1523 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001524 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001525 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001526 . "\n <tr>"
1527 . "\n $th1$h1</th>"
1528 . "\n $th2$h2</th>"
1529 . "\n $th3$h3</th>"
1530 . "\n $th4$h4</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001531 . "\n </tr>"
1532 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001533 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001534 . $_
1535 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001536 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001537}
1538
Fred Drakeda72b932000-09-21 15:58:02 +00001539sub do_env_longtableiv{
1540 return do_env_tableiv(@_);
1541}
1542
Fred Drakea0f4c941998-07-24 22:16:04 +00001543sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001544 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001545 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001546 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001547 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001548 my $c3 = next_argument();
1549 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001550 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001551 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001552 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001553 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001554 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001555 . " $c3align$c3</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001556 . " $c4align$c4</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001557 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001558}
1559
Fred Drakef269e592001-07-17 23:05:57 +00001560sub do_env_tablev{
1561 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001562 my $arg = next_argument();
1563 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001564 my $font = fix_font(next_argument());
1565 my $h1 = next_argument();
1566 my $h2 = next_argument();
1567 my $h3 = next_argument();
1568 my $h4 = next_argument();
1569 my $h5 = next_argument();
1570 s/[\s\n]+//;
1571 $globals{'lineifont'} = $font;
1572 my $a1 = $col_aligns[0];
1573 my $a2 = $col_aligns[1];
1574 my $a3 = $col_aligns[2];
1575 my $a4 = $col_aligns[3];
1576 my $a5 = $col_aligns[4];
1577 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001578 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001579 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001580 . "\n <tr>"
1581 . "\n $th1$h1</th>"
1582 . "\n $th2$h2</th>"
1583 . "\n $th3$h3</th>"
1584 . "\n $th4$h4</th>"
1585 . "\n $th5$h5</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001586 . "\n </tr>"
1587 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001588 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001589 . $_
1590 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001591 . "\n</table></div>";
Fred Drakef269e592001-07-17 23:05:57 +00001592}
1593
1594sub do_env_longtablev{
1595 return do_env_tablev(@_);
1596}
1597
1598sub do_cmd_linev{
1599 local($_) = @_;
1600 my $aligns = next_optional_argument();
1601 my $c1 = next_argument();
1602 my $c2 = next_argument();
1603 my $c3 = next_argument();
1604 my $c4 = next_argument();
1605 my $c5 = next_argument();
1606 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001607 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001608 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001609 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef269e592001-07-17 23:05:57 +00001610 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001611 . " $c3align$c3</td>\n"
1612 . " $c4align$c4</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001613 . " $c5align$c5</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001614 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001615}
1616
Fred Drake3be20742000-08-31 06:22:54 +00001617
1618# These can be used to control the title page appearance;
1619# they need a little bit of documentation.
1620#
1621# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1622# $ICONSERVER directory, or include path information (other than "./"). The
1623# default image type will be assumed if an extension is not provided.
1624#
1625# If specified, the "title page" will contain two colums: one containing the
1626# title/author/etc., and the other containing the graphic. Use the other
1627# four variables listed here to control specific details of the layout; all
1628# are optional.
1629#
1630# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1631# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1632# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1633# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1634# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1635
Fred Drakef5478632002-05-23 17:59:16 +00001636sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001637 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001638 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001639 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001640 }
1641 else {
1642 write_warnings("\nThis document has no title.");
1643 }
Fred Drake6659c301998-03-03 22:02:19 +00001644 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001645 if ($t_authorURL) {
1646 my $href = translate_commands($t_authorURL);
1647 $href = make_named_href('author', $href,
1648 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001649 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001650 $the_title .= "\n<p>$href</p>";
1651 }
Fred Drake3be20742000-08-31 06:22:54 +00001652 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001653 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001654 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001655 }
Fred Drake3be20742000-08-31 06:22:54 +00001656 }
1657 else {
1658 write_warnings("\nThere is no author for this document.");
1659 }
Fred Drake6659c301998-03-03 22:02:19 +00001660 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001661 $the_title .= "\n<p>$t_institute</p>";
1662 }
Fred Draked07868a1998-05-14 21:00:28 +00001663 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001664 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1665 }
Fred Drake6659c301998-03-03 22:02:19 +00001666 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001667 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001668 }
Fred Drake6659c301998-03-03 22:02:19 +00001669 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001670 $the_title .= "\n<p>";
1671 if ($PACKAGE_VERSION) {
1672 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001673 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001674 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001675 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001676 }
1677 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001678 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001679 }
1680 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001681 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001682 }
Fred Drake6659c301998-03-03 22:02:19 +00001683 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001684 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001685 }
1686 return $the_title;
1687}
1688
Fred Drakef5478632002-05-23 17:59:16 +00001689sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001690 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001691 my $graphic = "<td class=\"titlegraphic\"";
1692 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1693 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1694 $graphic .= "><img";
1695 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1696 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1697 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1698 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001699 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001700 return $graphic;
1701}
1702
Fred Drakef5478632002-05-23 17:59:16 +00001703sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001704 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001705 my $the_title = "\n";
1706 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001707 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001708 # body), but I don't see any other way to get this generated
1709 # at all. Browsers like Mozilla, that support navigation
1710 # links, can make use of this.
1711 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1712 . ($EXTERNAL_UP_TITLE
1713 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001714 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001715 }
1716 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001717 if ($TITLE_PAGE_GRAPHIC) {
1718 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1719 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1720 . "<tr align=\"right\">\n<td>"
1721 . make_my_titlepage()
1722 . "</td>\n"
1723 . make_my_titlegraphic()
1724 . "</tr>\n</table>");
1725 }
1726 else {
1727 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1728 . make_my_titlegraphic()
1729 . "<td>"
1730 . make_my_titlepage()
1731 . "</td></tr>\n</table>");
1732 }
1733 }
1734 else {
Fred Drake0a3c8182004-11-10 19:22:05 +00001735 $the_title .= ("\n<div class='center'>"
Fred Drake3be20742000-08-31 06:22:54 +00001736 . make_my_titlepage()
Fred Drake0a3c8182004-11-10 19:22:05 +00001737 . "\n</div>");
Fred Drake3be20742000-08-31 06:22:54 +00001738 }
1739 $the_title .= "\n</div>";
1740 return $the_title . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001741}
1742
1743
Fred Drake885215c1998-05-20 21:32:09 +00001744#
Fred Drakea0f4c941998-07-24 22:16:04 +00001745# Module synopsis support
1746#
1747
1748require SynopsisTable;
1749
Fred Drakef7685d71998-07-25 03:31:46 +00001750sub get_chapter_id(){
1751 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001752 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001753 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001754 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001755}
1756
Fred Drake643d76d2000-09-09 06:07:37 +00001757# 'chapter' => 'SynopsisTable instance'
1758%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001759
1760sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001761 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001762 my $key;
1763 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001764 if ($key eq $chap) {
1765 return $ModuleSynopses{$chap};
1766 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001767 }
Fred Drake643d76d2000-09-09 06:07:37 +00001768 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001769 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001770 return $st;
1771}
1772
Fred Drake62e43691998-08-10 19:40:44 +00001773sub do_cmd_moduleauthor{
1774 local($_) = @_;
1775 next_argument();
1776 next_argument();
1777 return $_;
1778}
1779
1780sub do_cmd_sectionauthor{
1781 local($_) = @_;
1782 next_argument();
1783 next_argument();
1784 return $_;
1785}
1786
Fred Drakea0f4c941998-07-24 22:16:04 +00001787sub do_cmd_declaremodule{
1788 local($_) = @_;
1789 my $key = next_optional_argument();
1790 my $type = next_argument();
1791 my $name = next_argument();
1792 my $st = get_synopsis_table(get_chapter_id());
1793 #
1794 $key = $name unless $key;
1795 $type = 'built-in' if $type eq 'builtin';
1796 $st->declare($name, $key, $type);
1797 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001798 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001799}
1800
1801sub do_cmd_modulesynopsis{
1802 local($_) = @_;
1803 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001804 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001805 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001806}
1807
1808sub do_cmd_localmoduletable{
1809 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001810 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001811 my $st = get_synopsis_table($chap);
1812 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001813 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001814}
1815
Fred Drakef5478632002-05-23 17:59:16 +00001816sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001817 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001818 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001819 my $st = $ModuleSynopses{$key};
1820 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001821 if ($file) {
1822 process_localmoduletables_in_file($file);
1823 }
1824 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001825 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001826 }
1827 }
1828}
1829
Fred Drakef5478632002-05-23 17:59:16 +00001830sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001831 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001832 open(MYFILE, "<$file");
1833 local($_);
1834 sysread(MYFILE, $_, 1024*1024);
1835 close(MYFILE);
1836 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001837 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001838 my $match = $&;
1839 my $chap = $1;
1840 my $st = get_synopsis_table($chap);
1841 my $data = $st->tohtml();
1842 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001843 }
Fred Drake643d76d2000-09-09 06:07:37 +00001844 open(MYFILE,">$file");
1845 print MYFILE $_;
1846 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001847}
Fred Drakef5478632002-05-23 17:59:16 +00001848sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001849 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001850 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001851}
Fred Drakea0f4c941998-07-24 22:16:04 +00001852
1853
1854#
1855# "See also:" -- references placed at the end of a \section
1856#
1857
1858sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001859 return ("<div class=\"seealso\">\n "
Fred Drake0cf87be2004-11-10 08:08:26 +00001860 . "<p class=\"heading\">See Also:</p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001861 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001862 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001863}
1864
Fred Drake5ed35fd2001-11-30 18:09:54 +00001865sub do_env_seealsostar{
1866 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001867 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001868 . '</div>');
1869}
1870
Fred Drakea0f4c941998-07-24 22:16:04 +00001871sub do_cmd_seemodule{
1872 # Insert the right magic to jump to the module definition. This should
1873 # work most of the time, at least for repeat builds....
1874 local($_) = @_;
1875 my $key = next_optional_argument();
1876 my $module = next_argument();
1877 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001878 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001879 $key = $module
1880 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001881 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001882 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001883 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001884 return ('<dl compact="compact" class="seemodule">'
Fred Drakef1927a62001-06-20 21:29:30 +00001885 . "\n <dt>Module <b><tt class=\"module\">"
1886 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1887 . "\n <dd>$text$period\n </dl>"
1888 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001889}
1890
Fred Drakee0197bf2001-04-12 04:03:22 +00001891sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001892 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001893 my $s = "$str";
1894 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1895 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1896 return $s;
1897}
1898
Fred Drakef5478632002-05-23 17:59:16 +00001899sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001900 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001901 my $rfcnum = next_argument();
1902 my $title = next_argument();
1903 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001904 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001905 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001906 my $attrtitle = strip_html_markup($title);
Fred Draked7a5bca2004-11-10 08:07:00 +00001907 return '<dl compact="compact" class="seerfc">'
Fred Drake37cc0c02000-04-26 18:05:24 +00001908 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001909 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001910 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001911 . "\n <dd>$text\n </dl>"
1912 . $_;
1913}
1914
Fred Drake643d76d2000-09-09 06:07:37 +00001915sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001916 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001917}
1918
1919sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001920 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001921 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001922}
1923
Fred Drake48449982000-09-12 17:52:33 +00001924sub do_cmd_seetitle{
1925 local($_) = @_;
1926 my $url = next_optional_argument();
1927 my $title = next_argument();
1928 my $text = next_argument();
1929 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001930 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001931 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001932 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001933 . "\n >$title$icon</a></em></dt>"
1934 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001935 . $_;
1936 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001937 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001938 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001939 . "\n >$title</em></dt>"
1940 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001941 . $_;
1942}
1943
Fred Drake4f687b32004-01-08 14:57:27 +00001944sub do_cmd_seelink{
1945 local($_) = @_;
1946 my $url = next_argument();
1947 my $linktext = next_argument();
1948 my $text = next_argument();
1949 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001950 return '<dl compact="compact" class="seeurl">'
Fred Drake4f687b32004-01-08 14:57:27 +00001951 . "\n <dt><a href='$url'"
1952 . "\n >$linktext$icon</a></dt>"
1953 . "\n <dd>$text</dd>\n </dl>"
1954 . $_;
1955}
1956
Fred Drakeef4d1112000-05-09 16:17:51 +00001957sub do_cmd_seeurl{
1958 local($_) = @_;
1959 my $url = next_argument();
1960 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001961 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001962 return '<dl compact="compact" class="seeurl">'
Fred Drakeef4d1112000-05-09 16:17:51 +00001963 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001964 . "\n class=\"url\">$url$icon</a></dt>"
1965 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001966 . $_;
1967}
1968
Fred Drakea0f4c941998-07-24 22:16:04 +00001969sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001970 local($_) = @_;
1971 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001972 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001973}
1974
1975
1976#
Fred Drake885215c1998-05-20 21:32:09 +00001977# Definition list support.
1978#
1979
1980sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001981 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001982}
1983
1984sub do_cmd_term{
1985 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001986 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001987 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001988 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001989 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001990}
1991
1992
Fred Drake4e72e052003-07-15 22:00:36 +00001993# Commands listed here have process-order dependencies; these often
1994# are related to indexing operations.
1995# XXX Not sure why funclineni, methodlineni, and samp are here.
1996#
Fred Drake2ff880e1999-02-05 18:31:29 +00001997process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001998declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001999funcline # {} # {}
2000funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002001memberline # [] # {}
2002methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00002003methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002004modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00002005bifuncindex # {}
2006exindex # {}
2007indexii # {} # {}
2008indexiii # {} # {} # {}
2009indexiv # {} # {} # {} # {}
2010kwindex # {}
2011obindex # {}
2012opindex # {}
2013stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002014platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002015samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002016setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002017withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002018_RAW_ARG_DEFERRED_CMDS_
2019
2020
Fred Drake8a5e6792002-04-15 18:41:31 +00002021$alltt_start = '<div class="verbatim"><pre>';
2022$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002023
Fred Drakef5478632002-05-23 17:59:16 +00002024sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002025 local ($_) = @_;
2026 local($closures,$reopens,@open_block_tags);
2027
2028 # get the tag-strings for all open tags
2029 local(@keep_open_tags) = @$open_tags_R;
2030 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2031
2032 # get the tags for text-level tags only
2033 $open_tags_R = [ @keep_open_tags ];
2034 local($local_closures, $local_reopens);
2035 ($local_closures, $local_reopens,@open_block_tags)
2036 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002037 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002038
2039 $open_tags_R = [ @open_block_tags ];
2040
2041 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002042 local($open_tags_R) = [ @open_block_tags ];
2043 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002044
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002045 local($cnt) = ++$global{'max_id'};
2046 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2047 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002048
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002049 $_ = &translate_environments($_);
2050 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002051
Fred Drake41aa0182003-09-05 15:43:00 +00002052 # remove spurious <BR> someone sticks in; not sure where they
2053 # actually come from
2054 # XXX the replacement space is there to accomodate something
2055 # broken that inserts a space in front of the first line of
2056 # the environment
2057 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002058
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002059 $_ = join('', $closures, $alltt_start, $local_reopens
2060 , $_
2061 , &balance_tags() #, $local_closures
2062 , $alltt_end, $reopens);
2063 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002064 };
2065 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002066 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002067}
2068
Fred Drake8effa012004-04-01 04:30:29 +00002069# List of all filenames produced by do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002070%VerbatimFiles = ();
2071@VerbatimOutputs = ();
2072
2073sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002074 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002075 #
2076 # Re-write the source filename to always use a .txt extension
2077 # so that Web servers will present it as text/plain. This is
2078 # needed since there is no other even moderately reliable way
2079 # to get the right Content-Type header on text files for
2080 # servers which we can't configure (like python.org mirrors).
2081 #
2082 if (defined $VerbatimFiles{$file}) {
2083 # We've seen this one before; re-use the same output file.
2084 return $VerbatimFiles{$file};
2085 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002086 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002087 $filename = "$srcname.txt";
2088 #
2089 # We need to determine if our default filename is already
2090 # being used, and find a new one it it is. If the name is in
2091 # used, this algorithm will first attempt to include the
2092 # source extension as part of the name, and if that is also in
2093 # use (if the same file is included multiple times, or if
2094 # another source file has that as the base name), a counter is
2095 # used instead.
2096 #
2097 my $found = 1;
2098 FIND:
2099 while ($found) {
2100 foreach $fn (@VerbatimOutputs) {
2101 if ($fn eq $filename) {
2102 if ($found == 1) {
2103 $srcext =~ s/^[.]//; # Remove '.' from extension
2104 $filename = "$srcname-$srcext.txt";
2105 }
2106 else {
2107 $filename = "$srcname-$found.txt";
2108 }
2109 ++$found;
2110 next FIND;
2111 }
2112 }
2113 $found = 0;
2114 }
2115 push @VerbatimOutputs, $filename;
2116 $VerbatimFiles{$file} = $filename;
2117 return $filename;
2118}
2119
Fred Drake57e52ef2001-06-15 21:31:57 +00002120sub do_cmd_verbatiminput{
2121 local($_) = @_;
2122 my $fname = next_argument();
2123 my $file;
2124 my $found = 0;
2125 my $texpath;
2126 # Search TEXINPUTS for the input file, the way we're supposed to:
2127 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2128 $file = "$texpath$dd$fname";
2129 last if ($found = (-f $file));
2130 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002131 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002132 my $text;
2133 if ($found) {
2134 open(MYFILE, "<$file") || die "\n$!\n";
2135 read(MYFILE, $text, 1024*1024);
2136 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002137 $filename = get_verbatim_output_name($file);
2138 # Now that we have a filename, write it out.
2139 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002140 print MYFILE $text;
2141 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002142 #
2143 # These rewrites convert the raw text to something that will
2144 # be properly visible as HTML and also will pass through the
2145 # vagaries of conversion through LaTeX2HTML. The order in
2146 # which the specific rewrites are performed is significant.
2147 #
2148 $text =~ s/\&/\&amp;/g;
2149 # These need to happen before the normal < and > re-writes,
2150 # since we need to avoid LaTeX2HTML's attempt to perform
2151 # ligature processing without regard to context (since it
2152 # doesn't have font information).
2153 $text =~ s/--/-&\#45;/g;
2154 $text =~ s/<</\&lt;\&\#60;/g;
2155 $text =~ s/>>/\&gt;\&\#62;/g;
2156 # Just normal re-writes...
2157 $text =~ s/</\&lt;/g;
2158 $text =~ s/>/\&gt;/g;
2159 # These last isn't needed for the HTML, but is needed to get
2160 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2161 # of &sol; since many browsers don't support that.
2162 $text =~ s/\\/\&\#92;/g;
2163 }
2164 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002165 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2166 }
2167 my $note = 'Download as text.';
2168 if ($file ne $filename) {
2169 $note = ('Download as text (original file name: <span class="file">'
2170 . $fname
2171 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002172 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002173 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002174 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002175 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002176 . "<a href=\"$filename\" type=\"text/plain\""
2177 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002178 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002179 . $_);
2180}
Fred Drake86333602001-04-10 17:13:39 +00002181
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021821; # This must be the last line