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