blob: 1f380cbcb6626429c7629443775190ab44919449 [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 Drake2fc88a62003-08-05 03:45:37 +000054 . " />");
Fred Drake7a40c072000-10-02 14:43:38 +000055 }
56 return '';
57}
Fred Drakee16f6791998-05-15 04:28:37 +000058
59# This is a fairly simple hack; it supports \let when it is used to create
60# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000061# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000062#
63sub do_cmd_let{
64 local($_) = @_;
65 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000066 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000067 if ($matched) {
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 Drake2fc88a62003-08-05 03:45:37 +0000348 return ("<a class=\"rfc\" name=\"$id\" id='$id'\n"
349 . "href=\"$href\">PEP $rfcnumber$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000350}
351
Fred Drake6659c301998-03-03 22:02:19 +0000352sub do_cmd_rfc{
353 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000354 my $rfcnumber = next_argument();
355 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000356 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000357 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000358 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000359 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000360 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake2fc88a62003-08-05 03:45:37 +0000361 return ("<a class=\"rfc\" name=\"$id\" id='$id'\nhref=\"$href\">"
362 . "RFC $rfcnumber$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000363}
364
Fred Drake77602f22001-07-06 22:43:02 +0000365sub do_cmd_ulink{
366 local($_) = @_;
367 my $text = next_argument();
368 my $url = next_argument();
369 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
370}
371
Fred Drakec9f5fe01999-11-09 16:59:42 +0000372sub do_cmd_citetitle{
373 local($_) = @_;
374 my $url = next_optional_argument();
375 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000376 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000377 my $repl = '';
378 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000379 $repl = ("<em class=\"citetitle\"><a\n"
380 . " href=\"$url\"\n"
381 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000382 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000383 }
384 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000385 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000386 }
387 return $repl . $_;
388}
389
Fred Drake6659c301998-03-03 22:02:19 +0000390sub do_cmd_deprecated{
391 # two parameters: \deprecated{version}{whattodo}
392 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000393 my $release = next_argument();
394 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000395 return ('<div class="versionnote">'
396 . "<b>Deprecated since release $release.</b>"
Fred Drake2fc88a62003-08-05 03:45:37 +0000397 . "\n$reason</div><p></p>"
Fred Drakeafc7ce12001-01-22 17:33:24 +0000398 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000399}
400
Fred Drakef5478632002-05-23 17:59:16 +0000401sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000402 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000403 my $type = $_[0];
404 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000405 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000406 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000407 my $text = "$type in version $release.";
408 if ($explanation) {
409 $text = "$type in version $release:\n$explanation.";
410 }
Fred Drakef1927a62001-06-20 21:29:30 +0000411 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000412}
413
414sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000415 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000416}
417
418sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000419 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000420}
421
Fred Drake557460c1999-03-02 16:05:35 +0000422#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000423# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000424#
425sub do_cmd_platform{
426 local($_) = @_;
427 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000428 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000429 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000430 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000431 return "\n<p class=\"availability\">Availability: <span"
432 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000433}
434
Fred Drake557460c1999-03-02 16:05:35 +0000435$IGNORE_PLATFORM_ANNOTATION = '';
436sub do_cmd_ignorePlatformAnnotation{
437 local($_) = @_;
438 $IGNORE_PLATFORM_ANNOTATION = next_argument();
439 return $_;
440}
441
Fred Drake6659c301998-03-03 22:02:19 +0000442
443# index commands
444
445$INDEX_SUBITEM = "";
446
Fred Drakef5478632002-05-23 17:59:16 +0000447sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000448 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000449}
450
451sub do_cmd_setindexsubitem{
452 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000453 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000454 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000455}
456
Fred Drakefc16e781998-03-12 21:03:26 +0000457sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000458 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000459 # do things in the right order, but we need to at least strip this stuff
460 # out, and leave anything that the second argument expanded out to.
461 #
462 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000463 my $oldsubitem = $INDEX_SUBITEM;
464 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000465 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000466 my $br_id = ++$globals{'max_id'};
467 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000468 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000469 return
470 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000471 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000472 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000473}
474
Fred Drake08932051998-04-17 02:15:42 +0000475# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000476# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
477# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000478#
Fred Drake49b33fa2002-11-15 19:04:10 +0000479sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000480
Fred Drake42b31a51998-03-27 05:16:10 +0000481# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000482#
Fred Drake08932051998-04-17 02:15:42 +0000483open(IDXFILE, '>index.dat') || die "\n$!\n";
484open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000485print INTLABELS "%internal_labels = ();\n";
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 Drake2fc88a62003-08-05 03:45:37 +0000515 my $aname = "<a name=\"$name\" id='$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 Drake2fc88a62003-08-05 03:45:37 +0000813 . " <td><code><a name=\"tok-$token\" id='tok-$token'>"
814 . "$token</a></code></td>\n"
Fred Drake77602f22001-07-06 22:43:02 +0000815 . " <td>&nbsp;::=&nbsp;</td>\n"
816 . " <td><code>"
817 . translate_commands($defn)
818 . "</code></td></tr>"
819 . $_);
820}
821
Fred Drake53815882002-03-15 23:21:37 +0000822sub do_cmd_productioncont{
823 local($_) = @_;
824 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000825 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000826 return ("<tr valign=\"baseline\">\n"
827 . " <td>&nbsp;</td>\n"
828 . " <td>&nbsp;</td>\n"
829 . " <td><code>"
830 . translate_commands($defn)
831 . "</code></td></tr>"
832 . $_);
833}
834
Fred Drakef5478632002-05-23 17:59:16 +0000835sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000836 my $lang;
837 my $filename;
838 local($_);
839 print "process_grammar_files()\n";
840 foreach $lang (keys %DefinedGrammars) {
841 $filename = "grammar-$lang.txt";
842 if ($lang eq '*') {
843 next;
844 }
845 if ($lang eq '') {
846 $filename = 'grammar.txt';
847 }
848 open(GRAMMAR, ">$filename") || die "\n$!\n";
849 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
850 close(GRAMMAR);
851 print "Wrote grammar file $filename\n";
852 }
853 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
854 foreach $filename (keys %BackpatchGrammarFiles) {
855 print "\nBack-patching grammar links in $filename\n";
856 my $buffer;
857 open(GRAMMAR, "<$filename") || die "\n$!\n";
858 # read all of the file into the buffer
859 sysread(GRAMMAR, $buffer, 1024*1024);
860 close(GRAMMAR);
861 while ($buffer =~ /$PATTERN/) {
862 my($lang, $token) = ($1, $2);
863 my $target = $TokenToTargetMapping{"$lang:$token"};
864 my $source = "<pyGrammarToken><$lang><$token>";
865 $buffer =~ s/$source/$target/g;
866 }
867 open(GRAMMAR, ">$filename") || die "\n$!\n";
868 print GRAMMAR $buffer;
869 close(GRAMMAR);
870 }
871}
872
Fred Drakef5478632002-05-23 17:59:16 +0000873sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000874 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000875 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000876 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
877 s/\\token(<<\d+>>)(.+)\1/$2/g;
878 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000879 s/<<\d+>>//g;
880 s/;SPMgt;/>/g;
881 s/;SPMlt;/</g;
882 s/;SPMquot;/\"/g;
883 return $_;
884}
885
886
Fred Drakee15956b2000-04-03 04:51:13 +0000887$REFCOUNTS_LOADED = 0;
888
Fred Drakef5478632002-05-23 17:59:16 +0000889sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000890 $REFCOUNTS_LOADED = 1;
891
Fred Drake49b33fa2002-11-15 19:04:10 +0000892 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drakee15956b2000-04-03 04:51:13 +0000893 chop $mydir; # remove trailing '/'
894 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
895 chop $mydir; # remove trailing '/'
896 $mydir = getcwd() . "$dd$mydir"
897 unless $mydir =~ s|^/|/|;
898 local $_;
899 my $filename = "$mydir${dd}api${dd}refcounts.dat";
900 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
901 print "[loading API refcount data]";
902 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000903 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000904 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
905 #print "\n$func($param) --> $count";
906 $REFCOUNTS{"$func:$param"} = $count;
907 }
908 }
909}
910
Fred Drakef5478632002-05-23 17:59:16 +0000911sub get_refcount($$){
912 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000913 load_refcounts()
914 unless $REFCOUNTS_LOADED;
915 return $REFCOUNTS{"$func:$param"};
916}
917
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000918
919$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000920$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000921
Fred Drakef5478632002-05-23 17:59:16 +0000922sub cfuncline_helper($$$){
923 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000924 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000925 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000926 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000927 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000928 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
929 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000930 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
931 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
932 . "<td>$args)</td>"
933 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000934}
935sub do_cmd_cfuncline{
936 local($_) = @_;
937 my $type = next_argument();
938 my $name = next_argument();
939 my $args = next_argument();
940 my $siginfo = cfuncline_helper($type, $name, $args);
941 return "<dt>$siginfo\n<dd>" . $_;
942}
943sub do_env_cfuncdesc{
944 local($_) = @_;
945 my $type = next_argument();
946 my $name = next_argument();
947 my $args = next_argument();
948 my $siginfo = cfuncline_helper($type, $name, $args);
949 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000950 my $rcinfo = '';
951 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000952 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000953 }
954 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000955 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000956 }
Fred Drakec2578c52000-04-10 18:26:45 +0000957 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000958 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000959 }
Fred Drakee15956b2000-04-03 04:51:13 +0000960 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000961 $rcinfo = ( "\n<div class=\"refcount-info\">"
962 . "\n <span class=\"label\">Return value:</span>"
963 . "\n <span class=\"value\">$rcinfo.</span>"
964 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000965 }
Fred Drake2fc88a62003-08-05 03:45:37 +0000966 return "<dl><dt>$siginfo</dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000967 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000968 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +0000969 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000970}
971
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000972sub do_cmd_cmemberline{
973 local($_) = @_;
974 my $container = next_argument();
975 my $type = next_argument();
976 my $name = next_argument();
977 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000978 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000979 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +0000980 return "<dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000981 . $_;
982}
983sub do_env_cmemberdesc{
984 local($_) = @_;
985 my $container = next_argument();
986 my $type = next_argument();
987 my $name = next_argument();
988 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000989 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000990 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +0000991 return "<dl><dt>$type <b>$idx</b></dt>\n<dd>"
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000992 . $_
993 . '</dl>';
994}
995
Fred Drakee15956b2000-04-03 04:51:13 +0000996sub do_env_csimplemacrodesc{
997 local($_) = @_;
998 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000999 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001000 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001001 . $_
1002 . '</dl>'
1003}
1004
Fred Drake6659c301998-03-03 22:02:19 +00001005sub do_env_ctypedesc{
1006 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001007 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001008 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001009 $index_name = $type_name
1010 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001011 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001012 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
Fred Drake2fc88a62003-08-05 03:45:37 +00001013 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b></dt>"
1014 . "\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001015 . $_
1016 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001017}
1018
1019sub do_env_cvardesc{
1020 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001021 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001022 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001023 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001024 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001025 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001026 return "<dl><dt>$var_type <b>$idx</b></dt>\n"
Fred Drake62e43691998-08-10 19:40:44 +00001027 . '<dd>'
1028 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001029 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001030}
1031
Fred Drake3cdb89d2000-09-14 20:17:23 +00001032sub convert_args($){
1033 local($IN_DESC_HANDLER) = 1;
1034 local($_) = @_;
1035 return translate_commands($_);
1036}
1037
Fred Drakef6e90272002-06-18 18:24:16 +00001038sub funcline_helper($$$){
1039 my($first, $idxitem, $arglist) = @_;
1040 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001041 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1042 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
Fred Drake2fc88a62003-08-05 03:45:37 +00001043 . "\n <td><var>$arglist</var>)</td></tr></table></dt>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001044}
1045
Fred Drake6659c301998-03-03 22:02:19 +00001046sub do_env_funcdesc{
1047 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001048 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001049 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001050 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1051 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001052 . get_indexsubitem());
1053 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001054 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001055 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001056}
1057
1058sub do_env_funcdescni{
1059 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001060 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001061 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001062 my $prefix = "<tt class=\"function\">$function_name</tt>";
1063 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001064}
1065
1066sub do_cmd_funcline{
1067 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001068 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001069 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001070 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001071 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1072 $prefix =~ s/\(\)//;
1073
Fred Drakef6e90272002-06-18 18:24:16 +00001074 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001075}
1076
Fred Drake6b3fb781999-07-12 16:50:09 +00001077sub do_cmd_funclineni{
1078 local($_) = @_;
1079 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001080 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001081 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001082
Fred Drakef6e90272002-06-18 18:24:16 +00001083 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001084}
1085
Fred Drake6659c301998-03-03 22:02:19 +00001086# Change this flag to index the opcode entries. I don't think it's very
1087# useful to index them, since they're only presented to describe the dis
1088# module.
1089#
1090$INDEX_OPCODES = 0;
1091
1092sub do_env_opcodedesc{
1093 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001094 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001095 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001096 my $idx;
1097 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001098 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1099 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001100 $idx =~ s/ \(byte code instruction\)//;
1101 }
1102 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001103 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001104 }
1105 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001106 if ($arg_list) {
1107 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1108 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001109 return $stuff . "</dt>\n<dd>" . $_ . '</dt></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001110}
1111
1112sub do_env_datadesc{
1113 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001114 my $dataname = next_argument();
1115 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001116 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001117 return "<dl><dt><b>$idx</b></dt>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001118 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001119 . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001120}
1121
1122sub do_env_datadescni{
1123 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001124 my $idx = next_argument();
1125 if (! $STRING_INDEX_TT) {
1126 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001127 }
Fred Drake2fc88a62003-08-05 03:45:37 +00001128 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dd></dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001129}
1130
1131sub do_cmd_dataline{
1132 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001133 my $data_name = next_argument();
1134 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001135 $idx =~ s/ \(.*\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001136 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001137}
1138
Fred Drakeadb272c2000-04-10 17:47:14 +00001139sub do_cmd_datalineni{
1140 local($_) = @_;
1141 my $data_name = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001142 return "<dt><b><tt>$data_name</tt></b></dt><dd>" . $_;
Fred Drakeadb272c2000-04-10 17:47:14 +00001143}
1144
Fred Drake42b31a51998-03-27 05:16:10 +00001145sub do_env_excdesc{
1146 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001147 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001148 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drake2fc88a62003-08-05 03:45:37 +00001149 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b></dt>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001150 . "\n<dd>"
1151 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001152 . '</dd></dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001153}
1154
Fred Drake62e43691998-08-10 19:40:44 +00001155sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001156
1157
Fred Drakef5478632002-05-23 17:59:16 +00001158sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001159 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001160 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001161 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001162 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001163 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001164 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001165 my $prefix = "$TLSTART$what$TLEND$idx";
1166 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001167}
1168
Fred Drake643d76d2000-09-09 06:07:37 +00001169sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001170 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001171}
1172
Fred Drake06a01e82001-05-11 01:00:30 +00001173sub do_env_classdescstar{
1174 local($_) = @_;
1175 $THIS_CLASS = next_argument();
1176 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001177 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001178 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001179 my $prefix = "${TLSTART}class$TLEND$idx";
1180 # Can't use funcline_helper() since there is no args list.
1181 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001182}
1183
Fred Drake643d76d2000-09-09 06:07:37 +00001184sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001185 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001186}
1187
Fred Drake42b31a51998-03-27 05:16:10 +00001188
1189sub do_env_methoddesc{
1190 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001191 my $class_name = next_optional_argument();
1192 $class_name = $THIS_CLASS
1193 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001194 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001195 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001196 my $extra = '';
1197 if ($class_name) {
1198 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001199 }
Fred Drakef1927a62001-06-20 21:29:30 +00001200 my $idx = make_str_index_entry(
1201 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001202 $idx =~ s/ \(.*\)//;
1203 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001204 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001205}
1206
1207
Fred Drake7d45f6d1999-01-05 14:39:27 +00001208sub do_cmd_methodline{
1209 local($_) = @_;
1210 my $class_name = next_optional_argument();
1211 $class_name = $THIS_CLASS
1212 unless $class_name;
1213 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001214 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001215 my $extra = '';
1216 if ($class_name) {
1217 $extra = " ($class_name method)";
1218 }
Fred Drakef1927a62001-06-20 21:29:30 +00001219 my $idx = make_str_index_entry(
1220 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001221 $idx =~ s/ \(.*\)//;
1222 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001223 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001224}
1225
1226
Fred Draked64a40d1998-09-10 18:59:13 +00001227sub do_cmd_methodlineni{
1228 local($_) = @_;
1229 next_optional_argument();
1230 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001231 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001232 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001233}
1234
Fred Drake42b31a51998-03-27 05:16:10 +00001235sub do_env_methoddescni{
1236 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001237 next_optional_argument();
1238 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001239 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001240 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001241}
1242
1243
1244sub do_env_memberdesc{
1245 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001246 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001247 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001248 $class = $THIS_CLASS
1249 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001250 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001251 $extra = " ($class attribute)"
1252 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001253 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001254 $idx =~ s/ \(.*\)//;
1255 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001256 return "<dl><dt><b>$idx</b></dt>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001257}
1258
1259
Fred Drake5ccf3301998-04-17 20:04:09 +00001260sub do_cmd_memberline{
1261 local($_) = @_;
1262 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001263 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001264 $class = $THIS_CLASS
1265 unless $class;
1266 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001267 $extra = " ($class attribute)"
1268 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001269 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001270 $idx =~ s/ \(.*\)//;
1271 $idx =~ s/\(\)//;
Fred Drake2fc88a62003-08-05 03:45:37 +00001272 return "<dt><b>$idx</b></dt><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001273}
1274
Fred Drakef269e592001-07-17 23:05:57 +00001275
Fred Drake42b31a51998-03-27 05:16:10 +00001276sub do_env_memberdescni{
1277 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001278 next_optional_argument();
1279 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001280 return "<dl><dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001281 . $_
Fred Drake2fc88a62003-08-05 03:45:37 +00001282 . '</dd></dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001283}
1284
1285
Fred Drake5ccf3301998-04-17 20:04:09 +00001286sub do_cmd_memberlineni{
1287 local($_) = @_;
1288 next_optional_argument();
1289 my $member = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001290 return "<dt><b><tt class=\"member\">$member</tt></b></dt>\n<dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001291}
1292
Fred Drakef269e592001-07-17 23:05:57 +00001293
1294@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001295
Fred Drakecb199762001-08-16 21:56:24 +00001296%FontConversions = ('cdata' => 'tt class="cdata"',
1297 'character' => 'tt class="character"',
1298 'class' => 'tt class="class"',
1299 'command' => 'code',
1300 'constant' => 'tt class="constant"',
1301 'exception' => 'tt class="exception"',
1302 'file' => 'tt class="file"',
1303 'filenq' => 'tt class="file"',
1304 'kbd' => 'kbd',
1305 'member' => 'tt class="member"',
1306 'programopt' => 'b',
1307 'textrm' => '',
1308 );
1309
Fred Drakef5478632002-05-23 17:59:16 +00001310sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001311 # do a little magic on a font name to get the right behavior in the first
1312 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001313 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001314 if (defined $FontConversions{$font}) {
1315 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001316 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001317 return $font;
1318}
1319
Fred Drakef5478632002-05-23 17:59:16 +00001320sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001321 my $a = $_[0];
1322 if (!defined $a) {
1323 return '';
1324 }
Fred Drakee15956b2000-04-03 04:51:13 +00001325 my $mark = substr($a, 0, 1);
1326 my $r = '';
1327 if ($mark eq 'c')
1328 { $r = ' align="center"'; }
1329 elsif ($mark eq 'r')
1330 { $r = ' align="right"'; }
1331 elsif ($mark eq 'l')
1332 { $r = ' align="left"'; }
1333 elsif ($mark eq 'p')
1334 { $r = ' align="left"'; }
1335 return $r;
1336}
1337
Fred Drakef5478632002-05-23 17:59:16 +00001338sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001339 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001340 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001341 my $a1 = figure_column_alignment($s1);
1342 my $a2 = figure_column_alignment($s2);
1343 my $a3 = figure_column_alignment($s3);
1344 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001345 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001346 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1347 $col_aligns[1] = "<td$a2>";
1348 $col_aligns[2] = "<td$a3>";
1349 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001350 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001351 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001352 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001353}
1354
Fred Drakef5478632002-05-23 17:59:16 +00001355sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001356 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001357 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001358 if ($font) {
1359 $sfont = "<$font>";
1360 $efont = "</$font>";
1361 $efont =~ s/ .*>/>/;
1362 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001363 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001364}
1365
1366sub do_env_tableii{
1367 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001368 my $arg = next_argument();
1369 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001370 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001371 my $h1 = next_argument();
1372 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001373 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001374 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001375 my $a1 = $col_aligns[0];
1376 my $a2 = $col_aligns[1];
1377 s/\\lineii</\\lineii[$a1|$a2]</g;
1378 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001379 . "\n <thead>"
1380 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001381 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1382 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001383 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001384 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001385 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001386 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001387 . "\n </tbody>"
1388 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001389}
1390
Fred Drakeda72b932000-09-21 15:58:02 +00001391sub do_env_longtableii{
1392 return do_env_tableii(@_);
1393}
1394
Fred Drake6659c301998-03-03 22:02:19 +00001395sub do_cmd_lineii{
1396 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001397 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001398 my $c1 = next_argument();
1399 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001400 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001401 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001402 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001403 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001404 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001405 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001406 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001407 }
Fred Drakee15956b2000-04-03 04:51:13 +00001408 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1409 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001410 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001411}
1412
1413sub do_env_tableiii{
1414 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001415 my $arg = next_argument();
1416 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001417 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001418 my $h1 = next_argument();
1419 my $h2 = next_argument();
1420 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001421 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001422 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001423 my $a1 = $col_aligns[0];
1424 my $a2 = $col_aligns[1];
1425 my $a3 = $col_aligns[2];
1426 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1427 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001428 . "\n <thead>"
1429 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001430 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1431 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1432 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001433 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001434 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001435 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001436 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001437 . "\n </tbody>"
1438 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001439}
1440
Fred Drakeda72b932000-09-21 15:58:02 +00001441sub do_env_longtableiii{
1442 return do_env_tableiii(@_);
1443}
1444
Fred Drake6659c301998-03-03 22:02:19 +00001445sub do_cmd_lineiii{
1446 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001447 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001448 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001449 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001450 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001451 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001452 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001453 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001454 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001455 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001456 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001457 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001458 }
Fred Drakee15956b2000-04-03 04:51:13 +00001459 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001460 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001461 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001462 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001463}
1464
Fred Drakea0f4c941998-07-24 22:16:04 +00001465sub do_env_tableiv{
1466 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001467 my $arg = next_argument();
1468 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001469 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001470 my $h1 = next_argument();
1471 my $h2 = next_argument();
1472 my $h3 = next_argument();
1473 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001474 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001475 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001476 my $a1 = $col_aligns[0];
1477 my $a2 = $col_aligns[1];
1478 my $a3 = $col_aligns[2];
1479 my $a4 = $col_aligns[3];
1480 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1481 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001482 . "\n <thead>"
1483 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001484 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1485 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1486 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1487 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001488 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001489 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001490 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001491 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001492 . "\n </tbody>"
1493 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001494}
1495
Fred Drakeda72b932000-09-21 15:58:02 +00001496sub do_env_longtableiv{
1497 return do_env_tableiv(@_);
1498}
1499
Fred Drakea0f4c941998-07-24 22:16:04 +00001500sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001501 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001502 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001503 my $c1 = next_argument();
1504 my $c2 = next_argument();
1505 my $c3 = next_argument();
1506 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001507 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001508 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001509 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001510 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001511 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001512 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001513 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001514 }
Fred Drakee15956b2000-04-03 04:51:13 +00001515 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001516 . " $c2align$c2</td>\n"
1517 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001518 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001519 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001520}
1521
Fred Drakef269e592001-07-17 23:05:57 +00001522sub do_env_tablev{
1523 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001524 my $arg = next_argument();
1525 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001526 my $font = fix_font(next_argument());
1527 my $h1 = next_argument();
1528 my $h2 = next_argument();
1529 my $h3 = next_argument();
1530 my $h4 = next_argument();
1531 my $h5 = next_argument();
1532 s/[\s\n]+//;
1533 $globals{'lineifont'} = $font;
1534 my $a1 = $col_aligns[0];
1535 my $a2 = $col_aligns[1];
1536 my $a3 = $col_aligns[2];
1537 my $a4 = $col_aligns[3];
1538 my $a5 = $col_aligns[4];
1539 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1540 return '<table border align="center" style="border-collapse: collapse">'
1541 . "\n <thead>"
1542 . "\n <tr class=\"tableheader\">"
1543 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1544 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1545 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1546 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1547 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1548 . "\n </tr>"
1549 . "\n </thead>"
1550 . "\n <tbody valign=\"baseline\">"
1551 . $_
1552 . "\n </tbody>"
1553 . "\n</table>";
1554}
1555
1556sub do_env_longtablev{
1557 return do_env_tablev(@_);
1558}
1559
1560sub do_cmd_linev{
1561 local($_) = @_;
1562 my $aligns = next_optional_argument();
1563 my $c1 = next_argument();
1564 my $c2 = next_argument();
1565 my $c3 = next_argument();
1566 my $c4 = next_argument();
1567 my $c5 = next_argument();
1568 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001569 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001570 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001571 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001572 my $padding = '';
1573 if ($c1align =~ /align="right"/ || $c1 eq '') {
1574 $padding = '&nbsp;';
1575 }
1576 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1577 . " $c2align$c2</td>\n"
1578 . " $c3align$c3</td>\n"
1579 . " $c4align$c4</td>\n"
1580 . " $c5align$c5</td>"
1581 . $_;
1582}
1583
Fred Drake3be20742000-08-31 06:22:54 +00001584
1585# These can be used to control the title page appearance;
1586# they need a little bit of documentation.
1587#
1588# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1589# $ICONSERVER directory, or include path information (other than "./"). The
1590# default image type will be assumed if an extension is not provided.
1591#
1592# If specified, the "title page" will contain two colums: one containing the
1593# title/author/etc., and the other containing the graphic. Use the other
1594# four variables listed here to control specific details of the layout; all
1595# are optional.
1596#
1597# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1598# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1599# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1600# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1601# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1602
Fred Drakef5478632002-05-23 17:59:16 +00001603sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001604 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001605 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001606 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001607 }
1608 else {
1609 write_warnings("\nThis document has no title.");
1610 }
Fred Drake6659c301998-03-03 22:02:19 +00001611 if ($t_author) {
1612 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001613 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001614 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001615 "<b><font size=\"+2\">$t_author"
1616 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001617 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001618 }
1619 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001620 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1621 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001622 }
Fred Drake3be20742000-08-31 06:22:54 +00001623 }
1624 else {
1625 write_warnings("\nThere is no author for this document.");
1626 }
Fred Drake6659c301998-03-03 22:02:19 +00001627 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001628 $the_title .= "\n<p>$t_institute</p>";
1629 }
Fred Draked07868a1998-05-14 21:00:28 +00001630 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001631 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1632 }
Fred Drake6659c301998-03-03 22:02:19 +00001633 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001634 $the_title .= "\n<p><i>$t_affil</i></p>";
1635 }
Fred Drake6659c301998-03-03 22:02:19 +00001636 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001637 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001638 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001639 $the_title .= ('<strong>Release '
Fred Drake2fc88a62003-08-05 03:45:37 +00001640 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br />\n");
Fred Drake3be20742000-08-31 06:22:54 +00001641 }
Fred Drakede77bc52000-12-14 18:36:12 +00001642 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001643 }
1644 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001645 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001646 }
1647 else {
Fred Drake2fc88a62003-08-05 03:45:37 +00001648 $the_title .= "\n<p></p>";
Fred Drake3be20742000-08-31 06:22:54 +00001649 }
Fred Drake6659c301998-03-03 22:02:19 +00001650 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001651 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001652 }
1653 return $the_title;
1654}
1655
Fred Drakef5478632002-05-23 17:59:16 +00001656sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001657 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001658 my $graphic = "<td class=\"titlegraphic\"";
1659 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1660 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1661 $graphic .= "><img";
1662 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1663 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1664 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1665 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake2fc88a62003-08-05 03:45:37 +00001666 $graphic .= "\n src=\"$filename\" /></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001667 return $graphic;
1668}
1669
Fred Drakef5478632002-05-23 17:59:16 +00001670sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001671 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001672 my $the_title = "\n";
1673 if ($EXTERNAL_UP_LINK) {
Fred Drake2fc88a62003-08-05 03:45:37 +00001674 # This generates a <link> element in the wrong place (the
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001675 # body), but I don't see any other way to get this generated
1676 # at all. Browsers like Mozilla, that support navigation
1677 # links, can make use of this.
1678 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1679 . ($EXTERNAL_UP_TITLE
1680 ? " title='$EXTERNAL_UP_TITLE'" : '')
Fred Drake2fc88a62003-08-05 03:45:37 +00001681 . " />\n");
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001682 }
1683 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001684 if ($TITLE_PAGE_GRAPHIC) {
1685 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1686 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1687 . "<tr align=\"right\">\n<td>"
1688 . make_my_titlepage()
1689 . "</td>\n"
1690 . make_my_titlegraphic()
1691 . "</tr>\n</table>");
1692 }
1693 else {
1694 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1695 . make_my_titlegraphic()
1696 . "<td>"
1697 . make_my_titlepage()
1698 . "</td></tr>\n</table>");
1699 }
1700 }
1701 else {
1702 $the_title .= ("\n<center>"
1703 . make_my_titlepage()
1704 . "\n</center>");
1705 }
1706 $the_title .= "\n</div>";
1707 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001708 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001709 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001710}
1711
1712
Fred Drake885215c1998-05-20 21:32:09 +00001713#
Fred Drakea0f4c941998-07-24 22:16:04 +00001714# Module synopsis support
1715#
1716
1717require SynopsisTable;
1718
Fred Drakef7685d71998-07-25 03:31:46 +00001719sub get_chapter_id(){
1720 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001721 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001722 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001723 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001724}
1725
Fred Drake643d76d2000-09-09 06:07:37 +00001726# 'chapter' => 'SynopsisTable instance'
1727%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001728
1729sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001730 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001731 my $key;
1732 foreach $key (keys %ModuleSynopses) {
1733 if ($key eq $chap) {
1734 return $ModuleSynopses{$chap};
1735 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001736 }
Fred Drake643d76d2000-09-09 06:07:37 +00001737 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001738 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001739 return $st;
1740}
1741
Fred Drake62e43691998-08-10 19:40:44 +00001742sub do_cmd_moduleauthor{
1743 local($_) = @_;
1744 next_argument();
1745 next_argument();
1746 return $_;
1747}
1748
1749sub do_cmd_sectionauthor{
1750 local($_) = @_;
1751 next_argument();
1752 next_argument();
1753 return $_;
1754}
1755
Fred Drakea0f4c941998-07-24 22:16:04 +00001756sub do_cmd_declaremodule{
1757 local($_) = @_;
1758 my $key = next_optional_argument();
1759 my $type = next_argument();
1760 my $name = next_argument();
1761 my $st = get_synopsis_table(get_chapter_id());
1762 #
1763 $key = $name unless $key;
1764 $type = 'built-in' if $type eq 'builtin';
1765 $st->declare($name, $key, $type);
1766 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001767 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001768}
1769
1770sub do_cmd_modulesynopsis{
1771 local($_) = @_;
1772 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001773 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001774 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001775}
1776
1777sub do_cmd_localmoduletable{
1778 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001779 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001780 my $st = get_synopsis_table($chap);
1781 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001782 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001783}
1784
Fred Drakef5478632002-05-23 17:59:16 +00001785sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001786 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001787 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001788 my $st = $ModuleSynopses{$key};
1789 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001790 if ($file) {
1791 process_localmoduletables_in_file($file);
1792 }
1793 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001794 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001795 }
1796 }
1797}
1798
Fred Drakef5478632002-05-23 17:59:16 +00001799sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001800 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001801 open(MYFILE, "<$file");
1802 local($_);
1803 sysread(MYFILE, $_, 1024*1024);
1804 close(MYFILE);
1805 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001806 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001807 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001808 my $chap = $1;
1809 my $st = get_synopsis_table($chap);
1810 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001811 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001812 }
Fred Drake643d76d2000-09-09 06:07:37 +00001813 open(MYFILE,">$file");
1814 print MYFILE $_;
1815 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001816}
Fred Drakef5478632002-05-23 17:59:16 +00001817sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001818 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001819 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001820}
Fred Drakea0f4c941998-07-24 22:16:04 +00001821
1822
1823#
1824# "See also:" -- references placed at the end of a \section
1825#
1826
1827sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001828 return ("<div class=\"seealso\">\n "
1829 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001830 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001831 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001832}
1833
Fred Drake5ed35fd2001-11-30 18:09:54 +00001834sub do_env_seealsostar{
1835 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001836 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001837 . '</div>');
1838}
1839
Fred Drakea0f4c941998-07-24 22:16:04 +00001840sub do_cmd_seemodule{
1841 # Insert the right magic to jump to the module definition. This should
1842 # work most of the time, at least for repeat builds....
1843 local($_) = @_;
1844 my $key = next_optional_argument();
1845 my $module = next_argument();
1846 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001847 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001848 $key = $module
1849 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001850 if ($text =~ /\.$/) {
1851 $period = '';
1852 }
Fred Drakef1927a62001-06-20 21:29:30 +00001853 return ('<dl compact class="seemodule">'
1854 . "\n <dt>Module <b><tt class=\"module\">"
1855 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1856 . "\n <dd>$text$period\n </dl>"
1857 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001858}
1859
Fred Drakee0197bf2001-04-12 04:03:22 +00001860sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001861 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001862 my $s = "$str";
1863 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1864 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1865 return $s;
1866}
1867
Fred Drakef5478632002-05-23 17:59:16 +00001868sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001869 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001870 my $rfcnum = next_argument();
1871 my $title = next_argument();
1872 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001873 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001874 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001875 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001876 return '<dl compact class="seerfc">'
1877 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001878 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001879 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001880 . "\n <dd>$text\n </dl>"
1881 . $_;
1882}
1883
Fred Drake643d76d2000-09-09 06:07:37 +00001884sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001885 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001886}
1887
1888sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001889 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001890 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001891}
1892
Fred Drake48449982000-09-12 17:52:33 +00001893sub do_cmd_seetitle{
1894 local($_) = @_;
1895 my $url = next_optional_argument();
1896 my $title = next_argument();
1897 my $text = next_argument();
1898 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001899 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001900 return '<dl compact class="seetitle">'
1901 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001902 . "\n >$title$icon</a></em></dt>"
1903 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001904 . $_;
1905 }
1906 return '<dl compact class="seetitle">'
1907 . "\n <dt><em class=\"citetitle\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001908 . "\n >$title</em></dt>"
1909 . "\n <dd>$text</dd>\n </dl>"
Fred Drake48449982000-09-12 17:52:33 +00001910 . $_;
1911}
1912
Fred Drakeef4d1112000-05-09 16:17:51 +00001913sub do_cmd_seeurl{
1914 local($_) = @_;
1915 my $url = next_argument();
1916 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001917 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001918 return '<dl compact class="seeurl">'
1919 . "\n <dt><a href=\"$url\""
Fred Drake2fc88a62003-08-05 03:45:37 +00001920 . "\n class=\"url\">$url$icon</a></dt>"
1921 . "\n <dd>$text</dd>\n </dl>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001922 . $_;
1923}
1924
Fred Drakea0f4c941998-07-24 22:16:04 +00001925sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001926 local($_) = @_;
1927 my $content = next_argument();
Fred Drake2fc88a62003-08-05 03:45:37 +00001928 return '<div class="seetext"><p>' . $content . '</p></div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001929}
1930
1931
1932#
Fred Drake885215c1998-05-20 21:32:09 +00001933# Definition list support.
1934#
1935
1936sub do_env_definitions{
Fred Drake2fc88a62003-08-05 03:45:37 +00001937 return '<dl class="definitions">' . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001938}
1939
1940sub do_cmd_term{
1941 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001942 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001943 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001944 # could easily add an index entry here...
Fred Drake2fc88a62003-08-05 03:45:37 +00001945 return "<dt><b>$aname" . $term . "</a></b></dt>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001946}
1947
1948
Fred Drake4e72e052003-07-15 22:00:36 +00001949# Commands listed here have process-order dependencies; these often
1950# are related to indexing operations.
1951# XXX Not sure why funclineni, methodlineni, and samp are here.
1952#
Fred Drake2ff880e1999-02-05 18:31:29 +00001953process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001954declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001955funcline # {} # {}
1956funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001957memberline # [] # {}
1958methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001959methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001960modulesynopsis # {}
Fred Drake4e72e052003-07-15 22:00:36 +00001961bifuncindex # {}
1962exindex # {}
1963indexii # {} # {}
1964indexiii # {} # {} # {}
1965indexiv # {} # {} # {} # {}
1966kwindex # {}
1967obindex # {}
1968opindex # {}
1969stindex # {}
Fred Drake557460c1999-03-02 16:05:35 +00001970platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001971samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001972setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001973withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001974_RAW_ARG_DEFERRED_CMDS_
1975
1976
Fred Drake8a5e6792002-04-15 18:41:31 +00001977$alltt_start = '<div class="verbatim"><pre>';
1978$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001979
Fred Drakef5478632002-05-23 17:59:16 +00001980sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001981 local ($_) = @_;
1982 local($closures,$reopens,@open_block_tags);
1983
1984 # get the tag-strings for all open tags
1985 local(@keep_open_tags) = @$open_tags_R;
1986 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1987
1988 # get the tags for text-level tags only
1989 $open_tags_R = [ @keep_open_tags ];
1990 local($local_closures, $local_reopens);
1991 ($local_closures, $local_reopens,@open_block_tags)
1992 = &preserve_open_block_tags
1993 if (@$open_tags_R);
1994
1995 $open_tags_R = [ @open_block_tags ];
1996
1997 do {
1998 local($open_tags_R) = [ @open_block_tags ];
1999 local(@save_open_tags) = ();
2000
2001 local($cnt) = ++$global{'max_id'};
2002 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
2003 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
2004
2005 $_ = &translate_environments($_);
2006 $_ = &translate_commands($_) if (/\\/);
2007
2008 # preserve space-runs, using &nbsp;
2009 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
2010 s/(<BR>) /$1;SPMnbsp;/g;
2011
2012 $_ = join('', $closures, $alltt_start, $local_reopens
2013 , $_
2014 , &balance_tags() #, $local_closures
2015 , $alltt_end, $reopens);
2016 undef $open_tags_R; undef @save_open_tags;
2017 };
2018 $open_tags_R = [ @keep_open_tags ];
2019 $_;
2020}
2021
Fred Drake6fc22f62002-06-17 15:01:05 +00002022# List of all filenames produced ny do_cmd_verbatiminput()
2023%VerbatimFiles = ();
2024@VerbatimOutputs = ();
2025
2026sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002027 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002028 #
2029 # Re-write the source filename to always use a .txt extension
2030 # so that Web servers will present it as text/plain. This is
2031 # needed since there is no other even moderately reliable way
2032 # to get the right Content-Type header on text files for
2033 # servers which we can't configure (like python.org mirrors).
2034 #
2035 if (defined $VerbatimFiles{$file}) {
2036 # We've seen this one before; re-use the same output file.
2037 return $VerbatimFiles{$file};
2038 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002039 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002040 $filename = "$srcname.txt";
2041 #
2042 # We need to determine if our default filename is already
2043 # being used, and find a new one it it is. If the name is in
2044 # used, this algorithm will first attempt to include the
2045 # source extension as part of the name, and if that is also in
2046 # use (if the same file is included multiple times, or if
2047 # another source file has that as the base name), a counter is
2048 # used instead.
2049 #
2050 my $found = 1;
2051 FIND:
2052 while ($found) {
2053 foreach $fn (@VerbatimOutputs) {
2054 if ($fn eq $filename) {
2055 if ($found == 1) {
2056 $srcext =~ s/^[.]//; # Remove '.' from extension
2057 $filename = "$srcname-$srcext.txt";
2058 }
2059 else {
2060 $filename = "$srcname-$found.txt";
2061 }
2062 ++$found;
2063 next FIND;
2064 }
2065 }
2066 $found = 0;
2067 }
2068 push @VerbatimOutputs, $filename;
2069 $VerbatimFiles{$file} = $filename;
2070 return $filename;
2071}
2072
Fred Drake57e52ef2001-06-15 21:31:57 +00002073sub do_cmd_verbatiminput{
2074 local($_) = @_;
2075 my $fname = next_argument();
2076 my $file;
2077 my $found = 0;
2078 my $texpath;
2079 # Search TEXINPUTS for the input file, the way we're supposed to:
2080 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2081 $file = "$texpath$dd$fname";
2082 last if ($found = (-f $file));
2083 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002084 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002085 my $text;
2086 if ($found) {
2087 open(MYFILE, "<$file") || die "\n$!\n";
2088 read(MYFILE, $text, 1024*1024);
2089 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002090 $filename = get_verbatim_output_name($file);
2091 # Now that we have a filename, write it out.
2092 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002093 print MYFILE $text;
2094 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002095 #
2096 # These rewrites convert the raw text to something that will
2097 # be properly visible as HTML and also will pass through the
2098 # vagaries of conversion through LaTeX2HTML. The order in
2099 # which the specific rewrites are performed is significant.
2100 #
2101 $text =~ s/\&/\&amp;/g;
2102 # These need to happen before the normal < and > re-writes,
2103 # since we need to avoid LaTeX2HTML's attempt to perform
2104 # ligature processing without regard to context (since it
2105 # doesn't have font information).
2106 $text =~ s/--/-&\#45;/g;
2107 $text =~ s/<</\&lt;\&\#60;/g;
2108 $text =~ s/>>/\&gt;\&\#62;/g;
2109 # Just normal re-writes...
2110 $text =~ s/</\&lt;/g;
2111 $text =~ s/>/\&gt;/g;
2112 # These last isn't needed for the HTML, but is needed to get
2113 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2114 # of &sol; since many browsers don't support that.
2115 $text =~ s/\\/\&\#92;/g;
2116 }
2117 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002118 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2119 }
2120 my $note = 'Download as text.';
2121 if ($file ne $filename) {
2122 $note = ('Download as text (original file name: <span class="file">'
2123 . $fname
2124 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002125 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002126 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002127 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002128 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002129 . "<a href=\"$filename\" type=\"text/plain\""
2130 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002131 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002132 . $_);
2133}
Fred Drake86333602001-04-10 17:13:39 +00002134
Fred Drake6659c301998-03-03 22:02:19 +000021351; # This must be the last line