Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

getprocaddress.py 1.9KB

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