Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # $Id: getprocaddress.py,v 1.1 2002/11/08 15:35:47 brianp Exp $ |
| 4 | |
| 5 | # Helper for the getprocaddress.c test. |
| 6 | |
| 7 | |
| 8 | import re, string |
| 9 | |
| 10 | def PrintHead(): |
| 11 | print """ |
| 12 | struct name_test_pair { |
| 13 | const char *name; |
| 14 | GLboolean (*test)(void *); |
| 15 | }; |
| 16 | |
| 17 | static struct name_test_pair functions[] = {""" |
| 18 | |
| 19 | |
| 20 | def PrintTail(): |
| 21 | print""" |
| 22 | { NULL, NULL } |
| 23 | }; |
| 24 | """ |
| 25 | |
| 26 | |
| 27 | def HaveTest(function): |
| 28 | testFuncs = [ |
| 29 | "glActiveTextureARB", |
| 30 | "glSampleCoverageARB" |
| 31 | ] |
| 32 | if function in testFuncs: |
| 33 | return 1 |
| 34 | else: |
| 35 | return 0 |
| 36 | |
| 37 | |
| 38 | def FindTestFunctions(): |
| 39 | """Scan getprocaddress.c for lines that start with "test_" to find |
| 40 | extension function tests. Return a list of names found.""" |
| 41 | functions = [] |
| 42 | f = open("getprocaddress.c") |
| 43 | if not f: |
| 44 | return functions |
| 45 | for line in f.readlines(): |
| 46 | v = re.search("^test_([a-zA-Z0-9]+)", line) |
| 47 | if v: |
| 48 | func = v.group(1) |
| 49 | #print "Found -%s-" % func |
| 50 | functions.append(func) |
| 51 | f.close |
| 52 | return functions |
| 53 | |
| 54 | |
| 55 | def PrintFunctions(specFile, tests): |
| 56 | |
| 57 | # init some vars |
| 58 | prevCategory = '' |
| 59 | funcName = '' |
| 60 | |
| 61 | f = open(specFile) |
| 62 | for line in f.readlines(): |
| 63 | |
| 64 | # split line into tokens |
| 65 | tokens = string.split(line) |
| 66 | |
| 67 | if len(tokens) > 0 and line[0] != '#': |
| 68 | |
| 69 | if tokens[0] == 'name': |
| 70 | if funcName != '': |
| 71 | if category != prevCategory: |
| 72 | print ' { "-%s", NULL},' % category |
| 73 | prevCategory = category |
| 74 | |
| 75 | # if HaveTest("gl" + funcName): |
| 76 | if funcName in tests: |
| 77 | test = "test_%s" % funcName |
| 78 | else: |
| 79 | test = "NULL" |
| 80 | print ' { "gl%s", %s },' % (funcName, test) |
| 81 | funcName = tokens[1] |
| 82 | |
| 83 | elif tokens[0] == 'category': |
| 84 | category = tokens[1] |
| 85 | |
| 86 | #endif |
| 87 | #endif |
| 88 | #endfor |
| 89 | #enddef |
| 90 | |
| 91 | |
| 92 | tests = FindTestFunctions() |
| 93 | PrintHead() |
| 94 | PrintFunctions("../bin/APIspec", tests) |
| 95 | PrintTail() |
| 96 | |
| 97 | |