File: create_docs_function_list.py

package info (click to toggle)
openclonk 8.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 169,656 kB
  • sloc: cpp: 180,484; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 148; sh: 101; javascript: 34
file content (63 lines) | stat: -rw-r--r-- 1,780 bytes parent folder | download | duplicates (7)
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
import xml.dom.minidom as XML
import sys
import os

# standard path assumes that this script is in OpenClonk/tools
directory = "../docs/sdk/script/fn";
if len(sys.argv) > 1:
	directory = sys.argv[1]
print("Working on " + directory)
# open output file at this point to write to when recursing the directory
output = open("functionlist.txt", "w+")
output.write("$functions = array(\n")

for dirname, dirnames, filenames in os.walk(directory):
	for filename in filenames:
		# only xml files
		if filename.find(".xml") == -1:
			continue;
		filename = dirname + "/" + filename
		print(filename)
		dom = XML.parse(filename);
		funcs = dom.getElementsByTagName("funcs")[0]
		func = funcs.getElementsByTagName("func")
		
		# no function? might be a constant!
		if not func or len(func) == 0:
			continue
		func = func[0]
		
		title = func.getElementsByTagName("title")[0].firstChild.nodeValue
		syntax = func.getElementsByTagName("syntax")[0]
		rtype = syntax.getElementsByTagName("rtype")[0].firstChild.nodeValue
		
		# write "\t'int Abs ("
		output.write("\t'" + rtype + " " + title + " (")
		
		params = syntax.getElementsByTagName("params")
		if not params or len(params) == 0:
			pass
		else:
			firstpar = True
			params = params[0]
			for param in params.getElementsByTagName("param"):
				type = param.getElementsByTagName("type")
				
				# might be a "..." parameter? See FindObject.xml
				if not type or len(type) == 0 or not type[0].firstChild:
					type = ""
				else:
					type = type[0].firstChild.nodeValue + " "
				
				name = param.getElementsByTagName("name")[0].firstChild.nodeValue
				
				if not firstpar:
					output.write(", ")
				firstpar = False
				output.write(type + name);
		output.write(")',\n");
			
output.write(");\n")
output.close()

print("DONE!")