⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 texi2www

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻
📖 第 1 页 / 共 3 页
字号:
#!/usr/bin/perl# (Works with both perl 4 and perl 5)##  $Id: texi2www,v 1.12.4.1 2003/05/21 19:29:32 ralf Exp $#$version = 'Jan 2 1996';$copyright = <<EOT;texi2www - converts texinfo to HTMLCopyright (C) 1994, 1995, 1996 Tim SingletaryThis program is freely distributable under the terms of the GNU GENERAL PUBLIC LICENSE.  In particular, modified versions of this program must retain this copyright notice and must remain freelydistributable.EOT$usage = <<EOT;Usage: texi2www [option ...] texinfo_filewhere options are:  -dir directory    -- Specify output directory.  Default is `.'.  -dirfile path     -- Specifies a replacement for ../dir.html  -header path      -- Specifies the path to a file containing HTML;                       this files gets inserted near the top of each                       generated HTML file.  -footer path      -- Specifies the path to a file containing HTML;                       this files gets inserted near the bottom of each                       generated HTML file.  -I path           -- Append path to the directories being searched for                       texi files.  -icons path       -- Specifies the path, relative to the output directory,                       to the arrow files.  Default is `..'.  -base             -- Specify the base part fo the genrated short file names  -uselongnames     -- Use long names for generated html files  -verbose          -- Verbose output.The complete user\'s is available athttp://sunland.gsfc.nasa.gov/info/texi2www/Top.htmlEOT########################################################################%lookup = ();                      # clear the name mapping hash$uselongnames=0;                   # default to using short names$base = "a";                       # default short name base (BASEnnnnn.html)$outcount = 0;                     # count for the nnnnn part of short names$icons = "..";                     # where are the icons$dir = ".";                        # where are the generated files to go$dirfile = "../dir.html";          # "up" node pointer@include_path = () ;	           # list of include directorieswhile ($ARGV[0] =~ /^-/) {    $_ = shift;    if (/-base/) {$base = shift; next;}    if (/-dirfile/) {$dirfile = shift; next;}    if (/-dir/) {$_ = shift; s!/$!!; s!$!/!; $dir = $_; next;}    if (/-footer/) {$footer = shift; next;}    if (/-header/) {$header = shift; next;}    if (/-icons/) {$_ = shift; s!\/$!!; $icons = $_; next;}    if (/-uselongnames/) {$uselongnames = 1; next;}    if (/-verbose/) {$verbose = 1; next;}    if (/-I/) { push @include_path, shift; next;}    die $usage;}print STDERR "include-path:@include_path\n" if $verbose ;&initialize_tables();## Read the texinfo input into @texinfo#&open_input_file($ARGV[0]);&read_input(1,'/^\@bye/',"$texinfo_file[0] line 1");$texinfo[$ntexinfo] = "\@bye\n";$origin[$ntexinfo] = "$texinfo_file[0] line $.";## Parse @texinfo#$texinfo_index = 0;while ($texinfo_index < @texinfo) {    &get_more_stuff_to_parse();    if (/^\@bye/) {        &terminate_node();        print "Normal completion\n";        exit;    }    &parse();}print "Huh? didn't parse the \@bye directive!\n";########################################################################sub canonical # (node_name){    local ($n) = @_;    $n =~ s/^\s+//; $n =~ s/\s+$//; # strip whitespace    return "$dirfile" if ($n =~ /\(dir\)/i); # handle (dir)        if ($n =~ /^\(([^\)]+)\)(.*)/) {	$p = $1; $p =~ s/^\s+//; $p =~ s/\s+$//; $p .= "/";	$n = $2; $n =~ s/^\s+//; $n =~ s/\s+$//;    } else {	$p = "";    }    $n =~ s/\$/\$\$/;		# `$' -> `$$'    $n =~ s/_/\$_/g;		# `_' -> `$_'    $n =~ s/\s+/_/g;		# whitespace -> `_'				# anything else that's funky get				# translated to `$xx' where `xx'				# are hex digits.    while ($n =~ /(.*)([^-a-zA-Z0-9\$_.])(.*)/) {	$n = $1 . sprintf("\$%02x",ord($2)) . $3;    }    if ($uselongnames) {      return "$p$n.html" if ($n);    } else {      if ($n eq 'Top') {        $lookup{"$p$n"}= "index.html";         return $lookup{"$p$n"};      } elsif ($n) {        if (! $lookup{"$p$n"})  {          $outcount = $outcount + 1;          #$lookup{"$p$n"}= "$base$outcount.html";           $lookup{"$p$n"} = sprintf "%s%05d.html", $base, $outcount;        }        return $lookup{"$p$n"};      }    }    return "";} # canonical########################################################################sub deduce_node_links## On entry, $_ is a node line and $start_index is the index (in @texinfo)# the node line.## &deduce_node_links() sets $next, $prev, and $up.{    local ($level,$i,$node,$j);    # First, search down from this node to the next sectioning command.    $level = &determine_node_level($start_index+1);    # Next, look for the `next' node (i.e., the next node at the    # same or a higher level).    undef($next);    for ($i=$start_index+1; $i < $ntexinfo; ++$i) {	$_ = $texinfo[$i];	next unless /^\@node +([^,]+).*\n/;	$j = &determine_node_level($i+1);	if ($j <= $level) {	    if ($j == $level) {$next = $1;}	    last;	}     }    # Look for the `prev' and `up' nodes    undef($prev);    undef($up);    for ($i=$start_index-1; $i > 1; --$i) {	$_ = $texinfo[$i];	next unless /^\@node\s+([^,]+).*\n/;	$j = &determine_node_level($i+1);	if ($j == $level) {	    unless ($prev) {$prev = $1;}	} elsif ($j < $level) {	    $up = $1;	    last;	}    }    unless (defined($up)) {$up = "(dir)";}    $xthis = $this;    $xthis =~ s/\n//;} # deduce_node_links########################################################################sub determine_node_level{    local ($i) = @_;    local ($level);    $level = 0;    while ($i < $ntexinfo) {	$_ = $texinfo[$i];	++$i;	next if /^\s+$/;	last if (/\@node/);	last unless (/\@(\w+)/);	if ($directive_section{$1}) {	    $level = $directive_section{$1};	    last;	}    }    return $level;} # determine_node_level########################################################################sub expand_xref{    local ($cmd,$arg) = @_;    local ($node,$xrefname,$topic,$infofile,$manual,$url,$x);    if ($cmd eq 'inforef') {	($node,$xrefname,$infofile) = split(/,/,$arg);	$topic = $manual = '';    } elsif ($cmd eq 'href') {	($xrefname,$node,$infofile,$url) = split(/,/,$arg);    } elsif ($cmd eq 'email') {	($xrefname,$node,$infofile,$url) = split(/,/,$arg);	$xrefname = "mailto:$xrefname";	$url = $xrefname    } elsif ($cmd eq 'uref') {	($url,$xrefname,$node,$infofile) = split(/,/,$arg);    } else {	($node,$xrefname,$topic,$infofile,$manual) = split(/,/,$arg);    }    $xrefname =~ s/^\s+//; $infofile =~ s/^\s+//;    $xrefname =~ s/\s+$//; $infofile =~ s/\s+$//;    $xrefname =~ s/\s+/ /; $infofile =~ s/\s+/ /;    $infofile =~ s/\.texi$//;    $infofile =~ s/\.texinfo$//;    if ($xrefname =~ /^$/) {$xrefname = $node;}    $node = &canonical($node);    unless ($url) {	unless ($infofile =~ /^$/) {$url = "../$infofile/";}	$url = $url . $node;    }    $x = "<A HREF=\"$url\">$xrefname</A>";} # expand_xref########################################################################sub get_more_stuff_to_parse{    $start_index = $texinfo_index;    $_ = '';    do {	if ($texinfo_index >= @texinfo) {	    print "Unclosed \@x{y} in chunk beginning at "		. "$origin[$start_index]\n";	    return;	}        s/\n$/ /;	$more = $texinfo[$texinfo_index++];	$more =~ s/\@\*/<BR>\n/g;	$more =~ s/\@\./\./g;	$more =~ s/\@\://g;	$more =~ s/\@refill//g;	$_ .= $more;	# Expand all @a{b} in line	while (/\@(\w+)\{([^{}]*)\}/) {            $atcmd = $1;	    $atarg = $2;            if ($z = $atxy_2_zyz{$atcmd}) {		if ($z =~ /(.+),(.+),(.+)/) {		    $left = $1; $z = $2; $right = $3;		} else {		    $left = ''; $right = '';		}		if ($z =~ s/^\^//) {$atarg =~ tr/a-z/A-Z/;}		$x = "$left<$z>$atarg</$z>$right";            } elsif ($atxy_2_y{$atcmd}) {                $x = $atarg;            } elsif ($z = $atxy_2_z{$atcmd}) {                $x = $z;            } elsif ($z = $atxy_2_ref{$atcmd}) {                $x = $z . &expand_xref($atcmd,$atarg);                $x =~ s/^X//; # works because $z must start with 'X'!            } elsif ($atcmd eq 'value') {                $x = $texinfo_variable{$atarg};            } elsif ($atcmd eq 'today') {                $x = &today();            } elsif ($atcmd eq 'footnote') {		$footnote[$nfootnotes++] = $atarg;                $x = "\[$nfootnotes\]";	    } elsif ($atcmd eq 'gif') {		$atarg =~ s/,.*//;		&copy_to_destdir($atarg);		$atarg =~ s|.*/||;		$x = "<IMG SRC=\"$atarg\">";            } else {                print "**WARNING** Don't know how to expand "                    . "\@$atcmd\{$atarg\}\n";		$debug = 1;                $x = "?$atcmd\?$atarg\?";            }            	    print "$origin[$start_index]: \@$atcmd\{$atarg\} => $x\n"		                                   if $debug{expansions};            s/\@\w+\{[^{}]*\}/$x/;	            }    } while (/\@\w+\{[^}]*$/);    print "$origin[$start_index]: $_" if $debug{chunks};} # get_more_stuff_to_parse########################################################################sub parse# On entry:#    $_ -- the line(s) to parse.#    $start_index -- where, in $texinfo, $_ begins.{    local ($x);    if (/^\@(\w+)/) {	if ($x=$directive_block{$1}) { # @example, @quotation, etc.	    &parse_block($1,$x);	} elsif ($directive_section{$1}) { # @chapter, @subsection, etc.	    &process_section();	} elsif ($1 eq 'bye') {	    if ($nfootnotes > 0) {		&printHTML("<P><HR>\n");		for ($n=0; $n < $nfootnotes; ++$n) {		    &printHTML("<P>\[" . ($n+1) . "\] $footnote[$n]</P>\n");		}	    }            &printHTML("<P><HR>\n");            &print_arrows;            &printHTML("</P>\n");	    &print_footer if $footer;	    &printHTML("</BODY></HTML>\n");	    close (HTML);	    return;	} elsif ($1 eq 'center') {	    /^\@center\s+(.*)/;	    &printHTML("$paragraph_end") if $in_paragraph;	    &printHTML("<P ALIGN=CENTER>$1</P>\n");	    $in_paragraph = 0;	} elsif ($1 eq 'clear') {	    /^\@clear\s+(\S+)/;	    undef($texinfo_variable{$1});	} elsif ($1 =~ /^def(code)?index/) {	    /^\@(def|defcode)index\s+(\w+)/;	    $index_name{$2} = $2 . "index";	    $index_style{$2} = 'CODE' if ($1 eq "defcode");	} elsif ($1 =~ /^(def.*)/) { # @defn, @defun, ... @deftp	    &parse_def($1);	} elsif ($1 eq 'enumerate') {	    &parse_enumerate();	} elsif ($1 eq 'exdent') {	    /^\@exdent\s+(.*)/;	    &printHTML("$paragraph_end") if $in_paragraph;	    # A bug -- doesn't exdent the line!	    &printHTML("<P>$1</P>\n");	    $in_paragraph = 0;	} elsif ($1 eq 'flushleft' || $1 eq 'flushright') {	    &parse_flush();	} elsif ($1 eq 'html') {	    while ($texinfo_index < @texinfo) {		&get_more_stuff_to_parse();		last if (/^\@end\s+html/);		s/\&quot;/\"/g; s/\&gt;/\>/g; s/\&lt;/\</g; s/\&amp;/\&/g;		&printHTML("$_");	    }	} elsif ($1 eq 'itemize') {	    &parse_itemize();	} elsif ($1 eq 'menu') {	    &parse_menu();	} elsif ($1 eq 'node') {	    $node=$_;	    &process_node();	} elsif ($1 eq 'printindex') {	    /^\@printindex\s+([a-z]+)/;	    &print_index($1);	} elsif ($1 eq 'settitle') {	    /^\@settitle\s+(.*)/;	    unless ($title) {$title = $1;}	} elsif ($1 eq 'set') {	    if (/^\@set\s+(\S+)\s+(.+)$/) {		$texinfo_variable{$1} = $2;	    } else {		/^\@set\s+(\S+)/;		$texinfo_variable{$1} = 1;	    }	} elsif ($1 eq 'syncodeindex') {	    &process_synindex(1);	} elsif ($1 eq 'synindex') {	    &process_synindex(0);	} elsif ($1 =~ /^.?table/) { # @table, @vtable, @ftable	    unless (/^\@(.?table)\s*\@(\w*)/		           && ($2 eq 'asis' || ($tbltype=$atxy_2_zyz{$2}))) {		print "**WARNING** $origin[$start_index]: assuming "		    . "\@table \@asis\n";		$tbltype = '';	    }	    &parse_table($1,$tbltype);	} elsif ($1 =~ /..?index/) { # @cindex, @findex, .. @auindex, etc.	    &process_index();	} else {	    print "**WARNING** $origin[$start_index]: ignoring $_";	}    } else {	if (/^\s*$/) {	    if ($in_paragraph) {		&printHTML("$paragraph_end");	    } elsif ($in_preformatted) {		&printHTML("\n");	    }	    $in_paragraph = 0;	} else {	    unless ($in_preformatted) {		unless ($in_paragraph) {		    &printHTML("<P>\n");		    $in_paragraph = 1;		    $paragraph_end = "</P>\n";		}	    }	    &printHTML("$_");	}    }} # parse########################################################################sub parse_block## Handles @example, @display, etc.##    > @example            > <PRE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -