ยปCore Development>Code coverage>Tools/scripts/texi2html.py

Python code coverage for Tools/scripts/texi2html.py

#countcontent
1n/a#! /usr/bin/env python3
2n/a
3n/a# Convert GNU texinfo files into HTML, one file per node.
4n/a# Based on Texinfo 2.14.
5n/a# Usage: texi2html [-d] [-d] [-c] inputfile outputdirectory
6n/a# The input file must be a complete texinfo file, e.g. emacs.texi.
7n/a# This creates many files (one per info node) in the output directory,
8n/a# overwriting existing files of the same name. All files created have
9n/a# ".html" as their extension.
10n/a
11n/a
12n/a# XXX To do:
13n/a# - handle @comment*** correctly
14n/a# - handle @xref {some words} correctly
15n/a# - handle @ftable correctly (items aren't indexed?)
16n/a# - handle @itemx properly
17n/a# - handle @exdent properly
18n/a# - add links directly to the proper line from indices
19n/a# - check against the definitive list of @-cmds; we still miss (among others):
20n/a# - @defindex (hard)
21n/a# - @c(omment) in the middle of a line (rarely used)
22n/a# - @this* (not really needed, only used in headers anyway)
23n/a# - @today{} (ever used outside title page?)
24n/a
25n/a# More consistent handling of chapters/sections/etc.
26n/a# Lots of documentation
27n/a# Many more options:
28n/a# -top designate top node
29n/a# -links customize which types of links are included
30n/a# -split split at chapters or sections instead of nodes
31n/a# -name Allow different types of filename handling. Non unix systems
32n/a# will have problems with long node names
33n/a# ...
34n/a# Support the most recent texinfo version and take a good look at HTML 3.0
35n/a# More debugging output (customizable) and more flexible error handling
36n/a# How about icons ?
37n/a
38n/a# rpyron 2002-05-07
39n/a# Robert Pyron <rpyron@alum.mit.edu>
40n/a# 1. BUGFIX: In function makefile(), strip blanks from the nodename.
41n/a# This is necessary to match the behavior of parser.makeref() and
42n/a# parser.do_node().
43n/a# 2. BUGFIX fixed KeyError in end_ifset (well, I may have just made
44n/a# it go away, rather than fix it)
45n/a# 3. BUGFIX allow @menu and menu items inside @ifset or @ifclear
46n/a# 4. Support added for:
47n/a# @uref URL reference
48n/a# @image image file reference (see note below)
49n/a# @multitable output an HTML table
50n/a# @vtable
51n/a# 5. Partial support for accents, to match MAKEINFO output
52n/a# 6. I added a new command-line option, '-H basename', to specify
53n/a# HTML Help output. This will cause three files to be created
54n/a# in the current directory:
55n/a# `basename`.hhp HTML Help Workshop project file
56n/a# `basename`.hhc Contents file for the project
57n/a# `basename`.hhk Index file for the project
58n/a# When fed into HTML Help Workshop, the resulting file will be
59n/a# named `basename`.chm.
60n/a# 7. A new class, HTMLHelp, to accomplish item 6.
61n/a# 8. Various calls to HTMLHelp functions.
62n/a# A NOTE ON IMAGES: Just as 'outputdirectory' must exist before
63n/a# running this program, all referenced images must already exist
64n/a# in outputdirectory.
65n/a
66n/aimport os
67n/aimport sys
68n/aimport string
69n/aimport re
70n/a
71n/aMAGIC = '\\input texinfo'
72n/a
73n/acmprog = re.compile('^@([a-z]+)([ \t]|$)') # Command (line-oriented)
74n/ablprog = re.compile('^[ \t]*$') # Blank line
75n/akwprog = re.compile('@[a-z]+') # Keyword (embedded, usually
76n/a # with {} args)
77n/aspprog = re.compile('[\n@{}&<>]') # Special characters in
78n/a # running text
79n/a #
80n/a # menu item (Yuck!)
81n/amiprog = re.compile(r'^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*')
82n/a# 0 1 1 2 3 34 42 0
83n/a# ----- ---------- ---------
84n/a# -|-----------------------------
85n/a# -----------------------------------------------------
86n/a
87n/a
88n/a
89n/a
90n/aclass HTMLNode:
91n/a """Some of the parser's functionality is separated into this class.
92n/a
93n/a A Node accumulates its contents, takes care of links to other Nodes
94n/a and saves itself when it is finished and all links are resolved.
95n/a """
96n/a
97n/a DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'
98n/a
99n/a type = 0
100n/a cont = ''
101n/a epilogue = '</BODY></HTML>\n'
102n/a
103n/a def __init__(self, dir, name, topname, title, next, prev, up):
104n/a self.dirname = dir
105n/a self.name = name
106n/a if topname:
107n/a self.topname = topname
108n/a else:
109n/a self.topname = name
110n/a self.title = title
111n/a self.next = next
112n/a self.prev = prev
113n/a self.up = up
114n/a self.lines = []
115n/a
116n/a def write(self, *lines):
117n/a for line in lines:
118n/a self.lines.append(line)
119n/a
120n/a def flush(self):
121n/a fp = open(self.dirname + '/' + makefile(self.name), 'w')
122n/a fp.write(self.prologue)
123n/a fp.write(self.text)
124n/a fp.write(self.epilogue)
125n/a fp.close()
126n/a
127n/a def link(self, label, nodename, rel=None, rev=None):
128n/a if nodename:
129n/a if nodename.lower() == '(dir)':
130n/a addr = '../dir.html'
131n/a title = ''
132n/a else:
133n/a addr = makefile(nodename)
134n/a title = ' TITLE="%s"' % nodename
135n/a self.write(label, ': <A HREF="', addr, '"', \
136n/a rel and (' REL=' + rel) or "", \
137n/a rev and (' REV=' + rev) or "", \
138n/a title, '>', nodename, '</A> \n')
139n/a
140n/a def finalize(self):
141n/a length = len(self.lines)
142n/a self.text = ''.join(self.lines)
143n/a self.lines = []
144n/a self.open_links()
145n/a self.output_links()
146n/a self.close_links()
147n/a links = ''.join(self.lines)
148n/a self.lines = []
149n/a self.prologue = (
150n/a self.DOCTYPE +
151n/a '\n<HTML><HEAD>\n'
152n/a ' <!-- Converted with texi2html and Python -->\n'
153n/a ' <TITLE>' + self.title + '</TITLE>\n'
154n/a ' <LINK REL=Next HREF="'
155n/a + makefile(self.next) + '" TITLE="' + self.next + '">\n'
156n/a ' <LINK REL=Previous HREF="'
157n/a + makefile(self.prev) + '" TITLE="' + self.prev + '">\n'
158n/a ' <LINK REL=Up HREF="'
159n/a + makefile(self.up) + '" TITLE="' + self.up + '">\n'
160n/a '</HEAD><BODY>\n' +
161n/a links)
162n/a if length > 20:
163n/a self.epilogue = '<P>\n%s</BODY></HTML>\n' % links
164n/a
165n/a def open_links(self):
166n/a self.write('<HR>\n')
167n/a
168n/a def close_links(self):
169n/a self.write('<HR>\n')
170n/a
171n/a def output_links(self):
172n/a if self.cont != self.next:
173n/a self.link(' Cont', self.cont)
174n/a self.link(' Next', self.next, rel='Next')
175n/a self.link(' Prev', self.prev, rel='Previous')
176n/a self.link(' Up', self.up, rel='Up')
177n/a if self.name != self.topname:
178n/a self.link(' Top', self.topname)
179n/a
180n/a
181n/aclass HTML3Node(HTMLNode):
182n/a
183n/a DOCTYPE = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML Level 3//EN//3.0">'
184n/a
185n/a def open_links(self):
186n/a self.write('<DIV CLASS=Navigation>\n <HR>\n')
187n/a
188n/a def close_links(self):
189n/a self.write(' <HR>\n</DIV>\n')
190n/a
191n/a
192n/aclass TexinfoParser:
193n/a
194n/a COPYRIGHT_SYMBOL = "&copy;"
195n/a FN_ID_PATTERN = "(%(id)s)"
196n/a FN_SOURCE_PATTERN = '<A NAME=footnoteref%(id)s' \
197n/a ' HREF="#footnotetext%(id)s">' \
198n/a + FN_ID_PATTERN + '</A>'
199n/a FN_TARGET_PATTERN = '<A NAME=footnotetext%(id)s' \
200n/a ' HREF="#footnoteref%(id)s">' \
201n/a + FN_ID_PATTERN + '</A>\n%(text)s<P>\n'
202n/a FN_HEADER = '\n<P>\n<HR NOSHADE SIZE=1 WIDTH=200>\n' \
203n/a '<STRONG><EM>Footnotes</EM></STRONG>\n<P>'
204n/a
205n/a
206n/a Node = HTMLNode
207n/a
208n/a # Initialize an instance
209n/a def __init__(self):
210n/a self.unknown = {} # statistics about unknown @-commands
211n/a self.filenames = {} # Check for identical filenames
212n/a self.debugging = 0 # larger values produce more output
213n/a self.print_headers = 0 # always print headers?
214n/a self.nodefp = None # open file we're writing to
215n/a self.nodelineno = 0 # Linenumber relative to node
216n/a self.links = None # Links from current node
217n/a self.savetext = None # If not None, save text head instead
218n/a self.savestack = [] # If not None, save text head instead
219n/a self.htmlhelp = None # html help data
220n/a self.dirname = 'tmp' # directory where files are created
221n/a self.includedir = '.' # directory to search @include files
222n/a self.nodename = '' # name of current node
223n/a self.topname = '' # name of top node (first node seen)
224n/a self.title = '' # title of this whole Texinfo tree
225n/a self.resetindex() # Reset all indices
226n/a self.contents = [] # Reset table of contents
227n/a self.numbering = [] # Reset section numbering counters
228n/a self.nofill = 0 # Normal operation: fill paragraphs
229n/a self.values={'html': 1} # Names that should be parsed in ifset
230n/a self.stackinfo={} # Keep track of state in the stack
231n/a # XXX The following should be reset per node?!
232n/a self.footnotes = [] # Reset list of footnotes
233n/a self.itemarg = None # Reset command used by @item
234n/a self.itemnumber = None # Reset number for @item in @enumerate
235n/a self.itemindex = None # Reset item index name
236n/a self.node = None
237n/a self.nodestack = []
238n/a self.cont = 0
239n/a self.includedepth = 0
240n/a
241n/a # Set htmlhelp helper class
242n/a def sethtmlhelp(self, htmlhelp):
243n/a self.htmlhelp = htmlhelp
244n/a
245n/a # Set (output) directory name
246n/a def setdirname(self, dirname):
247n/a self.dirname = dirname
248n/a
249n/a # Set include directory name
250n/a def setincludedir(self, includedir):
251n/a self.includedir = includedir
252n/a
253n/a # Parse the contents of an entire file
254n/a def parse(self, fp):
255n/a line = fp.readline()
256n/a lineno = 1
257n/a while line and (line[0] == '%' or blprog.match(line)):
258n/a line = fp.readline()
259n/a lineno = lineno + 1
260n/a if line[:len(MAGIC)] != MAGIC:
261n/a raise SyntaxError('file does not begin with %r' % (MAGIC,))
262n/a self.parserest(fp, lineno)
263n/a
264n/a # Parse the contents of a file, not expecting a MAGIC header
265n/a def parserest(self, fp, initial_lineno):
266n/a lineno = initial_lineno
267n/a self.done = 0
268n/a self.skip = 0
269n/a self.stack = []
270n/a accu = []
271n/a while not self.done:
272n/a line = fp.readline()
273n/a self.nodelineno = self.nodelineno + 1
274n/a if not line:
275n/a if accu:
276n/a if not self.skip: self.process(accu)
277n/a accu = []
278n/a if initial_lineno > 0:
279n/a print('*** EOF before @bye')
280n/a break
281n/a lineno = lineno + 1
282n/a mo = cmprog.match(line)
283n/a if mo:
284n/a a, b = mo.span(1)
285n/a cmd = line[a:b]
286n/a if cmd in ('noindent', 'refill'):
287n/a accu.append(line)
288n/a else:
289n/a if accu:
290n/a if not self.skip:
291n/a self.process(accu)
292n/a accu = []
293n/a self.command(line, mo)
294n/a elif blprog.match(line) and \
295n/a 'format' not in self.stack and \
296n/a 'example' not in self.stack:
297n/a if accu:
298n/a if not self.skip:
299n/a self.process(accu)
300n/a if self.nofill:
301n/a self.write('\n')
302n/a else:
303n/a self.write('<P>\n')
304n/a accu = []
305n/a else:
306n/a # Append the line including trailing \n!
307n/a accu.append(line)
308n/a #
309n/a if self.skip:
310n/a print('*** Still skipping at the end')
311n/a if self.stack:
312n/a print('*** Stack not empty at the end')
313n/a print('***', self.stack)
314n/a if self.includedepth == 0:
315n/a while self.nodestack:
316n/a self.nodestack[-1].finalize()
317n/a self.nodestack[-1].flush()
318n/a del self.nodestack[-1]
319n/a
320n/a # Start saving text in a buffer instead of writing it to a file
321n/a def startsaving(self):
322n/a if self.savetext is not None:
323n/a self.savestack.append(self.savetext)
324n/a # print '*** Recursively saving text, expect trouble'
325n/a self.savetext = ''
326n/a
327n/a # Return the text saved so far and start writing to file again
328n/a def collectsavings(self):
329n/a savetext = self.savetext
330n/a if len(self.savestack) > 0:
331n/a self.savetext = self.savestack[-1]
332n/a del self.savestack[-1]
333n/a else:
334n/a self.savetext = None
335n/a return savetext or ''
336n/a
337n/a # Write text to file, or save it in a buffer, or ignore it
338n/a def write(self, *args):
339n/a try:
340n/a text = ''.join(args)
341n/a except:
342n/a print(args)
343n/a raise TypeError
344n/a if self.savetext is not None:
345n/a self.savetext = self.savetext + text
346n/a elif self.nodefp:
347n/a self.nodefp.write(text)
348n/a elif self.node:
349n/a self.node.write(text)
350n/a
351n/a # Complete the current node -- write footnotes and close file
352n/a def endnode(self):
353n/a if self.savetext is not None:
354n/a print('*** Still saving text at end of node')
355n/a dummy = self.collectsavings()
356n/a if self.footnotes:
357n/a self.writefootnotes()
358n/a if self.nodefp:
359n/a if self.nodelineno > 20:
360n/a self.write('<HR>\n')
361n/a [name, next, prev, up] = self.nodelinks[:4]
362n/a self.link('Next', next)
363n/a self.link('Prev', prev)
364n/a self.link('Up', up)
365n/a if self.nodename != self.topname:
366n/a self.link('Top', self.topname)
367n/a self.write('<HR>\n')
368n/a self.write('</BODY>\n')
369n/a self.nodefp.close()
370n/a self.nodefp = None
371n/a elif self.node:
372n/a if not self.cont and \
373n/a (not self.node.type or \
374n/a (self.node.next and self.node.prev and self.node.up)):
375n/a self.node.finalize()
376n/a self.node.flush()
377n/a else:
378n/a self.nodestack.append(self.node)
379n/a self.node = None
380n/a self.nodename = ''
381n/a
382n/a # Process a list of lines, expanding embedded @-commands
383n/a # This mostly distinguishes between menus and normal text
384n/a def process(self, accu):
385n/a if self.debugging > 1:
386n/a print('!'*self.debugging, 'process:', self.skip, self.stack, end=' ')
387n/a if accu: print(accu[0][:30], end=' ')
388n/a if accu[0][30:] or accu[1:]: print('...', end=' ')
389n/a print()
390n/a if self.inmenu():
391n/a # XXX should be done differently
392n/a for line in accu:
393n/a mo = miprog.match(line)
394n/a if not mo:
395n/a line = line.strip() + '\n'
396n/a self.expand(line)
397n/a continue
398n/a bgn, end = mo.span(0)
399n/a a, b = mo.span(1)
400n/a c, d = mo.span(2)
401n/a e, f = mo.span(3)
402n/a g, h = mo.span(4)
403n/a label = line[a:b]
404n/a nodename = line[c:d]
405n/a if nodename[0] == ':': nodename = label
406n/a else: nodename = line[e:f]
407n/a punct = line[g:h]
408n/a self.write(' <LI><A HREF="',
409n/a makefile(nodename),
410n/a '">', nodename,
411n/a '</A>', punct, '\n')
412n/a self.htmlhelp.menuitem(nodename)
413n/a self.expand(line[end:])
414n/a else:
415n/a text = ''.join(accu)
416n/a self.expand(text)
417n/a
418n/a # find 'menu' (we might be inside 'ifset' or 'ifclear')
419n/a def inmenu(self):
420n/a #if 'menu' in self.stack:
421n/a # print 'inmenu :', self.skip, self.stack, self.stackinfo
422n/a stack = self.stack
423n/a while stack and stack[-1] in ('ifset','ifclear'):
424n/a try:
425n/a if self.stackinfo[len(stack)]:
426n/a return 0
427n/a except KeyError:
428n/a pass
429n/a stack = stack[:-1]
430n/a return (stack and stack[-1] == 'menu')
431n/a
432n/a # Write a string, expanding embedded @-commands
433n/a def expand(self, text):
434n/a stack = []
435n/a i = 0
436n/a n = len(text)
437n/a while i < n:
438n/a start = i
439n/a mo = spprog.search(text, i)
440n/a if mo:
441n/a i = mo.start()
442n/a else:
443n/a self.write(text[start:])
444n/a break
445n/a self.write(text[start:i])
446n/a c = text[i]
447n/a i = i+1
448n/a if c == '\n':
449n/a self.write('\n')
450n/a continue
451n/a if c == '<':
452n/a self.write('&lt;')
453n/a continue
454n/a if c == '>':
455n/a self.write('&gt;')
456n/a continue
457n/a if c == '&':
458n/a self.write('&amp;')
459n/a continue
460n/a if c == '{':
461n/a stack.append('')
462n/a continue
463n/a if c == '}':
464n/a if not stack:
465n/a print('*** Unmatched }')
466n/a self.write('}')
467n/a continue
468n/a cmd = stack[-1]
469n/a del stack[-1]
470n/a try:
471n/a method = getattr(self, 'close_' + cmd)
472n/a except AttributeError:
473n/a self.unknown_close(cmd)
474n/a continue
475n/a method()
476n/a continue
477n/a if c != '@':
478n/a # Cannot happen unless spprog is changed
479n/a raise RuntimeError('unexpected funny %r' % c)
480n/a start = i
481n/a while i < n and text[i] in string.ascii_letters: i = i+1
482n/a if i == start:
483n/a # @ plus non-letter: literal next character
484n/a i = i+1
485n/a c = text[start:i]
486n/a if c == ':':
487n/a # `@:' means no extra space after
488n/a # preceding `.', `?', `!' or `:'
489n/a pass
490n/a else:
491n/a # `@.' means a sentence-ending period;
492n/a # `@@', `@{', `@}' quote `@', `{', `}'
493n/a self.write(c)
494n/a continue
495n/a cmd = text[start:i]
496n/a if i < n and text[i] == '{':
497n/a i = i+1
498n/a stack.append(cmd)
499n/a try:
500n/a method = getattr(self, 'open_' + cmd)
501n/a except AttributeError:
502n/a self.unknown_open(cmd)
503n/a continue
504n/a method()
505n/a continue
506n/a try:
507n/a method = getattr(self, 'handle_' + cmd)
508n/a except AttributeError:
509n/a self.unknown_handle(cmd)
510n/a continue
511n/a method()
512n/a if stack:
513n/a print('*** Stack not empty at para:', stack)
514n/a
515n/a # --- Handle unknown embedded @-commands ---
516n/a
517n/a def unknown_open(self, cmd):
518n/a print('*** No open func for @' + cmd + '{...}')
519n/a cmd = cmd + '{'
520n/a self.write('@', cmd)
521n/a if cmd not in self.unknown:
522n/a self.unknown[cmd] = 1
523n/a else:
524n/a self.unknown[cmd] = self.unknown[cmd] + 1
525n/a
526n/a def unknown_close(self, cmd):
527n/a print('*** No close func for @' + cmd + '{...}')
528n/a cmd = '}' + cmd
529n/a self.write('}')
530n/a if cmd not in self.unknown:
531n/a self.unknown[cmd] = 1
532n/a else:
533n/a self.unknown[cmd] = self.unknown[cmd] + 1
534n/a
535n/a def unknown_handle(self, cmd):
536n/a print('*** No handler for @' + cmd)
537n/a self.write('@', cmd)
538n/a if cmd not in self.unknown:
539n/a self.unknown[cmd] = 1
540n/a else:
541n/a self.unknown[cmd] = self.unknown[cmd] + 1
542n/a
543n/a # XXX The following sections should be ordered as the texinfo docs
544n/a
545n/a # --- Embedded @-commands without {} argument list --
546n/a
547n/a def handle_noindent(self): pass
548n/a
549n/a def handle_refill(self): pass
550n/a
551n/a # --- Include file handling ---
552n/a
553n/a def do_include(self, args):
554n/a file = args
555n/a file = os.path.join(self.includedir, file)
556n/a try:
557n/a fp = open(file, 'r')
558n/a except IOError as msg:
559n/a print('*** Can\'t open include file', repr(file))
560n/a return
561n/a print('!'*self.debugging, '--> file', repr(file))
562n/a save_done = self.done
563n/a save_skip = self.skip
564n/a save_stack = self.stack
565n/a self.includedepth = self.includedepth + 1
566n/a self.parserest(fp, 0)
567n/a self.includedepth = self.includedepth - 1
568n/a fp.close()
569n/a self.done = save_done
570n/a self.skip = save_skip
571n/a self.stack = save_stack
572n/a print('!'*self.debugging, '<-- file', repr(file))
573n/a
574n/a # --- Special Insertions ---
575n/a
576n/a def open_dmn(self): pass
577n/a def close_dmn(self): pass
578n/a
579n/a def open_dots(self): self.write('...')
580n/a def close_dots(self): pass
581n/a
582n/a def open_bullet(self): pass
583n/a def close_bullet(self): pass
584n/a
585n/a def open_TeX(self): self.write('TeX')
586n/a def close_TeX(self): pass
587n/a
588n/a def handle_copyright(self): self.write(self.COPYRIGHT_SYMBOL)
589n/a def open_copyright(self): self.write(self.COPYRIGHT_SYMBOL)
590n/a def close_copyright(self): pass
591n/a
592n/a def open_minus(self): self.write('-')
593n/a def close_minus(self): pass
594n/a
595n/a # --- Accents ---
596n/a
597n/a # rpyron 2002-05-07
598n/a # I would like to do at least as well as makeinfo when
599n/a # it is producing HTML output:
600n/a #
601n/a # input output
602n/a # @"o @"o umlaut accent
603n/a # @'o 'o acute accent
604n/a # @,{c} @,{c} cedilla accent
605n/a # @=o @=o macron/overbar accent
606n/a # @^o @^o circumflex accent
607n/a # @`o `o grave accent
608n/a # @~o @~o tilde accent
609n/a # @dotaccent{o} @dotaccent{o} overdot accent
610n/a # @H{o} @H{o} long Hungarian umlaut
611n/a # @ringaccent{o} @ringaccent{o} ring accent
612n/a # @tieaccent{oo} @tieaccent{oo} tie-after accent
613n/a # @u{o} @u{o} breve accent
614n/a # @ubaraccent{o} @ubaraccent{o} underbar accent
615n/a # @udotaccent{o} @udotaccent{o} underdot accent
616n/a # @v{o} @v{o} hacek or check accent
617n/a # @exclamdown{} &#161; upside-down !
618n/a # @questiondown{} &#191; upside-down ?
619n/a # @aa{},@AA{} &#229;,&#197; a,A with circle
620n/a # @ae{},@AE{} &#230;,&#198; ae,AE ligatures
621n/a # @dotless{i} @dotless{i} dotless i
622n/a # @dotless{j} @dotless{j} dotless j
623n/a # @l{},@L{} l/,L/ suppressed-L,l
624n/a # @o{},@O{} &#248;,&#216; O,o with slash
625n/a # @oe{},@OE{} oe,OE oe,OE ligatures
626n/a # @ss{} &#223; es-zet or sharp S
627n/a #
628n/a # The following character codes and approximations have been
629n/a # copied from makeinfo's HTML output.
630n/a
631n/a def open_exclamdown(self): self.write('&#161;') # upside-down !
632n/a def close_exclamdown(self): pass
633n/a def open_questiondown(self): self.write('&#191;') # upside-down ?
634n/a def close_questiondown(self): pass
635n/a def open_aa(self): self.write('&#229;') # a with circle
636n/a def close_aa(self): pass
637n/a def open_AA(self): self.write('&#197;') # A with circle
638n/a def close_AA(self): pass
639n/a def open_ae(self): self.write('&#230;') # ae ligatures
640n/a def close_ae(self): pass
641n/a def open_AE(self): self.write('&#198;') # AE ligatures
642n/a def close_AE(self): pass
643n/a def open_o(self): self.write('&#248;') # o with slash
644n/a def close_o(self): pass
645n/a def open_O(self): self.write('&#216;') # O with slash
646n/a def close_O(self): pass
647n/a def open_ss(self): self.write('&#223;') # es-zet or sharp S
648n/a def close_ss(self): pass
649n/a def open_oe(self): self.write('oe') # oe ligatures
650n/a def close_oe(self): pass
651n/a def open_OE(self): self.write('OE') # OE ligatures
652n/a def close_OE(self): pass
653n/a def open_l(self): self.write('l/') # suppressed-l
654n/a def close_l(self): pass
655n/a def open_L(self): self.write('L/') # suppressed-L
656n/a def close_L(self): pass
657n/a
658n/a # --- Special Glyphs for Examples ---
659n/a
660n/a def open_result(self): self.write('=&gt;')
661n/a def close_result(self): pass
662n/a
663n/a def open_expansion(self): self.write('==&gt;')
664n/a def close_expansion(self): pass
665n/a
666n/a def open_print(self): self.write('-|')
667n/a def close_print(self): pass
668n/a
669n/a def open_error(self): self.write('error--&gt;')
670n/a def close_error(self): pass
671n/a
672n/a def open_equiv(self): self.write('==')
673n/a def close_equiv(self): pass
674n/a
675n/a def open_point(self): self.write('-!-')
676n/a def close_point(self): pass
677n/a
678n/a # --- Cross References ---
679n/a
680n/a def open_pxref(self):
681n/a self.write('see ')
682n/a self.startsaving()
683n/a def close_pxref(self):
684n/a self.makeref()
685n/a
686n/a def open_xref(self):
687n/a self.write('See ')
688n/a self.startsaving()
689n/a def close_xref(self):
690n/a self.makeref()
691n/a
692n/a def open_ref(self):
693n/a self.startsaving()
694n/a def close_ref(self):
695n/a self.makeref()
696n/a
697n/a def open_inforef(self):
698n/a self.write('See info file ')
699n/a self.startsaving()
700n/a def close_inforef(self):
701n/a text = self.collectsavings()
702n/a args = [s.strip() for s in text.split(',')]
703n/a while len(args) < 3: args.append('')
704n/a node = args[0]
705n/a file = args[2]
706n/a self.write('`', file, '\', node `', node, '\'')
707n/a
708n/a def makeref(self):
709n/a text = self.collectsavings()
710n/a args = [s.strip() for s in text.split(',')]
711n/a while len(args) < 5: args.append('')
712n/a nodename = label = args[0]
713n/a if args[2]: label = args[2]
714n/a file = args[3]
715n/a title = args[4]
716n/a href = makefile(nodename)
717n/a if file:
718n/a href = '../' + file + '/' + href
719n/a self.write('<A HREF="', href, '">', label, '</A>')
720n/a
721n/a # rpyron 2002-05-07 uref support
722n/a def open_uref(self):
723n/a self.startsaving()
724n/a def close_uref(self):
725n/a text = self.collectsavings()
726n/a args = [s.strip() for s in text.split(',')]
727n/a while len(args) < 2: args.append('')
728n/a href = args[0]
729n/a label = args[1]
730n/a if not label: label = href
731n/a self.write('<A HREF="', href, '">', label, '</A>')
732n/a
733n/a # rpyron 2002-05-07 image support
734n/a # GNU makeinfo producing HTML output tries `filename.png'; if
735n/a # that does not exist, it tries `filename.jpg'. If that does
736n/a # not exist either, it complains. GNU makeinfo does not handle
737n/a # GIF files; however, I include GIF support here because
738n/a # MySQL documentation uses GIF files.
739n/a
740n/a def open_image(self):
741n/a self.startsaving()
742n/a def close_image(self):
743n/a self.makeimage()
744n/a def makeimage(self):
745n/a text = self.collectsavings()
746n/a args = [s.strip() for s in text.split(',')]
747n/a while len(args) < 5: args.append('')
748n/a filename = args[0]
749n/a width = args[1]
750n/a height = args[2]
751n/a alt = args[3]
752n/a ext = args[4]
753n/a
754n/a # The HTML output will have a reference to the image
755n/a # that is relative to the HTML output directory,
756n/a # which is what 'filename' gives us. However, we need
757n/a # to find it relative to our own current directory,
758n/a # so we construct 'imagename'.
759n/a imagelocation = self.dirname + '/' + filename
760n/a
761n/a if os.path.exists(imagelocation+'.png'):
762n/a filename += '.png'
763n/a elif os.path.exists(imagelocation+'.jpg'):
764n/a filename += '.jpg'
765n/a elif os.path.exists(imagelocation+'.gif'): # MySQL uses GIF files
766n/a filename += '.gif'
767n/a else:
768n/a print("*** Cannot find image " + imagelocation)
769n/a #TODO: what is 'ext'?
770n/a self.write('<IMG SRC="', filename, '"', \
771n/a width and (' WIDTH="' + width + '"') or "", \
772n/a height and (' HEIGHT="' + height + '"') or "", \
773n/a alt and (' ALT="' + alt + '"') or "", \
774n/a '/>' )
775n/a self.htmlhelp.addimage(imagelocation)
776n/a
777n/a
778n/a # --- Marking Words and Phrases ---
779n/a
780n/a # --- Other @xxx{...} commands ---
781n/a
782n/a def open_(self): pass # Used by {text enclosed in braces}
783n/a def close_(self): pass
784n/a
785n/a open_asis = open_
786n/a close_asis = close_
787n/a
788n/a def open_cite(self): self.write('<CITE>')
789n/a def close_cite(self): self.write('</CITE>')
790n/a
791n/a def open_code(self): self.write('<CODE>')
792n/a def close_code(self): self.write('</CODE>')
793n/a
794n/a def open_t(self): self.write('<TT>')
795n/a def close_t(self): self.write('</TT>')
796n/a
797n/a def open_dfn(self): self.write('<DFN>')
798n/a def close_dfn(self): self.write('</DFN>')
799n/a
800n/a def open_emph(self): self.write('<EM>')
801n/a def close_emph(self): self.write('</EM>')
802n/a
803n/a def open_i(self): self.write('<I>')
804n/a def close_i(self): self.write('</I>')
805n/a
806n/a def open_footnote(self):
807n/a # if self.savetext is not None:
808n/a # print '*** Recursive footnote -- expect weirdness'
809n/a id = len(self.footnotes) + 1
810n/a self.write(self.FN_SOURCE_PATTERN % {'id': repr(id)})
811n/a self.startsaving()
812n/a
813n/a def close_footnote(self):
814n/a id = len(self.footnotes) + 1
815n/a self.footnotes.append((id, self.collectsavings()))
816n/a
817n/a def writefootnotes(self):
818n/a self.write(self.FN_HEADER)
819n/a for id, text in self.footnotes:
820n/a self.write(self.FN_TARGET_PATTERN
821n/a % {'id': repr(id), 'text': text})
822n/a self.footnotes = []
823n/a
824n/a def open_file(self): self.write('<CODE>')
825n/a def close_file(self): self.write('</CODE>')
826n/a
827n/a def open_kbd(self): self.write('<KBD>')
828n/a def close_kbd(self): self.write('</KBD>')
829n/a
830n/a def open_key(self): self.write('<KEY>')
831n/a def close_key(self): self.write('</KEY>')
832n/a
833n/a def open_r(self): self.write('<R>')
834n/a def close_r(self): self.write('</R>')
835n/a
836n/a def open_samp(self): self.write('`<SAMP>')
837n/a def close_samp(self): self.write('</SAMP>\'')
838n/a
839n/a def open_sc(self): self.write('<SMALLCAPS>')
840n/a def close_sc(self): self.write('</SMALLCAPS>')
841n/a
842n/a def open_strong(self): self.write('<STRONG>')
843n/a def close_strong(self): self.write('</STRONG>')
844n/a
845n/a def open_b(self): self.write('<B>')
846n/a def close_b(self): self.write('</B>')
847n/a
848n/a def open_var(self): self.write('<VAR>')
849n/a def close_var(self): self.write('</VAR>')
850n/a
851n/a def open_w(self): self.write('<NOBREAK>')
852n/a def close_w(self): self.write('</NOBREAK>')
853n/a
854n/a def open_url(self): self.startsaving()
855n/a def close_url(self):
856n/a text = self.collectsavings()
857n/a self.write('<A HREF="', text, '">', text, '</A>')
858n/a
859n/a def open_email(self): self.startsaving()
860n/a def close_email(self):
861n/a text = self.collectsavings()
862n/a self.write('<A HREF="mailto:', text, '">', text, '</A>')
863n/a
864n/a open_titlefont = open_
865n/a close_titlefont = close_
866n/a
867n/a def open_small(self): pass
868n/a def close_small(self): pass
869n/a
870n/a def command(self, line, mo):
871n/a a, b = mo.span(1)
872n/a cmd = line[a:b]
873n/a args = line[b:].strip()
874n/a if self.debugging > 1:
875n/a print('!'*self.debugging, 'command:', self.skip, self.stack, \
876n/a '@' + cmd, args)
877n/a try:
878n/a func = getattr(self, 'do_' + cmd)
879n/a except AttributeError:
880n/a try:
881n/a func = getattr(self, 'bgn_' + cmd)
882n/a except AttributeError:
883n/a # don't complain if we are skipping anyway
884n/a if not self.skip:
885n/a self.unknown_cmd(cmd, args)
886n/a return
887n/a self.stack.append(cmd)
888n/a func(args)
889n/a return
890n/a if not self.skip or cmd == 'end':
891n/a func(args)
892n/a
893n/a def unknown_cmd(self, cmd, args):
894n/a print('*** unknown', '@' + cmd, args)
895n/a if cmd not in self.unknown:
896n/a self.unknown[cmd] = 1
897n/a else:
898n/a self.unknown[cmd] = self.unknown[cmd] + 1
899n/a
900n/a def do_end(self, args):
901n/a words = args.split()
902n/a if not words:
903n/a print('*** @end w/o args')
904n/a else:
905n/a cmd = words[0]
906n/a if not self.stack or self.stack[-1] != cmd:
907n/a print('*** @end', cmd, 'unexpected')
908n/a else:
909n/a del self.stack[-1]
910n/a try:
911n/a func = getattr(self, 'end_' + cmd)
912n/a except AttributeError:
913n/a self.unknown_end(cmd)
914n/a return
915n/a func()
916n/a
917n/a def unknown_end(self, cmd):
918n/a cmd = 'end ' + cmd
919n/a print('*** unknown', '@' + cmd)
920n/a if cmd not in self.unknown:
921n/a self.unknown[cmd] = 1
922n/a else:
923n/a self.unknown[cmd] = self.unknown[cmd] + 1
924n/a
925n/a # --- Comments ---
926n/a
927n/a def do_comment(self, args): pass
928n/a do_c = do_comment
929n/a
930n/a # --- Conditional processing ---
931n/a
932n/a def bgn_ifinfo(self, args): pass
933n/a def end_ifinfo(self): pass
934n/a
935n/a def bgn_iftex(self, args): self.skip = self.skip + 1
936n/a def end_iftex(self): self.skip = self.skip - 1
937n/a
938n/a def bgn_ignore(self, args): self.skip = self.skip + 1
939n/a def end_ignore(self): self.skip = self.skip - 1
940n/a
941n/a def bgn_tex(self, args): self.skip = self.skip + 1
942n/a def end_tex(self): self.skip = self.skip - 1
943n/a
944n/a def do_set(self, args):
945n/a fields = args.split(' ')
946n/a key = fields[0]
947n/a if len(fields) == 1:
948n/a value = 1
949n/a else:
950n/a value = ' '.join(fields[1:])
951n/a self.values[key] = value
952n/a
953n/a def do_clear(self, args):
954n/a self.values[args] = None
955n/a
956n/a def bgn_ifset(self, args):
957n/a if args not in self.values or self.values[args] is None:
958n/a self.skip = self.skip + 1
959n/a self.stackinfo[len(self.stack)] = 1
960n/a else:
961n/a self.stackinfo[len(self.stack)] = 0
962n/a def end_ifset(self):
963n/a try:
964n/a if self.stackinfo[len(self.stack) + 1]:
965n/a self.skip = self.skip - 1
966n/a del self.stackinfo[len(self.stack) + 1]
967n/a except KeyError:
968n/a print('*** end_ifset: KeyError :', len(self.stack) + 1)
969n/a
970n/a def bgn_ifclear(self, args):
971n/a if args in self.values and self.values[args] is not None:
972n/a self.skip = self.skip + 1
973n/a self.stackinfo[len(self.stack)] = 1
974n/a else:
975n/a self.stackinfo[len(self.stack)] = 0
976n/a def end_ifclear(self):
977n/a try:
978n/a if self.stackinfo[len(self.stack) + 1]:
979n/a self.skip = self.skip - 1
980n/a del self.stackinfo[len(self.stack) + 1]
981n/a except KeyError:
982n/a print('*** end_ifclear: KeyError :', len(self.stack) + 1)
983n/a
984n/a def open_value(self):
985n/a self.startsaving()
986n/a
987n/a def close_value(self):
988n/a key = self.collectsavings()
989n/a if key in self.values:
990n/a self.write(self.values[key])
991n/a else:
992n/a print('*** Undefined value: ', key)
993n/a
994n/a # --- Beginning a file ---
995n/a
996n/a do_finalout = do_comment
997n/a do_setchapternewpage = do_comment
998n/a do_setfilename = do_comment
999n/a
1000n/a def do_settitle(self, args):
1001n/a self.startsaving()
1002n/a self.expand(args)
1003n/a self.title = self.collectsavings()
1004n/a def do_parskip(self, args): pass
1005n/a
1006n/a # --- Ending a file ---
1007n/a
1008n/a def do_bye(self, args):
1009n/a self.endnode()
1010n/a self.done = 1
1011n/a
1012n/a # --- Title page ---
1013n/a
1014n/a def bgn_titlepage(self, args): self.skip = self.skip + 1
1015n/a def end_titlepage(self): self.skip = self.skip - 1
1016n/a def do_shorttitlepage(self, args): pass
1017n/a
1018n/a def do_center(self, args):
1019n/a # Actually not used outside title page...
1020n/a self.write('<H1>')
1021n/a self.expand(args)
1022n/a self.write('</H1>\n')
1023n/a do_title = do_center
1024n/a do_subtitle = do_center
1025n/a do_author = do_center
1026n/a
1027n/a do_vskip = do_comment
1028n/a do_vfill = do_comment
1029n/a do_smallbook = do_comment
1030n/a
1031n/a do_paragraphindent = do_comment
1032n/a do_setchapternewpage = do_comment
1033n/a do_headings = do_comment
1034n/a do_footnotestyle = do_comment
1035n/a
1036n/a do_evenheading = do_comment
1037n/a do_evenfooting = do_comment
1038n/a do_oddheading = do_comment
1039n/a do_oddfooting = do_comment
1040n/a do_everyheading = do_comment
1041n/a do_everyfooting = do_comment
1042n/a
1043n/a # --- Nodes ---
1044n/a
1045n/a def do_node(self, args):
1046n/a self.endnode()
1047n/a self.nodelineno = 0
1048n/a parts = [s.strip() for s in args.split(',')]
1049n/a while len(parts) < 4: parts.append('')
1050n/a self.nodelinks = parts
1051n/a [name, next, prev, up] = parts[:4]
1052n/a file = self.dirname + '/' + makefile(name)
1053n/a if file in self.filenames:
1054n/a print('*** Filename already in use: ', file)
1055n/a else:
1056n/a if self.debugging: print('!'*self.debugging, '--- writing', file)
1057n/a self.filenames[file] = 1
1058n/a # self.nodefp = open(file, 'w')
1059n/a self.nodename = name
1060n/a if self.cont and self.nodestack:
1061n/a self.nodestack[-1].cont = self.nodename
1062n/a if not self.topname: self.topname = name
1063n/a title = name
1064n/a if self.title: title = title + ' -- ' + self.title
1065n/a self.node = self.Node(self.dirname, self.nodename, self.topname,
1066n/a title, next, prev, up)
1067n/a self.htmlhelp.addnode(self.nodename,next,prev,up,file)
1068n/a
1069n/a def link(self, label, nodename):
1070n/a if nodename:
1071n/a if nodename.lower() == '(dir)':
1072n/a addr = '../dir.html'
1073n/a else:
1074n/a addr = makefile(nodename)
1075n/a self.write(label, ': <A HREF="', addr, '" TYPE="',
1076n/a label, '">', nodename, '</A> \n')
1077n/a
1078n/a # --- Sectioning commands ---
1079n/a
1080n/a def popstack(self, type):
1081n/a if (self.node):
1082n/a self.node.type = type
1083n/a while self.nodestack:
1084n/a if self.nodestack[-1].type > type:
1085n/a self.nodestack[-1].finalize()
1086n/a self.nodestack[-1].flush()
1087n/a del self.nodestack[-1]
1088n/a elif self.nodestack[-1].type == type:
1089n/a if not self.nodestack[-1].next:
1090n/a self.nodestack[-1].next = self.node.name
1091n/a if not self.node.prev:
1092n/a self.node.prev = self.nodestack[-1].name
1093n/a self.nodestack[-1].finalize()
1094n/a self.nodestack[-1].flush()
1095n/a del self.nodestack[-1]
1096n/a else:
1097n/a if type > 1 and not self.node.up:
1098n/a self.node.up = self.nodestack[-1].name
1099n/a break
1100n/a
1101n/a def do_chapter(self, args):
1102n/a self.heading('H1', args, 0)
1103n/a self.popstack(1)
1104n/a
1105n/a def do_unnumbered(self, args):
1106n/a self.heading('H1', args, -1)
1107n/a self.popstack(1)
1108n/a def do_appendix(self, args):
1109n/a self.heading('H1', args, -1)
1110n/a self.popstack(1)
1111n/a def do_top(self, args):
1112n/a self.heading('H1', args, -1)
1113n/a def do_chapheading(self, args):
1114n/a self.heading('H1', args, -1)
1115n/a def do_majorheading(self, args):
1116n/a self.heading('H1', args, -1)
1117n/a
1118n/a def do_section(self, args):
1119n/a self.heading('H1', args, 1)
1120n/a self.popstack(2)
1121n/a
1122n/a def do_unnumberedsec(self, args):
1123n/a self.heading('H1', args, -1)
1124n/a self.popstack(2)
1125n/a def do_appendixsec(self, args):
1126n/a self.heading('H1', args, -1)
1127n/a self.popstack(2)
1128n/a do_appendixsection = do_appendixsec
1129n/a def do_heading(self, args):
1130n/a self.heading('H1', args, -1)
1131n/a
1132n/a def do_subsection(self, args):
1133n/a self.heading('H2', args, 2)
1134n/a self.popstack(3)
1135n/a def do_unnumberedsubsec(self, args):
1136n/a self.heading('H2', args, -1)
1137n/a self.popstack(3)
1138n/a def do_appendixsubsec(self, args):
1139n/a self.heading('H2', args, -1)
1140n/a self.popstack(3)
1141n/a def do_subheading(self, args):
1142n/a self.heading('H2', args, -1)
1143n/a
1144n/a def do_subsubsection(self, args):
1145n/a self.heading('H3', args, 3)
1146n/a self.popstack(4)
1147n/a def do_unnumberedsubsubsec(self, args):
1148n/a self.heading('H3', args, -1)
1149n/a self.popstack(4)
1150n/a def do_appendixsubsubsec(self, args):
1151n/a self.heading('H3', args, -1)
1152n/a self.popstack(4)
1153n/a def do_subsubheading(self, args):
1154n/a self.heading('H3', args, -1)
1155n/a
1156n/a def heading(self, type, args, level):
1157n/a if level >= 0:
1158n/a while len(self.numbering) <= level:
1159n/a self.numbering.append(0)
1160n/a del self.numbering[level+1:]
1161n/a self.numbering[level] = self.numbering[level] + 1
1162n/a x = ''
1163n/a for i in self.numbering:
1164n/a x = x + repr(i) + '.'
1165n/a args = x + ' ' + args
1166n/a self.contents.append((level, args, self.nodename))
1167n/a self.write('<', type, '>')
1168n/a self.expand(args)
1169n/a self.write('</', type, '>\n')
1170n/a if self.debugging or self.print_headers:
1171n/a print('---', args)
1172n/a
1173n/a def do_contents(self, args):
1174n/a # pass
1175n/a self.listcontents('Table of Contents', 999)
1176n/a
1177n/a def do_shortcontents(self, args):
1178n/a pass
1179n/a # self.listcontents('Short Contents', 0)
1180n/a do_summarycontents = do_shortcontents
1181n/a
1182n/a def listcontents(self, title, maxlevel):
1183n/a self.write('<H1>', title, '</H1>\n<UL COMPACT PLAIN>\n')
1184n/a prevlevels = [0]
1185n/a for level, title, node in self.contents:
1186n/a if level > maxlevel:
1187n/a continue
1188n/a if level > prevlevels[-1]:
1189n/a # can only advance one level at a time
1190n/a self.write(' '*prevlevels[-1], '<UL PLAIN>\n')
1191n/a prevlevels.append(level)
1192n/a elif level < prevlevels[-1]:
1193n/a # might drop back multiple levels
1194n/a while level < prevlevels[-1]:
1195n/a del prevlevels[-1]
1196n/a self.write(' '*prevlevels[-1],
1197n/a '</UL>\n')
1198n/a self.write(' '*level, '<LI> <A HREF="',
1199n/a makefile(node), '">')
1200n/a self.expand(title)
1201n/a self.write('</A>\n')
1202n/a self.write('</UL>\n' * len(prevlevels))
1203n/a
1204n/a # --- Page lay-out ---
1205n/a
1206n/a # These commands are only meaningful in printed text
1207n/a
1208n/a def do_page(self, args): pass
1209n/a
1210n/a def do_need(self, args): pass
1211n/a
1212n/a def bgn_group(self, args): pass
1213n/a def end_group(self): pass
1214n/a
1215n/a # --- Line lay-out ---
1216n/a
1217n/a def do_sp(self, args):
1218n/a if self.nofill:
1219n/a self.write('\n')
1220n/a else:
1221n/a self.write('<P>\n')
1222n/a
1223n/a def do_hline(self, args):
1224n/a self.write('<HR>')
1225n/a
1226n/a # --- Function and variable definitions ---
1227n/a
1228n/a def bgn_deffn(self, args):
1229n/a self.write('<DL>')
1230n/a self.do_deffnx(args)
1231n/a
1232n/a def end_deffn(self):
1233n/a self.write('</DL>\n')
1234n/a
1235n/a def do_deffnx(self, args):
1236n/a self.write('<DT>')
1237n/a words = splitwords(args, 2)
1238n/a [category, name], rest = words[:2], words[2:]
1239n/a self.expand('@b{%s}' % name)
1240n/a for word in rest: self.expand(' ' + makevar(word))
1241n/a #self.expand(' -- ' + category)
1242n/a self.write('\n<DD>')
1243n/a self.index('fn', name)
1244n/a
1245n/a def bgn_defun(self, args): self.bgn_deffn('Function ' + args)
1246n/a end_defun = end_deffn
1247n/a def do_defunx(self, args): self.do_deffnx('Function ' + args)
1248n/a
1249n/a def bgn_defmac(self, args): self.bgn_deffn('Macro ' + args)
1250n/a end_defmac = end_deffn
1251n/a def do_defmacx(self, args): self.do_deffnx('Macro ' + args)
1252n/a
1253n/a def bgn_defspec(self, args): self.bgn_deffn('{Special Form} ' + args)
1254n/a end_defspec = end_deffn
1255n/a def do_defspecx(self, args): self.do_deffnx('{Special Form} ' + args)
1256n/a
1257n/a def bgn_defvr(self, args):
1258n/a self.write('<DL>')
1259n/a self.do_defvrx(args)
1260n/a
1261n/a end_defvr = end_deffn
1262n/a
1263n/a def do_defvrx(self, args):
1264n/a self.write('<DT>')
1265n/a words = splitwords(args, 2)
1266n/a [category, name], rest = words[:2], words[2:]
1267n/a self.expand('@code{%s}' % name)
1268n/a # If there are too many arguments, show them
1269n/a for word in rest: self.expand(' ' + word)
1270n/a #self.expand(' -- ' + category)
1271n/a self.write('\n<DD>')
1272n/a self.index('vr', name)
1273n/a
1274n/a def bgn_defvar(self, args): self.bgn_defvr('Variable ' + args)
1275n/a end_defvar = end_defvr
1276n/a def do_defvarx(self, args): self.do_defvrx('Variable ' + args)
1277n/a
1278n/a def bgn_defopt(self, args): self.bgn_defvr('{User Option} ' + args)
1279n/a end_defopt = end_defvr
1280n/a def do_defoptx(self, args): self.do_defvrx('{User Option} ' + args)
1281n/a
1282n/a # --- Ditto for typed languages ---
1283n/a
1284n/a def bgn_deftypefn(self, args):
1285n/a self.write('<DL>')
1286n/a self.do_deftypefnx(args)
1287n/a
1288n/a end_deftypefn = end_deffn
1289n/a
1290n/a def do_deftypefnx(self, args):
1291n/a self.write('<DT>')
1292n/a words = splitwords(args, 3)
1293n/a [category, datatype, name], rest = words[:3], words[3:]
1294n/a self.expand('@code{%s} @b{%s}' % (datatype, name))
1295n/a for word in rest: self.expand(' ' + makevar(word))
1296n/a #self.expand(' -- ' + category)
1297n/a self.write('\n<DD>')
1298n/a self.index('fn', name)
1299n/a
1300n/a
1301n/a def bgn_deftypefun(self, args): self.bgn_deftypefn('Function ' + args)
1302n/a end_deftypefun = end_deftypefn
1303n/a def do_deftypefunx(self, args): self.do_deftypefnx('Function ' + args)
1304n/a
1305n/a def bgn_deftypevr(self, args):
1306n/a self.write('<DL>')
1307n/a self.do_deftypevrx(args)
1308n/a
1309n/a end_deftypevr = end_deftypefn
1310n/a
1311n/a def do_deftypevrx(self, args):
1312n/a self.write('<DT>')
1313n/a words = splitwords(args, 3)
1314n/a [category, datatype, name], rest = words[:3], words[3:]
1315n/a self.expand('@code{%s} @b{%s}' % (datatype, name))
1316n/a # If there are too many arguments, show them
1317n/a for word in rest: self.expand(' ' + word)
1318n/a #self.expand(' -- ' + category)
1319n/a self.write('\n<DD>')
1320n/a self.index('fn', name)
1321n/a
1322n/a def bgn_deftypevar(self, args):
1323n/a self.bgn_deftypevr('Variable ' + args)
1324n/a end_deftypevar = end_deftypevr
1325n/a def do_deftypevarx(self, args):
1326n/a self.do_deftypevrx('Variable ' + args)
1327n/a
1328n/a # --- Ditto for object-oriented languages ---
1329n/a
1330n/a def bgn_defcv(self, args):
1331n/a self.write('<DL>')
1332n/a self.do_defcvx(args)
1333n/a
1334n/a end_defcv = end_deftypevr
1335n/a
1336n/a def do_defcvx(self, args):
1337n/a self.write('<DT>')
1338n/a words = splitwords(args, 3)
1339n/a [category, classname, name], rest = words[:3], words[3:]
1340n/a self.expand('@b{%s}' % name)
1341n/a # If there are too many arguments, show them
1342n/a for word in rest: self.expand(' ' + word)
1343n/a #self.expand(' -- %s of @code{%s}' % (category, classname))
1344n/a self.write('\n<DD>')
1345n/a self.index('vr', '%s @r{on %s}' % (name, classname))
1346n/a
1347n/a def bgn_defivar(self, args):
1348n/a self.bgn_defcv('{Instance Variable} ' + args)
1349n/a end_defivar = end_defcv
1350n/a def do_defivarx(self, args):
1351n/a self.do_defcvx('{Instance Variable} ' + args)
1352n/a
1353n/a def bgn_defop(self, args):
1354n/a self.write('<DL>')
1355n/a self.do_defopx(args)
1356n/a
1357n/a end_defop = end_defcv
1358n/a
1359n/a def do_defopx(self, args):
1360n/a self.write('<DT>')
1361n/a words = splitwords(args, 3)
1362n/a [category, classname, name], rest = words[:3], words[3:]
1363n/a self.expand('@b{%s}' % name)
1364n/a for word in rest: self.expand(' ' + makevar(word))
1365n/a #self.expand(' -- %s of @code{%s}' % (category, classname))
1366n/a self.write('\n<DD>')
1367n/a self.index('fn', '%s @r{on %s}' % (name, classname))
1368n/a
1369n/a def bgn_defmethod(self, args):
1370n/a self.bgn_defop('Method ' + args)
1371n/a end_defmethod = end_defop
1372n/a def do_defmethodx(self, args):
1373n/a self.do_defopx('Method ' + args)
1374n/a
1375n/a # --- Ditto for data types ---
1376n/a
1377n/a def bgn_deftp(self, args):
1378n/a self.write('<DL>')
1379n/a self.do_deftpx(args)
1380n/a
1381n/a end_deftp = end_defcv
1382n/a
1383n/a def do_deftpx(self, args):
1384n/a self.write('<DT>')
1385n/a words = splitwords(args, 2)
1386n/a [category, name], rest = words[:2], words[2:]
1387n/a self.expand('@b{%s}' % name)
1388n/a for word in rest: self.expand(' ' + word)
1389n/a #self.expand(' -- ' + category)
1390n/a self.write('\n<DD>')
1391n/a self.index('tp', name)
1392n/a
1393n/a # --- Making Lists and Tables
1394n/a
1395n/a def bgn_enumerate(self, args):
1396n/a if not args:
1397n/a self.write('<OL>\n')
1398n/a self.stackinfo[len(self.stack)] = '</OL>\n'
1399n/a else:
1400n/a self.itemnumber = args
1401n/a self.write('<UL>\n')
1402n/a self.stackinfo[len(self.stack)] = '</UL>\n'
1403n/a def end_enumerate(self):
1404n/a self.itemnumber = None
1405n/a self.write(self.stackinfo[len(self.stack) + 1])
1406n/a del self.stackinfo[len(self.stack) + 1]
1407n/a
1408n/a def bgn_itemize(self, args):
1409n/a self.itemarg = args
1410n/a self.write('<UL>\n')
1411n/a def end_itemize(self):
1412n/a self.itemarg = None
1413n/a self.write('</UL>\n')
1414n/a
1415n/a def bgn_table(self, args):
1416n/a self.itemarg = args
1417n/a self.write('<DL>\n')
1418n/a def end_table(self):
1419n/a self.itemarg = None
1420n/a self.write('</DL>\n')
1421n/a
1422n/a def bgn_ftable(self, args):
1423n/a self.itemindex = 'fn'
1424n/a self.bgn_table(args)
1425n/a def end_ftable(self):
1426n/a self.itemindex = None
1427n/a self.end_table()
1428n/a
1429n/a def bgn_vtable(self, args):
1430n/a self.itemindex = 'vr'
1431n/a self.bgn_table(args)
1432n/a def end_vtable(self):
1433n/a self.itemindex = None
1434n/a self.end_table()
1435n/a
1436n/a def do_item(self, args):
1437n/a if self.itemindex: self.index(self.itemindex, args)
1438n/a if self.itemarg:
1439n/a if self.itemarg[0] == '@' and self.itemarg[1] and \
1440n/a self.itemarg[1] in string.ascii_letters:
1441n/a args = self.itemarg + '{' + args + '}'
1442n/a else:
1443n/a # some other character, e.g. '-'
1444n/a args = self.itemarg + ' ' + args
1445n/a if self.itemnumber is not None:
1446n/a args = self.itemnumber + '. ' + args
1447n/a self.itemnumber = increment(self.itemnumber)
1448n/a if self.stack and self.stack[-1] == 'table':
1449n/a self.write('<DT>')
1450n/a self.expand(args)
1451n/a self.write('\n<DD>')
1452n/a elif self.stack and self.stack[-1] == 'multitable':
1453n/a self.write('<TR><TD>')
1454n/a self.expand(args)
1455n/a self.write('</TD>\n</TR>\n')
1456n/a else:
1457n/a self.write('<LI>')
1458n/a self.expand(args)
1459n/a self.write(' ')
1460n/a do_itemx = do_item # XXX Should suppress leading blank line
1461n/a
1462n/a # rpyron 2002-05-07 multitable support
1463n/a def bgn_multitable(self, args):
1464n/a self.itemarg = None # should be handled by columnfractions
1465n/a self.write('<TABLE BORDER="">\n')
1466n/a def end_multitable(self):
1467n/a self.itemarg = None
1468n/a self.write('</TABLE>\n<BR>\n')
1469n/a def handle_columnfractions(self):
1470n/a # It would be better to handle this, but for now it's in the way...
1471n/a self.itemarg = None
1472n/a def handle_tab(self):
1473n/a self.write('</TD>\n <TD>')
1474n/a
1475n/a # --- Enumerations, displays, quotations ---
1476n/a # XXX Most of these should increase the indentation somehow
1477n/a
1478n/a def bgn_quotation(self, args): self.write('<BLOCKQUOTE>')
1479n/a def end_quotation(self): self.write('</BLOCKQUOTE>\n')
1480n/a
1481n/a def bgn_example(self, args):
1482n/a self.nofill = self.nofill + 1
1483n/a self.write('<PRE>')
1484n/a def end_example(self):
1485n/a self.write('</PRE>\n')
1486n/a self.nofill = self.nofill - 1
1487n/a
1488n/a bgn_lisp = bgn_example # Synonym when contents are executable lisp code
1489n/a end_lisp = end_example
1490n/a
1491n/a bgn_smallexample = bgn_example # XXX Should use smaller font
1492n/a end_smallexample = end_example
1493n/a
1494n/a bgn_smalllisp = bgn_lisp # Ditto
1495n/a end_smalllisp = end_lisp
1496n/a
1497n/a bgn_display = bgn_example
1498n/a end_display = end_example
1499n/a
1500n/a bgn_format = bgn_display
1501n/a end_format = end_display
1502n/a
1503n/a def do_exdent(self, args): self.expand(args + '\n')
1504n/a # XXX Should really mess with indentation
1505n/a
1506n/a def bgn_flushleft(self, args):
1507n/a self.nofill = self.nofill + 1
1508n/a self.write('<PRE>\n')
1509n/a def end_flushleft(self):
1510n/a self.write('</PRE>\n')
1511n/a self.nofill = self.nofill - 1
1512n/a
1513n/a def bgn_flushright(self, args):
1514n/a self.nofill = self.nofill + 1
1515n/a self.write('<ADDRESS COMPACT>\n')
1516n/a def end_flushright(self):
1517n/a self.write('</ADDRESS>\n')
1518n/a self.nofill = self.nofill - 1
1519n/a
1520n/a def bgn_menu(self, args):
1521n/a self.write('<DIR>\n')
1522n/a self.write(' <STRONG><EM>Menu</EM></STRONG><P>\n')
1523n/a self.htmlhelp.beginmenu()
1524n/a def end_menu(self):
1525n/a self.write('</DIR>\n')
1526n/a self.htmlhelp.endmenu()
1527n/a
1528n/a def bgn_cartouche(self, args): pass
1529n/a def end_cartouche(self): pass
1530n/a
1531n/a # --- Indices ---
1532n/a
1533n/a def resetindex(self):
1534n/a self.noncodeindices = ['cp']
1535n/a self.indextitle = {}
1536n/a self.indextitle['cp'] = 'Concept'
1537n/a self.indextitle['fn'] = 'Function'
1538n/a self.indextitle['ky'] = 'Keyword'
1539n/a self.indextitle['pg'] = 'Program'
1540n/a self.indextitle['tp'] = 'Type'
1541n/a self.indextitle['vr'] = 'Variable'
1542n/a #
1543n/a self.whichindex = {}
1544n/a for name in self.indextitle:
1545n/a self.whichindex[name] = []
1546n/a
1547n/a def user_index(self, name, args):
1548n/a if name in self.whichindex:
1549n/a self.index(name, args)
1550n/a else:
1551n/a print('*** No index named', repr(name))
1552n/a
1553n/a def do_cindex(self, args): self.index('cp', args)
1554n/a def do_findex(self, args): self.index('fn', args)
1555n/a def do_kindex(self, args): self.index('ky', args)
1556n/a def do_pindex(self, args): self.index('pg', args)
1557n/a def do_tindex(self, args): self.index('tp', args)
1558n/a def do_vindex(self, args): self.index('vr', args)
1559n/a
1560n/a def index(self, name, args):
1561n/a self.whichindex[name].append((args, self.nodename))
1562n/a self.htmlhelp.index(args, self.nodename)
1563n/a
1564n/a def do_synindex(self, args):
1565n/a words = args.split()
1566n/a if len(words) != 2:
1567n/a print('*** bad @synindex', args)
1568n/a return
1569n/a [old, new] = words
1570n/a if old not in self.whichindex or \
1571n/a new not in self.whichindex:
1572n/a print('*** bad key(s) in @synindex', args)
1573n/a return
1574n/a if old != new and \
1575n/a self.whichindex[old] is not self.whichindex[new]:
1576n/a inew = self.whichindex[new]
1577n/a inew[len(inew):] = self.whichindex[old]
1578n/a self.whichindex[old] = inew
1579n/a do_syncodeindex = do_synindex # XXX Should use code font
1580n/a
1581n/a def do_printindex(self, args):
1582n/a words = args.split()
1583n/a for name in words:
1584n/a if name in self.whichindex:
1585n/a self.prindex(name)
1586n/a else:
1587n/a print('*** No index named', repr(name))
1588n/a
1589n/a def prindex(self, name):
1590n/a iscodeindex = (name not in self.noncodeindices)
1591n/a index = self.whichindex[name]
1592n/a if not index: return
1593n/a if self.debugging:
1594n/a print('!'*self.debugging, '--- Generating', \
1595n/a self.indextitle[name], 'index')
1596n/a # The node already provides a title
1597n/a index1 = []
1598n/a junkprog = re.compile('^(@[a-z]+)?{')
1599n/a for key, node in index:
1600n/a sortkey = key.lower()
1601n/a # Remove leading `@cmd{' from sort key
1602n/a # -- don't bother about the matching `}'
1603n/a oldsortkey = sortkey
1604n/a while 1:
1605n/a mo = junkprog.match(sortkey)
1606n/a if not mo:
1607n/a break
1608n/a i = mo.end()
1609n/a sortkey = sortkey[i:]
1610n/a index1.append((sortkey, key, node))
1611n/a del index[:]
1612n/a index1.sort()
1613n/a self.write('<DL COMPACT>\n')
1614n/a prevkey = prevnode = None
1615n/a for sortkey, key, node in index1:
1616n/a if (key, node) == (prevkey, prevnode):
1617n/a continue
1618n/a if self.debugging > 1: print('!'*self.debugging, key, ':', node)
1619n/a self.write('<DT>')
1620n/a if iscodeindex: key = '@code{' + key + '}'
1621n/a if key != prevkey:
1622n/a self.expand(key)
1623n/a self.write('\n<DD><A HREF="%s">%s</A>\n' % (makefile(node), node))
1624n/a prevkey, prevnode = key, node
1625n/a self.write('</DL>\n')
1626n/a
1627n/a # --- Final error reports ---
1628n/a
1629n/a def report(self):
1630n/a if self.unknown:
1631n/a print('--- Unrecognized commands ---')
1632n/a cmds = sorted(self.unknown.keys())
1633n/a for cmd in cmds:
1634n/a print(cmd.ljust(20), self.unknown[cmd])
1635n/a
1636n/a
1637n/aclass TexinfoParserHTML3(TexinfoParser):
1638n/a
1639n/a COPYRIGHT_SYMBOL = "&copy;"
1640n/a FN_ID_PATTERN = "[%(id)s]"
1641n/a FN_SOURCE_PATTERN = '<A ID=footnoteref%(id)s ' \
1642n/a 'HREF="#footnotetext%(id)s">' + FN_ID_PATTERN + '</A>'
1643n/a FN_TARGET_PATTERN = '<FN ID=footnotetext%(id)s>\n' \
1644n/a '<P><A HREF="#footnoteref%(id)s">' + FN_ID_PATTERN \
1645n/a + '</A>\n%(text)s</P></FN>\n'
1646n/a FN_HEADER = '<DIV CLASS=footnotes>\n <HR NOSHADE WIDTH=200>\n' \
1647n/a ' <STRONG><EM>Footnotes</EM></STRONG>\n <P>\n'
1648n/a
1649n/a Node = HTML3Node
1650n/a
1651n/a def bgn_quotation(self, args): self.write('<BQ>')
1652n/a def end_quotation(self): self.write('</BQ>\n')
1653n/a
1654n/a def bgn_example(self, args):
1655n/a # this use of <CODE> would not be legal in HTML 2.0,
1656n/a # but is in more recent DTDs.
1657n/a self.nofill = self.nofill + 1
1658n/a self.write('<PRE CLASS=example><CODE>')
1659n/a def end_example(self):
1660n/a self.write("</CODE></PRE>\n")
1661n/a self.nofill = self.nofill - 1
1662n/a
1663n/a def bgn_flushleft(self, args):
1664n/a self.nofill = self.nofill + 1
1665n/a self.write('<PRE CLASS=flushleft>\n')
1666n/a
1667n/a def bgn_flushright(self, args):
1668n/a self.nofill = self.nofill + 1
1669n/a self.write('<DIV ALIGN=right CLASS=flushright><ADDRESS COMPACT>\n')
1670n/a def end_flushright(self):
1671n/a self.write('</ADDRESS></DIV>\n')
1672n/a self.nofill = self.nofill - 1
1673n/a
1674n/a def bgn_menu(self, args):
1675n/a self.write('<UL PLAIN CLASS=menu>\n')
1676n/a self.write(' <LH>Menu</LH>\n')
1677n/a def end_menu(self):
1678n/a self.write('</UL>\n')
1679n/a
1680n/a
1681n/a# rpyron 2002-05-07
1682n/aclass HTMLHelp:
1683n/a """
1684n/a This class encapsulates support for HTML Help. Node names,
1685n/a file names, menu items, index items, and image file names are
1686n/a accumulated until a call to finalize(). At that time, three
1687n/a output files are created in the current directory:
1688n/a
1689n/a `helpbase`.hhp is a HTML Help Workshop project file.
1690n/a It contains various information, some of
1691n/a which I do not understand; I just copied
1692n/a the default project info from a fresh
1693n/a installation.
1694n/a `helpbase`.hhc is the Contents file for the project.
1695n/a `helpbase`.hhk is the Index file for the project.
1696n/a
1697n/a When these files are used as input to HTML Help Workshop,
1698n/a the resulting file will be named:
1699n/a
1700n/a `helpbase`.chm
1701n/a
1702n/a If none of the defaults in `helpbase`.hhp are changed,
1703n/a the .CHM file will have Contents, Index, Search, and
1704n/a Favorites tabs.
1705n/a """
1706n/a
1707n/a codeprog = re.compile('@code{(.*?)}')
1708n/a
1709n/a def __init__(self,helpbase,dirname):
1710n/a self.helpbase = helpbase
1711n/a self.dirname = dirname
1712n/a self.projectfile = None
1713n/a self.contentfile = None
1714n/a self.indexfile = None
1715n/a self.nodelist = []
1716n/a self.nodenames = {} # nodename : index
1717n/a self.nodeindex = {}
1718n/a self.filenames = {} # filename : filename
1719n/a self.indexlist = [] # (args,nodename) == (key,location)
1720n/a self.current = ''
1721n/a self.menudict = {}
1722n/a self.dumped = {}
1723n/a
1724n/a
1725n/a def addnode(self,name,next,prev,up,filename):
1726n/a node = (name,next,prev,up,filename)
1727n/a # add this file to dict
1728n/a # retrieve list with self.filenames.values()
1729n/a self.filenames[filename] = filename
1730n/a # add this node to nodelist
1731n/a self.nodeindex[name] = len(self.nodelist)
1732n/a self.nodelist.append(node)
1733n/a # set 'current' for menu items
1734n/a self.current = name
1735n/a self.menudict[self.current] = []
1736n/a
1737n/a def menuitem(self,nodename):
1738n/a menu = self.menudict[self.current]
1739n/a menu.append(nodename)
1740n/a
1741n/a
1742n/a def addimage(self,imagename):
1743n/a self.filenames[imagename] = imagename
1744n/a
1745n/a def index(self, args, nodename):
1746n/a self.indexlist.append((args,nodename))
1747n/a
1748n/a def beginmenu(self):
1749n/a pass
1750n/a
1751n/a def endmenu(self):
1752n/a pass
1753n/a
1754n/a def finalize(self):
1755n/a if not self.helpbase:
1756n/a return
1757n/a
1758n/a # generate interesting filenames
1759n/a resultfile = self.helpbase + '.chm'
1760n/a projectfile = self.helpbase + '.hhp'
1761n/a contentfile = self.helpbase + '.hhc'
1762n/a indexfile = self.helpbase + '.hhk'
1763n/a
1764n/a # generate a reasonable title
1765n/a title = self.helpbase
1766n/a
1767n/a # get the default topic file
1768n/a (topname,topnext,topprev,topup,topfile) = self.nodelist[0]
1769n/a defaulttopic = topfile
1770n/a
1771n/a # PROJECT FILE
1772n/a try:
1773n/a fp = open(projectfile,'w')
1774n/a print('[OPTIONS]', file=fp)
1775n/a print('Auto Index=Yes', file=fp)
1776n/a print('Binary TOC=No', file=fp)
1777n/a print('Binary Index=Yes', file=fp)
1778n/a print('Compatibility=1.1', file=fp)
1779n/a print('Compiled file=' + resultfile + '', file=fp)
1780n/a print('Contents file=' + contentfile + '', file=fp)
1781n/a print('Default topic=' + defaulttopic + '', file=fp)
1782n/a print('Error log file=ErrorLog.log', file=fp)
1783n/a print('Index file=' + indexfile + '', file=fp)
1784n/a print('Title=' + title + '', file=fp)
1785n/a print('Display compile progress=Yes', file=fp)
1786n/a print('Full-text search=Yes', file=fp)
1787n/a print('Default window=main', file=fp)
1788n/a print('', file=fp)
1789n/a print('[WINDOWS]', file=fp)
1790n/a print('main=,"' + contentfile + '","' + indexfile
1791n/a + '","","",,,,,0x23520,222,0x1046,[10,10,780,560],'
1792n/a '0xB0000,,,,,,0', file=fp)
1793n/a print('', file=fp)
1794n/a print('[FILES]', file=fp)
1795n/a print('', file=fp)
1796n/a self.dumpfiles(fp)
1797n/a fp.close()
1798n/a except IOError as msg:
1799n/a print(projectfile, ':', msg)
1800n/a sys.exit(1)
1801n/a
1802n/a # CONTENT FILE
1803n/a try:
1804n/a fp = open(contentfile,'w')
1805n/a print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp)
1806n/a print('<!-- This file defines the table of contents -->', file=fp)
1807n/a print('<HTML>', file=fp)
1808n/a print('<HEAD>', file=fp)
1809n/a print('<meta name="GENERATOR"'
1810n/a 'content="Microsoft&reg; HTML Help Workshop 4.1">', file=fp)
1811n/a print('<!-- Sitemap 1.0 -->', file=fp)
1812n/a print('</HEAD>', file=fp)
1813n/a print('<BODY>', file=fp)
1814n/a print(' <OBJECT type="text/site properties">', file=fp)
1815n/a print(' <param name="Window Styles" value="0x800025">', file=fp)
1816n/a print(' <param name="comment" value="title:">', file=fp)
1817n/a print(' <param name="comment" value="base:">', file=fp)
1818n/a print(' </OBJECT>', file=fp)
1819n/a self.dumpnodes(fp)
1820n/a print('</BODY>', file=fp)
1821n/a print('</HTML>', file=fp)
1822n/a fp.close()
1823n/a except IOError as msg:
1824n/a print(contentfile, ':', msg)
1825n/a sys.exit(1)
1826n/a
1827n/a # INDEX FILE
1828n/a try:
1829n/a fp = open(indexfile ,'w')
1830n/a print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp)
1831n/a print('<!-- This file defines the index -->', file=fp)
1832n/a print('<HTML>', file=fp)
1833n/a print('<HEAD>', file=fp)
1834n/a print('<meta name="GENERATOR"'
1835n/a 'content="Microsoft&reg; HTML Help Workshop 4.1">', file=fp)
1836n/a print('<!-- Sitemap 1.0 -->', file=fp)
1837n/a print('</HEAD>', file=fp)
1838n/a print('<BODY>', file=fp)
1839n/a print('<OBJECT type="text/site properties">', file=fp)
1840n/a print('</OBJECT>', file=fp)
1841n/a self.dumpindex(fp)
1842n/a print('</BODY>', file=fp)
1843n/a print('</HTML>', file=fp)
1844n/a fp.close()
1845n/a except IOError as msg:
1846n/a print(indexfile , ':', msg)
1847n/a sys.exit(1)
1848n/a
1849n/a def dumpfiles(self, outfile=sys.stdout):
1850n/a filelist = sorted(self.filenames.values())
1851n/a for filename in filelist:
1852n/a print(filename, file=outfile)
1853n/a
1854n/a def dumpnodes(self, outfile=sys.stdout):
1855n/a self.dumped = {}
1856n/a if self.nodelist:
1857n/a nodename, dummy, dummy, dummy, dummy = self.nodelist[0]
1858n/a self.topnode = nodename
1859n/a
1860n/a print('<UL>', file=outfile)
1861n/a for node in self.nodelist:
1862n/a self.dumpnode(node,0,outfile)
1863n/a print('</UL>', file=outfile)
1864n/a
1865n/a def dumpnode(self, node, indent=0, outfile=sys.stdout):
1866n/a if node:
1867n/a # Retrieve info for this node
1868n/a (nodename,next,prev,up,filename) = node
1869n/a self.current = nodename
1870n/a
1871n/a # Have we been dumped already?
1872n/a if nodename in self.dumped:
1873n/a return
1874n/a self.dumped[nodename] = 1
1875n/a
1876n/a # Print info for this node
1877n/a print(' '*indent, end=' ', file=outfile)
1878n/a print('<LI><OBJECT type="text/sitemap">', end=' ', file=outfile)
1879n/a print('<param name="Name" value="' + nodename +'">', end=' ', file=outfile)
1880n/a print('<param name="Local" value="'+ filename +'">', end=' ', file=outfile)
1881n/a print('</OBJECT>', file=outfile)
1882n/a
1883n/a # Does this node have menu items?
1884n/a try:
1885n/a menu = self.menudict[nodename]
1886n/a self.dumpmenu(menu,indent+2,outfile)
1887n/a except KeyError:
1888n/a pass
1889n/a
1890n/a def dumpmenu(self, menu, indent=0, outfile=sys.stdout):
1891n/a if menu:
1892n/a currentnode = self.current
1893n/a if currentnode != self.topnode: # XXX this is a hack
1894n/a print(' '*indent + '<UL>', file=outfile)
1895n/a indent += 2
1896n/a for item in menu:
1897n/a menunode = self.getnode(item)
1898n/a self.dumpnode(menunode,indent,outfile)
1899n/a if currentnode != self.topnode: # XXX this is a hack
1900n/a print(' '*indent + '</UL>', file=outfile)
1901n/a indent -= 2
1902n/a
1903n/a def getnode(self, nodename):
1904n/a try:
1905n/a index = self.nodeindex[nodename]
1906n/a return self.nodelist[index]
1907n/a except KeyError:
1908n/a return None
1909n/a except IndexError:
1910n/a return None
1911n/a
1912n/a # (args,nodename) == (key,location)
1913n/a def dumpindex(self, outfile=sys.stdout):
1914n/a print('<UL>', file=outfile)
1915n/a for (key,location) in self.indexlist:
1916n/a key = self.codeexpand(key)
1917n/a location = makefile(location)
1918n/a location = self.dirname + '/' + location
1919n/a print('<LI><OBJECT type="text/sitemap">', end=' ', file=outfile)
1920n/a print('<param name="Name" value="' + key + '">', end=' ', file=outfile)
1921n/a print('<param name="Local" value="' + location + '">', end=' ', file=outfile)
1922n/a print('</OBJECT>', file=outfile)
1923n/a print('</UL>', file=outfile)
1924n/a
1925n/a def codeexpand(self, line):
1926n/a co = self.codeprog.match(line)
1927n/a if not co:
1928n/a return line
1929n/a bgn, end = co.span(0)
1930n/a a, b = co.span(1)
1931n/a line = line[:bgn] + line[a:b] + line[end:]
1932n/a return line
1933n/a
1934n/a
1935n/a# Put @var{} around alphabetic substrings
1936n/adef makevar(str):
1937n/a return '@var{'+str+'}'
1938n/a
1939n/a
1940n/a# Split a string in "words" according to findwordend
1941n/adef splitwords(str, minlength):
1942n/a words = []
1943n/a i = 0
1944n/a n = len(str)
1945n/a while i < n:
1946n/a while i < n and str[i] in ' \t\n': i = i+1
1947n/a if i >= n: break
1948n/a start = i
1949n/a i = findwordend(str, i, n)
1950n/a words.append(str[start:i])
1951n/a while len(words) < minlength: words.append('')
1952n/a return words
1953n/a
1954n/a
1955n/a# Find the end of a "word", matching braces and interpreting @@ @{ @}
1956n/afwprog = re.compile('[@{} ]')
1957n/adef findwordend(str, i, n):
1958n/a level = 0
1959n/a while i < n:
1960n/a mo = fwprog.search(str, i)
1961n/a if not mo:
1962n/a break
1963n/a i = mo.start()
1964n/a c = str[i]; i = i+1
1965n/a if c == '@': i = i+1 # Next character is not special
1966n/a elif c == '{': level = level+1
1967n/a elif c == '}': level = level-1
1968n/a elif c == ' ' and level <= 0: return i-1
1969n/a return n
1970n/a
1971n/a
1972n/a# Convert a node name into a file name
1973n/adef makefile(nodename):
1974n/a nodename = nodename.strip()
1975n/a return fixfunnychars(nodename) + '.html'
1976n/a
1977n/a
1978n/a# Characters that are perfectly safe in filenames and hyperlinks
1979n/agoodchars = string.ascii_letters + string.digits + '!@-=+.'
1980n/a
1981n/a# Replace characters that aren't perfectly safe by dashes
1982n/a# Underscores are bad since Cern HTTPD treats them as delimiters for
1983n/a# encoding times, so you get mismatches if you compress your files:
1984n/a# a.html.gz will map to a_b.html.gz
1985n/adef fixfunnychars(addr):
1986n/a i = 0
1987n/a while i < len(addr):
1988n/a c = addr[i]
1989n/a if c not in goodchars:
1990n/a c = '-'
1991n/a addr = addr[:i] + c + addr[i+1:]
1992n/a i = i + len(c)
1993n/a return addr
1994n/a
1995n/a
1996n/a# Increment a string used as an enumeration
1997n/adef increment(s):
1998n/a if not s:
1999n/a return '1'
2000n/a for sequence in string.digits, string.ascii_lowercase, string.ascii_uppercase:
2001n/a lastc = s[-1]
2002n/a if lastc in sequence:
2003n/a i = sequence.index(lastc) + 1
2004n/a if i >= len(sequence):
2005n/a if len(s) == 1:
2006n/a s = sequence[0]*2
2007n/a if s == '00':
2008n/a s = '10'
2009n/a else:
2010n/a s = increment(s[:-1]) + sequence[0]
2011n/a else:
2012n/a s = s[:-1] + sequence[i]
2013n/a return s
2014n/a return s # Don't increment
2015n/a
2016n/a
2017n/adef test():
2018n/a import sys
2019n/a debugging = 0
2020n/a print_headers = 0
2021n/a cont = 0
2022n/a html3 = 0
2023n/a htmlhelp = ''
2024n/a
2025n/a while sys.argv[1] == ['-d']:
2026n/a debugging = debugging + 1
2027n/a del sys.argv[1]
2028n/a if sys.argv[1] == '-p':
2029n/a print_headers = 1
2030n/a del sys.argv[1]
2031n/a if sys.argv[1] == '-c':
2032n/a cont = 1
2033n/a del sys.argv[1]
2034n/a if sys.argv[1] == '-3':
2035n/a html3 = 1
2036n/a del sys.argv[1]
2037n/a if sys.argv[1] == '-H':
2038n/a helpbase = sys.argv[2]
2039n/a del sys.argv[1:3]
2040n/a if len(sys.argv) != 3:
2041n/a print('usage: texi2hh [-d [-d]] [-p] [-c] [-3] [-H htmlhelp]', \
2042n/a 'inputfile outputdirectory')
2043n/a sys.exit(2)
2044n/a
2045n/a if html3:
2046n/a parser = TexinfoParserHTML3()
2047n/a else:
2048n/a parser = TexinfoParser()
2049n/a parser.cont = cont
2050n/a parser.debugging = debugging
2051n/a parser.print_headers = print_headers
2052n/a
2053n/a file = sys.argv[1]
2054n/a dirname = sys.argv[2]
2055n/a parser.setdirname(dirname)
2056n/a parser.setincludedir(os.path.dirname(file))
2057n/a
2058n/a htmlhelp = HTMLHelp(helpbase, dirname)
2059n/a parser.sethtmlhelp(htmlhelp)
2060n/a
2061n/a try:
2062n/a fp = open(file, 'r')
2063n/a except IOError as msg:
2064n/a print(file, ':', msg)
2065n/a sys.exit(1)
2066n/a
2067n/a parser.parse(fp)
2068n/a fp.close()
2069n/a parser.report()
2070n/a
2071n/a htmlhelp.finalize()
2072n/a
2073n/a
2074n/aif __name__ == "__main__":
2075n/a test()