updated DocMaker to generate section-specific pages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
diff --git a/ChangeLog b/ChangeLog
index b33d80e..07b0cd0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
* src/base/ftsystem.c (FT_Done_Memory): fixed an obvious bug,
the ANSI "free" function was called, instead of "memory->free()"
+ * docs/docmaker.py: added section filtering, multi-page generation
+ (index page generation is still missing though)
+
2000-12-04 David Turner <david.turner@freetype.org>
* builds/unix/install.mk, builds/unix/ft2unix.h: the file "ft2unix.h"
diff --git a/docs/docmaker.py b/docs/docmaker.py
index 85b17f2..d5441ef 100644
--- a/docs/docmaker.py
+++ b/docs/docmaker.py
@@ -35,6 +35,15 @@ html_footer = """
</html>
"""
+section_title_header = """
+<center><h1>
+"""
+
+section_title_footer = """
+</h1></center>
+"""
+
+
code_header = """
<font color=blue><pre>
"""
@@ -55,6 +64,10 @@ source_footer = """</pre></table></center>
<br><br>
"""
+
+current_section = None
+
+
# The FreeType 2 reference is extracted from the source files. These contain
# various comment blocks that follow one of the following formats:
#
@@ -244,6 +257,16 @@ class DocParagraph:
#print "§" #for debugging only
+ def dump_string( self ):
+ s = ""
+ space = ""
+ for word in self.words:
+ s = s + space + word
+ space = " "
+
+ return s
+
+
def dump_html( self ):
print para_header
@@ -390,6 +413,16 @@ class DocContent:
return "UNKNOWN_CONTENT_IDENTIFIER!!"
+ def get_title( self ):
+ if self.items:
+ item = self.items[0]
+ for element in item[1]:
+ return element.dump_string()
+
+ # should never happen
+ return "UNKNOWN_CONTENT_TITLE"
+
+
def dump( self ):
for item in self.items:
field = item[0]
@@ -459,6 +492,7 @@ class DocBlock:
marker = None # current marker
content = [] # current content lines list
alphanum = string.letters + string.digits + "_"
+ self.name = None
for line in block_line_list:
line2 = string.lstrip( line )
@@ -494,6 +528,11 @@ class DocBlock:
if self.items:
self.source = source_line_list
+ # now retrieve block name when possible
+ if self.items:
+ first = self.items[0]
+ self.name = first[1].get_identifier()
+
# this function is used to add a new element to self.items
# 'marker' is a marker string, or None
@@ -520,6 +559,13 @@ class DocBlock:
if not self.identifier:
self.identifier = content.get_identifier()
+
+ def find_content( self, marker ):
+ for item in self.items:
+ if ( item[0] == marker ):
+ return item[1]
+ return None
+
def dump( self ):
@@ -576,6 +622,163 @@ class DocBlock:
print block_footer
+######################################################################################
+#
+#
+# The DocSection class is used to store a given documentation section
+#
+# Each section is made of an identifier, an abstract and a description
+#
+# For example, look at:
+#
+# <Section> Basic_Data_Types
+#
+# <Abstract>
+# Definitions of basic FreeType data types
+#
+# <Description>
+# FreeType defines several basic data types for all its
+# operations....
+#
+class DocSection:
+
+ def __init__( self, block ):
+ self.block = block
+ self.name = string.lower(block.name)
+ self.abstract = block.find_content("abstract")
+ self.description = block.find_content("description")
+ title_content = block.find_content("title")
+ if title_content:
+ self.title = title_content.get_title()
+ else:
+ self.title = "UNKNOWN SECTION TITLE !!"
+ self.elements = {}
+ self.list = []
+ self.filename = self.name + ".html"
+
+ #sys.stderr.write( "new section '"+self.name+"'" )
+
+ def add_element( self, block ):
+ # check that we don't have a duplicate element in this
+ # section..
+ if self.elements.has_key( block.name ):
+ sys.stderr.write( "ERROR - duplicate element definition for " +
+ "'" + block.name + "' in section '" +
+ section.name + "'" )
+ sys.quit()
+
+ self.elements[ block.name ] = block
+ self.list.append( block )
+
+
+ def dump_html( self ):
+ """make an HTML page from a given DocSection"""
+
+ # print HTML header
+ print html_header
+
+ # print title
+ print section_title_header
+ print self.title
+ print section_title_footer
+
+ # print description
+ print block_header
+ self.description.dump_html()
+ print block_footer
+
+ # print elements
+ for element in self.list:
+ element.dump_html()
+
+ print html_footer
+
+
+
+
+
+class DocSectionList:
+
+ def __init__( self ):
+ self.sections = {}
+ self.list = []
+ self.current_section = None
+
+
+ def append_section( self, block ):
+ name = block.name
+ abstract = block.find_content( "abstract" )
+
+ if self.sections.has_key(name):
+ # there is already a section with this name in our
+ # list. We'll try to complete it.
+
+ section = self.sections[name]
+ if section.abstract:
+ # this section already has an abstract defined,
+ # simply check that the new section doesn't
+ # provide a new one.
+ if abstract:
+ stderr.write( "ERROR - duplicate section definition" +
+ " for '" + name + "'" )
+ sys.quit()
+ else:
+ # the old section didn't contain an abstract, we're
+ # now going to replace it
+ section.abstract = abstract
+ section.description = block.find_content( "description" )
+ else:
+ # a new section
+ section = DocSection( block )
+ self.sections[name] = section
+ self.list.append( section )
+
+ self.current_section = section
+
+
+ def append_block( self, block ):
+ if block.name:
+ section = block.find_content( "section" )
+ if section:
+ self.append_section( block )
+
+ elif self.current_section:
+ #sys.stderr.write( " new block" )
+ self.current_section.add_element( block )
+
+
+ def dump_html_toc( self ):
+ # dump an html table of contents
+ print html_header
+
+ print "<center><h1>Table of Contents</h1></center>"
+
+ print "<center><table cellpadding=5>"
+ for section in self.list:
+ print "<tr valign=top><td>"
+ print '<a href="'+section.filename+'">'
+ print section.title
+ print "</a></td><td>"
+ section.abstract.dump_html()
+ print "</td></tr>"
+
+ print "</table></center>"
+
+ print html_footer
+
+
+ def dump_html_sections( self ):
+ old_stdout = sys.stdout
+ for section in self.sections.values():
+ new_file = open( section.filename, "w" )
+ sys.stdout = new_file
+ section.dump_html()
+ new_file.close()
+
+ sys.stdout = old_stdout
+
+
+
# filter a given list of DocBlocks. Returns a new list
# of DocBlock objects that only contains element whose
# "type" (i.e. first marker) is in the "types" parameter
@@ -807,11 +1010,18 @@ def main( argv ):
list = make_block_list()
list = block_make_list(list)
- list2 = filter_blocks( list, ['type','macro','enum','constant', 'functype'] )
+ section_list = DocSectionList()
+ for block in list:
+ section_list.append_block( block )
+
+ section_list.dump_html_toc()
+ section_list.dump_html_sections()
+
+ #list2 = filter_blocks( list, ['type','macro','enum','constant', 'functype'] )
#list2 = list
- list2.sort( block_lexicographical_compare )
+ #list2.sort( block_lexicographical_compare )
- dump_html_1( list2 )
+ #dump_html_1( list2 )
#dump_doc_blocks( list )
#dump_block_lists( list )
#dump_html_1( list )