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