home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / docs / misc / amigafaqg / bin / texi2html
Text File  |  1994-07-28  |  41KB  |  1,570 lines

  1. #!/usr/local/dist/bin/perl
  2. 'di';
  3. 'ig00';
  4. #+##############################################################################
  5. #                                                                              #
  6. # File: texi2html                                                              #
  7. #                                                                              #
  8. # Description: Program to transform most Texinfo documents to HTML             #
  9. #                                                                              #
  10. #-##############################################################################
  11.  
  12. # @(#)texi2html    1.29 04/21/94    Written by Lionel Cons, Lionel.Cons@cern.ch
  13.  
  14. # texi2html 1.29af 08.08.94   by Hans Maurer
  15. # Made some modifications for better compatability with AmigaFAQ
  16.  
  17. # The man page for this program is included at the end of this file and can be
  18. # viewed using the command 'nroff -man texi2html'.
  19. # Please read the copyright at the end of the man page.
  20.  
  21. #+++############################################################################
  22. #                                                                              #
  23. # Constants                                                                    #
  24. #                                                                              #
  25. #---############################################################################
  26.  
  27. $DEBUG_TOC = 1;
  28. $DEBUG_INDEX = 2;
  29. $DEBUG_BIB = 4;
  30. $DEBUG_GLOSS = 8;
  31. $DEBUG_DEF = 16;
  32.  
  33. $BIBRE = '\[[\w\/]+\]';            # RE for a bibliography reference
  34. $FILERE = '[\/\w.+-]+';            # RE for a file name
  35. $VARRE = '[^\s\{\}]+';            # RE for a variable name
  36. $NODERE = '[^@{}:\'`",]+';        # RE for a node name
  37. $NODESRE = '[^@{}:\'`"]+';        # RE for a list of node names
  38. $XREFRE = '[^@{}]+';            # RE for a xref (should use NODERE)
  39.  
  40. $THISPROG = "texi2html 1.29af";            # program name and version
  41. $TODAY = &pretty_date;            # like "20 September 1993"
  42. $SPLITTAG = "<!-- SPLIT HERE -->\n";    # tag to know where to split
  43. $PROTECTTAG = "_ThisIsProtected_";    # tag to recognize protected sections
  44.  
  45. #
  46. # language dependent constants
  47. #
  48. $LDC =
  49.     (
  50.      'xrefstring',     'see',
  51.      'Xrefstring',     'See',
  52.      'Footnotestring', 'Footnote',
  53.      'Chapterstring',  'Chapter',
  54.      'Appendixstring', 'Appendix',
  55.      'Sectionstring',  'Section',
  56.      'sectionstring',  'section',
  57.      'pagestring',     'page',
  58.      );
  59.  
  60. #
  61. # texinfo section names to level
  62. #
  63. %sec2level = (
  64.           'top', 0,
  65.           'chapter', 1,
  66.           'unnumbered', 1,
  67.           'majorheading', 1,
  68.           'chapheading', 1,
  69.           'appendix', 1,
  70.           'section', 2,
  71.           'unnumberedsec', 2,
  72.           'heading', 2,
  73.           'appendixsec', 2,
  74.           'appendixsection', 2,
  75.           'subsection', 3,
  76.           'unnumberedsubsec', 3,
  77.           'subheading', 3,
  78.           'appendixsubsec', 3,
  79.           'subsubsection', 4,
  80.           'unnumberedsubsubsec', 4,
  81.           'subsubheading', 4,
  82.           'appendixsubsubsec', 4,
  83.           );
  84.  
  85. #
  86. # texinfo "simple things" (@foo) to HTML ones
  87. #
  88. %simple_map = (
  89.            # cf. makeinfo.c
  90.            "*", "<BR>",        # HTML+
  91.            " ", " ",
  92.            "\n", "\n",
  93.            "|", "",
  94.            # spacing commands
  95.            ":", "",
  96.            "!", "!",
  97.            "?", "?",
  98.            ".", ".",
  99.            );
  100.  
  101. #
  102. # texinfo "things" (@foo{}) to HTML ones
  103. #
  104. %things_map = (
  105.            'TeX', 'TeX',
  106.            'br', '<P>',        # paragraph break
  107.            'bullet', '*',
  108.            'copyright', '(C)',
  109.            'dots', '...',
  110.            'equiv', '==',
  111.            'error', 'error-->',
  112.            'expansion', '==>',
  113.            'minus', '-',
  114.            'point', '-!-',
  115.            'print', '-|',
  116.            'result', '=>',
  117.            'today', $TODAY,
  118.            );
  119.  
  120. #
  121. # texinfo styles (@foo{bar}) to HTML ones
  122. #
  123. %style_map = (
  124.           'asis', '',
  125.           'b', 'B',
  126.           'cite', 'CITE',
  127.           'code', 'CODE',
  128.           'ctrl', '&do_ctrl',    # special case
  129.           'dfn', 'DFN',
  130.           'dmn', '',        # useless
  131.           'emph', 'EM',
  132.           'file', '"TT',        # will put quotes, cf. &apply_style
  133.           'i', 'I',
  134.           'kbd', 'KBD',
  135.           'key', 'KBD',
  136.           'r', '',            # unsupported
  137.           'samp', '"SAMP',        # will put quotes, cf. &apply_style
  138.           'sc', '&do_sc',        # special case
  139.           'subtitle', 'H2',
  140.           'strong', 'STRONG',
  141.           't', 'TT',
  142.           'title', 'H1',
  143.           'titlefont', '',        # useless
  144.           'var', 'VAR',
  145.           'w', '',            # unsupported
  146.           );
  147.  
  148. #
  149. # texinfo format (@foo/@end foo) to HTML ones
  150. #
  151. %format_map = (
  152.            'display', 'PRE',
  153.            'example', 'PRE',
  154.            'format', 'PRE',
  155.            'lisp', 'PRE',
  156.            'quotation', 'BLOCKQUOTE',
  157.            'smallexample', 'PRE',
  158.            'smalllisp', 'PRE',
  159.            # lists
  160.            'itemize', 'UL',
  161.            'enumerate', 'OL',
  162.            # poorly supported
  163.            'flushleft', 'PRE',
  164.            'flushright', 'PRE',
  165.            );
  166.  
  167. #
  168. # texinfo definition shortcuts to real ones
  169. #
  170. %def_map = (
  171.         # basic commands
  172.         'deffn', 0,
  173.         'defvr', 0,
  174.         'deftypefn', 0,
  175.         'deftypevr', 0,
  176.         'defcv', 0,
  177.         'defop', 0,
  178.         'deftp', 0,
  179.         # basic x commands
  180.         'deffnx', 0,
  181.         'defvrx', 0,
  182.         'deftypefnx', 0,
  183.         'deftypevrx', 0,
  184.         'defcvx', 0,
  185.         'defopx', 0,
  186.         'deftpx', 0,
  187.         # shortcuts
  188.         'defun', 'deffn Function',
  189.         'defmac', 'deffn Macro',
  190.         'defspec', 'deffn {Special Form}',
  191.         'defvar', 'defvr Variable',
  192.         'defopt', 'defvr {User Option}',
  193.         'deftypefun', 'deftypefn Function',
  194.         'deftypevar', 'deftypevr Variable',
  195.         'defivar', 'defcv {Instance Variable}',
  196.         'defmethod', 'defop Method',
  197.         # x shortcuts
  198.         'defunx', 'deffnx Function',
  199.         'defmacx', 'deffnx Macro',
  200.         'defspecx', 'deffnx {Special Form}',
  201.         'defvarx', 'defvrx Variable',
  202.         'defoptx', 'defvrx {User Option}',
  203.         'deftypefunx', 'deftypefnx Function',
  204.         'deftypevarx', 'deftypevrx Variable',
  205.         'defivarx', 'defcvx {Instance Variable}',
  206.         'defmethodx', 'defopx Method',
  207.         );
  208.  
  209. #
  210. # things to skip
  211. #
  212. %to_skip = (
  213.         # comments
  214.         'c', 1,
  215.         'comment', 1,
  216.         # useless
  217.         'contents', 1,
  218.         'shortcontents', 1,
  219.         'summarycontents', 1,
  220.         'footnotestyle', 1,
  221.         'end ifclear', 1,
  222.         'end ifset', 1,
  223.         'iftex', 1,
  224.         'end iftex', 1,
  225.         'parskip', 1,
  226.         'titlepage', 1,
  227.         'end titlepage', 1,
  228.         # unsupported commands (formatting)
  229.         'afourpaper', 1,
  230.         'cropmarks', 1,
  231.         'finalout', 1,
  232.         'headings', 1,
  233.         'need', 1,
  234.         'page', 1,
  235.         'setchapternewpage', 1,
  236.         'everyheading', 1,
  237.         'everyfooting', 1,
  238.         'evenheading', 1,
  239.         'evenfooting', 1,
  240.         'oddheading', 1,
  241.         'oddfooting', 1,
  242.         'smallbook', 1,
  243.         'vskip', 1,
  244.         # unsupported formats
  245.         'cartouche', 1,
  246.         'end cartouche', 1,
  247.         'group', 1,
  248.         'end group', 1,
  249.         # misc unsupported commands
  250.             'defindex', 1,
  251.         );
  252.  
  253. #+++############################################################################
  254. #                                                                              #
  255. # Argument parsing, initialisation                                             #
  256. #                                                                              #
  257. #---############################################################################
  258.  
  259. $invisible_mark = '';
  260. $use_bibliography = 1;
  261. $usage = <<EOT;
  262. This is $THISPROG
  263. To convert a Texinfo file to HMTL: $0 [options] file
  264.   where options can be:
  265.     -glossary      : handle a glossary
  266.     -invisible name: use name as an invisible anchor
  267.     -menu          : handle menus
  268.     -split_chapter : split on main sections
  269.     -split_node    : split on nodes
  270.     -usage         : print usage instructions
  271.     -verbose       : verbose output
  272. To check converted files: $0 -check [-verbose] files
  273. EOT
  274.  
  275. while ($_ = $ARGV[0], /^-/) {
  276.     shift;
  277.     if (/^-d(ebug)?(\d+)?$/) { $debug = $2 || shift; next; }
  278.     if (/^-c(heck)?$/)       { $check = 1; next; }
  279.     if (/^-g(lossary)?$/)    { $use_glossary = 1; next; }
  280.     if (/^-i(nvisible)?$/)   { $invisible_mark = shift; next; }
  281.     if (/^-iso$/)            { $use_iso = 1; next; }
  282.     if (/^-m(enu)?$/)        { $show_menu = 1; next; }
  283.     if (/^-s(plit)?_?(n(ode)?|c(hapter)?)?$/) {
  284.     if ($2 =~ /^n/) {
  285.         $split_node = 1;
  286.     } else {
  287.         $split_chapter = 1;
  288.     }
  289.     next;
  290.     }
  291.     if (/^-v(erbose)?$/)     { $verbose = 1; next;