blob: 7d50e491ef4cbc9b2cb00e676b3c83fe2e43b815 [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
2#
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)
19 ||(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 Drake7a40c072000-10-02 14:43:38 +000054 . " >");
55 }
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) {
68 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
71 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000072 else {
73 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
74 if ($matched) {
75 my($new, $char) = ($1, $3);
Fred Drake49b33fa2002-11-15 19:04:10 +000076 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
Fred Drake7a4ad0f1998-05-15 13:45:54 +000077 print "\ndefining handler for \\$new to insert '$char'\n";
78 }
79 else {
80 write_warnings("Could not interpret \\let construct...");
81 }
82 }
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 Drake166abba1998-04-08 23:10:54 +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 Drake7a40c072000-10-02 14:43:38 +0000348 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
349 . "$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 Drake7a40c072000-10-02 14:43:38 +0000361 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
362 . "$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>"
397 . "\n$reason</div><p>"
398 . $_);
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";
486print INTLABELS "1; # hack in case there are no entries\n\n";
487
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 Drakef5478632002-05-23 17:59:16 +0000513sub new_link_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000514 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000515 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000516 my $ahref = gen_link($CURRENT_FILE, $name);
517 return ($name, $aname, $ahref);
518}
519
Fred Drakeab032151999-05-13 18:36:54 +0000520$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000521sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000522 my $count = @_;
523 my $i = 0;
524 for (; $i < $count; ++$i) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000525 my $name = $_[$i];
Fred Drakeab032151999-05-13 18:36:54 +0000526 my $cmd = "idx_cmd_$name";
527 die "\nNo function $cmd() defined!\n"
528 if (!defined &$cmd);
529 eval ("sub do_cmd_$name { return process_index_macros("
Fred Drake49b33fa2002-11-15 19:04:10 +0000530 . "\$_[0], '$name'); }");
Fred Drakeab032151999-05-13 18:36:54 +0000531 if (length($IndexMacroPattern) == 0) {
532 $IndexMacroPattern = "$name";
533 }
534 else {
535 $IndexMacroPattern .= "|$name";
536 }
537 }
538}
539
540$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000541sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000542 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000543 my $cmdname = $_[1]; # This is what triggered us in the first place;
Fred Drakeab032151999-05-13 18:36:54 +0000544 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000545 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000546 my $cmd = "idx_cmd_$cmdname";
547 print "\nIndexing: \\$cmdname"
548 if $DEBUG_INDEXING;
549 &$cmd($ahref); # modifies $_ and adds index entries
550 while (/^[\s\n]*\\($IndexMacroPattern)</) {
551 $cmdname = "$1";
552 print " \\$cmdname"
553 if $DEBUG_INDEXING;
554 $cmd = "idx_cmd_$cmdname";
555 if (!defined &$cmd) {
556 last;
557 }
558 else {
559 s/^[\s\n]*\\$cmdname//;
560 &$cmd($ahref);
561 }
562 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000563 if (/^[ \t\r\n]/) {
564 $_ = substr($_, 1);
565 }
Fred Drake62e43691998-08-10 19:40:44 +0000566 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000567}
568
Fred Drakeab032151999-05-13 18:36:54 +0000569define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000570sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000571 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000572 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000573}
574
Fred Drakeab032151999-05-13 18:36:54 +0000575define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000576sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000577 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000578 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
579 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000580}
581
582define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000583sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000584 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000585 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000586 add_index_entry("$str1!$str2", $_[0]);
587 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000588}
589
Fred Drakeab032151999-05-13 18:36:54 +0000590define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000591sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000592 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000593 my $str2 = next_argument();
594 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000595 add_index_entry("$str1!$str2 $str3", $_[0]);
596 add_index_entry("$str2!$str3, $str1", $_[0]);
597 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000598}
599
Fred Drakeab032151999-05-13 18:36:54 +0000600define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000601sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000602 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000603 my $str2 = next_argument();
604 my $str3 = next_argument();
605 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000606 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
607 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
608 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
609 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000610}
611
Fred Drakeab032151999-05-13 18:36:54 +0000612define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000613sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000614 my $str = next_argument();
615 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000616 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000617}
Fred Drake6659c301998-03-03 22:02:19 +0000618
Fred Drakef5478632002-05-23 17:59:16 +0000619sub my_typed_index_helper($$){
620 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000621 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000622 add_index_entry("$str $word", $ahref);
623 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000624}
625
Fred Drakeab032151999-05-13 18:36:54 +0000626define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000627sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
628sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
629sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
630sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000631
Fred Drakeab032151999-05-13 18:36:54 +0000632define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000633sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000634 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000635 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000636 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000637}
638
639
Fred Drakef5478632002-05-23 17:59:16 +0000640sub make_mod_index_entry($$){
641 my($str, $define) = @_;
642 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000643 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000644 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
645 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000646 $str = gen_index_id($str, $define);
647 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000648 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000649
Fred Drakec9a44381998-03-17 06:29:13 +0000650 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000651 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000652 $str =~ /(<tt.*<\/tt>)/;
653 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000654 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000655 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000656 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000657}
658
Fred Drake557460c1999-03-02 16:05:35 +0000659
Fred Drakec9a44381998-03-17 06:29:13 +0000660$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000661$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000662
Fred Drakef5478632002-05-23 17:59:16 +0000663sub define_module($$){
664 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000665 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000666 if ($word ne "built-in" && $word ne "extension"
667 && $word ne "standard" && $word ne "") {
668 write_warnings("Bad module type '$word'"
669 . " for \\declaremodule (module $name)");
670 $word = "";
671 }
Fred Drake6659c301998-03-03 22:02:19 +0000672 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000673 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000674 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000675 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000676 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000677 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000678}
679
Fred Drakef5478632002-05-23 17:59:16 +0000680sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000681 local($word, $_) = @_;
682 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000683 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000684}
685
Fred Drake49b33fa2002-11-15 19:04:10 +0000686sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
687sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
688sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
689sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
690# local($_) = @_;
691# my $name = next_argument();
692# return define_module('standard', $name) . $_;
693# }
Fred Drake6659c301998-03-03 22:02:19 +0000694
Fred Drakef5478632002-05-23 17:59:16 +0000695sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000696 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000697 my $str = next_argument();
698 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000699 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000700 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
701 # just inline it all here
702 $str = gen_index_id($str, 'REF');
703 $index{$str} .= $ahref;
704 write_idxfile($ahref, $str);
705}
706
Fred Drake6659c301998-03-03 22:02:19 +0000707# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000708define_indexing_macro('refmodindex', 'refbimodindex',
709 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000710sub idx_cmd_refmodindex($){
711 return ref_module_index_helper('', $_[0]); }
712sub idx_cmd_refbimodindex($){
713 return ref_module_index_helper('built-in', $_[0]); }
714sub idx_cmd_refexmodindex($){
715 return ref_module_index_helper('extension', $_[0]);}
716sub idx_cmd_refstmodindex($){
717 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000718
Fred Drake49b33fa2002-11-15 19:04:10 +0000719sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000720
Fred Drakef5478632002-05-23 17:59:16 +0000721sub init_myformat(){
Fred Drakeafc7ce12001-01-22 17:33:24 +0000722 $anchor_invisible_mark = '&nbsp;';
723 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000724 $anchor_mark = '';
725 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000726}
Fred Drake42b31a51998-03-27 05:16:10 +0000727init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000728
Fred Drakeab032151999-05-13 18:36:54 +0000729# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000730# instead of the dummy filler.
731#
Fred Drakef5478632002-05-23 17:59:16 +0000732sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000733 my $str = $_[0];
Fred Drakef5478632002-05-23 17:59:16 +0000734 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000735 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000736 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000737}
738
Fred Drake77602f22001-07-06 22:43:02 +0000739
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000740%TokenToTargetMapping = (); # language:token -> link target
741%DefinedGrammars = (); # language -> full grammar text
742%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000743
744sub do_cmd_token{
745 local($_) = @_;
746 my $token = next_argument();
747 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
748 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
749 # recursive definition or display-only productionlist
750 return "$token";
751 }
752 if ($target eq '') {
753 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
754 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
755 print "Adding '$CURRENT_FILE' to back-patch list.\n";
756 }
757 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
758 }
759 return "<a href=\"$target\">$token</a>" . $_;
760}
761
Fred Drake16bb4192001-08-20 21:36:38 +0000762sub do_cmd_grammartoken{
763 return do_cmd_token(@_);
764}
765
Fred Drake77602f22001-07-06 22:43:02 +0000766sub do_env_productionlist{
767 local($_) = @_;
768 my $lang = next_optional_argument();
769 my $filename = "grammar-$lang.txt";
770 if ($lang eq '') {
771 $filename = 'grammar.txt';
772 }
773 local($CURRENT_GRAMMAR) = $lang;
774 $DefinedGrammars{$lang} .= $_;
775 return ("<dl><dd class=\"grammar\">\n"
776 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000777 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000778 . translate_commands(translate_environments($_))
779 . "</table>\n"
780 . "</div>\n"
781 . (($lang eq '*')
782 ? ''
783 : ("<a class=\"grammar-footer\"\n"
784 . " href=\"$filename\" type=\"text/plain\"\n"
785 . " >Download entire grammar as text.</a>\n"))
786 . "</dd></dl>");
787}
788
789sub do_cmd_production{
790 local($_) = @_;
791 my $token = next_argument();
792 my $defn = next_argument();
793 my $lang = $CURRENT_GRAMMAR;
794 local($CURRENT_TOKEN) = $token;
795 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000796 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000797 . " <td><code>$token</code></td>\n"
798 . " <td>&nbsp;::=&nbsp;</td>\n"
799 . " <td><code>"
800 . translate_commands($defn)
801 . "</code></td></tr>"
802 . $_);
803 }
804 my $target;
805 if ($lang eq '') {
806 $target = "$CURRENT_FILE\#tok-$token";
807 }
808 else {
809 $target = "$CURRENT_FILE\#tok-$lang-$token";
810 }
811 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000812 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000813 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
814 . " <td>&nbsp;::=&nbsp;</td>\n"
815 . " <td><code>"
816 . translate_commands($defn)
817 . "</code></td></tr>"
818 . $_);
819}
820
Fred Drake53815882002-03-15 23:21:37 +0000821sub do_cmd_productioncont{
822 local($_) = @_;
823 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000824 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000825 return ("<tr valign=\"baseline\">\n"
826 . " <td>&nbsp;</td>\n"
827 . " <td>&nbsp;</td>\n"
828 . " <td><code>"
829 . translate_commands($defn)
830 . "</code></td></tr>"
831 . $_);
832}
833
Fred Drakef5478632002-05-23 17:59:16 +0000834sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000835 my $lang;
836 my $filename;
837 local($_);
838 print "process_grammar_files()\n";
839 foreach $lang (keys %DefinedGrammars) {
840 $filename = "grammar-$lang.txt";
841 if ($lang eq '*') {
842 next;
843 }
844 if ($lang eq '') {
845 $filename = 'grammar.txt';
846 }
847 open(GRAMMAR, ">$filename") || die "\n$!\n";
848 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
849 close(GRAMMAR);
850 print "Wrote grammar file $filename\n";
851 }
852 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
853 foreach $filename (keys %BackpatchGrammarFiles) {
854 print "\nBack-patching grammar links in $filename\n";
855 my $buffer;
856 open(GRAMMAR, "<$filename") || die "\n$!\n";
857 # read all of the file into the buffer
858 sysread(GRAMMAR, $buffer, 1024*1024);
859 close(GRAMMAR);
860 while ($buffer =~ /$PATTERN/) {
861 my($lang, $token) = ($1, $2);
862 my $target = $TokenToTargetMapping{"$lang:$token"};
863 my $source = "<pyGrammarToken><$lang><$token>";
864 $buffer =~ s/$source/$target/g;
865 }
866 open(GRAMMAR, ">$filename") || die "\n$!\n";
867 print GRAMMAR $buffer;
868 close(GRAMMAR);
869 }
870}
871
Fred Drakef5478632002-05-23 17:59:16 +0000872sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000873 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000874 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000875 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
876 s/\\token(<<\d+>>)(.+)\1/$2/g;
877 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000878 s/<<\d+>>//g;
879 s/;SPMgt;/>/g;
880 s/;SPMlt;/</g;
881 s/;SPMquot;/\"/g;
882 return $_;
883}
884
885
Fred Drakee15956b2000-04-03 04:51:13 +0000886$REFCOUNTS_LOADED = 0;
887
Fred Drakef5478632002-05-23 17:59:16 +0000888sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000889 $REFCOUNTS_LOADED = 1;
890
Fred Drake49b33fa2002-11-15 19:04:10 +0000891 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drakee15956b2000-04-03 04:51:13 +0000892 chop $mydir; # remove trailing '/'
893 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
894 chop $mydir; # remove trailing '/'
895 $mydir = getcwd() . "$dd$mydir"
896 unless $mydir =~ s|^/|/|;
897 local $_;
898 my $filename = "$mydir${dd}api${dd}refcounts.dat";
899 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
900 print "[loading API refcount data]";
901 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000902 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000903 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
904 #print "\n$func($param) --> $count";
905 $REFCOUNTS{"$func:$param"} = $count;
906 }
907 }
908}
909
Fred Drakef5478632002-05-23 17:59:16 +0000910sub get_refcount($$){
911 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000912 load_refcounts()
913 unless $REFCOUNTS_LOADED;
914 return $REFCOUNTS{"$func:$param"};
915}
916
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000917
918$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000919$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000920
Fred Drakef5478632002-05-23 17:59:16 +0000921sub cfuncline_helper($$$){
922 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000923 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000924 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000925 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000926 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000927 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
928 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000929 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
930 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
931 . "<td>$args)</td>"
932 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000933}
934sub do_cmd_cfuncline{
935 local($_) = @_;
936 my $type = next_argument();
937 my $name = next_argument();
938 my $args = next_argument();
939 my $siginfo = cfuncline_helper($type, $name, $args);
940 return "<dt>$siginfo\n<dd>" . $_;
941}
942sub do_env_cfuncdesc{
943 local($_) = @_;
944 my $type = next_argument();
945 my $name = next_argument();
946 my $args = next_argument();
947 my $siginfo = cfuncline_helper($type, $name, $args);
948 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000949 my $rcinfo = '';
950 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000951 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000952 }
953 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000954 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000955 }
Fred Drakec2578c52000-04-10 18:26:45 +0000956 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000957 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000958 }
Fred Drakee15956b2000-04-03 04:51:13 +0000959 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000960 $rcinfo = ( "\n<div class=\"refcount-info\">"
961 . "\n <span class=\"label\">Return value:</span>"
962 . "\n <span class=\"value\">$rcinfo.</span>"
963 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000964 }
Fred Drake34adb8a2002-04-15 20:48:40 +0000965 return "<dl><dt>$siginfo\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000966 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000967 . $_
968 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000969}
970
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000971sub do_cmd_cmemberline{
972 local($_) = @_;
973 my $container = next_argument();
974 my $type = next_argument();
975 my $name = next_argument();
976 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000977 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000978 $idx =~ s/ \(.*\)//;
979 return "<dt>$type <b>$idx</b>\n<dd>"
980 . $_;
981}
982sub do_env_cmemberdesc{
983 local($_) = @_;
984 my $container = next_argument();
985 my $type = next_argument();
986 my $name = next_argument();
987 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000988 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000989 $idx =~ s/ \(.*\)//;
990 return "<dl><dt>$type <b>$idx</b>\n<dd>"
991 . $_
992 . '</dl>';
993}
994
Fred Drakee15956b2000-04-03 04:51:13 +0000995sub do_env_csimplemacrodesc{
996 local($_) = @_;
997 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000998 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000999 return "<dl><dt><b>$idx</b>\n<dd>"
1000 . $_
1001 . '</dl>'
1002}
1003
Fred Drake6659c301998-03-03 22:02:19 +00001004sub do_env_ctypedesc{
1005 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001006 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001007 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001008 $index_name = $type_name
1009 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001010 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001011 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1012 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001013 . $_
1014 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001015}
1016
1017sub do_env_cvardesc{
1018 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001019 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001020 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001021 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001022 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001023 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001024 return "<dl><dt>$var_type <b>$idx</b>\n"
1025 . '<dd>'
1026 . $_
1027 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001028}
1029
Fred Drake3cdb89d2000-09-14 20:17:23 +00001030sub convert_args($){
1031 local($IN_DESC_HANDLER) = 1;
1032 local($_) = @_;
1033 return translate_commands($_);
1034}
1035
Fred Drakef6e90272002-06-18 18:24:16 +00001036sub funcline_helper($$$){
1037 my($first, $idxitem, $arglist) = @_;
1038 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001039 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1040 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1041 . "\n <td><var>$arglist</var>)</td></tr></table>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001042}
1043
Fred Drake6659c301998-03-03 22:02:19 +00001044sub do_env_funcdesc{
1045 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001046 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001047 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001048 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1049 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001050 . get_indexsubitem());
1051 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001052 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001053 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001054}
1055
1056sub do_env_funcdescni{
1057 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001058 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001059 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001060 my $prefix = "<tt class=\"function\">$function_name</tt>";
1061 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001062}
1063
1064sub do_cmd_funcline{
1065 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001066 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001067 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001068 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001069 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1070 $prefix =~ s/\(\)//;
1071
Fred Drakef6e90272002-06-18 18:24:16 +00001072 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001073}
1074
Fred Drake6b3fb781999-07-12 16:50:09 +00001075sub do_cmd_funclineni{
1076 local($_) = @_;
1077 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001078 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001079 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001080
Fred Drakef6e90272002-06-18 18:24:16 +00001081 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001082}
1083
Fred Drake6659c301998-03-03 22:02:19 +00001084# Change this flag to index the opcode entries. I don't think it's very
1085# useful to index them, since they're only presented to describe the dis
1086# module.
1087#
1088$INDEX_OPCODES = 0;
1089
1090sub do_env_opcodedesc{
1091 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001092 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001093 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001094 my $idx;
1095 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001096 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1097 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001098 $idx =~ s/ \(byte code instruction\)//;
1099 }
1100 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001101 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001102 }
1103 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001104 if ($arg_list) {
1105 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1106 }
Fred Drake62e43691998-08-10 19:40:44 +00001107 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001108}
1109
1110sub do_env_datadesc{
1111 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001112 my $dataname = next_argument();
1113 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001114 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001115 return "<dl><dt><b>$idx</b>\n<dd>"
1116 . $_
1117 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001118}
1119
1120sub do_env_datadescni{
1121 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001122 my $idx = next_argument();
1123 if (! $STRING_INDEX_TT) {
1124 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001125 }
Fred Drake62e43691998-08-10 19:40:44 +00001126 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001127}
1128
1129sub do_cmd_dataline{
1130 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001131 my $data_name = next_argument();
1132 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001133 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001134 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001135}
1136
Fred Drakeadb272c2000-04-10 17:47:14 +00001137sub do_cmd_datalineni{
1138 local($_) = @_;
1139 my $data_name = next_argument();
1140 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1141}
1142
Fred Drake42b31a51998-03-27 05:16:10 +00001143sub do_env_excdesc{
1144 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001145 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001146 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakef6e90272002-06-18 18:24:16 +00001147 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001148 . "\n<dd>"
1149 . $_
1150 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001151}
1152
Fred Drake62e43691998-08-10 19:40:44 +00001153sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001154
1155
Fred Drakef5478632002-05-23 17:59:16 +00001156sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001157 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001158 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001159 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001160 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001161 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001162 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001163 my $prefix = "$TLSTART$what$TLEND$idx";
1164 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001165}
1166
Fred Drake643d76d2000-09-09 06:07:37 +00001167sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001168 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001169}
1170
Fred Drake06a01e82001-05-11 01:00:30 +00001171sub do_env_classdescstar{
1172 local($_) = @_;
1173 $THIS_CLASS = next_argument();
1174 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001175 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001176 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001177 my $prefix = "${TLSTART}class$TLEND$idx";
1178 # Can't use funcline_helper() since there is no args list.
1179 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001180}
1181
Fred Drake643d76d2000-09-09 06:07:37 +00001182sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001183 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001184}
1185
Fred Drake42b31a51998-03-27 05:16:10 +00001186
1187sub do_env_methoddesc{
1188 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001189 my $class_name = next_optional_argument();
1190 $class_name = $THIS_CLASS
1191 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001192 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001193 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001194 my $extra = '';
1195 if ($class_name) {
1196 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001197 }
Fred Drakef1927a62001-06-20 21:29:30 +00001198 my $idx = make_str_index_entry(
1199 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001200 $idx =~ s/ \(.*\)//;
1201 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001202 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001203}
1204
1205
Fred Drake7d45f6d1999-01-05 14:39:27 +00001206sub do_cmd_methodline{
1207 local($_) = @_;
1208 my $class_name = next_optional_argument();
1209 $class_name = $THIS_CLASS
1210 unless $class_name;
1211 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001212 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001213 my $extra = '';
1214 if ($class_name) {
1215 $extra = " ($class_name method)";
1216 }
Fred Drakef1927a62001-06-20 21:29:30 +00001217 my $idx = make_str_index_entry(
1218 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001219 $idx =~ s/ \(.*\)//;
1220 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001221 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001222}
1223
1224
Fred Draked64a40d1998-09-10 18:59:13 +00001225sub do_cmd_methodlineni{
1226 local($_) = @_;
1227 next_optional_argument();
1228 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001229 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001230 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001231}
1232
Fred Drake42b31a51998-03-27 05:16:10 +00001233sub do_env_methoddescni{
1234 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001235 next_optional_argument();
1236 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001237 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001238 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001239}
1240
1241
1242sub do_env_memberdesc{
1243 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001244 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001245 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001246 $class = $THIS_CLASS
1247 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001248 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001249 $extra = " ($class attribute)"
1250 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001251 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001252 $idx =~ s/ \(.*\)//;
1253 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001254 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001255}
1256
1257
Fred Drake5ccf3301998-04-17 20:04:09 +00001258sub do_cmd_memberline{
1259 local($_) = @_;
1260 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001261 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001262 $class = $THIS_CLASS
1263 unless $class;
1264 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001265 $extra = " ($class attribute)"
1266 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001267 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001268 $idx =~ s/ \(.*\)//;
1269 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001270 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001271}
1272
Fred Drakef269e592001-07-17 23:05:57 +00001273
Fred Drake42b31a51998-03-27 05:16:10 +00001274sub do_env_memberdescni{
1275 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001276 next_optional_argument();
1277 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001278 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001279 . $_
1280 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001281}
1282
1283
Fred Drake5ccf3301998-04-17 20:04:09 +00001284sub do_cmd_memberlineni{
1285 local($_) = @_;
1286 next_optional_argument();
1287 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001288 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001289}
1290
Fred Drakef269e592001-07-17 23:05:57 +00001291
1292@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001293
Fred Drakecb199762001-08-16 21:56:24 +00001294%FontConversions = ('cdata' => 'tt class="cdata"',
1295 'character' => 'tt class="character"',
1296 'class' => 'tt class="class"',
1297 'command' => 'code',
1298 'constant' => 'tt class="constant"',
1299 'exception' => 'tt class="exception"',
1300 'file' => 'tt class="file"',
1301 'filenq' => 'tt class="file"',
1302 'kbd' => 'kbd',
1303 'member' => 'tt class="member"',
1304 'programopt' => 'b',
1305 'textrm' => '',
1306 );
1307
Fred Drakef5478632002-05-23 17:59:16 +00001308sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001309 # do a little magic on a font name to get the right behavior in the first
1310 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001311 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001312 if (defined $FontConversions{$font}) {
1313 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001314 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001315 return $font;
1316}
1317
Fred Drakef5478632002-05-23 17:59:16 +00001318sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001319 my $a = $_[0];
1320 if (!defined $a) {
1321 return '';
1322 }
Fred Drakee15956b2000-04-03 04:51:13 +00001323 my $mark = substr($a, 0, 1);
1324 my $r = '';
1325 if ($mark eq 'c')
1326 { $r = ' align="center"'; }
1327 elsif ($mark eq 'r')
1328 { $r = ' align="right"'; }
1329 elsif ($mark eq 'l')
1330 { $r = ' align="left"'; }
1331 elsif ($mark eq 'p')
1332 { $r = ' align="left"'; }
1333 return $r;
1334}
1335
Fred Drakef5478632002-05-23 17:59:16 +00001336sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001337 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001338 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001339 my $a1 = figure_column_alignment($s1);
1340 my $a2 = figure_column_alignment($s2);
1341 my $a3 = figure_column_alignment($s3);
1342 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001343 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001344 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1345 $col_aligns[1] = "<td$a2>";
1346 $col_aligns[2] = "<td$a3>";
1347 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001348 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001349 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001350 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001351}
1352
Fred Drakef5478632002-05-23 17:59:16 +00001353sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001354 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001355 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001356 if ($font) {
1357 $sfont = "<$font>";
1358 $efont = "</$font>";
1359 $efont =~ s/ .*>/>/;
1360 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001361 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001362}
1363
1364sub do_env_tableii{
1365 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001366 my $arg = next_argument();
1367 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001368 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001369 my $h1 = next_argument();
1370 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001371 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001372 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001373 my $a1 = $col_aligns[0];
1374 my $a2 = $col_aligns[1];
1375 s/\\lineii</\\lineii[$a1|$a2]</g;
1376 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001377 . "\n <thead>"
1378 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001379 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1380 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001381 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001382 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001383 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001384 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001385 . "\n </tbody>"
1386 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001387}
1388
Fred Drakeda72b932000-09-21 15:58:02 +00001389sub do_env_longtableii{
1390 return do_env_tableii(@_);
1391}
1392
Fred Drake6659c301998-03-03 22:02:19 +00001393sub do_cmd_lineii{
1394 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001395 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001396 my $c1 = next_argument();
1397 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001398 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001399 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001400 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001401 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001402 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001403 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001404 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001405 }
Fred Drakee15956b2000-04-03 04:51:13 +00001406 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1407 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001408 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001409}
1410
1411sub do_env_tableiii{
1412 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001413 my $arg = next_argument();
1414 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001415 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001416 my $h1 = next_argument();
1417 my $h2 = next_argument();
1418 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001419 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001420 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001421 my $a1 = $col_aligns[0];
1422 my $a2 = $col_aligns[1];
1423 my $a3 = $col_aligns[2];
1424 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1425 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001426 . "\n <thead>"
1427 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001428 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1429 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1430 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001431 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001432 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001433 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001434 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001435 . "\n </tbody>"
1436 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001437}
1438
Fred Drakeda72b932000-09-21 15:58:02 +00001439sub do_env_longtableiii{
1440 return do_env_tableiii(@_);
1441}
1442
Fred Drake6659c301998-03-03 22:02:19 +00001443sub do_cmd_lineiii{
1444 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001445 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001446 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001447 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001448 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001449 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001450 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001451 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001452 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001453 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001454 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001455 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001456 }
Fred Drakee15956b2000-04-03 04:51:13 +00001457 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001458 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001459 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001460 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001461}
1462
Fred Drakea0f4c941998-07-24 22:16:04 +00001463sub do_env_tableiv{
1464 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001465 my $arg = next_argument();
1466 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001467 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001468 my $h1 = next_argument();
1469 my $h2 = next_argument();
1470 my $h3 = next_argument();
1471 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001472 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001473 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001474 my $a1 = $col_aligns[0];
1475 my $a2 = $col_aligns[1];
1476 my $a3 = $col_aligns[2];
1477 my $a4 = $col_aligns[3];
1478 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1479 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001480 . "\n <thead>"
1481 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001482 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1483 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1484 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1485 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001486 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001487 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001488 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001489 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001490 . "\n </tbody>"
1491 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001492}
1493
Fred Drakeda72b932000-09-21 15:58:02 +00001494sub do_env_longtableiv{
1495 return do_env_tableiv(@_);
1496}
1497
Fred Drakea0f4c941998-07-24 22:16:04 +00001498sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001499 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001500 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001501 my $c1 = next_argument();
1502 my $c2 = next_argument();
1503 my $c3 = next_argument();
1504 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001505 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001506 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001507 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001508 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001509 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001510 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001511 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001512 }
Fred Drakee15956b2000-04-03 04:51:13 +00001513 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001514 . " $c2align$c2</td>\n"
1515 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001516 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001517 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001518}
1519
Fred Drakef269e592001-07-17 23:05:57 +00001520sub do_env_tablev{
1521 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001522 my $arg = next_argument();
1523 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001524 my $font = fix_font(next_argument());
1525 my $h1 = next_argument();
1526 my $h2 = next_argument();
1527 my $h3 = next_argument();
1528 my $h4 = next_argument();
1529 my $h5 = next_argument();
1530 s/[\s\n]+//;
1531 $globals{'lineifont'} = $font;
1532 my $a1 = $col_aligns[0];
1533 my $a2 = $col_aligns[1];
1534 my $a3 = $col_aligns[2];
1535 my $a4 = $col_aligns[3];
1536 my $a5 = $col_aligns[4];
1537 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1538 return '<table border align="center" style="border-collapse: collapse">'
1539 . "\n <thead>"
1540 . "\n <tr class=\"tableheader\">"
1541 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1542 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1543 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1544 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1545 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1546 . "\n </tr>"
1547 . "\n </thead>"
1548 . "\n <tbody valign=\"baseline\">"
1549 . $_
1550 . "\n </tbody>"
1551 . "\n</table>";
1552}
1553
1554sub do_env_longtablev{
1555 return do_env_tablev(@_);
1556}
1557
1558sub do_cmd_linev{
1559 local($_) = @_;
1560 my $aligns = next_optional_argument();
1561 my $c1 = next_argument();
1562 my $c2 = next_argument();
1563 my $c3 = next_argument();
1564 my $c4 = next_argument();
1565 my $c5 = next_argument();
1566 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001567 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001568 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001569 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001570 my $padding = '';
1571 if ($c1align =~ /align="right"/ || $c1 eq '') {
1572 $padding = '&nbsp;';
1573 }
1574 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1575 . " $c2align$c2</td>\n"
1576 . " $c3align$c3</td>\n"
1577 . " $c4align$c4</td>\n"
1578 . " $c5align$c5</td>"
1579 . $_;
1580}
1581
Fred Drake3be20742000-08-31 06:22:54 +00001582
1583# These can be used to control the title page appearance;
1584# they need a little bit of documentation.
1585#
1586# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1587# $ICONSERVER directory, or include path information (other than "./"). The
1588# default image type will be assumed if an extension is not provided.
1589#
1590# If specified, the "title page" will contain two colums: one containing the
1591# title/author/etc., and the other containing the graphic. Use the other
1592# four variables listed here to control specific details of the layout; all
1593# are optional.
1594#
1595# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1596# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1597# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1598# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1599# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1600
Fred Drakef5478632002-05-23 17:59:16 +00001601sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001602 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001603 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001604 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001605 }
1606 else {
1607 write_warnings("\nThis document has no title.");
1608 }
Fred Drake6659c301998-03-03 22:02:19 +00001609 if ($t_author) {
1610 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001611 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001612 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001613 "<b><font size=\"+2\">$t_author"
1614 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001615 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001616 }
1617 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001618 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1619 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001620 }
Fred Drake3be20742000-08-31 06:22:54 +00001621 }
1622 else {
1623 write_warnings("\nThere is no author for this document.");
1624 }
Fred Drake6659c301998-03-03 22:02:19 +00001625 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001626 $the_title .= "\n<p>$t_institute</p>";
1627 }
Fred Draked07868a1998-05-14 21:00:28 +00001628 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001629 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1630 }
Fred Drake6659c301998-03-03 22:02:19 +00001631 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001632 $the_title .= "\n<p><i>$t_affil</i></p>";
1633 }
Fred Drake6659c301998-03-03 22:02:19 +00001634 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001635 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001636 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001637 $the_title .= ('<strong>Release '
1638 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001639 }
Fred Drakede77bc52000-12-14 18:36:12 +00001640 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001641 }
1642 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001643 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001644 }
1645 else {
1646 $the_title .= "\n<p>";
1647 }
Fred Drake6659c301998-03-03 22:02:19 +00001648 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001649 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001650 }
1651 return $the_title;
1652}
1653
Fred Drakef5478632002-05-23 17:59:16 +00001654sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001655 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001656 my $graphic = "<td class=\"titlegraphic\"";
1657 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1658 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1659 $graphic .= "><img";
1660 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1661 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1662 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1663 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001664 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001665 return $graphic;
1666}
1667
Fred Drakef5478632002-05-23 17:59:16 +00001668sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001669 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001670 my $the_title = "\n";
1671 if ($EXTERNAL_UP_LINK) {
1672 # This generates a <LINK> element in the wrong place (the
1673 # body), but I don't see any other way to get this generated
1674 # at all. Browsers like Mozilla, that support navigation
1675 # links, can make use of this.
1676 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1677 . ($EXTERNAL_UP_TITLE
1678 ? " title='$EXTERNAL_UP_TITLE'" : '')
1679 . ">\n");
1680 }
1681 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001682 if ($TITLE_PAGE_GRAPHIC) {
1683 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1684 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1685 . "<tr align=\"right\">\n<td>"
1686 . make_my_titlepage()
1687 . "</td>\n"
1688 . make_my_titlegraphic()
1689 . "</tr>\n</table>");
1690 }
1691 else {
1692 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1693 . make_my_titlegraphic()
1694 . "<td>"
1695 . make_my_titlepage()
1696 . "</td></tr>\n</table>");
1697 }
1698 }
1699 else {
1700 $the_title .= ("\n<center>"
1701 . make_my_titlepage()
1702 . "\n</center>");
1703 }
1704 $the_title .= "\n</div>";
1705 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001706 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001707 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001708}
1709
1710
Fred Drake885215c1998-05-20 21:32:09 +00001711#
Fred Drakea0f4c941998-07-24 22:16:04 +00001712# Module synopsis support
1713#
1714
1715require SynopsisTable;
1716
Fred Drakef7685d71998-07-25 03:31:46 +00001717sub get_chapter_id(){
1718 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001719 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001720 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001721 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001722}
1723
Fred Drake643d76d2000-09-09 06:07:37 +00001724# 'chapter' => 'SynopsisTable instance'
1725%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001726
1727sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001728 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001729 my $key;
1730 foreach $key (keys %ModuleSynopses) {
1731 if ($key eq $chap) {
1732 return $ModuleSynopses{$chap};
1733 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001734 }
Fred Drake643d76d2000-09-09 06:07:37 +00001735 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001736 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001737 return $st;
1738}
1739
Fred Drake62e43691998-08-10 19:40:44 +00001740sub do_cmd_moduleauthor{
1741 local($_) = @_;
1742 next_argument();
1743 next_argument();
1744 return $_;
1745}
1746
1747sub do_cmd_sectionauthor{
1748 local($_) = @_;
1749 next_argument();
1750 next_argument();
1751 return $_;
1752}
1753
Fred Drakea0f4c941998-07-24 22:16:04 +00001754sub do_cmd_declaremodule{
1755 local($_) = @_;
1756 my $key = next_optional_argument();
1757 my $type = next_argument();
1758 my $name = next_argument();
1759 my $st = get_synopsis_table(get_chapter_id());
1760 #
1761 $key = $name unless $key;
1762 $type = 'built-in' if $type eq 'builtin';
1763 $st->declare($name, $key, $type);
1764 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001765 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001766}
1767
1768sub do_cmd_modulesynopsis{
1769 local($_) = @_;
1770 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001771 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001772 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001773}
1774
1775sub do_cmd_localmoduletable{
1776 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001777 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001778 my $st = get_synopsis_table($chap);
1779 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001780 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001781}
1782
Fred Drakef5478632002-05-23 17:59:16 +00001783sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001784 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001785 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001786 my $st = $ModuleSynopses{$key};
1787 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001788 if ($file) {
1789 process_localmoduletables_in_file($file);
1790 }
1791 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001792 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001793 }
1794 }
1795}
1796
Fred Drakef5478632002-05-23 17:59:16 +00001797sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001798 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001799 open(MYFILE, "<$file");
1800 local($_);
1801 sysread(MYFILE, $_, 1024*1024);
1802 close(MYFILE);
1803 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001804 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001805 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001806 my $chap = $1;
1807 my $st = get_synopsis_table($chap);
1808 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001809 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001810 }
Fred Drake643d76d2000-09-09 06:07:37 +00001811 open(MYFILE,">$file");
1812 print MYFILE $_;
1813 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001814}
Fred Drakef5478632002-05-23 17:59:16 +00001815sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001816 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001817 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001818}
Fred Drakea0f4c941998-07-24 22:16:04 +00001819
1820
1821#
1822# "See also:" -- references placed at the end of a \section
1823#
1824
1825sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001826 return ("<div class=\"seealso\">\n "
1827 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001828 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001829 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001830}
1831
Fred Drake5ed35fd2001-11-30 18:09:54 +00001832sub do_env_seealsostar{
1833 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001834 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001835 . '</div>');
1836}
1837
Fred Drakea0f4c941998-07-24 22:16:04 +00001838sub do_cmd_seemodule{
1839 # Insert the right magic to jump to the module definition. This should
1840 # work most of the time, at least for repeat builds....
1841 local($_) = @_;
1842 my $key = next_optional_argument();
1843 my $module = next_argument();
1844 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001845 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001846 $key = $module
1847 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001848 if ($text =~ /\.$/) {
1849 $period = '';
1850 }
Fred Drakef1927a62001-06-20 21:29:30 +00001851 return ('<dl compact class="seemodule">'
1852 . "\n <dt>Module <b><tt class=\"module\">"
1853 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1854 . "\n <dd>$text$period\n </dl>"
1855 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001856}
1857
Fred Drakee0197bf2001-04-12 04:03:22 +00001858sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001859 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001860 my $s = "$str";
1861 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1862 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1863 return $s;
1864}
1865
Fred Drakef5478632002-05-23 17:59:16 +00001866sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001867 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001868 my $rfcnum = next_argument();
1869 my $title = next_argument();
1870 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001871 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001872 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001873 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001874 return '<dl compact class="seerfc">'
1875 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001876 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001877 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001878 . "\n <dd>$text\n </dl>"
1879 . $_;
1880}
1881
Fred Drake643d76d2000-09-09 06:07:37 +00001882sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001883 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001884}
1885
1886sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001887 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001888 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001889}
1890
Fred Drake48449982000-09-12 17:52:33 +00001891sub do_cmd_seetitle{
1892 local($_) = @_;
1893 my $url = next_optional_argument();
1894 my $title = next_argument();
1895 my $text = next_argument();
1896 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001897 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001898 return '<dl compact class="seetitle">'
1899 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001900 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001901 . "\n <dd>$text\n </dl>"
1902 . $_;
1903 }
1904 return '<dl compact class="seetitle">'
1905 . "\n <dt><em class=\"citetitle\""
1906 . "\n >$title</em>"
1907 . "\n <dd>$text\n </dl>"
1908 . $_;
1909}
1910
Fred Drakeef4d1112000-05-09 16:17:51 +00001911sub do_cmd_seeurl{
1912 local($_) = @_;
1913 my $url = next_argument();
1914 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001915 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001916 return '<dl compact class="seeurl">'
1917 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001918 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001919 . "\n <dd>$text\n </dl>"
1920 . $_;
1921}
1922
Fred Drakea0f4c941998-07-24 22:16:04 +00001923sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001924 local($_) = @_;
1925 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001926 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001927}
1928
1929
1930#
Fred Drake885215c1998-05-20 21:32:09 +00001931# Definition list support.
1932#
1933
1934sub do_env_definitions{
Fred Drake49b33fa2002-11-15 19:04:10 +00001935 return "<dl class=\"definitions\">" . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001936}
1937
1938sub do_cmd_term{
1939 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001940 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001941 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001942 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001943 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001944}
1945
1946
Fred Drake4e72e052003-07-15 22:00:36 +00001947# Commands listed here have process-order dependencies; these often
1948# are related to indexing operations.
1949# XXX Not sure why funclineni, methodlineni, and samp are here.
1950#
Fred Drake2ff880e1999-02-05 18:31:29 +00001951process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001952declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001953funcline # {} # {}
1954funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001955memberline # [] # {}
1956methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001957methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001958modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001959bifuncindex # {}
1960exindex # {}
1961indexii # {} # {}
1962indexiii # {} # {} # {}
1963indexiv # {} # {} # {} # {}
1964kwindex # {}
1965obindex # {}
1966opindex # {}
1967stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00001968platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001969samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001970setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001971withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001972_RAW_ARG_DEFERRED_CMDS_
1973
1974
Fred Drake8a5e6792002-04-15 18:41:31 +00001975$alltt_start = '<div class="verbatim"><pre>';
1976$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001977
Fred Drakef5478632002-05-23 17:59:16 +00001978sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001979 local ($_) = @_;
1980 local($closures,$reopens,@open_block_tags);
1981
1982 # get the tag-strings for all open tags
1983 local(@keep_open_tags) = @$open_tags_R;
1984 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1985
1986 # get the tags for text-level tags only
1987 $open_tags_R = [ @keep_open_tags ];
1988 local($local_closures, $local_reopens);
1989 ($local_closures, $local_reopens,@open_block_tags)
1990 = &preserve_open_block_tags
1991 if (@$open_tags_R);
1992
1993 $open_tags_R = [ @open_block_tags ];
1994
1995 do {
1996 local($open_tags_R) = [ @open_block_tags ];
1997 local(@save_open_tags) = ();
1998
1999 local($cnt) = ++$global{'max_id'};
2000 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2001 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
2002
2003 $_ = &translate_environments($_);
2004 $_ = &translate_commands($_) if (/\\/);
2005
2006 # preserve space-runs, using &nbsp;
2007 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
2008 s/(<BR>) /$1;SPMnbsp;/g;
2009
2010 $_ = join('', $closures, $alltt_start, $local_reopens
2011 , $_
2012 , &balance_tags() #, $local_closures
2013 , $alltt_end, $reopens);
2014 undef $open_tags_R; undef @save_open_tags;
2015 };
2016 $open_tags_R = [ @keep_open_tags ];
2017 $_;
2018}
2019
Fred Drake6fc22f62002-06-17 15:01:05 +00002020# List of all filenames produced ny do_cmd_verbatiminput()
2021%VerbatimFiles = ();
2022@VerbatimOutputs = ();
2023
2024sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002025 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002026 #
2027 # Re-write the source filename to always use a .txt extension
2028 # so that Web servers will present it as text/plain. This is
2029 # needed since there is no other even moderately reliable way
2030 # to get the right Content-Type header on text files for
2031 # servers which we can't configure (like python.org mirrors).
2032 #
2033 if (defined $VerbatimFiles{$file}) {
2034 # We've seen this one before; re-use the same output file.
2035 return $VerbatimFiles{$file};
2036 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002037 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002038 $filename = "$srcname.txt";
2039 #
2040 # We need to determine if our default filename is already
2041 # being used, and find a new one it it is. If the name is in
2042 # used, this algorithm will first attempt to include the
2043 # source extension as part of the name, and if that is also in
2044 # use (if the same file is included multiple times, or if
2045 # another source file has that as the base name), a counter is
2046 # used instead.
2047 #
2048 my $found = 1;
2049 FIND:
2050 while ($found) {
2051 foreach $fn (@VerbatimOutputs) {
2052 if ($fn eq $filename) {
2053 if ($found == 1) {
2054 $srcext =~ s/^[.]//; # Remove '.' from extension
2055 $filename = "$srcname-$srcext.txt";
2056 }
2057 else {
2058 $filename = "$srcname-$found.txt";
2059 }
2060 ++$found;
2061 next FIND;
2062 }
2063 }
2064 $found = 0;
2065 }
2066 push @VerbatimOutputs, $filename;
2067 $VerbatimFiles{$file} = $filename;
2068 return $filename;
2069}
2070
Fred Drake57e52ef2001-06-15 21:31:57 +00002071sub do_cmd_verbatiminput{
2072 local($_) = @_;
2073 my $fname = next_argument();
2074 my $file;
2075 my $found = 0;
2076 my $texpath;
2077 # Search TEXINPUTS for the input file, the way we're supposed to:
2078 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2079 $file = "$texpath$dd$fname";
2080 last if ($found = (-f $file));
2081 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002082 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002083 my $text;
2084 if ($found) {
2085 open(MYFILE, "<$file") || die "\n$!\n";
2086 read(MYFILE, $text, 1024*1024);
2087 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002088 $filename = get_verbatim_output_name($file);
2089 # Now that we have a filename, write it out.
2090 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002091 print MYFILE $text;
2092 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002093 #
2094 # These rewrites convert the raw text to something that will
2095 # be properly visible as HTML and also will pass through the
2096 # vagaries of conversion through LaTeX2HTML. The order in
2097 # which the specific rewrites are performed is significant.
2098 #
2099 $text =~ s/\&/\&amp;/g;
2100 # These need to happen before the normal < and > re-writes,
2101 # since we need to avoid LaTeX2HTML's attempt to perform
2102 # ligature processing without regard to context (since it
2103 # doesn't have font information).
2104 $text =~ s/--/-&\#45;/g;
2105 $text =~ s/<</\&lt;\&\#60;/g;
2106 $text =~ s/>>/\&gt;\&\#62;/g;
2107 # Just normal re-writes...
2108 $text =~ s/</\&lt;/g;
2109 $text =~ s/>/\&gt;/g;
2110 # These last isn't needed for the HTML, but is needed to get
2111 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2112 # of &sol; since many browsers don't support that.
2113 $text =~ s/\\/\&\#92;/g;
2114 }
2115 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002116 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2117 }
2118 my $note = 'Download as text.';
2119 if ($file ne $filename) {
2120 $note = ('Download as text (original file name: <span class="file">'
2121 . $fname
2122 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002123 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002124 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002125 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002126 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002127 . "<a href=\"$filename\" type=\"text/plain\""
2128 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002129 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002130 . $_);
2131}
Fred Drake86333602001-04-10 17:13:39 +00002132
Fred Drake6659c301998-03-03 22:02:19 +000021331; # This must be the last line