From 66dc19979490ac878aa757bf193991f6362e6d70 Mon Sep 17 00:00:00 2001 From: brianp Date: Wed, 2 Jul 2003 15:53:05 +0000 Subject: [PATCH] rewrite of glutExtensionSupported - works correctly now git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@122 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/freeglut_misc.c | 53 +++++++++++---------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/freeglut/freeglut/src/freeglut_misc.c b/freeglut/freeglut/src/freeglut_misc.c index 8c376eb..1bfe733 100644 --- a/freeglut/freeglut/src/freeglut_misc.c +++ b/freeglut/freeglut/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 @@ -60,42 +60,31 @@ int FGAPIENTRY glutExtensionSupported( const char* extension ) freeglut_assert_ready; freeglut_return_val_if_fail( fgStructure.Window != NULL, 0 ); + /* + * Check if the extension itself looks valid (contains no spaces) + */ + if (strchr(extension, ' ')) + return 0; + /* * Note it is safe to query the extensions */ - extensions = glGetString(GL_EXTENSIONS); + start = extensions = (const char *) glGetString(GL_EXTENSIONS); + /* XXX consider printing a warning to stderr that there's no current + * rendering context. + */ freeglut_return_val_if_fail( extensions != NULL, 0 ); - /* - * Check if the extension itself looks valid - */ - if ( strchr ( extension, ' ' ) != NULL ) - return( 0 ); - - /* - * Look for our extension - */ - 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 ; - - 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 ;