3 # DocMaker 0.2 (c) 2002 David Turner <david@freetype.org>
5 # This program is a re-write of the original DocMaker took used
6 # to generate the API Reference of the FreeType font engine
7 # by converting in-source comments into structured HTML
9 # This new version is capable of outputting XML data, as well
10 # as accepts more liberal formatting options
12 # It also uses regular expression matching and substitution
13 # to speed things significantly
19 from formatter import *
24 import sys, os, time, string, glob, getopt
27 def file_exists( pathname ):
28 """checks that a given file exists"""
31 file = open( pathname, "r" )
35 sys.stderr.write( pathname + " couldn't be accessed\n" )
40 def make_file_list( args = None ):
41 """builds a list of input files from command-line arguments"""
44 # sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
50 if string.find( pathname, '*' ) >= 0:
51 newpath = glob.glob( pathname )
52 newpath.sort() # sort files -- this is important because
53 # of the order of files
57 file_list.extend( newpath )
59 if len( file_list ) == 0:
62 # now filter the file list to remove non-existing ones
63 file_list = filter( file_exists, file_list )
70 print "\nDocMaker 0.2 Usage information\n"
71 print " docmaker [options] file1 [ file2 ... ]\n"
72 print "using the following options:\n"
73 print " -h : print this page"
74 print " -t : set project title, as in '-t \"My Project\"'"
75 print " -o : set output directory, as in '-o mydir'"
76 print " -p : set documentation prefix, as in '-p ft2'"
78 print " --title : same as -t, as in '--title=\"My Project\"'"
79 print " --output : same as -o, as in '--output=mydir'"
80 print " --prefix : same as -p, as in '--prefix=ft2'"
84 """main program loop"""
89 opts, args = getopt.getopt( sys.argv[1:],
91 [ "help", "title=", "output=", "prefix=" ] )
93 except getopt.GetoptError:
103 project_title = "Project"
104 project_prefix = None
108 if opt[0] in ( "-h", "--help" ):
112 if opt[0] in ( "-t", "--title" ):
113 project_title = opt[1]
115 if opt[0] in ( "-o", "--output" ):
116 utils.output_dir = opt[1]
118 if opt[0] in ( "-p", "--prefix" ):
119 project_prefix = opt[1]
123 # create context and processor
124 source_processor = SourceProcessor()
125 content_processor = ContentProcessor()
127 # retrieve the list of files to process
128 file_list = make_file_list( args )
129 for filename in file_list:
130 source_processor.parse_file( filename )
131 content_processor.parse_sources( source_processor )
134 content_processor.finish()
136 formatter = HtmlFormatter( content_processor, project_title, project_prefix )
139 formatter.index_dump()
140 formatter.section_dump_all()
143 # if called from the command line
145 if __name__ == '__main__':