-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert.py
executable file
·65 lines (61 loc) · 1.8 KB
/
convert.py
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
import os,sys
def main(protos):
line = protos.readline()
while (line != ''):
convert(line)
line = protos.readline()
def convert(line):
splitline = line.split("\t", 1)
if len(splitline) == 1:
splitline = line.split(" ", 1)
return_type = splitline[0]
arg_list = splitline[1].split('(')[1][:-3]
arg_dict = []
for pair in arg_list.split(","):
pair = pair.strip()
if pair != "":
pair = pair.split(" ")
arg_dict.append(pair[1])
func_name = splitline[1].split()[0].split('(')[0]
sys.stdout.write("\tdef " + func_name + "(self")
if (func_name[:3] == "set") or (func_name[:3] == "add"):
for arg in arg_dict:
if arg != "pXfoObj":
sys.stdout.write(", " + arg)
sys.stdout.write("):\n")
if return_type == "void":
sys.stdout.write("\t\txfoifc_c.xfo_" + func_name + "(")
count = 0
for arg in arg_dict:
if count != 0:
sys.stdout.write(", ")
if arg == "pXfoObj":
sys.stdout.write("self.")
sys.stdout.write(arg)
count += 1
sys.stdout.write(")\n")
elif return_type == "char*":
sys.stdout.write("\t\tcstr = create_string_buffer(1024)\n")
sys.stdout.write("\t\txfoifc_c.xfo_" + func_name + ".argtypes = [c_void_p, c_char_p, c_int]\n")
sys.stdout.write("\t\txfoifc_c.xfo_" + func_name + ".restype = c_char_p\n")
sys.stdout.write("\t\treturn xfoifc_c.xfo_" + func_name + "(")
sys.stdout.write("self.pXfoObj, cstr, 1024")
sys.stdout.write(")\n")
if (len(arg_dict) != 3):
sys.stderr.write("Warning: " + line)
sys.stderr.write("\n")
else:
sys.stdout.write("\t\treturn xfoifc_c.xfo_" + func_name + "(")
count = 0
for arg in arg_dict:
if count != 0:
sys.stdout.write(", ")
if arg == "pXfoObj":
sys.stdout.write("self.")
sys.stdout.write(arg)
count += 1
sys.stdout.write(")\n")
print
if __name__=="__main__":
protos = file(sys.argv[1], 'r')
main(protos)