mesa: Simplify logic in get_extension_override()
* Reduce max indentation level from 7 to 3. * Eliminate counter variables. * Remove function append().
This commit is contained in:
@@ -731,78 +731,57 @@ _mesa_extension_is_enabled( struct gl_context *ctx, const char *name )
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append string 'b' onto string 'a'. Free 'a' and return new string.
|
* \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
append(const char *a, const char *b)
|
|
||||||
{
|
|
||||||
const GLuint aLen = a ? strlen(a) : 0;
|
|
||||||
const GLuint bLen = b ? strlen(b) : 0;
|
|
||||||
char *s = calloc(1, aLen + bLen + 1);
|
|
||||||
if (s) {
|
|
||||||
if (a)
|
|
||||||
memcpy(s, a, aLen);
|
|
||||||
if (b)
|
|
||||||
memcpy(s + aLen, b, bLen);
|
|
||||||
s[aLen + bLen] = '\0';
|
|
||||||
}
|
|
||||||
if (a)
|
|
||||||
free((void *) a);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check the MESA_EXTENSION_OVERRIDE env var.
|
|
||||||
* For extension names that are recognized, turn them on. For extension
|
|
||||||
* names that are recognized and prefixed with '-', turn them off.
|
|
||||||
* Return a string of the unknown/leftover names.
|
|
||||||
*
|
*
|
||||||
* Returnd string needs to be freed.
|
* \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
|
||||||
|
* enable or disable. The list is processed thus:
|
||||||
|
* - Disable recognized extension names that are prefixed with '-'.
|
||||||
|
* - Enable recognized extension names that are not prefixed.
|
||||||
|
* - Collect unrecognized extension names in a new string.
|
||||||
|
*
|
||||||
|
* \return Space-separated list of unrecognized extension names (which must
|
||||||
|
* be freed). Does not return \c NULL.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
get_extension_override( struct gl_context *ctx )
|
get_extension_override( struct gl_context *ctx )
|
||||||
{
|
{
|
||||||
const char *envExt = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
|
const char *env_const= _mesa_getenv("MESA_EXTENSION_OVERRIDE");
|
||||||
char *extraExt = NULL;
|
if (env_const == NULL) {
|
||||||
char ext[1000];
|
/* Return the empty string rather than NULL. This simplifies the logic
|
||||||
GLuint extLen = 0;
|
* of client functions. */
|
||||||
GLuint i;
|
return calloc(1, sizeof(char));
|
||||||
GLboolean disableExt = GL_FALSE;
|
}
|
||||||
|
|
||||||
if (!envExt)
|
/* extra_exts: List of unrecognized extensions. */
|
||||||
return NULL;
|
char *extra_exts = calloc(strlen(env_const), sizeof(char));
|
||||||
|
|
||||||
for (i = 0; ; i++) {
|
/* Copy env_const because strtok() is destructive. */
|
||||||
if (envExt[i] == '\0' || envExt[i] == ' ') {
|
char *env = strdup(env_const);
|
||||||
/* terminate/process 'ext' if extLen > 0 */
|
char *ext;
|
||||||
if (extLen > 0) {
|
for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
|
||||||
assert(extLen < sizeof(ext));
|
int enable;
|
||||||
/* enable extension named by 'ext' */
|
switch (ext[0]) {
|
||||||
ext[extLen] = 0;
|
case '-':
|
||||||
if (!set_extension(ctx, ext, !disableExt)) {
|
enable = 0;
|
||||||
/* unknown extension name, append it to extraExt */
|
++ext;
|
||||||
if (extraExt) {
|
break;
|
||||||
extraExt = append(extraExt, " ");
|
default:
|
||||||
}
|
enable = 1;
|
||||||
extraExt = append(extraExt, ext);
|
break;
|
||||||
}
|
|
||||||
extLen = 0;
|
|
||||||
disableExt = GL_FALSE;
|
|
||||||
}
|
|
||||||
if (envExt[i] == '\0')
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else if (envExt[i] == '-') {
|
int recognized = set_extension(ctx, ext, enable);
|
||||||
disableExt = GL_TRUE;
|
if (!recognized) {
|
||||||
}
|
strcat(extra_exts, ext);
|
||||||
else {
|
strcat(extra_exts, " ");
|
||||||
/* accumulate this non-space character */
|
|
||||||
ext[extLen++] = envExt[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return extraExt;
|
/* Remove trailing space. */
|
||||||
|
int len = strlen(extra_exts);
|
||||||
|
if (extra_exts[len - 1] == ' ')
|
||||||
|
extra_exts[len - 1] = '\0';
|
||||||
|
|
||||||
|
return extra_exts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user