blob: 3c3f7be09c7ac03d48f6825f72685273a65f40af [file] [log] [blame]
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
Fred Drake6659c301998-03-03 22:02:19 +00002#
3# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
4#
5# Extension to LaTeX2HTML for documents using myformat.sty.
6# Subroutines of the form do_cmd_<name> here define translations
7# for LaTeX commands \<name> defined in the corresponding .sty file.
8
9package main;
10
Fred Drake49b33fa2002-11-15 19:04:10 +000011use warnings;
Fred Drake7a40c072000-10-02 14:43:38 +000012use File::Basename;
13
Fred Drake6659c301998-03-03 22:02:19 +000014
Fred Drake08932051998-04-17 02:15:42 +000015sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000016 my $param;
17 $param = missing_braces()
18 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
Fred Drake1b1ca0c2003-09-05 15:43:58 +000019 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000020 return $param;
Fred Drake08932051998-04-17 02:15:42 +000021}
22
23sub next_optional_argument{
Fred Drakef5478632002-05-23 17:59:16 +000024 my($param, $rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000025 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000026 return $param;
Fred Drake08932051998-04-17 02:15:42 +000027}
28
Fred Drake7a40c072000-10-02 14:43:38 +000029sub make_icon_filename($){
Fred Drake49b33fa2002-11-15 19:04:10 +000030 my($myname, $mydir, $myext) = fileparse($_[0], '\..*');
Fred Drake7a40c072000-10-02 14:43:38 +000031 chop $mydir;
32 if ($mydir eq '.') {
33 $mydir = $ICONSERVER;
34 }
35 $myext = ".$IMAGE_TYPE"
36 unless $myext;
37 return "$mydir$dd$myname$myext";
38}
39
Fred Drake7a40c072000-10-02 14:43:38 +000040sub get_link_icon($){
Fred Drake49b33fa2002-11-15 19:04:10 +000041 my $url = $_[0];
Fred Drake7a40c072000-10-02 14:43:38 +000042 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
43 # absolute URL; assume it points off-site
44 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
Fred Drakef1927a62001-06-20 21:29:30 +000045 return (" <img src=\"$icon\"\n"
46 . ' border="0" class="offsitelink"'
Fred Drake5f84c9b2000-10-03 06:05:25 +000047 . ($OFF_SITE_LINK_ICON_HEIGHT
Fred Drakef1927a62001-06-20 21:29:30 +000048 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000049 : '')
50 . ($OFF_SITE_LINK_ICON_WIDTH
Fred Drakef1927a62001-06-20 21:29:30 +000051 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000052 : '')
Fred Drakef1927a62001-06-20 21:29:30 +000053 . " alt=\"[off-site link]\"\n"
Fred Drake2fc88a62003-08-05 03:45:37 +000054 . " />");
Fred Drake7a40c072000-10-02 14:43:38 +000055 }
56 return '';
57}
Fred Drakee16f6791998-05-15 04:28:37 +000058
59# This is a fairly simple hack; it supports \let when it is used to create
60# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000061# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000062#
63sub do_cmd_let{
64 local($_) = @_;
65 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000066 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000067 if ($matched) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +000068 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
Fred Drakee16f6791998-05-15 04:28:37 +000071 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000072 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +000073 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
74 if ($matched) {
75 my($new, $char) = ($1, $3);
76 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
77 print "\ndefining handler for \\$new to insert '$char'\n";
78 }
79 else {
80 write_warnings("Could not interpret \\let construct...");
81 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000082 }
Fred Drake62e43691998-08-10 19:40:44 +000083 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000084}
85
86
Fred Drakec3fd45f2000-06-15 22:41:48 +000087# the older version of LaTeX2HTML we use doesn't support this, but we use it:
88
Fred Drake49b33fa2002-11-15 19:04:10 +000089sub do_cmd_textasciitilde{ '&#126;' . $_[0]; }
90sub do_cmd_textasciicircum{ '^' . $_[0]; }
91sub do_cmd_textbar{ '|' . $_[0]; }
Fred Drake7adcfad2003-07-10 17:04:45 +000092sub do_cmd_texteuro { '&#8364;' . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +000093sub do_cmd_textgreater{ '&gt;' . $_[0]; }
94sub do_cmd_textless{ '&lt;' . $_[0]; }
95sub do_cmd_textunderscore{ '_' . $_[0]; }
96sub do_cmd_infinity{ '&infin;' . $_[0]; }
97sub do_cmd_plusminus{ '&plusmn;' . $_[0]; }
Fred Drakebd5fdd92003-07-16 14:01:56 +000098sub do_cmd_menuselection{
99 return use_wrappers($_[0], '<span class="menuselection">', '</span>'); }
Fred Drake49b33fa2002-11-15 19:04:10 +0000100sub do_cmd_sub{ ' > ' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +0000101
102
Fred Drake6659c301998-03-03 22:02:19 +0000103# words typeset in a special way (not in HTML though)
104
Fred Drake49b33fa2002-11-15 19:04:10 +0000105sub do_cmd_ABC{ 'ABC' . $_[0]; }
Fred Drake5bbeb8d2003-02-04 15:01:37 +0000106sub do_cmd_UNIX{ '<font style="font-variant: small-caps;">Unix</font>'
107 . $_[0]; }
Fred Drake49b33fa2002-11-15 19:04:10 +0000108sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
109sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
110sub do_cmd_C{ 'C' . $_[0]; }
111sub do_cmd_Cpp{ 'C++' . $_[0]; }
112sub do_cmd_EOF{ 'EOF' . $_[0]; }
113sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000114
Fred Drake49b33fa2002-11-15 19:04:10 +0000115sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000116
Fred Draked07868a1998-05-14 21:00:28 +0000117$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000118$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000119$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000120$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000121
Fred Drake49b33fa2002-11-15 19:04:10 +0000122sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
123sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000124sub do_cmd_release{
125 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000126 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000127 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000128}
129
Fred Drakef1927a62001-06-20 21:29:30 +0000130sub do_cmd_setreleaseinfo{
131 local($_) = @_;
132 $RELEASE_INFO = next_argument();
133 return $_;
134}
135
Fred Drake3cdb89d2000-09-14 20:17:23 +0000136sub do_cmd_setshortversion{
137 local($_) = @_;
138 $SHORT_VERSION = next_argument();
139 return $_;
140}
141
Fred Drake6659c301998-03-03 22:02:19 +0000142sub do_cmd_authoraddress{
143 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000144 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000145 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000146}
147
Fred Drake49b33fa2002-11-15 19:04:10 +0000148#sub do_cmd_developer{ do_cmd_author($_[0]); }
149#sub do_cmd_developers{ do_cmd_author($_[0]); }
150#sub do_cmd_developersaddress{ do_cmd_authoraddress($_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000151
Fred Drake6659c301998-03-03 22:02:19 +0000152sub 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 Drakef5478632002-05-23 17:59:16 +0000158sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000159 local($_,$before,$after) = @_;
160 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000161 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000162}
163
Fred Drake3cdb89d2000-09-14 20:17:23 +0000164$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000165sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000166 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000167 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000168 "</var><big>\]</big><var>");
169 }
170 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000171 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000172 }
Fred Drake6659c301998-03-03 22:02:19 +0000173}
174
Fred Drakec9a44381998-03-17 06:29:13 +0000175# Logical formatting (some based on texinfo), needs to be converted to
176# minimalist HTML. The "minimalist" is primarily to reduce the size of
177# output files for users that read them over the network rather than
178# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000179
Fred Drake49b33fa2002-11-15 19:04:10 +0000180sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000181sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000182 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000183sub do_cmd_code{
Fred Drake49b33fa2002-11-15 19:04:10 +0000184 return use_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000185sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000186 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000187sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000188 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000189sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000190 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000191sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000192 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000193sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000194 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000195sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000196 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000197sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000198 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000199sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000200 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000201sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000202 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000203sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000204 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000205sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000206 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000207sub do_cmd_regexp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000208 return use_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000209sub do_cmd_character{
Fred Drake49b33fa2002-11-15 19:04:10 +0000210 return use_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000211sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000212 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000213sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000214 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000215sub do_cmd_longprogramopt{
216 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000217 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000218sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000219 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000220sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000221 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000222sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000223 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000224sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000225 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000226sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000227 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000228sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000229 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000230sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000231 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000232sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000233 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000234sub do_cmd_samp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000235 return use_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000236sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000237 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000238sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000239 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000240sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000241 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000242sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000243 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000244# This can be changed/overridden for translations:
245%NoticeNames = ('note' => 'Note:',
246 'warning' => 'Warning:',
247 );
248
Fred Drake92350b32001-10-09 18:01:23 +0000249sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000250 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000251 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000252 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000253 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000254 '</span>'); }
255sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000256 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000257 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000258 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000259 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000260 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000261
Fred Drake6ca33772001-12-14 22:50:06 +0000262sub do_env_notice{
263 local($_) = @_;
264 my $notice = next_optional_argument();
265 if (!$notice) {
266 $notice = 'note';
267 }
268 my $label = $NoticeNames{$notice};
269 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
270 . $_
271 . '</div>');
272}
273
Fred Drake3d5a04a2000-08-03 17:25:44 +0000274sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000275 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000276sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000277 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000278
Fred Drakec9a44381998-03-17 06:29:13 +0000279
Fred Drake25817041999-01-13 17:06:34 +0000280sub do_cmd_refmodule{
281 # Insert the right magic to jump to the module definition.
282 local($_) = @_;
283 my $key = next_optional_argument();
284 my $module = next_argument();
285 $key = $module
286 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000287 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000288 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000289}
290
Fred Drake1a7af391998-04-01 22:44:56 +0000291sub do_cmd_newsgroup{
292 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000293 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000294 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000295 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
296 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000297 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000298}
Fred Drakefc16e781998-03-12 21:03:26 +0000299
300sub do_cmd_envvar{
301 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000302 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000303 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000304 # The <tt> here is really to keep buildindex.py from making
305 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000306 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000307 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000308 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000309 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000310 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000311}
312
Fred Drake6659c301998-03-03 22:02:19 +0000313sub do_cmd_url{
314 # use the URL as both text and hyperlink
315 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000316 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000317 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000318 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000319 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000320}
321
322sub do_cmd_manpage{
323 # two parameters: \manpage{name}{section}
324 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000325 my $page = next_argument();
326 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000327 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000328}
329
Fred Drakedbfe7682002-04-03 02:47:14 +0000330$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000331#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
332$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000333
334sub get_rfc_url($$){
335 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000336 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000337}
338
339sub do_cmd_pep{
340 local($_) = @_;
341 my $rfcnumber = next_argument();
342 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000343 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000344 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000345 # Save the reference
346 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
347 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake04bf7242003-11-26 20:55:49 +0000348 return ("<a class=\"rfc\" id='$id'\n"
Fred Drake2fc88a62003-08-05 03:45:37 +0000349 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000350}
351
Fred Drake6659c301998-03-03 22:02:19 +0000352sub do_cmd_rfc{
353 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000354 my $rfcnumber = next_argument();
355 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000356 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000357 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000358 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000359 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000360 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake04bf7242003-11-26 20:55:49 +0000361 return ("<a class=\"rfc\" id='$id'\nhref=\"$href\">"
Fred Drake2fc88a62003-08-05 03:45:37 +0000362 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000363}
364
Fred Drake77602f22001-07-06 22:43:02 +0000365sub do_cmd_ulink{
366 local($_) = @_;
367 my $text = next_argument();
368 my $url = next_argument();
369 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
370}
371
Fred Drakec9f5fe01999-11-09 16:59:42 +0000372sub do_cmd_citetitle{
373 local($_) = @_;
374 my $url = next_optional_argument();
375 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000376 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000377 my $repl = '';
378 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000379 $repl = ("<em class=\"citetitle\"><a\n"
380 . " href=\"$url\"\n"
381 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000382 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000383 }
384 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000385 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000386 }
387 return $repl . $_;
388}
389
Fred Drake6659c301998-03-03 22:02:19 +0000390sub do_cmd_deprecated{
391 # two parameters: \deprecated{version}{whattodo}
392 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000393 my $release = next_argument();
394 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000395 return ('<div class="versionnote">'
396 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000397 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000398 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000399}
400
Fred Drakef5478632002-05-23 17:59:16 +0000401sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000402 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000403 my $type = $_[0];
404 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000405 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000406 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000407 my $text = "$type in version $release.";
408 if ($explanation) {
409 $text = "$type in version $release:\n$explanation.";
410 }
Fred Drakef1927a62001-06-20 21:29:30 +0000411 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000412}
413
414sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000415 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000416}
417
418sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000419 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000420}
421
Fred Drake557460c1999-03-02 16:05:35 +0000422#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000423# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000424#
425sub do_cmd_platform{
426 local($_) = @_;
427 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000428 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000429 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000430 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000431 return "\n<p class=\"availability\">Availability: <span"
432 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000433}
434
Fred Drake557460c1999-03-02 16:05:35 +0000435$IGNORE_PLATFORM_ANNOTATION = '';
436sub do_cmd_ignorePlatformAnnotation{
437 local($_) = @_;
438 $IGNORE_PLATFORM_ANNOTATION = next_argument();
439 return $_;
440}
441
Fred Drake6659c301998-03-03 22:02:19 +0000442
443# index commands
444
445$INDEX_SUBITEM = "";
446
Fred Drakef5478632002-05-23 17:59:16 +0000447sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000448 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000449}
450
451sub do_cmd_setindexsubitem{
452 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000453 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000454 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000455}
456
Fred Drakefc16e781998-03-12 21:03:26 +0000457sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000458 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000459 # do things in the right order, but we need to at least strip this stuff
460 # out, and leave anything that the second argument expanded out to.
461 #
462 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000463 my $oldsubitem = $INDEX_SUBITEM;
464 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000465 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000466 my $br_id = ++$globals{'max_id'};
467 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000468 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000469 return
470 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000471 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000472 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000473}
474
Fred Drake08932051998-04-17 02:15:42 +0000475# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000476# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
477# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000478#
Fred Drake49b33fa2002-11-15 19:04:10 +0000479sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000480
Fred Drake42b31a51998-03-27 05:16:10 +0000481# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000482#
Fred Drake08932051998-04-17 02:15:42 +0000483open(IDXFILE, '>index.dat') || die "\n$!\n";
484open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000485print INTLABELS "%internal_labels = ();\n";
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000486print INTLABELS "1; # hack in case there are no entries\n\n";
Fred Drake166abba1998-04-08 23:10:54 +0000487
488# Using \0 for this is bad because we can't use common tools to work with the
489# resulting files. Things like grep can be useful with this stuff!
490#
491$IDXFILE_FIELD_SEP = "\1";
492
Fred Drakef5478632002-05-23 17:59:16 +0000493sub write_idxfile($$){
494 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000495 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000496}
497
Fred Drake42b31a51998-03-27 05:16:10 +0000498
Fred Drakef5478632002-05-23 17:59:16 +0000499sub gen_link($$){
500 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000501 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000502 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000503}
504
Fred Drakef5478632002-05-23 17:59:16 +0000505sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000506 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000507 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000508 $str = gen_index_id($str, '');
509 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000510 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000511}
512
Fred Drake04bf7242003-11-26 20:55:49 +0000513sub new_link_name_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000514 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drake04bf7242003-11-26 20:55:49 +0000515 my $aname = "<a id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000516 my $ahref = gen_link($CURRENT_FILE, $name);
Fred Drake04bf7242003-11-26 20:55:49 +0000517 return ($name, $ahref);
518}
519
520sub new_link_info(){
521 my($name, $ahref) = new_link_name_info();
522 my $aname = "<a id='$name'>";
Fred Drake42b31a51998-03-27 05:16:10 +0000523 return ($name, $aname, $ahref);
524}
525
Fred Drakeab032151999-05-13 18:36:54 +0000526$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000527sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000528 my $count = @_;
529 my $i = 0;
530 for (; $i < $count; ++$i) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000531 my $name = $_[$i];
532 my $cmd = "idx_cmd_$name";
533 die "\nNo function $cmd() defined!\n"
534 if (!defined &$cmd);
535 eval ("sub do_cmd_$name { return process_index_macros("
536 . "\$_[0], '$name'); }");
537 if (length($IndexMacroPattern) == 0) {
538 $IndexMacroPattern = "$name";
539 }
540 else {
541 $IndexMacroPattern .= "|$name";
542 }
Fred Drakeab032151999-05-13 18:36:54 +0000543 }
544}
545
546$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000547sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000548 local($_) = @_;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000549 my $cmdname = $_[1]; # This is what triggered us in the first place;
550 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000551 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000552 my $cmd = "idx_cmd_$cmdname";
553 print "\nIndexing: \\$cmdname"
554 if $DEBUG_INDEXING;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000555 &$cmd($ahref); # modifies $_ and adds index entries
Fred Drakeab032151999-05-13 18:36:54 +0000556 while (/^[\s\n]*\\($IndexMacroPattern)</) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000557 $cmdname = "$1";
558 print " \\$cmdname"
559 if $DEBUG_INDEXING;
560 $cmd = "idx_cmd_$cmdname";
561 if (!defined &$cmd) {
562 last;
563 }
564 else {
565 s/^[\s\n]*\\$cmdname//;
566 &$cmd($ahref);
567 }
Fred Drakeab032151999-05-13 18:36:54 +0000568 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000569 if (/^[ \t\r\n]/) {
570 $_ = substr($_, 1);
571 }
Fred Drake62e43691998-08-10 19:40:44 +0000572 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000573}
574
Fred Drakeab032151999-05-13 18:36:54 +0000575define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000576sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000577 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000578 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000579}
580
Fred Drakeab032151999-05-13 18:36:54 +0000581define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000582sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000583 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000584 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
585 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000586}
587
588define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000589sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000590 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000591 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000592 add_index_entry("$str1!$str2", $_[0]);
593 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000594}
595
Fred Drakeab032151999-05-13 18:36:54 +0000596define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000597sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000598 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000599 my $str2 = next_argument();
600 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000601 add_index_entry("$str1!$str2 $str3", $_[0]);
602 add_index_entry("$str2!$str3, $str1", $_[0]);
603 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000604}
605
Fred Drakeab032151999-05-13 18:36:54 +0000606define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000607sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000608 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000609 my $str2 = next_argument();
610 my $str3 = next_argument();
611 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000612 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
613 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
614 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
615 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000616}
617
Fred Drakeab032151999-05-13 18:36:54 +0000618define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000619sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000620 my $str = next_argument();
621 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000622 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000623}
Fred Drake6659c301998-03-03 22:02:19 +0000624
Fred Drakef5478632002-05-23 17:59:16 +0000625sub my_typed_index_helper($$){
626 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000627 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000628 add_index_entry("$str $word", $ahref);
629 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000630}
631
Fred Drakeab032151999-05-13 18:36:54 +0000632define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000633sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
634sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
635sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
636sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000637
Fred Drakeab032151999-05-13 18:36:54 +0000638define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000639sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000640 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000641 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000642 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000643}
644
645
Fred Drakef5478632002-05-23 17:59:16 +0000646sub make_mod_index_entry($$){
647 my($str, $define) = @_;
648 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000649 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000650 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
651 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000652 $str = gen_index_id($str, $define);
653 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000654 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000655
Fred Drakec9a44381998-03-17 06:29:13 +0000656 if ($define eq 'DEF') {
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000657 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000658 $str =~ /(<tt.*<\/tt>)/;
659 my $nstr = $1;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000660 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000661 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000662 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000663}
664
Fred Drake557460c1999-03-02 16:05:35 +0000665
Fred Drakec9a44381998-03-17 06:29:13 +0000666$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000667$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000668
Fred Drakef5478632002-05-23 17:59:16 +0000669sub define_module($$){
670 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000671 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000672 if ($word ne "built-in" && $word ne "extension"
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000673 && $word ne "standard" && $word ne "") {
674 write_warnings("Bad module type '$word'"
675 . " for \\declaremodule (module $name)");
676 $word = "";
Fred Drake3e4c6141999-05-17 15:00:32 +0000677 }
Fred Drake6659c301998-03-03 22:02:19 +0000678 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000679 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000680 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000681 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000682 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000683 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000684}
685
Fred Drakef5478632002-05-23 17:59:16 +0000686sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000687 local($word, $_) = @_;
688 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000689 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000690}
691
Fred Drake49b33fa2002-11-15 19:04:10 +0000692sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
693sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
694sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
695sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
696# local($_) = @_;
697# my $name = next_argument();
698# return define_module('standard', $name) . $_;
699# }
Fred Drake6659c301998-03-03 22:02:19 +0000700
Fred Drakef5478632002-05-23 17:59:16 +0000701sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000702 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000703 my $str = next_argument();
704 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000705 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000706 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
707 # just inline it all here
708 $str = gen_index_id($str, 'REF');
709 $index{$str} .= $ahref;
710 write_idxfile($ahref, $str);
711}
712
Fred Drake6659c301998-03-03 22:02:19 +0000713# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000714define_indexing_macro('refmodindex', 'refbimodindex',
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000715 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000716sub idx_cmd_refmodindex($){
717 return ref_module_index_helper('', $_[0]); }
718sub idx_cmd_refbimodindex($){
719 return ref_module_index_helper('built-in', $_[0]); }
720sub idx_cmd_refexmodindex($){
721 return ref_module_index_helper('extension', $_[0]);}
722sub idx_cmd_refstmodindex($){
723 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000724
Fred Drake49b33fa2002-11-15 19:04:10 +0000725sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000726
Fred Drakef5478632002-05-23 17:59:16 +0000727sub init_myformat(){
Fred Drake5d9c636f2003-08-05 05:00:23 +0000728 # These markers must be non-empty or the main latex2html script
729 # may remove a surrounding element that has not other content as
730 # "extraneous"; this ensures these elements (usually hyperlink
731 # targets) are not removed improperly. We use comments since
732 # there's no meaningful actual content.
733 # Thanks to Dave Kuhlman for figuring why some named anchors were
734 # being lost.
735 $anchor_invisible_mark = '<!--x-->';
736 $anchor_invisible_mark2 = '<!--y-->';
737 $anchor_mark = '<!--z-->';
Fred Drake6659c301998-03-03 22:02:19 +0000738 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000739}
Fred Drake42b31a51998-03-27 05:16:10 +0000740init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000741
Fred Drakeab032151999-05-13 18:36:54 +0000742# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000743# instead of the dummy filler.
744#
Fred Drakef5478632002-05-23 17:59:16 +0000745sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000746 my $str = $_[0];
Fred Drake04bf7242003-11-26 20:55:49 +0000747 my($name, $ahref) = new_link_name_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000748 add_index_entry($str, $ahref);
Fred Drake04bf7242003-11-26 20:55:49 +0000749 if ($str =~ /^<[a-z]+\b/) {
750 my $s = "$str";
751 $s =~ s/^<([a-z]+)\b/<$1 id='$name'/;
752 return $s;
753 }
754 else {
755 return "<a id='$name'>$str</a>";
756 }
Fred Drake6659c301998-03-03 22:02:19 +0000757}
758
Fred Drake77602f22001-07-06 22:43:02 +0000759
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000760%TokenToTargetMapping = (); # language:token -> link target
761%DefinedGrammars = (); # language -> full grammar text
762%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000763
764sub do_cmd_token{
765 local($_) = @_;
766 my $token = next_argument();
767 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
768 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
769 # recursive definition or display-only productionlist
770 return "$token";
771 }
772 if ($target eq '') {
773 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
774 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
775 print "Adding '$CURRENT_FILE' to back-patch list.\n";
776 }
777 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
778 }
779 return "<a href=\"$target\">$token</a>" . $_;
780}
781
Fred Drake16bb4192001-08-20 21:36:38 +0000782sub do_cmd_grammartoken{
783 return do_cmd_token(@_);
784}
785
Fred Drake77602f22001-07-06 22:43:02 +0000786sub do_env_productionlist{
787 local($_) = @_;
788 my $lang = next_optional_argument();
789 my $filename = "grammar-$lang.txt";
790 if ($lang eq '') {
791 $filename = 'grammar.txt';
792 }
793 local($CURRENT_GRAMMAR) = $lang;
794 $DefinedGrammars{$lang} .= $_;
795 return ("<dl><dd class=\"grammar\">\n"
796 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000797 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000798 . translate_commands(translate_environments($_))
799 . "</table>\n"
800 . "</div>\n"
801 . (($lang eq '*')
802 ? ''
803 : ("<a class=\"grammar-footer\"\n"
804 . " href=\"$filename\" type=\"text/plain\"\n"
805 . " >Download entire grammar as text.</a>\n"))
806 . "</dd></dl>");
807}
808
809sub do_cmd_production{
810 local($_) = @_;
811 my $token = next_argument();
812 my $defn = next_argument();
813 my $lang = $CURRENT_GRAMMAR;
814 local($CURRENT_TOKEN) = $token;
815 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000816 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000817 . " <td><code>$token</code></td>\n"
818 . " <td>&nbsp;::=&nbsp;</td>\n"
819 . " <td><code>"
820 . translate_commands($defn)
821 . "</code></td></tr>"
822 . $_);
823 }
824 my $target;
825 if ($lang eq '') {
826 $target = "$CURRENT_FILE\#tok-$token";
827 }
828 else {
829 $target = "$CURRENT_FILE\#tok-$lang-$token";
830 }
831 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000832 return ("<tr valign=\"baseline\">\n"
Fred Drake04bf7242003-11-26 20:55:49 +0000833 . " <td><code><a id='tok-$token'>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000834 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000835 . " <td>&nbsp;::=&nbsp;</td>\n"
836 . " <td><code>"
837 . translate_commands($defn)
838 . "</code></td></tr>"
839 . $_);
840}
841
Fred Drake53815882002-03-15 23:21:37 +0000842sub do_cmd_productioncont{
843 local($_) = @_;
844 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000845 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000846 return ("<tr valign=\"baseline\">\n"
847 . " <td>&nbsp;</td>\n"
848 . " <td>&nbsp;</td>\n"
849 . " <td><code>"
850 . translate_commands($defn)
851 . "</code></td></tr>"
852 . $_);
853}
854
Fred Drakef5478632002-05-23 17:59:16 +0000855sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000856 my $lang;
857 my $filename;
858 local($_);
859 print "process_grammar_files()\n";
860 foreach $lang (keys %DefinedGrammars) {
861 $filename = "grammar-$lang.txt";
862 if ($lang eq '*') {
863 next;
864 }
865 if ($lang eq '') {
866 $filename = 'grammar.txt';
867 }
868 open(GRAMMAR, ">$filename") || die "\n$!\n";
869 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
870 close(GRAMMAR);
871 print "Wrote grammar file $filename\n";
872 }
873 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
874 foreach $filename (keys %BackpatchGrammarFiles) {
875 print "\nBack-patching grammar links in $filename\n";
876 my $buffer;
877 open(GRAMMAR, "<$filename") || die "\n$!\n";
878 # read all of the file into the buffer
879 sysread(GRAMMAR, $buffer, 1024*1024);
880 close(GRAMMAR);
881 while ($buffer =~ /$PATTERN/) {
882 my($lang, $token) = ($1, $2);
883 my $target = $TokenToTargetMapping{"$lang:$token"};
884 my $source = "<pyGrammarToken><$lang><$token>";
885 $buffer =~ s/$source/$target/g;
886 }
887 open(GRAMMAR, ">$filename") || die "\n$!\n";
888 print GRAMMAR $buffer;
889 close(GRAMMAR);
890 }
891}
892
Fred Drakef5478632002-05-23 17:59:16 +0000893sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000894 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000895 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000896 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
897 s/\\token(<<\d+>>)(.+)\1/$2/g;
898 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000899 s/<<\d+>>//g;
900 s/;SPMgt;/>/g;
901 s/;SPMlt;/</g;
902 s/;SPMquot;/\"/g;
903 return $_;
904}
905
906
Fred Drakee15956b2000-04-03 04:51:13 +0000907$REFCOUNTS_LOADED = 0;
908
Fred Drakef5478632002-05-23 17:59:16 +0000909sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000910 $REFCOUNTS_LOADED = 1;
911
Fred Drake49b33fa2002-11-15 19:04:10 +0000912 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000913 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000914 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000915 chop $mydir; # remove trailing '/'
Fred Drakee15956b2000-04-03 04:51:13 +0000916 $mydir = getcwd() . "$dd$mydir"
917 unless $mydir =~ s|^/|/|;
918 local $_;
919 my $filename = "$mydir${dd}api${dd}refcounts.dat";
920 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
921 print "[loading API refcount data]";
922 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000923 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000924 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
925 #print "\n$func($param) --> $count";
926 $REFCOUNTS{"$func:$param"} = $count;
927 }
928 }
929}
930
Fred Drakef5478632002-05-23 17:59:16 +0000931sub get_refcount($$){
932 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000933 load_refcounts()
934 unless $REFCOUNTS_LOADED;
935 return $REFCOUNTS{"$func:$param"};
936}
937
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000938
939$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000940$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000941
Fred Drakef5478632002-05-23 17:59:16 +0000942sub cfuncline_helper($$$){
943 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000944 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000945 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000946 $idx =~ s/ \(.*\)//;
Fred Drake1b1ca0c2003-09-05 15:43:58 +0000947 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000948 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
949 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000950 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
951 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
952 . "<td>$args)</td>"
953 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000954}
955sub do_cmd_cfuncline{
956 local($_) = @_;
957 my $type = next_argument();
958 my $name = next_argument();
959 my $args = next_argument();
960 my $siginfo = cfuncline_helper($type, $name, $args);
961 return "<dt>$siginfo\n<dd>" . $_;
962}
963sub do_env_cfuncdesc{
964 local($_) = @_;
965 my $type = next_argument();
966 my $name = next_argument();
967 my $args = next_argument();
968 my $siginfo = cfuncline_helper($type, $name, $args);
969 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000970 my $rcinfo = '';
971 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000972 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000973 }
974 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000975 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000976 }
Fred Drakec2578c52000-04-10 18:26:45 +0000977 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000978 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000979 }
Fred Drakee15956b2000-04-03 04:51:13 +0000980 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000981 $rcinfo = ( "\n<div class=\"refcount-info\">"
982 . "\n <span class=\"label\">Return value:</span>"
983 . "\n <span class=\"value\">$rcinfo.</span>"
984 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000985 }
Fred Drake2fc88a62003-08-05 03:45:37 +0000986 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000987 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000988 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +0000989 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000990}
991
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000992sub do_cmd_cmemberline{
993 local($_) = @_;
994 my $container = next_argument();
995 my $type = next_argument();
996 my $name = next_argument();
997 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000998 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000999 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001000 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001001 . $_;
1002}
1003sub do_env_cmemberdesc{
1004 local($_) = @_;
1005 my $container = next_argument();
1006 my $type = next_argument();
1007 my $name = next_argument();
1008 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +00001009 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001010 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001011 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +00001012 . $_
1013 . '</dl>';
1014}
1015
Fred Drakee15956b2000-04-03 04:51:13 +00001016sub do_env_csimplemacrodesc{
1017 local($_) = @_;
1018 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001019 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001020 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001021 . $_
1022 . '</dl>'
1023}
1024
Fred Drake6659c301998-03-03 22:02:19 +00001025sub do_env_ctypedesc{
1026 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001027 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001028 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001029 $index_name = $type_name
1030 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001031 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001032 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001033 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1034 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001035 . $_
1036 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001037}
1038
1039sub do_env_cvardesc{
1040 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001041 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001042 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001043 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001044 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001045 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001046 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001047 . '<dd>'
1048 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001049 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001050}
1051
Fred Drake3cdb89d2000-09-14 20:17:23 +00001052sub convert_args($){
1053 local($IN_DESC_HANDLER) = 1;
1054 local($_) = @_;
1055 return translate_commands($_);
1056}
1057
Fred Drakef6e90272002-06-18 18:24:16 +00001058sub funcline_helper($$$){
1059 my($first, $idxitem, $arglist) = @_;
1060 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001061 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1062 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001063 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001064}
1065
Fred Drake6659c301998-03-03 22:02:19 +00001066sub do_env_funcdesc{
1067 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001068 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001069 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001070 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1071 . '</tt>'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001072 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001073 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001074 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001075 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001076}
1077
1078sub do_env_funcdescni{
1079 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001080 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001081 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001082 my $prefix = "<tt class=\"function\">$function_name</tt>";
1083 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001084}
1085
1086sub do_cmd_funcline{
1087 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001088 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001089 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001090 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001091 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1092 $prefix =~ s/\(\)//;
1093
Fred Drakef6e90272002-06-18 18:24:16 +00001094 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001095}
1096
Fred Drake6b3fb781999-07-12 16:50:09 +00001097sub do_cmd_funclineni{
1098 local($_) = @_;
1099 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001100 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001101 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001102
Fred Drakef6e90272002-06-18 18:24:16 +00001103 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001104}
1105
Fred Drake6659c301998-03-03 22:02:19 +00001106# Change this flag to index the opcode entries. I don't think it's very
1107# useful to index them, since they're only presented to describe the dis
1108# module.
1109#
1110$INDEX_OPCODES = 0;
1111
1112sub do_env_opcodedesc{
1113 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001114 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001115 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001116 my $idx;
1117 if ($INDEX_OPCODES) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001118 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
Fred Drakef1927a62001-06-20 21:29:30 +00001119 . ' (byte code instruction)');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001120 $idx =~ s/ \(byte code instruction\)//;
Fred Drake08932051998-04-17 02:15:42 +00001121 }
1122 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001123 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001124 }
1125 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001126 if ($arg_list) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001127 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
Fred Drake6659c301998-03-03 22:02:19 +00001128 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001129 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001130}
1131
1132sub do_env_datadesc{
1133 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001134 my $dataname = next_argument();
1135 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001136 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001137 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001138 . $_
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001139 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001140}
1141
1142sub do_env_datadescni{
1143 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001144 my $idx = next_argument();
1145 if (! $STRING_INDEX_TT) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001146 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001147 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001148 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001149}
1150
1151sub do_cmd_dataline{
1152 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001153 my $data_name = next_argument();
1154 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001155 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001156 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001157}
1158
Fred Drakeadb272c2000-04-10 17:47:14 +00001159sub do_cmd_datalineni{
1160 local($_) = @_;
1161 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001162 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001163}
1164
Fred Drake42b31a51998-03-27 05:16:10 +00001165sub do_env_excdesc{
1166 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001167 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001168 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001169 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001170 . "\n<dd>"
1171 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001172 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001173}
1174
Fred Drake62e43691998-08-10 19:40:44 +00001175sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001176
1177
Fred Drakef5478632002-05-23 17:59:16 +00001178sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001179 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001180 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001181 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001182 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001183 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001184 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001185 my $prefix = "$TLSTART$what$TLEND$idx";
1186 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001187}
1188
Fred Drake643d76d2000-09-09 06:07:37 +00001189sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001190 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001191}
1192
Fred Drake06a01e82001-05-11 01:00:30 +00001193sub do_env_classdescstar{
1194 local($_) = @_;
1195 $THIS_CLASS = next_argument();
1196 $idx = make_str_index_entry(
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001197 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001198 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001199 my $prefix = "${TLSTART}class$TLEND$idx";
1200 # Can't use funcline_helper() since there is no args list.
1201 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001202}
1203
Fred Drake643d76d2000-09-09 06:07:37 +00001204sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001205 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001206}
1207
Fred Drake42b31a51998-03-27 05:16:10 +00001208
1209sub do_env_methoddesc{
1210 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001211 my $class_name = next_optional_argument();
1212 $class_name = $THIS_CLASS
1213 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001214 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001215 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001216 my $extra = '';
1217 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001218 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001219 }
Fred Drakef1927a62001-06-20 21:29:30 +00001220 my $idx = make_str_index_entry(
1221 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001222 $idx =~ s/ \(.*\)//;
1223 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001224 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001225}
1226
1227
Fred Drake7d45f6d1999-01-05 14:39:27 +00001228sub do_cmd_methodline{
1229 local($_) = @_;
1230 my $class_name = next_optional_argument();
1231 $class_name = $THIS_CLASS
1232 unless $class_name;
1233 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001234 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001235 my $extra = '';
1236 if ($class_name) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001237 $extra = " ($class_name method)";
Fred Drake7d45f6d1999-01-05 14:39:27 +00001238 }
Fred Drakef1927a62001-06-20 21:29:30 +00001239 my $idx = make_str_index_entry(
1240 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001241 $idx =~ s/ \(.*\)//;
1242 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001243 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001244}
1245
1246
Fred Draked64a40d1998-09-10 18:59:13 +00001247sub do_cmd_methodlineni{
1248 local($_) = @_;
1249 next_optional_argument();
1250 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001251 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001252 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001253}
1254
Fred Drake42b31a51998-03-27 05:16:10 +00001255sub do_env_methoddescni{
1256 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001257 next_optional_argument();
1258 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001259 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001260 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001261}
1262
1263
1264sub do_env_memberdesc{
1265 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001266 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001267 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001268 $class = $THIS_CLASS
1269 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001270 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001271 $extra = " ($class attribute)"
1272 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001273 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001274 $idx =~ s/ \(.*\)//;
1275 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001276 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001277}
1278
1279
Fred Drake5ccf3301998-04-17 20:04:09 +00001280sub do_cmd_memberline{
1281 local($_) = @_;
1282 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001283 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001284 $class = $THIS_CLASS
1285 unless $class;
1286 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001287 $extra = " ($class attribute)"
1288 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001289 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001290 $idx =~ s/ \(.*\)//;
1291 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001292 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001293}
1294
Fred Drakef269e592001-07-17 23:05:57 +00001295
Fred Drake42b31a51998-03-27 05:16:10 +00001296sub do_env_memberdescni{
1297 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001298 next_optional_argument();
1299 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001300 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001301 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001302 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001303}
1304
1305
Fred Drake5ccf3301998-04-17 20:04:09 +00001306sub do_cmd_memberlineni{
1307 local($_) = @_;
1308 next_optional_argument();
1309 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001310 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001311}
1312
Fred Drakef269e592001-07-17 23:05:57 +00001313
1314@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001315
Fred Drakecb199762001-08-16 21:56:24 +00001316%FontConversions = ('cdata' => 'tt class="cdata"',
1317 'character' => 'tt class="character"',
1318 'class' => 'tt class="class"',
1319 'command' => 'code',
1320 'constant' => 'tt class="constant"',
1321 'exception' => 'tt class="exception"',
1322 'file' => 'tt class="file"',
1323 'filenq' => 'tt class="file"',
1324 'kbd' => 'kbd',
1325 'member' => 'tt class="member"',
1326 'programopt' => 'b',
1327 'textrm' => '',
1328 );
1329
Fred Drakef5478632002-05-23 17:59:16 +00001330sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001331 # do a little magic on a font name to get the right behavior in the first
1332 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001333 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001334 if (defined $FontConversions{$font}) {
1335 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001336 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001337 return $font;
1338}
1339
Fred Drakef5478632002-05-23 17:59:16 +00001340sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001341 my $a = $_[0];
1342 if (!defined $a) {
1343 return '';
1344 }
Fred Drakee15956b2000-04-03 04:51:13 +00001345 my $mark = substr($a, 0, 1);
1346 my $r = '';
1347 if ($mark eq 'c')
1348 { $r = ' align="center"'; }
1349 elsif ($mark eq 'r')
1350 { $r = ' align="right"'; }
1351 elsif ($mark eq 'l')
1352 { $r = ' align="left"'; }
1353 elsif ($mark eq 'p')
1354 { $r = ' align="left"'; }
1355 return $r;
1356}
1357
Fred Drakef5478632002-05-23 17:59:16 +00001358sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001359 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001360 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001361 my $a1 = figure_column_alignment($s1);
1362 my $a2 = figure_column_alignment($s2);
1363 my $a3 = figure_column_alignment($s3);
1364 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001365 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001366 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1367 $col_aligns[1] = "<td$a2>";
1368 $col_aligns[2] = "<td$a3>";
1369 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001370 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001371 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001372 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001373}
1374
Fred Drakef5478632002-05-23 17:59:16 +00001375sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001376 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001377 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001378 if ($font) {
1379 $sfont = "<$font>";
1380 $efont = "</$font>";
1381 $efont =~ s/ .*>/>/;
1382 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001383 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001384}
1385
1386sub do_env_tableii{
1387 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001388 my $arg = next_argument();
1389 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001390 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001391 my $h1 = next_argument();
1392 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001393 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001394 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001395 my $a1 = $col_aligns[0];
1396 my $a2 = $col_aligns[1];
1397 s/\\lineii</\\lineii[$a1|$a2]</g;
1398 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001399 . "\n <thead>"
1400 . "\n <tr class=\"tableheader\">"
1401 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1402 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1403 . "\n </tr>"
1404 . "\n </thead>"
1405 . "\n <tbody valign=\"baseline\">"
1406 . $_
1407 . "\n </tbody>"
1408 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001409}
1410
Fred Drakeda72b932000-09-21 15:58:02 +00001411sub do_env_longtableii{
1412 return do_env_tableii(@_);
1413}
1414
Fred Drake6659c301998-03-03 22:02:19 +00001415sub do_cmd_lineii{
1416 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001417 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001418 my $c1 = next_argument();
1419 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001420 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001421 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001422 $c1 = '&nbsp;' if ($c1 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001423 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001424 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001425 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001426 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001427 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001428 }
Fred Drakee15956b2000-04-03 04:51:13 +00001429 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1430 . " $c2align$c2</td>"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001431 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001432}
1433
1434sub do_env_tableiii{
1435 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001436 my $arg = next_argument();
1437 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001438 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001439 my $h1 = next_argument();
1440 my $h2 = next_argument();
1441 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001442 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001443 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001444 my $a1 = $col_aligns[0];
1445 my $a2 = $col_aligns[1];
1446 my $a3 = $col_aligns[2];
1447 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1448 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001449 . "\n <thead>"
1450 . "\n <tr class=\"tableheader\">"
1451 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1452 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1453 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1454 . "\n </tr>"
1455 . "\n </thead>"
1456 . "\n <tbody valign=\"baseline\">"
1457 . $_
1458 . "\n </tbody>"
1459 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001460}
1461
Fred Drakeda72b932000-09-21 15:58:02 +00001462sub do_env_longtableiii{
1463 return do_env_tableiii(@_);
1464}
1465
Fred Drake6659c301998-03-03 22:02:19 +00001466sub do_cmd_lineiii{
1467 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001468 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001469 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001470 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001471 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001472 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001473 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001474 $c1 = '&nbsp;' if ($c1 eq '');
1475 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001476 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001477 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001478 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001479 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001480 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001481 }
Fred Drakee15956b2000-04-03 04:51:13 +00001482 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001483 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001484 . " $c3align$c3</td>"
1485 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001486}
1487
Fred Drakea0f4c941998-07-24 22:16:04 +00001488sub do_env_tableiv{
1489 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001490 my $arg = next_argument();
1491 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001492 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001493 my $h1 = next_argument();
1494 my $h2 = next_argument();
1495 my $h3 = next_argument();
1496 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001497 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001498 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001499 my $a1 = $col_aligns[0];
1500 my $a2 = $col_aligns[1];
1501 my $a3 = $col_aligns[2];
1502 my $a4 = $col_aligns[3];
1503 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1504 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001505 . "\n <thead>"
1506 . "\n <tr class=\"tableheader\">"
1507 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1508 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1509 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1510 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1511 . "\n </tr>"
1512 . "\n </thead>"
1513 . "\n <tbody valign=\"baseline\">"
1514 . $_
1515 . "\n </tbody>"
1516 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001517}
1518
Fred Drakeda72b932000-09-21 15:58:02 +00001519sub do_env_longtableiv{
1520 return do_env_tableiv(@_);
1521}
1522
Fred Drakea0f4c941998-07-24 22:16:04 +00001523sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001524 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001525 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001526 my $c1 = next_argument();
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001527 my $c2 = next_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001528 my $c3 = next_argument();
1529 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001530 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001531 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001532 $c1 = '&nbsp;' if ($c1 eq '');
1533 $c2 = '&nbsp;' if ($c2 eq '');
1534 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakee15956b2000-04-03 04:51:13 +00001535 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001536 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001537 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001538 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001539 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001540 }
Fred Drakee15956b2000-04-03 04:51:13 +00001541 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001542 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001543 . " $c3align$c3</td>\n"
1544 . " $c4align$c4</td>"
1545 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001546}
1547
Fred Drakef269e592001-07-17 23:05:57 +00001548sub do_env_tablev{
1549 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001550 my $arg = next_argument();
1551 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001552 my $font = fix_font(next_argument());
1553 my $h1 = next_argument();
1554 my $h2 = next_argument();
1555 my $h3 = next_argument();
1556 my $h4 = next_argument();
1557 my $h5 = next_argument();
1558 s/[\s\n]+//;
1559 $globals{'lineifont'} = $font;
1560 my $a1 = $col_aligns[0];
1561 my $a2 = $col_aligns[1];
1562 my $a3 = $col_aligns[2];
1563 my $a4 = $col_aligns[3];
1564 my $a5 = $col_aligns[4];
1565 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1566 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001567 . "\n <thead>"
1568 . "\n <tr class=\"tableheader\">"
1569 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1570 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1571 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1572 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1573 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1574 . "\n </tr>"
1575 . "\n </thead>"
1576 . "\n <tbody valign=\"baseline\">"
1577 . $_
1578 . "\n </tbody>"
1579 . "\n</table>";
Fred Drakef269e592001-07-17 23:05:57 +00001580}
1581
1582sub do_env_longtablev{
1583 return do_env_tablev(@_);
1584}
1585
1586sub do_cmd_linev{
1587 local($_) = @_;
1588 my $aligns = next_optional_argument();
1589 my $c1 = next_argument();
1590 my $c2 = next_argument();
1591 my $c3 = next_argument();
1592 my $c4 = next_argument();
1593 my $c5 = next_argument();
1594 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001595 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakeecbfceb2003-09-04 21:25:03 +00001596 $c1 = '&nbsp;' if ($c1 eq '');
1597 $c2 = '&nbsp;' if ($c2 eq '');
1598 $c3 = '&nbsp;' if ($c3 eq '');
1599 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef269e592001-07-17 23:05:57 +00001600 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001601 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001602 my $padding = '';
1603 if ($c1align =~ /align="right"/ || $c1 eq '') {
1604 $padding = '&nbsp;';
1605 }
1606 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1607 . " $c2align$c2</td>\n"
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001608 . " $c3align$c3</td>\n"
1609 . " $c4align$c4</td>\n"
1610 . " $c5align$c5</td>"
1611 . $_;
Fred Drakef269e592001-07-17 23:05:57 +00001612}
1613
Fred Drake3be20742000-08-31 06:22:54 +00001614
1615# These can be used to control the title page appearance;
1616# they need a little bit of documentation.
1617#
1618# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1619# $ICONSERVER directory, or include path information (other than "./"). The
1620# default image type will be assumed if an extension is not provided.
1621#
1622# If specified, the "title page" will contain two colums: one containing the
1623# title/author/etc., and the other containing the graphic. Use the other
1624# four variables listed here to control specific details of the layout; all
1625# are optional.
1626#
1627# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1628# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1629# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1630# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1631# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1632
Fred Drakef5478632002-05-23 17:59:16 +00001633sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001634 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001635 if ($t_title) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001636 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001637 }
1638 else {
1639 write_warnings("\nThis document has no title.");
1640 }
Fred Drake6659c301998-03-03 22:02:19 +00001641 if ($t_author) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001642 if ($t_authorURL) {
1643 my $href = translate_commands($t_authorURL);
1644 $href = make_named_href('author', $href,
1645 "<b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001646 . '</font></b>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001647 $the_title .= "\n<p>$href</p>";
1648 }
Fred Drake3be20742000-08-31 06:22:54 +00001649 else {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001650 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
Fred Drakef1927a62001-06-20 21:29:30 +00001651 . '</font></b></p>');
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001652 }
Fred Drake3be20742000-08-31 06:22:54 +00001653 }
1654 else {
1655 write_warnings("\nThere is no author for this document.");
1656 }
Fred Drake6659c301998-03-03 22:02:19 +00001657 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001658 $the_title .= "\n<p>$t_institute</p>";
1659 }
Fred Draked07868a1998-05-14 21:00:28 +00001660 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001661 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1662 }
Fred Drake6659c301998-03-03 22:02:19 +00001663 if ($t_affil) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001664 $the_title .= "\n<p><i>$t_affil</i></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001665 }
Fred Drake6659c301998-03-03 22:02:19 +00001666 if ($t_date) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001667 $the_title .= "\n<p>";
1668 if ($PACKAGE_VERSION) {
1669 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001670 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001671 }
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001672 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001673 }
1674 if ($t_address) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001675 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001676 }
1677 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001678 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001679 }
Fred Drake6659c301998-03-03 22:02:19 +00001680 if ($t_email) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001681 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001682 }
1683 return $the_title;
1684}
1685
Fred Drakef5478632002-05-23 17:59:16 +00001686sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001687 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001688 my $graphic = "<td class=\"titlegraphic\"";
1689 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1690 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1691 $graphic .= "><img";
1692 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1693 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1694 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1695 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001696 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001697 return $graphic;
1698}
1699
Fred Drakef5478632002-05-23 17:59:16 +00001700sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001701 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001702 my $the_title = "\n";
1703 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001704 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001705 # body), but I don't see any other way to get this generated
1706 # at all. Browsers like Mozilla, that support navigation
1707 # links, can make use of this.
1708 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1709 . ($EXTERNAL_UP_TITLE
1710 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001711 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001712 }
1713 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001714 if ($TITLE_PAGE_GRAPHIC) {
1715 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1716 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1717 . "<tr align=\"right\">\n<td>"
1718 . make_my_titlepage()
1719 . "</td>\n"
1720 . make_my_titlegraphic()
1721 . "</tr>\n</table>");
1722 }
1723 else {
1724 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1725 . make_my_titlegraphic()
1726 . "<td>"
1727 . make_my_titlepage()
1728 . "</td></tr>\n</table>");
1729 }
1730 }
1731 else {
1732 $the_title .= ("\n<center>"
1733 . make_my_titlepage()
1734 . "\n</center>");
1735 }
1736 $the_title .= "\n</div>";
1737 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001738 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001739 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001740}
1741
1742
Fred Drake885215c1998-05-20 21:32:09 +00001743#
Fred Drakea0f4c941998-07-24 22:16:04 +00001744# Module synopsis support
1745#
1746
1747require SynopsisTable;
1748
Fred Drakef7685d71998-07-25 03:31:46 +00001749sub get_chapter_id(){
1750 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001751 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001752 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001753 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001754}
1755
Fred Drake643d76d2000-09-09 06:07:37 +00001756# 'chapter' => 'SynopsisTable instance'
1757%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001758
1759sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001760 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001761 my $key;
1762 foreach $key (keys %ModuleSynopses) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001763 if ($key eq $chap) {
1764 return $ModuleSynopses{$chap};
1765 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001766 }
Fred Drake643d76d2000-09-09 06:07:37 +00001767 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001768 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001769 return $st;
1770}
1771
Fred Drake62e43691998-08-10 19:40:44 +00001772sub do_cmd_moduleauthor{
1773 local($_) = @_;
1774 next_argument();
1775 next_argument();
1776 return $_;
1777}
1778
1779sub do_cmd_sectionauthor{
1780 local($_) = @_;
1781 next_argument();
1782 next_argument();
1783 return $_;
1784}
1785
Fred Drakea0f4c941998-07-24 22:16:04 +00001786sub do_cmd_declaremodule{
1787 local($_) = @_;
1788 my $key = next_optional_argument();
1789 my $type = next_argument();
1790 my $name = next_argument();
1791 my $st = get_synopsis_table(get_chapter_id());
1792 #
1793 $key = $name unless $key;
1794 $type = 'built-in' if $type eq 'builtin';
1795 $st->declare($name, $key, $type);
1796 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001797 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001798}
1799
1800sub do_cmd_modulesynopsis{
1801 local($_) = @_;
1802 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001803 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001804 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001805}
1806
1807sub do_cmd_localmoduletable{
1808 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001809 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001810 my $st = get_synopsis_table($chap);
1811 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001812 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001813}
1814
Fred Drakef5478632002-05-23 17:59:16 +00001815sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001816 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001817 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001818 my $st = $ModuleSynopses{$key};
1819 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001820 if ($file) {
1821 process_localmoduletables_in_file($file);
1822 }
1823 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001824 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001825 }
1826 }
1827}
1828
Fred Drakef5478632002-05-23 17:59:16 +00001829sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001830 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001831 open(MYFILE, "<$file");
1832 local($_);
1833 sysread(MYFILE, $_, 1024*1024);
1834 close(MYFILE);
1835 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001836 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001837 my $match = $&;
1838 my $chap = $1;
1839 my $st = get_synopsis_table($chap);
1840 my $data = $st->tohtml();
1841 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001842 }
Fred Drake643d76d2000-09-09 06:07:37 +00001843 open(MYFILE,">$file");
1844 print MYFILE $_;
1845 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001846}
Fred Drakef5478632002-05-23 17:59:16 +00001847sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001848 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001849 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001850}
Fred Drakea0f4c941998-07-24 22:16:04 +00001851
1852
1853#
1854# "See also:" -- references placed at the end of a \section
1855#
1856
1857sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001858 return ("<div class=\"seealso\">\n "
1859 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001860 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001861 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001862}
1863
Fred Drake5ed35fd2001-11-30 18:09:54 +00001864sub do_env_seealsostar{
1865 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001866 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001867 . '</div>');
1868}
1869
Fred Drakea0f4c941998-07-24 22:16:04 +00001870sub do_cmd_seemodule{
1871 # Insert the right magic to jump to the module definition. This should
1872 # work most of the time, at least for repeat builds....
1873 local($_) = @_;
1874 my $key = next_optional_argument();
1875 my $module = next_argument();
1876 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001877 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001878 $key = $module
1879 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001880 if ($text =~ /\.$/) {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00001881 $period = '';
Fred Drake84bd6f31999-05-11 15:42:51 +00001882 }
Fred Drakef1927a62001-06-20 21:29:30 +00001883 return ('<dl compact class="seemodule">'
1884 . "\n <dt>Module <b><tt class=\"module\">"
1885 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1886 . "\n <dd>$text$period\n </dl>"
1887 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001888}
1889
Fred Drakee0197bf2001-04-12 04:03:22 +00001890sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001891 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001892 my $s = "$str";
1893 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1894 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1895 return $s;
1896}
1897
Fred Drakef5478632002-05-23 17:59:16 +00001898sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001899 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001900 my $rfcnum = next_argument();
1901 my $title = next_argument();
1902 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001903 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001904 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001905 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001906 return '<dl compact class="seerfc">'
1907 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001908 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001909 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001910 . "\n <dd>$text\n </dl>"
1911 . $_;
1912}
1913
Fred Drake643d76d2000-09-09 06:07:37 +00001914sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001915 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001916}
1917
1918sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001919 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001920 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001921}
1922
Fred Drake48449982000-09-12 17:52:33 +00001923sub do_cmd_seetitle{
1924 local($_) = @_;
1925 my $url = next_optional_argument();
1926 my $title = next_argument();
1927 my $text = next_argument();
1928 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001929 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001930 return '<dl compact class="seetitle">'
1931 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001932 . "\n >$title$icon</a></em></dt>"
1933 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001934 . $_;
1935 }
1936 return '<dl compact class="seetitle">'
1937 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001938 . "\n >$title</em></dt>"
1939 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001940 . $_;
1941}
1942
Fred Drakeef4d1112000-05-09 16:17:51 +00001943sub do_cmd_seeurl{
1944 local($_) = @_;
1945 my $url = next_argument();
1946 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001947 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001948 return '<dl compact class="seeurl">'
1949 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001950 . "\n class=\"url\">$url$icon</a></dt>"
1951 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001952 . $_;
1953}
1954
Fred Drakea0f4c941998-07-24 22:16:04 +00001955sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001956 local($_) = @_;
1957 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001958 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001959}
1960
1961
1962#
Fred Drake885215c1998-05-20 21:32:09 +00001963# Definition list support.
1964#
1965
1966sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001967 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001968}
1969
1970sub do_cmd_term{
1971 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001972 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001973 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001974 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001975 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001976}
1977
1978
Fred Drake4e72e052003-07-15 22:00:36 +00001979# Commands listed here have process-order dependencies; these often
1980# are related to indexing operations.
1981# XXX Not sure why funclineni, methodlineni, and samp are here.
1982#
Fred Drake2ff880e1999-02-05 18:31:29 +00001983process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001984declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001985funcline # {} # {}
1986funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001987memberline # [] # {}
1988methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001989methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001990modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001991bifuncindex # {}
1992exindex # {}
1993indexii # {} # {}
1994indexiii # {} # {} # {}
1995indexiv # {} # {} # {} # {}
1996kwindex # {}
1997obindex # {}
1998opindex # {}
1999stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00002000platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002001samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00002002setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00002003withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00002004_RAW_ARG_DEFERRED_CMDS_
2005
2006
Fred Drake8a5e6792002-04-15 18:41:31 +00002007$alltt_start = '<div class="verbatim"><pre>';
2008$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00002009
Fred Drakef5478632002-05-23 17:59:16 +00002010sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00002011 local ($_) = @_;
2012 local($closures,$reopens,@open_block_tags);
2013
2014 # get the tag-strings for all open tags
2015 local(@keep_open_tags) = @$open_tags_R;
2016 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
2017
2018 # get the tags for text-level tags only
2019 $open_tags_R = [ @keep_open_tags ];
2020 local($local_closures, $local_reopens);
2021 ($local_closures, $local_reopens,@open_block_tags)
2022 = &preserve_open_block_tags
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002023 if (@$open_tags_R);
Fred Drake86333602001-04-10 17:13:39 +00002024
2025 $open_tags_R = [ @open_block_tags ];
2026
2027 do {
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002028 local($open_tags_R) = [ @open_block_tags ];
2029 local(@save_open_tags) = ();
Fred Drake86333602001-04-10 17:13:39 +00002030
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002031 local($cnt) = ++$global{'max_id'};
2032 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2033 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
Fred Drake86333602001-04-10 17:13:39 +00002034
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002035 $_ = &translate_environments($_);
2036 $_ = &translate_commands($_) if (/\\/);
Fred Drake86333602001-04-10 17:13:39 +00002037
Fred Drake41aa0182003-09-05 15:43:00 +00002038 # remove spurious <BR> someone sticks in; not sure where they
2039 # actually come from
2040 # XXX the replacement space is there to accomodate something
2041 # broken that inserts a space in front of the first line of
2042 # the environment
2043 s/<BR>/ /gi;
Fred Drake86333602001-04-10 17:13:39 +00002044
Fred Drake1b1ca0c2003-09-05 15:43:58 +00002045 $_ = join('', $closures, $alltt_start, $local_reopens
2046 , $_
2047 , &balance_tags() #, $local_closures
2048 , $alltt_end, $reopens);
2049 undef $open_tags_R; undef @save_open_tags;
Fred Drake86333602001-04-10 17:13:39 +00002050 };
2051 $open_tags_R = [ @keep_open_tags ];
2052 $_;
2053}
2054
Fred Drake6fc22f62002-06-17 15:01:05 +00002055# List of all filenames produced ny do_cmd_verbatiminput()
2056%VerbatimFiles = ();
2057@VerbatimOutputs = ();
2058
2059sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002060 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002061 #
2062 # Re-write the source filename to always use a .txt extension
2063 # so that Web servers will present it as text/plain. This is
2064 # needed since there is no other even moderately reliable way
2065 # to get the right Content-Type header on text files for
2066 # servers which we can't configure (like python.org mirrors).
2067 #
2068 if (defined $VerbatimFiles{$file}) {
2069 # We've seen this one before; re-use the same output file.
2070 return $VerbatimFiles{$file};
2071 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002072 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002073 $filename = "$srcname.txt";
2074 #
2075 # We need to determine if our default filename is already
2076 # being used, and find a new one it it is. If the name is in
2077 # used, this algorithm will first attempt to include the
2078 # source extension as part of the name, and if that is also in
2079 # use (if the same file is included multiple times, or if
2080 # another source file has that as the base name), a counter is
2081 # used instead.
2082 #
2083 my $found = 1;
2084 FIND:
2085 while ($found) {
2086 foreach $fn (@VerbatimOutputs) {
2087 if ($fn eq $filename) {
2088 if ($found == 1) {
2089 $srcext =~ s/^[.]//; # Remove '.' from extension
2090 $filename = "$srcname-$srcext.txt";
2091 }
2092 else {
2093 $filename = "$srcname-$found.txt";
2094 }
2095 ++$found;
2096 next FIND;
2097 }
2098 }
2099 $found = 0;
2100 }
2101 push @VerbatimOutputs, $filename;
2102 $VerbatimFiles{$file} = $filename;
2103 return $filename;
2104}
2105
Fred Drake57e52ef2001-06-15 21:31:57 +00002106sub do_cmd_verbatiminput{
2107 local($_) = @_;
2108 my $fname = next_argument();
2109 my $file;
2110 my $found = 0;
2111 my $texpath;
2112 # Search TEXINPUTS for the input file, the way we're supposed to:
2113 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2114 $file = "$texpath$dd$fname";
2115 last if ($found = (-f $file));
2116 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002117 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002118 my $text;
2119 if ($found) {
2120 open(MYFILE, "<$file") || die "\n$!\n";
2121 read(MYFILE, $text, 1024*1024);
2122 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002123 $filename = get_verbatim_output_name($file);
2124 # Now that we have a filename, write it out.
2125 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002126 print MYFILE $text;
2127 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002128 #
2129 # These rewrites convert the raw text to something that will
2130 # be properly visible as HTML and also will pass through the
2131 # vagaries of conversion through LaTeX2HTML. The order in
2132 # which the specific rewrites are performed is significant.
2133 #
2134 $text =~ s/\&/\&amp;/g;
2135 # These need to happen before the normal < and > re-writes,
2136 # since we need to avoid LaTeX2HTML's attempt to perform
2137 # ligature processing without regard to context (since it
2138 # doesn't have font information).
2139 $text =~ s/--/-&\#45;/g;
2140 $text =~ s/<</\&lt;\&\#60;/g;
2141 $text =~ s/>>/\&gt;\&\#62;/g;
2142 # Just normal re-writes...
2143 $text =~ s/</\&lt;/g;
2144 $text =~ s/>/\&gt;/g;
2145 # These last isn't needed for the HTML, but is needed to get
2146 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2147 # of &sol; since many browsers don't support that.
2148 $text =~ s/\\/\&\#92;/g;
2149 }
2150 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002151 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2152 }
2153 my $note = 'Download as text.';
2154 if ($file ne $filename) {
2155 $note = ('Download as text (original file name: <span class="file">'
2156 . $fname
2157 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002158 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002159 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002160 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002161 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002162 . "<a href=\"$filename\" type=\"text/plain\""
2163 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002164 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002165 . $_);
2166}
Fred Drake86333602001-04-10 17:13:39 +00002167
Fred Drake1b1ca0c2003-09-05 15:43:58 +000021681; # This must be the last line