Merge 25584, 25588.
[reactos.git] / reactos / dll / 3rdparty / freetype / src / tools / docmaker / docbeauty.py
1 #!/usr/bin/env python
2 #
3 # DocBeauty (c) 2003, 2004 David Turner <david@freetype.org>
4 #
5 # This program is used to beautify the documentation comments used
6 # in the FreeType 2 public headers.
7 #
8
9 from sources import *
10 from content import *
11 from utils import *
12
13 import utils
14
15 import sys, os, time, string, getopt
16
17 content_processor = ContentProcessor()
18
19
20 def beautify_block( block ):
21 if block.content:
22 content_processor.reset()
23
24 markups = content_processor.process_content( block.content )
25 text = []
26 first = 1
27
28 for markup in markups:
29 text.extend( markup.beautify( first ) )
30 first = 0
31
32 # now beautify the documentation "borders" themselves
33 lines = [ " /*************************************************************************" ]
34 for l in text:
35 lines.append( " *" + l )
36 lines.append( " */" )
37
38 block.lines = lines
39
40
41 def usage():
42 print "\nDocBeauty 0.1 Usage information\n"
43 print " docbeauty [options] file1 [ file2 ... ]\n"
44 print "using the following options:\n"
45 print " -h : print this page"
46 print " -b : backup original files with the 'orig' extension"
47 print ""
48 print " --backup : same as -b"
49
50
51 def main( argv ):
52 """main program loop"""
53
54 global output_dir
55
56 try:
57 opts, args = getopt.getopt( sys.argv[1:],
58 "hb",
59 [ "help", "backup" ] )
60
61 except getopt.GetoptError:
62 usage()
63 sys.exit( 2 )
64
65 if args == []:
66 usage()
67 sys.exit( 1 )
68
69 # process options
70 #
71 output_dir = None
72 do_backup = None
73
74 for opt in opts:
75 if opt[0] in ( "-h", "--help" ):
76 usage()
77 sys.exit( 0 )
78
79 if opt[0] in ( "-b", "--backup" ):
80 do_backup = 1
81
82 # create context and processor
83 source_processor = SourceProcessor()
84
85 # retrieve the list of files to process
86 file_list = make_file_list( args )
87 for filename in file_list:
88 source_processor.parse_file( filename )
89 for block in source_processor.blocks:
90 beautify_block( block )
91 new_name = filename + ".new"
92 ok = None
93 try:
94 file = open( new_name, "wt" )
95 for block in source_processor.blocks:
96 for line in block.lines:
97 file.write( line )
98 file.write( "\n" )
99 file.close()
100 except:
101 ok = 0
102
103 # if called from the command line
104 #
105 if __name__ == '__main__':
106 main( sys.argv )
107
108
109 # eof