1#!/usr/bin/env python 2 3 4# Helper for the getprocaddress.c test. 5 6 7import sys, getopt, re, os 8argc = len(sys.argv) 9if (argc): 10 glapi_xml_path = sys.argv[1] 11else: 12 glapi_xml_path = "../../src/mapi/glapi/gen/" 13 14sys.path.append(glapi_xml_path) 15import gl_XML 16import license 17 18 19 20def FindTestFunctions(): 21 """Scan getprocaddress.c for lines that start with "test_" to find 22 extension function tests. Return a list of names found.""" 23 functions = [] 24 f = open("getprocaddress.c") 25 if not f: 26 return functions 27 for line in f.readlines(): 28 v = re.search("^test_([a-zA-Z0-9]+)", line) 29 if v: 30 func = v.group(1) 31 functions.append(func) 32 f.close 33 return functions 34 35 36class PrintExports(gl_XML.gl_print_base): 37 def __init__(self): 38 gl_XML.gl_print_base.__init__(self) 39 40 self.name = "getprocaddress.py (from Mesa)" 41 self.license = license.bsd_license_template % ( \ 42"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 43(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") 44 45 self.tests = FindTestFunctions() 46 self.prevCategory = "" 47 return 48 49 50 def printRealHeader(self): 51 print """ 52struct name_test_pair { 53 const char *name; 54 GLboolean (*test)(generic_func); 55}; 56 57static struct name_test_pair functions[] = {""" 58 59 def printBody(self, api): 60 prev_category = None 61 62 63 for f in api.functionIterateByCategory(): 64 [category, num] = api.get_category_for_name( f.name ) 65 if category != prev_category: 66 print ' { "-%s", NULL},' % category 67 prev_category = category 68 69 test = "NULL" 70 for name in f.entry_points: 71 if name in self.tests: 72 test = "test_%s" % name 73 break 74 75 print ' { "gl%s", %s },' % (f.name, test) 76 77 print '' 78 print ' { NULL, NULL }' 79 print '};' 80 print '' 81 return 82 83 84if __name__ == '__main__': 85 file_name = os.path.join(glapi_xml_path, "gl_API.xml") 86 87 try: 88 (args, trail) = getopt.getopt(sys.argv[1:], "f:") 89 except Exception,e: 90 show_usage() 91 92 for (arg,val) in args: 93 if arg == "-f": 94 file_name = val 95 96 printer = PrintExports() 97 98 api = gl_XML.parse_GL_API( file_name, gl_XML.gl_item_factory() ) 99 100 printer.Print( api ) 101