[1] | 1 | import sys, os, string, getopt, types |
---|
| 2 | import xml.parsers.expat |
---|
| 3 | |
---|
| 4 | #------------------------------------------------------------ |
---|
| 5 | # A Section holds |
---|
| 6 | # an id of the form n.m.p |
---|
| 7 | # a title |
---|
| 8 | # the level |
---|
| 9 | # |
---|
| 10 | class Section : |
---|
| 11 | def __init__ (self, id, title, level) : |
---|
| 12 | self.id = id |
---|
| 13 | self.title = title |
---|
| 14 | self.level = level |
---|
| 15 | # end def |
---|
| 16 | |
---|
| 17 | # Format the index entry for this section |
---|
| 18 | def show_index_entry (self) : |
---|
| 19 | tab = string.rjust ("", 4*self.level) |
---|
| 20 | tab = tab.replace (" ", " ") |
---|
| 21 | print '<tr>' |
---|
| 22 | print '<td width="100">' + self.id + '</td>' |
---|
| 23 | print '<td>' + tab + '<a href="#' + self.title + '">' + self.title + '</a></td>' |
---|
| 24 | print '</tr>' |
---|
| 25 | # end def |
---|
| 26 | |
---|
| 27 | #------------------------------------------------------------ |
---|
| 28 | # A Book |
---|
| 29 | # It holds the history of sections and the definitions of internal entities |
---|
| 30 | # |
---|
| 31 | class Book : |
---|
| 32 | # Format one level of a section id as %2.2d |
---|
| 33 | def format_id (self, id) : |
---|
| 34 | r = repr (id) |
---|
| 35 | if id < 10 : |
---|
| 36 | r = ' ' + r |
---|
| 37 | return r |
---|
| 38 | # end def |
---|
| 39 | |
---|
| 40 | # Format a complete section id, with all individual level ids |
---|
| 41 | # Currently the implementation is somewhat ugly. This is due |
---|
| 42 | # to the strange behaviour of the ideal form (using a for-loop |
---|
| 43 | # over the elements of self.level_ids). Once we can understand |
---|
| 44 | # the reason of this unexpected behaviour we can improve it. |
---|
| 45 | def build_id (self) : |
---|
| 46 | id = '<tt>' |
---|
| 47 | n = len (self.level_ids) |
---|
| 48 | if n >= 1 : |
---|
| 49 | id += self.format_id (self.level_ids[0]) |
---|
| 50 | if n >= 2 : |
---|
| 51 | id += '.' + self.format_id (self.level_ids[1]) |
---|
| 52 | if n >= 3 : |
---|
| 53 | id += '.' + self.format_id (self.level_ids[2]) |
---|
| 54 | if n >= 4 : |
---|
| 55 | id += '.' + self.format_id (self.level_ids[3]) |
---|
| 56 | id += '</tt>' |
---|
| 57 | return id |
---|
| 58 | # end def |
---|
| 59 | |
---|
| 60 | # Create a new Section object |
---|
| 61 | # Register the history of sections (with level hierarchy) |
---|
| 62 | def open_section (self, name) : |
---|
| 63 | self.level_ids [self.level] += 1 |
---|
| 64 | i = self.level_ids [self.level] |
---|
| 65 | id = self.build_id () |
---|
| 66 | self.sections.append (Section (id, name, self.level)) |
---|
| 67 | self.level += 1 |
---|
| 68 | self.level_ids.append (0) |
---|
| 69 | return id |
---|
| 70 | # end def |
---|
| 71 | |
---|
| 72 | # Pop one level in the level hierarchy |
---|
| 73 | def close_section (self) : |
---|
| 74 | self.level_ids.pop () |
---|
| 75 | self.level -= 1 |
---|
| 76 | # end def |
---|
| 77 | |
---|
| 78 | # Register the definition of an internal entity in the entity dictionary |
---|
| 79 | def entity_decl (self, name, is_parameter, value, base, systemId, publicId, notation) : |
---|
| 80 | if value : |
---|
| 81 | self.entities['&' + name + ';'] = value |
---|
| 82 | # end def |
---|
| 83 | |
---|
| 84 | # Generic parser |
---|
| 85 | def generic_parse (self, p, name) : |
---|
| 86 | p.StartElementHandler = self.start_element |
---|
| 87 | p.EndElementHandler = self.end_element |
---|
| 88 | p.CharacterDataHandler = self.char_data |
---|
| 89 | p.ExternalEntityRefHandler = self.external_entity |
---|
| 90 | p.DefaultHandler = self.dummy |
---|
| 91 | p.EntityDeclHandler = self.entity_decl |
---|
| 92 | #file_name = os.path.join (sys.path[0], name) |
---|
| 93 | f = open (name) |
---|
| 94 | p.ParseFile (f) |
---|
| 95 | f.close () |
---|
| 96 | # end def |
---|
| 97 | |
---|
| 98 | # Top level parser |
---|
| 99 | def parse (self, name) : |
---|
| 100 | self.p = xml.parsers.expat.ParserCreate () |
---|
| 101 | self.generic_parse (self.p, name) |
---|
| 102 | # end def |
---|
| 103 | |
---|
| 104 | # Sub-parser for external entities |
---|
| 105 | def external_entity (self, context, base, system_id, public_id): |
---|
| 106 | #print "external entity " + repr(context) + " " + repr(system_id) + ' ' + sys.path[0] |
---|
| 107 | ep = self.p.ExternalEntityParserCreate (context) |
---|
| 108 | self.generic_parse (ep, system_id) |
---|
| 109 | # end def |
---|
| 110 | |
---|
| 111 | # Format a tabulation according to the stored tabulation level |
---|
| 112 | def tab (self) : |
---|
| 113 | return (string.rjust ("", self.tabulation)) |
---|
| 114 | # end def |
---|
| 115 | |
---|
| 116 | # Flush the internal line buffer and display it using the tabulation |
---|
| 117 | def purge (self) : |
---|
| 118 | if self.line != '': |
---|
| 119 | if self.in_code == 0 : |
---|
| 120 | print self.tab () + self.line |
---|
| 121 | self.line = '' |
---|
| 122 | # end def |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | #---------------------------------------------------------- |
---|
| 126 | # |
---|
| 127 | # All XML element handlers |
---|
| 128 | # |
---|
| 129 | #---------------------------------------------------------- |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | # any element : simply reproduce the element with its attributes |
---|
| 133 | # (ie assume it is a true HTML element) |
---|
| 134 | def default_start (self, name, attrs) : |
---|
| 135 | self.line += '<' + name |
---|
| 136 | if len (attrs) > 0 : |
---|
| 137 | i = len (attrs) |
---|
| 138 | for k, v in attrs.items() : |
---|
| 139 | self.line += ' ' + k + '="' + v + '"' |
---|
| 140 | i -= 1 |
---|
| 141 | if i <= 0 : break |
---|
| 142 | self.line += '>' |
---|
| 143 | self.purge () |
---|
| 144 | self.tabulation += 2 |
---|
| 145 | # end def |
---|
| 146 | |
---|
| 147 | def default_end (self, name) : |
---|
| 148 | self.tabulation -= 2 |
---|
| 149 | self.line += '</' + name + '>' |
---|
| 150 | self.purge () |
---|
| 151 | # end def |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | # <book> |
---|
| 155 | def book_start (self, attrs) : |
---|
| 156 | self.name = attrs['name'] |
---|
| 157 | self.title = attrs['title'] |
---|
| 158 | self.version = attrs['version'] |
---|
| 159 | self.author = attrs['author'] |
---|
| 160 | print '<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> ' |
---|
| 161 | print '<html>' |
---|
| 162 | print '<title>' + self.name + '</title>' |
---|
| 163 | print '<body bgcolor="#ffffff" link="#550088" alink="#007777" alink="#007777">' |
---|
| 164 | print '<font face="Arial, Helvetica" color="#000000">' |
---|
| 165 | print '<h1><center>' + self.name + '</center>' |
---|
| 166 | print '<center>' + self.title + '</center></h1>' |
---|
| 167 | print '<h2><center>Version ' + self.version + '</center>' |
---|
| 168 | print '<center>' + self.author + '</center>' |
---|
| 169 | print '<center><tt>' + attrs['email'] + '</tt></center></h2>' |
---|
| 170 | self.line += '<hr><h2>' |
---|
| 171 | self.line += '<a href="#index">General index</a>' |
---|
| 172 | self.line += '</h2>' |
---|
| 173 | self.purge () |
---|
| 174 | # end def |
---|
| 175 | |
---|
| 176 | def book_end (self) : |
---|
| 177 | print '<hr><h1><A NAME="index"></A>Contents</h1>' |
---|
| 178 | print '<blockquote>' |
---|
| 179 | print '<table cols="2">' |
---|
| 180 | for k in range (len (self.sections)) : |
---|
| 181 | self.sections[k].show_index_entry () |
---|
| 182 | print '<tr><td colspan="2"> </td></tr>' |
---|
| 183 | print '<tr><td colspan="2"><h2>Images</h2></td></tr>' |
---|
| 184 | for k in range (len (self.images)) : |
---|
| 185 | print '<tr>' |
---|
| 186 | print '<td width="100"><tt>' + repr(k+1) + '</tt></td>' |
---|
| 187 | print '<td><a href="#' + self.images[k] + '">' + self.images[k] + '</a></td>' |
---|
| 188 | print '</tr>' |
---|
| 189 | print '</table>' |
---|
| 190 | print '</blockquote>' |
---|
| 191 | print '</font>' |
---|
| 192 | print '<address>' |
---|
| 193 | print '<i>' + self.author + '</i>' |
---|
| 194 | print '</address>' |
---|
| 195 | print '</body>' |
---|
| 196 | print '</html>' |
---|
| 197 | # end def |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | # <section> |
---|
| 201 | def section_start (self, attrs) : |
---|
| 202 | title = attrs['title'] |
---|
| 203 | title = title.replace ('>', '>') |
---|
| 204 | title = title.replace ('<', '<') |
---|
| 205 | id = self.open_section (title) |
---|
| 206 | h_level = repr(self.level+1) |
---|
| 207 | self.line += '<hr><h' + h_level + '>' |
---|
| 208 | self.line += '<a name="' + title + '"></a>' |
---|
| 209 | self.line += '<a href="#index">' + id + '</a> - ' + title |
---|
| 210 | self.line += '</h' + h_level + '>' |
---|
| 211 | self.purge () |
---|
| 212 | self.line = '<blockquote>' |
---|
| 213 | self.purge () |
---|
| 214 | # end def |
---|
| 215 | |
---|
| 216 | def section_end (self) : |
---|
| 217 | self.purge () |
---|
| 218 | self.line = '</blockquote>' |
---|
| 219 | self.purge () |
---|
| 220 | self.close_section () |
---|
| 221 | # end def |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | # <code> |
---|
| 225 | def code_start (self, attrs) : |
---|
| 226 | self.purge () |
---|
| 227 | self.in_code += 1 |
---|
| 228 | self.line = '<pre>' |
---|
| 229 | # end def |
---|
| 230 | |
---|
| 231 | def code_end (self) : |
---|
| 232 | self.in_code -= 1 |
---|
| 233 | print self.line + '</pre>' |
---|
| 234 | self.line = '' |
---|
| 235 | # end def |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | # <syntax> |
---|
| 239 | def syntax_start (self, attrs) : |
---|
| 240 | print '<center>' |
---|
| 241 | print '<table cols="3">' |
---|
| 242 | print '<tr>' |
---|
| 243 | if 'rule-width' in attrs : |
---|
| 244 | print '<td width="' + attrs['rule-width'] + '"></td>' |
---|
| 245 | else : |
---|
| 246 | print '<td></td>' |
---|
| 247 | if 'name' in attrs : |
---|
| 248 | self.ruleref_prefix = 'kw' + attrs['name'] + '-' |
---|
| 249 | else : |
---|
| 250 | self.ruleref_prefix = 'kw-' |
---|
| 251 | print '<td width="10"></td>' |
---|
| 252 | print '<td></td>' |
---|
| 253 | print '</tr>' |
---|
| 254 | # end def |
---|
| 255 | |
---|
| 256 | def syntax_end (self) : |
---|
| 257 | print '</table>' |
---|
| 258 | print '</center>' |
---|
| 259 | # end def |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | # <rule> |
---|
| 263 | def rule_start (self, attrs) : |
---|
| 264 | self.rule_name = attrs['name'] |
---|
| 265 | self.rule_started = 0 |
---|
| 266 | # end def |
---|
| 267 | |
---|
| 268 | def rule_end (self) : |
---|
| 269 | self.rule_name = '' |
---|
| 270 | self.rule_started = 0 |
---|
| 271 | # end def |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | # <alt> |
---|
| 275 | def alt_start (self, attrs) : |
---|
| 276 | print '<tr>' |
---|
| 277 | if self.rule_started == 0 : |
---|
| 278 | self.rule_started = 1 |
---|
| 279 | print '<td><font face="courier new, courier" COLOR="#770000"><i><a name="' + self.ruleref_prefix + self.rule_name + '"></a>' + self.rule_name + '</i></font></td>' |
---|
| 280 | print '<td>:</td>' |
---|
| 281 | print '<td>' |
---|
| 282 | else : |
---|
| 283 | print '<td></td>' |
---|
| 284 | print '<td>|</td>' |
---|
| 285 | print '<td>' |
---|
| 286 | # end def |
---|
| 287 | |
---|
| 288 | def alt_end (self) : |
---|
| 289 | print '</td>' |
---|
| 290 | print '</tr>' |
---|
| 291 | # end def |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | # <continuation> |
---|
| 295 | def continuation_start (self, attrs) : |
---|
| 296 | print '<tr>' |
---|
| 297 | print '<td></td>' |
---|
| 298 | print '<td></td>' |
---|
| 299 | print '<td> ' |
---|
| 300 | # end def |
---|
| 301 | |
---|
| 302 | def continuation_end (self) : |
---|
| 303 | print '</td>' |
---|
| 304 | print '</tr>' |
---|
| 305 | # end def |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | # <kwd> |
---|
| 309 | def kwd_start (self, attrs) : |
---|
| 310 | print '<font face="courier new, courier" COLOR="#FF0000">' |
---|
| 311 | if 'name' in attrs : |
---|
| 312 | name = attrs['name'] |
---|
| 313 | else : |
---|
| 314 | name = self.rule_name |
---|
| 315 | if 'value' in attrs : |
---|
| 316 | name += '=' |
---|
| 317 | value = '<font face="courier new, courier" COLOR="#770000"><i>' |
---|
| 318 | value += attrs['value'] |
---|
| 319 | value += '</i></font>' |
---|
| 320 | else : |
---|
| 321 | value = '' |
---|
| 322 | print name + value |
---|
| 323 | # end def |
---|
| 324 | |
---|
| 325 | def kwd_end (self) : |
---|
| 326 | print '</font>' |
---|
| 327 | # end def |
---|
| 328 | |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | # <term> |
---|
| 332 | def term_start (self, attrs) : |
---|
| 333 | print '<font face="courier new, courier" COLOR="#770000"><i>' |
---|
| 334 | print attrs['name'] |
---|
| 335 | # end def |
---|
| 336 | |
---|
| 337 | def term_end (self) : |
---|
| 338 | print '</i></font>' |
---|
| 339 | # end def |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | # <ruleref> |
---|
| 344 | def ruleref_start (self, attrs) : |
---|
| 345 | print '<font face="courier new, courier" COLOR="#770000"><i>' |
---|
| 346 | print '<a href="#' + self.ruleref_prefix + attrs['name'] + '">' + attrs['name'] + '</a>' |
---|
| 347 | # end def |
---|
| 348 | |
---|
| 349 | def ruleref_end (self) : |
---|
| 350 | print '</i></font>' |
---|
| 351 | # end def |
---|
| 352 | |
---|
| 353 | |
---|
| 354 | # <option> |
---|
| 355 | def option_start (self, attrs) : |
---|
| 356 | print '[ ' |
---|
| 357 | # end def |
---|
| 358 | |
---|
| 359 | def option_end (self) : |
---|
| 360 | print ' ] ' |
---|
| 361 | # end def |
---|
| 362 | |
---|
| 363 | |
---|
| 364 | # <seq> |
---|
| 365 | def seq_start (self, attrs) : |
---|
| 366 | i=0 |
---|
| 367 | # end def |
---|
| 368 | |
---|
| 369 | def seq_end (self) : |
---|
| 370 | print ' ... ' |
---|
| 371 | # end def |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | # <optionseq> |
---|
| 375 | def optionseq_start (self, attrs) : |
---|
| 376 | print '[ ' |
---|
| 377 | # end def |
---|
| 378 | |
---|
| 379 | def optionseq_end (self) : |
---|
| 380 | print ' ... ' |
---|
| 381 | print ' ] ' |
---|
| 382 | # end def |
---|
| 383 | |
---|
| 384 | |
---|
| 385 | |
---|
| 386 | # <image> |
---|
| 387 | def image_start (self, attrs) : |
---|
| 388 | caption = attrs['caption'] |
---|
| 389 | self.images.append (caption) |
---|
| 390 | n = len (self.images) |
---|
| 391 | print '<center>' |
---|
| 392 | print '<a name="' + caption + '"></a>' |
---|
| 393 | print '<img src="' + attrs['src'] + '"/>' |
---|
| 394 | print '</center>' |
---|
| 395 | print '<center>' |
---|
| 396 | print '<tt>' + repr(n) + '</tt> - <i>' + caption + '</i>' |
---|
| 397 | # end def |
---|
| 398 | |
---|
| 399 | def image_end (self) : |
---|
| 400 | print '</center>' |
---|
| 401 | # end def |
---|
| 402 | |
---|
| 403 | def blockquote_start (self, attrs) : |
---|
| 404 | print '<blockquote><hr>' |
---|
| 405 | # end def |
---|
| 406 | |
---|
| 407 | def blockquote_end (self) : |
---|
| 408 | print '<hr></blockquote>' |
---|
| 409 | # end def |
---|
| 410 | |
---|
| 411 | |
---|
| 412 | # Basic element parsing handler |
---|
| 413 | def start_element (self, name, attrs): |
---|
| 414 | #print 'start_element: name=' + repr(name) |
---|
| 415 | try : |
---|
| 416 | if self.start_handlers.has_key (name) : |
---|
| 417 | self.start_handlers [name] (attrs) |
---|
| 418 | else : |
---|
| 419 | self.default_start (name, attrs) |
---|
| 420 | except TypeError: |
---|
| 421 | print 'start_element: (error) name=' + repr(name) |
---|
| 422 | self.default_start (name, attrs) |
---|
| 423 | # end def |
---|
| 424 | |
---|
| 425 | def end_element (self, name) : |
---|
| 426 | #print 'end_element: name=' + repr(name) |
---|
| 427 | try : |
---|
| 428 | if self.end_handlers.has_key (name) : |
---|
| 429 | self.end_handlers [name] () |
---|
| 430 | else : |
---|
| 431 | self.default_end (name) |
---|
| 432 | except TypeError: |
---|
| 433 | #print 'end_element: (error) name=' + repr(name) |
---|
| 434 | if name == u'cmt:book' : |
---|
| 435 | self.book_end () |
---|
| 436 | else : |
---|
| 437 | self.default_end (name) |
---|
| 438 | # end def |
---|
| 439 | |
---|
| 440 | # Unhandled elements will be trapped here |
---|
| 441 | def dummy (self, data) : |
---|
| 442 | if self.entities.has_key (data) : |
---|
| 443 | self.char_data (self.entities[data]) |
---|
| 444 | #print "dummy:[" + repr (data) + "]" + repr (type(data)) |
---|
| 445 | # end def |
---|
| 446 | |
---|
| 447 | # CDATA handling inside code sections |
---|
| 448 | def code_char_data (self, data) : |
---|
| 449 | if data == u'\n' : |
---|
| 450 | self.line += data |
---|
| 451 | else : |
---|
| 452 | n = len (data) |
---|
| 453 | # |
---|
| 454 | if n > 0 : |
---|
| 455 | if data == u'<': |
---|
| 456 | self.line += '<' |
---|
| 457 | elif data == u'>' : |
---|
| 458 | self.line += '>' |
---|
| 459 | else : |
---|
| 460 | self.line += data |
---|
| 461 | # end def |
---|
| 462 | |
---|
| 463 | # CDATA handling outside code sections |
---|
| 464 | def plain_char_data (self, data) : |
---|
| 465 | if data == u'\n' : |
---|
| 466 | self.purge () |
---|
| 467 | else : |
---|
| 468 | n = len (string.strip (data)) |
---|
| 469 | # |
---|
| 470 | if n > 0 : |
---|
| 471 | if data == u'<': |
---|
| 472 | self.line += '<' |
---|
| 473 | elif data == u'>' : |
---|
| 474 | self.line += '>' |
---|
| 475 | else : |
---|
| 476 | self.line += string.strip (data) |
---|
| 477 | # end def |
---|
| 478 | |
---|
| 479 | # CDATA handling |
---|
| 480 | def char_data (self, data) : |
---|
| 481 | #print '[' + repr(data) + ']' + repr (type (data)) + ' ' + repr(len (string.strip (data))) |
---|
| 482 | if self.in_code > 0 : |
---|
| 483 | self.code_char_data (data) |
---|
| 484 | else : |
---|
| 485 | self.plain_char_data (data) |
---|
| 486 | # end def |
---|
| 487 | |
---|
| 488 | def __init__ (self) : |
---|
| 489 | self.line = '' |
---|
| 490 | self.tabulation = 0 |
---|
| 491 | self.in_code = 0 |
---|
| 492 | self.sections = [] |
---|
| 493 | self.level_ids = [0] |
---|
| 494 | self.level = 0 |
---|
| 495 | self.images = [] |
---|
| 496 | self.entities = {} |
---|
| 497 | # |
---|
| 498 | self.start_handlers = {} |
---|
| 499 | self.start_handlers['cmt:code'] = self.code_start |
---|
| 500 | self.start_handlers['cmt:section'] = self.section_start |
---|
| 501 | self.start_handlers['cmt:book'] = self.book_start |
---|
| 502 | self.start_handlers['cmt:syntax'] = self.syntax_start |
---|
| 503 | self.start_handlers['cmt:rule'] = self.rule_start |
---|
| 504 | self.start_handlers['cmt:alt'] = self.alt_start |
---|
| 505 | self.start_handlers['cmt:continuation'] = self.continuation_start |
---|
| 506 | self.start_handlers['cmt:kwd'] = self.kwd_start |
---|
| 507 | self.start_handlers['cmt:term'] = self.term_start |
---|
| 508 | self.start_handlers['cmt:ruleref'] = self.ruleref_start |
---|
| 509 | self.start_handlers['cmt:option'] = self.option_start |
---|
| 510 | self.start_handlers['cmt:seq'] = self.seq_start |
---|
| 511 | self.start_handlers['cmt:optionseq'] = self.optionseq_start |
---|
| 512 | self.start_handlers['cmt:image'] = self.image_start |
---|
| 513 | self.start_handlers['cmt:blockquote'] = self.blockquote_start |
---|
| 514 | # |
---|
| 515 | self.end_handlers = {} |
---|
| 516 | self.end_handlers['cmt:code'] = self.code_end |
---|
| 517 | self.end_handlers['cmt:section'] = self.section_end |
---|
| 518 | self.end_handlers['cmt:book'] = self.book_end |
---|
| 519 | self.end_handlers['cmt:syntax'] = self.syntax_end |
---|
| 520 | self.end_handlers['cmt:rule'] = self.rule_end |
---|
| 521 | self.end_handlers['cmt:alt'] = self.alt_end |
---|
| 522 | self.end_handlers['cmt:continuation'] = self.continuation_end |
---|
| 523 | self.end_handlers['cmt:kwd'] = self.kwd_end |
---|
| 524 | self.end_handlers['cmt:term'] = self.term_end |
---|
| 525 | self.end_handlers['cmt:ruleref'] = self.ruleref_end |
---|
| 526 | self.end_handlers['cmt:option'] = self.option_end |
---|
| 527 | self.end_handlers['cmt:seq'] = self.seq_end |
---|
| 528 | self.end_handlers['cmt:optionseq'] = self.optionseq_end |
---|
| 529 | self.end_handlers['cmt:image'] = self.image_end |
---|
| 530 | self.end_handlers['cmt:blockquote'] = self.blockquote_end |
---|
| 531 | # end def |
---|
| 532 | |
---|
| 533 | |
---|
| 534 | |
---|
| 535 | #---------------------------------------------------------------------------------- |
---|
| 536 | |
---|
| 537 | #---------------------------------------------------------------------------------- |
---|
| 538 | # |
---|
| 539 | # Various top level functions |
---|
| 540 | # |
---|
| 541 | #---------------------------------------------------------------------------------- |
---|
| 542 | def usage() : |
---|
| 543 | print 'Usage:' |
---|
| 544 | print ' gendoc' |
---|
| 545 | print 'Try "gendoc --help" for more information.' |
---|
| 546 | sys.exit() |
---|
| 547 | # end def |
---|
| 548 | |
---|
| 549 | #---------------------------------------------------------------------------------- |
---|
| 550 | def help() : |
---|
| 551 | print "Generates the HTML documentation from Xml" |
---|
| 552 | # end def |
---|
| 553 | |
---|
| 554 | #---------------------------------------------------------------------------------- |
---|
| 555 | def main() : |
---|
| 556 | file_name = '' |
---|
| 557 | options = [] |
---|
| 558 | for a in sys.argv[1:] : |
---|
| 559 | if a[0] == '-' : |
---|
| 560 | options = sys.argv[sys.argv.index(a):] |
---|
| 561 | break |
---|
| 562 | else : |
---|
| 563 | file_name = a |
---|
| 564 | try: |
---|
| 565 | opts, args = getopt.getopt(options, 'h', ['help']) |
---|
| 566 | except getopt.GetoptError: |
---|
| 567 | usage() |
---|
| 568 | sys.exit(2) |
---|
| 569 | for o, a in opts: |
---|
| 570 | if o in ('-h', '--help'): |
---|
| 571 | help() |
---|
| 572 | sys.exit() |
---|
| 573 | book = Book () |
---|
| 574 | book.parse (file_name) |
---|
| 575 | # end def |
---|
| 576 | |
---|
| 577 | #--------------------------------------------------------------------- |
---|
| 578 | #print '__name__ = ' + __name__ |
---|
| 579 | if __name__ == "__main__": |
---|
| 580 | main() |
---|
| 581 | # end def |
---|
| 582 | |
---|