blob: 267e54931ea24d5b3bf166e40b92bd06ca868c3a [file] [log] [blame]
Fred Drake6659c301998-03-03 22:02:19 +00001# python.perl by Fred L. Drake, Jr. <fdrake@acm.org> -*- perl -*-
2#
3# Heavily based on Guido van Rossum's myformat.perl (now obsolete).
4#
5# Extension to LaTeX2HTML for documents using myformat.sty.
6# Subroutines of the form do_cmd_<name> here define translations
7# for LaTeX commands \<name> defined in the corresponding .sty file.
8
9package main;
10
Fred Drake49b33fa2002-11-15 19:04:10 +000011use warnings;
Fred Drake7a40c072000-10-02 14:43:38 +000012use File::Basename;
13
Fred Drake6659c301998-03-03 22:02:19 +000014
Fred Drake08932051998-04-17 02:15:42 +000015sub next_argument{
Fred Drakeccc62721999-01-05 22:16:29 +000016 my $param;
17 $param = missing_braces()
18 unless ((s/$next_pair_pr_rx/$param=$2;''/eo)
19 ||(s/$next_pair_rx/$param=$2;''/eo));
Fred Drake62e43691998-08-10 19:40:44 +000020 return $param;
Fred Drake08932051998-04-17 02:15:42 +000021}
22
23sub next_optional_argument{
Fred Drakef5478632002-05-23 17:59:16 +000024 my($param, $rx) = ('', "^\\s*(\\[([^]]*)\\])?");
Fred Drake5ccf3301998-04-17 20:04:09 +000025 s/$rx/$param=$2;''/eo;
Fred Drake62e43691998-08-10 19:40:44 +000026 return $param;
Fred Drake08932051998-04-17 02:15:42 +000027}
28
Fred Drake7a40c072000-10-02 14:43:38 +000029sub make_icon_filename($){
Fred Drake49b33fa2002-11-15 19:04:10 +000030 my($myname, $mydir, $myext) = fileparse($_[0], '\..*');
Fred Drake7a40c072000-10-02 14:43:38 +000031 chop $mydir;
32 if ($mydir eq '.') {
33 $mydir = $ICONSERVER;
34 }
35 $myext = ".$IMAGE_TYPE"
36 unless $myext;
37 return "$mydir$dd$myname$myext";
38}
39
Fred Drake7a40c072000-10-02 14:43:38 +000040sub get_link_icon($){
Fred Drake49b33fa2002-11-15 19:04:10 +000041 my $url = $_[0];
Fred Drake7a40c072000-10-02 14:43:38 +000042 if ($OFF_SITE_LINK_ICON && ($url =~ /^[-a-zA-Z0-9.]+:/)) {
43 # absolute URL; assume it points off-site
44 my $icon = make_icon_filename($OFF_SITE_LINK_ICON);
Fred Drakef1927a62001-06-20 21:29:30 +000045 return (" <img src=\"$icon\"\n"
46 . ' border="0" class="offsitelink"'
Fred Drake5f84c9b2000-10-03 06:05:25 +000047 . ($OFF_SITE_LINK_ICON_HEIGHT
Fred Drakef1927a62001-06-20 21:29:30 +000048 ? " height=\"$OFF_SITE_LINK_ICON_HEIGHT\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000049 : '')
50 . ($OFF_SITE_LINK_ICON_WIDTH
Fred Drakef1927a62001-06-20 21:29:30 +000051 ? " width=\"$OFF_SITE_LINK_ICON_WIDTH\""
Fred Drake5f84c9b2000-10-03 06:05:25 +000052 : '')
Fred Drakef1927a62001-06-20 21:29:30 +000053 . " alt=\"[off-site link]\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +000054 . " >");
55 }
56 return '';
57}
Fred Drakee16f6791998-05-15 04:28:37 +000058
59# This is a fairly simple hack; it supports \let when it is used to create
60# (or redefine) a macro to exactly be some other macro: \let\newname=\oldname.
Fred Drake5b73cdf1998-05-15 16:59:38 +000061# Many possible uses of \let aren't supported or aren't supported correctly.
Fred Drakee16f6791998-05-15 04:28:37 +000062#
63sub do_cmd_let{
64 local($_) = @_;
65 my $matched = 0;
Fred Drake7a4ad0f1998-05-15 13:45:54 +000066 s/[\\]([a-zA-Z]+)\s*(=\s*)?[\\]([a-zA-Z]*)/$matched=1; ''/e;
Fred Drakee16f6791998-05-15 04:28:37 +000067 if ($matched) {
68 my($new, $old) = ($1, $3);
69 eval "sub do_cmd_$new { do_cmd_$old" . '(@_); }';
70 print "\ndefining handler for \\$new using \\$old\n";
71 }
Fred Drake7a4ad0f1998-05-15 13:45:54 +000072 else {
73 s/[\\]([a-zA-Z]+)\s*(=\s*)?([^\\])/$matched=1; ''/es;
74 if ($matched) {
75 my($new, $char) = ($1, $3);
Fred Drake49b33fa2002-11-15 19:04:10 +000076 eval "sub do_cmd_$new { \"\\$char\" . \$_[0]; }";
Fred Drake7a4ad0f1998-05-15 13:45:54 +000077 print "\ndefining handler for \\$new to insert '$char'\n";
78 }
79 else {
80 write_warnings("Could not interpret \\let construct...");
81 }
82 }
Fred Drake62e43691998-08-10 19:40:44 +000083 return $_;
Fred Drakee16f6791998-05-15 04:28:37 +000084}
85
86
Fred Drakec3fd45f2000-06-15 22:41:48 +000087# the older version of LaTeX2HTML we use doesn't support this, but we use it:
88
Fred Drake49b33fa2002-11-15 19:04:10 +000089sub do_cmd_textasciitilde{ '&#126;' . $_[0]; }
90sub do_cmd_textasciicircum{ '^' . $_[0]; }
91sub do_cmd_textbar{ '|' . $_[0]; }
92sub do_cmd_textgreater{ '&gt;' . $_[0]; }
93sub do_cmd_textless{ '&lt;' . $_[0]; }
94sub do_cmd_textunderscore{ '_' . $_[0]; }
95sub do_cmd_infinity{ '&infin;' . $_[0]; }
96sub do_cmd_plusminus{ '&plusmn;' . $_[0]; }
97sub do_cmd_menuselection{ $_[0]; }
98sub do_cmd_sub{ ' > ' . $_[0]; }
Fred Drakec3fd45f2000-06-15 22:41:48 +000099
100
Fred Drake6659c301998-03-03 22:02:19 +0000101# words typeset in a special way (not in HTML though)
102
Fred Drake49b33fa2002-11-15 19:04:10 +0000103sub do_cmd_ABC{ 'ABC' . $_[0]; }
104sub do_cmd_UNIX{ 'Unix'. $_[0]; }
105sub do_cmd_ASCII{ 'ASCII' . $_[0]; }
106sub do_cmd_POSIX{ 'POSIX' . $_[0]; }
107sub do_cmd_C{ 'C' . $_[0]; }
108sub do_cmd_Cpp{ 'C++' . $_[0]; }
109sub do_cmd_EOF{ 'EOF' . $_[0]; }
110sub do_cmd_NULL{ '<tt class="constant">NULL</tt>' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000111
Fred Drake49b33fa2002-11-15 19:04:10 +0000112sub do_cmd_e{ '&#92;' . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000113
Fred Draked07868a1998-05-14 21:00:28 +0000114$DEVELOPER_ADDRESS = '';
Fred Drake3cdb89d2000-09-14 20:17:23 +0000115$SHORT_VERSION = '';
Fred Drakef1927a62001-06-20 21:29:30 +0000116$RELEASE_INFO = '';
Fred Draked04592a2000-10-25 16:15:13 +0000117$PACKAGE_VERSION = '';
Fred Drake6659c301998-03-03 22:02:19 +0000118
Fred Drake49b33fa2002-11-15 19:04:10 +0000119sub do_cmd_version{ $PACKAGE_VERSION . $_[0]; }
120sub do_cmd_shortversion{ $SHORT_VERSION . $_[0]; }
Fred Drake6659c301998-03-03 22:02:19 +0000121sub do_cmd_release{
122 local($_) = @_;
Fred Draked04592a2000-10-25 16:15:13 +0000123 $PACKAGE_VERSION = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000124 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000125}
126
Fred Drakef1927a62001-06-20 21:29:30 +0000127sub do_cmd_setreleaseinfo{
128 local($_) = @_;
129 $RELEASE_INFO = next_argument();
130 return $_;
131}
132
Fred Drake3cdb89d2000-09-14 20:17:23 +0000133sub do_cmd_setshortversion{
134 local($_) = @_;
135 $SHORT_VERSION = next_argument();
136 return $_;
137}
138
Fred Drake6659c301998-03-03 22:02:19 +0000139sub do_cmd_authoraddress{
140 local($_) = @_;
Fred Draked07868a1998-05-14 21:00:28 +0000141 $DEVELOPER_ADDRESS = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000142 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000143}
144
Fred Drake49b33fa2002-11-15 19:04:10 +0000145#sub do_cmd_developer{ do_cmd_author($_[0]); }
146#sub do_cmd_developers{ do_cmd_author($_[0]); }
147#sub do_cmd_developersaddress{ do_cmd_authoraddress($_[0]); }
Fred Draked07868a1998-05-14 21:00:28 +0000148
Fred Drake6659c301998-03-03 22:02:19 +0000149sub do_cmd_hackscore{
150 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000151 next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000152 return '_' . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000153}
154
Fred Drakef5478632002-05-23 17:59:16 +0000155sub use_wrappers($$$){
Fred Drake08932051998-04-17 02:15:42 +0000156 local($_,$before,$after) = @_;
157 my $stuff = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000158 return $before . $stuff . $after . $_;
Fred Drake08932051998-04-17 02:15:42 +0000159}
160
Fred Drake3cdb89d2000-09-14 20:17:23 +0000161$IN_DESC_HANDLER = 0;
Fred Drake6659c301998-03-03 22:02:19 +0000162sub do_cmd_optional{
Fred Drake3cdb89d2000-09-14 20:17:23 +0000163 if ($IN_DESC_HANDLER) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000164 return use_wrappers($_[0], "</var><big>\[</big><var>",
Fred Drake3cdb89d2000-09-14 20:17:23 +0000165 "</var><big>\]</big><var>");
166 }
167 else {
Fred Drake49b33fa2002-11-15 19:04:10 +0000168 return use_wrappers($_[0], "<big>\[</big>", "<big>\]</big>");
Fred Drake3cdb89d2000-09-14 20:17:23 +0000169 }
Fred Drake6659c301998-03-03 22:02:19 +0000170}
171
Fred Drakec9a44381998-03-17 06:29:13 +0000172# Logical formatting (some based on texinfo), needs to be converted to
173# minimalist HTML. The "minimalist" is primarily to reduce the size of
174# output files for users that read them over the network rather than
175# from local repositories.
Fred Drake6659c301998-03-03 22:02:19 +0000176
Fred Drake49b33fa2002-11-15 19:04:10 +0000177sub do_cmd_pytype{ return $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000178sub do_cmd_makevar{
Fred Drake49b33fa2002-11-15 19:04:10 +0000179 return use_wrappers($_[0], '<span class="makevar">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000180sub do_cmd_code{
Fred Drake49b33fa2002-11-15 19:04:10 +0000181 return use_wrappers($_[0], '<code>', '</code>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000182sub do_cmd_module{
Fred Drake49b33fa2002-11-15 19:04:10 +0000183 return use_wrappers($_[0], '<tt class="module">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000184sub do_cmd_keyword{
Fred Drake49b33fa2002-11-15 19:04:10 +0000185 return use_wrappers($_[0], '<tt class="keyword">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000186sub do_cmd_exception{
Fred Drake49b33fa2002-11-15 19:04:10 +0000187 return use_wrappers($_[0], '<tt class="exception">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000188sub do_cmd_class{
Fred Drake49b33fa2002-11-15 19:04:10 +0000189 return use_wrappers($_[0], '<tt class="class">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000190sub do_cmd_function{
Fred Drake49b33fa2002-11-15 19:04:10 +0000191 return use_wrappers($_[0], '<tt class="function">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000192sub do_cmd_constant{
Fred Drake49b33fa2002-11-15 19:04:10 +0000193 return use_wrappers($_[0], '<tt class="constant">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000194sub do_cmd_member{
Fred Drake49b33fa2002-11-15 19:04:10 +0000195 return use_wrappers($_[0], '<tt class="member">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000196sub do_cmd_method{
Fred Drake49b33fa2002-11-15 19:04:10 +0000197 return use_wrappers($_[0], '<tt class="method">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000198sub do_cmd_cfunction{
Fred Drake49b33fa2002-11-15 19:04:10 +0000199 return use_wrappers($_[0], '<tt class="cfunction">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000200sub do_cmd_cdata{
Fred Drake49b33fa2002-11-15 19:04:10 +0000201 return use_wrappers($_[0], '<tt class="cdata">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000202sub do_cmd_ctype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000203 return use_wrappers($_[0], '<tt class="ctype">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000204sub do_cmd_regexp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000205 return use_wrappers($_[0], '<tt class="regexp">', '</tt>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000206sub do_cmd_character{
Fred Drake49b33fa2002-11-15 19:04:10 +0000207 return use_wrappers($_[0], '"<tt class="character">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000208sub do_cmd_program{
Fred Drake49b33fa2002-11-15 19:04:10 +0000209 return use_wrappers($_[0], '<b class="program">', '</b>'); }
Fred Drakec9f5fe01999-11-09 16:59:42 +0000210sub do_cmd_programopt{
Fred Drake49b33fa2002-11-15 19:04:10 +0000211 return use_wrappers($_[0], '<b class="programopt">', '</b>'); }
Fred Drake0cd60212000-04-11 18:46:59 +0000212sub do_cmd_longprogramopt{
213 # note that the --- will be later converted to -- by LaTeX2HTML
Fred Drake49b33fa2002-11-15 19:04:10 +0000214 return use_wrappers($_[0], '<b class="programopt">---', '</b>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000215sub do_cmd_email{
Fred Drake49b33fa2002-11-15 19:04:10 +0000216 return use_wrappers($_[0], '<span class="email">', '</span>'); }
Fred Drake7eac0cb2001-08-03 18:36:17 +0000217sub do_cmd_mailheader{
Fred Drake49b33fa2002-11-15 19:04:10 +0000218 return use_wrappers($_[0], '<span class="mailheader">', ':</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000219sub do_cmd_mimetype{
Fred Drake49b33fa2002-11-15 19:04:10 +0000220 return use_wrappers($_[0], '<span class="mimetype">', '</span>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000221sub do_cmd_var{
Fred Drake49b33fa2002-11-15 19:04:10 +0000222 return use_wrappers($_[0], "<var>", "</var>"); }
Fred Drake90fdda51999-02-16 20:27:42 +0000223sub do_cmd_dfn{
Fred Drake49b33fa2002-11-15 19:04:10 +0000224 return use_wrappers($_[0], '<i class="dfn">', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000225sub do_cmd_emph{
Fred Drake49b33fa2002-11-15 19:04:10 +0000226 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000227sub do_cmd_file{
Fred Drake49b33fa2002-11-15 19:04:10 +0000228 return use_wrappers($_[0], '<span class="file">', '</span>'); }
Fred Drakef74e5b71999-04-28 14:58:49 +0000229sub do_cmd_filenq{
Fred Drake49b33fa2002-11-15 19:04:10 +0000230 return do_cmd_file($_[0]); }
Fred Drake90fdda51999-02-16 20:27:42 +0000231sub do_cmd_samp{
Fred Drake49b33fa2002-11-15 19:04:10 +0000232 return use_wrappers($_[0], '"<tt class="samp">', '</tt>"'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000233sub do_cmd_kbd{
Fred Drake49b33fa2002-11-15 19:04:10 +0000234 return use_wrappers($_[0], '<kbd>', '</kbd>'); }
Fred Drake90fdda51999-02-16 20:27:42 +0000235sub do_cmd_strong{
Fred Drake49b33fa2002-11-15 19:04:10 +0000236 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000237sub do_cmd_textbf{
Fred Drake49b33fa2002-11-15 19:04:10 +0000238 return use_wrappers($_[0], '<b>', '</b>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000239sub do_cmd_textit{
Fred Drake49b33fa2002-11-15 19:04:10 +0000240 return use_wrappers($_[0], '<i>', '</i>'); }
Fred Drake6ca33772001-12-14 22:50:06 +0000241# This can be changed/overridden for translations:
242%NoticeNames = ('note' => 'Note:',
243 'warning' => 'Warning:',
244 );
245
Fred Drake92350b32001-10-09 18:01:23 +0000246sub do_cmd_note{
Fred Drake6ca33772001-12-14 22:50:06 +0000247 my $label = $NoticeNames{'note'};
Fred Drake92350b32001-10-09 18:01:23 +0000248 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000249 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000250 "<span class=\"note\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000251 '</span>'); }
252sub do_cmd_warning{
Fred Drake6ca33772001-12-14 22:50:06 +0000253 my $label = $NoticeNames{'warning'};
Fred Drake92350b32001-10-09 18:01:23 +0000254 return use_wrappers(
Fred Drake49b33fa2002-11-15 19:04:10 +0000255 $_[0],
Fred Drake6ca33772001-12-14 22:50:06 +0000256 "<span class=\"warning\"><b class=\"label\">$label</b>\n",
Fred Drake92350b32001-10-09 18:01:23 +0000257 '</span>'); }
Fred Drake2cafcbb1999-03-25 16:57:04 +0000258
Fred Drake6ca33772001-12-14 22:50:06 +0000259sub do_env_notice{
260 local($_) = @_;
261 my $notice = next_optional_argument();
262 if (!$notice) {
263 $notice = 'note';
264 }
265 my $label = $NoticeNames{$notice};
266 return ("<div class=\"$notice\"><b class=\"label\">$label</b>\n"
267 . $_
268 . '</div>');
269}
270
Fred Drake3d5a04a2000-08-03 17:25:44 +0000271sub do_cmd_moreargs{
Fred Drake49b33fa2002-11-15 19:04:10 +0000272 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000273sub do_cmd_unspecified{
Fred Drake49b33fa2002-11-15 19:04:10 +0000274 return '...' . $_[0]; }
Fred Drake3d5a04a2000-08-03 17:25:44 +0000275
Fred Drakec9a44381998-03-17 06:29:13 +0000276
Fred Drake25817041999-01-13 17:06:34 +0000277sub do_cmd_refmodule{
278 # Insert the right magic to jump to the module definition.
279 local($_) = @_;
280 my $key = next_optional_argument();
281 my $module = next_argument();
282 $key = $module
283 unless $key;
Fred Drakef1927a62001-06-20 21:29:30 +0000284 return "<tt class=\"module\"><a href=\"module-$key.html\">$module</a></tt>"
Fred Drakee15956b2000-04-03 04:51:13 +0000285 . $_;
Fred Drake25817041999-01-13 17:06:34 +0000286}
287
Fred Drake1a7af391998-04-01 22:44:56 +0000288sub do_cmd_newsgroup{
289 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000290 my $newsgroup = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000291 my $icon = get_link_icon("news:$newsgroup");
Fred Drakef1927a62001-06-20 21:29:30 +0000292 my $stuff = ("<a class=\"newsgroup\" href=\"news:$newsgroup\">"
293 . "$newsgroup$icon</a>");
Fred Drake62e43691998-08-10 19:40:44 +0000294 return $stuff . $_;
Fred Drake1a7af391998-04-01 22:44:56 +0000295}
Fred Drakefc16e781998-03-12 21:03:26 +0000296
297sub do_cmd_envvar{
298 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000299 my $envvar = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +0000300 my($name, $aname, $ahref) = new_link_info();
Fred Drake166abba1998-04-08 23:10:54 +0000301 # The <tt> here is really to keep buildindex.py from making
302 # the variable name case-insensitive.
Fred Drakeafc7ce12001-01-22 17:33:24 +0000303 add_index_entry("environment variables!$envvar@<tt>$envvar</tt>",
Fred Drake166abba1998-04-08 23:10:54 +0000304 $ahref);
Fred Drakeafc7ce12001-01-22 17:33:24 +0000305 add_index_entry("$envvar (environment variable)", $ahref);
Fred Drakee15956b2000-04-03 04:51:13 +0000306 $aname =~ s/<a/<a class="envvar"/;
Fred Drakeafc7ce12001-01-22 17:33:24 +0000307 return "$aname$envvar</a>" . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000308}
309
Fred Drake6659c301998-03-03 22:02:19 +0000310sub do_cmd_url{
311 # use the URL as both text and hyperlink
312 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000313 my $url = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000314 my $icon = get_link_icon($url);
Fred Drake6659c301998-03-03 22:02:19 +0000315 $url =~ s/~/&#126;/g;
Fred Drake7a40c072000-10-02 14:43:38 +0000316 return "<a class=\"url\" href=\"$url\">$url$icon</a>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000317}
318
319sub do_cmd_manpage{
320 # two parameters: \manpage{name}{section}
321 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000322 my $page = next_argument();
323 my $section = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000324 return "<span class=\"manpage\"><i>$page</i>($section)</span>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000325}
326
Fred Drakedbfe7682002-04-03 02:47:14 +0000327$PEP_FORMAT = "http://www.python.org/peps/pep-%04d.html";
Fred Drakef1927a62001-06-20 21:29:30 +0000328#$RFC_FORMAT = "http://www.ietf.org/rfc/rfc%04d.txt";
329$RFC_FORMAT = "http://www.faqs.org/rfcs/rfc%d.html";
Fred Drakeafc7ce12001-01-22 17:33:24 +0000330
331sub get_rfc_url($$){
332 my($rfcnum, $format) = @_;
Fred Drakef1927a62001-06-20 21:29:30 +0000333 return sprintf($format, $rfcnum);
Fred Drake643d76d2000-09-09 06:07:37 +0000334}
335
336sub do_cmd_pep{
337 local($_) = @_;
338 my $rfcnumber = next_argument();
339 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000340 my $href = get_rfc_url($rfcnumber, $PEP_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000341 my $icon = get_link_icon($href);
Fred Drake643d76d2000-09-09 06:07:37 +0000342 # Save the reference
343 my $nstr = gen_index_id("Python Enhancement Proposals!PEP $rfcnumber", '');
344 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000345 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">PEP $rfcnumber"
346 . "$icon</a>" . $_);
Fred Drake643d76d2000-09-09 06:07:37 +0000347}
348
Fred Drake6659c301998-03-03 22:02:19 +0000349sub do_cmd_rfc{
350 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000351 my $rfcnumber = next_argument();
352 my $id = "rfcref-" . ++$global{'max_id'};
Fred Drakeafc7ce12001-01-22 17:33:24 +0000353 my $href = get_rfc_url($rfcnumber, $RFC_FORMAT);
Fred Drake7a40c072000-10-02 14:43:38 +0000354 my $icon = get_link_icon($href);
Fred Drake6659c301998-03-03 22:02:19 +0000355 # Save the reference
Fred Drake08932051998-04-17 02:15:42 +0000356 my $nstr = gen_index_id("RFC!RFC $rfcnumber", '');
Fred Drakeccc62721999-01-05 22:16:29 +0000357 $index{$nstr} .= make_half_href("$CURRENT_FILE#$id");
Fred Drake7a40c072000-10-02 14:43:38 +0000358 return ("<a class=\"rfc\" name=\"$id\"\nhref=\"$href\">RFC $rfcnumber"
359 . "$icon</a>" . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000360}
361
Fred Drake77602f22001-07-06 22:43:02 +0000362sub do_cmd_ulink{
363 local($_) = @_;
364 my $text = next_argument();
365 my $url = next_argument();
366 return "<a class=\"ulink\" href=\"$url\"\n >$text</a>" . $_;
367}
368
Fred Drakec9f5fe01999-11-09 16:59:42 +0000369sub do_cmd_citetitle{
370 local($_) = @_;
371 my $url = next_optional_argument();
372 my $title = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +0000373 my $icon = get_link_icon($url);
Fred Drakec9f5fe01999-11-09 16:59:42 +0000374 my $repl = '';
375 if ($url) {
Fred Drakef1927a62001-06-20 21:29:30 +0000376 $repl = ("<em class=\"citetitle\"><a\n"
377 . " href=\"$url\"\n"
378 . " title=\"$title\"\n"
Fred Drake7a40c072000-10-02 14:43:38 +0000379 . " >$title$icon</a></em>");
Fred Drakec9f5fe01999-11-09 16:59:42 +0000380 }
381 else {
Fred Drakef1927a62001-06-20 21:29:30 +0000382 $repl = "<em class=\"citetitle\"\n >$title</em>";
Fred Drakec9f5fe01999-11-09 16:59:42 +0000383 }
384 return $repl . $_;
385}
386
Fred Drake6659c301998-03-03 22:02:19 +0000387sub do_cmd_deprecated{
388 # two parameters: \deprecated{version}{whattodo}
389 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +0000390 my $release = next_argument();
391 my $reason = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +0000392 return ('<div class="versionnote">'
393 . "<b>Deprecated since release $release.</b>"
394 . "\n$reason</div><p>"
395 . $_);
Fred Drake6659c301998-03-03 22:02:19 +0000396}
397
Fred Drakef5478632002-05-23 17:59:16 +0000398sub versionnote($$){
Fred Drakec2b29d02001-04-18 03:11:04 +0000399 # one or two parameters: \versionnote[explanation]{version}
Fred Drake49b33fa2002-11-15 19:04:10 +0000400 my $type = $_[0];
401 local $_ = $_[1];
Fred Drakec2b29d02001-04-18 03:11:04 +0000402 my $explanation = next_optional_argument();
Fred Drake897d12b1998-07-27 20:33:17 +0000403 my $release = next_argument();
Fred Drakec2b29d02001-04-18 03:11:04 +0000404 my $text = "$type in version $release.";
405 if ($explanation) {
406 $text = "$type in version $release:\n$explanation.";
407 }
Fred Drakef1927a62001-06-20 21:29:30 +0000408 return "\n<span class=\"versionnote\">$text</span>\n" . $_;
Fred Drakec2b29d02001-04-18 03:11:04 +0000409}
410
411sub do_cmd_versionadded{
Fred Drake49b33fa2002-11-15 19:04:10 +0000412 return versionnote('New', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000413}
414
415sub do_cmd_versionchanged{
Fred Drake49b33fa2002-11-15 19:04:10 +0000416 return versionnote('Changed', $_[0]);
Fred Drake897d12b1998-07-27 20:33:17 +0000417}
418
Fred Drake557460c1999-03-02 16:05:35 +0000419#
Fred Drake2cafcbb1999-03-25 16:57:04 +0000420# These function handle platform dependency tracking.
Fred Drake557460c1999-03-02 16:05:35 +0000421#
422sub do_cmd_platform{
423 local($_) = @_;
424 my $platform = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000425 $ModulePlatforms{"<tt class=\"module\">$THIS_MODULE</tt>"} = $platform;
Fred Drake557460c1999-03-02 16:05:35 +0000426 $platform = "Macintosh"
Fred Drake085b8121999-04-21 14:00:29 +0000427 if $platform eq 'Mac';
Fred Drakef1927a62001-06-20 21:29:30 +0000428 return "\n<p class=\"availability\">Availability: <span"
429 . "\n class=\"platform\">$platform</span>.</p>\n" . $_;
Fred Drake557460c1999-03-02 16:05:35 +0000430}
431
Fred Drake557460c1999-03-02 16:05:35 +0000432$IGNORE_PLATFORM_ANNOTATION = '';
433sub do_cmd_ignorePlatformAnnotation{
434 local($_) = @_;
435 $IGNORE_PLATFORM_ANNOTATION = next_argument();
436 return $_;
437}
438
Fred Drake6659c301998-03-03 22:02:19 +0000439
440# index commands
441
442$INDEX_SUBITEM = "";
443
Fred Drakef5478632002-05-23 17:59:16 +0000444sub get_indexsubitem(){
Fred Drake7d45f6d1999-01-05 14:39:27 +0000445 return $INDEX_SUBITEM ? " $INDEX_SUBITEM" : '';
Fred Drake6659c301998-03-03 22:02:19 +0000446}
447
448sub do_cmd_setindexsubitem{
449 local($_) = @_;
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000450 $INDEX_SUBITEM = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000451 return $_;
Fred Drake6659c301998-03-03 22:02:19 +0000452}
453
Fred Drakefc16e781998-03-12 21:03:26 +0000454sub do_cmd_withsubitem{
Fred Drake7d45f6d1999-01-05 14:39:27 +0000455 # We can't really do the right thing, because LaTeX2HTML doesn't
Fred Drakefc16e781998-03-12 21:03:26 +0000456 # do things in the right order, but we need to at least strip this stuff
457 # out, and leave anything that the second argument expanded out to.
458 #
459 local($_) = @_;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000460 my $oldsubitem = $INDEX_SUBITEM;
461 $INDEX_SUBITEM = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000462 my $stuff = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +0000463 my $br_id = ++$globals{'max_id'};
464 my $marker = "$O$br_id$C";
Fred Drakebe6dd302001-12-11 20:49:23 +0000465 $stuff =~ s/^\s+//;
Fred Drake7d45f6d1999-01-05 14:39:27 +0000466 return
467 $stuff
Fred Drakeccc62721999-01-05 22:16:29 +0000468 . "\\setindexsubitem$marker$oldsubitem$marker"
Fred Drake7d45f6d1999-01-05 14:39:27 +0000469 . $_;
Fred Drakefc16e781998-03-12 21:03:26 +0000470}
471
Fred Drake08932051998-04-17 02:15:42 +0000472# This is the prologue macro which is required to start writing the
Fred Drakeab032151999-05-13 18:36:54 +0000473# mod\jobname.idx file; we can just ignore it. (Defining this suppresses
474# a warning that \makemodindex is unknown.)
Fred Drake08932051998-04-17 02:15:42 +0000475#
Fred Drake49b33fa2002-11-15 19:04:10 +0000476sub do_cmd_makemodindex{ return $_[0]; }
Fred Drakefc16e781998-03-12 21:03:26 +0000477
Fred Drake42b31a51998-03-27 05:16:10 +0000478# We're in the document subdirectory when this happens!
Fred Drake166abba1998-04-08 23:10:54 +0000479#
Fred Drake08932051998-04-17 02:15:42 +0000480open(IDXFILE, '>index.dat') || die "\n$!\n";
481open(INTLABELS, '>intlabels.pl') || die "\n$!\n";
Fred Drake166abba1998-04-08 23:10:54 +0000482print INTLABELS "%internal_labels = ();\n";
483print INTLABELS "1; # hack in case there are no entries\n\n";
484
485# Using \0 for this is bad because we can't use common tools to work with the
486# resulting files. Things like grep can be useful with this stuff!
487#
488$IDXFILE_FIELD_SEP = "\1";
489
Fred Drakef5478632002-05-23 17:59:16 +0000490sub write_idxfile($$){
491 my($ahref, $str) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000492 print IDXFILE $ahref, $IDXFILE_FIELD_SEP, $str, "\n";
Fred Drake42b31a51998-03-27 05:16:10 +0000493}
494
Fred Drake42b31a51998-03-27 05:16:10 +0000495
Fred Drakef5478632002-05-23 17:59:16 +0000496sub gen_link($$){
497 my($node, $target) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000498 print INTLABELS "\$internal_labels{\"$target\"} = \"/$node\";\n";
Fred Drakef1927a62001-06-20 21:29:30 +0000499 return "<a href=\"$node#$target\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000500}
501
Fred Drakef5478632002-05-23 17:59:16 +0000502sub add_index_entry($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000503 # add an entry to the index structures; ignore the return value
Fred Drakef5478632002-05-23 17:59:16 +0000504 my($str, $ahref) = @_;
Fred Drake42b31a51998-03-27 05:16:10 +0000505 $str = gen_index_id($str, '');
506 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000507 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000508}
509
Fred Drakef5478632002-05-23 17:59:16 +0000510sub new_link_info(){
Fred Drakeccc62721999-01-05 22:16:29 +0000511 my $name = "l2h-" . ++$globals{'max_id'};
Fred Drakef1927a62001-06-20 21:29:30 +0000512 my $aname = "<a name=\"$name\">";
Fred Drake42b31a51998-03-27 05:16:10 +0000513 my $ahref = gen_link($CURRENT_FILE, $name);
514 return ($name, $aname, $ahref);
515}
516
Fred Drakeab032151999-05-13 18:36:54 +0000517$IndexMacroPattern = '';
Fred Drakef5478632002-05-23 17:59:16 +0000518sub define_indexing_macro(@){
Fred Drakeab032151999-05-13 18:36:54 +0000519 my $count = @_;
520 my $i = 0;
521 for (; $i < $count; ++$i) {
Fred Drake49b33fa2002-11-15 19:04:10 +0000522 my $name = $_[$i];
Fred Drakeab032151999-05-13 18:36:54 +0000523 my $cmd = "idx_cmd_$name";
524 die "\nNo function $cmd() defined!\n"
525 if (!defined &$cmd);
526 eval ("sub do_cmd_$name { return process_index_macros("
Fred Drake49b33fa2002-11-15 19:04:10 +0000527 . "\$_[0], '$name'); }");
Fred Drakeab032151999-05-13 18:36:54 +0000528 if (length($IndexMacroPattern) == 0) {
529 $IndexMacroPattern = "$name";
530 }
531 else {
532 $IndexMacroPattern .= "|$name";
533 }
534 }
535}
536
537$DEBUG_INDEXING = 0;
Fred Drakef5478632002-05-23 17:59:16 +0000538sub process_index_macros($$){
Fred Drake42b31a51998-03-27 05:16:10 +0000539 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +0000540 my $cmdname = $_[1]; # This is what triggered us in the first place;
Fred Drakeab032151999-05-13 18:36:54 +0000541 # we know it's real, so just process it.
Fred Drakef5478632002-05-23 17:59:16 +0000542 my($name, $aname, $ahref) = new_link_info();
Fred Drakeab032151999-05-13 18:36:54 +0000543 my $cmd = "idx_cmd_$cmdname";
544 print "\nIndexing: \\$cmdname"
545 if $DEBUG_INDEXING;
546 &$cmd($ahref); # modifies $_ and adds index entries
547 while (/^[\s\n]*\\($IndexMacroPattern)</) {
548 $cmdname = "$1";
549 print " \\$cmdname"
550 if $DEBUG_INDEXING;
551 $cmd = "idx_cmd_$cmdname";
552 if (!defined &$cmd) {
553 last;
554 }
555 else {
556 s/^[\s\n]*\\$cmdname//;
557 &$cmd($ahref);
558 }
559 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000560 if (/^[ \t\r\n]/) {
561 $_ = substr($_, 1);
562 }
Fred Drake62e43691998-08-10 19:40:44 +0000563 return "$aname$anchor_invisible_mark</a>" . $_;
Fred Drake42b31a51998-03-27 05:16:10 +0000564}
565
Fred Drakeab032151999-05-13 18:36:54 +0000566define_indexing_macro('index');
Fred Drakef5478632002-05-23 17:59:16 +0000567sub idx_cmd_index($){
Fred Drakeccc62721999-01-05 22:16:29 +0000568 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000569 add_index_entry("$str", $_[0]);
Fred Drake2e7edb81998-05-11 18:31:17 +0000570}
571
Fred Drakeab032151999-05-13 18:36:54 +0000572define_indexing_macro('kwindex');
Fred Drakef5478632002-05-23 17:59:16 +0000573sub idx_cmd_kwindex($){
Fred Drakeab032151999-05-13 18:36:54 +0000574 my $str = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000575 add_index_entry("<tt>$str</tt>!keyword", $_[0]);
576 add_index_entry("keyword!<tt>$str</tt>", $_[0]);
Fred Drakeab032151999-05-13 18:36:54 +0000577}
578
579define_indexing_macro('indexii');
Fred Drakef5478632002-05-23 17:59:16 +0000580sub idx_cmd_indexii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000581 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000582 my $str2 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000583 add_index_entry("$str1!$str2", $_[0]);
584 add_index_entry("$str2!$str1", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000585}
586
Fred Drakeab032151999-05-13 18:36:54 +0000587define_indexing_macro('indexiii');
Fred Drakef5478632002-05-23 17:59:16 +0000588sub idx_cmd_indexiii($){
Fred Drakeccc62721999-01-05 22:16:29 +0000589 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000590 my $str2 = next_argument();
591 my $str3 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000592 add_index_entry("$str1!$str2 $str3", $_[0]);
593 add_index_entry("$str2!$str3, $str1", $_[0]);
594 add_index_entry("$str3!$str1 $str2", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000595}
596
Fred Drakeab032151999-05-13 18:36:54 +0000597define_indexing_macro('indexiv');
Fred Drakef5478632002-05-23 17:59:16 +0000598sub idx_cmd_indexiv($){
Fred Drakeccc62721999-01-05 22:16:29 +0000599 my $str1 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +0000600 my $str2 = next_argument();
601 my $str3 = next_argument();
602 my $str4 = next_argument();
Fred Drake49b33fa2002-11-15 19:04:10 +0000603 add_index_entry("$str1!$str2 $str3 $str4", $_[0]);
604 add_index_entry("$str2!$str3 $str4, $str1", $_[0]);
605 add_index_entry("$str3!$str4, $str1 $str2", $_[0]);
606 add_index_entry("$str4!$str1 $str2 $str3", $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000607}
608
Fred Drakeab032151999-05-13 18:36:54 +0000609define_indexing_macro('ttindex');
Fred Drakef5478632002-05-23 17:59:16 +0000610sub idx_cmd_ttindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000611 my $str = next_argument();
612 my $entry = $str . get_indexsubitem();
Fred Drake49b33fa2002-11-15 19:04:10 +0000613 add_index_entry($entry, $_[0]);
Fred Drakec9a44381998-03-17 06:29:13 +0000614}
Fred Drake6659c301998-03-03 22:02:19 +0000615
Fred Drakef5478632002-05-23 17:59:16 +0000616sub my_typed_index_helper($$){
617 my($word, $ahref) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +0000618 my $str = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +0000619 add_index_entry("$str $word", $ahref);
620 add_index_entry("$word!$str", $ahref);
Fred Drake6659c301998-03-03 22:02:19 +0000621}
622
Fred Drakeab032151999-05-13 18:36:54 +0000623define_indexing_macro('stindex', 'opindex', 'exindex', 'obindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000624sub idx_cmd_stindex($){ my_typed_index_helper('statement', $_[0]); }
625sub idx_cmd_opindex($){ my_typed_index_helper('operator', $_[0]); }
626sub idx_cmd_exindex($){ my_typed_index_helper('exception', $_[0]); }
627sub idx_cmd_obindex($){ my_typed_index_helper('object', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000628
Fred Drakeab032151999-05-13 18:36:54 +0000629define_indexing_macro('bifuncindex');
Fred Drakef5478632002-05-23 17:59:16 +0000630sub idx_cmd_bifuncindex($){
Fred Drakeccc62721999-01-05 22:16:29 +0000631 my $str = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000632 add_index_entry("<tt class=\"function\">$str()</tt> (built-in function)",
Fred Drake49b33fa2002-11-15 19:04:10 +0000633 $_[0]);
Fred Drake6659c301998-03-03 22:02:19 +0000634}
635
636
Fred Drakef5478632002-05-23 17:59:16 +0000637sub make_mod_index_entry($$){
638 my($str, $define) = @_;
639 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000640 # equivalent of add_index_entry() using $define instead of ''
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000641 $ahref =~ s/\#[-_a-zA-Z0-9]*\"/\"/
642 if ($define eq 'DEF');
Fred Drake42b31a51998-03-27 05:16:10 +0000643 $str = gen_index_id($str, $define);
644 $index{$str} .= $ahref;
Fred Drakeccc62721999-01-05 22:16:29 +0000645 write_idxfile($ahref, $str);
Fred Drake42b31a51998-03-27 05:16:10 +0000646
Fred Drakec9a44381998-03-17 06:29:13 +0000647 if ($define eq 'DEF') {
Fred Drake42b31a51998-03-27 05:16:10 +0000648 # add to the module index
Fred Drakee15956b2000-04-03 04:51:13 +0000649 $str =~ /(<tt.*<\/tt>)/;
650 my $nstr = $1;
Fred Drake42b31a51998-03-27 05:16:10 +0000651 $Modules{$nstr} .= $ahref;
Fred Drake6659c301998-03-03 22:02:19 +0000652 }
Fred Drakeafc7ce12001-01-22 17:33:24 +0000653 return "$aname$anchor_invisible_mark2</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000654}
655
Fred Drake557460c1999-03-02 16:05:35 +0000656
Fred Drakec9a44381998-03-17 06:29:13 +0000657$THIS_MODULE = '';
Fred Drake42b31a51998-03-27 05:16:10 +0000658$THIS_CLASS = '';
Fred Drakec9a44381998-03-17 06:29:13 +0000659
Fred Drakef5478632002-05-23 17:59:16 +0000660sub define_module($$){
661 my($word, $name) = @_;
Fred Drakec9a44381998-03-17 06:29:13 +0000662 my $section_tag = join('', @curr_sec_id);
Fred Drake3e4c6141999-05-17 15:00:32 +0000663 if ($word ne "built-in" && $word ne "extension"
664 && $word ne "standard" && $word ne "") {
665 write_warnings("Bad module type '$word'"
666 . " for \\declaremodule (module $name)");
667 $word = "";
668 }
Fred Drake6659c301998-03-03 22:02:19 +0000669 $word = "$word " if $word;
Fred Drakea0f4c941998-07-24 22:16:04 +0000670 $THIS_MODULE = "$name";
Fred Drake5942b432000-10-30 06:24:56 +0000671 $INDEX_SUBITEM = "(in module $name)";
Fred Drake2e1ee3e1999-02-10 21:17:04 +0000672 print "[$name]";
Fred Drakee15956b2000-04-03 04:51:13 +0000673 return make_mod_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +0000674 "<tt class=\"module\">$name</tt> (${word}module)", 'DEF');
Fred Drakea0f4c941998-07-24 22:16:04 +0000675}
676
Fred Drakef5478632002-05-23 17:59:16 +0000677sub my_module_index_helper($$){
Fred Drakea0f4c941998-07-24 22:16:04 +0000678 local($word, $_) = @_;
679 my $name = next_argument();
Fred Drake62e43691998-08-10 19:40:44 +0000680 return define_module($word, $name) . $_;
Fred Drake6659c301998-03-03 22:02:19 +0000681}
682
Fred Drake49b33fa2002-11-15 19:04:10 +0000683sub do_cmd_modindex{ return my_module_index_helper('', $_[0]); }
684sub do_cmd_bimodindex{ return my_module_index_helper('built-in', $_[0]); }
685sub do_cmd_exmodindex{ return my_module_index_helper('extension', $_[0]); }
686sub do_cmd_stmodindex{ return my_module_index_helper('standard', $_[0]); }
687# local($_) = @_;
688# my $name = next_argument();
689# return define_module('standard', $name) . $_;
690# }
Fred Drake6659c301998-03-03 22:02:19 +0000691
Fred Drakef5478632002-05-23 17:59:16 +0000692sub ref_module_index_helper($$){
Fred Drake37cc0c02000-04-26 18:05:24 +0000693 my($word, $ahref) = @_;
Fred Drakeab032151999-05-13 18:36:54 +0000694 my $str = next_argument();
695 $word = "$word " if $word;
Fred Drakef1927a62001-06-20 21:29:30 +0000696 $str = "<tt class=\"module\">$str</tt> (${word}module)";
Fred Drakeab032151999-05-13 18:36:54 +0000697 # can't use add_index_entry() since the 2nd arg to gen_index_id() is used;
698 # just inline it all here
699 $str = gen_index_id($str, 'REF');
700 $index{$str} .= $ahref;
701 write_idxfile($ahref, $str);
702}
703
Fred Drake6659c301998-03-03 22:02:19 +0000704# these should be adjusted a bit....
Fred Drakeab032151999-05-13 18:36:54 +0000705define_indexing_macro('refmodindex', 'refbimodindex',
706 'refexmodindex', 'refstmodindex');
Fred Drake49b33fa2002-11-15 19:04:10 +0000707sub idx_cmd_refmodindex($){
708 return ref_module_index_helper('', $_[0]); }
709sub idx_cmd_refbimodindex($){
710 return ref_module_index_helper('built-in', $_[0]); }
711sub idx_cmd_refexmodindex($){
712 return ref_module_index_helper('extension', $_[0]);}
713sub idx_cmd_refstmodindex($){
714 return ref_module_index_helper('standard', $_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000715
Fred Drake49b33fa2002-11-15 19:04:10 +0000716sub do_cmd_nodename{ return do_cmd_label($_[0]); }
Fred Drake6659c301998-03-03 22:02:19 +0000717
Fred Drakef5478632002-05-23 17:59:16 +0000718sub init_myformat(){
Fred Drakeafc7ce12001-01-22 17:33:24 +0000719 $anchor_invisible_mark = '&nbsp;';
720 $anchor_invisible_mark2 = '';
Fred Drake6659c301998-03-03 22:02:19 +0000721 $anchor_mark = '';
722 $icons{'anchor_mark'} = '';
Fred Drake6659c301998-03-03 22:02:19 +0000723}
Fred Drake42b31a51998-03-27 05:16:10 +0000724init_myformat();
Fred Drake6659c301998-03-03 22:02:19 +0000725
Fred Drakeab032151999-05-13 18:36:54 +0000726# Create an index entry, but include the string in the target anchor
Fred Drake6659c301998-03-03 22:02:19 +0000727# instead of the dummy filler.
728#
Fred Drakef5478632002-05-23 17:59:16 +0000729sub make_str_index_entry($){
Fred Drake49b33fa2002-11-15 19:04:10 +0000730 my $str = $_[0];
Fred Drakef5478632002-05-23 17:59:16 +0000731 my($name, $aname, $ahref) = new_link_info();
Fred Drake42b31a51998-03-27 05:16:10 +0000732 add_index_entry($str, $ahref);
Fred Drake62e43691998-08-10 19:40:44 +0000733 return "$aname$str</a>";
Fred Drake6659c301998-03-03 22:02:19 +0000734}
735
Fred Drake77602f22001-07-06 22:43:02 +0000736
Fred Drakedbb2b9d2002-10-30 21:38:32 +0000737%TokenToTargetMapping = (); # language:token -> link target
738%DefinedGrammars = (); # language -> full grammar text
739%BackpatchGrammarFiles = (); # file -> 1 (hash of files to fixup)
Fred Drake77602f22001-07-06 22:43:02 +0000740
741sub do_cmd_token{
742 local($_) = @_;
743 my $token = next_argument();
744 my $target = $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"};
745 if ($token eq $CURRENT_TOKEN || $CURRENT_GRAMMAR eq '*') {
746 # recursive definition or display-only productionlist
747 return "$token";
748 }
749 if ($target eq '') {
750 $target = "<pyGrammarToken><$CURRENT_GRAMMAR><$token>";
751 if (! $BackpatchGrammarFiles{"$CURRENT_FILE"}) {
752 print "Adding '$CURRENT_FILE' to back-patch list.\n";
753 }
754 $BackpatchGrammarFiles{"$CURRENT_FILE"} = 1;
755 }
756 return "<a href=\"$target\">$token</a>" . $_;
757}
758
Fred Drake16bb4192001-08-20 21:36:38 +0000759sub do_cmd_grammartoken{
760 return do_cmd_token(@_);
761}
762
Fred Drake77602f22001-07-06 22:43:02 +0000763sub do_env_productionlist{
764 local($_) = @_;
765 my $lang = next_optional_argument();
766 my $filename = "grammar-$lang.txt";
767 if ($lang eq '') {
768 $filename = 'grammar.txt';
769 }
770 local($CURRENT_GRAMMAR) = $lang;
771 $DefinedGrammars{$lang} .= $_;
772 return ("<dl><dd class=\"grammar\">\n"
773 . "<div class=\"productions\">\n"
Fred Drakee27f8682001-12-14 16:54:53 +0000774 . "<table cellpadding=\"2\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000775 . translate_commands(translate_environments($_))
776 . "</table>\n"
777 . "</div>\n"
778 . (($lang eq '*')
779 ? ''
780 : ("<a class=\"grammar-footer\"\n"
781 . " href=\"$filename\" type=\"text/plain\"\n"
782 . " >Download entire grammar as text.</a>\n"))
783 . "</dd></dl>");
784}
785
786sub do_cmd_production{
787 local($_) = @_;
788 my $token = next_argument();
789 my $defn = next_argument();
790 my $lang = $CURRENT_GRAMMAR;
791 local($CURRENT_TOKEN) = $token;
792 if ($lang eq '*') {
Fred Drakee27f8682001-12-14 16:54:53 +0000793 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000794 . " <td><code>$token</code></td>\n"
795 . " <td>&nbsp;::=&nbsp;</td>\n"
796 . " <td><code>"
797 . translate_commands($defn)
798 . "</code></td></tr>"
799 . $_);
800 }
801 my $target;
802 if ($lang eq '') {
803 $target = "$CURRENT_FILE\#tok-$token";
804 }
805 else {
806 $target = "$CURRENT_FILE\#tok-$lang-$token";
807 }
808 $TokenToTargetMapping{"$CURRENT_GRAMMAR:$token"} = $target;
Fred Drakee27f8682001-12-14 16:54:53 +0000809 return ("<tr valign=\"baseline\">\n"
Fred Drake77602f22001-07-06 22:43:02 +0000810 . " <td><code><a name=\"tok-$token\">$token</a></code></td>\n"
811 . " <td>&nbsp;::=&nbsp;</td>\n"
812 . " <td><code>"
813 . translate_commands($defn)
814 . "</code></td></tr>"
815 . $_);
816}
817
Fred Drake53815882002-03-15 23:21:37 +0000818sub do_cmd_productioncont{
819 local($_) = @_;
820 my $defn = next_argument();
Fred Drake4837fa32002-06-18 18:30:28 +0000821 $defn =~ s/^( +)/'&nbsp;' x length $1/e;
Fred Drake53815882002-03-15 23:21:37 +0000822 return ("<tr valign=\"baseline\">\n"
823 . " <td>&nbsp;</td>\n"
824 . " <td>&nbsp;</td>\n"
825 . " <td><code>"
826 . translate_commands($defn)
827 . "</code></td></tr>"
828 . $_);
829}
830
Fred Drakef5478632002-05-23 17:59:16 +0000831sub process_grammar_files(){
Fred Drake77602f22001-07-06 22:43:02 +0000832 my $lang;
833 my $filename;
834 local($_);
835 print "process_grammar_files()\n";
836 foreach $lang (keys %DefinedGrammars) {
837 $filename = "grammar-$lang.txt";
838 if ($lang eq '*') {
839 next;
840 }
841 if ($lang eq '') {
842 $filename = 'grammar.txt';
843 }
844 open(GRAMMAR, ">$filename") || die "\n$!\n";
845 print GRAMMAR strip_grammar_markup($DefinedGrammars{$lang});
846 close(GRAMMAR);
847 print "Wrote grammar file $filename\n";
848 }
849 my $PATTERN = '<pyGrammarToken><([^>]*)><([^>]*)>';
850 foreach $filename (keys %BackpatchGrammarFiles) {
851 print "\nBack-patching grammar links in $filename\n";
852 my $buffer;
853 open(GRAMMAR, "<$filename") || die "\n$!\n";
854 # read all of the file into the buffer
855 sysread(GRAMMAR, $buffer, 1024*1024);
856 close(GRAMMAR);
857 while ($buffer =~ /$PATTERN/) {
858 my($lang, $token) = ($1, $2);
859 my $target = $TokenToTargetMapping{"$lang:$token"};
860 my $source = "<pyGrammarToken><$lang><$token>";
861 $buffer =~ s/$source/$target/g;
862 }
863 open(GRAMMAR, ">$filename") || die "\n$!\n";
864 print GRAMMAR $buffer;
865 close(GRAMMAR);
866 }
867}
868
Fred Drakef5478632002-05-23 17:59:16 +0000869sub strip_grammar_markup($){
Fred Drake77602f22001-07-06 22:43:02 +0000870 local($_) = @_;
Fred Drake53815882002-03-15 23:21:37 +0000871 s/\\productioncont/ /g;
Fred Drake49b33fa2002-11-15 19:04:10 +0000872 s/\\production(<<\d+>>)(.+)\1/\n$2 ::= /g;
873 s/\\token(<<\d+>>)(.+)\1/$2/g;
874 s/\\e([^a-zA-Z])/\\$1/g;
Fred Drake77602f22001-07-06 22:43:02 +0000875 s/<<\d+>>//g;
876 s/;SPMgt;/>/g;
877 s/;SPMlt;/</g;
878 s/;SPMquot;/\"/g;
879 return $_;
880}
881
882
Fred Drakee15956b2000-04-03 04:51:13 +0000883$REFCOUNTS_LOADED = 0;
884
Fred Drakef5478632002-05-23 17:59:16 +0000885sub load_refcounts(){
Fred Drakee15956b2000-04-03 04:51:13 +0000886 $REFCOUNTS_LOADED = 1;
887
Fred Drake49b33fa2002-11-15 19:04:10 +0000888 my($myname, $mydir, $myext) = fileparse(__FILE__, '\..*');
Fred Drakee15956b2000-04-03 04:51:13 +0000889 chop $mydir; # remove trailing '/'
890 ($myname, $mydir, $myext) = fileparse($mydir, '\..*');
891 chop $mydir; # remove trailing '/'
892 $mydir = getcwd() . "$dd$mydir"
893 unless $mydir =~ s|^/|/|;
894 local $_;
895 my $filename = "$mydir${dd}api${dd}refcounts.dat";
896 open(REFCOUNT_FILE, "<$filename") || die "\n$!\n";
897 print "[loading API refcount data]";
898 while (<REFCOUNT_FILE>) {
Fred Drakec2578c52000-04-10 18:26:45 +0000899 if (/([a-zA-Z0-9_]+):PyObject\*:([a-zA-Z0-9_]*):(0|[-+]1|null):(.*)$/) {
Fred Drakee15956b2000-04-03 04:51:13 +0000900 my($func, $param, $count, $comment) = ($1, $2, $3, $4);
901 #print "\n$func($param) --> $count";
902 $REFCOUNTS{"$func:$param"} = $count;
903 }
904 }
905}
906
Fred Drakef5478632002-05-23 17:59:16 +0000907sub get_refcount($$){
908 my($func, $param) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000909 load_refcounts()
910 unless $REFCOUNTS_LOADED;
911 return $REFCOUNTS{"$func:$param"};
912}
913
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000914
915$TLSTART = '<span class="typelabel">';
Fred Drakef6e90272002-06-18 18:24:16 +0000916$TLEND = '</span>&nbsp;';
Fred Drakeaf07b2c2001-10-26 03:09:27 +0000917
Fred Drakef5478632002-05-23 17:59:16 +0000918sub cfuncline_helper($$$){
919 my($type, $name, $args) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +0000920 my $idx = make_str_index_entry(
Fred Drake34adb8a2002-04-15 20:48:40 +0000921 "<tt class=\"cfunction\">$name()</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +0000922 $idx =~ s/ \(.*\)//;
Fred Drake241551c2000-08-11 20:04:19 +0000923 $idx =~ s/\(\)//; # ???? - why both of these?
Fred Drake49b33fa2002-11-15 19:04:10 +0000924 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*),/$1<var>$2<\/var>,/g;
925 $args =~ s/(\s|\*)([a-z_][a-z_0-9]*)$/$1<var>$2<\/var>/s;
Fred Drakeb02f0df2002-11-13 19:16:37 +0000926 return ('<table cellpadding="0" cellspacing="0"><tr valign="baseline">'
927 . "<td><nobr>$type\&nbsp;<b>$idx</b>(</nobr></td>"
928 . "<td>$args)</td>"
929 . '</tr></table>');
Fred Drake34adb8a2002-04-15 20:48:40 +0000930}
931sub do_cmd_cfuncline{
932 local($_) = @_;
933 my $type = next_argument();
934 my $name = next_argument();
935 my $args = next_argument();
936 my $siginfo = cfuncline_helper($type, $name, $args);
937 return "<dt>$siginfo\n<dd>" . $_;
938}
939sub do_env_cfuncdesc{
940 local($_) = @_;
941 my $type = next_argument();
942 my $name = next_argument();
943 my $args = next_argument();
944 my $siginfo = cfuncline_helper($type, $name, $args);
945 my $result_rc = get_refcount($name, '');
Fred Drakee15956b2000-04-03 04:51:13 +0000946 my $rcinfo = '';
947 if ($result_rc eq '+1') {
Fred Drake241551c2000-08-11 20:04:19 +0000948 $rcinfo = 'New reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000949 }
950 elsif ($result_rc eq '0') {
Fred Drake241551c2000-08-11 20:04:19 +0000951 $rcinfo = 'Borrowed reference';
Fred Drakee15956b2000-04-03 04:51:13 +0000952 }
Fred Drakec2578c52000-04-10 18:26:45 +0000953 elsif ($result_rc eq 'null') {
Fred Drake241551c2000-08-11 20:04:19 +0000954 $rcinfo = 'Always <tt class="constant">NULL</tt>';
Fred Drakec2578c52000-04-10 18:26:45 +0000955 }
Fred Drakee15956b2000-04-03 04:51:13 +0000956 if ($rcinfo ne '') {
Fred Drake241551c2000-08-11 20:04:19 +0000957 $rcinfo = ( "\n<div class=\"refcount-info\">"
958 . "\n <span class=\"label\">Return value:</span>"
959 . "\n <span class=\"value\">$rcinfo.</span>"
960 . "\n</div>");
Fred Drakee15956b2000-04-03 04:51:13 +0000961 }
Fred Drake34adb8a2002-04-15 20:48:40 +0000962 return "<dl><dt>$siginfo\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +0000963 . $rcinfo
Fred Drake62e43691998-08-10 19:40:44 +0000964 . $_
965 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +0000966}
967
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000968sub do_cmd_cmemberline{
969 local($_) = @_;
970 my $container = next_argument();
971 my $type = next_argument();
972 my $name = next_argument();
973 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000974 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000975 $idx =~ s/ \(.*\)//;
976 return "<dt>$type <b>$idx</b>\n<dd>"
977 . $_;
978}
979sub do_env_cmemberdesc{
980 local($_) = @_;
981 my $container = next_argument();
982 my $type = next_argument();
983 my $name = next_argument();
984 my $idx = make_str_index_entry("<tt class=\"cmember\">$name</tt>"
Fred Drake01572762002-04-15 19:35:29 +0000985 . " ($container member)");
Fred Drakeeeb5ec42002-04-15 17:46:00 +0000986 $idx =~ s/ \(.*\)//;
987 return "<dl><dt>$type <b>$idx</b>\n<dd>"
988 . $_
989 . '</dl>';
990}
991
Fred Drakee15956b2000-04-03 04:51:13 +0000992sub do_env_csimplemacrodesc{
993 local($_) = @_;
994 my $name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +0000995 my $idx = make_str_index_entry("<tt class=\"macro\">$name</tt>");
Fred Drakee15956b2000-04-03 04:51:13 +0000996 return "<dl><dt><b>$idx</b>\n<dd>"
997 . $_
998 . '</dl>'
999}
1000
Fred Drake6659c301998-03-03 22:02:19 +00001001sub do_env_ctypedesc{
1002 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001003 my $index_name = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001004 my $type_name = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001005 $index_name = $type_name
1006 unless $index_name;
Fred Drakef5478632002-05-23 17:59:16 +00001007 my($name, $aname, $ahref) = new_link_info();
Fred Drakef1927a62001-06-20 21:29:30 +00001008 add_index_entry("<tt class=\"ctype\">$index_name</tt> (C type)", $ahref);
1009 return "<dl><dt><b><tt class=\"ctype\">$aname$type_name</a></tt></b>\n<dd>"
Fred Drake62e43691998-08-10 19:40:44 +00001010 . $_
1011 . '</dl>'
Fred Drake6659c301998-03-03 22:02:19 +00001012}
1013
1014sub do_env_cvardesc{
1015 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001016 my $var_type = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001017 my $var_name = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001018 my $idx = make_str_index_entry("<tt class=\"cdata\">$var_name</tt>"
Fred Drake90fdda51999-02-16 20:27:42 +00001019 . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001020 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001021 return "<dl><dt>$var_type <b>$idx</b>\n"
1022 . '<dd>'
1023 . $_
1024 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001025}
1026
Fred Drake3cdb89d2000-09-14 20:17:23 +00001027sub convert_args($){
1028 local($IN_DESC_HANDLER) = 1;
1029 local($_) = @_;
1030 return translate_commands($_);
1031}
1032
Fred Drakef6e90272002-06-18 18:24:16 +00001033sub funcline_helper($$$){
1034 my($first, $idxitem, $arglist) = @_;
1035 return (($first ? '<dl>' : '')
Fred Drakeb02f0df2002-11-13 19:16:37 +00001036 . '<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">'
1037 . "\n <td><nobr><b>$idxitem</b>(</nobr></td>"
1038 . "\n <td><var>$arglist</var>)</td></tr></table>\n<dd>");
Fred Drakef6e90272002-06-18 18:24:16 +00001039}
1040
Fred Drake6659c301998-03-03 22:02:19 +00001041sub do_env_funcdesc{
1042 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001043 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001044 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001045 my $idx = make_str_index_entry("<tt class=\"function\">$function_name()"
1046 . '</tt>'
Fred Drake08932051998-04-17 02:15:42 +00001047 . get_indexsubitem());
1048 $idx =~ s/ \(.*\)//;
Fred Drakeccc62721999-01-05 22:16:29 +00001049 $idx =~ s/\(\)<\/tt>/<\/tt>/;
Fred Drakef6e90272002-06-18 18:24:16 +00001050 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001051}
1052
1053sub do_env_funcdescni{
1054 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001055 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001056 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001057 my $prefix = "<tt class=\"function\">$function_name</tt>";
1058 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001059}
1060
1061sub do_cmd_funcline{
1062 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001063 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001064 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001065 my $prefix = "<tt class=\"function\">$function_name()</tt>";
Fred Drakeca675e41999-04-21 15:58:58 +00001066 my $idx = make_str_index_entry($prefix . get_indexsubitem());
1067 $prefix =~ s/\(\)//;
1068
Fred Drakef6e90272002-06-18 18:24:16 +00001069 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001070}
1071
Fred Drake6b3fb781999-07-12 16:50:09 +00001072sub do_cmd_funclineni{
1073 local($_) = @_;
1074 my $function_name = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001075 my $arg_list = convert_args(next_argument());
Fred Drakef1927a62001-06-20 21:29:30 +00001076 my $prefix = "<tt class=\"function\">$function_name</tt>";
Fred Drake6b3fb781999-07-12 16:50:09 +00001077
Fred Drakef6e90272002-06-18 18:24:16 +00001078 return funcline_helper(0, $prefix, $arg_list) . $_;
Fred Drake6b3fb781999-07-12 16:50:09 +00001079}
1080
Fred Drake6659c301998-03-03 22:02:19 +00001081# Change this flag to index the opcode entries. I don't think it's very
1082# useful to index them, since they're only presented to describe the dis
1083# module.
1084#
1085$INDEX_OPCODES = 0;
1086
1087sub do_env_opcodedesc{
1088 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001089 my $opcode_name = next_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001090 my $arg_list = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001091 my $idx;
1092 if ($INDEX_OPCODES) {
Fred Drakef1927a62001-06-20 21:29:30 +00001093 $idx = make_str_index_entry("<tt class=\"opcode\">$opcode_name</tt>"
1094 . ' (byte code instruction)');
Fred Drake08932051998-04-17 02:15:42 +00001095 $idx =~ s/ \(byte code instruction\)//;
1096 }
1097 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001098 $idx = "<tt class=\"opcode\">$opcode_name</tt>";
Fred Drake08932051998-04-17 02:15:42 +00001099 }
1100 my $stuff = "<dl><dt><b>$idx</b>";
Fred Drake6659c301998-03-03 22:02:19 +00001101 if ($arg_list) {
1102 $stuff .= "&nbsp;&nbsp;&nbsp;&nbsp;<var>$arg_list</var>";
1103 }
Fred Drake62e43691998-08-10 19:40:44 +00001104 return $stuff . "\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001105}
1106
1107sub do_env_datadesc{
1108 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001109 my $dataname = next_argument();
1110 my $idx = make_str_index_entry("<tt>$dataname</tt>" . get_indexsubitem());
Fred Drake08932051998-04-17 02:15:42 +00001111 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001112 return "<dl><dt><b>$idx</b>\n<dd>"
1113 . $_
1114 . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001115}
1116
1117sub do_env_datadescni{
1118 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001119 my $idx = next_argument();
1120 if (! $STRING_INDEX_TT) {
1121 $idx = "<tt>$idx</tt>";
Fred Drake6659c301998-03-03 22:02:19 +00001122 }
Fred Drake62e43691998-08-10 19:40:44 +00001123 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake6659c301998-03-03 22:02:19 +00001124}
1125
1126sub do_cmd_dataline{
1127 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001128 my $data_name = next_argument();
1129 my $idx = make_str_index_entry("<tt>$data_name</tt>" . get_indexsubitem());
Fred Drake6659c301998-03-03 22:02:19 +00001130 $idx =~ s/ \(.*\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001131 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001132}
1133
Fred Drakeadb272c2000-04-10 17:47:14 +00001134sub do_cmd_datalineni{
1135 local($_) = @_;
1136 my $data_name = next_argument();
1137 return "<dt><b><tt>$data_name</tt></b><dd>" . $_;
1138}
1139
Fred Drake42b31a51998-03-27 05:16:10 +00001140sub do_env_excdesc{
1141 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001142 my $excname = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001143 my $idx = make_str_index_entry("<tt class=\"exception\">$excname</tt>");
Fred Drakef6e90272002-06-18 18:24:16 +00001144 return ("<dl><dt><b>${TLSTART}exception$TLEND$idx</b>"
Fred Drakeaf07b2c2001-10-26 03:09:27 +00001145 . "\n<dd>"
1146 . $_
1147 . '</dl>');
Fred Drake42b31a51998-03-27 05:16:10 +00001148}
1149
Fred Drake62e43691998-08-10 19:40:44 +00001150sub do_env_fulllineitems{ return do_env_itemize(@_); }
Fred Drake6659c301998-03-03 22:02:19 +00001151
1152
Fred Drakef5478632002-05-23 17:59:16 +00001153sub handle_classlike_descriptor($$){
Fred Drake643d76d2000-09-09 06:07:37 +00001154 local($_, $what) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001155 $THIS_CLASS = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001156 my $arg_list = convert_args(next_argument());
Fred Drakeccc62721999-01-05 22:16:29 +00001157 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001158 "<tt class=\"$what\">$THIS_CLASS</tt> ($what in $THIS_MODULE)" );
Fred Drake08932051998-04-17 02:15:42 +00001159 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001160 my $prefix = "$TLSTART$what$TLEND$idx";
1161 return funcline_helper(1, $prefix, $arg_list) . $_ . '</dl>';
Fred Drakec9a44381998-03-17 06:29:13 +00001162}
1163
Fred Drake643d76d2000-09-09 06:07:37 +00001164sub do_env_classdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001165 return handle_classlike_descriptor($_[0], "class");
Fred Drake643d76d2000-09-09 06:07:37 +00001166}
1167
Fred Drake06a01e82001-05-11 01:00:30 +00001168sub do_env_classdescstar{
1169 local($_) = @_;
1170 $THIS_CLASS = next_argument();
1171 $idx = make_str_index_entry(
Fred Drakef1927a62001-06-20 21:29:30 +00001172 "<tt class=\"class\">$THIS_CLASS</tt> (class in $THIS_MODULE)");
Fred Drake06a01e82001-05-11 01:00:30 +00001173 $idx =~ s/ \(.*\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001174 my $prefix = "${TLSTART}class$TLEND$idx";
1175 # Can't use funcline_helper() since there is no args list.
1176 return "<dl><dt><b>$prefix</b>\n<dd>" . $_ . '</dl>';
Fred Drake06a01e82001-05-11 01:00:30 +00001177}
1178
Fred Drake643d76d2000-09-09 06:07:37 +00001179sub do_env_excclassdesc{
Fred Drake49b33fa2002-11-15 19:04:10 +00001180 return handle_classlike_descriptor($_[0], "exception");
Fred Drake643d76d2000-09-09 06:07:37 +00001181}
1182
Fred Drake42b31a51998-03-27 05:16:10 +00001183
1184sub do_env_methoddesc{
1185 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001186 my $class_name = next_optional_argument();
1187 $class_name = $THIS_CLASS
1188 unless $class_name;
Fred Drake5a0ca4e1999-01-12 04:16:51 +00001189 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001190 my $arg_list = convert_args(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001191 my $extra = '';
1192 if ($class_name) {
1193 $extra = " ($class_name method)";
Fred Drake42b31a51998-03-27 05:16:10 +00001194 }
Fred Drakef1927a62001-06-20 21:29:30 +00001195 my $idx = make_str_index_entry(
1196 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake08932051998-04-17 02:15:42 +00001197 $idx =~ s/ \(.*\)//;
1198 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001199 return funcline_helper(1, $idx, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001200}
1201
1202
Fred Drake7d45f6d1999-01-05 14:39:27 +00001203sub do_cmd_methodline{
1204 local($_) = @_;
1205 my $class_name = next_optional_argument();
1206 $class_name = $THIS_CLASS
1207 unless $class_name;
1208 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001209 my $arg_list = convert_args(next_argument());
Fred Drake7d45f6d1999-01-05 14:39:27 +00001210 my $extra = '';
1211 if ($class_name) {
1212 $extra = " ($class_name method)";
1213 }
Fred Drakef1927a62001-06-20 21:29:30 +00001214 my $idx = make_str_index_entry(
1215 "<tt class=\"method\">$method()</tt>$extra");
Fred Drake7d45f6d1999-01-05 14:39:27 +00001216 $idx =~ s/ \(.*\)//;
1217 $idx =~ s/\(\)//;
Fred Drakef6e90272002-06-18 18:24:16 +00001218 return funcline_helper(0, $idx, $arg_list) . $_;
Fred Drake7d45f6d1999-01-05 14:39:27 +00001219}
1220
1221
Fred Draked64a40d1998-09-10 18:59:13 +00001222sub do_cmd_methodlineni{
1223 local($_) = @_;
1224 next_optional_argument();
1225 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001226 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001227 return funcline_helper(0, $method, $arg_list) . $_;
Fred Draked64a40d1998-09-10 18:59:13 +00001228}
1229
Fred Drake42b31a51998-03-27 05:16:10 +00001230sub do_env_methoddescni{
1231 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001232 next_optional_argument();
1233 my $method = next_argument();
Fred Drake3cdb89d2000-09-14 20:17:23 +00001234 my $arg_list = convert_args(next_argument());
Fred Drakef6e90272002-06-18 18:24:16 +00001235 return funcline_helper(1, $method, $arg_list) . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001236}
1237
1238
1239sub do_env_memberdesc{
1240 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001241 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001242 my $member = next_argument();
Fred Drake42b31a51998-03-27 05:16:10 +00001243 $class = $THIS_CLASS
1244 unless $class;
Fred Drake08932051998-04-17 02:15:42 +00001245 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001246 $extra = " ($class attribute)"
1247 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001248 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake42b31a51998-03-27 05:16:10 +00001249 $idx =~ s/ \(.*\)//;
1250 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001251 return "<dl><dt><b>$idx</b>\n<dd>" . $_ . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001252}
1253
1254
Fred Drake5ccf3301998-04-17 20:04:09 +00001255sub do_cmd_memberline{
1256 local($_) = @_;
1257 my $class = next_optional_argument();
Fred Drakeccc62721999-01-05 22:16:29 +00001258 my $member = next_argument();
Fred Drake5ccf3301998-04-17 20:04:09 +00001259 $class = $THIS_CLASS
1260 unless $class;
1261 my $extra = '';
Fred Drake085b8121999-04-21 14:00:29 +00001262 $extra = " ($class attribute)"
1263 if ($class ne '');
Fred Drakef1927a62001-06-20 21:29:30 +00001264 my $idx = make_str_index_entry("<tt class=\"member\">$member</tt>$extra");
Fred Drake5ccf3301998-04-17 20:04:09 +00001265 $idx =~ s/ \(.*\)//;
1266 $idx =~ s/\(\)//;
Fred Drake62e43691998-08-10 19:40:44 +00001267 return "<dt><b>$idx</b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001268}
1269
Fred Drakef269e592001-07-17 23:05:57 +00001270
Fred Drake42b31a51998-03-27 05:16:10 +00001271sub do_env_memberdescni{
1272 local($_) = @_;
Fred Drake08932051998-04-17 02:15:42 +00001273 next_optional_argument();
1274 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001275 return "<dl><dt><b><tt class=\"member\">$member</tt></b>\n<dd>"
Fred Drakee15956b2000-04-03 04:51:13 +00001276 . $_
1277 . '</dl>';
Fred Drake42b31a51998-03-27 05:16:10 +00001278}
1279
1280
Fred Drake5ccf3301998-04-17 20:04:09 +00001281sub do_cmd_memberlineni{
1282 local($_) = @_;
1283 next_optional_argument();
1284 my $member = next_argument();
Fred Drakef1927a62001-06-20 21:29:30 +00001285 return "<dt><b><tt class=\"member\">$member</tt></b><dd>" . $_;
Fred Drake5ccf3301998-04-17 20:04:09 +00001286}
1287
Fred Drakef269e592001-07-17 23:05:57 +00001288
1289@col_aligns = ('<td>', '<td>', '<td>', '<td>', '<td>');
Fred Drake6659c301998-03-03 22:02:19 +00001290
Fred Drakecb199762001-08-16 21:56:24 +00001291%FontConversions = ('cdata' => 'tt class="cdata"',
1292 'character' => 'tt class="character"',
1293 'class' => 'tt class="class"',
1294 'command' => 'code',
1295 'constant' => 'tt class="constant"',
1296 'exception' => 'tt class="exception"',
1297 'file' => 'tt class="file"',
1298 'filenq' => 'tt class="file"',
1299 'kbd' => 'kbd',
1300 'member' => 'tt class="member"',
1301 'programopt' => 'b',
1302 'textrm' => '',
1303 );
1304
Fred Drakef5478632002-05-23 17:59:16 +00001305sub fix_font($){
Fred Drakef74e5b71999-04-28 14:58:49 +00001306 # do a little magic on a font name to get the right behavior in the first
1307 # column of the output table
Fred Drake49b33fa2002-11-15 19:04:10 +00001308 my $font = $_[0];
Fred Drakecb199762001-08-16 21:56:24 +00001309 if (defined $FontConversions{$font}) {
1310 $font = $FontConversions{$font};
Fred Drakeafc7ce12001-01-22 17:33:24 +00001311 }
Fred Drakef74e5b71999-04-28 14:58:49 +00001312 return $font;
1313}
1314
Fred Drakef5478632002-05-23 17:59:16 +00001315sub figure_column_alignment($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001316 my $a = $_[0];
1317 if (!defined $a) {
1318 return '';
1319 }
Fred Drakee15956b2000-04-03 04:51:13 +00001320 my $mark = substr($a, 0, 1);
1321 my $r = '';
1322 if ($mark eq 'c')
1323 { $r = ' align="center"'; }
1324 elsif ($mark eq 'r')
1325 { $r = ' align="right"'; }
1326 elsif ($mark eq 'l')
1327 { $r = ' align="left"'; }
1328 elsif ($mark eq 'p')
1329 { $r = ' align="left"'; }
1330 return $r;
1331}
1332
Fred Drakef5478632002-05-23 17:59:16 +00001333sub setup_column_alignments($){
Fred Drake6659c301998-03-03 22:02:19 +00001334 local($_) = @_;
Fred Drake49b33fa2002-11-15 19:04:10 +00001335 my($s1, $s2, $s3, $s4, $s5) = split(/[|]/,$_);
Fred Drakee15956b2000-04-03 04:51:13 +00001336 my $a1 = figure_column_alignment($s1);
1337 my $a2 = figure_column_alignment($s2);
1338 my $a3 = figure_column_alignment($s3);
1339 my $a4 = figure_column_alignment($s4);
Fred Drakef269e592001-07-17 23:05:57 +00001340 my $a5 = figure_column_alignment($s5);
Fred Drakee15956b2000-04-03 04:51:13 +00001341 $col_aligns[0] = "<td$a1 valign=\"baseline\">";
1342 $col_aligns[1] = "<td$a2>";
1343 $col_aligns[2] = "<td$a3>";
1344 $col_aligns[3] = "<td$a4>";
Fred Drakef269e592001-07-17 23:05:57 +00001345 $col_aligns[4] = "<td$a5>";
Fred Drake79189b51999-04-28 13:54:30 +00001346 # return the aligned header start tags
Fred Drakef269e592001-07-17 23:05:57 +00001347 return ("<th$a1>", "<th$a2>", "<th$a3>", "<th$a4>", "<th$a5>");
Fred Drakee15956b2000-04-03 04:51:13 +00001348}
1349
Fred Drakef5478632002-05-23 17:59:16 +00001350sub get_table_col1_fonts(){
Fred Drakee15956b2000-04-03 04:51:13 +00001351 my $font = $globals{'lineifont'};
Fred Drakef5478632002-05-23 17:59:16 +00001352 my($sfont, $efont) = ('', '');
Fred Drakee15956b2000-04-03 04:51:13 +00001353 if ($font) {
1354 $sfont = "<$font>";
1355 $efont = "</$font>";
1356 $efont =~ s/ .*>/>/;
1357 }
Fred Drakee463f8e2000-11-30 07:17:27 +00001358 return ($sfont, $efont);
Fred Drake6659c301998-03-03 22:02:19 +00001359}
1360
1361sub do_env_tableii{
1362 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001363 my $arg = next_argument();
1364 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001365 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001366 my $h1 = next_argument();
1367 my $h2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001368 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001369 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001370 my $a1 = $col_aligns[0];
1371 my $a2 = $col_aligns[1];
1372 s/\\lineii</\\lineii[$a1|$a2]</g;
1373 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001374 . "\n <thead>"
1375 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001376 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1377 . "\n $th2<b>$h2</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001378 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001379 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001380 . "\n <tbody valign=\"baseline\">"
Fred Drake351960d2000-10-26 20:14:58 +00001381 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001382 . "\n </tbody>"
1383 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001384}
1385
Fred Drakeda72b932000-09-21 15:58:02 +00001386sub do_env_longtableii{
1387 return do_env_tableii(@_);
1388}
1389
Fred Drake6659c301998-03-03 22:02:19 +00001390sub do_cmd_lineii{
1391 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001392 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001393 my $c1 = next_argument();
1394 my $c2 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001395 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001396 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001397 $c2 = '&nbsp;' if ($c2 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001398 my($c1align, $c2align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001399 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001400 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001401 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001402 }
Fred Drakee15956b2000-04-03 04:51:13 +00001403 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1404 . " $c2align$c2</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001405 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001406}
1407
1408sub do_env_tableiii{
1409 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001410 my $arg = next_argument();
1411 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001412 my $font = fix_font(next_argument());
Fred Drake08932051998-04-17 02:15:42 +00001413 my $h1 = next_argument();
1414 my $h2 = next_argument();
1415 my $h3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001416 s/[\s\n]+//;
Fred Drake08932051998-04-17 02:15:42 +00001417 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001418 my $a1 = $col_aligns[0];
1419 my $a2 = $col_aligns[1];
1420 my $a3 = $col_aligns[2];
1421 s/\\lineiii</\\lineiii[$a1|$a2|$a3]</g;
1422 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001423 . "\n <thead>"
1424 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001425 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1426 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1427 . "\n $th3<b>$h3</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001428 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001429 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001430 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001431 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001432 . "\n </tbody>"
1433 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001434}
1435
Fred Drakeda72b932000-09-21 15:58:02 +00001436sub do_env_longtableiii{
1437 return do_env_tableiii(@_);
1438}
1439
Fred Drake6659c301998-03-03 22:02:19 +00001440sub do_cmd_lineiii{
1441 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001442 my $aligns = next_optional_argument();
Fred Drake08932051998-04-17 02:15:42 +00001443 my $c1 = next_argument();
Fred Drakef269e592001-07-17 23:05:57 +00001444 my $c2 = next_argument();
Fred Drake08932051998-04-17 02:15:42 +00001445 my $c3 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001446 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001447 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001448 $c3 = '&nbsp;' if ($c3 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001449 my($c1align, $c2align, $c3align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001450 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001451 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001452 $padding = '&nbsp;';
Fred Drake58b2bfd1998-04-02 20:14:04 +00001453 }
Fred Drakee15956b2000-04-03 04:51:13 +00001454 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001455 . " $c2align$c2</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001456 . " $c3align$c3</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001457 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001458}
1459
Fred Drakea0f4c941998-07-24 22:16:04 +00001460sub do_env_tableiv{
1461 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001462 my $arg = next_argument();
1463 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef74e5b71999-04-28 14:58:49 +00001464 my $font = fix_font(next_argument());
Fred Drakea0f4c941998-07-24 22:16:04 +00001465 my $h1 = next_argument();
1466 my $h2 = next_argument();
1467 my $h3 = next_argument();
1468 my $h4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001469 s/[\s\n]+//;
Fred Drakea0f4c941998-07-24 22:16:04 +00001470 $globals{'lineifont'} = $font;
Fred Drakee15956b2000-04-03 04:51:13 +00001471 my $a1 = $col_aligns[0];
1472 my $a2 = $col_aligns[1];
1473 my $a3 = $col_aligns[2];
1474 my $a4 = $col_aligns[3];
1475 s/\\lineiv</\\lineiv[$a1|$a2|$a3|$a4]</g;
1476 return '<table border align="center" style="border-collapse: collapse">'
Fred Drake351960d2000-10-26 20:14:58 +00001477 . "\n <thead>"
1478 . "\n <tr class=\"tableheader\">"
Fred Drakee15956b2000-04-03 04:51:13 +00001479 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1480 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1481 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1482 . "\n $th4<b>$h4</b>\&nbsp;</th>"
Fred Drake351960d2000-10-26 20:14:58 +00001483 . "\n </tr>"
Fred Drakef74e5b71999-04-28 14:58:49 +00001484 . "\n </thead>"
Fred Drakef1927a62001-06-20 21:29:30 +00001485 . "\n <tbody valign=\"baseline\">"
Fred Drake62e43691998-08-10 19:40:44 +00001486 . $_
Fred Drakef74e5b71999-04-28 14:58:49 +00001487 . "\n </tbody>"
1488 . "\n</table>";
Fred Drake6659c301998-03-03 22:02:19 +00001489}
1490
Fred Drakeda72b932000-09-21 15:58:02 +00001491sub do_env_longtableiv{
1492 return do_env_tableiv(@_);
1493}
1494
Fred Drakea0f4c941998-07-24 22:16:04 +00001495sub do_cmd_lineiv{
Fred Drake6659c301998-03-03 22:02:19 +00001496 local($_) = @_;
Fred Drakee15956b2000-04-03 04:51:13 +00001497 my $aligns = next_optional_argument();
Fred Drakea0f4c941998-07-24 22:16:04 +00001498 my $c1 = next_argument();
1499 my $c2 = next_argument();
1500 my $c3 = next_argument();
1501 my $c4 = next_argument();
Fred Drakef74e5b71999-04-28 14:58:49 +00001502 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001503 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakee15956b2000-04-03 04:51:13 +00001504 $c4 = '&nbsp;' if ($c4 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001505 my($c1align, $c2align, $c3align, $c4align) = split('\|', $aligns);
Fred Drakee15956b2000-04-03 04:51:13 +00001506 my $padding = '';
Fred Drakee463f8e2000-11-30 07:17:27 +00001507 if ($c1align =~ /align="right"/ || $c1 eq '') {
Fred Drakee15956b2000-04-03 04:51:13 +00001508 $padding = '&nbsp;';
Fred Drakea0f4c941998-07-24 22:16:04 +00001509 }
Fred Drakee15956b2000-04-03 04:51:13 +00001510 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
Fred Drakef74e5b71999-04-28 14:58:49 +00001511 . " $c2align$c2</td>\n"
1512 . " $c3align$c3</td>\n"
Fred Drakee15956b2000-04-03 04:51:13 +00001513 . " $c4align$c4</td>"
Fred Drake62e43691998-08-10 19:40:44 +00001514 . $_;
Fred Drake6659c301998-03-03 22:02:19 +00001515}
1516
Fred Drakef269e592001-07-17 23:05:57 +00001517sub do_env_tablev{
1518 local($_) = @_;
Fred Drakef5478632002-05-23 17:59:16 +00001519 my $arg = next_argument();
1520 my($th1, $th2, $th3, $th4, $th5) = setup_column_alignments($arg);
Fred Drakef269e592001-07-17 23:05:57 +00001521 my $font = fix_font(next_argument());
1522 my $h1 = next_argument();
1523 my $h2 = next_argument();
1524 my $h3 = next_argument();
1525 my $h4 = next_argument();
1526 my $h5 = next_argument();
1527 s/[\s\n]+//;
1528 $globals{'lineifont'} = $font;
1529 my $a1 = $col_aligns[0];
1530 my $a2 = $col_aligns[1];
1531 my $a3 = $col_aligns[2];
1532 my $a4 = $col_aligns[3];
1533 my $a5 = $col_aligns[4];
1534 s/\\linev</\\linev[$a1|$a2|$a3|$a4|$a5]</g;
1535 return '<table border align="center" style="border-collapse: collapse">'
1536 . "\n <thead>"
1537 . "\n <tr class=\"tableheader\">"
1538 . "\n $th1<b>$h1</b>\&nbsp;</th>"
1539 . "\n $th2<b>$h2</b>\&nbsp;</th>"
1540 . "\n $th3<b>$h3</b>\&nbsp;</th>"
1541 . "\n $th4<b>$h4</b>\&nbsp;</th>"
1542 . "\n $th5<b>$h5</b>\&nbsp;</th>"
1543 . "\n </tr>"
1544 . "\n </thead>"
1545 . "\n <tbody valign=\"baseline\">"
1546 . $_
1547 . "\n </tbody>"
1548 . "\n</table>";
1549}
1550
1551sub do_env_longtablev{
1552 return do_env_tablev(@_);
1553}
1554
1555sub do_cmd_linev{
1556 local($_) = @_;
1557 my $aligns = next_optional_argument();
1558 my $c1 = next_argument();
1559 my $c2 = next_argument();
1560 my $c3 = next_argument();
1561 my $c4 = next_argument();
1562 my $c5 = next_argument();
1563 s/[\s\n]+//;
Fred Drakef5478632002-05-23 17:59:16 +00001564 my($sfont, $efont) = get_table_col1_fonts();
Fred Drakef269e592001-07-17 23:05:57 +00001565 $c5 = '&nbsp;' if ($c5 eq '');
Fred Drakef5478632002-05-23 17:59:16 +00001566 my($c1align, $c2align, $c3align, $c4align, $c5align) = split('\|',$aligns);
Fred Drakef269e592001-07-17 23:05:57 +00001567 my $padding = '';
1568 if ($c1align =~ /align="right"/ || $c1 eq '') {
1569 $padding = '&nbsp;';
1570 }
1571 return "\n <tr>$c1align$sfont$c1$efont$padding</td>\n"
1572 . " $c2align$c2</td>\n"
1573 . " $c3align$c3</td>\n"
1574 . " $c4align$c4</td>\n"
1575 . " $c5align$c5</td>"
1576 . $_;
1577}
1578
Fred Drake3be20742000-08-31 06:22:54 +00001579
1580# These can be used to control the title page appearance;
1581# they need a little bit of documentation.
1582#
1583# If $TITLE_PAGE_GRAPHIC is set, it should be the name of a file in the
1584# $ICONSERVER directory, or include path information (other than "./"). The
1585# default image type will be assumed if an extension is not provided.
1586#
1587# If specified, the "title page" will contain two colums: one containing the
1588# title/author/etc., and the other containing the graphic. Use the other
1589# four variables listed here to control specific details of the layout; all
1590# are optional.
1591#
1592# $TITLE_PAGE_GRAPHIC = "my-company-logo";
1593# $TITLE_PAGE_GRAPHIC_COLWIDTH = "30%";
1594# $TITLE_PAGE_GRAPHIC_WIDTH = 150;
1595# $TITLE_PAGE_GRAPHIC_HEIGHT = 150;
1596# $TITLE_PAGE_GRAPHIC_ON_RIGHT = 0;
1597
Fred Drakef5478632002-05-23 17:59:16 +00001598sub make_my_titlepage(){
Fred Drake3be20742000-08-31 06:22:54 +00001599 my $the_title = "";
Fred Drake6659c301998-03-03 22:02:19 +00001600 if ($t_title) {
Fred Drake90fdda51999-02-16 20:27:42 +00001601 $the_title .= "\n<h1>$t_title</h1>";
Fred Drake3be20742000-08-31 06:22:54 +00001602 }
1603 else {
1604 write_warnings("\nThis document has no title.");
1605 }
Fred Drake6659c301998-03-03 22:02:19 +00001606 if ($t_author) {
1607 if ($t_authorURL) {
Fred Drake08932051998-04-17 02:15:42 +00001608 my $href = translate_commands($t_authorURL);
Fred Drake2d1f81e1999-02-09 16:03:31 +00001609 $href = make_named_href('author', $href,
Fred Drakef1927a62001-06-20 21:29:30 +00001610 "<b><font size=\"+2\">$t_author"
1611 . '</font></b>');
Fred Drakec9a44381998-03-17 06:29:13 +00001612 $the_title .= "\n<p>$href</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001613 }
1614 else {
Fred Drakef1927a62001-06-20 21:29:30 +00001615 $the_title .= ("\n<p><b><font size=\"+2\">$t_author"
1616 . '</font></b></p>');
Fred Drake6659c301998-03-03 22:02:19 +00001617 }
Fred Drake3be20742000-08-31 06:22:54 +00001618 }
1619 else {
1620 write_warnings("\nThere is no author for this document.");
1621 }
Fred Drake6659c301998-03-03 22:02:19 +00001622 if ($t_institute) {
Fred Drake3be20742000-08-31 06:22:54 +00001623 $the_title .= "\n<p>$t_institute</p>";
1624 }
Fred Draked07868a1998-05-14 21:00:28 +00001625 if ($DEVELOPER_ADDRESS) {
Fred Drake3be20742000-08-31 06:22:54 +00001626 $the_title .= "\n<p>$DEVELOPER_ADDRESS</p>";
1627 }
Fred Drake6659c301998-03-03 22:02:19 +00001628 if ($t_affil) {
Fred Drake3be20742000-08-31 06:22:54 +00001629 $the_title .= "\n<p><i>$t_affil</i></p>";
1630 }
Fred Drake6659c301998-03-03 22:02:19 +00001631 if ($t_date) {
Fred Drakede77bc52000-12-14 18:36:12 +00001632 $the_title .= "\n<p>";
Fred Draked04592a2000-10-25 16:15:13 +00001633 if ($PACKAGE_VERSION) {
Fred Drakef1927a62001-06-20 21:29:30 +00001634 $the_title .= ('<strong>Release '
1635 . "$PACKAGE_VERSION$RELEASE_INFO</strong><br>\n");
Fred Drake3be20742000-08-31 06:22:54 +00001636 }
Fred Drakede77bc52000-12-14 18:36:12 +00001637 $the_title .= "<strong>$t_date</strong></p>"
Fred Drake6659c301998-03-03 22:02:19 +00001638 }
1639 if ($t_address) {
Fred Drakec9a44381998-03-17 06:29:13 +00001640 $the_title .= "\n<p>$t_address</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001641 }
1642 else {
1643 $the_title .= "\n<p>";
1644 }
Fred Drake6659c301998-03-03 22:02:19 +00001645 if ($t_email) {
Fred Drakec9a44381998-03-17 06:29:13 +00001646 $the_title .= "\n<p>$t_email</p>";
Fred Drake3be20742000-08-31 06:22:54 +00001647 }
1648 return $the_title;
1649}
1650
Fred Drakef5478632002-05-23 17:59:16 +00001651sub make_my_titlegraphic(){
Fred Drake7a40c072000-10-02 14:43:38 +00001652 my $filename = make_icon_filename($TITLE_PAGE_GRAPHIC);
Fred Drake3be20742000-08-31 06:22:54 +00001653 my $graphic = "<td class=\"titlegraphic\"";
1654 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_COLWIDTH\""
1655 if ($TITLE_PAGE_GRAPHIC_COLWIDTH);
1656 $graphic .= "><img";
1657 $graphic .= " width=\"$TITLE_PAGE_GRAPHIC_WIDTH\""
1658 if ($TITLE_PAGE_GRAPHIC_WIDTH);
1659 $graphic .= " height=\"$TITLE_PAGE_GRAPHIC_HEIGHT\""
1660 if ($TITLE_PAGE_GRAPHIC_HEIGHT);
Fred Drake5f84c9b2000-10-03 06:05:25 +00001661 $graphic .= "\n src=\"$filename\"></td>\n";
Fred Drake3be20742000-08-31 06:22:54 +00001662 return $graphic;
1663}
1664
Fred Drakef5478632002-05-23 17:59:16 +00001665sub do_cmd_maketitle{
Fred Drake3be20742000-08-31 06:22:54 +00001666 local($_) = @_;
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001667 my $the_title = "\n";
1668 if ($EXTERNAL_UP_LINK) {
1669 # This generates a <LINK> element in the wrong place (the
1670 # body), but I don't see any other way to get this generated
1671 # at all. Browsers like Mozilla, that support navigation
1672 # links, can make use of this.
1673 $the_title .= ("<link rel='up' href='$EXTERNAL_UP_LINK'"
1674 . ($EXTERNAL_UP_TITLE
1675 ? " title='$EXTERNAL_UP_TITLE'" : '')
1676 . ">\n");
1677 }
1678 $the_title .= '<div class="titlepage">';
Fred Drake3be20742000-08-31 06:22:54 +00001679 if ($TITLE_PAGE_GRAPHIC) {
1680 if ($TITLE_PAGE_GRAPHIC_ON_RIGHT) {
1681 $the_title .= ("\n<table border=\"0\" width=\"100%\">"
1682 . "<tr align=\"right\">\n<td>"
1683 . make_my_titlepage()
1684 . "</td>\n"
1685 . make_my_titlegraphic()
1686 . "</tr>\n</table>");
1687 }
1688 else {
1689 $the_title .= ("\n<table border=\"0\" width=\"100%\"><tr>\n"
1690 . make_my_titlegraphic()
1691 . "<td>"
1692 . make_my_titlepage()
1693 . "</td></tr>\n</table>");
1694 }
1695 }
1696 else {
1697 $the_title .= ("\n<center>"
1698 . make_my_titlepage()
1699 . "\n</center>");
1700 }
1701 $the_title .= "\n</div>";
1702 return $the_title . $_;
Fred Drake90fdda51999-02-16 20:27:42 +00001703 $the_title .= "\n</center></div>";
Fred Drake62e43691998-08-10 19:40:44 +00001704 return $the_title . $_ ;
Fred Drake6659c301998-03-03 22:02:19 +00001705}
1706
1707
Fred Drake885215c1998-05-20 21:32:09 +00001708#
Fred Drakea0f4c941998-07-24 22:16:04 +00001709# Module synopsis support
1710#
1711
1712require SynopsisTable;
1713
Fred Drakef7685d71998-07-25 03:31:46 +00001714sub get_chapter_id(){
1715 my $id = do_cmd_thechapter('');
Fred Drake49b33fa2002-11-15 19:04:10 +00001716 $id =~ s/<SPAN CLASS="arabic">(\d+)<\/SPAN>/$1/;
Fred Drake45f26011998-08-04 22:07:18 +00001717 $id =~ s/\.//;
Fred Drakef7685d71998-07-25 03:31:46 +00001718 return $id;
Fred Drakea0f4c941998-07-24 22:16:04 +00001719}
1720
Fred Drake643d76d2000-09-09 06:07:37 +00001721# 'chapter' => 'SynopsisTable instance'
1722%ModuleSynopses = ();
Fred Drakef7685d71998-07-25 03:31:46 +00001723
1724sub get_synopsis_table($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001725 my $chap = $_[0];
Fred Drakef7685d71998-07-25 03:31:46 +00001726 my $key;
1727 foreach $key (keys %ModuleSynopses) {
1728 if ($key eq $chap) {
1729 return $ModuleSynopses{$chap};
1730 }
Fred Drakea0f4c941998-07-24 22:16:04 +00001731 }
Fred Drake643d76d2000-09-09 06:07:37 +00001732 my $st = SynopsisTable->new();
Fred Drakef7685d71998-07-25 03:31:46 +00001733 $ModuleSynopses{$chap} = $st;
Fred Drakea0f4c941998-07-24 22:16:04 +00001734 return $st;
1735}
1736
Fred Drake62e43691998-08-10 19:40:44 +00001737sub do_cmd_moduleauthor{
1738 local($_) = @_;
1739 next_argument();
1740 next_argument();
1741 return $_;
1742}
1743
1744sub do_cmd_sectionauthor{
1745 local($_) = @_;
1746 next_argument();
1747 next_argument();
1748 return $_;
1749}
1750
Fred Drakea0f4c941998-07-24 22:16:04 +00001751sub do_cmd_declaremodule{
1752 local($_) = @_;
1753 my $key = next_optional_argument();
1754 my $type = next_argument();
1755 my $name = next_argument();
1756 my $st = get_synopsis_table(get_chapter_id());
1757 #
1758 $key = $name unless $key;
1759 $type = 'built-in' if $type eq 'builtin';
1760 $st->declare($name, $key, $type);
1761 define_module($type, $name);
Fred Drake62e43691998-08-10 19:40:44 +00001762 return anchor_label("module-$key",$CURRENT_FILE,$_)
Fred Drakea0f4c941998-07-24 22:16:04 +00001763}
1764
1765sub do_cmd_modulesynopsis{
1766 local($_) = @_;
1767 my $st = get_synopsis_table(get_chapter_id());
Fred Drake1cc58991999-04-13 22:08:59 +00001768 $st->set_synopsis($THIS_MODULE, translate_commands(next_argument()));
Fred Drake62e43691998-08-10 19:40:44 +00001769 return $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001770}
1771
1772sub do_cmd_localmoduletable{
1773 local($_) = @_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001774 my $chap = get_chapter_id();
Fred Drake643d76d2000-09-09 06:07:37 +00001775 my $st = get_synopsis_table($chap);
1776 $st->set_file("$CURRENT_FILE");
Fred Drake557460c1999-03-02 16:05:35 +00001777 return "<tex2html-localmoduletable><$chap>\\tableofchildlinks[off]" . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001778}
1779
Fred Drakef5478632002-05-23 17:59:16 +00001780sub process_all_localmoduletables(){
Fred Drake643d76d2000-09-09 06:07:37 +00001781 my $key;
Fred Drake643d76d2000-09-09 06:07:37 +00001782 foreach $key (keys %ModuleSynopses) {
Fred Drake49b33fa2002-11-15 19:04:10 +00001783 my $st = $ModuleSynopses{$key};
1784 my $file = $st->get_file();
Fred Drake643d76d2000-09-09 06:07:37 +00001785 if ($file) {
1786 process_localmoduletables_in_file($file);
1787 }
1788 else {
Fred Drake6fe46602001-06-23 03:13:30 +00001789 print "\nsynopsis table $key has no file association\n";
Fred Drake643d76d2000-09-09 06:07:37 +00001790 }
1791 }
1792}
1793
Fred Drakef5478632002-05-23 17:59:16 +00001794sub process_localmoduletables_in_file($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001795 my $file = $_[0];
Fred Drake643d76d2000-09-09 06:07:37 +00001796 open(MYFILE, "<$file");
1797 local($_);
1798 sysread(MYFILE, $_, 1024*1024);
1799 close(MYFILE);
1800 # need to get contents of file in $_
Fred Drake557460c1999-03-02 16:05:35 +00001801 while (/<tex2html-localmoduletable><(\d+)>/) {
Fred Drakef7685d71998-07-25 03:31:46 +00001802 my $match = $&;
Fred Drakea0f4c941998-07-24 22:16:04 +00001803 my $chap = $1;
1804 my $st = get_synopsis_table($chap);
1805 my $data = $st->tohtml();
Fred Drakef7685d71998-07-25 03:31:46 +00001806 s/$match/$data/;
Fred Drakea0f4c941998-07-24 22:16:04 +00001807 }
Fred Drake643d76d2000-09-09 06:07:37 +00001808 open(MYFILE,">$file");
1809 print MYFILE $_;
1810 close(MYFILE);
Fred Drakea0f4c941998-07-24 22:16:04 +00001811}
Fred Drakef5478632002-05-23 17:59:16 +00001812sub process_python_state(){
Fred Drake557460c1999-03-02 16:05:35 +00001813 process_all_localmoduletables();
Fred Drake77602f22001-07-06 22:43:02 +00001814 process_grammar_files();
Fred Drake557460c1999-03-02 16:05:35 +00001815}
Fred Drakea0f4c941998-07-24 22:16:04 +00001816
1817
1818#
1819# "See also:" -- references placed at the end of a \section
1820#
1821
1822sub do_env_seealso{
Fred Drakef1927a62001-06-20 21:29:30 +00001823 return ("<div class=\"seealso\">\n "
1824 . "<p class=\"heading\"><b>See Also:</b></p>\n"
Fred Drake49b33fa2002-11-15 19:04:10 +00001825 . $_[0]
Fred Drakef1927a62001-06-20 21:29:30 +00001826 . '</div>');
Fred Drakea0f4c941998-07-24 22:16:04 +00001827}
1828
Fred Drake5ed35fd2001-11-30 18:09:54 +00001829sub do_env_seealsostar{
1830 return ("<div class=\"seealso-simple\">\n "
Fred Drake49b33fa2002-11-15 19:04:10 +00001831 . $_[0]
Fred Drake5ed35fd2001-11-30 18:09:54 +00001832 . '</div>');
1833}
1834
Fred Drakea0f4c941998-07-24 22:16:04 +00001835sub do_cmd_seemodule{
1836 # Insert the right magic to jump to the module definition. This should
1837 # work most of the time, at least for repeat builds....
1838 local($_) = @_;
1839 my $key = next_optional_argument();
1840 my $module = next_argument();
1841 my $text = next_argument();
Fred Drake84bd6f31999-05-11 15:42:51 +00001842 my $period = '.';
Fred Drakea0f4c941998-07-24 22:16:04 +00001843 $key = $module
1844 unless $key;
Fred Drake84bd6f31999-05-11 15:42:51 +00001845 if ($text =~ /\.$/) {
1846 $period = '';
1847 }
Fred Drakef1927a62001-06-20 21:29:30 +00001848 return ('<dl compact class="seemodule">'
1849 . "\n <dt>Module <b><tt class=\"module\">"
1850 . "<a href=\"module-$key.html\">$module</a></tt>:</b>"
1851 . "\n <dd>$text$period\n </dl>"
1852 . $_);
Fred Drakea0f4c941998-07-24 22:16:04 +00001853}
1854
Fred Drakee0197bf2001-04-12 04:03:22 +00001855sub strip_html_markup($){
Fred Drake49b33fa2002-11-15 19:04:10 +00001856 my $str = $_[0];
Fred Drakee0197bf2001-04-12 04:03:22 +00001857 my $s = "$str";
1858 $s =~ s/<[a-zA-Z0-9]+(\s+[a-zA-Z0-9]+(\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[a-zA-Z0-9]+))?)*\s*>//g;
1859 $s =~ s/<\/[a-zA-Z0-9]+>//g;
1860 return $s;
1861}
1862
Fred Drakef5478632002-05-23 17:59:16 +00001863sub handle_rfclike_reference($$$){
Fred Drakeafc7ce12001-01-22 17:33:24 +00001864 local($_, $what, $format) = @_;
Fred Drake37cc0c02000-04-26 18:05:24 +00001865 my $rfcnum = next_argument();
1866 my $title = next_argument();
1867 my $text = next_argument();
Fred Drakeafc7ce12001-01-22 17:33:24 +00001868 my $url = get_rfc_url($rfcnum, $format);
Fred Drake7a40c072000-10-02 14:43:38 +00001869 my $icon = get_link_icon($url);
Fred Drakee0197bf2001-04-12 04:03:22 +00001870 my $attrtitle = strip_html_markup($title);
Fred Drake37cc0c02000-04-26 18:05:24 +00001871 return '<dl compact class="seerfc">'
1872 . "\n <dt><a href=\"$url\""
Fred Drakee0197bf2001-04-12 04:03:22 +00001873 . "\n title=\"$attrtitle\""
Fred Drake5f84c9b2000-10-03 06:05:25 +00001874 . "\n >$what $rfcnum, <em>$title</em>$icon</a>"
Fred Drake37cc0c02000-04-26 18:05:24 +00001875 . "\n <dd>$text\n </dl>"
1876 . $_;
1877}
1878
Fred Drake643d76d2000-09-09 06:07:37 +00001879sub do_cmd_seepep{
Fred Drake49b33fa2002-11-15 19:04:10 +00001880 return handle_rfclike_reference($_[0], "PEP", $PEP_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001881}
1882
1883sub do_cmd_seerfc{
Fred Drakedbb2b9d2002-10-30 21:38:32 +00001884 # XXX Would be nice to add links to the text/plain and PDF versions.
Fred Drake49b33fa2002-11-15 19:04:10 +00001885 return handle_rfclike_reference($_[0], "RFC", $RFC_FORMAT);
Fred Drake643d76d2000-09-09 06:07:37 +00001886}
1887
Fred Drake48449982000-09-12 17:52:33 +00001888sub do_cmd_seetitle{
1889 local($_) = @_;
1890 my $url = next_optional_argument();
1891 my $title = next_argument();
1892 my $text = next_argument();
1893 if ($url) {
Fred Drake5f84c9b2000-10-03 06:05:25 +00001894 my $icon = get_link_icon($url);
Fred Drake48449982000-09-12 17:52:33 +00001895 return '<dl compact class="seetitle">'
1896 . "\n <dt><em class=\"citetitle\"><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001897 . "\n >$title$icon</a></em>"
Fred Drake48449982000-09-12 17:52:33 +00001898 . "\n <dd>$text\n </dl>"
1899 . $_;
1900 }
1901 return '<dl compact class="seetitle">'
1902 . "\n <dt><em class=\"citetitle\""
1903 . "\n >$title</em>"
1904 . "\n <dd>$text\n </dl>"
1905 . $_;
1906}
1907
Fred Drakeef4d1112000-05-09 16:17:51 +00001908sub do_cmd_seeurl{
1909 local($_) = @_;
1910 my $url = next_argument();
1911 my $text = next_argument();
Fred Drake7a40c072000-10-02 14:43:38 +00001912 my $icon = get_link_icon($url);
Fred Drakeef4d1112000-05-09 16:17:51 +00001913 return '<dl compact class="seeurl">'
1914 . "\n <dt><a href=\"$url\""
Fred Drake7a40c072000-10-02 14:43:38 +00001915 . "\n class=\"url\">$url$icon</a>"
Fred Drakeef4d1112000-05-09 16:17:51 +00001916 . "\n <dd>$text\n </dl>"
1917 . $_;
1918}
1919
Fred Drakea0f4c941998-07-24 22:16:04 +00001920sub do_cmd_seetext{
Fred Drake79189b51999-04-28 13:54:30 +00001921 local($_) = @_;
1922 my $content = next_argument();
Fred Drakee15956b2000-04-03 04:51:13 +00001923 return '<div class="seetext"><p>' . $content . '</div>' . $_;
Fred Drakea0f4c941998-07-24 22:16:04 +00001924}
1925
1926
1927#
Fred Drake885215c1998-05-20 21:32:09 +00001928# Definition list support.
1929#
1930
1931sub do_env_definitions{
Fred Drake49b33fa2002-11-15 19:04:10 +00001932 return "<dl class=\"definitions\">" . $_[0] . "</dl>\n";
Fred Drake885215c1998-05-20 21:32:09 +00001933}
1934
1935sub do_cmd_term{
1936 local($_) = @_;
Fred Drakeccc62721999-01-05 22:16:29 +00001937 my $term = next_argument();
Fred Drakef5478632002-05-23 17:59:16 +00001938 my($name, $aname, $ahref) = new_link_info();
Fred Drake885215c1998-05-20 21:32:09 +00001939 # could easily add an index entry here...
Fred Drake62e43691998-08-10 19:40:44 +00001940 return "<dt><b>$aname" . $term . "</a></b>\n<dd>" . $_;
Fred Drake885215c1998-05-20 21:32:09 +00001941}
1942
1943
Fred Drake38178fd2000-09-22 17:05:04 +00001944# I don't recall exactly why this was needed, but it was very much needed.
1945# We'll see if anything breaks when I move the "code" line out -- some
1946# things broke with it in.
1947
1948#code # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001949process_commands_wrap_deferred(<<_RAW_ARG_DEFERRED_CMDS_);
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001950declaremodule # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001951funcline # {} # {}
1952funclineni # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001953memberline # [] # {}
1954methodline # [] # {} # {}
Fred Drake44005092002-11-13 17:55:17 +00001955methodlineni # [] # {} # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001956modulesynopsis # {}
Fred Drake557460c1999-03-02 16:05:35 +00001957platform # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001958samp # {}
Fred Drake2e1ee3e1999-02-10 21:17:04 +00001959setindexsubitem # {}
Fred Drakef32834c1999-02-12 22:06:32 +00001960withsubitem # {} # {}
Fred Drake2ff880e1999-02-05 18:31:29 +00001961_RAW_ARG_DEFERRED_CMDS_
1962
1963
Fred Drake8a5e6792002-04-15 18:41:31 +00001964$alltt_start = '<div class="verbatim"><pre>';
1965$alltt_end = '</pre></div>';
Fred Drake86333602001-04-10 17:13:39 +00001966
Fred Drakef5478632002-05-23 17:59:16 +00001967sub do_env_alltt{
Fred Drake86333602001-04-10 17:13:39 +00001968 local ($_) = @_;
1969 local($closures,$reopens,@open_block_tags);
1970
1971 # get the tag-strings for all open tags
1972 local(@keep_open_tags) = @$open_tags_R;
1973 ($closures,$reopens) = &preserve_open_tags() if (@$open_tags_R);
1974
1975 # get the tags for text-level tags only
1976 $open_tags_R = [ @keep_open_tags ];
1977 local($local_closures, $local_reopens);
1978 ($local_closures, $local_reopens,@open_block_tags)
1979 = &preserve_open_block_tags
1980 if (@$open_tags_R);
1981
1982 $open_tags_R = [ @open_block_tags ];
1983
1984 do {
1985 local($open_tags_R) = [ @open_block_tags ];
1986 local(@save_open_tags) = ();
1987
1988 local($cnt) = ++$global{'max_id'};
1989 $_ = join('',"$O$cnt$C\\tt$O", ++$global{'max_id'}, $C
1990 , $_ , $O, $global{'max_id'}, "$C$O$cnt$C");
1991
1992 $_ = &translate_environments($_);
1993 $_ = &translate_commands($_) if (/\\/);
1994
1995 # preserve space-runs, using &nbsp;
1996 while (s/(\S) ( +)/$1$2;SPMnbsp;/g){};
1997 s/(<BR>) /$1;SPMnbsp;/g;
1998
1999 $_ = join('', $closures, $alltt_start, $local_reopens
2000 , $_
2001 , &balance_tags() #, $local_closures
2002 , $alltt_end, $reopens);
2003 undef $open_tags_R; undef @save_open_tags;
2004 };
2005 $open_tags_R = [ @keep_open_tags ];
2006 $_;
2007}
2008
Fred Drake6fc22f62002-06-17 15:01:05 +00002009# List of all filenames produced ny do_cmd_verbatiminput()
2010%VerbatimFiles = ();
2011@VerbatimOutputs = ();
2012
2013sub get_verbatim_output_name($){
Fred Drake49b33fa2002-11-15 19:04:10 +00002014 my $file = $_[0];
Fred Drake6fc22f62002-06-17 15:01:05 +00002015 #
2016 # Re-write the source filename to always use a .txt extension
2017 # so that Web servers will present it as text/plain. This is
2018 # needed since there is no other even moderately reliable way
2019 # to get the right Content-Type header on text files for
2020 # servers which we can't configure (like python.org mirrors).
2021 #
2022 if (defined $VerbatimFiles{$file}) {
2023 # We've seen this one before; re-use the same output file.
2024 return $VerbatimFiles{$file};
2025 }
Fred Drake49b33fa2002-11-15 19:04:10 +00002026 my($srcname, $srcdir, $srcext) = fileparse($file, '\..*');
Fred Drake6fc22f62002-06-17 15:01:05 +00002027 $filename = "$srcname.txt";
2028 #
2029 # We need to determine if our default filename is already
2030 # being used, and find a new one it it is. If the name is in
2031 # used, this algorithm will first attempt to include the
2032 # source extension as part of the name, and if that is also in
2033 # use (if the same file is included multiple times, or if
2034 # another source file has that as the base name), a counter is
2035 # used instead.
2036 #
2037 my $found = 1;
2038 FIND:
2039 while ($found) {
2040 foreach $fn (@VerbatimOutputs) {
2041 if ($fn eq $filename) {
2042 if ($found == 1) {
2043 $srcext =~ s/^[.]//; # Remove '.' from extension
2044 $filename = "$srcname-$srcext.txt";
2045 }
2046 else {
2047 $filename = "$srcname-$found.txt";
2048 }
2049 ++$found;
2050 next FIND;
2051 }
2052 }
2053 $found = 0;
2054 }
2055 push @VerbatimOutputs, $filename;
2056 $VerbatimFiles{$file} = $filename;
2057 return $filename;
2058}
2059
Fred Drake57e52ef2001-06-15 21:31:57 +00002060sub do_cmd_verbatiminput{
2061 local($_) = @_;
2062 my $fname = next_argument();
2063 my $file;
2064 my $found = 0;
2065 my $texpath;
2066 # Search TEXINPUTS for the input file, the way we're supposed to:
2067 foreach $texpath (split /$envkey/, $TEXINPUTS) {
2068 $file = "$texpath$dd$fname";
2069 last if ($found = (-f $file));
2070 }
Fred Drake6fc22f62002-06-17 15:01:05 +00002071 my $filename = '';
Fred Drake57e52ef2001-06-15 21:31:57 +00002072 my $text;
2073 if ($found) {
2074 open(MYFILE, "<$file") || die "\n$!\n";
2075 read(MYFILE, $text, 1024*1024);
2076 close(MYFILE);
Fred Drake6fc22f62002-06-17 15:01:05 +00002077 $filename = get_verbatim_output_name($file);
2078 # Now that we have a filename, write it out.
2079 open(MYFILE, ">$filename");
Fred Drake77602f22001-07-06 22:43:02 +00002080 print MYFILE $text;
2081 close(MYFILE);
Fred Drake57e52ef2001-06-15 21:31:57 +00002082 #
2083 # These rewrites convert the raw text to something that will
2084 # be properly visible as HTML and also will pass through the
2085 # vagaries of conversion through LaTeX2HTML. The order in
2086 # which the specific rewrites are performed is significant.
2087 #
2088 $text =~ s/\&/\&amp;/g;
2089 # These need to happen before the normal < and > re-writes,
2090 # since we need to avoid LaTeX2HTML's attempt to perform
2091 # ligature processing without regard to context (since it
2092 # doesn't have font information).
2093 $text =~ s/--/-&\#45;/g;
2094 $text =~ s/<</\&lt;\&\#60;/g;
2095 $text =~ s/>>/\&gt;\&\#62;/g;
2096 # Just normal re-writes...
2097 $text =~ s/</\&lt;/g;
2098 $text =~ s/>/\&gt;/g;
2099 # These last isn't needed for the HTML, but is needed to get
2100 # past LaTeX2HTML processing TeX macros. We use &#92; instead
2101 # of &sol; since many browsers don't support that.
2102 $text =~ s/\\/\&\#92;/g;
2103 }
2104 else {
Fred Drake6fc22f62002-06-17 15:01:05 +00002105 return '<b>Could not locate requested file <i>$fname</i>!</b>\n';
2106 }
2107 my $note = 'Download as text.';
2108 if ($file ne $filename) {
2109 $note = ('Download as text (original file name: <span class="file">'
2110 . $fname
2111 . '</span>).');
Fred Drake57e52ef2001-06-15 21:31:57 +00002112 }
Fred Drake8a5e6792002-04-15 18:41:31 +00002113 return ("<div class=\"verbatim\">\n<pre>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002114 . $text
Fred Drake8a5e6792002-04-15 18:41:31 +00002115 . "</pre>\n<div class=\"footer\">\n"
Fred Drake6fc22f62002-06-17 15:01:05 +00002116 . "<a href=\"$filename\" type=\"text/plain\""
2117 . ">$note</a>"
Fred Drake8a5e6792002-04-15 18:41:31 +00002118 . "\n</div></div>"
Fred Drake57e52ef2001-06-15 21:31:57 +00002119 . $_);
2120}
Fred Drake86333602001-04-10 17:13:39 +00002121
Fred Drake6659c301998-03-03 22:02:19 +000021221; # This must be the last line