diff options
-rw-r--r-- | src/mesa/drivers/dri/common/xmlconfig.c | 724 |
1 files changed, 362 insertions, 362 deletions
diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c index 4c1b34543c1..d4649370ee2 100644 --- a/src/mesa/drivers/dri/common/xmlconfig.c +++ b/src/mesa/drivers/dri/common/xmlconfig.c @@ -77,15 +77,15 @@ __getProgramName() static const char *progname; if (progname == NULL) { - const char *e = getexecname(); - if (e != NULL) { - /* Have to make a copy since getexecname can return a readonly - string, but basename expects to be able to modify its arg. */ - char *n = strdup(e); - if (n != NULL) { - progname = basename(n); - } - } + const char *e = getexecname(); + if (e != NULL) { + /* Have to make a copy since getexecname can return a readonly + string, but basename expects to be able to modify its arg. */ + char *n = strdup(e); + if (n != NULL) { + progname = basename(n); + } + } } return progname; } @@ -126,17 +126,17 @@ findOption(const driOptionCache *cache, const char *name) /* compute a hash from the variable length name */ for (i = 0, shift = 0; i < len; ++i, shift = (shift+8) & 31) - hash += (uint32_t)name[i] << shift; + hash += (uint32_t)name[i] << shift; hash *= hash; hash = (hash >> (16-cache->tableSize/2)) & mask; /* this is just the starting point of the linear search for the option */ for (i = 0; i < size; ++i, hash = (hash+1) & mask) { /* if we hit an empty entry then the option is not defined (yet) */ - if (cache->info[hash].name == 0) - break; - else if (!strcmp (name, cache->info[hash].name)) - break; + if (cache->info[hash].name == 0) + break; + else if (!strcmp (name, cache->info[hash].name)) + break; } /* this assertion fails if the hash table is full */ assert (i < size); @@ -148,8 +148,8 @@ findOption(const driOptionCache *cache, const char *name) #define XSTRDUP(dest,source) do { \ uint32_t len = strlen (source); \ if (!(dest = malloc(len+1))) { \ - fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); \ - abort(); \ + fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); \ + abort(); \ } \ memcpy (dest, source, len+1); \ } while (0) @@ -164,9 +164,9 @@ bsearchStr (const XML_Char *name, const XML_Char *elems[], uint32_t count) const XML_Char **found; found = bsearch (&name, elems, count, sizeof (XML_Char *), compare); if (found) - return found - elems; + return found - elems; else - return count; + return count; } /** \brief Locale-independent integer parser. @@ -190,39 +190,39 @@ strToI(const XML_Char *string, const XML_Char **tail, int base) assert (radix >= 2 && radix <= 36); if (*string == '-') { - sign = -1; - string++; + sign = -1; + string++; } else if (*string == '+') - string++; + string++; if (base == 0 && *string == '0') { - numberFound = true; - if (*(string+1) == 'x' || *(string+1) == 'X') { - radix = 16; - string += 2; - } else { - radix = 8; - string++; - } + numberFound = true; + if (*(string+1) == 'x' || *(string+1) == 'X') { + radix = 16; + string += 2; + } else { + radix = 8; + string++; + } } do { - int digit = -1; - if (radix <= 10) { - if (*string >= '0' && *string < '0' + radix) - digit = *string - '0'; - } else { - if (*string >= '0' && *string <= '9') - digit = *string - '0'; - else if (*string >= 'a' && *string < 'a' + radix - 10) - digit = *string - 'a' + 10; - else if (*string >= 'A' && *string < 'A' + radix - 10) - digit = *string - 'A' + 10; - } - if (digit != -1) { - numberFound = true; - result = radix*result + digit; - string++; - } else - break; + int digit = -1; + if (radix <= 10) { + if (*string >= '0' && *string < '0' + radix) + digit = *string - '0'; + } else { + if (*string >= '0' && *string <= '9') + digit = *string - '0'; + else if (*string >= 'a' && *string < 'a' + radix - 10) + digit = *string - 'a' + 10; + else if (*string >= 'A' && *string < 'A' + radix - 10) + digit = *string - 'A' + 10; + } + if (digit != -1) { + numberFound = true; + result = radix*result + digit; + string++; + } else + break; } while (true); *tail = numberFound ? string : start; return sign * result; @@ -249,41 +249,41 @@ strToF(const XML_Char *string, const XML_Char **tail) /* sign */ if (*string == '-') { - sign = -1.0f; - string++; + sign = -1.0f; + string++; } else if (*string == '+') - string++; + string++; /* first pass: determine position of decimal point, number of * digits, exponent and the end of the number. */ numStart = string; while (*string >= '0' && *string <= '9') { - string++; - nDigits++; + string++; + nDigits++; } pointPos = nDigits; if (*string == '.') { - string++; - while (*string >= '0' && *string <= '9') { - string++; - nDigits++; - } + string++; + while (*string >= '0' && *string <= '9') { + string++; + nDigits++; + } } if (nDigits == 0) { - /* no digits, no number */ - *tail = start; - return 0.0f; + /* no digits, no number */ + *tail = start; + return 0.0f; } *tail = string; if (*string == 'e' || *string == 'E') { - const XML_Char *expTail; - exponent = strToI (string+1, &expTail, 10); - if (expTail == string+1) - exponent = 0; - else - *tail = expTail; + const XML_Char *expTail; + exponent = strToI (string+1, &expTail, 10); + if (expTail == string+1) + exponent = 0; + else + *tail = expTail; } else - exponent = 0; + exponent = 0; string = numStart; /* scale of the first digit */ @@ -291,13 +291,13 @@ strToF(const XML_Char *string, const XML_Char **tail) /* second pass: parse digits */ do { - if (*string != '.') { - assert (*string >= '0' && *string <= '9'); - result += scale * (float)(*string - '0'); - scale *= 0.1f; - nDigits--; - } - string++; + if (*string != '.') { + assert (*string >= '0' && *string <= '9'); + result += scale * (float)(*string - '0'); + scale *= 0.1f; + nDigits--; + } + string++; } while (nDigits > 0); return result; @@ -312,36 +312,36 @@ parseValue(driOptionValue *v, driOptionType type, const XML_Char *string) string += strspn (string, " \f\n\r\t\v"); switch (type) { case DRI_BOOL: - if (!strcmp (string, "false")) { - v->_bool = false; - tail = string + 5; - } else if (!strcmp (string, "true")) { - v->_bool = true; - tail = string + 4; - } - else - return false; - break; + if (!strcmp (string, "false")) { + v->_bool = false; + tail = string + 5; + } else if (!strcmp (string, "true")) { + v->_bool = true; + tail = string + 4; + } + else + return false; + break; case DRI_ENUM: /* enum is just a special integer */ case DRI_INT: - v->_int = strToI (string, &tail, 0); - break; + v->_int = strToI (string, &tail, 0); + break; case DRI_FLOAT: - v->_float = strToF (string, &tail); - break; + v->_float = strToF (string, &tail); + break; case DRI_STRING: - free (v->_string); - v->_string = strndup(string, STRING_CONF_MAXLEN); - return GL_TRUE; + free (v->_string); + v->_string = strndup(string, STRING_CONF_MAXLEN); + return GL_TRUE; } if (tail == string) - return false; /* empty string (or containing only white-space) */ + return false; /* empty string (or containing only white-space) */ /* skip trailing white space */ if (*tail) - tail += strspn (tail, " \f\n\r\t\v"); + tail += strspn (tail, " \f\n\r\t\v"); if (*tail) - return false; /* something left over that is not part of value */ + return false; /* something left over that is not part of value */ return true; } @@ -358,50 +358,50 @@ parseRanges(driOptionInfo *info, const XML_Char *string) /* pass 1: determine the number of ranges (number of commas + 1) */ range = cp; for (nRanges = 1; *range; ++range) - if (*range == ',') - ++nRanges; + if (*range == ',') + ++nRanges; if ((ranges = malloc(nRanges*sizeof(driOptionRange))) == NULL) { - fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); - abort(); + fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); + abort(); } /* pass 2: parse all ranges into preallocated array */ range = cp; for (i = 0; i < nRanges; ++i) { - XML_Char *end, *sep; - assert (range); - end = strchr (range, ','); - if (end) - *end = '\0'; - sep = strchr (range, ':'); - if (sep) { /* non-empty interval */ - *sep = '\0'; - if (!parseValue (&ranges[i].start, info->type, range) || - !parseValue (&ranges[i].end, info->type, sep+1)) - break; - if (info->type == DRI_INT && - ranges[i].start._int > ranges[i].end._int) - break; - if (info->type == DRI_FLOAT && - ranges[i].start._float > ranges[i].end._float) - break; - } else { /* empty interval */ - if (!parseValue (&ranges[i].start, info->type, range)) - break; - ranges[i].end = ranges[i].start; - } - if (end) - range = end+1; - else - range = NULL; + XML_Char *end, *sep; + assert (range); + end = strchr (range, ','); + if (end) + *end = '\0'; + sep = strchr (range, ':'); + if (sep) { /* non-empty interval */ + *sep = '\0'; + if (!parseValue (&ranges[i].start, info->type, range) || + !parseValue (&ranges[i].end, info->type, sep+1)) + break; + if (info->type == DRI_INT && + ranges[i].start._int > ranges[i].end._int) + break; + if (info->type == DRI_FLOAT && + ranges[i].start._float > ranges[i].end._float) + break; + } else { /* empty interval */ + if (!parseValue (&ranges[i].start, info->type, range)) + break; + ranges[i].end = ranges[i].start; + } + if (end) + range = end+1; + else + range = NULL; } free(cp); if (i < nRanges) { - free(ranges); - return false; + free(ranges); + return false; } else - assert (range == NULL); + assert (range == NULL); info->nRanges = nRanges; info->ranges = ranges; @@ -415,25 +415,25 @@ checkValue(const driOptionValue *v, const driOptionInfo *info) uint32_t i; assert (info->type != DRI_BOOL); /* should be caught by the parser */ if (info->nRanges == 0) - return true; + return true; switch (info->type) { case DRI_ENUM: /* enum is just a special integer */ case DRI_INT: - for (i = 0; i < info->nRanges; ++i) - if (v->_int >= info->ranges[i].start._int && - v->_int <= info->ranges[i].end._int) - return true; - break; + for (i = 0; i < info->nRanges; ++i) + if (v->_int >= info->ranges[i].start._int && + v->_int <= info->ranges[i].end._int) + return true; + break; case DRI_FLOAT: - for (i = 0; i < info->nRanges; ++i) - if (v->_float >= info->ranges[i].start._float && - v->_float <= info->ranges[i].end._float) - return true; - break; + for (i = 0; i < info->nRanges; ++i) + if (v->_float >= info->ranges[i].start._float && + v->_float <= info->ranges[i].end._float) + return true; + break; case DRI_STRING: - break; + break; default: - assert (0); /* should never happen */ + assert (0); /* should never happen */ } return false; } @@ -490,15 +490,15 @@ __driUtilMessage(const char *f, ...) #define XML_FATAL1(msg) do { \ fprintf (stderr, "Fatal error in %s line %d, column %d: "msg"\n", \ data->name, \ - (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentLineNumber(data->parser), \ (int) XML_GetCurrentColumnNumber(data->parser)); \ abort();\ } while (0) #define XML_FATAL(msg,args...) do { \ fprintf (stderr, "Fatal error in %s line %d, column %d: "msg"\n", \ data->name, \ - (int) XML_GetCurrentLineNumber(data->parser), \ - (int) XML_GetCurrentColumnNumber(data->parser), \ + (int) XML_GetCurrentLineNumber(data->parser), \ + (int) XML_GetCurrentColumnNumber(data->parser), \ args); \ abort();\ } while (0) @@ -537,16 +537,16 @@ parseEnumAttr(struct OptInfoData *data, const XML_Char **attr) driOptionValue v; uint32_t opt = data->curOption; for (i = 0; attr[i]; i += 2) { - if (!strcmp (attr[i], "value")) value = attr[i+1]; - else if (!strcmp (attr[i], "text")) text = attr[i+1]; - else XML_FATAL("illegal enum attribute: %s.", attr[i]); + if (!strcmp (attr[i], "value")) value = attr[i+1]; + else if (!strcmp (attr[i], "text")) text = attr[i+1]; + else XML_FATAL("illegal enum attribute: %s.", attr[i]); } if (!value) XML_FATAL1 ("value attribute missing in enum."); if (!text) XML_FATAL1 ("text attribute missing in enum."); if (!parseValue (&v, data->cache->info[opt].type, value)) - XML_FATAL ("illegal enum value: %s.", value); + XML_FATAL ("illegal enum value: %s.", value); if (!checkValue (&v, &data->cache->info[opt])) - XML_FATAL ("enum value out of valid range: %s.", value); + XML_FATAL ("enum value out of valid range: %s.", value); } /** \brief Parse attributes of a description element. @@ -560,9 +560,9 @@ parseDescAttr(struct OptInfoData *data, const XML_Char **attr) uint32_t i; const XML_Char *lang = NULL, *text = NULL; for (i = 0; attr[i]; i += 2) { - if (!strcmp (attr[i], "lang")) lang = attr[i+1]; - else if (!strcmp (attr[i], "text")) text = attr[i+1]; - else XML_FATAL("illegal description attribute: %s.", attr[i]); + if (!strcmp (attr[i], "lang")) lang = attr[i+1]; + else if (!strcmp (attr[i], "text")) text = attr[i+1]; + else XML_FATAL("illegal description attribute: %s.", attr[i]); } if (!lang) XML_FATAL1 ("lang attribute missing in description."); if (!text) XML_FATAL1 ("text attribute missing in description."); @@ -579,10 +579,10 @@ parseOptInfoAttr(struct OptInfoData *data, const XML_Char **attr) driOptionCache *cache = data->cache; uint32_t opt, i; for (i = 0; attr[i]; i += 2) { - uint32_t attrName = bsearchStr (attr[i], optAttr, OA_COUNT); - if (attrName >= OA_COUNT) - XML_FATAL ("illegal option attribute: %s", attr[i]); - attrVal[attrName] = attr[i+1]; + uint32_t attrName = bsearchStr (attr[i], optAttr, OA_COUNT); + if (attrName >= OA_COUNT) + XML_FATAL ("illegal option attribute: %s", attr[i]); + attrVal[attrName] = attr[i+1]; } if (!attrVal[OA_NAME]) XML_FATAL1 ("name attribute missing in option."); if (!attrVal[OA_TYPE]) XML_FATAL1 ("type attribute missing in option."); @@ -590,48 +590,48 @@ parseOptInfoAttr(struct OptInfoData *data, const XML_Char **attr) opt = findOption (cache, attrVal[OA_NAME]); if (cache->info[opt].name) - XML_FATAL ("option %s redefined.", attrVal[OA_NAME]); + XML_FATAL ("option %s redefined.", attrVal[OA_NAME]); data->curOption = opt; XSTRDUP (cache->info[opt].name, attrVal[OA_NAME]); if (!strcmp (attrVal[OA_TYPE], "bool")) - cache->info[opt].type = DRI_BOOL; + cache->info[opt].type = DRI_BOOL; else if (!strcmp (attrVal[OA_TYPE], "enum")) - cache->info[opt].type = DRI_ENUM; + cache->info[opt].type = DRI_ENUM; else if (!strcmp (attrVal[OA_TYPE], "int")) - cache->info[opt].type = DRI_INT; + cache->info[opt].type = DRI_INT; else if (!strcmp (attrVal[OA_TYPE], "float")) - cache->info[opt].type = DRI_FLOAT; + cache->info[opt].type = DRI_FLOAT; else if (!strcmp (attrVal[OA_TYPE], "string")) - cache->info[opt].type = DRI_STRING; + cache->info[opt].type = DRI_STRING; else - XML_FATAL ("illegal type in option: %s.", attrVal[OA_TYPE]); + XML_FATAL ("illegal type in option: %s.", attrVal[OA_TYPE]); defaultVal = getenv (cache->info[opt].name); if (defaultVal != NULL) { /* don't use XML_WARNING, we want the user to see this! */ - fprintf (stderr, - "ATTENTION: default value of option %s overridden by environment.\n", - cache->info[opt].name); + fprintf (stderr, + "ATTENTION: default value of option %s overridden by environment.\n", + cache->info[opt].name); } else - defaultVal = attrVal[OA_DEFAULT]; + defaultVal = attrVal[OA_DEFAULT]; if (!parseValue (&cache->values[opt], cache->info[opt].type, defaultVal)) - XML_FATAL ("illegal default value for %s: %s.", cache->info[opt].name, defaultVal); + XML_FATAL ("illegal default value for %s: %s.", cache->info[opt].name, defaultVal); if (attrVal[OA_VALID]) { - if (cache->info[opt].type == DRI_BOOL) - XML_FATAL1 ("boolean option with valid attribute."); - if (!parseRanges (&cache->info[opt], attrVal[OA_VALID])) - XML_FATAL ("illegal valid attribute: %s.", attrVal[OA_VALID]); - if (!checkValue (&cache->values[opt], &cache->info[opt])) - XML_FATAL ("default value out of valid range '%s': %s.", - attrVal[OA_VALID], defaultVal); + if (cache->info[opt].type == DRI_BOOL) + XML_FATAL1 ("boolean option with valid attribute."); + if (!parseRanges (&cache->info[opt], attrVal[OA_VALID])) + XML_FATAL ("illegal valid attribute: %s.", attrVal[OA_VALID]); + if (!checkValue (&cache->values[opt], &cache->info[opt])) + XML_FATAL ("default value out of valid range '%s': %s.", + attrVal[OA_VALID], defaultVal); } else if (cache->info[opt].type == DRI_ENUM) { - XML_FATAL1 ("valid attribute missing in option (mandatory for enums)."); + XML_FATAL1 ("valid attribute missing in option (mandatory for enums)."); } else { - cache->info[opt].nRanges = 0; - cache->info[opt].ranges = NULL; + cache->info[opt].nRanges = 0; + cache->info[opt].ranges = NULL; } } @@ -643,49 +643,49 @@ optInfoStartElem(void *userData, const XML_Char *name, const XML_Char **attr) enum OptInfoElem elem = bsearchStr (name, OptInfoElems, OI_COUNT); switch (elem) { case OI_DRIINFO: - if (data->inDriInfo) - XML_FATAL1 ("nested <driinfo> elements."); - if (attr[0]) - XML_FATAL1 ("attributes specified on <driinfo> element."); - data->inDriInfo = true; - break; + if (data->inDriInfo) + XML_FATAL1 ("nested <driinfo> elements."); + if (attr[0]) + XML_FATAL1 ("attributes specified on <driinfo> element."); + data->inDriInfo = true; + break; case OI_SECTION: - if (!data->inDriInfo) - XML_FATAL1 ("<section> must be inside <driinfo>."); - if (data->inSection) - XML_FATAL1 ("nested <section> elements."); - if (attr[0]) - XML_FATAL1 ("attributes specified on <section> element."); - data->inSection = true; - break; + if (!data->inDriInfo) + XML_FATAL1 ("<section> must be inside <driinfo>."); + if (data->inSection) + XML_FATAL1 ("nested <section> elements."); + if (attr[0]) + XML_FATAL1 ("attributes specified on <section> element."); + data->inSection = true; + break; case OI_DESCRIPTION: - if (!data->inSection && !data->inOption) - XML_FATAL1 ("<description> must be inside <description> or <option."); - if (data->inDesc) - XML_FATAL1 ("nested <description> elements."); - data->inDesc = true; - parseDescAttr (data, attr); - break; + if (!data->inSection && !data->inOption) + XML_FATAL1 ("<description> must be inside <description> or <option."); + if (data->inDesc) + XML_FATAL1 ("nested <description> elements."); + data->inDesc = true; + parseDescAttr (data, attr); + break; case OI_OPTION: - if (!data->inSection) - XML_FATAL1 ("<option> must be inside <section>."); - if (data->inDesc) - XML_FATAL1 ("<option> nested in <description> element."); - if (data->inOption) - XML_FATAL1 ("nested <option> elements."); - data->inOption = true; - parseOptInfoAttr (data, attr); - break; + if (!data->inSection) + XML_FATAL1 ("<option> must be inside <section>."); + if (data->inDesc) + XML_FATAL1 ("<option> nested in <description> element."); + if (data->inOption) + XML_FATAL1 ("nested <option> elements."); + data->inOption = true; + parseOptInfoAttr (data, attr); + break; case OI_ENUM: - if (!(data->inOption && data->inDesc)) - XML_FATAL1 ("<enum> must be inside <option> and <description>."); - if (data->inEnum) - XML_FATAL1 ("nested <enum> elements."); - data->inEnum = true; - parseEnumAttr (data, attr); - break; + if (!(data->inOption && data->inDesc)) + XML_FATAL1 ("<enum> must be inside <option> and <description>."); + if (data->inEnum) + XML_FATAL1 ("nested <enum> elements."); + data->inEnum = true; + parseEnumAttr (data, attr); + break; default: - XML_FATAL ("unknown element: %s.", name); + XML_FATAL ("unknown element: %s.", name); } } @@ -697,22 +697,22 @@ optInfoEndElem(void *userData, const XML_Char *name) enum OptInfoElem elem = bsearchStr (name, OptInfoElems, OI_COUNT); switch (elem) { case OI_DRIINFO: - data->inDriInfo = false; - break; + data->inDriInfo = false; + break; case OI_SECTION: - data->inSection = false; - break; + data->inSection = false; + break; case OI_DESCRIPTION: - data->inDesc = false; - break; + data->inDesc = false; + break; case OI_OPTION: - data->inOption = false; - break; + data->inOption = false; + break; case OI_ENUM: - data->inEnum = false; - break; + data->inEnum = false; + break; default: - assert (0); /* should have been caught by StartElem */ + assert (0); /* should have been caught by StartElem */ } } @@ -731,8 +731,8 @@ driParseOptionInfo(driOptionCache *info, const char *configOptions) info->info = calloc(1 << info->tableSize, sizeof (driOptionInfo)); info->values = calloc(1 << info->tableSize, sizeof (driOptionValue)); if (info->info == NULL || info->values == NULL) { - fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); - abort(); + fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); + abort(); } p = XML_ParserCreate ("UTF-8"); /* always UTF-8 */ @@ -751,7 +751,7 @@ driParseOptionInfo(driOptionCache *info, const char *configOptions) status = XML_Parse (p, configOptions, strlen (configOptions), 1); if (!status) - XML_FATAL ("%s.", XML_ErrorString(XML_GetErrorCode(p))); + XML_FATAL ("%s.", XML_ErrorString(XML_GetErrorCode(p))); XML_ParserFree (p); } @@ -786,18 +786,18 @@ parseDeviceAttr(struct OptConfData *data, const XML_Char **attr) uint32_t i; const XML_Char *driver = NULL, *screen = NULL; for (i = 0; attr[i]; i += 2) { - if (!strcmp (attr[i], "driver")) driver = attr[i+1]; - else if (!strcmp (attr[i], "screen")) screen = attr[i+1]; - else XML_WARNING("unknown device attribute: %s.", attr[i]); + if (!strcmp (attr[i], "driver")) driver = attr[i+1]; + else if (!strcmp (attr[i], "screen")) screen = attr[i+1]; + else XML_WARNING("unknown device attribute: %s.", attr[i]); } if (driver && strcmp (driver, data->driverName)) - data->ignoringDevice = data->inDevice; + data->ignoringDevice = data->inDevice; else if (screen) { - driOptionValue screenNum; - if (!parseValue (&screenNum, DRI_INT, screen)) - XML_WARNING("illegal screen number: %s.", screen); - else if (screenNum._int != data->screenNum) - data->ignoringDevice = data->inDevice; + driOptionValue screenNum; + if (!parseValue (&screenNum, DRI_INT, screen)) + XML_WARNING("illegal screen number: %s.", screen); + else if (screenNum._int != data->screenNum) + data->ignoringDevice = data->inDevice; } } @@ -808,12 +808,12 @@ parseAppAttr(struct OptConfData *data, const XML_Char **attr) uint32_t i; const XML_Char *exec = NULL; for (i = 0; attr[i]; i += 2) { - if (!strcmp (attr[i], "name")) /* not needed here */; - else if (!strcmp (attr[i], "executable")) exec = attr[i+1]; - else XML_WARNING("unknown application attribute: %s.", attr[i]); + if (!strcmp (attr[i], "name")) /* not needed here */; + else if (!strcmp (attr[i], "executable")) exec = attr[i+1]; + else XML_WARNING("unknown application attribute: %s.", attr[i]); } if (exec && strcmp (exec, data->execName)) - data->ignoringApp = data->inApp; + data->ignoringApp = data->inApp; } /** \brief Parse attributes of an option element. */ @@ -823,25 +823,25 @@ parseOptConfAttr(struct OptConfData *data, const XML_Char **attr) uint32_t i; const XML_Char *name = NULL, *value = NULL; for (i = 0; attr[i]; i += 2) { - if (!strcmp (attr[i], "name")) name = attr[i+1]; - else if (!strcmp (attr[i], "value")) value = attr[i+1]; - else XML_WARNING("unknown option attribute: %s.", attr[i]); + if (!strcmp (attr[i], "name")) name = attr[i+1]; + else if (!strcmp (attr[i], "value")) value = attr[i+1]; + else XML_WARNING("unknown option attribute: %s.", attr[i]); } if (!name) XML_WARNING1 ("name attribute missing in option."); if (!value) XML_WARNING1 ("value attribute missing in option."); if (name && value) { - driOptionCache *cache = data->cache; - uint32_t opt = findOption (cache, name); - if (cache->info[opt].name == NULL) + driOptionCache *cache = data->cache; + uint32_t opt = findOption (cache, name); + if (cache->info[opt].name == NULL) /* don't use XML_WARNING, drirc defines options for all drivers, * but not all drivers support them */ return; - else if (getenv (cache->info[opt].name)) - /* don't use XML_WARNING, we want the user to see this! */ - fprintf (stderr, "ATTENTION: option value of option %s ignored.\n", - cache->info[opt].name); - else if (!parseValue (&cache->values[opt], cache->info[opt].type, value)) - XML_WARNING ("illegal option value: %s.", value); + else if (getenv (cache->info[opt].name)) + /* don't use XML_WARNING, we want the user to see this! */ + fprintf (stderr, "ATTENTION: option value of option %s ignored.\n", + cache->info[opt].name); + else if (!parseValue (&cache->values[opt], cache->info[opt].type, value)) + XML_WARNING ("illegal option value: %s.", value); } } @@ -854,41 +854,41 @@ optConfStartElem(void *userData, const XML_Char *name, enum OptConfElem elem = bsearchStr (name, OptConfElems, OC_COUNT); switch (elem) { case OC_DRICONF: - if (data->inDriConf) - XML_WARNING1 ("nested <driconf> elements."); - if (attr[0]) - XML_WARNING1 ("attributes specified on <driconf> element."); - data->inDriConf++; - break; + if (data->inDriConf) + XML_WARNING1 ("nested <driconf> elements."); + if (attr[0]) + XML_WARNING1 ("attributes specified on <driconf> element."); + data->inDriConf++; + break; case OC_DEVICE: - if (!data->inDriConf) - XML_WARNING1 ("<device> should be inside <driconf>."); - if (data->inDevice) - XML_WARNING1 ("nested <device> elements."); - data->inDevice++; - if (!data->ignoringDevice && !data->ignoringApp) - parseDeviceAttr (data, attr); - break; + if (!data->inDriConf) + XML_WARNING1 ("<device> should be inside <driconf>."); + if (data->inDevice) + XML_WARNING1 ("nested <device> elements."); + data->inDevice++; + if (!data->ignoringDevice && !data->ignoringApp) + parseDeviceAttr (data, attr); + break; case OC_APPLICATION: - if (!data->inDevice) - XML_WARNING1 ("<application> should be inside <device>."); - if (data->inApp) - XML_WARNING1 ("nested <application> elements."); - data->inApp++; - if (!data->ignoringDevice && !data->ignoringApp) - parseAppAttr (data, attr); - break; + if (!data->inDevice) + XML_WARNING1 ("<application> should be inside <device>."); + if (data->inApp) + XML_WARNING1 ("nested <application> elements."); + data->inApp++; + if (!data->ignoringDevice && !data->ignoringApp) + parseAppAttr (data, attr); + break; case OC_OPTION: - if (!data->inApp) - XML_WARNING1 ("<option> should be inside <application>."); - if (data->inOption) - XML_WARNING1 ("nested <option> elements."); - data->inOption++; - if (!data->ignoringDevice && !data->ignoringApp) - parseOptConfAttr (data, attr); - break; + if (!data->inApp) + XML_WARNING1 ("<option> should be inside <application>."); + if (data->inOption) + XML_WARNING1 ("nested <option> elements."); + data->inOption++; + if (!data->ignoringDevice && !data->ignoringApp) + parseOptConfAttr (data, attr); + break; default: - XML_WARNING ("unknown element: %s.", name); + XML_WARNING ("unknown element: %s.", name); } } @@ -900,21 +900,21 @@ optConfEndElem(void *userData, const XML_Char *name) enum OptConfElem elem = bsearchStr (name, OptConfElems, OC_COUNT); switch (elem) { case OC_DRICONF: - data->inDriConf--; - break; + data->inDriConf--; + break; case OC_DEVICE: - if (data->inDevice-- == data->ignoringDevice) - data->ignoringDevice = 0; - break; + if (data->inDevice-- == data->ignoringDevice) + data->ignoringDevice = 0; + break; case OC_APPLICATION: - if (data->inApp-- == data->ignoringApp) - data->ignoringApp = 0; - break; + if (data->inApp-- == data->ignoringApp) + data->ignoringApp = 0; + break; case OC_OPTION: - data->inOption--; - break; + data->inOption--; + break; default: - /* unknown element, warning was produced on start tag */; + /* unknown element, warning was produced on start tag */; } } @@ -927,14 +927,14 @@ initOptionCache(driOptionCache *cache, const driOptionCache *info) cache->tableSize = info->tableSize; cache->values = malloc((1<<info->tableSize) * sizeof (driOptionValue)); if (cache->values == NULL) { - fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); - abort(); + fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); + abort(); } memcpy (cache->values, info->values, - (1<<info->tableSize) * sizeof (driOptionValue)); + (1<<info->tableSize) * sizeof (driOptionValue)); for (i = 0; i < size; ++i) { - if (cache->info[i].type == DRI_STRING) - XSTRDUP(cache->values[i]._string, info->values[i]._string); + if (cache->info[i].type == DRI_STRING) + XSTRDUP(cache->values[i]._string, info->values[i]._string); } } @@ -948,31 +948,31 @@ parseOneConfigFile(XML_Parser p) int fd; if ((fd = open (data->name, O_RDONLY)) == -1) { - __driUtilMessage ("Can't open configuration file %s: %s.", - data->name, strerror (errno)); - return; + __driUtilMessage ("Can't open configuration file %s: %s.", + data->name, strerror (errno)); + return; } while (1) { - int bytesRead; - void *buffer = XML_GetBuffer (p, BUF_SIZE); - if (!buffer) { - __driUtilMessage ("Can't allocate parser buffer."); - break; - } - bytesRead = read (fd, buffer, BUF_SIZE); - if (bytesRead == -1) { - __driUtilMessage ("Error reading from configuration file %s: %s.", - data->name, strerror (errno)); - break; - } - status = XML_ParseBuffer (p, bytesRead, bytesRead == 0); - if (!status) { - XML_ERROR ("%s.", XML_ErrorString(XML_GetErrorCode(p))); - break; - } - if (bytesRead == 0) - break; + int bytesRead; + void *buffer = XML_GetBuffer (p, BUF_SIZE); + if (!buffer) { + __driUtilMessage ("Can't allocate parser buffer."); + break; + } + bytesRead = read (fd, buffer, BUF_SIZE); + if (bytesRead == -1) { + __driUtilMessage ("Error reading from configuration file %s: %s.", + data->name, strerror (errno)); + break; + } + status = XML_ParseBuffer (p, bytesRead, bytesRead == 0); + if (!status) { + XML_ERROR ("%s.", XML_ErrorString(XML_GetErrorCode(p))); + break; + } + if (bytesRead == 0) + break; } close (fd); @@ -1000,35 +1000,35 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, userData.execName = GET_PROGRAM_NAME(); if ((home = getenv ("HOME"))) { - uint32_t len = strlen (home); - filenames[1] = malloc(len + 7+1); - if (filenames[1] == NULL) - __driUtilMessage ("Can't allocate memory for %s/.drirc.", home); - else { - memcpy (filenames[1], home, len); - memcpy (filenames[1] + len, "/.drirc", 7+1); - } + uint32_t len = strlen (home); + filenames[1] = malloc(len + 7+1); + if (filenames[1] == NULL) + __driUtilMessage ("Can't allocate memory for %s/.drirc.", home); + else { + memcpy (filenames[1], home, len); + memcpy (filenames[1] + len, "/.drirc", 7+1); + } } for (i = 0; i < 2; ++i) { - XML_Parser p; - if (filenames[i] == NULL) - continue; - - p = XML_ParserCreate (NULL); /* use encoding specified by file */ - XML_SetElementHandler (p, optConfStartElem, optConfEndElem); - XML_SetUserData (p, &userData); - userData.parser = p; - userData.name = filenames[i]; - userData.ignoringDevice = 0; - userData.ignoringApp = 0; - userData.inDriConf = 0; - userData.inDevice = 0; - userData.inApp = 0; - userData.inOption = 0; - - parseOneConfigFile (p); - XML_ParserFree (p); + XML_Parser p; + if (filenames[i] == NULL) + continue; + + p = XML_ParserCreate (NULL); /* use encoding specified by file */ + XML_SetElementHandler (p, optConfStartElem, optConfEndElem); + XML_SetUserData (p, &userData); + userData.parser = p; + userData.name = filenames[i]; + userData.ignoringDevice = 0; + userData.ignoringApp = 0; + userData.inDriConf = 0; + userData.inDevice = 0; + userData.inApp = 0; + userData.inOption = 0; + + parseOneConfigFile (p); + XML_ParserFree (p); } free(filenames[1]); @@ -1039,14 +1039,14 @@ driDestroyOptionInfo(driOptionCache *info) { driDestroyOptionCache(info); if (info->info) { - uint32_t i, size = 1 << info->tableSize; - for (i = 0; i < size; ++i) { - if (info->info[i].name) { - free(info->info[i].name); - free(info->info[i].ranges); - } - } - free(info->info); + uint32_t i, size = 1 << info->tableSize; + for (i = 0; i < size; ++i) { + if (info->info[i].name) { + free(info->info[i].name); + free(info->info[i].ranges); + } + } + free(info->info); } } @@ -1054,11 +1054,11 @@ void driDestroyOptionCache(driOptionCache *cache) { if (cache->info) { - GLuint i, size = 1 << cache->tableSize; - for (i = 0; i < size; ++i) { - if (cache->info[i].type == DRI_STRING) - free(cache->values[i]._string); - } + GLuint i, size = 1 << cache->tableSize; + for (i = 0; i < size; ++i) { + if (cache->info[i].type == DRI_STRING) + free(cache->values[i]._string); + } } free(cache->values); } |