From: Brian Paul Date: Wed, 2 Jul 2003 15:53:05 +0000 (+0000) Subject: rewrite of glutExtensionSupported - works correctly now X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=cd48fd8ffee1375326f0ccf5426dae28b14a8ee8;p=freeglut rewrite of glutExtensionSupported - works correctly now git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@122 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/src/freeglut_misc.c b/src/freeglut_misc.c index 8c376eb..1bfe733 100644 --- a/src/freeglut_misc.c +++ b/src/freeglut_misc.c @@ -50,9 +50,9 @@ */ int FGAPIENTRY glutExtensionSupported( const char* extension ) { - const char *extensions; + const char *extensions, *start; const char *ptr; - int len = strlen ( extension ) ; + const int len = strlen( extension ) ; /* * Make sure there is a current window, and thus -- a current context available @@ -61,41 +61,30 @@ int FGAPIENTRY glutExtensionSupported( const char* extension ) freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 ); /* - * Note it is safe to query the extensions + * Check if the extension itself looks valid (contains no spaces) */ - extensions = glGetString(GL_EXTENSIONS); - - freeglut_return_val_if_fail( extensions != NULL, 0 ); + if (strchr(extension, ' ')) + return 0; /* - * Check if the extension itself looks valid + * Note it is safe to query the extensions */ - if ( strchr ( extension, ' ' ) != NULL ) - return( 0 ); + start = extensions = (const char *) glGetString(GL_EXTENSIONS); - /* - * Look for our extension + /* XXX consider printing a warning to stderr that there's no current + * rendering context. */ - for (ptr = extensions; *ptr;) - { - /* - * Is it the current extension? - */ - if ( strncmp ( extension, extensions, len ) == 0 ) - return 1 ; - - /* - * No, go find the next extension. They are separated from each other by one or more blank spaces. - */ - ptr = strchr ( ptr, ' ' ) ; - - /* - * If we ran off the end of the "extensions" character string, we didn't find it. Return failure. - */ - if ( !ptr ) return 0 ; + freeglut_return_val_if_fail( extensions != NULL, 0 ); - while ( *ptr == ' ' ) - ptr++ ; + while (1) { + const char *p = strstr(extensions, extension); + if (!p) + return 0; /* not found */ + /* check that the match isn't a super string */ + if ((p == start || p[-1] == ' ') && (p[len] == ' ' || p[len] == 0)) + return 1; + /* skip the false match and continue */ + extensions = p + len; } return 0 ;