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