Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Brian Paul | 9a2121c | 2003-06-10 14:54:37 +0000 | [diff] [blame] | 3 | # $Id: getprocaddress.py,v 1.3 2003/06/10 14:54:37 brianp Exp $ |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 4 | |
| 5 | # Helper for the getprocaddress.c test. |
| 6 | |
| 7 | |
| 8 | import re, string |
| 9 | |
Brian Paul | 0b0245c | 2002-11-08 15:49:31 +0000 | [diff] [blame] | 10 | |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 11 | def PrintHead(): |
| 12 | print """ |
| 13 | struct name_test_pair { |
| 14 | const char *name; |
| 15 | GLboolean (*test)(void *); |
| 16 | }; |
| 17 | |
| 18 | static struct name_test_pair functions[] = {""" |
| 19 | |
| 20 | |
| 21 | def PrintTail(): |
| 22 | print""" |
| 23 | { NULL, NULL } |
| 24 | }; |
| 25 | """ |
| 26 | |
| 27 | |
| 28 | def HaveTest(function): |
| 29 | testFuncs = [ |
| 30 | "glActiveTextureARB", |
| 31 | "glSampleCoverageARB" |
| 32 | ] |
| 33 | if function in testFuncs: |
| 34 | return 1 |
| 35 | else: |
| 36 | return 0 |
| 37 | |
| 38 | |
| 39 | def FindTestFunctions(): |
| 40 | """Scan getprocaddress.c for lines that start with "test_" to find |
| 41 | extension function tests. Return a list of names found.""" |
| 42 | functions = [] |
| 43 | f = open("getprocaddress.c") |
| 44 | if not f: |
| 45 | return functions |
| 46 | for line in f.readlines(): |
| 47 | v = re.search("^test_([a-zA-Z0-9]+)", line) |
| 48 | if v: |
| 49 | func = v.group(1) |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 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 | |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 75 | if funcName in tests: |
| 76 | test = "test_%s" % funcName |
| 77 | else: |
| 78 | test = "NULL" |
| 79 | print ' { "gl%s", %s },' % (funcName, test) |
| 80 | funcName = tokens[1] |
| 81 | |
| 82 | elif tokens[0] == 'category': |
| 83 | category = tokens[1] |
| 84 | |
| 85 | #endif |
| 86 | #endif |
| 87 | #endfor |
| 88 | #enddef |
| 89 | |
| 90 | |
| 91 | tests = FindTestFunctions() |
| 92 | PrintHead() |
Brian Paul | 9a2121c | 2003-06-10 14:54:37 +0000 | [diff] [blame] | 93 | PrintFunctions("../../src/mesa/glapi/APIspec", tests) |
Brian Paul | d1efbf0 | 2002-11-08 15:35:46 +0000 | [diff] [blame] | 94 | PrintTail() |
| 95 | |
| 96 | |