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

# $Id: getprocaddress.py,v 1.6 2004/11/27 19:57:46 brianp Exp $

# Helper for the getprocaddress.c test.

from xml.sax import saxutils
from xml.sax import make_parser
from xml.sax.handler import feature_namespaces

import sys, getopt, re
sys.path.append("../../src/mesa/glapi/" )
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.FilterGLAPISpecBase):
	name = "gl_exports.py (from Mesa)"

	def __init__(self):
		gl_XML.FilterGLAPISpecBase.__init__(self)
		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 = ""

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

	def printRealFooter(self):
		print"""
   { NULL, NULL }
};
"""

	def printFunction(self, f):
		if f.category != self.prevCategory:
			print '   { "-%s", NULL},' % f.category
			self.prevCategory = f.category
			
		if f.name in self.tests:
			test = "test_%s" % f.name
		else:
			test = "NULL"
		print '   { "gl%s", %s },' % (f.name, test)
		return


if __name__ == '__main__':
	file_name = "../../src/mesa/glapi/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

	dh = PrintExports()

	parser = make_parser()
	parser.setFeature(feature_namespaces, 0)
	parser.setContentHandler(dh)

	f = open(file_name)

	parser.parse(f)
	dh.printHeader()
	dh.printFunctions()
	dh.printFooter()