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