1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
"""h2xml - convert C include file(s) into an xml file by running gccxml."""
import sys, os, ConfigParser
from ctypeslib.codegen import cparser
from optparse import OptionParser
def compile_to_xml(argv):
def add_option(option, opt, value, parser):
parser.values.gccxml_options.extend((opt, value))
# Hm, should there be a way to disable the config file?
# And then, this should be done AFTER the parameters are processed.
config = ConfigParser.ConfigParser()
try:
config.read("h2xml.cfg")
except ConfigParser.ParsingError, detail:
print >> sys.stderr, detail
return 1
parser = OptionParser("usage: %prog includefile ... [options]")
parser.add_option("-q", "--quiet",
dest="quiet",
action="store_true",
default=False)
parser.add_option("-D",
type="string",
action="callback",
callback=add_option,
dest="gccxml_options",
help="macros to define",
metavar="NAME[=VALUE]",
default=[])
parser.add_option("-U",
type="string",
action="callback",
callback=add_option,
help="macros to undefine",
metavar="NAME")
parser.add_option("-I",
type="string",
action="callback",
callback=add_option,
dest="gccxml_options",
help="additional include directories",
metavar="DIRECTORY")
parser.add_option("-o",
dest="xmlfile",
help="XML output filename",
default=None)
parser.add_option("-c", "--cpp-symbols",
dest="cpp_symbols",
action="store_true",
help="try to find #define symbols - this may give compiler errors, " \
"so it's off by default.",
default=False)
parser.add_option("-k",
dest="keep_temporary_files",
action="store_true",
help="don't delete the temporary files created "\
"(useful for finding problems)",
default=False)
options, files = parser.parse_args(argv[1:])
if not files:
print "Error: no files to process"
print >> sys.stderr, __doc__
return 1
options.flags = options.gccxml_options
options.verbose = not options.quiet
parser = cparser.IncludeParser(options)
parser.parse(files)
def main(argv=None):
if argv is None:
argv = sys.argv
try:
compile_to_xml(argv)
except cparser.CompilerError, detail:
print >> sys.stderr, "CompilerError:", detail
return 1
if __name__ == "__main__":
sys.exit(main())
|