* docs/docmaker.py: updated the DocMaker script in order to add command line options (--output,--prefix,--title), fix the erroneous line numbers reported during errors and warnings, and other formatting issues..
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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
diff --git a/docs/docmaker.py b/docs/docmaker.py
index d09a642..08ff445 100644
--- a/docs/docmaker.py
+++ b/docs/docmaker.py
@@ -1,18 +1,46 @@
#!/usr/bin/env python
#
-# DocMaker is a very simple program used to generate HTML documentation
-# from the source files of the FreeType packages.
+# DocMaker 0.1 (c) 2000-2001 David Turner <david@freetype.org>
+#
+# DocMaker is a very simple program used to generate the API Reference
+# of programs by extracting comments from source files, and generating
+# the equivalent HTML documentation.
+#
+# DocMaker is very similar to other tools like Doxygen, with the
+# following differences:
+#
+# - it is written in Python (so it's slow, but easy to maintain and
+# improve)
+#
+# - the comment syntax used by DocMaker is simpler and makes for
+# clearer comments
+#
+# Of course, it doesn't have all the goodies of most similar tools,
+# (e.g. C++ class hierarchies), but hey, it's only 2000 lines of
+# python
+#
+# DocMaker is mainly used to generate the API references of several
+# FreeType packages.
#
-# I should really be using regular expressions to do this, but hey,
-# i'm too lazy right now, and the damn thing seems to work :-)
# - David
#
-import fileinput, sys, string, glob
+import fileinput, sys, os, string, glob, getopt
# The Project's title. This can be overridden from the command line with
-# an option.
-project_title = "Project"
+# the options "-t" or "--title"
+project_title = "Project"
+
+# The project's filename prefix. This can be set from the command line with
+# the options "-p" or "--prefix"
+#
+project_prefix = ""
+
+# The project's documentation output directory. This can be set from the
+# command line with the options "-o" or "--output"
+#
+output_dir = None
+
# The following defines the HTML header used by all generated pages.
#
@@ -22,7 +50,7 @@ html_header_1 = """\
<title>"""
html_header_2= """ API Reference</title>
-<basefont face="Georgia, Arial, Helvetica, Geneva">
+<basefont face="Verdana,Geneva,Arial,Helvetica">
<style content="text/css">
P { text-align=justify }
H1 { text-align=center }
@@ -43,6 +71,7 @@ html_header_3=""" API Reference</h1></center>
#
html_header = html_header_1 + project_title + html_header_2 + project_title + html_header_3
+
# The HTML footer used by all generated pages.
#
html_footer = """\
@@ -141,13 +170,50 @@ def sort_order_list( input_list, order_list ):
# Translate a single line of source to HTML. This will convert
# a "<" into "<.", ">" into ">.", etc.
#
-def html_format( line )
+def html_format( line ):
result = string.replace( line, "<", "<." )
result = string.replace( line, ">", ">." )
result = string.replace( line, "&", "&." )
return result
+# open the standard output to a given project documentation file
+# use "output_dir" to determine the filename location, when necessary
+# and save the old stdout in a tuple that is returned by this function
+#
+def open_output( filename ):
+ global output_dir
+
+ if output_dir and output_dir != "":
+ filename = output_dir + os.sep + filename
+
+ old_stdout = sys.stdout
+ new_file = open( filename, "w" )
+ sys.stdout = new_file
+
+ return ( new_file, old_stdout )
+
+
+# close the output that was returned by "close_output"
+#
+#
+def close_output( output ):
+ output[0].close()
+ sys.stdout = output[1]
+
+# check output directoy
+#
+def check_output( ):
+ global output_dir
+ if output_dir:
+ if output_dir != "":
+ if not os.path.isdir( output_dir ):
+ sys.stderr.write( "argument '"+output_dir+"' is not a valid directory" )
+ sys.exit(2)
+ else:
+ output_dir = None
+
+
# The FreeType 2 reference is extracted from the source files. These
# contain various comment blocks that follow one of the following formats:
#
@@ -346,11 +412,12 @@ class DocParagraph:
# we need to find non-alphanumeric characters
#
- i = len( word )
- while i > 0 and not word[i - 1] in alphanum:
- i = i - 1
-
- if i > 0:
+ l = len( word )
+ i = 0
+ while i < l and word[i] in alphanum:
+ i = i + 1
+
+ if i < l:
extra = word[i :]
word = word[0 : i]
@@ -363,7 +430,7 @@ class DocParagraph:
if cursor + len( word ) + 1 > max_width:
print html_format( line )
cursor = 0
- line = ""
+ line = ""
line = line + word
if not extra:
@@ -413,7 +480,7 @@ class DocParagraph:
# DocContent is used to store the content of a given marker.
#
# The "self.items" list contains (field,elements) records, where "field"
-# corresponds to a given structure fields or function parameter (indicated
+# corresponds to a given structure field or function parameter (indicated
# by a "::"), or NULL for a normal section of text/code.
#
# Hence, the following example:
@@ -871,7 +938,7 @@ class DocSection:
# section
#
if self.elements.has_key( block.name ):
- self.print_error( "duplicate element definition for " +
+ block.print_error( "duplicate element definition for " +
"'" + block.name + "' " +
"in section " +
"'" + self.name + "'\n" +
@@ -1052,22 +1119,20 @@ class DocSectionList:
def dump_html_sections( self ):
- old_stdout = sys.stdout
-
+
for section in self.sections.values():
if section.filename:
- new_file = open( section.filename, "w" )
- sys.stdout = new_file
+ output = open_output( section.filename )
+
section.dump_html( self.identifiers )
- new_file.close()
+
+ close_output( output )
- sys.stdout = old_stdout
def dump_html_index( self ):
- old_stdout = sys.stdout
- new_file = open( self.index_filename, "w" )
- sys.stdout = new_file
+
+ output = open_output( self.index_filename )
num_columns = 3
total = len( self.index )
@@ -1096,7 +1161,7 @@ class DocSectionList:
print "</tr></table></center>"
print html_footer
- sys.stdout = old_stdout
+ close_output( output )
@@ -1190,9 +1255,7 @@ class DocDocument:
def dump_toc_html( self ):
# dump an html table of contents
#
- old_stdout = sys.stdout
- new_file = open( self.section_list.toc_filename, "w" )
- sys.stdout = new_file
+ output = open_output( self.section_list.toc_filename )
print html_header
@@ -1240,7 +1303,7 @@ class DocDocument:
print html_footer
- sys.stdout = old_stdout
+ close_output( output )
def dump_index_html( self ):
@@ -1317,13 +1380,16 @@ def add_new_block( list, filename, lineno, block_lines, source_lines ):
list.append( block )
-def make_block_list():
+def make_block_list( args = None ):
"""parse a file and extract comments blocks from it"""
file_list = []
# sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
- for pathname in sys.argv[1 :]:
+ if not args:
+ args = sys.argv[1:]
+
+ for pathname in args:
if string.find( pathname, '*' ) >= 0:
newpath = glob.glob( pathname )
newpath.sort() # sort files -- this is important because
@@ -1358,6 +1424,7 @@ def make_block_list():
source = []
state = 0
+ fileinput.close()
for line in fileinput.input( file_list ):
l = len( line )
if l > 0 and line[l - 1] == '\012':
@@ -1399,7 +1466,7 @@ def make_block_list():
block = []
source = []
format = 1
- lineno = fileinput.lineno()
+ lineno = fileinput.filelineno()
elif i == l - 1 and line2[i] == '/':
# this is '/**' followed by any number of '*', followed
@@ -1408,7 +1475,7 @@ def make_block_list():
block = []
source = []
format = 2
- lineno = fileinput.lineno()
+ lineno = fileinput.filelineno()
##############################################################
#
@@ -1507,39 +1574,73 @@ def dump_block_list( list ):
print "---------the end-----------------------"
+def usage():
+ print "\nDocMaker 0.1 Usage information\n"
+ print " docmaker [options] file1 [ file2 ... ]\n"
+ print "using the following options:\n"
+ print " -h : print this page"
+ print " -t : set project title, as in '-t \"My Project\"'"
+ print " -o : set output directory, as in '-o mydir'"
+ print " -p : set documentation prefix, as in '-p ft2'"
+ print ""
+ print " --title : same as -t, as in '--title=\"My Project\"'"
+ print " --output : same as -o, as in '--output=mydir'"
+ print " --prefix : same as -p, as in '--prefix=ft2'"
+
+
def main( argv ):
"""main program loop"""
+ global output_dir, project_title, project_prefix
+ global html_header, html_header1, html_header2, html_header3
+
+ try:
+ opts, args = getopt.getopt( sys.argv[1:], "ht:o:p:", [ "help", "title=", "output=", "prefix=" ] )
+
+ except getopt.GetoptError:
+ usage()
+ sys.exit(2)
+
+ if args == []:
+ usage()
+ sys.exit(1)
+
+ # process options
+ project_title = "Project"
+ project_prefix = None
+ output_dir = None
+
+ for opt in opts:
+ if opt[0] in ( "-h", "--help" ):
+ usage()
+ sys.exit(0)
+
+ if opt[0] in ( "-t", "--title" ):
+ project_title = opt[1]
+
+ if opt[0] in ( "-o", "--output" ):
+ output_dir = opt[1]
+
+ if opt[0] in ( "-p", "--prefix" ):
+ project_prefix = opt[1]
+
+ html_header = html_header_1 + project_title + html_header_2 + project_title + html_header_3
+ check_output( )
+
# we begin by simply building a list of DocBlock elements
- #
- sys.stderr.write( "extracting comment blocks from sources...\n" )
- list = make_block_list()
+ list = make_block_list( args )
# now, sort the blocks into sections
- #
document = DocDocument()
for block in list:
document.append_block( block )
- document.prepare_files( "ft2" )
+ document.prepare_files( project_prefix )
document.dump_toc_html()
document.dump_sections_html()
document.dump_index_html()
-## section_list = DocSectionList()
-## for block in list:
-## section_list.append_block( block )
-##
-## section_list.prepare_files( "ft2" )
-
-## # dump the section list TOC and sections
-## #
-## section_list.dump_html_toc()
-## section_list.dump_html_sections()
-## section_list.dump_html_index()
-
-
# if called from the command line
#
if __name__ == '__main__':