3 # (C) Copyright IBM Corporation 2004
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 # Ian Romanick <idr@us.ibm.com>
28 from xml
.sax
import saxutils
29 from xml
.sax
import make_parser
30 from xml
.sax
.handler
import feature_namespaces
36 class PrintGlProcs(gl_XML
.FilterGLAPISpecBase
):
37 name
= "gl_procs.py (from Mesa)"
39 def __init__(self
, long_strings
):
40 self
.long_strings
= long_strings
41 gl_XML
.FilterGLAPISpecBase
.__init
__(self
)
42 self
.license
= license
.bsd_license_template
% ( \
43 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
44 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
47 def printRealHeader(self
):
48 print '/* This file is only included by glapi.c and is used for'
49 print ' * the GetProcAddress() function'
52 print 'typedef struct {'
53 print ' int Name_offset;'
54 print '#ifdef NEED_FUNCTION_POINTER'
55 print ' _glapi_proc Address;'
57 print ' unsigned int Offset;'
58 print '} glprocs_table_t;'
60 print '#ifdef NEED_FUNCTION_POINTER'
61 print '# define NAME_FUNC_OFFSET(n,f,o) { n , (_glapi_proc) f , o }'
63 print '# define NAME_FUNC_OFFSET(n,f,o) { n , o }'
68 def printRealFooter(self
):
70 print '#undef NAME_FUNC_OFFSET'
73 def printFunctionString(self
, f
):
75 print ' "gl%s\\0"' % (f
.name
)
83 def printFunctionOffset(self
, f
, offset_of_name
):
84 print ' NAME_FUNC_OFFSET( % 5u, gl%s, _gloffset_%s ),' % (offset_of_name
, f
.name
, f
.real_name
)
87 def printFunctions(self
):
90 print 'static const char gl_string_table[] ='
92 print 'static const char gl_string_table[] = {'
94 keys
= self
.functions
.keys()
98 self
.printFunctionString(self
.functions
[k
])
103 self
.printFunctionString(self
.functions
[k
])
105 if self
.long_strings
:
111 print 'static const glprocs_table_t static_functions[] = {'
113 keys
= self
.functions
.keys()
118 self
.printFunctionOffset(self
.functions
[k
], base_offset
)
120 # The length of the function's name, plus 2 for "gl",
121 # plus 1 for the NUL.
123 base_offset
+= len(self
.functions
[k
].name
) + 3
128 self
.printFunctionOffset(self
.functions
[k
], base_offset
)
130 # The length of the function's name, plus 2 for "gl",
131 # plus 1 for the NUL.
133 base_offset
+= len(self
.functions
[k
].name
) + 3
135 print ' NAME_FUNC_OFFSET( -1, NULL, -1 )'
141 print "Usage: %s [-f input_file_name] [-m mode]" % sys
.argv
[0]
142 print "mode can be one of:"
143 print " long - Create code for compilers that can handle very "
144 print " long string constants. (default)"
145 print " short - Create code for compilers that can only handle "
146 print " ANSI C89 string constants."
149 if __name__
== '__main__':
150 file_name
= "gl_API.xml"
153 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:m:")
158 for (arg
,val
) in args
:
169 dh
= PrintGlProcs( long_string
)
171 parser
= make_parser()
172 parser
.setFeature(feature_namespaces
, 0)
173 parser
.setContentHandler(dh
)