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


# Helper for the getprocaddress.c test.

glapi_xml_path = "../../src/mapi/glapi/gen/"

import sys, getopt, re
sys.path.append(glapi_xml_path)
import gl_XML
import license


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)
			functions.append(func)
	f.close
	return functions


class PrintExports(gl_XML.gl_print_base):
	def __init__(self):
		gl_XML.gl_print_base.__init__(self)

		self.name = "getprocaddress.py (from Mesa)"
		self.license = license.bsd_license_template % ( \
"""Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")

		self.tests = FindTestFunctions()
		self.prevCategory = ""
		return


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

	def printBody(self, api):
		prev_category = None
		

		for f in api.functionIterateByCategory():
			[category, num] = api.get_category_for_name( f.name )
			if category != prev_category:
				print '   { "-%s", NULL},' % category
				prev_category = category
			
			test = "NULL"
			for name in f.entry_points:
				if name in self.tests:
					test = "test_%s" % name
					break

			print '   { "gl%s", %s },' % (f.name, test)

		print ''
		print '   { NULL, NULL }'
		print '};'
		print ''
		return


if __name__ == '__main__':
	file_name = glapi_xml_path + "gl_API.xml"
    
	try:
		(args, trail) = getopt.getopt(sys.argv[1:], "f:")
	except Exception,e:
		show_usage()

	for (arg,val) in args:
		if arg == "-f":
			file_name = val

	printer = PrintExports()

	api = gl_XML.parse_GL_API( file_name, gl_XML.gl_item_factory() )

	printer.Print( api )