misc/libfreetype/src/tools/docmaker/docbeauty.py
changeset 9372 915436ff64ab
parent 9371 f3840de881bd
child 9373 b769a8e38cbd
equal deleted inserted replaced
9371:f3840de881bd 9372:915436ff64ab
     1 #!/usr/bin/env python
       
     2 #
       
     3 #  DocBeauty (c) 2003, 2004, 2008 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 
       
    18 content_processor = ContentProcessor()
       
    19 
       
    20 
       
    21 def  beautify_block( block ):
       
    22     if block.content:
       
    23         content_processor.reset()
       
    24 
       
    25         markups = content_processor.process_content( block.content )
       
    26         text    = []
       
    27         first   = 1
       
    28 
       
    29         for markup in markups:
       
    30             text.extend( markup.beautify( first ) )
       
    31             first = 0
       
    32 
       
    33         # now beautify the documentation "borders" themselves
       
    34         lines = [" /*************************************************************************"]
       
    35         for l in text:
       
    36             lines.append( "  *" + l )
       
    37         lines.append( "  */" )
       
    38 
       
    39         block.lines = lines
       
    40 
       
    41 
       
    42 def  usage():
       
    43     print "\nDocBeauty 0.1 Usage information\n"
       
    44     print "  docbeauty [options] file1 [file2 ...]\n"
       
    45     print "using the following options:\n"
       
    46     print "  -h : print this page"
       
    47     print "  -b : backup original files with the 'orig' extension"
       
    48     print ""
       
    49     print "  --backup : same as -b"
       
    50 
       
    51 
       
    52 def  main( argv ):
       
    53     """main program loop"""
       
    54 
       
    55     global output_dir
       
    56 
       
    57     try:
       
    58         opts, args = getopt.getopt( sys.argv[1:], \
       
    59                                     "hb",         \
       
    60                                     ["help", "backup"] )
       
    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 
       
    90         for block in source_processor.blocks:
       
    91             beautify_block( block )
       
    92 
       
    93         new_name = filename + ".new"
       
    94         ok       = None
       
    95 
       
    96         try:
       
    97             file = open( new_name, "wt" )
       
    98             for block in source_processor.blocks:
       
    99                 for line in block.lines:
       
   100                     file.write( line )
       
   101                     file.write( "\n" )
       
   102             file.close()
       
   103         except:
       
   104             ok = 0
       
   105 
       
   106 
       
   107 # if called from the command line
       
   108 #
       
   109 if __name__ == '__main__':
       
   110     main( sys.argv )
       
   111 
       
   112 
       
   113 # eof