1
2import sys
3from xml.etree import ElementTree
4
5CTEMPLATE = \
6"""
7/*
8 * This file has been auto-generated from the introspection data available
9 * in the at-spi2-core repository. The D-Bus procol is defined in this
10 * repository, which can be found at:
11 *
12 * http://download.gnome.org/sources/at-spi2-core/0.1/
13 *
14 * DO NOT EDIT.
15 */
16
17%s
18"""
19
20HTEMPLATE = \
21"""
22/*
23 * This file has been auto-generated from the introspection data available
24 * in the at-spi2-core repository. The D-Bus procol is defined in this
25 * repository, which can be found at:
26 *
27 * http://download.gnome.org/sources/at-spi2-core/0.1/
28 *
29 * DO NOT EDIT.
30 */
31
32#ifndef SPI_INTROSPECTION_DATA_H_
33#define SPI_INTROSPECTION_DATA_H_
34
35%s
36
37#endif /* SPI_INTROSPECTION_DATA_H_ */
38"""
39
40DECTEMPLATE = \
41"""
42extern const char *%s;
43"""
44
45DEFTEMPLATE = \
46"""
47const char *%s =
48%s;
49"""
50
51VERSION = "0.1.7"
52
53def convert_name (name):
54	return "spi_" + name.replace (".", "_")
55
56def convert_contents (contents):
57	contents = contents.replace ("\"", "\\\"")
58	literals = ["\"%s\"" % (line) for line in contents.split ("\n")]
59	return "\n".join (literals)
60
61def main (argv):
62	#Open the XML file and process includes.
63	tree = ElementTree.parse ("Processed.xml")
64	root = tree.getroot ()
65
66	#Open the output files.
67	cfile = open ("introspection.c", "w")
68	hfile = open ("introspection.h", "w")
69
70	ccontents = ""
71	hcontents = ""
72
73	for itf in root.findall ("node/interface"):
74		#Get and convert the name of the interface.
75		name = convert_name (itf.attrib["name"])
76
77		#Create the introspection string with version information.
78		itf.attrib["version"] = VERSION
79		contents = convert_contents (ElementTree.tostring (itf))
80
81		hcontents += DECTEMPLATE % (name)
82		ccontents += DEFTEMPLATE % (name, contents)
83
84	cfile.write (CTEMPLATE % (ccontents))
85	hfile.write (HTEMPLATE % (hcontents))
86
87	cfile.close ()
88	hfile.close ()
89
90if __name__ == "__main__":
91	sys.exit(main(sys.argv))
92