Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Brian Paul | ecfdd88 | 2000-05-11 17:45:20 +0000 | [diff] [blame^] | 3 | # $Id: gloffsets.py,v 1.4 2000/05/11 17:45:20 brianp Exp $ |
Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 4 | |
| 5 | # Mesa 3-D graphics library |
| 6 | # Version: 3.3 |
| 7 | # |
| 8 | # Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| 9 | # |
| 10 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 11 | # copy of this software and associated documentation files (the "Software"), |
| 12 | # to deal in the Software without restriction, including without limitation |
| 13 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 | # and/or sell copies of the Software, and to permit persons to whom the |
| 15 | # Software is furnished to do so, subject to the following conditions: |
| 16 | # |
| 17 | # The above copyright notice and this permission notice shall be included |
| 18 | # in all copies or substantial portions of the Software. |
| 19 | # |
| 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 21 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 24 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 26 | |
| 27 | |
| 28 | # Generate the glapioffsets.h file. |
| 29 | # |
| 30 | # Usage: |
| 31 | # gloffsets.py >glapioffsets.h |
| 32 | # |
| 33 | # Dependencies: |
| 34 | # The gl.spec file from the SI must be in the current directory. |
| 35 | # |
| 36 | # Brian Paul 3 February 2000 |
| 37 | |
| 38 | |
| 39 | import string |
| 40 | import re |
| 41 | |
| 42 | |
| 43 | def PrintHead(): |
Brian Paul | ecfdd88 | 2000-05-11 17:45:20 +0000 | [diff] [blame^] | 44 | print '/* DO NOT EDIT - This file generated automatically by gloffsets.py script */' |
Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 45 | print '#ifndef _GLAPI_OFFSETS_H_' |
| 46 | print '#define _GLAPI_OFFSETS_H_' |
| 47 | print '' |
| 48 | return |
| 49 | #endif |
| 50 | |
| 51 | |
| 52 | def PrintTail(): |
| 53 | print '' |
| 54 | print '#endif' |
| 55 | #endif |
| 56 | |
| 57 | |
| 58 | def GenerateDefine(name, offset): |
Brian Paul | a511609 | 2000-02-22 23:59:25 +0000 | [diff] [blame] | 59 | s = '#define _gloffset_' + name + ' ' + str(offset) |
Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 60 | return s; |
| 61 | #enddef |
| 62 | |
| 63 | |
| 64 | def PrintDefines(): |
| 65 | functionPattern = re.compile('^[a-zA-Z0-9]+\(') |
| 66 | functionNamePattern = re.compile('^[a-zA-Z0-9]+') |
| 67 | |
| 68 | funcName = '' |
| 69 | |
Brian Paul | a511609 | 2000-02-22 23:59:25 +0000 | [diff] [blame] | 70 | maxOffset = 0 |
| 71 | offsetInfo = { } |
| 72 | |
Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 73 | f = open('gl.spec') |
| 74 | for line in f.readlines(): |
| 75 | |
| 76 | m = functionPattern.match(line) |
| 77 | if m: |
| 78 | # extract funcName |
| 79 | n = functionNamePattern.findall(line) |
| 80 | funcName = n[0] |
| 81 | |
| 82 | m = string.split(line) |
| 83 | if len(m) > 1: |
| 84 | if m[0] == 'param': |
| 85 | paramName = m[1] |
| 86 | if m[0] == 'offset': |
Brian Paul | ecfdd88 | 2000-05-11 17:45:20 +0000 | [diff] [blame^] | 87 | if m[1] == '?': |
| 88 | #print 'WARNING skipping', funcName |
| 89 | noop = 0 |
Brian Paul | b5d049f | 2000-02-24 18:36:32 +0000 | [diff] [blame] | 90 | else: |
Brian Paul | ecfdd88 | 2000-05-11 17:45:20 +0000 | [diff] [blame^] | 91 | funcOffset = int(m[1]) |
| 92 | if funcOffset > maxOffset: |
| 93 | maxOffset = funcOffset |
| 94 | s = GenerateDefine(funcName, funcOffset) |
| 95 | if offsetInfo.has_key(funcOffset): |
| 96 | print 'ERROR: offset', funcOffset, 'already used!' |
| 97 | raise ERROR |
| 98 | else: |
| 99 | offsetInfo[funcOffset] = s; |
| 100 | #endif |
| 101 | #endif |
| 102 | #endif |
Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 103 | #endif |
| 104 | #endfor |
Brian Paul | a511609 | 2000-02-22 23:59:25 +0000 | [diff] [blame] | 105 | |
| 106 | # Now print the #defines in order of dispatch offset |
| 107 | for i in range(0, maxOffset + 1): |
Brian Paul | b5d049f | 2000-02-24 18:36:32 +0000 | [diff] [blame] | 108 | if offsetInfo.has_key(i): |
| 109 | print offsetInfo[i] |
| 110 | else: |
| 111 | print 'ERROR: missing offset:', i |
| 112 | raise ERROR |
Brian Paul | a511609 | 2000-02-22 23:59:25 +0000 | [diff] [blame] | 113 | |
Brian Paul | feaf04a | 2000-02-22 22:45:20 +0000 | [diff] [blame] | 114 | #enddef |
| 115 | |
| 116 | |
| 117 | |
| 118 | PrintHead() |
| 119 | PrintDefines() |
| 120 | PrintTail() |