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