summaryrefslogtreecommitdiff
path: root/src/mesa/glapi
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2005-02-23 16:36:17 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2005-02-23 16:36:17 +0000
commit8f5f6b3d59fa2ee25654283a235991f332bc8960 (patch)
tree2d8ac7e763655f695e2610897ca56da27d2f9ca6 /src/mesa/glapi
parent6614766f3e8f0ff472d328b3c42677117781d1e4 (diff)
Sort the enums in the Python code, instead of at runtime. (Zack Rusin)
Diffstat (limited to 'src/mesa/glapi')
-rw-r--r--src/mesa/glapi/gl_enums.py92
1 files changed, 36 insertions, 56 deletions
diff --git a/src/mesa/glapi/gl_enums.py b/src/mesa/glapi/gl_enums.py
index 509afec381e..776f814b5b6 100644
--- a/src/mesa/glapi/gl_enums.py
+++ b/src/mesa/glapi/gl_enums.py
@@ -53,11 +53,11 @@ class PrintGlEnums(gl_XML.FilterGLAPISpecBase):
print ' int n;'
print '} enum_elt;'
print ''
- print 'static enum_elt all_enums[] ='
+ print 'static const enum_elt all_enums[] ='
print '{'
return
- def printRealFooter(self):
+ def printBody(self):
print """
};
@@ -65,92 +65,72 @@ class PrintGlEnums(gl_XML.FilterGLAPISpecBase):
typedef int (*cfunc)(const void *, const void *);
-static enum_elt **index1;
-static int sorted;
-
-static int compar_name( const enum_elt *a, const enum_elt *b )
-{
- return _mesa_strcmp(a->c, b->c);
-}
-
-
/* note the extra level of indirection
*/
-static int compar_nr( const enum_elt **a, const enum_elt **b )
+static int compar_name( const enum_elt **a, const enum_elt **b )
{
- return (*a)->n - (*b)->n;
+ return _mesa_strcmp((*a)->c, (*b)->c);
}
-
-static void sort_enums( void )
+static int compar_nr( const enum_elt *a, const enum_elt *b )
{
- GLuint i;
- index1 = (enum_elt **)MALLOC( Elements(all_enums) * sizeof(enum_elt *) );
- sorted = 1;
-
- if (!index1)
- return; /* what else can we do? */
-
- qsort( all_enums, Elements(all_enums), sizeof(*all_enums),
- (cfunc) compar_name );
-
- for (i = 0 ; i < Elements(all_enums) ; i++)
- index1[i] = &all_enums[i];
-
- qsort( index1, Elements(all_enums), sizeof(*index1), (cfunc) compar_nr );
+ return a->n - b->n;
}
+static char token_tmp[20];
-int _mesa_lookup_enum_by_name( const char *symbol )
+const char *_mesa_lookup_enum_by_nr( int nr )
{
- enum_elt tmp;
- enum_elt *e;
+ enum_elt tmp, *e;
- if (!sorted)
- sort_enums();
-
- if (!symbol)
- return 0;
+ tmp.n = nr;
- tmp.c = symbol;
e = (enum_elt *)bsearch( &tmp, all_enums, Elements(all_enums),
- sizeof(*all_enums), (cfunc) compar_name );
+ sizeof(*all_enums), (cfunc) compar_nr );
- return e ? e->n : -1;
+ if (e) {
+ return e->c;
+ }
+ else {
+ /* this isn't re-entrant safe, no big deal here */
+ _mesa_sprintf(token_tmp, "0x%x", nr);
+ return token_tmp;
+ }
}
-
-static char token_tmp[20];
-
-const char *_mesa_lookup_enum_by_nr( int nr )
+int _mesa_lookup_enum_by_name( const char *symbol )
{
enum_elt tmp, *e, **f;
+ static const enum_elt * const index1[] = {"""
- if (!sorted)
- sort_enums();
+ def printRealFooter(self):
+ print """ };
- tmp.n = nr;
+ if (!symbol)
+ return 0;
+
+ tmp.c = symbol;
e = &tmp;
f = (enum_elt **)bsearch( &e, index1, Elements(all_enums),
- sizeof(*index1), (cfunc) compar_nr );
+ sizeof(*index1), (cfunc) compar_name );
- if (f) {
- return (*f)->c;
- }
- else {
- /* this isn't re-entrant safe, no big deal here */
- _mesa_sprintf(token_tmp, "0x%x", nr);
- return token_tmp;
- }
+ return f ? (*f)->n : -1;
}
+
"""
return
def printFunctions(self):
+ self.enums.sort(lambda x,y: x.value - y.value)
for enum in self.enums:
print ' { "%s", 0x%X },' % (enum.name, enum.value)
+ nameEnums = self.enums[:]
+ self.printBody();
+ self.enums.sort(lambda x,y: cmp(x.name, y.name))
+ for enum in self.enums:
+ print ' &all_enums[%d], ' % (nameEnums.index(enum))
return