Changeset - dea27821a7e8
[Not reviewed]
0 1 0
HanzZ - 13 years ago 2012-04-10 10:51:12
hanzz.k@gmail.com
Show methods which are not found + find also win32dep.h methods
1 file changed with 28 insertions and 3 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/gen_dynamic_purple.py
Show inline comments
 
@@ -10,35 +10,42 @@ if len(sys.argv) != 2:
 
	print "Usage:", sys.argv[0], "<path_to_libpurple_dir_containing_libpurple_headers>"
 
	sys.exit(1)
 

	
 

	
 
def handle_file(cpp):
 
	global methods
 
	sys.stdout.write("getting used methods in " + cpp + ": ")
 
	sys.stdout.flush()
 

	
 
	counter = 0
 

	
 
	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:
 
				if line[index-1] == "_" or line[index:].find("(") == -1 or line[index:].startswith("purple_commands_init"):
 
					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:
 
				if not m + "(" in methods and len(m) != 0:
 
					methods += [m + "("]
 
					counter += 1
 
			index += 1
 
		new_file += new_line
 
	f.close()
 

	
 
	print counter, "new methods found"
 
	return new_file
 

	
 
def handle_header(header, method):
 
	global definitions
 

	
 
	f = open(os.path.join(sys.argv[1], header), "r")
 
@@ -60,12 +67,13 @@ def handle_header(header, method):
 
			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:
 
				print "found", method[:-1], "in", header
 
				definitions += [m]
 
			break
 
	f.close()
 

	
 
def get_raw_args(d):
 
	return d[d.find("(")+1:-2]
 
@@ -151,18 +159,35 @@ def output():
 
		
 

	
 
for f in os.listdir("."):
 
	if not f.endswith(".cpp") or f.startswith("purple_defs"):
 
		continue
 
	new_file = handle_file(f)
 

	
 
	print "updating", f
 
	fd = open(f, "w")
 
	fd.write(new_file)
 
	fd.close()
 

	
 
print methods
 
for f in os.listdir(sys.argv[1]):
 
	if not f.endswith(".h"):
 
		continue
 
	for m in methods:
 
		handle_header(f, m)
 

	
 
sys.argv[1] = sys.argv[1] + "/win32"
 
for f in os.listdir(sys.argv[1]):
 
	if not f.endswith(".h"):
 
		continue
 
	for m in methods:
 
		handle_header(f, m)
 

	
 
for m in methods:
 
	found = False
 
	for d in definitions:
 
		if d.find(m[:-1]) != -1:
 
			found = True
 
			break
 
	if not found:
 
		print "NOT FOUND:", m
 

	
 
output()
0 comments (0 inline, 0 general)