This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / lib / freetype / src / tools / docmaker / docmaker.py
1 #!/usr/bin/env python
2 #
3 #  DocMaker 0.2 (c) 2002 David Turner <david@freetype.org>
4 #
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
8 #
9 # This new version is capable of outputting XML data, as well
10 # as accepts more liberal formatting options
11 #
12 # It also uses regular expression matching and substitution
13 # to speed things significantly
14 #
15
16 from sources   import *
17 from content   import *
18 from utils     import *
19 from formatter import *
20 from tohtml    import *
21
22 import utils
23
24 import sys, os, time, string, glob, getopt
25
26
27 def file_exists( pathname ):
28     """checks that a given file exists"""
29     result = 1
30     try:
31         file = open( pathname, "r" )
32         file.close()
33     except:
34         result = None
35         sys.stderr.write( pathname + " couldn't be accessed\n" )
36
37     return result
38
39
40 def make_file_list( args = None ):
41     """builds a list of input files from command-line arguments"""
42
43     file_list = []
44     # sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
45
46     if not args:
47         args = sys.argv[1 :]
48
49     for pathname in args:
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
54         else:
55             newpath = [pathname]
56             
57         file_list.extend( newpath )
58
59     if len( file_list ) == 0:
60         file_list = None
61     else:
62         # now filter the file list to remove non-existing ones
63         file_list = filter( file_exists, file_list )
64     
65     return file_list
66
67
68
69 def usage():
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'"
77     print ""
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'"
81     
82
83 def main( argv ):
84     """main program loop"""
85
86     global output_dir
87
88     try:
89         opts, args = getopt.getopt( sys.argv[1:],
90                                     "ht:o:p:",
91                                     [ "help", "title=", "output=", "prefix=" ] )
92
93     except getopt.GetoptError:
94         usage()
95         sys.exit( 2 )
96
97     if args == []:
98         usage()
99         sys.exit( 1 )
100
101     # process options
102     #
103     project_title  = "Project"
104     project_prefix = None
105     output_dir     = None
106
107     for opt in opts:
108         if opt[0] in ( "-h", "--help" ):
109             usage()
110             sys.exit( 0 )
111
112         if opt[0] in ( "-t", "--title" ):
113             project_title = opt[1]
114
115         if opt[0] in ( "-o", "--output" ):
116             utils.output_dir = opt[1]
117
118         if opt[0] in ( "-p", "--prefix" ):
119             project_prefix = opt[1]
120
121     check_output( )
122
123     # create context and processor
124     source_processor  = SourceProcessor()
125     content_processor = ContentProcessor()
126
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 )
132         
133     # process sections
134     content_processor.finish()
135
136     formatter = HtmlFormatter( content_processor, project_title, project_prefix )
137
138     formatter.toc_dump()
139     formatter.index_dump()
140     formatter.section_dump_all()
141
142
143 # if called from the command line
144 #
145 if __name__ == '__main__':
146     main( sys.argv )
147
148
149 # eof