summaryrefslogtreecommitdiffstats
path: root/progs/tests/getprocaddress.py
blob: e5d2fbbc6f57d3c6ca6bc63b332bdc63bc46bd66 (plain)
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
#!/usr/bin/env python

# $Id: getprocaddress.py,v 1.1 2002/11/08 15:35:47 brianp Exp $

# Helper for the getprocaddress.c test.


import re, string

def PrintHead():
	print """
struct name_test_pair {
   const char *name;
   GLboolean (*test)(void *);
};
   
static struct name_test_pair functions[] = {"""


def PrintTail():
	print"""
   { NULL, NULL }
};
"""


def HaveTest(function):
	testFuncs = [
		"glActiveTextureARB",
		"glSampleCoverageARB"
	]
	if function in testFuncs:
		return 1
	else:
		return 0


def FindTestFunctions():
	"""Scan getprocaddress.c for lines that start with "test_" to find
	extension function tests.  Return a list of names found."""
	functions = []
	f = open("getprocaddress.c")
	if not f:
		return functions
	for line in f.readlines():
		v = re.search("^test_([a-zA-Z0-9]+)", line)
		if v:
			func = v.group(1)
			#print "Found -%s-" % func
			functions.append(func)
	f.close
	return functions


def PrintFunctions(specFile, tests):

	# init some vars
	prevCategory = ''
	funcName = ''

	f = open(specFile)
	for line in f.readlines():

		# split line into tokens
		tokens = string.split(line)

		if len(tokens) > 0 and line[0] != '#':

			if tokens[0] == 'name':
				if funcName != '':
					if category != prevCategory:
						print '   { "-%s", NULL},' % category
						prevCategory = category

#					if HaveTest("gl" + funcName):
					if funcName in tests:
						test = "test_%s" % funcName
					else:
						test = "NULL"
					print '   { "gl%s", %s },' % (funcName, test)
				funcName = tokens[1]

			elif tokens[0] == 'category':
				category = tokens[1]

			#endif
		#endif
	#endfor
#enddef


tests = FindTestFunctions()
PrintHead()
PrintFunctions("../bin/APIspec", tests)
PrintTail()