[8e12a82] | 1 | #!/usr/bin/perl |
---|
[cfdba52] | 2 | # (Works with both perl 4 and perl 5) |
---|
[0bbbf52] | 3 | # |
---|
| 4 | # $Id$ |
---|
| 5 | # |
---|
| 6 | |
---|
[cfdba52] | 7 | $version = 'Jan 2 1996'; |
---|
| 8 | $copyright = <<EOT; |
---|
| 9 | texi2www - converts texinfo to HTML |
---|
| 10 | Copyright (C) 1994, 1995, 1996 Tim Singletary |
---|
| 11 | |
---|
| 12 | This program is freely distributable under the terms of the GNU |
---|
| 13 | GENERAL PUBLIC LICENSE. In particular, modified versions of this |
---|
| 14 | program must retain this copyright notice and must remain freely |
---|
| 15 | distributable. |
---|
| 16 | |
---|
| 17 | EOT |
---|
| 18 | $usage = <<EOT; |
---|
| 19 | Usage: texi2www [option ...] texinfo_file |
---|
| 20 | where options are: |
---|
| 21 | -dir directory -- Specify output directory. Default is `.'. |
---|
[05862b4] | 22 | -dirfile path -- Specifies a replacement for ../dir.html |
---|
[3ab325e] | 23 | -header path -- Specifies the path to a file containing HTML; |
---|
| 24 | this files gets inserted near the top of each |
---|
| 25 | generated HTML file. |
---|
[cfdba52] | 26 | -footer path -- Specifies the path to a file containing HTML; |
---|
| 27 | this files gets inserted near the bottom of each |
---|
| 28 | generated HTML file. |
---|
| 29 | -icons path -- Specifies the path, relative to the output directory, |
---|
| 30 | to the arrow files. Default is `..'. |
---|
[05862b4] | 31 | -base -- Specify the base part fo the genrated short file names |
---|
| 32 | -uselongnames -- Use long names for generated html files |
---|
[cfdba52] | 33 | -verbose -- Verbose output. |
---|
| 34 | |
---|
| 35 | The complete user\'s is available at |
---|
| 36 | http://sunland.gsfc.nasa.gov/info/texi2www/Top.html |
---|
| 37 | EOT |
---|
| 38 | |
---|
| 39 | ######################################################################## |
---|
| 40 | |
---|
[05862b4] | 41 | %lookup = (); # clear the name mapping hash |
---|
| 42 | $uselongnames=0; # default to using short names |
---|
| 43 | $base = "a"; # default short name base (BASEnnnnn.html) |
---|
| 44 | $outcount = 0; # count for the nnnnn part of short names |
---|
| 45 | $icons = ".."; # where are the icons |
---|
| 46 | $dir = "."; # where are the generated files to go |
---|
| 47 | $dirfile = "../dir.html"; # "up" node pointer |
---|
[cfdba52] | 48 | while ($ARGV[0] =~ /^-/) { |
---|
| 49 | $_ = shift; |
---|
[05862b4] | 50 | if (/-base/) {$base = shift; next;} |
---|
[3ab325e] | 51 | if (/-dirfile/) {$dirfile = shift; next;} |
---|
[cfdba52] | 52 | if (/-dir/) {$_ = shift; s!/$!!; s!$!/!; $dir = $_; next;} |
---|
| 53 | if (/-footer/) {$footer = shift; next;} |
---|
[3ab325e] | 54 | if (/-header/) {$header = shift; next;} |
---|
[cfdba52] | 55 | if (/-icons/) {$_ = shift; s!\/$!!; $icons = $_; next;} |
---|
[05862b4] | 56 | if (/-uselongnames/) {$uselongnames = 1; next;} |
---|
| 57 | if (/-verbose/) {$verbose = 1; next;} |
---|
[cfdba52] | 58 | die $usage; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | &initialize_tables(); |
---|
| 62 | |
---|
| 63 | # |
---|
| 64 | # Read the texinfo input into @texinfo |
---|
| 65 | # |
---|
| 66 | &open_input_file($ARGV[0]); |
---|
| 67 | &read_input(1,'/^\@bye/',"$texinfo_file[0] line 1"); |
---|
| 68 | $texinfo[$ntexinfo] = "\@bye\n"; |
---|
| 69 | $origin[$ntexinfo] = "$texinfo_file[0] line $."; |
---|
| 70 | |
---|
| 71 | # |
---|
| 72 | # Parse @texinfo |
---|
| 73 | # |
---|
| 74 | $texinfo_index = 0; |
---|
| 75 | while ($texinfo_index < @texinfo) { |
---|
| 76 | &get_more_stuff_to_parse(); |
---|
| 77 | if (/^\@bye/) { |
---|
| 78 | &terminate_node(); |
---|
| 79 | print "Normal completion\n"; |
---|
| 80 | exit; |
---|
| 81 | } |
---|
| 82 | &parse(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | print "Huh? didn't parse the \@bye directive!\n"; |
---|
| 86 | |
---|
| 87 | ######################################################################## |
---|
| 88 | sub canonical # (node_name) |
---|
| 89 | { |
---|
| 90 | local ($n) = @_; |
---|
| 91 | |
---|
| 92 | $n =~ s/^\s+//; $n =~ s/\s+$//; # strip whitespace |
---|
| 93 | |
---|
[3ab325e] | 94 | return "$dirfile" if ($n =~ /\(dir\)/i); # handle (dir) |
---|
[cfdba52] | 95 | |
---|
| 96 | if ($n =~ /^\(([^\)]+)\)(.*)/) { |
---|
| 97 | $p = $1; $p =~ s/^\s+//; $p =~ s/\s+$//; $p .= "/"; |
---|
| 98 | $n = $2; $n =~ s/^\s+//; $n =~ s/\s+$//; |
---|
| 99 | } else { |
---|
| 100 | $p = ""; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | $n =~ s/\$/\$\$/; # `$' -> `$$' |
---|
| 105 | $n =~ s/_/\$_/g; # `_' -> `$_' |
---|
| 106 | $n =~ s/\s+/_/g; # whitespace -> `_' |
---|
| 107 | |
---|
| 108 | # anything else that's funky get |
---|
| 109 | # translated to `$xx' where `xx' |
---|
| 110 | # are hex digits. |
---|
| 111 | while ($n =~ /(.*)([^-a-zA-Z0-9\$_.])(.*)/) { |
---|
| 112 | $n = $1 . sprintf("\$%02x",ord($2)) . $3; |
---|
| 113 | } |
---|
| 114 | |
---|
[05862b4] | 115 | if ($uselongnames) { |
---|
| 116 | return "$p$n.html" if ($n); |
---|
| 117 | } else { |
---|
| 118 | if ($n eq 'Top') { |
---|
| 119 | $lookup{"$p$n"}= "Top.html"; |
---|
| 120 | return $lookup{"$p$n"}; |
---|
| 121 | } elsif ($n) { |
---|
| 122 | if (! $lookup{"$p$n"}) { |
---|
| 123 | $outcount = $outcount + 1; |
---|
| 124 | #$lookup{"$p$n"}= "$base$outcount.html"; |
---|
| 125 | $lookup{"$p$n"} = sprintf "%s%05d.html", $base, $outcount; |
---|
| 126 | } |
---|
| 127 | return $lookup{"$p$n"}; |
---|
| 128 | } |
---|
| 129 | } |
---|
[cfdba52] | 130 | return ""; |
---|
| 131 | } # canonical |
---|
| 132 | |
---|
| 133 | ######################################################################## |
---|
| 134 | sub deduce_node_links |
---|
| 135 | # |
---|
| 136 | # On entry, $_ is a node line and $start_index is the index (in @texinfo) |
---|
| 137 | # the node line. |
---|
| 138 | # |
---|
| 139 | # &deduce_node_links() sets $next, $prev, and $up. |
---|
| 140 | { |
---|
| 141 | local ($level,$i,$node,$j); |
---|
| 142 | |
---|
| 143 | # First, search down from this node to the next sectioning command. |
---|
| 144 | $level = &determine_node_level($start_index+1); |
---|
| 145 | |
---|
| 146 | # Next, look for the `next' node (i.e., the next node at the |
---|
| 147 | # same or a higher level). |
---|
| 148 | undef($next); |
---|
| 149 | for ($i=$start_index+1; $i < $ntexinfo; ++$i) { |
---|
| 150 | $_ = $texinfo[$i]; |
---|
| 151 | next unless /^\@node +([^,]+).*\n/; |
---|
| 152 | $j = &determine_node_level($i+1); |
---|
| 153 | if ($j <= $level) { |
---|
| 154 | if ($j == $level) {$next = $1;} |
---|
| 155 | last; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | # Look for the `prev' and `up' nodes |
---|
| 160 | undef($prev); |
---|
| 161 | undef($up); |
---|
| 162 | for ($i=$start_index-1; $i > 1; --$i) { |
---|
| 163 | $_ = $texinfo[$i]; |
---|
| 164 | next unless /^\@node\s+([^,]+).*\n/; |
---|
| 165 | $j = &determine_node_level($i+1); |
---|
| 166 | if ($j == $level) { |
---|
| 167 | unless ($prev) {$prev = $1;} |
---|
| 168 | } elsif ($j < $level) { |
---|
| 169 | $up = $1; |
---|
| 170 | last; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | unless (defined($up)) {$up = "(dir)";} |
---|
| 174 | |
---|
| 175 | $xthis = $this; |
---|
| 176 | $xthis =~ s/\n//; |
---|
| 177 | |
---|
| 178 | } # deduce_node_links |
---|
| 179 | |
---|
| 180 | ######################################################################## |
---|
| 181 | sub determine_node_level |
---|
| 182 | { |
---|
| 183 | local ($i) = @_; |
---|
| 184 | local ($level); |
---|
| 185 | |
---|
| 186 | $level = 0; |
---|
| 187 | while ($i < $ntexinfo) { |
---|
| 188 | $_ = $texinfo[$i]; |
---|
| 189 | ++$i; |
---|
| 190 | next if /^\s+$/; |
---|
| 191 | last if (/\@node/); |
---|
| 192 | last unless (/\@(\w+)/); |
---|
| 193 | if ($directive_section{$1}) { |
---|
| 194 | $level = $directive_section{$1}; |
---|
| 195 | last; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | return $level; |
---|
| 200 | } # determine_node_level |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | ######################################################################## |
---|
| 204 | sub expand_xref |
---|
| 205 | { |
---|
| 206 | local ($cmd,$arg) = @_; |
---|
| 207 | local ($node,$xrefname,$topic,$infofile,$manual,$url,$x); |
---|
| 208 | |
---|
| 209 | if ($cmd eq 'inforef') { |
---|
| 210 | ($node,$xrefname,$infofile) = split(/,/,$arg); |
---|
| 211 | $topic = $manual = ''; |
---|
| 212 | } elsif ($cmd eq 'href') { |
---|
| 213 | ($xrefname,$node,$infofile,$url) = split(/,/,$arg); |
---|
| 214 | } else { |
---|
| 215 | ($node,$xrefname,$topic,$infofile,$manual) = split(/,/,$arg); |
---|
| 216 | } |
---|
| 217 | $xrefname =~ s/^\s+//; $infofile =~ s/^\s+//; |
---|
| 218 | $xrefname =~ s/\s+$//; $infofile =~ s/\s+$//; |
---|
| 219 | $xrefname =~ s/\s+/ /; $infofile =~ s/\s+/ /; |
---|
| 220 | $infofile =~ s/\.texi$//; |
---|
| 221 | $infofile =~ s/\.texinfo$//; |
---|
| 222 | |
---|
| 223 | if ($xrefname =~ /^$/) {$xrefname = $node;} |
---|
| 224 | |
---|
| 225 | $node = &canonical($node); |
---|
| 226 | unless ($url) { |
---|
| 227 | unless ($infofile =~ /^$/) {$url = "../$infofile/";} |
---|
| 228 | $url = $url . $node; |
---|
| 229 | } |
---|
| 230 | $x = "<A HREF=\"$url\">$xrefname</A>"; |
---|
| 231 | } # expand_xref |
---|
| 232 | |
---|
| 233 | ######################################################################## |
---|
| 234 | sub get_more_stuff_to_parse |
---|
| 235 | { |
---|
| 236 | $start_index = $texinfo_index; |
---|
| 237 | |
---|
| 238 | $_ = ''; |
---|
| 239 | do { |
---|
| 240 | if ($texinfo_index >= @texinfo) { |
---|
| 241 | print "Unclosed \@x{y} in chunk beginning at " |
---|
| 242 | . "$origin[$start_index]\n"; |
---|
| 243 | return; |
---|
| 244 | } |
---|
| 245 | s/\n$/ /; |
---|
| 246 | $more = $texinfo[$texinfo_index++]; |
---|
| 247 | $more =~ s/\@\*/<BR>\n/g; |
---|
| 248 | $more =~ s/\@\./\./g; |
---|
| 249 | $more =~ s/\@\://g; |
---|
| 250 | $more =~ s/\@refill//g; |
---|
| 251 | |
---|
| 252 | $_ .= $more; |
---|
| 253 | |
---|
| 254 | # Expand all @a{b} in line |
---|
| 255 | while (/\@(\w+)\{([^{}]*)\}/) { |
---|
| 256 | $atcmd = $1; |
---|
| 257 | $atarg = $2; |
---|
| 258 | |
---|
| 259 | if ($z = $atxy_2_zyz{$atcmd}) { |
---|
| 260 | if ($z =~ /(.+),(.+),(.+)/) { |
---|
| 261 | $left = $1; $z = $2; $right = $3; |
---|
| 262 | } else { |
---|
| 263 | $left = ''; $right = ''; |
---|
| 264 | } |
---|
| 265 | if ($z =~ s/^\^//) {$atarg =~ tr/a-z/A-Z/;} |
---|
| 266 | $x = "$left<$z>$atarg</$z>$right"; |
---|
| 267 | } elsif ($atxy_2_y{$atcmd}) { |
---|
| 268 | $x = $atarg; |
---|
| 269 | } elsif ($z = $atxy_2_z{$atcmd}) { |
---|
| 270 | $x = $z; |
---|
| 271 | } elsif ($z = $atxy_2_ref{$atcmd}) { |
---|
| 272 | $x = $z . &expand_xref($atcmd,$atarg); |
---|
| 273 | $x =~ s/^X//; # works because $z must start with 'X'! |
---|
| 274 | } elsif ($atcmd eq 'value') { |
---|
| 275 | $x = $texinfo_variable{$atarg}; |
---|
| 276 | } elsif ($atcmd eq 'today') { |
---|
| 277 | $x = &today(); |
---|
| 278 | } elsif ($atcmd eq 'footnote') { |
---|
| 279 | $footnote[$nfootnotes++] = $atarg; |
---|
| 280 | $x = "\[$nfootnotes\]"; |
---|
| 281 | } elsif ($atcmd eq 'gif') { |
---|
| 282 | $atarg =~ s/,.*//; |
---|
| 283 | ©_to_destdir($atarg); |
---|
| 284 | $atarg =~ s|.*/||; |
---|
| 285 | $x = "<IMG SRC=\"$atarg\">"; |
---|
| 286 | } else { |
---|
| 287 | print "**WARNING** Don't know how to expand " |
---|
| 288 | . "\@$atcmd\{$atarg\}\n"; |
---|
| 289 | $debug = 1; |
---|
| 290 | $x = "?$atcmd\?$atarg\?"; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | print "$origin[$start_index]: \@$atcmd\{$atarg\} => $x\n" |
---|
| 294 | if $debug{expansions}; |
---|
| 295 | |
---|
| 296 | s/\@\w+\{[^{}]*\}/$x/; |
---|
| 297 | } |
---|
| 298 | } while (/\@\w+\{[^}]*$/); |
---|
| 299 | print "$origin[$start_index]: $_" if $debug{chunks}; |
---|
| 300 | } # get_more_stuff_to_parse |
---|
| 301 | |
---|
| 302 | ######################################################################## |
---|
| 303 | sub parse |
---|
| 304 | # On entry: |
---|
| 305 | # $_ -- the line(s) to parse. |
---|
| 306 | # $start_index -- where, in $texinfo, $_ begins. |
---|
| 307 | { |
---|
| 308 | local ($x); |
---|
| 309 | |
---|
| 310 | if (/^\@(\w+)/) { |
---|
| 311 | if ($x=$directive_block{$1}) { # @example, @quotation, etc. |
---|
| 312 | &parse_block($1,$x); |
---|
| 313 | } elsif ($directive_section{$1}) { # @chapter, @subsection, etc. |
---|
| 314 | &process_section(); |
---|
| 315 | } elsif ($1 eq 'bye') { |
---|
| 316 | if ($nfootnotes > 0) { |
---|
| 317 | &printHTML("<P><HR>\n"); |
---|
| 318 | for ($n=0; $n < $nfootnotes; ++$n) { |
---|
| 319 | &printHTML("<P>\[" . ($n+1) . "\] $footnote[$n]</P>\n"); |
---|
| 320 | } |
---|
| 321 | } |
---|
[0a46c6d] | 322 | &printHTML("<P><HR>\n"); |
---|
| 323 | &print_arrows; |
---|
| 324 | &printHTML("</P>\n"); |
---|
[cfdba52] | 325 | &print_footer if $footer; |
---|
| 326 | &printHTML("</BODY></HTML>\n"); |
---|
| 327 | close (HTML); |
---|
| 328 | return; |
---|
| 329 | } elsif ($1 eq 'center') { |
---|
| 330 | /^\@center\s+(.*)/; |
---|
| 331 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 332 | &printHTML("<P ALIGN=CENTER>$1</P>\n"); |
---|
| 333 | $in_paragraph = 0; |
---|
| 334 | } elsif ($1 eq 'clear') { |
---|
| 335 | /^\@clear\s+(\S+)/; |
---|
| 336 | undef($texinfo_variable{$1}); |
---|
| 337 | } elsif ($1 =~ /^def(code)?index/) { |
---|
| 338 | /^\@(def|defcode)index\s+(\w+)/; |
---|
| 339 | $index_name{$2} = $2 . "index"; |
---|
| 340 | $index_style{$2} = 'CODE' if ($1 eq "defcode"); |
---|
| 341 | } elsif ($1 =~ /^(def.*)/) { # @defn, @defun, ... @deftp |
---|
| 342 | &parse_def($1); |
---|
| 343 | } elsif ($1 eq 'enumerate') { |
---|
| 344 | &parse_enumerate(); |
---|
| 345 | } elsif ($1 eq 'exdent') { |
---|
| 346 | /^\@exdent\s+(.*)/; |
---|
| 347 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 348 | # A bug -- doesn't exdent the line! |
---|
| 349 | &printHTML("<P>$1</P>\n"); |
---|
| 350 | $in_paragraph = 0; |
---|
| 351 | } elsif ($1 eq 'flushleft' || $1 eq 'flushright') { |
---|
| 352 | &parse_flush(); |
---|
| 353 | } elsif ($1 eq 'html') { |
---|
| 354 | while ($texinfo_index < @texinfo) { |
---|
| 355 | &get_more_stuff_to_parse(); |
---|
| 356 | last if (/^\@end\s+html/); |
---|
| 357 | s/\"/\"/g; s/\>/\>/g; s/\</\</g; s/\&/\&/g; |
---|
| 358 | &printHTML("$_"); |
---|
| 359 | } |
---|
| 360 | } elsif ($1 eq 'itemize') { |
---|
| 361 | &parse_itemize(); |
---|
| 362 | } elsif ($1 eq 'menu') { |
---|
| 363 | &parse_menu(); |
---|
| 364 | } elsif ($1 eq 'node') { |
---|
[0a46c6d] | 365 | $node=$_; |
---|
[cfdba52] | 366 | &process_node(); |
---|
| 367 | } elsif ($1 eq 'printindex') { |
---|
| 368 | /^\@printindex\s+([a-z]+)/; |
---|
| 369 | &print_index($1); |
---|
| 370 | } elsif ($1 eq 'settitle') { |
---|
| 371 | /^\@settitle\s+(.*)/; |
---|
| 372 | unless ($title) {$title = $1;} |
---|
| 373 | } elsif ($1 eq 'set') { |
---|
| 374 | if (/^\@set\s+(\S+)\s+(.+)$/) { |
---|
| 375 | $texinfo_variable{$1} = $2; |
---|
| 376 | } else { |
---|
| 377 | /^\@set\s+(\S+)/; |
---|
| 378 | $texinfo_variable{$1} = 1; |
---|
| 379 | } |
---|
| 380 | } elsif ($1 eq 'syncodeindex') { |
---|
| 381 | &process_synindex(1); |
---|
| 382 | } elsif ($1 eq 'synindex') { |
---|
| 383 | &process_synindex(0); |
---|
| 384 | } elsif ($1 =~ /^.?table/) { # @table, @vtable, @ftable |
---|
| 385 | unless (/^\@(.?table)\s*\@(\w*)/ |
---|
| 386 | && ($2 eq 'asis' || ($tbltype=$atxy_2_zyz{$2}))) { |
---|
| 387 | print "**WARNING** $origin[$start_index]: assuming " |
---|
| 388 | . "\@table \@asis\n"; |
---|
| 389 | $tbltype = ''; |
---|
| 390 | } |
---|
| 391 | &parse_table($1,$tbltype); |
---|
| 392 | } elsif ($1 =~ /..?index/) { # @cindex, @findex, .. @auindex, etc. |
---|
| 393 | &process_index(); |
---|
| 394 | } else { |
---|
| 395 | print "**WARNING** $origin[$start_index]: ignoring $_"; |
---|
| 396 | } |
---|
| 397 | } else { |
---|
| 398 | if (/^\s*$/) { |
---|
| 399 | if ($in_paragraph) { |
---|
| 400 | &printHTML("$paragraph_end"); |
---|
| 401 | } elsif ($in_preformatted) { |
---|
| 402 | &printHTML("\n"); |
---|
| 403 | } |
---|
| 404 | $in_paragraph = 0; |
---|
| 405 | } else { |
---|
| 406 | unless ($in_preformatted) { |
---|
| 407 | unless ($in_paragraph) { |
---|
| 408 | &printHTML("<P>\n"); |
---|
| 409 | $in_paragraph = 1; |
---|
| 410 | $paragraph_end = "</P>\n"; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | &printHTML("$_"); |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | } # parse |
---|
| 417 | |
---|
| 418 | ######################################################################## |
---|
| 419 | sub parse_block |
---|
| 420 | # |
---|
| 421 | # Handles @example, @display, etc. |
---|
| 422 | # |
---|
| 423 | # > @example > <PRE> |
---|
| 424 | # > a + b = c ==> > a + b = c |
---|
| 425 | # > @end example > </PRE> |
---|
| 426 | { |
---|
| 427 | local ($block,$pre) = @_; |
---|
| 428 | local ($started_at); |
---|
| 429 | |
---|
| 430 | $started_at = $start_index; |
---|
| 431 | |
---|
| 432 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 433 | $in_paragraph = 0; |
---|
| 434 | |
---|
| 435 | if ($pre eq '>PRE') { |
---|
| 436 | &printHTML("<DL><DT><DD>\n<PRE>\n"); |
---|
| 437 | } else { |
---|
| 438 | &printHTML("<$pre>\n") unless ($pre eq '-'); |
---|
| 439 | } |
---|
| 440 | $in_preformatted = $block; |
---|
| 441 | while ($texinfo_index < @texinfo) { |
---|
| 442 | &get_more_stuff_to_parse(); |
---|
| 443 | if (/^\@end\s+$block/) { |
---|
| 444 | if ($pre eq 'HR') { |
---|
| 445 | &printHTML("</HR>\n"); |
---|
| 446 | } elsif ($pre eq '>PRE') { |
---|
| 447 | &printHTML("</PRE>\n</DL>\n"); |
---|
| 448 | } else { |
---|
| 449 | &printHTML("</$pre>\n") unless ($pre eq '-'); |
---|
| 450 | } |
---|
| 451 | $in_preformatted = 0; |
---|
| 452 | return; |
---|
| 453 | } |
---|
| 454 | &parse(); |
---|
| 455 | } |
---|
| 456 | print "**ERROR** reached EOF while searching for end of the \@$block " |
---|
| 457 | . "block that started on $origin[$started_at]\n"; |
---|
| 458 | } # parse_block |
---|
| 459 | |
---|
| 460 | ######################################################################## |
---|
| 461 | sub parse_def |
---|
| 462 | # $_ contains a @def* command |
---|
| 463 | { |
---|
| 464 | local ($def) = @_; |
---|
| 465 | local ($started_at,$in_dd); |
---|
| 466 | |
---|
| 467 | $started_at = $start_index; |
---|
| 468 | |
---|
| 469 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 470 | $in_paragraph = 0; |
---|
| 471 | |
---|
| 472 | &printHTML("<DL>\n"); |
---|
| 473 | |
---|
| 474 | &printdef(); |
---|
| 475 | |
---|
| 476 | while ($texinfo_index < @texinfo) { |
---|
| 477 | &get_more_stuff_to_parse(); |
---|
| 478 | if (/^\@end\s+$def/) { |
---|
| 479 | &printHTML("</DL>\n"); |
---|
| 480 | $in_paragraph = 0; |
---|
| 481 | return; |
---|
| 482 | } |
---|
| 483 | if (s/^(\@def\w+)x\s/$1 /) {&printdef();} |
---|
| 484 | else { |
---|
| 485 | unless ($in_dd) { |
---|
| 486 | &printHTML("<DD>\n"); |
---|
| 487 | ++$in_dd; |
---|
| 488 | $in_paragraph = 1; |
---|
| 489 | $paragraph_end = "\n"; |
---|
| 490 | } |
---|
| 491 | &parse(); |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | print "**ERROR** reached EOF while searching for end of the $def " |
---|
| 495 | . "definition that started on $origin[$started_at]\n"; |
---|
| 496 | |
---|
| 497 | } # parse_def |
---|
| 498 | sub printdef |
---|
| 499 | { |
---|
| 500 | |
---|
| 501 | s/\@defun(x?)\s/\@deffn Function / |
---|
| 502 | || s/\@defmac(x?)\s/\@deffn Macro / |
---|
| 503 | || s/\@defspec(x?)\s/\@deffn \{Special Form\} / |
---|
| 504 | || s/\@defvar(x?)\s/\@defvr Variable / |
---|
| 505 | || s/\@defopt(x?)\s/\@defvr \{User Option\} / |
---|
| 506 | || s/\@deftypefun(x?)\s/\@deftypefn Function / |
---|
| 507 | || s/\@deftypevar(x?)\s/\@deftypefn Variable / |
---|
| 508 | || s/\@defivar(x?)\s/\@defcv \{Instance Variable\} / |
---|
| 509 | || s/\@defmethod(x?)\s/\@defop Method /; |
---|
| 510 | s/(\@\w+)x\s/$1 /; |
---|
| 511 | |
---|
| 512 | @words = split; |
---|
| 513 | |
---|
| 514 | $i = 1; |
---|
| 515 | $category = $words[$i++]; |
---|
| 516 | while ($i < @words && $category =~ /^\{[^}]*$/) { |
---|
| 517 | $category .= ' ' . $words[$i++]; |
---|
| 518 | } |
---|
| 519 | if ($i>=@words) { |
---|
| 520 | print "def error at $origin{$started_at}\n"; |
---|
| 521 | } |
---|
| 522 | $category =~ s/^\{//; |
---|
| 523 | $category =~ s/\}$//; |
---|
| 524 | |
---|
| 525 | &printHTML("<DT>$category: "); |
---|
| 526 | |
---|
| 527 | if ($words[0] eq '@deftypefn' || $words[0] eq '@deftypevr' |
---|
| 528 | || $words[0] eq '@defcv' || $words[0] eq '@defop') { |
---|
| 529 | if ($words[$i] =~ s/^\{//) { |
---|
| 530 | &printHTML("<VAR>"); |
---|
| 531 | until ($words[$i] =~ s/\}$//) {&printHTML("$words[$i++]");} |
---|
| 532 | &printHTML("$words[$i++]</VAR> "); |
---|
| 533 | } else { |
---|
| 534 | &printHTML("<VAR>$words[$i++]</VAR> "); |
---|
| 535 | } |
---|
| 536 | $words[0] =~ /.*([a-z][a-z])/; |
---|
| 537 | $_ = "\@" . $1 . "index " . $words[$i]; |
---|
| 538 | &process_index; |
---|
| 539 | } |
---|
| 540 | &printHTML("<STRONG>$words[$i++]</STRONG>\n<VAR>"); |
---|
| 541 | |
---|
| 542 | while ($i < @words) {&printHTML(" $words[$i++]");} |
---|
| 543 | &printHTML("</VAR>\n"); |
---|
| 544 | |
---|
| 545 | } # printdef |
---|
| 546 | |
---|
| 547 | ######################################################################## |
---|
| 548 | sub parse_enumerate |
---|
| 549 | # $_ is `@enumerate'. Note that @enumerate with an arg (`@enumerate 3', |
---|
| 550 | # for example) is kinda funky due to HTML limitations. |
---|
| 551 | { |
---|
| 552 | local ($count,$started_at); |
---|
| 553 | |
---|
| 554 | $started_at = $start_index; |
---|
| 555 | |
---|
| 556 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 557 | $in_paragraph = 0; |
---|
| 558 | |
---|
| 559 | if (/^\@enumerate\s*(\S+)/) {$count = $1;} |
---|
| 560 | |
---|
| 561 | &printHTML("<" . ($count ? "UL" : "OL") . ">\n"); |
---|
| 562 | |
---|
| 563 | while ($texinfo_index < @texinfo) { |
---|
| 564 | &get_more_stuff_to_parse(); |
---|
| 565 | if (/^\@end\s+enumerate/) { |
---|
| 566 | &printHTML("</" . ($count ? "UL" : "OL") . ">\n"); |
---|
| 567 | return; |
---|
| 568 | } |
---|
| 569 | if (/^\@item\s+(.*)/ || /^\@item()$/) { |
---|
| 570 | if ($count) { |
---|
| 571 | &printHTML("<LI>$count: $1\n"); |
---|
| 572 | ++$count; |
---|
| 573 | } else { |
---|
| 574 | &printHTML("<LI>$1\n"); |
---|
| 575 | } |
---|
| 576 | $in_paragraph = 1; |
---|
| 577 | $paragraph_end = "\n"; |
---|
| 578 | } else { |
---|
| 579 | &parse(); |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | print "**ERROR** reached EOF while searching for end of the \@enumerate " |
---|
| 583 | . "that started on $origin[$started_at]\n"; |
---|
| 584 | } # parse_enumerate |
---|
| 585 | |
---|
| 586 | ######################################################################## |
---|
| 587 | sub parse_flush |
---|
| 588 | { |
---|
| 589 | local ($started_at,$flush); |
---|
| 590 | |
---|
| 591 | /^\@(\w+)\s/; |
---|
| 592 | $flush = $1; |
---|
| 593 | $started_at = $start_index; |
---|
| 594 | |
---|
| 595 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 596 | $in_paragraph = 0; |
---|
| 597 | |
---|
| 598 | while ($texinfo_index < @texinfo) { |
---|
| 599 | &get_more_stuff_to_parse(); |
---|
| 600 | if (/^\@end\s+$flush/) { |
---|
| 601 | return; |
---|
| 602 | } |
---|
| 603 | &parse(); |
---|
| 604 | } |
---|
| 605 | print "**ERROR** reached EOF while searching for end of the $flush " |
---|
| 606 | . "that started on $origin[$started_at]\n"; |
---|
| 607 | |
---|
| 608 | |
---|
| 609 | } # parse_flush |
---|
| 610 | |
---|
| 611 | ######################################################################## |
---|
| 612 | sub parse_itemize |
---|
| 613 | # $_ is `@itemize'. Due to HTML limitation, `@itemize @bullet' comes |
---|
| 614 | # out the same as `@itemize @minus'. |
---|
| 615 | { |
---|
| 616 | local ($started_at); |
---|
| 617 | |
---|
| 618 | $started_at = $start_index; |
---|
| 619 | |
---|
| 620 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 621 | $in_paragraph = 0; |
---|
| 622 | |
---|
| 623 | &printHTML("<UL>\n"); |
---|
| 624 | |
---|
| 625 | |
---|
| 626 | while ($texinfo_index < @texinfo) { |
---|
| 627 | &get_more_stuff_to_parse(); |
---|
| 628 | if (/^\@end\s+itemize/) { |
---|
| 629 | &printHTML("</UL>\n"); |
---|
| 630 | return; |
---|
| 631 | } |
---|
| 632 | if (/^\@item\s+(.*)/ || /^\@item()$/) { |
---|
| 633 | &printHTML("<LI>$1\n"); |
---|
| 634 | $in_paragraph = 1; |
---|
| 635 | $paragraph_end = "\n"; |
---|
| 636 | } else { |
---|
| 637 | &parse(); |
---|
| 638 | } |
---|
| 639 | } |
---|
| 640 | print "**ERROR** reached EOF while searching for end of the itemize " |
---|
| 641 | . "that started on $origin[$started_at]\n"; |
---|
| 642 | } # parse_itemize |
---|
| 643 | |
---|
| 644 | ######################################################################## |
---|
| 645 | sub parse_menu |
---|
| 646 | { |
---|
| 647 | local ($started_at); |
---|
| 648 | |
---|
| 649 | $started_at = $start_index; |
---|
| 650 | |
---|
| 651 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 652 | $in_paragraph = 0; |
---|
| 653 | |
---|
| 654 | &printHTML("<MENU>\n"); |
---|
| 655 | |
---|
| 656 | while ($texinfo_index < @texinfo) { |
---|
| 657 | &get_more_stuff_to_parse(); |
---|
| 658 | if (/^\@end\s+menu/) { |
---|
| 659 | &printHTML("</MENU>\n"); |
---|
| 660 | return; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | # Like ` * menu-item:: description of item' |
---|
| 664 | if (/^\s*\*\s*([^:]*)\s*::\s*(.*)$/) { |
---|
| 665 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 666 | $in_paragraph = 0; |
---|
| 667 | $node = &canonical($1); |
---|
| 668 | &printHTML("<LI><A HREF=\"$node\">$1</A>\n"); |
---|
| 669 | &printHTML("$2\n") if $2; |
---|
| 670 | # Like ` * menu-item: cross-reference. description of item' |
---|
| 671 | } elsif (/^\s*\*\s*([^:]*)\s*:([^.]*)\.\s*(.*)$/) { |
---|
| 672 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 673 | $in_paragraph = 0; |
---|
| 674 | $node = &canonical($2); |
---|
| 675 | &printHTML("<LI><A HREF=\"$node\">$1</A>\n"); |
---|
| 676 | &printHTML("$3\n"); |
---|
| 677 | } elsif (/^\@/) { |
---|
| 678 | print "**WARNING** Don\'t know how to process \`$_\' inside " |
---|
| 679 | . "a menu!\n"; |
---|
| 680 | } else { |
---|
| 681 | if (/^\s*$/ && !$in_paragraph) { |
---|
| 682 | &printHTML("<P>"); |
---|
| 683 | $in_paragraph = "1"; |
---|
| 684 | $paragraph_end = "</P>\n"; |
---|
| 685 | } |
---|
| 686 | &printHTML("$_"); |
---|
| 687 | } |
---|
| 688 | } |
---|
| 689 | print "**ERROR** reached EOF while searching for end of the menu " |
---|
| 690 | . "that started on $origin[$started_at]\n"; |
---|
| 691 | } # parse_menu |
---|
| 692 | |
---|
| 693 | ######################################################################## |
---|
| 694 | sub parse_table |
---|
| 695 | # $_ is `@itemize'. Due to HTML limitation, `@itemize @bullet' comes |
---|
| 696 | # out the same as `@itemize @minus'. |
---|
| 697 | { |
---|
| 698 | local ($table,$ttype,$after_DT,$started_at,$first_para); |
---|
| 699 | ($table,$ttype) = @_; |
---|
| 700 | |
---|
| 701 | $started_at = $start_index; |
---|
| 702 | |
---|
| 703 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 704 | $in_paragraph = 0; |
---|
| 705 | |
---|
| 706 | &printHTML("<DL>\n"); |
---|
| 707 | |
---|
| 708 | while ($texinfo_index < @texinfo) { |
---|
| 709 | &get_more_stuff_to_parse(); |
---|
| 710 | if (/^\@end\s+$table/) { |
---|
| 711 | &printHTML("</DL>\n"); |
---|
| 712 | return; |
---|
| 713 | } |
---|
| 714 | if (/^\@item(x?)\s+(.*)/ || /^\@item(x?)()$/) { |
---|
| 715 | $atarg = $2; |
---|
| 716 | if ($ttype) { |
---|
| 717 | if ($ttype =~ /(.+),(.+),(.+)/) { |
---|
| 718 | $left = $1; $z = $2; $right = $3; |
---|
| 719 | } else { |
---|
| 720 | $left = ''; $z = $ttype; $right = ''; |
---|
| 721 | } |
---|
| 722 | if ($z =~ s/^\^//) {$atarg =~ tr/a-z/A-Z/;} |
---|
| 723 | &printHTML("<DT>$left<$z>$atarg</$z>$right\n"); |
---|
| 724 | } else { |
---|
| 725 | &printHTML("<DT>$2\n"); |
---|
| 726 | } |
---|
| 727 | $item = $2; |
---|
| 728 | if ($item && $table =~ /([fv])table/) { |
---|
| 729 | $_ = "\@" . $1 . "index " . $item; |
---|
| 730 | &process_index; |
---|
| 731 | } |
---|
| 732 | $after_DT = 1; |
---|
| 733 | } else { |
---|
| 734 | if ($after_DT) { |
---|
| 735 | &printHTML("<DD>\n"); |
---|
| 736 | $in_paragraph = 1; |
---|
| 737 | $paragraph_end = "\n"; |
---|
| 738 | $after_DT = 0; |
---|
| 739 | $first_para = 1; |
---|
| 740 | } |
---|
| 741 | unless ($first_para && /^\s*$/) { |
---|
| 742 | $first_para = 0; |
---|
| 743 | &parse(); |
---|
| 744 | } |
---|
| 745 | } |
---|
| 746 | } |
---|
| 747 | print "**ERROR** reached EOF while searching for end of the table " |
---|
| 748 | . "that started on $origin[$started_at]\n"; |
---|
| 749 | } # parse_table |
---|
| 750 | |
---|
| 751 | ######################################################################## |
---|
| 752 | sub print_index |
---|
| 753 | { |
---|
| 754 | local ($index) = @_; |
---|
| 755 | $index = $index_name{$index}; |
---|
| 756 | |
---|
| 757 | eval "\@keys = keys \%$index"; |
---|
| 758 | |
---|
| 759 | &printHTML("<MENU>\n"); |
---|
| 760 | foreach $item (sort texinfo_sort @keys) { |
---|
| 761 | eval "\$val = \$$index\{\$item\}"; |
---|
| 762 | &printHTML("<LI>$val\n"); |
---|
| 763 | } |
---|
| 764 | &printHTML("</MENU>\n"); |
---|
| 765 | } # print_index |
---|
| 766 | |
---|
| 767 | sub texinfo_sort |
---|
| 768 | { |
---|
| 769 | $x = $a; $x =~ s/<[^>]*>//g; $x =~ tr/A-Z/a-z/; |
---|
| 770 | $y = $b; $y =~ s/<[^>]*>//g; $y =~ tr/A-Z/a-z/; |
---|
| 771 | $x cmp $y; |
---|
| 772 | } # texinfo_sort |
---|
| 773 | |
---|
| 774 | ######################################################################## |
---|
| 775 | sub process_index |
---|
| 776 | # |
---|
| 777 | # For example, `@cindex whatever' generates an entry in %cpindex |
---|
| 778 | # |
---|
| 779 | { |
---|
| 780 | s/\@cindex/\@cpindex/ || s/\@findex/\@fnindex/ |
---|
| 781 | || s/\@vindex/\@vrindex/ || s/\@kindex/\@kyindex/ |
---|
| 782 | || s/\@pindex/\@pgindex/ || s/\@tindex/\@tpindex/; |
---|
| 783 | |
---|
| 784 | /\@(..)index\s+(.*)/; |
---|
| 785 | |
---|
| 786 | if ($x=$index_style{$1}) { |
---|
| 787 | $entry = "<A HREF=\"$cthis\"><$x>$2</$x></A>"; |
---|
| 788 | } else { |
---|
| 789 | $entry = "<A HREF=\"$cthis\">$2</A>"; |
---|
| 790 | } |
---|
| 791 | |
---|
| 792 | print "*** \$$index_name{$1}\{$2\} = $entry\n" if $debug{'index'}; |
---|
| 793 | eval "\$$index_name{$1}\{\$2\} = \$entry"; |
---|
| 794 | } # process_index |
---|
| 795 | |
---|
[0a46c6d] | 796 | ######################################################################## |
---|
| 797 | sub print_arrows |
---|
| 798 | { |
---|
| 799 | &printHTML("<LINK REL=\"Precedes\" HREF=\"$cnext\">\n") if $next; |
---|
| 800 | &printHTML("<LINK REV=\"Precedes\" HREF=\"$cprev\">\n") if $prev; |
---|
| 801 | &printHTML("<LINK REV=\"Subdocument\" HREF=\"$cup\">\n") if $up; |
---|
[05862b4] | 802 | &printHTML("<LINK REV=\"Library\" HREF=\"$dirfile\">\n") if $dirfile; |
---|
[0a46c6d] | 803 | &printHTML("</HEAD><BODY><P>\n"); |
---|
| 804 | if ($cprev) { |
---|
| 805 | &printHTML("<A HREF=\"$cprev\"><IMG ALIGN=MIDDLE " |
---|
| 806 | . "SRC=\"$icons/prev-arrow.gif\" ALT=\"PREV\"></A>\n"); |
---|
| 807 | } else { |
---|
| 808 | &printHTML("<A><IMG ALIGN=MIDDLE " |
---|
| 809 | . "SRC=\"$icons/missing-arrow.gif\" ALT=\"prev\"></A>\n"); |
---|
| 810 | } |
---|
| 811 | if ($cup) { |
---|
| 812 | &printHTML("<A HREF=\"$cup\"> <IMG ALIGN=MIDDLE " |
---|
| 813 | . "SRC=\"$icons/up-arrow.gif\" ALT=\"UP\"></A>\n"); |
---|
| 814 | } else { |
---|
| 815 | &printHTML("<A><IMG ALIGN=MIDDLE " |
---|
| 816 | . "SRC=\"$icons/missing-arrow.gif\" ALT=\"up\"></A>\n"); |
---|
| 817 | } |
---|
| 818 | if ($cnext) { |
---|
| 819 | &printHTML("<A HREF=\"$cnext\"><IMG ALIGN=MIDDLE " |
---|
| 820 | . "SRC=\"$icons/next-arrow.gif\" ALT=\"NEXT\"></A>\n"); |
---|
| 821 | } else { |
---|
| 822 | &printHTML("<A><IMG ALIGN=MIDDLE " |
---|
| 823 | . "SRC=\"$icons/missing-arrow.gif\" ALT=\"next\"></A>\n"); |
---|
| 824 | } |
---|
[05862b4] | 825 | if ($dirfile) { |
---|
| 826 | # XXX need new graphic for this one |
---|
| 827 | &printHTML("<A HREF=\"$dirfile\"> <IMG ALIGN=MIDDLE " |
---|
| 828 | . "SRC=\"$icons/dir-arrow.gif\" ALT=\"Bookshelf\"></A>\n"); |
---|
| 829 | } else { |
---|
| 830 | &printHTML("<A><IMG ALIGN=MIDDLE " |
---|
| 831 | . "SRC=\"$icons/missing-arrow.gif\" ALT=\"Bookshelf\"></A>\n"); |
---|
| 832 | } |
---|
[0a46c6d] | 833 | &printHTML("<CITE>$title</CITE>") if $title; |
---|
| 834 | } |
---|
| 835 | |
---|
[cfdba52] | 836 | ######################################################################## |
---|
| 837 | sub process_node |
---|
| 838 | # On entry, $_ is an @node line. |
---|
| 839 | { |
---|
| 840 | s/^\@node\s+//; |
---|
| 841 | ($this,$next,$prev,$up) = split(/,/); |
---|
| 842 | |
---|
| 843 | &deduce_node_links() unless ($next || $prev || $up); |
---|
| 844 | |
---|
[a9a992cb] | 845 | &terminate_node(); |
---|
| 846 | |
---|
[cfdba52] | 847 | $cthis = &canonical($this); |
---|
| 848 | $cnext = &canonical($next); |
---|
| 849 | $cprev = &canonical($prev); |
---|
| 850 | $cup = &canonical($up); |
---|
| 851 | |
---|
| 852 | print "... opening $dir$cthis ...\n" if $debug{nodes}; |
---|
| 853 | open(HTML,">$dir/$cthis") || die "Couldn't open $dir$cthis -- $!\n"; |
---|
| 854 | |
---|
| 855 | $nfootnotes = 0; |
---|
| 856 | |
---|
| 857 | &printHTML("<HTML>\n"); |
---|
| 858 | &printHTML("<!-- created $today from " . |
---|
| 859 | $origin[$start_index] . " via texi2www -->\n"); |
---|
[3ab325e] | 860 | &print_header if $header; |
---|
[cfdba52] | 861 | &printHTML("<HEAD>\n<TITLE>$this</TITLE>\n"); |
---|
[0a46c6d] | 862 | &print_arrows; |
---|
[cfdba52] | 863 | &printHTML("</P>\n"); |
---|
| 864 | |
---|
| 865 | } # process_node |
---|
[0a46c6d] | 866 | |
---|
[cfdba52] | 867 | sub terminate_node |
---|
| 868 | { |
---|
| 869 | if ($nfootnotes) { |
---|
| 870 | &printHTML("<P><HR>\n"); |
---|
| 871 | for ($n=0; $n < $nfootnotes; ++$n) { |
---|
| 872 | &printHTML("<P>\[" . ($n+1) . "\] $footnote[$n]</P>\n"); |
---|
| 873 | } |
---|
| 874 | } |
---|
[0a46c6d] | 875 | |
---|
| 876 | |
---|
| 877 | &printHTML("<P><HR>\n"); |
---|
| 878 | &print_arrows; |
---|
| 879 | &printHTML("</P>\n"); |
---|
[cfdba52] | 880 | &print_footer if $footer; |
---|
| 881 | &printHTML("</BODY></HTML>\n"); |
---|
| 882 | close (HTML); |
---|
| 883 | } |
---|
| 884 | |
---|
| 885 | ######################################################################## |
---|
| 886 | sub process_section |
---|
| 887 | # |
---|
| 888 | # On entry: |
---|
| 889 | # $_ is the section command (I.e. `@chapter Overview') |
---|
| 890 | # $i is the index to $_ in @lines |
---|
| 891 | { |
---|
| 892 | &printHTML("$paragraph_end") if $in_paragraph; |
---|
| 893 | $in_paragraph = 0; |
---|
| 894 | |
---|
| 895 | /^\@(\w+)\s+(.*)/; |
---|
| 896 | |
---|
| 897 | $section_number = ''; |
---|
| 898 | if ($1 eq 'chapter') { |
---|
| 899 | ++$chapter; $section=$subsection=$subsubsection=0; |
---|
| 900 | $section_number = "Chapter $chapter: "; |
---|
| 901 | } elsif ($1 eq 'section') { |
---|
| 902 | ++$section; $subsection=$subsubsection=0; |
---|
| 903 | $section_number = "$chapter.$section: "; |
---|
| 904 | } elsif ($1 eq 'subsection') { |
---|
| 905 | ++$subsection; $subsubsection=0; |
---|
| 906 | $section_number = "$chapter.$section.$subsection: "; |
---|
| 907 | } elsif ($1 eq 'subsubsection') { |
---|
| 908 | ++$subsubsection; |
---|
| 909 | $section_number = "$chapter.$section.$subsection.$subsubsection: "; |
---|
| 910 | } elsif ($1 eq 'appendix') { |
---|
| 911 | ++$appendix; $section=$subsection=$subsubsection=0; |
---|
| 912 | $x = ('A'..'Z')[$appendix-1]; |
---|
| 913 | $section_number = "Appendix $x: "; |
---|
| 914 | } elsif ($1 eq 'appendixsec') { |
---|
| 915 | ++$section; $subsection=$subsubsection=0; |
---|
| 916 | $x = ('A'..'Z')[$appendix-1]; |
---|
| 917 | $section_number = "$x.$section: "; |
---|
| 918 | } elsif ($1 eq 'appendixsubsec') { |
---|
| 919 | ++$subsection; $subsubsection=0; |
---|
| 920 | $x = ('A'..'Z')[$appendix-1]; |
---|
| 921 | $section_number = "$x.$section.$subsection: "; |
---|
| 922 | } elsif ($1 eq 'appendixsubsubsec') { |
---|
| 923 | ++$subsubsection; |
---|
| 924 | $x = ('A'..'Z')[$appendix-1]; |
---|
| 925 | $section_number = "$x.$section.$subsection.$subsubsection: "; |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | $x = $directive_section{$1}; |
---|
| 929 | &printHTML("<H$x>$section_number$2</H$x>\n"); |
---|
| 930 | } # process_section |
---|
| 931 | |
---|
| 932 | ######################################################################## |
---|
| 933 | sub process_synindex |
---|
| 934 | # |
---|
| 935 | # There's perhaps a bug here -- this presumes the @synindex comes before |
---|
| 936 | # any @?index directives; anything already in <from> doesn't get merged |
---|
| 937 | # into <to>! |
---|
| 938 | # |
---|
| 939 | { |
---|
| 940 | local ($code) = @_; # Either 0 or 1; 1 means @syncodeindex |
---|
| 941 | |
---|
| 942 | /\@syn\w*index\s+(\w+)\s+(\w+)/; |
---|
| 943 | |
---|
| 944 | print "*** synindex $1 $2\n" if $debug{'index'}; |
---|
| 945 | |
---|
| 946 | $index_name{$1} = $2 . "index"; |
---|
| 947 | $index_style{$1} = 'CODE' if $code; |
---|
| 948 | } # process_synindex |
---|
| 949 | |
---|
| 950 | ######################################################################## |
---|
| 951 | sub printHTML |
---|
| 952 | { |
---|
| 953 | local ($line) = @_; |
---|
| 954 | $line =~ s/\$R/\}/g; |
---|
| 955 | $line =~ s/\$L/\{/g; |
---|
| 956 | $line =~ s/\$A/\@/g; |
---|
| 957 | $line =~ s/\$D/\$/g; |
---|
| 958 | if ($debug{printHTML}) { |
---|
| 959 | print $line; |
---|
| 960 | } else { |
---|
| 961 | print HTML $line; |
---|
| 962 | } |
---|
| 963 | } # printHTML |
---|
| 964 | |
---|
[3ab325e] | 965 | ######################################################################## |
---|
| 966 | sub print_header |
---|
| 967 | { |
---|
| 968 | unless (open(HEADER,$header)) { |
---|
| 969 | print "WARNING -- couldn't open header file \"$header\" -- $!\n"; |
---|
| 970 | $header = 0; |
---|
| 971 | return; |
---|
| 972 | } |
---|
| 973 | while (<HEADER>) { |
---|
| 974 | &printHTML($_); |
---|
| 975 | } |
---|
| 976 | close(HEADER); |
---|
| 977 | } |
---|
| 978 | |
---|
[cfdba52] | 979 | ######################################################################## |
---|
| 980 | sub print_footer |
---|
| 981 | { |
---|
| 982 | unless (open(FOOTER,$footer)) { |
---|
| 983 | print "WARNING -- couldn't open footer file \"$footer\" -- $!\n"; |
---|
| 984 | $footer = 0; |
---|
| 985 | return; |
---|
| 986 | } |
---|
| 987 | while (<FOOTER>) { |
---|
| 988 | &printHTML($_); |
---|
| 989 | } |
---|
| 990 | close(FOOTER); |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | ######################################################################## |
---|
| 994 | sub read_input |
---|
| 995 | # |
---|
| 996 | # Read the texinfo source into @texinfo. Don't copy comments or the |
---|
| 997 | # `@ifxxx' and `@end ifxxx' surrounding [or the contents of] conditional |
---|
| 998 | # blocks. Read `@include' files. |
---|
| 999 | { |
---|
| 1000 | local ($echo,$terminator_re,$started_at) = @_; |
---|
| 1001 | |
---|
| 1002 | while (&texinfo_read()) { |
---|
| 1003 | |
---|
| 1004 | next if (/^\@c$/ || /^\@c\s/ || /^\@comment/); |
---|
| 1005 | |
---|
| 1006 | if (/^\@ifinfo/) { |
---|
| 1007 | &read_input($echo,'/^\@end\s+ifinfo/', |
---|
| 1008 | "$texinfo_file[0] line $."); |
---|
| 1009 | next; |
---|
| 1010 | } |
---|
| 1011 | if (/^\@ifhtml/) { |
---|
| 1012 | &read_input($echo,'/^\@end\s+ifhtml/', |
---|
| 1013 | "$texinfo_file[0] line $."); |
---|
| 1014 | next; |
---|
| 1015 | } |
---|
| 1016 | if (/^\@iftex/) { |
---|
| 1017 | &read_input(0,'/^\@end\s+iftex/', |
---|
| 1018 | "$texinfo_file[0] line $."); |
---|
| 1019 | next; |
---|
| 1020 | } |
---|
| 1021 | if (/^\@tex/) { |
---|
| 1022 | &read_input(0,'/^\@end\s+tex/', |
---|
| 1023 | "$texinfo_file[0] line $."); |
---|
| 1024 | next; |
---|
| 1025 | } |
---|
| 1026 | if (/^\@ignore/) { |
---|
| 1027 | # @ignore doesn't nest |
---|
| 1028 | $ignore_from = "$texinfo_file[0] line $."; |
---|
| 1029 | while (&texinfo_read()) { |
---|
| 1030 | last if (/^\@end\s+ignore/); |
---|
| 1031 | } |
---|
| 1032 | unless (/^\@end\s+ignore/) { |
---|
| 1033 | print "Unexpected EOF while searching from $ignore_from " |
---|
| 1034 | . "for \'\@end ignore\'\n"; |
---|
| 1035 | } |
---|
| 1036 | next; |
---|
| 1037 | } |
---|
| 1038 | if (/^\@titlepage/) { |
---|
| 1039 | &read_input(0,'/^\@end\s+titlepage/',"$texinfo_file[0] line $."); |
---|
| 1040 | next; |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | if (/^\@ifclear\s+(\S+)/) { |
---|
| 1044 | &read_input($echo&&(!defined($set{$1})),'/^\@end\s+ifclear/', |
---|
| 1045 | "$texinfo_file[0] line $."); |
---|
| 1046 | next; |
---|
| 1047 | } |
---|
| 1048 | if (/^\@ifset\s+(\S+)/) { |
---|
| 1049 | &read_input($echo&&defined($set{$1}),'/^\@end\s+ifset/', |
---|
| 1050 | "$texinfo_file[0] line $."); |
---|
| 1051 | next; |
---|
| 1052 | } |
---|
| 1053 | |
---|
| 1054 | return if eval "$terminator_re"; |
---|
| 1055 | |
---|
| 1056 | if (/^\@include\s+(\S+)/) { |
---|
| 1057 | &open_input_file($1); |
---|
| 1058 | next; |
---|
| 1059 | } |
---|
| 1060 | |
---|
| 1061 | if (/^\@(set|clear)\s+(\S+)/) { |
---|
| 1062 | if ($1 eq "set") { |
---|
| 1063 | $set{$2} = 1; |
---|
| 1064 | } else { |
---|
| 1065 | undef($set{$2}); |
---|
| 1066 | } |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | next unless $echo; |
---|
| 1070 | |
---|
| 1071 | if (/^\@(\w+)/) {next if $ignore_these_directives{$1};} |
---|
| 1072 | |
---|
| 1073 | # Hide @@, @{, and @} so later on it'll be easier to process |
---|
| 1074 | # stuff like `@code{@@TeX@{@}}'. |
---|
| 1075 | s/\$/\$D/g; s/\@\@/\$A/g; s/\@{/\$L/g; s/\@}/\$R/g; |
---|
| 1076 | |
---|
| 1077 | # Convert the HTML special characters |
---|
| 1078 | s/\&/\&/g; s/\</\</g; s/\>/\>/g; s/\"/\"/g; |
---|
| 1079 | |
---|
| 1080 | $texinfo[$ntexinfo] = $_; |
---|
| 1081 | $origin[$ntexinfo] = "$texinfo_file[0] line $."; |
---|
| 1082 | ++$ntexinfo; |
---|
| 1083 | } |
---|
| 1084 | |
---|
| 1085 | print "Unexpected EOF while searching from $started_at " |
---|
| 1086 | . "for $terminator_re\n"; |
---|
| 1087 | } # read_input |
---|
| 1088 | |
---|
| 1089 | ######################################################################## |
---|
| 1090 | sub initialize_tables |
---|
| 1091 | { |
---|
| 1092 | # Lists which `@x{y}' get expanded into `y'. |
---|
| 1093 | %atxy_2_y = ( |
---|
| 1094 | 'asis', 1, |
---|
| 1095 | 'r', 1, |
---|
| 1096 | 'w', 1, |
---|
| 1097 | ); |
---|
| 1098 | |
---|
| 1099 | # Describes which `@x{y}' get expanded into `<z>y</z>' and what `z' |
---|
| 1100 | # is in those expansions! (If the expansion matches |
---|
| 1101 | # ``/(.*),(.*),(.*)/'' then y actually expands to ``$1<$2>y</$2>$3''; |
---|
| 1102 | # if z (or $2) begins with ^ then uppercase y before doing the |
---|
| 1103 | # expansion). |
---|
| 1104 | %atxy_2_zyz= ( |
---|
| 1105 | 'b', 'STRONG', |
---|
| 1106 | 'cite', 'CITE', |
---|
| 1107 | 'code', "CODE", |
---|
| 1108 | 'dfn', 'EM', |
---|
| 1109 | 'dmn', 'EM', |
---|
| 1110 | 'emph', 'EM', |
---|
| 1111 | 'file', "`,CODE,'", |
---|
| 1112 | 'i', 'EM', |
---|
| 1113 | 'kbd', 'KBD', |
---|
| 1114 | 'key', '^CODE', |
---|
| 1115 | 'math', 'CODE', |
---|
| 1116 | 'samp', "`,CODE,'", |
---|
| 1117 | 'sc', '^EM', |
---|
| 1118 | 'strong', 'STRONG', |
---|
| 1119 | 't', 'CODE', |
---|
| 1120 | 'titlefont', 'CITE', |
---|
| 1121 | 'var', 'VAR', |
---|
| 1122 | ); |
---|
| 1123 | |
---|
| 1124 | # Describes which `@x{y}' can be expanded into `z' and what `z' is in |
---|
| 1125 | # those expansions! |
---|
| 1126 | %atxy_2_z = ( |
---|
| 1127 | 'TeX', '<i>T</i>e<i>X</i>', |
---|
| 1128 | 'bullet', '*', |
---|
| 1129 | 'copyright', '(C)', |
---|
| 1130 | 'dots', '...', |
---|
| 1131 | 'equiv', '==', |
---|
| 1132 | 'error', 'error-->', |
---|
| 1133 | 'expansion', '==>', |
---|
| 1134 | 'minus', '-', |
---|
| 1135 | 'point', '-!-', |
---|
| 1136 | 'print', '-|', |
---|
| 1137 | 'result', '=>', |
---|
| 1138 | 'today', &today(), |
---|
| 1139 | ); |
---|
| 1140 | |
---|
| 1141 | # Lists the '@x{y}' cross reference commands, and describes how they get |
---|
| 1142 | # expanded. Note the 'X' beginning each expansion -- it's there so 'ref' |
---|
| 1143 | # doesn't get expanded to ''! |
---|
| 1144 | %atxy_2_ref = ( |
---|
| 1145 | 'xref', 'XSee ', |
---|
| 1146 | 'ref', 'X', |
---|
| 1147 | 'pxref', 'Xsee ', |
---|
| 1148 | 'href', 'X', |
---|
| 1149 | 'inforef', 'XSee ', |
---|
| 1150 | ); |
---|
| 1151 | |
---|
| 1152 | %ignore_these_directives = ( |
---|
| 1153 | 'author', 1, |
---|
| 1154 | 'break', 1, |
---|
| 1155 | 'contents', 1, |
---|
| 1156 | 'evenfooting', 1, |
---|
| 1157 | 'everyfooting', 1, |
---|
| 1158 | 'everyheading', 1, |
---|
| 1159 | 'finalout', 1, |
---|
| 1160 | 'footnotestyle', 1, |
---|
| 1161 | 'headings', 1, |
---|
| 1162 | 'need', 1, |
---|
| 1163 | 'noindent', 1, |
---|
| 1164 | 'oddfooting', 1, |
---|
| 1165 | 'page', 1, |
---|
| 1166 | 'paragraphindent', 1, |
---|
| 1167 | 'setchapternewpage', 1, |
---|
| 1168 | 'setfilename', 1, |
---|
| 1169 | 'shortcontents', 1, |
---|
| 1170 | 'shorttitlepage', 1, |
---|
| 1171 | 'smallbook', 1, |
---|
| 1172 | 'sp', 1, |
---|
| 1173 | 'subtitle', 1, |
---|
| 1174 | 'summarycontents', 1, |
---|
| 1175 | 'top', 1, |
---|
| 1176 | 'vskip', 1, |
---|
| 1177 | ); |
---|
| 1178 | |
---|
| 1179 | # List the section directives and indicate what heading level |
---|
| 1180 | # each one gets. |
---|
| 1181 | %directive_section = ( |
---|
| 1182 | 'chapter', 1, |
---|
| 1183 | 'section', 2, |
---|
| 1184 | 'subsection', 3, |
---|
| 1185 | 'subsubsection',4, |
---|
| 1186 | 'appendix', 1, |
---|
| 1187 | 'appendixsec', 2, |
---|
| 1188 | 'appendixsubsec', 3, |
---|
| 1189 | 'appendixsubsubsec', 4, |
---|
| 1190 | 'chapheading', 1, |
---|
| 1191 | 'majorheading', 1, |
---|
| 1192 | 'heading', 2, |
---|
| 1193 | 'subheading', 3, |
---|
| 1194 | 'subsubheading', 4, |
---|
| 1195 | 'unnumbered', 1, |
---|
| 1196 | 'unnumberedsec', 2, |
---|
| 1197 | 'unnumberedsubsec', 3, |
---|
| 1198 | 'unnumberedsubsubsec', 4, |
---|
| 1199 | ); |
---|
| 1200 | |
---|
| 1201 | # These @ directives begin a block of preformatted text |
---|
| 1202 | # (">PRE" means indented inside <PRE>...</PRE>) |
---|
| 1203 | %directive_block = ( |
---|
| 1204 | 'cartouche', 'HR', |
---|
| 1205 | 'display', '>PRE', |
---|
| 1206 | 'example', '>PRE', |
---|
| 1207 | 'format', 'PRE', |
---|
| 1208 | 'group', '-', |
---|
| 1209 | 'lisp', '>PRE', |
---|
| 1210 | 'quotation', 'BLOCKQUOTE', |
---|
| 1211 | 'smallexample','>PRE', |
---|
| 1212 | ); |
---|
| 1213 | |
---|
| 1214 | %index_name = ( |
---|
| 1215 | 'cp', 'cpindex', |
---|
| 1216 | 'fn', 'fnindex', |
---|
| 1217 | 'ky', 'kyindex', |
---|
| 1218 | 'pg', 'pgindex', |
---|
| 1219 | 'tp', 'tpindex', |
---|
| 1220 | 'vr', 'vrindex', |
---|
| 1221 | ); |
---|
| 1222 | %index_style = ( |
---|
| 1223 | 'fn', 'CODE', |
---|
| 1224 | 'ky', 'CODE', |
---|
| 1225 | 'pg', 'CODE', |
---|
| 1226 | 'tp', 'CODE', |
---|
| 1227 | 'vr', 'CODE', |
---|
| 1228 | ); |
---|
| 1229 | } # initialize_tables |
---|
| 1230 | |
---|
| 1231 | ######################################################################## |
---|
| 1232 | sub open_input_file |
---|
| 1233 | { |
---|
| 1234 | unshift(@texinfo_file,$_[0]); |
---|
| 1235 | print "opening $_[0] ...\n" if $debug{open_input_file}; |
---|
| 1236 | open($texinfo_file[0],$_[0]) || die "Couldn't open $_[0]: $!\n"; |
---|
| 1237 | } # open_input_file |
---|
| 1238 | |
---|
| 1239 | ######################################################################## |
---|
| 1240 | sub texinfo_read |
---|
| 1241 | # Reads the next line of texinfo input into $_. |
---|
| 1242 | { |
---|
| 1243 | do { |
---|
| 1244 | $fd = $texinfo_file[0]; |
---|
| 1245 | $_ = <$fd>; |
---|
| 1246 | } while ($_ eq '' && shift @texinfo_file); |
---|
| 1247 | return $_; |
---|
| 1248 | } # texinfo_read |
---|
| 1249 | |
---|
| 1250 | ######################################################################## |
---|
| 1251 | sub today |
---|
| 1252 | { |
---|
| 1253 | $today = `date`; |
---|
| 1254 | $today =~ s/\w+ (\w+ +[0-9]+) [0-9]+:[0-9]+:[0-9]+ \w+ ([0-9]+)\n/$1 $2/; |
---|
| 1255 | $today =~ s/ +/ /g; |
---|
| 1256 | return $today; |
---|
| 1257 | } # today |
---|
| 1258 | |
---|
| 1259 | ######################################################################## |
---|
| 1260 | sub copy_to_destdir |
---|
| 1261 | { |
---|
| 1262 | ($copy_from) = @_; |
---|
| 1263 | |
---|
| 1264 | if ($copy_from =~ m|(.*)/([^/]*)|) { |
---|
| 1265 | $copy_from_dir = $1; |
---|
| 1266 | $copy_from_file = $2; |
---|
| 1267 | } else { |
---|
| 1268 | $copy_from_dir = "."; |
---|
| 1269 | $copy_from_file = $copy_from; |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | if ($copy_from_dir ne $dir && !-e "$dir/$copy_from_file") { |
---|
| 1273 | system("cp $copy_from $dir") |
---|
| 1274 | && die "Couldn\'t \`cp $copy_from $dir\'\n"; |
---|
| 1275 | } |
---|
| 1276 | } |
---|