blob: cf0301ebd6d840a9358229dd270b9f306dd00fd3 [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 Drakec2b29d02001-04-18 03:11:04 +0000425 my $text = "$type in version $release.";
426 if ($explanation) {
427 $text = "$type in version $release:\n$explanation.";
428 }
Fred Drakef1927a62001-06-20 21:29:30 +0000429 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000430}
431
432sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000433 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000434}
435
436sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000437 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000438}
439
Fred Drake557460c1999-03-02 16:05:35 +0000440#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000441# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000442#
443sub do_cmd_platform{
444 local($_) = @_;
445 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000446 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000447 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000448 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000449 return "\n<p class=\"availability\">Availability: <span"
450 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000451}
452
Fred Drake557460c1999-03-02 16:05:35 +0000453$IGNORE_PLATFORM_ANNOTATION = '';
454sub do_cmd_ignorePlatformAnnotation{
455 local($_) = @_;
456 $IGNORE_PLATFORM_ANNOTATION = next_argument();
457 return $_;
458}
459
Fred Drake6659c301998-03-03 22:02:19 +0000460
461# index commands
462
463$INDEX_SUBITEM = "";
464
Fred Drakef5478632002-05-23 17:59:16 +0000465sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000466 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000467}
468
469sub do_cmd_setindexsubitem{
470 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000471 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000472 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000473}
474
Fred Drakefc16e781998-03-12 21:03:26 +0000475sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000476 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000477 # do things in the right order, but we need to at least strip this stuff
478 # out, and leave anything that the second argument expanded out to.
479 #
480 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000481 my $oldsubitem = $INDEX_SUBITEM;
482 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000483 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000484 my $br_id = ++$globals{'max_id'};
485 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000486 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000487 return
488 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000489 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000490 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000491}
492
Fred Drake08932051998-04-17 02:15:42 +0000493# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000494# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
495# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000496#
Fred Drake49b33fa2002-11-15 19:04:10 +0000497sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000498
Fred Drake42b31a51998-03-27 05:16:10 +0000499# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000500#
Fred Drake08932051998-04-17 02:15:42 +0000501open(IDXFILE, '>index.dat') || die "\n$!\n";
502open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000503print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000504print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000505
506# Using \0 for this is bad because we can't use common tools to work with the
507# resulting files. Things like grep can be useful with this stuff!
508#
509$IDXFILE_FIELD_SEP = "\1";
510
Fred Drakef5478632002-05-23 17:59:16 +0000511sub write_idxfile($$){
512 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000513 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000514}
515
Fred Drake42b31a51998-03-27 05:16:10 +0000516
Fred Drakef5478632002-05-23 17:59:16 +0000517sub gen_link($$){
518 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000519 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000520 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000521}
522
Fred Drakef5478632002-05-23 17:59:16 +0000523sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000524 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000525 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000526 $str = gen_index_id($str, '');
527 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000528 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000529}
530
Fred Drake04bf7242003-11-26 20:55:49 +0000531sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000532 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake42b31a51998-03-27 05:16:10 +0000533 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000534 return ($name, $ahref);
535}
536
537sub new_link_info(){
538 my($name, $ahref) = new_link_name_info();
Fred Drake0c1b2532004-10-29 19:47:52 +0000539 my $aname = "<a id='$name' xml:id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000540 return ($name, $aname, $ahref);
541}
542
Fred Drakeab032151999-05-13 18:36:54 +0000543$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000544sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000545 my $count = @_;
546 my $i = 0;
547 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000548 my $name = $_[$i];
549 my $cmd = "idx_cmd_$name";
550 die "\nNo function $cmd() defined!\n"
551 if (!defined &$cmd);
552 eval ("sub do_cmd_$name { return process_index_macros("
553 . "\$_[0], '$name'); }");
554 if (length($IndexMacroPattern) == 0) {
555 $IndexMacroPattern = "$name";
556 }
557 else {
558 $IndexMacroPattern .= "|$name";
559 }
Fred Drakeab032151999-05-13 18:36:54 +0000560 }
561}
562
563$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000564sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000565 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000566 my $cmdname = $_[1]; # This is what triggered us in the first place;
567 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000568 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000569 my $cmd = "idx_cmd_$cmdname";
570 print "\nIndexing: \\$cmdname"
571 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000572 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000573 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000574 $cmdname = "$1";
575 print " \\$cmdname"
576 if $DEBUG_INDEXING;
577 $cmd = "idx_cmd_$cmdname";
578 if (!defined &$cmd) {
579 last;
580 }
581 else {
582 s/^[\s\n]*\\$cmdname//;
583 &$cmd($ahref);
584 }
Fred Drakeab032151999-05-13 18:36:54 +0000585 }
Fred Drake899072a2004-04-08 15:30:12 +0000586# XXX I don't remember why I added this to begin with.
587# if (/^[ \t\r\n]/) {
588# $_ = substr($_, 1);
589# }
Fred Drake62e43691998-08-10 19:40:44 +0000590 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000591}
592
Fred Drakeab032151999-05-13 18:36:54 +0000593define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000594sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000595 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000596 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000597}
598
Fred Drakeab032151999-05-13 18:36:54 +0000599define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000600sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000601 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000602 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
603 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000604}
605
606define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000607sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000608 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000609 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000610 add_index_entry("$str1!$str2", $_[0]);
611 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000612}
613
Fred Drakeab032151999-05-13 18:36:54 +0000614define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000615sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000616 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000617 my $str2 = next_argument();
618 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000619 add_index_entry("$str1!$str2 $str3", $_[0]);
620 add_index_entry("$str2!$str3, $str1", $_[0]);
621 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000622}
623
Fred Drakeab032151999-05-13 18:36:54 +0000624define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000625sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000626 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000627 my $str2 = next_argument();
628 my $str3 = next_argument();
629 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000630 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
631 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
632 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
633 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000634}
635
Fred Drakeab032151999-05-13 18:36:54 +0000636define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000637sub idx_cmd_ttindex($){
Fred Drake345555d2003-12-30 16:19:28 +0000638 my $str = codetext(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +0000639 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000640 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000641}
Fred Drake6659c301998-03-03 22:02:19 +0000642
Fred Drakef5478632002-05-23 17:59:16 +0000643sub my_typed_index_helper($$){
644 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000645 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000646 add_index_entry("$str $word", $ahref);
647 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000648}
649
Fred Drakeab032151999-05-13 18:36:54 +0000650define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000651sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
652sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
653sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
654sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000655
Fred Drakeab032151999-05-13 18:36:54 +0000656define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000657sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000658 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000659 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000660 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000661}
662
663
Fred Drakef5478632002-05-23 17:59:16 +0000664sub make_mod_index_entry($$){
665 my($str, $define) = @_;
666 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000667 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000668 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
669 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000670 $str = gen_index_id($str, $define);
671 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000672 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000673
Fred Drakec9a44381998-03-17 06:29:13 +0000674 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000675 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000676 $str =~ /(<tt.*<\/tt>)/;
677 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000678 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000679 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000680 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000681}
682
Fred Drake557460c1999-03-02 16:05:35 +0000683
Fred Drakec9a44381998-03-17 06:29:13 +0000684$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000685$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000686
Fred Drakef5478632002-05-23 17:59:16 +0000687sub define_module($$){
688 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000689 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000690 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000691 && $word ne "standard" && $word ne "") {
692 write_warnings("Bad module type '$word'"
693 . " for \\declaremodule (module $name)");
694 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000695 }
Fred Drake6659c301998-03-03 22:02:19 +0000696 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000697 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000698 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000699 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000700 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000701 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000702}
703
Fred Drakef5478632002-05-23 17:59:16 +0000704sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000705 local($word, $_) = @_;
706 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000707 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000708}
709
Fred Drake49b33fa2002-11-15 19:04:10 +0000710sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
711sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
712sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
713sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
714# local($_) = @_;
715# my $name = next_argument();
716# return define_module('standard', $name) . $_;
717# }
Fred Drake6659c301998-03-03 22:02:19 +0000718
Fred Drakef5478632002-05-23 17:59:16 +0000719sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000720 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000721 my $str = next_argument();
722 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000723 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000724 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
725 # just inline it all here
726 $str = gen_index_id($str, 'REF');
727 $index{$str} .= $ahref;
728 write_idxfile($ahref, $str);
729}
730
Fred Drake6659c301998-03-03 22:02:19 +0000731# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000732define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000733 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000734sub idx_cmd_refmodindex($){
735 return ref_module_index_helper('', $_[0]); }
736sub idx_cmd_refbimodindex($){
737 return ref_module_index_helper('built-in', $_[0]); }
738sub idx_cmd_refexmodindex($){
739 return ref_module_index_helper('extension', $_[0]);}
740sub idx_cmd_refstmodindex($){
741 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000742
Fred Drake49b33fa2002-11-15 19:04:10 +0000743sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000744
Fred Drakef5478632002-05-23 17:59:16 +0000745sub init_myformat(){
Fred Drakeaf305b12004-11-11 08:05:34 +0000746 # This depends on the override of text_cleanup() in l2hinit.perl;
747 # if that function cleans out empty tags, the first three of these
748 # variables must be set to comments.
749 #
Fred Drake5d9c636f2003-08-05 05:00:23 +0000750 # Thanks to Dave Kuhlman for figuring why some named anchors were
751 # being lost.
Fred Drakeaf305b12004-11-11 08:05:34 +0000752 $anchor_invisible_mark = '';
753 $anchor_invisible_mark2 = '';
754 $anchor_mark = '';
Fred Drake6659c301998-03-03 22:02:19 +0000755 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000756}
Fred Drake42b31a51998-03-27 05:16:10 +0000757init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000758
Fred Drakeab032151999-05-13 18:36:54 +0000759# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000760# instead of the dummy filler.
761#
Fred Drakef5478632002-05-23 17:59:16 +0000762sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000763 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000764 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000765 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000766 if ($str =~ /^<[a-z]+\b/) {
767 my $s = "$str";
Fred Drake0c1b2532004-10-29 19:47:52 +0000768 $s =~ s/^<([a-z]+)\b/<$1 id='$name' xml:id='$name'/;
Fred Drake04bf7242003-11-26 20:55:49 +0000769 return $s;
770 }
771 else {
Fred Drake0c1b2532004-10-29 19:47:52 +0000772 return "<a id='$name' xml:id='$name'>$str</a>";
Fred Drake04bf7242003-11-26 20:55:49 +0000773 }
Fred Drake6659c301998-03-03 22:02:19 +0000774}
775
Fred Drake77602f22001-07-06 22:43:02 +0000776
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000777%TokenToTargetMapping = (); # language:token -> link target
778%DefinedGrammars = (); # language -> full grammar text
779%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000780
781sub do_cmd_token{
782 local($_) = @_;
783 my $token = next_argument();
784 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
785 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
786 # recursive definition or display-only productionlist
787 return "$token";
788 }
789 if ($target eq '') {
790 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
791 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
792 print "Adding '$CURRENT_FILE' to back-patch list.\n";
793 }
794 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
795 }
Fred Drake5d93eef2004-11-10 17:02:43 +0000796 return "<a class='grammartoken' href=\"$target\">$token</a>" . $_;
Fred Drake77602f22001-07-06 22:43:02 +0000797}
798
Fred Drake16bb4192001-08-20 21:36:38 +0000799sub do_cmd_grammartoken{
800 return do_cmd_token(@_);
801}
802
Fred Drake77602f22001-07-06 22:43:02 +0000803sub do_env_productionlist{
804 local($_) = @_;
805 my $lang = next_optional_argument();
806 my $filename = "grammar-$lang.txt";
807 if ($lang eq '') {
808 $filename = 'grammar.txt';
809 }
810 local($CURRENT_GRAMMAR) = $lang;
811 $DefinedGrammars{$lang} .= $_;
812 return ("<dl><dd class=\"grammar\">\n"
813 . "<div class=\"productions\">\n"
Fred Drake5d93eef2004-11-10 17:02:43 +0000814 . "<table>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000815 . translate_commands(translate_environments($_))
816 . "</table>\n"
817 . "</div>\n"
818 . (($lang eq '*')
819 ? ''
820 : ("<a class=\"grammar-footer\"\n"
821 . " href=\"$filename\" type=\"text/plain\"\n"
822 . " >Download entire grammar as text.</a>\n"))
823 . "</dd></dl>");
824}
825
826sub do_cmd_production{
827 local($_) = @_;
828 my $token = next_argument();
829 my $defn = next_argument();
830 my $lang = $CURRENT_GRAMMAR;
831 local($CURRENT_TOKEN) = $token;
832 if ($lang eq '*') {
Fred Drake5d93eef2004-11-10 17:02:43 +0000833 return ("<tr>\n"
834 . " <td>$token</td>\n"
835 . " <td>::=</td>\n"
836 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000837 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000838 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000839 . $_);
840 }
841 my $target;
842 if ($lang eq '') {
843 $target = "$CURRENT_FILE\#tok-$token";
844 }
845 else {
846 $target = "$CURRENT_FILE\#tok-$lang-$token";
847 }
848 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drake5d93eef2004-11-10 17:02:43 +0000849 return ("<tr>\n"
850 . " <td><a id='tok-$token' xml:id='tok-$token'>"
851 . "$token</a></td>\n"
852 . " <td>::=</td>\n"
853 . " <td>"
Fred Drake77602f22001-07-06 22:43:02 +0000854 . translate_commands($defn)
Fred Drake5d93eef2004-11-10 17:02:43 +0000855 . "</td></tr>"
Fred Drake77602f22001-07-06 22:43:02 +0000856 . $_);
857}
858
Fred Drake53815882002-03-15 23:21:37 +0000859sub do_cmd_productioncont{
860 local($_) = @_;
861 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000862 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake5d93eef2004-11-10 17:02:43 +0000863 return ("<tr>\n"
864 . " <td></td>\n"
865 . " <td></td>\n"
Fred Drake53815882002-03-15 23:21:37 +0000866 . " <td><code>"
867 . translate_commands($defn)
868 . "</code></td></tr>"
869 . $_);
870}
871
Fred Drakef5478632002-05-23 17:59:16 +0000872sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000873 my $lang;
874 my $filename;
875 local($_);
876 print "process_grammar_files()\n";
877 foreach $lang (keys %DefinedGrammars) {
878 $filename = "grammar-$lang.txt";
879 if ($lang eq '*') {
880 next;
881 }
882 if ($lang eq '') {
883 $filename = 'grammar.txt';
884 }
885 open(GRAMMAR, ">$filename") || die "\n$!\n";
Armin Rigo863f3d12006-09-07 15:06:00 +0000886 print GRAMMAR "##################################################\n";
887 print GRAMMAR "# This file is only meant to be a guide, #\n";
888 print GRAMMAR "# and differs in small ways from the real #\n";
889 print GRAMMAR "# grammar. The exact reference is the file #\n";
890 print GRAMMAR "# Grammar/Grammar distributed with the source. #\n";
891 print GRAMMAR "##################################################\n";
Fred Drake77602f22001-07-06 22:43:02 +0000892 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
893 close(GRAMMAR);
894 print "Wrote grammar file $filename\n";
895 }
896 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
897 foreach $filename (keys %BackpatchGrammarFiles) {
898 print "\nBack-patching grammar links in $filename\n";
899 my $buffer;
900 open(GRAMMAR, "<$filename") || die "\n$!\n";
901 # read all of the file into the buffer
902 sysread(GRAMMAR, $buffer, 1024*1024);
903 close(GRAMMAR);
904 while ($buffer =~ /$PATTERN/) {
905 my($lang, $token) = ($1, $2);
906 my $target = $TokenToTargetMapping{"$lang:$token"};
907 my $source = "<pyGrammarToken><$lang><$token>";
908 $buffer =~ s/$source/$target/g;
909 }
910 open(GRAMMAR, ">$filename") || die "\n$!\n";
911 print GRAMMAR $buffer;
912 close(GRAMMAR);
913 }
914}
915
Fred Drakef5478632002-05-23 17:59:16 +0000916sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000917 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000918 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000919 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
920 s/\\token(<<\d+>>)(.+)\1/$2/g;
921 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000922 s/<<\d+>>//g;
923 s/;SPMgt;/>/g;
924 s/;SPMlt;/</g;
925 s/;SPMquot;/\"/g;
926 return $_;
927}
928
929
Fred Drakee15956b2000-04-03 04:51:13 +0000930$REFCOUNTS_LOADED = 0;
931
Fred Drakef5478632002-05-23 17:59:16 +0000932sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000933 $REFCOUNTS_LOADED = 1;
934
Fred Drake49b33fa2002-11-15 19:04:10 +0000935 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000936 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000937 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000938 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000939 $mydir = getcwd() . "$dd$mydir"
940 unless $mydir =~ s|^/|/|;
941 local $_;
942 my $filename = "$mydir${dd}api${dd}refcounts.dat";
943 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
944 print "[loading API refcount data]";
945 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000946 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000947 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
948 #print "\n$func($param) --> $count";
949 $REFCOUNTS{"$func:$param"} = $count;
950 }
951 }
952}
953
Fred Drakef5478632002-05-23 17:59:16 +0000954sub get_refcount($$){
955 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000956 load_refcounts()
957 unless $REFCOUNTS_LOADED;
958 return $REFCOUNTS{"$func:$param"};
959}
960
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000961
962$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000963$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000964
Fred Drakef5478632002-05-23 17:59:16 +0000965sub cfuncline_helper($$$){
966 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000967 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000968 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000969 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000970 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000971 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
972 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000973 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
974 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
975 . "<td>$args)</td>"
976 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000977}
978sub do_cmd_cfuncline{
979 local($_) = @_;
980 my $type = next_argument();
981 my $name = next_argument();
982 my $args = next_argument();
983 my $siginfo = cfuncline_helper($type, $name, $args);
984 return "<dt>$siginfo\n<dd>" . $_;
985}
986sub do_env_cfuncdesc{
987 local($_) = @_;
988 my $type = next_argument();
989 my $name = next_argument();
990 my $args = next_argument();
991 my $siginfo = cfuncline_helper($type, $name, $args);
992 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000993 my $rcinfo = '';
994 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000995 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000996 }
997 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000998 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000999 }
Fred Drakec2578c52000-04-10 18:26:45 +00001000 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +00001001 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +00001002 }
Fred Drakee15956b2000-04-03 04:51:13 +00001003 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +00001004 $rcinfo = ( "\n<div class=\"refcount-info\">"
1005 . "\n <span class=\"label\">Return value:</span>"
1006 . "\n <span class=\"value\">$rcinfo.</span>"
1007 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +00001008 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001009 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001010 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +00001011 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001012 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001013}
1014
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001015sub do_cmd_cmemberline{
1016 local($_) = @_;
1017 my $container = next_argument();
1018 my $type = next_argument();
1019 my $name = next_argument();
1020 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001021 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001022 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001023 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001024 . $_;
1025}
1026sub do_env_cmemberdesc{
1027 local($_) = @_;
1028 my $container = next_argument();
1029 my $type = next_argument();
1030 my $name = next_argument();
1031 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001032 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001033 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001034 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001035 . $_
1036 . '</dl>';
1037}
1038
Fred Drakee15956b2000-04-03 04:51:13 +00001039sub do_env_csimplemacrodesc{
1040 local($_) = @_;
1041 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001042 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001043 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001044 . $_
1045 . '</dl>'
1046}
1047
Fred Drake6659c301998-03-03 22:02:19 +00001048sub do_env_ctypedesc{
1049 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001050 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001051 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001052 $index_name = $type_name
1053 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001054 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001055 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001056 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1057 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001058 . $_
1059 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001060}
1061
1062sub do_env_cvardesc{
1063 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001064 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001065 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001066 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001067 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001068 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001069 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001070 . '<dd>'
1071 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001072 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001073}
1074
Fred Drake3cdb89d2000-09-14 20:17:23 +00001075sub convert_args($){
1076 local($IN_DESC_HANDLER) = 1;
1077 local($_) = @_;
1078 return translate_commands($_);
1079}
1080
Fred Drakef6e90272002-06-18 18:24:16 +00001081sub funcline_helper($$$){
1082 my($first, $idxitem, $arglist) = @_;
1083 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001084 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1085 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001086 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001087}
1088
Fred Drake6659c301998-03-03 22:02:19 +00001089sub do_env_funcdesc{
1090 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001091 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001092 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001093 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1094 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001095 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001096 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001097 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001098 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001099}
1100
1101sub do_env_funcdescni{
1102 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001103 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001104 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001105 my $prefix = "<tt class=\"function\">$function_name</tt>";
1106 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001107}
1108
1109sub do_cmd_funcline{
1110 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001111 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001112 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001113 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001114 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1115 $prefix =~ s/\(\)//;
1116
Fred Drakef6e90272002-06-18 18:24:16 +00001117 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001118}
1119
Fred Drake6b3fb781999-07-12 16:50:09 +00001120sub do_cmd_funclineni{
1121 local($_) = @_;
1122 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001123 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001124 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001125
Fred Drakef6e90272002-06-18 18:24:16 +00001126 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001127}
1128
Fred Drake6659c301998-03-03 22:02:19 +00001129# Change this flag to index the opcode entries. I don't think it's very
1130# useful to index them, since they're only presented to describe the dis
1131# module.
1132#
1133$INDEX_OPCODES = 0;
1134
1135sub do_env_opcodedesc{
1136 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001137 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001138 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001139 my $idx;
1140 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001141 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001142 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001143 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001144 }
1145 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001146 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001147 }
1148 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001149 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001150 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001151 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001152 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001153}
1154
1155sub do_env_datadesc{
1156 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001157 my $dataname = next_argument();
1158 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001159 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001160 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001161 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001162 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001163}
1164
1165sub do_env_datadescni{
1166 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001167 my $idx = next_argument();
1168 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001169 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001170 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001171 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001172}
1173
1174sub do_cmd_dataline{
1175 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001176 my $data_name = next_argument();
1177 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001178 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001179 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001180}
1181
Fred Drakeadb272c2000-04-10 17:47:14 +00001182sub do_cmd_datalineni{
1183 local($_) = @_;
1184 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001185 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001186}
1187
Fred Drake42b31a51998-03-27 05:16:10 +00001188sub do_env_excdesc{
1189 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001190 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001191 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001192 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001193 . "\n<dd>"
1194 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001195 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001196}
1197
Fred Drake62e43691998-08-10 19:40:44 +00001198sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001199
1200
Fred Drakef5478632002-05-23 17:59:16 +00001201sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001202 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001203 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001204 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001205 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001206 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001207 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001208 my $prefix = "$TLSTART$what$TLEND$idx";
1209 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001210}
1211
Fred Drake643d76d2000-09-09 06:07:37 +00001212sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001213 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001214}
1215
Fred Drake06a01e82001-05-11 01:00:30 +00001216sub do_env_classdescstar{
1217 local($_) = @_;
1218 $THIS_CLASS = next_argument();
1219 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001220 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001221 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001222 my $prefix = "${TLSTART}class$TLEND$idx";
1223 # Can't use funcline_helper() since there is no args list.
1224 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001225}
1226
Fred Drake643d76d2000-09-09 06:07:37 +00001227sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001228 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001229}
1230
Fred Drake42b31a51998-03-27 05:16:10 +00001231
1232sub do_env_methoddesc{
1233 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001234 my $class_name = next_optional_argument();
1235 $class_name = $THIS_CLASS
1236 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001237 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001238 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001239 my $extra = '';
1240 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001241 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001242 }
Fred Drakef1927a62001-06-20 21:29:30 +00001243 my $idx = make_str_index_entry(
1244 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001245 $idx =~ s/ \(.*\)//;
1246 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001247 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001248}
1249
1250
Fred Drake7d45f6d1999-01-05 14:39:27 +00001251sub do_cmd_methodline{
1252 local($_) = @_;
1253 my $class_name = next_optional_argument();
1254 $class_name = $THIS_CLASS
1255 unless $class_name;
1256 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001257 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001258 my $extra = '';
1259 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001260 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001261 }
Fred Drakef1927a62001-06-20 21:29:30 +00001262 my $idx = make_str_index_entry(
1263 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001264 $idx =~ s/ \(.*\)//;
1265 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001266 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001267}
1268
1269
Fred Draked64a40d1998-09-10 18:59:13 +00001270sub do_cmd_methodlineni{
1271 local($_) = @_;
1272 next_optional_argument();
1273 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001274 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001275 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001276}
1277
Fred Drake42b31a51998-03-27 05:16:10 +00001278sub do_env_methoddescni{
1279 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001280 next_optional_argument();
1281 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001282 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001283 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001284}
1285
1286
1287sub do_env_memberdesc{
1288 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001289 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001290 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001291 $class = $THIS_CLASS
1292 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001293 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001294 $extra = " ($class attribute)"
1295 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001296 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001297 $idx =~ s/ \(.*\)//;
1298 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001299 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001300}
1301
1302
Fred Drake5ccf3301998-04-17 20:04:09 +00001303sub do_cmd_memberline{
1304 local($_) = @_;
1305 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001306 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001307 $class = $THIS_CLASS
1308 unless $class;
1309 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001310 $extra = " ($class attribute)"
1311 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001312 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001313 $idx =~ s/ \(.*\)//;
1314 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001315 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001316}
1317
Fred Drakef269e592001-07-17 23:05:57 +00001318
Fred Drake42b31a51998-03-27 05:16:10 +00001319sub do_env_memberdescni{
1320 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001321 next_optional_argument();
1322 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001323 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001324 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001325 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001326}
1327
1328
Fred Drake5ccf3301998-04-17 20:04:09 +00001329sub do_cmd_memberlineni{
1330 local($_) = @_;
1331 next_optional_argument();
1332 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001333 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001334}
1335
Fred Drakef269e592001-07-17 23:05:57 +00001336
Fred Drake9e927f12004-11-10 15:49:25 +00001337# For tables, we include a class on every cell to allow the CSS to set
1338# the text-align property; this is because support for styling columns
1339# via the <col> element appears nearly non-existant on even the latest
1340# browsers (Mozilla 1.7 is stable at the time of this writing).
1341# Hopefully this can be improved as browsers evolve.
1342
Fred Drakef269e592001-07-17 23:05:57 +00001343@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001344
Fred Drakecb199762001-08-16 21:56:24 +00001345%FontConversions = ('cdata' => 'tt class="cdata"',
1346 'character' => 'tt class="character"',
1347 'class' => 'tt class="class"',
1348 'command' => 'code',
1349 'constant' => 'tt class="constant"',
1350 'exception' => 'tt class="exception"',
1351 'file' => 'tt class="file"',
1352 'filenq' => 'tt class="file"',
1353 'kbd' => 'kbd',
1354 'member' => 'tt class="member"',
1355 'programopt' => 'b',
1356 'textrm' => '',
1357 );
1358
Fred Drakef5478632002-05-23 17:59:16 +00001359sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001360 # do a little magic on a font name to get the right behavior in the first
1361 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001362 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001363 if (defined $FontConversions{$font}) {
1364 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001365 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001366 return $font;
1367}
1368
Fred Drakef5478632002-05-23 17:59:16 +00001369sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001370 my $a = $_[0];
1371 if (!defined $a) {
1372 return '';
1373 }
Fred Drakee15956b2000-04-03 04:51:13 +00001374 my $mark = substr($a, 0, 1);
1375 my $r = '';
1376 if ($mark eq 'c')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001377 { $r = ' class="center"'; }
Fred Drakee15956b2000-04-03 04:51:13 +00001378 elsif ($mark eq 'r')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001379 { $r = ' class="right" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001380 elsif ($mark eq 'l')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001381 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001382 elsif ($mark eq 'p')
Fred Drake39a6a6d2004-11-10 15:37:54 +00001383 { $r = ' class="left" '; }
Fred Drakee15956b2000-04-03 04:51:13 +00001384 return $r;
1385}
1386
Fred Drakef5478632002-05-23 17:59:16 +00001387sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001388 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001389 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001390 my $a1 = figure_column_alignment($s1);
1391 my $a2 = figure_column_alignment($s2);
1392 my $a3 = figure_column_alignment($s3);
1393 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001394 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001395 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1396 $col_aligns[1] = "<td$a2>";
1397 $col_aligns[2] = "<td$a3>";
1398 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001399 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001400 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001401 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001402}
1403
Fred Drakef5478632002-05-23 17:59:16 +00001404sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001405 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001406 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001407 if ($font) {
1408 $sfont = "<$font>";
1409 $efont = "</$font>";
1410 $efont =~ s/ .*>/>/;
1411 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001412 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001413}
1414
1415sub do_env_tableii{
1416 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001417 my $arg = next_argument();
1418 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001419 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001420 my $h1 = next_argument();
1421 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001422 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001423 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001424 my $a1 = $col_aligns[0];
1425 my $a2 = $col_aligns[1];
1426 s/\\lineii</\\lineii[$a1|$a2]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001427 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001428 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001429 . "\n <tr>"
1430 . "\n $th1$h1</th>"
1431 . "\n $th2$h2</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001432 . "\n </tr>"
1433 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001434 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001435 . $_
1436 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001437 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001438}
1439
Fred Drakeda72b932000-09-21 15:58:02 +00001440sub do_env_longtableii{
1441 return do_env_tableii(@_);
1442}
1443
Fred Drake6659c301998-03-03 22:02:19 +00001444sub do_cmd_lineii{
1445 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001446 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001447 my $c1 = next_argument();
1448 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001449 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001450 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001451 my($c1align, $c2align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001452 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
1453 . " $c2align$c2</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001454 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001455}
1456
1457sub do_env_tableiii{
1458 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001459 my $arg = next_argument();
1460 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001461 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001462 my $h1 = next_argument();
1463 my $h2 = next_argument();
1464 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001465 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001466 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001467 my $a1 = $col_aligns[0];
1468 my $a2 = $col_aligns[1];
1469 my $a3 = $col_aligns[2];
1470 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001471 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001472 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001473 . "\n <tr>"
1474 . "\n $th1$h1</th>"
1475 . "\n $th2$h2</th>"
1476 . "\n $th3$h3</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001477 . "\n </tr>"
1478 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001479 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001480 . $_
1481 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001482 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001483}
1484
Fred Drakeda72b932000-09-21 15:58:02 +00001485sub do_env_longtableiii{
1486 return do_env_tableiii(@_);
1487}
1488
Fred Drake6659c301998-03-03 22:02:19 +00001489sub do_cmd_lineiii{
1490 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001491 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001492 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001493 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001494 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001495 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001496 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001497 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001498 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001499 . " $c2align$c2</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001500 . " $c3align$c3</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001501 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001502}
1503
Fred Drakea0f4c941998-07-24 22:16:04 +00001504sub do_env_tableiv{
1505 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001506 my $arg = next_argument();
1507 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001508 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001509 my $h1 = next_argument();
1510 my $h2 = next_argument();
1511 my $h3 = next_argument();
1512 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001513 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001514 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001515 my $a1 = $col_aligns[0];
1516 my $a2 = $col_aligns[1];
1517 my $a3 = $col_aligns[2];
1518 my $a4 = $col_aligns[3];
1519 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001520 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001521 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001522 . "\n <tr>"
1523 . "\n $th1$h1</th>"
1524 . "\n $th2$h2</th>"
1525 . "\n $th3$h3</th>"
1526 . "\n $th4$h4</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001527 . "\n </tr>"
1528 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001529 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001530 . $_
1531 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001532 . "\n</table></div>";
Fred Drake6659c301998-03-03 22:02:19 +00001533}
1534
Fred Drakeda72b932000-09-21 15:58:02 +00001535sub do_env_longtableiv{
1536 return do_env_tableiv(@_);
1537}
1538
Fred Drakea0f4c941998-07-24 22:16:04 +00001539sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001540 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001541 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001542 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001543 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001544 my $c3 = next_argument();
1545 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001546 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001547 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001548 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001549 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001550 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001551 . " $c3align$c3</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001552 . " $c4align$c4</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001553 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001554}
1555
Fred Drakef269e592001-07-17 23:05:57 +00001556sub do_env_tablev{
1557 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001558 my $arg = next_argument();
1559 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001560 my $font = fix_font(next_argument());
1561 my $h1 = next_argument();
1562 my $h2 = next_argument();
1563 my $h3 = next_argument();
1564 my $h4 = next_argument();
1565 my $h5 = next_argument();
1566 s/[\s\n]+//;
1567 $globals{'lineifont'} = $font;
1568 my $a1 = $col_aligns[0];
1569 my $a2 = $col_aligns[1];
1570 my $a3 = $col_aligns[2];
1571 my $a4 = $col_aligns[3];
1572 my $a5 = $col_aligns[4];
1573 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
Fred Drake0a3c8182004-11-10 19:22:05 +00001574 return '<div class="center"><table class="realtable">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001575 . "\n <thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001576 . "\n <tr>"
1577 . "\n $th1$h1</th>"
1578 . "\n $th2$h2</th>"
1579 . "\n $th3$h3</th>"
1580 . "\n $th4$h4</th>"
1581 . "\n $th5$h5</th>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001582 . "\n </tr>"
1583 . "\n </thead>"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001584 . "\n <tbody>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001585 . $_
1586 . "\n </tbody>"
Fred Drake0a3c8182004-11-10 19:22:05 +00001587 . "\n</table></div>";
Fred Drakef269e592001-07-17 23:05:57 +00001588}
1589
1590sub do_env_longtablev{
1591 return do_env_tablev(@_);
1592}
1593
1594sub do_cmd_linev{
1595 local($_) = @_;
1596 my $aligns = next_optional_argument();
1597 my $c1 = next_argument();
1598 my $c2 = next_argument();
1599 my $c3 = next_argument();
1600 my $c4 = next_argument();
1601 my $c5 = next_argument();
1602 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001603 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef5478632002-05-23 17:59:16 +00001604 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drake39a6a6d2004-11-10 15:37:54 +00001605 return "\n <tr>$c1align$sfont$c1$efont</td>\n"
Fred Drakef269e592001-07-17 23:05:57 +00001606 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001607 . " $c3align$c3</td>\n"
1608 . " $c4align$c4</td>\n"
Fred Drake39a6a6d2004-11-10 15:37:54 +00001609 . " $c5align$c5</td></tr>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001610 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001611}
1612
Fred Drake3be20742000-08-31 06:22:54 +00001613
1614# These can be used to control the title page appearance;
1615# they need a little bit of documentation.
1616#
1617# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1618# $ICONSERVER directory, or include path information (other than "./"). The
1619# default image type will be assumed if an extension is not provided.
1620#
1621# If specified, the "title page" will contain two colums: one containing the
1622# title/author/etc., and the other containing the graphic. Use the other
1623# four variables listed here to control specific details of the layout; all
1624# are optional.
1625#
1626# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1627# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1628# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1629# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1630# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1631
Fred Drakef5478632002-05-23 17:59:16 +00001632sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001633 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001634 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001635 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001636 }
1637 else {
1638 write_warnings("\nThis document has no title.");
1639 }
Fred Drake6659c301998-03-03 22:02:19 +00001640 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001641 if ($t_authorURL) {
1642 my $href = translate_commands($t_authorURL);
1643 $href = make_named_href('author', $href,
1644 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001645 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001646 $the_title .= "\n<p>$href</p>";
1647 }
Fred Drake3be20742000-08-31 06:22:54 +00001648 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001649 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001650 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001651 }
Fred Drake3be20742000-08-31 06:22:54 +00001652 }
1653 else {
1654 write_warnings("\nThere is no author for this document.");
1655 }
Fred Drake6659c301998-03-03 22:02:19 +00001656 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001657 $the_title .= "\n<p>$t_institute</p>";
1658 }
Fred Draked07868a1998-05-14 21:00:28 +00001659 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001660 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1661 }
Fred Drake6659c301998-03-03 22:02:19 +00001662 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001663 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001664 }
Fred Drake6659c301998-03-03 22:02:19 +00001665 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001666 $the_title .= "\n<p>";
1667 if ($PACKAGE_VERSION) {
1668 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001669 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001670 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001671 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001672 }
1673 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001674 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001675 }
1676 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001677 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001678 }
Fred Drake6659c301998-03-03 22:02:19 +00001679 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001680 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001681 }
1682 return $the_title;
1683}
1684
Fred Drakef5478632002-05-23 17:59:16 +00001685sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001686 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001687 my $graphic = "<td class=\"titlegraphic\"";
1688 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1689 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1690 $graphic .= "><img";
1691 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1692 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1693 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1694 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001695 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001696 return $graphic;
1697}
1698
Fred Drakef5478632002-05-23 17:59:16 +00001699sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001700 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001701 my $the_title = "\n";
1702 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001703 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001704 # body), but I don't see any other way to get this generated
1705 # at all. Browsers like Mozilla, that support navigation
1706 # links, can make use of this.
1707 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1708 . ($EXTERNAL_UP_TITLE
1709 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001710 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001711 }
1712 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001713 if ($TITLE_PAGE_GRAPHIC) {
1714 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1715 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1716 . "<tr align=\"right\">\n<td>"
1717 . make_my_titlepage()
1718 . "</td>\n"
1719 . make_my_titlegraphic()
1720 . "</tr>\n</table>");
1721 }
1722 else {
1723 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1724 . make_my_titlegraphic()
1725 . "<td>"
1726 . make_my_titlepage()
1727 . "</td></tr>\n</table>");
1728 }
1729 }
1730 else {
Fred Drake0a3c8182004-11-10 19:22:05 +00001731 $the_title .= ("\n<div class='center'>"
Fred Drake3be20742000-08-31 06:22:54 +00001732 . make_my_titlepage()
Fred Drake0a3c8182004-11-10 19:22:05 +00001733 . "\n</div>");
Fred Drake3be20742000-08-31 06:22:54 +00001734 }
1735 $the_title .= "\n</div>";
1736 return $the_title . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001737}
1738
1739
Fred Drake885215c1998-05-20 21:32:09 +00001740#
Fred Drakea0f4c941998-07-24 22:16:04 +00001741# Module synopsis support
1742#
1743
1744require SynopsisTable;
1745
Fred Drakef7685d71998-07-25 03:31:46 +00001746sub get_chapter_id(){
1747 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001748 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001749 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001750 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001751}
1752
Fred Drake643d76d2000-09-09 06:07:37 +00001753# 'chapter' => 'SynopsisTable instance'
1754%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001755
1756sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001757 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001758 my $key;
1759 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001760 if ($key eq $chap) {
1761 return $ModuleSynopses{$chap};
1762 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001763 }
Fred Drake643d76d2000-09-09 06:07:37 +00001764 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001765 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001766 return $st;
1767}
1768
Fred Drake62e43691998-08-10 19:40:44 +00001769sub do_cmd_moduleauthor{
1770 local($_) = @_;
1771 next_argument();
1772 next_argument();
1773 return $_;
1774}
1775
1776sub do_cmd_sectionauthor{
1777 local($_) = @_;
1778 next_argument();
1779 next_argument();
1780 return $_;
1781}
1782
Fred Drakea0f4c941998-07-24 22:16:04 +00001783sub do_cmd_declaremodule{
1784 local($_) = @_;
1785 my $key = next_optional_argument();
1786 my $type = next_argument();
1787 my $name = next_argument();
1788 my $st = get_synopsis_table(get_chapter_id());
1789 #
1790 $key = $name unless $key;
1791 $type = 'built-in' if $type eq 'builtin';
1792 $st->declare($name, $key, $type);
1793 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001794 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001795}
1796
1797sub do_cmd_modulesynopsis{
1798 local($_) = @_;
1799 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001800 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001801 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001802}
1803
1804sub do_cmd_localmoduletable{
1805 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001806 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001807 my $st = get_synopsis_table($chap);
1808 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001809 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001810}
1811
Fred Drakef5478632002-05-23 17:59:16 +00001812sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001813 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001814 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001815 my $st = $ModuleSynopses{$key};
1816 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001817 if ($file) {
1818 process_localmoduletables_in_file($file);
1819 }
1820 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001821 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001822 }
1823 }
1824}
1825
Fred Drakef5478632002-05-23 17:59:16 +00001826sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001827 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001828 open(MYFILE, "<$file");
1829 local($_);
1830 sysread(MYFILE, $_, 1024*1024);
1831 close(MYFILE);
1832 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001833 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001834 my $match = $&;
1835 my $chap = $1;
1836 my $st = get_synopsis_table($chap);
1837 my $data = $st->tohtml();
1838 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001839 }
Fred Drake643d76d2000-09-09 06:07:37 +00001840 open(MYFILE,">$file");
1841 print MYFILE $_;
1842 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001843}
Fred Drakef5478632002-05-23 17:59:16 +00001844sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001845 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001846 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001847}
Fred Drakea0f4c941998-07-24 22:16:04 +00001848
1849
1850#
1851# "See also:" -- references placed at the end of a \section
1852#
1853
1854sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001855 return ("<div class=\"seealso\">\n "
Fred Drake0cf87be2004-11-10 08:08:26 +00001856 . "<p class=\"heading\">See Also:</p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001857 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001858 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001859}
1860
Fred Drake5ed35fd2001-11-30 18:09:54 +00001861sub do_env_seealsostar{
1862 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001863 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001864 . '</div>');
1865}
1866
Fred Drakea0f4c941998-07-24 22:16:04 +00001867sub do_cmd_seemodule{
1868 # Insert the right magic to jump to the module definition. This should
1869 # work most of the time, at least for repeat builds....
1870 local($_) = @_;
1871 my $key = next_optional_argument();
1872 my $module = next_argument();
1873 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001874 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001875 $key = $module
1876 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001877 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001878 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001879 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001880 return ('<dl compact="compact" class="seemodule">'
Fred Drakef1927a62001-06-20 21:29:30 +00001881 . "\n <dt>Module <b><tt class=\"module\">"
1882 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1883 . "\n <dd>$text$period\n </dl>"
1884 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001885}
1886
Fred Drakee0197bf2001-04-12 04:03:22 +00001887sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001888 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001889 my $s = "$str";
1890 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1891 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1892 return $s;
1893}
1894
Fred Drakef5478632002-05-23 17:59:16 +00001895sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001896 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001897 my $rfcnum = next_argument();
1898 my $title = next_argument();
1899 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001900 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001901 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001902 my $attrtitle = strip_html_markup($title);
Fred Draked7a5bca2004-11-10 08:07:00 +00001903 return '<dl compact="compact" class="seerfc">'
Fred Drake37cc0c02000-04-26 18:05:24 +00001904 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001905 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001906 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001907 . "\n <dd>$text\n </dl>"
1908 . $_;
1909}
1910
Fred Drake643d76d2000-09-09 06:07:37 +00001911sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001912 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001913}
1914
1915sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001916 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001917 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001918}
1919
Fred Drake48449982000-09-12 17:52:33 +00001920sub do_cmd_seetitle{
1921 local($_) = @_;
1922 my $url = next_optional_argument();
1923 my $title = next_argument();
1924 my $text = next_argument();
1925 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001926 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001927 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001928 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001929 . "\n >$title$icon</a></em></dt>"
1930 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001931 . $_;
1932 }
Fred Draked7a5bca2004-11-10 08:07:00 +00001933 return '<dl compact="compact" class="seetitle">'
Fred Drake48449982000-09-12 17:52:33 +00001934 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001935 . "\n >$title</em></dt>"
1936 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001937 . $_;
1938}
1939
Fred Drake4f687b32004-01-08 14:57:27 +00001940sub do_cmd_seelink{
1941 local($_) = @_;
1942 my $url = next_argument();
1943 my $linktext = next_argument();
1944 my $text = next_argument();
1945 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001946 return '<dl compact="compact" class="seeurl">'
Fred Drake4f687b32004-01-08 14:57:27 +00001947 . "\n <dt><a href='$url'"
1948 . "\n >$linktext$icon</a></dt>"
1949 . "\n <dd>$text</dd>\n </dl>"
1950 . $_;
1951}
1952
Fred Drakeef4d1112000-05-09 16:17:51 +00001953sub do_cmd_seeurl{
1954 local($_) = @_;
1955 my $url = next_argument();
1956 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001957 my $icon = get_link_icon($url);
Fred Draked7a5bca2004-11-10 08:07:00 +00001958 return '<dl compact="compact" class="seeurl">'
Fred Drakeef4d1112000-05-09 16:17:51 +00001959 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001960 . "\n class=\"url\">$url$icon</a></dt>"
1961 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001962 . $_;
1963}
1964
Fred Drakea0f4c941998-07-24 22:16:04 +00001965sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001966 local($_) = @_;
1967 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001968 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001969}
1970
1971
1972#
Fred Drake885215c1998-05-20 21:32:09 +00001973# Definition list support.
1974#
1975
1976sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001977 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001978}
1979
1980sub do_cmd_term{
1981 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001982 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001983 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001984 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001985 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001986}
1987
1988
Fred Drake4e72e052003-07-15 22:00:36 +00001989# Commands listed here have process-order dependencies; these often
1990# are related to indexing operations.
1991# XXX Not sure why funclineni, methodlineni, and samp are here.
1992#
Fred Drake2ff880e1999-02-05 18:31:29 +00001993process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001994declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001995funcline # {} # {}
1996funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001997memberline # [] # {}
1998methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001999methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002000modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00002001bifuncindex # {}
2002exindex # {}
2003indexii # {} # {}
2004indexiii # {} # {} # {}
2005indexiv # {} # {} # {} # {}
2006kwindex # {}
2007obindex # {}
2008opindex # {}
2009stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002010platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002011samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002012setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002013withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002014_RAW_ARG_DEFERRED_CMDS_
2015
2016
Fred Drake8a5e6792002-04-15 18:41:31 +00002017$alltt_start = '<div class="verbatim"><pre>';
2018$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002019
Fred Drakef5478632002-05-23 17:59:16 +00002020sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002021 local ($_) = @_;
2022 local($closures,$reopens,@open_block_tags);
2023
2024 # get the tag-strings for all open tags
2025 local(@keep_open_tags) = @$open_tags_R;
2026 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2027
2028 # get the tags for text-level tags only
2029 $open_tags_R = [ @keep_open_tags ];
2030 local($local_closures, $local_reopens);
2031 ($local_closures, $local_reopens,@open_block_tags)
2032 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002033 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002034
2035 $open_tags_R = [ @open_block_tags ];
2036
2037 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002038 local($open_tags_R) = [ @open_block_tags ];
2039 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002040
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002041 local($cnt) = ++$global{'max_id'};
2042 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2043 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002044
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002045 $_ = &translate_environments($_);
2046 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002047
Fred Drake41aa0182003-09-05 15:43:00 +00002048 # remove spurious <BR> someone sticks in; not sure where they
2049 # actually come from
2050 # XXX the replacement space is there to accomodate something
2051 # broken that inserts a space in front of the first line of
2052 # the environment
2053 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002054
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002055 $_ = join('', $closures, $alltt_start, $local_reopens
2056 , $_
2057 , &balance_tags() #, $local_closures
2058 , $alltt_end, $reopens);
2059 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002060 };
2061 $open_tags_R = [ @keep_open_tags ];
Fred Drake345555d2003-12-30 16:19:28 +00002062 return codetext($_);
Fred Drake86333602001-04-10 17:13:39 +00002063}
2064
Fred Drake8effa012004-04-01 04:30:29 +00002065# List of all filenames produced by do_cmd_verbatiminput()
Fred Drake6fc22f62002-06-17 15:01:05 +00002066%VerbatimFiles = ();
2067@VerbatimOutputs = ();
2068
2069sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002070 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002071 #
2072 # Re-write the source filename to always use a .txt extension
2073 # so that Web servers will present it as text/plain. This is
2074 # needed since there is no other even moderately reliable way
2075 # to get the right Content-Type header on text files for
2076 # servers which we can't configure (like python.org mirrors).
2077 #
2078 if (defined $VerbatimFiles{$file}) {
2079 # We've seen this one before; re-use the same output file.
2080 return $VerbatimFiles{$file};
2081 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002082 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002083 $filename = "$srcname.txt";
2084 #
2085 # We need to determine if our default filename is already
2086 # being used, and find a new one it it is. If the name is in
2087 # used, this algorithm will first attempt to include the
2088 # source extension as part of the name, and if that is also in
2089 # use (if the same file is included multiple times, or if
2090 # another source file has that as the base name), a counter is
2091 # used instead.
2092 #
2093 my $found = 1;
2094 FIND:
2095 while ($found) {
2096 foreach $fn (@VerbatimOutputs) {
2097 if ($fn eq $filename) {
2098 if ($found == 1) {
2099 $srcext =~ s/^[.]//; # Remove '.' from extension
2100 $filename = "$srcname-$srcext.txt";
2101 }
2102 else {
2103 $filename = "$srcname-$found.txt";
2104 }
2105 ++$found;
2106 next FIND;
2107 }
2108 }
2109 $found = 0;
2110 }
2111 push @VerbatimOutputs, $filename;
2112 $VerbatimFiles{$file} = $filename;
2113 return $filename;
2114}
2115
Fred Drake57e52ef2001-06-15 21:31:57 +00002116sub do_cmd_verbatiminput{
2117 local($_) = @_;
2118 my $fname = next_argument();
2119 my $file;
2120 my $found = 0;
2121 my $texpath;
2122 # Search TEXINPUTS for the input file, the way we're supposed to:
2123 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2124 $file = "$texpath$dd$fname";
2125 last if ($found = (-f $file));
2126 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002127 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002128 my $text;
2129 if ($found) {
2130 open(MYFILE, "<$file") || die "\n$!\n";
2131 read(MYFILE, $text, 1024*1024);
2132 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002133 $filename = get_verbatim_output_name($file);
2134 # Now that we have a filename, write it out.
2135 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002136 print MYFILE $text;
2137 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002138 #
2139 # These rewrites convert the raw text to something that will
2140 # be properly visible as HTML and also will pass through the
2141 # vagaries of conversion through LaTeX2HTML. The order in
2142 # which the specific rewrites are performed is significant.
2143 #
2144 $text =~ s/\&/\&amp;/g;
2145 # These need to happen before the normal < and > re-writes,
2146 # since we need to avoid LaTeX2HTML's attempt to perform
2147 # ligature processing without regard to context (since it
2148 # doesn't have font information).
2149 $text =~ s/--/-&\#45;/g;
2150 $text =~ s/<</\&lt;\&\#60;/g;
2151 $text =~ s/>>/\&gt;\&\#62;/g;
2152 # Just normal re-writes...
2153 $text =~ s/</\&lt;/g;
2154 $text =~ s/>/\&gt;/g;
2155 # These last isn't needed for the HTML, but is needed to get
2156 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2157 # of &sol; since many browsers don't support that.
2158 $text =~ s/\\/\&\#92;/g;
2159 }
2160 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002161 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2162 }
2163 my $note = 'Download as text.';
2164 if ($file ne $filename) {
2165 $note = ('Download as text (original file name: <span class="file">'
2166 . $fname
2167 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002168 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002169 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002170 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002171 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002172 . "<a href=\"$filename\" type=\"text/plain\""
2173 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002174 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002175 . $_);
2176}
Fred Drake86333602001-04-10 17:13:39 +00002177
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021781; # This must be the last line