misc/libfreetype/src/tools/docmaker/docmaker.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
#  DocMaker (c) 2002, 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 a re-write of the original DocMaker took used
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
# to generate the API Reference of the FreeType font engine
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
# by converting in-source comments into structured HTML.
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
# This new version is capable of outputting XML data, as well
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
# as accepts more liberal formatting options.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
# It also uses regular expression matching and substitution
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
# to speed things significantly.
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
from sources   import *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
from content   import *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
from utils     import *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
from formatter import *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
from tohtml    import *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
import utils
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
import sys, os, time, string, glob, getopt
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
def  usage():
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
    print "\nDocMaker Usage information\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
    print "  docmaker [options] file1 [file2 ...]\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
    print "using the following options:\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
    print "  -h : print this page"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
    print "  -t : set project title, as in '-t \"My Project\"'"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    print "  -o : set output directory, as in '-o mydir'"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
    print "  -p : set documentation prefix, as in '-p ft2'"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    print ""
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
    print "  --title  : same as -t, as in '--title=\"My Project\"'"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    print "  --output : same as -o, as in '--output=mydir'"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    print "  --prefix : same as -p, as in '--prefix=ft2'"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
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
def  main( argv ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    """main program loop"""
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    global output_dir
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    try:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
        opts, args = getopt.getopt( sys.argv[1:], \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
                                    "ht:o:p:",    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
                                    ["help", "title=", "output=", "prefix="] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    except getopt.GetoptError:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
        usage()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
        sys.exit( 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    if args == []:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
        usage()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
        sys.exit( 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    # process options
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    #
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    project_title  = "Project"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    project_prefix = None
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    output_dir     = None
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    for opt in opts:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
        if opt[0] in ( "-h", "--help" ):
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( 0 )
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
        if opt[0] in ( "-t", "--title" ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
            project_title = opt[1]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
        if opt[0] in ( "-o", "--output" ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
            utils.output_dir = opt[1]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
        if opt[0] in ( "-p", "--prefix" ):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
            project_prefix = opt[1]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    check_output()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    # create context and processor
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    source_processor  = SourceProcessor()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    content_processor = ContentProcessor()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    # retrieve the list of files to process
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    file_list = make_file_list( args )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    for filename in file_list:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
        source_processor.parse_file( filename )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
        content_processor.parse_sources( source_processor )
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
    # process sections
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    content_processor.finish()
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
    formatter = HtmlFormatter( content_processor, project_title, project_prefix )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    formatter.toc_dump()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    formatter.index_dump()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    formatter.section_dump_all()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
# if called from the command line
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
#
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
if __name__ == '__main__':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    main( sys.argv )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
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
# eof