7 def __init__( self, processor ):
9 self.processor = processor
11 self.chapters = processor.chapters
12 self.sections = processor.sections.values()
15 # store all blocks in a dictionary
17 for section in self.sections:
18 for block in section.blocks.values():
19 self.add_identifier( block.name, block )
21 # add enumeration values to the index, since this is useful
22 for markup in block.markups:
23 if markup.tag == 'values':
24 for field in markup.fields:
25 self.add_identifier( field.name, block )
28 self.block_index = self.identifiers.keys()
29 self.block_index.sort( index_sort )
32 def add_identifier( self, name, block ):
33 if self.identifiers.has_key( name ):
36 "WARNING: duplicate definition for '" + name + "' in " + \
37 block.location() + ", previous definition in " + \
38 self.identifiers[ name ].location() + "\n" )
40 self.identifiers[name] = block
44 # Formatting the table of contents
47 def toc_enter( self ):
50 def toc_chapter_enter( self, chapter ):
53 def toc_section_enter( self, section ):
56 def toc_section_exit( self, section ):
59 def toc_chapter_exit( self, chapter ):
62 def toc_index( self, index_filename ):
68 def toc_dump( self, toc_filename = None, index_filename = None ):
72 output = open_output( toc_filename )
76 for chap in self.processor.chapters:
78 self.toc_chapter_enter( chap )
80 for section in chap.sections:
81 self.toc_section_enter( section )
82 self.toc_section_exit( section )
84 self.toc_chapter_exit ( chap )
86 self.toc_index( index_filename )
91 close_output( output )
94 # Formatting the index
97 def index_enter( self ):
100 def index_name_enter( self, name ):
103 def index_name_exit( self, name ):
106 def index_exit( self ):
109 def index_dump( self, index_filename = None ):
113 output = open_output( index_filename )
117 for name in self.block_index:
118 self.index_name_enter( name )
119 self.index_name_exit ( name )
124 close_output( output )
127 # Formatting a section
129 def section_enter( self, section ):
132 def block_enter( self, block ):
135 def markup_enter( self, markup, block = None ):
138 def field_enter( self, field, markup = None, block = None ):
141 def field_exit( self, field, markup = None, block = None ):
144 def markup_exit( self, markup, block = None ):
147 def block_exit( self, block ):
150 def section_exit( self, section ):
154 def section_dump( self, section, section_filename = None ):
158 output = open_output( section_filename )
160 self.section_enter( section )
162 for name in section.block_names:
163 block = self.identifiers[ name ]
164 self.block_enter( block )
166 for markup in block.markups[1:]: # always ignore first markup !!
167 self.markup_enter( markup, block )
169 for field in markup.fields:
170 self.field_enter( field, markup, block )
172 self.field_exit ( field, markup, block )
174 self.markup_exit( markup, block )
176 self.block_exit( block )
178 self.section_exit ( section )
181 close_output( output )
184 def section_dump_all( self ):
185 for section in self.sections:
186 self.section_dump( section )