Files
@ 6e8ae7e0375a
Branch filter:
Location: libtransport.git/backends/libpurple/gen_dynamic_purple.py - annotation
6e8ae7e0375a
4.2 KiB
text/x-python
fixed include
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f 592c3ab0d88f | import sys
import os
methods = []
definitions = []
if len(sys.argv) != 2:
print "Usage:", sys.argv[0], "<path_to_libpurple_dir>"
sys.exit(1)
def handle_file(cpp):
global methods
new_file = ""
f = open(cpp, "r")
for line in f.readlines():
new_line = ""
index = 0
while index < len(line):
new_line += line[index]
if line[index:].startswith("purple_") or line[index:].startswith("wpurple_"):
if line[index:].find("=") != -1 and line[index:].find("=") < line[index:].find("("):
index += 1
continue
if line[index-1] == "_" or line[index:].find("(") == -1:
index += 1
continue
m = line[index:line[index:].find("(")+index]
new_line += m[1:] + "_wrapped("
index += len(m)
if not m in methods and len(m) != 0:
methods += [m + "("]
index += 1
new_file += new_line
f.close()
return new_file
def handle_header(header, method):
global definitions
f = open(os.path.join(sys.argv[1], header), "r")
lines = f.readlines()
for i in range(len(lines)):
line = lines[i]
if line.find(method) != -1:
m = line[:-1]
l = unicode(m).strip()
if l.endswith(")"):
continue
index = i;
while not m.endswith(";"):
index += 1
m += " " + lines[index][:-1].lstrip()
l = unicode(m).strip()
if (l.startswith("#") or l.startswith("*") or l.startswith("/*") or l.count("***") != 0 or l.count("&&") != 0
or l.endswith(")")):
continue;
if not m in definitions:
definitions += [m]
break
f.close()
def get_raw_args(d):
return d[d.find("(")+1:-2]
def get_args(d):
x = d[d.find("(")+1:-2]
x = x.split(",")
args = []
for arg in x:
y = arg.split(" ")
if len(y) == 1:
continue
args += [y[-1].replace("*", "")]
return args
def get_name(d):
x = d[:d.find("(")+1].lstrip()
return x[x.find("purple_"):]
def get_rtype(d):
return d[:d.find("purple_") - 1].lstrip()
def output():
global definitions
header = open("purple_defs.h", "w")
print >> header, "#pragma once"
print >> header, "#ifdef WIN32"
for d in definitions:
#typedef void (WINAPI * purple_util_set_user_wrapped_func)(const char *dir);
print >> header, "typedef", get_rtype(d), "(WINAPI *", get_name(d)[:-1] + "spectrum_fnc)(" + get_raw_args(d) + ");"
#extern purple_util_set_user_wrapped_func purple_util_set_user_wrapped;
print >> header, "extern", get_name(d)[:-1] + "_wrapped_fnc", get_name(d)[:-1] + "_wrapped;"
print >> header, ""
print >> header, ""
print >> header, "#else"
print >> header, ""
for d in definitions:
#define purple_util_set_user_wrapped purple_util_set_user
print >> header, "#define", get_name(d)[:-1] + "_wrapped", get_name(d)[:-1]
print >> header, "#endif"
print >> header, ""
print >> header, "bool resolvePurpleFunctions();"
print >> header, ""
cpp = open("purple_defs.cpp", "w")
print >> cpp, "#include \"purple_defs.h\""
print >> cpp, ""
print >> cpp, "#ifdef WIN32"
print >> cpp, "static HMODULE f_hPurple = NULL;"
for d in definitions:
#purple_util_set_user_wrapped_fnc purple_util_set_user_wrapped = NULL;
print >> cpp, get_name(d)[:-1] + "_wrapped_fnc", get_name(d)[:-1] + "_wrapped = NULL;"
print >> cpp, "#endif"
print >> cpp, "bool resolvePurpleFunctions() {"
print >> cpp, "#ifdef WIN32"
print >> cpp, "\tf_hPurple = LoadLibrary(\"libpurple.dll\");"
print >> cpp, "\tif (!f_hPurple)"
print >> cpp, "\t\t\treturn false;"
for d in definitions:
#purple_util_set_user_wrapped = (purple_util_set_user_wrapped_func)GetProcAddress(f_hPurple, "purple_util_set_user_dir");
print >> cpp, "\t" + get_name(d)[:-1] + "_wrapped = (" + get_name(d)[:-1] + "_wrapped_fnc)GetProcAddress(f_hPurple, \"" + get_name(d)[:-1] + "\");"
#if (!purple_util_set_user_wrapped)
print >> cpp, "\tif (!" + get_name(d)[:-1] + "_wrapped)"
print >> cpp, "\t\treturn false";
print >> cpp, ""
print >> cpp, "#endif"
print >> cpp, "\treturn true;"
print >> cpp, "}"
print >> cpp, ""
cpp.close()
header.close()
for f in os.listdir("."):
if not f.endswith(".cpp") or f.startswith("purple_defs"):
continue
new_file = handle_file(f)
fd = open(f, "w")
fd.write(new_file)
fd.close()
for f in os.listdir(sys.argv[1]):
if not f.endswith(".h"):
continue
for m in methods:
handle_header(f, m)
output()
|