texi2html

来自「FFTW, a collection of fast C routines to」· 代码 · 共 2,095 行 · 第 1/4 页

TXT
2,095
字号
#!/usr/local/bin/perl'di ';'ig 00 ';#+###############################################################################                                                                              ## File: texi2html                                                              ##                                                                              ## Description: Program to transform most Texinfo documents to HTML             ##                                                                              ##-############################################################################### @(#)texi2html	1.52 01/05/98	Written (mainly) by Lionel Cons, Lionel.Cons@cern.ch# Hacked by athena@fftw.org and stevenj@alum.mit.edu# The man page for this program is included at the end of this file and can be# viewed using the command 'nroff -man texi2html'.# Please read the copyright at the end of the man page.#+++#############################################################################                                                                              ## Constants                                                                    ##                                                                              ##---############################################################################$DEBUG_TOC   =  1;$DEBUG_INDEX =  2;$DEBUG_BIB   =  4;$DEBUG_GLOSS =  8;$DEBUG_DEF   = 16;$DEBUG_HTML  = 32;$DEBUG_USER  = 64;$BIBRE = '\[[\w\/-]+\]';		# RE for a bibliography reference$FILERE = '[\/\w.+-]+';			# RE for a file name$VARRE = '[^\s\{\}]+';			# RE for a variable name$NODERE = '[^@{}:\'`",]+';		# RE for a node name$NODESRE = '[^@{}:\'`"]+';		# RE for a list of node names$XREFRE = '[^@{}]+';			# RE for a xref (should use NODERE)$ERROR = "***";			        # prefix for errors and warnings$THISPROG = "texi2html 1.52";			# program name and version$HOMEPAGE = "http://wwwinfo.cern.ch/dis/texi2html/"; # program home page$TODAY = &pretty_date;			# like "20 September 1993"$SPLITTAG = "<!-- SPLIT HERE -->\n";	# tag to know where to split$PROTECTTAG = "_ThisIsProtected_";	# tag to recognize protected sections$html2_doctype = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Strict Level 2//EN">';## language dependent constants##$LDC_SEE = 'see';#$LDC_SECTION = 'section';#$LDC_IN = 'in';#$LDC_TOC = 'Table of Contents';#$LDC_GOTO = 'Go to the';#$LDC_FOOT = 'Footnotes';# TODO: @def* shortcuts## pre-defined indices#%predefined_index = (		    'cp', 'c',		    'fn', 'f',		    'vr', 'v',		    'ky', 'k',		    'pg', 'p',		    'tp', 't',	            );## valid indices#%valid_index = (		    'c', 1,		    'f', 1,		    'v', 1,		    'k', 1,		    'p', 1,		    't', 1,		);## texinfo section names to level#%sec2level = (	      'top', 0,	      'chapter', 1,	      'unnumbered', 1,	      'majorheading', 1,	      'chapheading', 1,	      'appendix', 1,	      'section', 2,	      'unnumberedsec', 2,	      'heading', 2,	      'appendixsec', 2,	      'appendixsection', 2,	      'subsection', 3,	      'unnumberedsubsec', 3,	      'subheading', 3,	      'appendixsubsec', 3,	      'subsubsection', 4,	      'unnumberedsubsubsec', 4,	      'subsubheading', 4,	      'appendixsubsubsec', 4,	      );## accent map, TeX command to ISO name#%accent_map = (	       '"',  'uml',	       '~',  'tilde',	       '^',  'circ',	       '`',  'grave',	       '\'', 'acute',	       );## texinfo "simple things" (@foo) to HTML ones#%simple_map = (	       # cf. makeinfo.c	       "*", "<BR>",		# HTML+	       " ", " ",	       "\n", "\n",	       "|", "",	       # spacing commands	       ":", "",	       "!", "!",	       "?", "?",	       ".", ".",               # hyphenation	       "-", ""  # use &shy; entity here?	       );## texinfo "things" (@foo{}) to HTML ones#%things_map = (	       'TeX', 'TeX',	       'br', '<P>',		# paragraph break	       'bullet', '*',	       'copyright', '&copy;',	       'dots', '...',  # use &hellip; entity here?	       'equiv', '==',	       'error', 'error-->',	       'expansion', '==>',	       'minus', '-',	       'point', '-!-',	       'print', '-|',	       'result', '=>',	       'today', $TODAY,	       );## texinfo styles (@foo{bar}) to HTML ones#%style_map = (	      'asis', '',	      'b', 'B',	      'cite', 'CITE',	      'code', 'CODE',	      'ctrl', '&do_ctrl',	# special case	      'dfn', 'EM',		# DFN tag is illegal in the standard	      'dmn', '',		# useless	      'email', '&do_email',     # insert a clickable email address	      'emph', 'EM',	      'file', '"TT',		# will put quotes, cf. &apply_style	      'i', 'I',	      'kbd', 'KBD',	      'key', 'KBD',	      'math', '',	      'r', '',			# unsupported	      'samp', '"SAMP',		# will put quotes, cf. &apply_style	      'sc', '&do_sc',		# special case	      'strong', 'STRONG',	      't', 'TT',	      'titlefont', '',		# useless	      'uref', '&do_uref',       # insert a clickable URL	      'url', '&do_url',         # insert a clickable URL	      'var', 'VAR',	      'w', '',			# unsupported	      );## texinfo format (@foo/@end foo) to HTML ones#%format_map = (	       'display', 'PRE',	       'example', 'PRE',	       'format', 'PRE',	       'lisp', 'PRE',	       'quotation', 'BLOCKQUOTE',	       'smallexample', 'PRE',	       'smalllisp', 'PRE',	       # lists	       'itemize', 'UL',	       'enumerate', 'OL',	       # poorly supported	       'flushleft', 'PRE',	       'flushright', 'PRE',	       );## texinfo definition shortcuts to real ones#%def_map = (	    # basic commands	    'deffn', 0,	    'defvr', 0,	    'deftypefn', 0,	    'deftypevr', 0,	    'defcv', 0,	    'defop', 0,	    'deftp', 0,	    # basic x commands	    'deffnx', 0,	    'defvrx', 0,	    'deftypefnx', 0,	    'deftypevrx', 0,	    'defcvx', 0,	    'defopx', 0,	    'deftpx', 0,	    # shortcuts	    'defun', 'deffn Function',	    'defmac', 'deffn Macro',	    'defspec', 'deffn {Special Form}',	    'defvar', 'defvr Variable',	    'defopt', 'defvr {User Option}',	    'deftypefun', 'deftypefn Function',	    'deftypevar', 'deftypevr Variable',	    'defivar', 'defcv {Instance Variable}',	    'defmethod', 'defop Method',	    # x shortcuts	    'defunx', 'deffnx Function',	    'defmacx', 'deffnx Macro',	    'defspecx', 'deffnx {Special Form}',	    'defvarx', 'defvrx Variable',	    'defoptx', 'defvrx {User Option}',	    'deftypefunx', 'deftypefnx Function',	    'deftypevarx', 'deftypevrx Variable',	    'defivarx', 'defcvx {Instance Variable}',	    'defmethodx', 'defopx Method',	    );## things to skip#%to_skip = (	    # comments	    'c', 1,	    'comment', 1,	    # useless	    'contents', 1,	    'shortcontents', 1,	    'summarycontents', 1,	    'footnotestyle', 1,	    'end ifclear', 1,	    'end ifset', 1,	    'titlepage', 1,	    'end titlepage', 1,	    # unsupported commands (formatting)	    'afourpaper', 1,	    'cropmarks', 1,	    'finalout', 1,	    'headings', 1,	    'need', 1,	    'page', 1,	    'setchapternewpage', 1,	    'everyheading', 1,	    'everyfooting', 1,	    'evenheading', 1,	    'evenfooting', 1,	    'oddheading', 1,	    'oddfooting', 1,	    'smallbook', 1,	    'vskip', 1,	    'filbreak', 1,	    'paragraphindent', 1,	    # unsupported formats	    'cartouche', 1,	    'end cartouche', 1,	    'group', 1,	    'end group', 1,	    );#+++#############################################################################                                                                              ## Argument parsing, initialisation                                             ##                                                                              ##---############################################################################%value = ();				# hold texinfo variables, see also -D$use_bibliography = 1;$use_acc = 0;$debug = 0;$doctype = '';$check = 0;$expandinfo = 0;$use_glossary = 0;$invisible_mark = '';$use_iso = 0;@include_dirs = ();$show_menu = 0;$number_sections = 0;$split_node = 0;$split_chapter = 0;$no_toc_href = 0;$monolithic = 0;$verbose = 0;$usage = <<EOT;This is $THISPROGTo convert a Texinfo file to HMTL: $0 [options] file  where options can be:    -expandinfo    : use \@ifinfo sections, not \@iftex    -glossary      : handle a glossary    -invisible name: use 'name' as an invisible anchor    -Dname         : define name like with \@set    -I dir         : search also for files in 'dir'    -menu          : handle menus    -monolithic    : output only one file including ToC    -number        : number sections    -split_chapter : split on main sections    -split_node    : split on nodes    -no_toc_href : don't write links to TOC    -usage         : print usage instructions    -verbose       : verbose outputTo check converted files: $0 -check [-verbose] filesEOTwhile (@ARGV && $ARGV[0] =~ /^-/) {    $_ = shift(@ARGV);    if (/^-acc$/)            { $use_acc = 1; next; }    if (/^-d(ebug)?(\d+)?$/) { $debug = $2 || shift(@ARGV); next; }    if (/^-doctype$/)        { $doctype = shift(@ARGV); next; }    if (/^-c(heck)?$/)       { $check = 1; next; }    if (/^-e(xpandinfo)?$/)  { $expandinfo = 1; next; }    if (/^-g(lossary)?$/)    { $use_glossary = 1; next; }    if (/^-i(nvisible)?$/)   { $invisible_mark = shift(@ARGV); next; }    if (/^-iso$/)            { $use_iso = 1; next; }    if (/^-n(o_toc_href)?$/)            { $no_toc_href = 1; next; }    if (/^-D(.+)?$/)         { $value{$1 || shift(@ARGV)} = 1; next; }    if (/^-I(.+)?$/)         { push(@include_dirs, $1 || shift(@ARGV)); next; }    if (/^-m(enu)?$/)        { $show_menu = 1; next; }    if (/^-mono(lithic)?$/)  { $monolithic = 1; next; }    if (/^-n(umber)?$/)      { $number_sections = 1; next; }    if (/^-s(plit)?_?(n(ode)?|c(hapter)?)?$/) {	if ($2 =~ /^n/) {	    $split_node = 1;	} else {	    $split_chapter = 1;	}	next;    }    if (/^-v(erbose)?$/)     { $verbose = 1; next; }    die $usage;}if ($check) {    die $usage unless @ARGV > 0;    &check;    exit;}if (($split_node || $split_chapter) && $monolithic) {    warn "Can't use -monolithic with -split, -monolithic ignored.\n";    $monolithic = 0;}if ($expandinfo) {    $to_skip{'ifinfo'}++;    $to_skip{'end ifinfo'}++;} else {    $to_skip{'iftex'}++;    $to_skip{'end iftex'}++;}$invisible_mark = '<IMG SRC="invisible.xbm">' if $invisible_mark eq 'xbm';die $usage unless @ARGV == 1;$docu = shift(@ARGV);if ($docu =~ /.*\//) {    chop($docu_dir = $&);    $docu_name = $';} else {    $docu_dir = '.';    $docu_name = $docu;}unshift(@include_dirs, $docu_dir);$docu_name =~ s/\.te?x(i|info)?$//;	# basename of the document$docu_doc = "$docu_name.html";		# document's contentsif ($monolithic) {    $docu_toc = $docu_foot = $docu_doc;} else {    $docu_toc  = "${docu_name}_toc.html";  # document's table of contents    $docu_foot = "${docu_name}_foot.html"; # document's footnotes}## variables#$value{'html'} = 1;			# predefine html (the output format)$value{'texi2html'} = '1.52';		# predefine texi2html (the translator)# _foo: internal to track @fooforeach ('_author', '_title', '_subtitle',	 '_settitle', '_setfilename') {    $value{$_} = '';		        # prevent -w warnings}%node2sec = ();				# node to section name%node2href = ();			# node to HREF%bib2href = ();				# bibliography reference to HREF%gloss2href = ();			# glossary term to HREF@sections = ();				# list of sections%tag2pro = ();				# protected sections## initial indexes#$bib_num = 0;$foot_num = 0;$gloss_num = 0;$idx_num = 0;$sec_num = 0;$doc_num = 0;$html_num = 0;## can I use ISO8879 characters? (HTML+)#if ($use_iso) {    $things_map{'bullet'} = "&bull;";    $things_map{'copyright'} = "&copy;";    $things_map{'dots'} = "&hellip;";    $things_map{'equiv'} = "&equiv;";    $things_map{'expansion'} = "&rarr;";    $things_map{'point'} = "&lowast;";    $things_map{'result'} = "&rArr;";}## read texi2html extensions (if any)#$extensions = 'texi2html.ext'; # extensions in working directoryif (-f $extensions) {    print "# reading extensions from $extensions\n" if $verbose;    require($extensions);}($progdir = $0) =~ s/[^\/]+$//;if ($progdir && ($progdir ne './')) {    $extensions = "${progdir}texi2html.ext"; # extensions in texi2html directory    if (-f $extensions) {	print "# reading extensions from $extensions\n" if $verbose;	require($extensions);    }}print "# reading from $docu\n" if $verbose;#+++#############################################################################                                                                              ## Pass 1: read source, handle command, variable, simple substitution           ##                                                                              ##---############################################################################@lines = ();				# whole document@toc_lines = ();			# table of contents$toplevel = 0;			        # top level seen in hierarchy$curlevel = 0;				# current level in TOC$node = '';				# current node name$in_table = 0;				# am I inside a table$table_type = '';			# type of table ('', 'f', 'v', 'multi')@tables = ();			        # nested table support$in_bibliography = 0;			# am I inside a bibliography$in_glossary = 0;			# am I inside a glossary$in_top = 0;				# am I inside the top node$in_pre = 0;				# am I inside a preformatted section$in_list = 0;				# am I inside a list$in_html = 0;				# am I inside an HTML section$first_line = 1;		        # is it the first line$dont_html = 0;				# don't protect HTML on thisline$split_num = 0;				# split index$deferred_ref = '';			# deferred reference for indexes@html_stack = ();			# HTML elements stack$html_element = '';			# current HTML element&html_reset;# build code for simple substitutions# the maps used (%simple_map and %things_map) MUST be aware of this# watch out for regexps, / and escaped characters!$subst_code = '';foreach (keys(%simple_map)) {    ($re = $_) =~ s/(\W)/\\$1/g; # protect regexp chars    $subst_code .= "s/\\\@$re/$simple_map{$_}/g;\n";}foreach (keys(%things_map)) {    $subst_code .= "s/\\\@$_\\{\\}/$things_map{$_}/g;\n";}if ($use_acc) {    # accentuated characters    foreach (keys(%accent_map)) {	if ($_ eq "`") {	    $subst_code .= "s/$;3";	} elsif ($_ eq "'") {	    $subst_code .= "s/$;4";	} else {	    $subst_code .= "s/\\\@\\$_";	}	$subst_code .= "([aeiou])/&\${1}$accent_map{$_};/gi;\n";    }}eval("sub simple_substitutions { $subst_code }");&init_input;while ($_ = &next_line) {    #    # remove \input on the first lines only    #    if ($first_line) {	next if /^\\input/;	$first_line = 0;    }    #    # parse texinfo tags

⌨️ 快捷键说明

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