2003-10-21 07:05:39 +01:00
|
|
|
/*
|
|
|
|
* XML DRI client-side driver configuration
|
|
|
|
* Copyright (C) 2003 Felix Kuehling
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file xmlconfig.c
|
|
|
|
* \brief Driver-independent client-side part of the XML configuration
|
|
|
|
* \author Felix Kuehling
|
|
|
|
*/
|
|
|
|
|
2018-08-06 04:19:22 +01:00
|
|
|
#include <limits.h>
|
2015-02-24 23:55:53 +00:00
|
|
|
#include <stdarg.h>
|
2019-05-22 15:32:27 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2015-03-05 02:17:57 +00:00
|
|
|
#include <stdio.h>
|
2019-05-22 15:32:27 +01:00
|
|
|
#include <stdlib.h>
|
2003-10-21 07:05:39 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <expat.h>
|
|
|
|
#include <fcntl.h>
|
2015-02-25 00:56:45 +00:00
|
|
|
#include <math.h>
|
2003-10-21 07:05:39 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2018-08-06 04:41:33 +01:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <fnmatch.h>
|
2019-09-08 10:59:32 +01:00
|
|
|
#include <regex.h>
|
2018-05-17 19:33:35 +01:00
|
|
|
#include "strndup.h"
|
2003-10-21 07:05:39 +01:00
|
|
|
#include "xmlconfig.h"
|
2018-07-10 23:00:13 +01:00
|
|
|
#include "u_process.h"
|
2020-03-16 09:49:45 +00:00
|
|
|
#include "os_file.h"
|
2003-10-21 07:05:39 +01:00
|
|
|
|
2019-02-27 15:08:56 +00:00
|
|
|
/* For systems like Hurd */
|
|
|
|
#ifndef PATH_MAX
|
|
|
|
#define PATH_MAX 4096
|
|
|
|
#endif
|
2003-10-21 07:05:39 +01:00
|
|
|
|
2019-11-26 01:05:47 +00:00
|
|
|
static bool
|
|
|
|
be_verbose(void)
|
|
|
|
{
|
|
|
|
const char *s = getenv("MESA_DEBUG");
|
|
|
|
if (!s)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return strstr(s, "silent") == NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
/** \brief Find an option in an option cache with the name as key */
|
2017-02-13 22:03:26 +00:00
|
|
|
static uint32_t
|
|
|
|
findOption(const driOptionCache *cache, const char *name)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t len = strlen (name);
|
|
|
|
uint32_t size = 1 << cache->tableSize, mask = size - 1;
|
|
|
|
uint32_t hash = 0;
|
|
|
|
uint32_t i, shift;
|
2003-10-21 07:05:39 +01:00
|
|
|
|
|
|
|
/* compute a hash from the variable length name */
|
|
|
|
for (i = 0, shift = 0; i < len; ++i, shift = (shift+8) & 31)
|
2017-02-13 22:03:27 +00:00
|
|
|
hash += (uint32_t)name[i] << shift;
|
2003-10-21 07:05:39 +01:00
|
|
|
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) */
|
2017-02-13 22:03:27 +00:00
|
|
|
if (cache->info[hash].name == 0)
|
|
|
|
break;
|
|
|
|
else if (!strcmp (name, cache->info[hash].name))
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
/* this assertion fails if the hash table is full */
|
|
|
|
assert (i < size);
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2020-09-11 00:45:14 +01:00
|
|
|
/** \brief Like strdup with error checking. */
|
2003-10-21 07:05:39 +01:00
|
|
|
#define XSTRDUP(dest,source) do { \
|
2020-09-11 00:45:14 +01:00
|
|
|
if (!(dest = strdup(source))) { \
|
2017-02-13 22:03:27 +00:00
|
|
|
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); \
|
|
|
|
abort(); \
|
2003-10-21 07:05:39 +01:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static int compare (const void *a, const void *b) {
|
|
|
|
return strcmp (*(char *const*)a, *(char *const*)b);
|
|
|
|
}
|
|
|
|
/** \brief Binary search in a string array. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static uint32_t
|
|
|
|
bsearchStr (const XML_Char *name, const XML_Char *elems[], uint32_t count)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
const XML_Char **found;
|
|
|
|
found = bsearch (&name, elems, count, sizeof (XML_Char *), compare);
|
|
|
|
if (found)
|
2017-02-13 22:03:27 +00:00
|
|
|
return found - elems;
|
2003-10-21 07:05:39 +01:00
|
|
|
else
|
2017-02-13 22:03:27 +00:00
|
|
|
return count;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
2004-01-07 23:35:00 +00:00
|
|
|
/** \brief Locale-independent integer parser.
|
|
|
|
*
|
|
|
|
* Works similar to strtol. Leading space is NOT skipped. The input
|
|
|
|
* number may have an optional sign. Radix is specified by base. If
|
|
|
|
* base is 0 then decimal is assumed unless the input number is
|
|
|
|
* prefixed by 0x or 0X for hexadecimal or 0 for octal. After
|
|
|
|
* returning tail points to the first character that is not part of
|
|
|
|
* the integer number. If no number was found then tail points to the
|
|
|
|
* start of the input string. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static int
|
|
|
|
strToI(const XML_Char *string, const XML_Char **tail, int base)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
int radix = base == 0 ? 10 : base;
|
|
|
|
int result = 0;
|
|
|
|
int sign = 1;
|
|
|
|
bool numberFound = false;
|
2004-01-07 23:35:00 +00:00
|
|
|
const XML_Char *start = string;
|
|
|
|
|
|
|
|
assert (radix >= 2 && radix <= 36);
|
|
|
|
|
|
|
|
if (*string == '-') {
|
2017-02-13 22:03:27 +00:00
|
|
|
sign = -1;
|
|
|
|
string++;
|
2004-01-07 23:35:00 +00:00
|
|
|
} else if (*string == '+')
|
2017-02-13 22:03:27 +00:00
|
|
|
string++;
|
2004-01-07 23:35:00 +00:00
|
|
|
if (base == 0 && *string == '0') {
|
2017-02-13 22:03:27 +00:00
|
|
|
numberFound = true;
|
|
|
|
if (*(string+1) == 'x' || *(string+1) == 'X') {
|
|
|
|
radix = 16;
|
|
|
|
string += 2;
|
|
|
|
} else {
|
|
|
|
radix = 8;
|
|
|
|
string++;
|
|
|
|
}
|
2004-01-07 23:35:00 +00:00
|
|
|
}
|
|
|
|
do {
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2014-06-27 04:11:44 +01:00
|
|
|
} while (true);
|
2004-01-07 23:35:00 +00:00
|
|
|
*tail = numberFound ? string : start;
|
|
|
|
return sign * result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Locale-independent floating-point parser.
|
|
|
|
*
|
|
|
|
* Works similar to strtod. Leading space is NOT skipped. The input
|
|
|
|
* number may have an optional sign. '.' is interpreted as decimal
|
2010-09-20 23:27:34 +01:00
|
|
|
* point and may occur at most once. Optionally the number may end in
|
2004-01-07 23:35:00 +00:00
|
|
|
* [eE]<exponent>, where <exponent> is an integer as recognized by
|
|
|
|
* strToI. In that case the result is number * 10^exponent. After
|
|
|
|
* returning tail points to the first character that is not part of
|
|
|
|
* the floating point number. If no number was found then tail points
|
|
|
|
* to the start of the input string.
|
|
|
|
*
|
|
|
|
* Uses two passes for maximum accuracy. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static float
|
|
|
|
strToF(const XML_Char *string, const XML_Char **tail)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
int nDigits = 0, pointPos, exponent;
|
|
|
|
float sign = 1.0f, result = 0.0f, scale;
|
2004-01-07 23:35:00 +00:00
|
|
|
const XML_Char *start = string, *numStart;
|
|
|
|
|
|
|
|
/* sign */
|
|
|
|
if (*string == '-') {
|
2017-02-13 22:03:27 +00:00
|
|
|
sign = -1.0f;
|
|
|
|
string++;
|
2004-01-07 23:35:00 +00:00
|
|
|
} else if (*string == '+')
|
2017-02-13 22:03:27 +00:00
|
|
|
string++;
|
2004-01-07 23:35:00 +00:00
|
|
|
|
|
|
|
/* first pass: determine position of decimal point, number of
|
|
|
|
* digits, exponent and the end of the number. */
|
|
|
|
numStart = string;
|
|
|
|
while (*string >= '0' && *string <= '9') {
|
2017-02-13 22:03:27 +00:00
|
|
|
string++;
|
|
|
|
nDigits++;
|
2004-01-07 23:35:00 +00:00
|
|
|
}
|
|
|
|
pointPos = nDigits;
|
|
|
|
if (*string == '.') {
|
2017-02-13 22:03:27 +00:00
|
|
|
string++;
|
|
|
|
while (*string >= '0' && *string <= '9') {
|
|
|
|
string++;
|
|
|
|
nDigits++;
|
|
|
|
}
|
2004-01-07 23:35:00 +00:00
|
|
|
}
|
|
|
|
if (nDigits == 0) {
|
2017-02-13 22:03:27 +00:00
|
|
|
/* no digits, no number */
|
|
|
|
*tail = start;
|
|
|
|
return 0.0f;
|
2004-01-07 23:35:00 +00:00
|
|
|
}
|
|
|
|
*tail = string;
|
|
|
|
if (*string == 'e' || *string == 'E') {
|
2017-02-13 22:03:27 +00:00
|
|
|
const XML_Char *expTail;
|
|
|
|
exponent = strToI (string+1, &expTail, 10);
|
|
|
|
if (expTail == string+1)
|
|
|
|
exponent = 0;
|
|
|
|
else
|
|
|
|
*tail = expTail;
|
2004-01-07 23:35:00 +00:00
|
|
|
} else
|
2017-02-13 22:03:27 +00:00
|
|
|
exponent = 0;
|
2004-01-07 23:35:00 +00:00
|
|
|
string = numStart;
|
|
|
|
|
|
|
|
/* scale of the first digit */
|
2014-06-27 04:11:44 +01:00
|
|
|
scale = sign * (float)pow (10.0, (double)(pointPos-1 + exponent));
|
2004-01-07 23:35:00 +00:00
|
|
|
|
|
|
|
/* second pass: parse digits */
|
|
|
|
do {
|
2017-02-13 22:03:27 +00:00
|
|
|
if (*string != '.') {
|
|
|
|
assert (*string >= '0' && *string <= '9');
|
|
|
|
result += scale * (float)(*string - '0');
|
|
|
|
scale *= 0.1f;
|
|
|
|
nDigits--;
|
|
|
|
}
|
|
|
|
string++;
|
2004-01-07 23:35:00 +00:00
|
|
|
} while (nDigits > 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
/** \brief Parse a value of a given type. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static unsigned char
|
|
|
|
parseValue(driOptionValue *v, driOptionType type, const XML_Char *string)
|
|
|
|
{
|
2008-04-25 10:39:52 +01:00
|
|
|
const XML_Char *tail = NULL;
|
2003-10-21 07:05:39 +01:00
|
|
|
/* skip leading white-space */
|
|
|
|
string += strspn (string, " \f\n\r\t\v");
|
|
|
|
switch (type) {
|
|
|
|
case DRI_BOOL:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
case DRI_ENUM: /* enum is just a special integer */
|
|
|
|
case DRI_INT:
|
2017-02-13 22:03:27 +00:00
|
|
|
v->_int = strToI (string, &tail, 0);
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case DRI_FLOAT:
|
2017-02-13 22:03:27 +00:00
|
|
|
v->_float = strToF (string, &tail);
|
|
|
|
break;
|
2014-03-06 11:02:44 +00:00
|
|
|
case DRI_STRING:
|
2017-02-13 22:03:27 +00:00
|
|
|
free (v->_string);
|
|
|
|
v->_string = strndup(string, STRING_CONF_MAXLEN);
|
2017-06-30 10:56:50 +01:00
|
|
|
return true;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tail == string)
|
2017-02-13 22:03:27 +00:00
|
|
|
return false; /* empty string (or containing only white-space) */
|
2003-10-21 07:05:39 +01:00
|
|
|
/* skip trailing white space */
|
|
|
|
if (*tail)
|
2017-02-13 22:03:27 +00:00
|
|
|
tail += strspn (tail, " \f\n\r\t\v");
|
2003-10-21 07:05:39 +01:00
|
|
|
if (*tail)
|
2017-02-13 22:03:27 +00:00
|
|
|
return false; /* something left over that is not part of value */
|
2003-10-21 07:05:39 +01:00
|
|
|
|
2014-06-27 04:11:44 +01:00
|
|
|
return true;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Parse a list of ranges of type info->type. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static unsigned char
|
|
|
|
parseRanges(driOptionInfo *info, const XML_Char *string)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
XML_Char *cp, *range;
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t nRanges, i;
|
2003-10-21 07:05:39 +01:00
|
|
|
driOptionRange *ranges;
|
|
|
|
|
|
|
|
XSTRDUP (cp, string);
|
|
|
|
/* pass 1: determine the number of ranges (number of commas + 1) */
|
|
|
|
range = cp;
|
|
|
|
for (nRanges = 1; *range; ++range)
|
2017-02-13 22:03:27 +00:00
|
|
|
if (*range == ',')
|
|
|
|
++nRanges;
|
2003-10-21 07:05:39 +01:00
|
|
|
|
2012-09-01 14:47:24 +01:00
|
|
|
if ((ranges = malloc(nRanges*sizeof(driOptionRange))) == NULL) {
|
2017-02-13 22:03:27 +00:00
|
|
|
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__);
|
|
|
|
abort();
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pass 2: parse all ranges into preallocated array */
|
|
|
|
range = cp;
|
|
|
|
for (i = 0; i < nRanges; ++i) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
2012-09-01 14:47:24 +01:00
|
|
|
free(cp);
|
2003-10-21 07:05:39 +01:00
|
|
|
if (i < nRanges) {
|
2017-02-13 22:03:27 +00:00
|
|
|
free(ranges);
|
|
|
|
return false;
|
2003-10-21 07:05:39 +01:00
|
|
|
} else
|
2017-02-13 22:03:27 +00:00
|
|
|
assert (range == NULL);
|
2003-10-21 07:05:39 +01:00
|
|
|
|
|
|
|
info->nRanges = nRanges;
|
|
|
|
info->ranges = ranges;
|
2014-06-27 04:11:44 +01:00
|
|
|
return true;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Check if a value is in one of info->ranges. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static bool
|
|
|
|
checkValue(const driOptionValue *v, const driOptionInfo *info)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i;
|
2003-10-21 07:05:39 +01:00
|
|
|
assert (info->type != DRI_BOOL); /* should be caught by the parser */
|
|
|
|
if (info->nRanges == 0)
|
2017-02-13 22:03:27 +00:00
|
|
|
return true;
|
2003-10-21 07:05:39 +01:00
|
|
|
switch (info->type) {
|
|
|
|
case DRI_ENUM: /* enum is just a special integer */
|
|
|
|
case DRI_INT:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
case DRI_FLOAT:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2014-03-06 11:02:44 +00:00
|
|
|
case DRI_STRING:
|
2017-02-13 22:03:27 +00:00
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
default:
|
2017-02-13 22:03:27 +00:00
|
|
|
assert (0); /* should never happen */
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
2014-06-27 04:11:44 +01:00
|
|
|
return false;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
2011-11-03 12:19:41 +00:00
|
|
|
/**
|
|
|
|
* Print message to \c stderr if the \c LIBGL_DEBUG environment variable
|
|
|
|
* is set.
|
|
|
|
*
|
|
|
|
* Is called from the drivers.
|
|
|
|
*
|
|
|
|
* \param f \c printf like format string.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
__driUtilMessage(const char *f, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2014-08-26 21:47:51 +01:00
|
|
|
const char *libgl_debug;
|
2011-11-03 12:19:41 +00:00
|
|
|
|
2014-08-26 21:47:51 +01:00
|
|
|
libgl_debug=getenv("LIBGL_DEBUG");
|
|
|
|
if (libgl_debug && !strstr(libgl_debug, "quiet")) {
|
2011-11-03 12:19:41 +00:00
|
|
|
fprintf(stderr, "libGL: ");
|
|
|
|
va_start(args, f);
|
|
|
|
vfprintf(stderr, f, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
/** \brief Output a warning message. */
|
|
|
|
#define XML_WARNING1(msg) do {\
|
|
|
|
__driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \
|
2007-12-21 20:31:00 +00:00
|
|
|
(int) XML_GetCurrentLineNumber(data->parser), \
|
|
|
|
(int) XML_GetCurrentColumnNumber(data->parser)); \
|
2003-10-21 07:05:39 +01:00
|
|
|
} while (0)
|
2017-08-22 11:39:35 +01:00
|
|
|
#define XML_WARNING(msg, ...) do { \
|
2003-10-21 07:05:39 +01:00
|
|
|
__driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \
|
2007-12-21 20:31:00 +00:00
|
|
|
(int) XML_GetCurrentLineNumber(data->parser), \
|
|
|
|
(int) XML_GetCurrentColumnNumber(data->parser), \
|
2017-08-22 11:39:35 +01:00
|
|
|
##__VA_ARGS__); \
|
2003-10-21 07:05:39 +01:00
|
|
|
} while (0)
|
|
|
|
/** \brief Output an error message. */
|
|
|
|
#define XML_ERROR1(msg) do { \
|
|
|
|
__driUtilMessage ("Error in %s line %d, column %d: "msg, data->name, \
|
2007-12-21 20:31:00 +00:00
|
|
|
(int) XML_GetCurrentLineNumber(data->parser), \
|
|
|
|
(int) XML_GetCurrentColumnNumber(data->parser)); \
|
2003-10-21 07:05:39 +01:00
|
|
|
} while (0)
|
2017-08-22 11:39:35 +01:00
|
|
|
#define XML_ERROR(msg, ...) do { \
|
2003-10-21 07:05:39 +01:00
|
|
|
__driUtilMessage ("Error in %s line %d, column %d: "msg, data->name, \
|
2007-12-21 20:31:00 +00:00
|
|
|
(int) XML_GetCurrentLineNumber(data->parser), \
|
|
|
|
(int) XML_GetCurrentColumnNumber(data->parser), \
|
2017-08-22 11:39:35 +01:00
|
|
|
##__VA_ARGS__); \
|
2003-10-21 07:05:39 +01:00
|
|
|
} while (0)
|
|
|
|
/** \brief Output a fatal error message and abort. */
|
|
|
|
#define XML_FATAL1(msg) do { \
|
|
|
|
fprintf (stderr, "Fatal error in %s line %d, column %d: "msg"\n", \
|
|
|
|
data->name, \
|
2017-02-13 22:03:27 +00:00
|
|
|
(int) XML_GetCurrentLineNumber(data->parser), \
|
2007-12-21 20:31:00 +00:00
|
|
|
(int) XML_GetCurrentColumnNumber(data->parser)); \
|
2003-10-21 07:05:39 +01:00
|
|
|
abort();\
|
|
|
|
} while (0)
|
2017-08-22 11:39:35 +01:00
|
|
|
#define XML_FATAL(msg, ...) do { \
|
2003-10-21 07:05:39 +01:00
|
|
|
fprintf (stderr, "Fatal error in %s line %d, column %d: "msg"\n", \
|
|
|
|
data->name, \
|
2017-02-13 22:03:27 +00:00
|
|
|
(int) XML_GetCurrentLineNumber(data->parser), \
|
|
|
|
(int) XML_GetCurrentColumnNumber(data->parser), \
|
2017-08-22 11:39:35 +01:00
|
|
|
##__VA_ARGS__); \
|
2003-10-21 07:05:39 +01:00
|
|
|
abort();\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** \brief Parser context for __driConfigOptions. */
|
|
|
|
struct OptInfoData {
|
|
|
|
const char *name;
|
|
|
|
XML_Parser parser;
|
|
|
|
driOptionCache *cache;
|
2014-06-27 04:11:44 +01:00
|
|
|
bool inDriInfo;
|
|
|
|
bool inSection;
|
|
|
|
bool inDesc;
|
|
|
|
bool inOption;
|
|
|
|
bool inEnum;
|
2003-10-21 07:05:39 +01:00
|
|
|
int curOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Elements in __driConfigOptions. */
|
|
|
|
enum OptInfoElem {
|
|
|
|
OI_DESCRIPTION = 0, OI_DRIINFO, OI_ENUM, OI_OPTION, OI_SECTION, OI_COUNT
|
|
|
|
};
|
|
|
|
static const XML_Char *OptInfoElems[] = {
|
|
|
|
"description", "driinfo", "enum", "option", "section"
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Parse attributes of an enum element.
|
|
|
|
*
|
|
|
|
* We're not actually interested in the data. Just make sure this is ok
|
|
|
|
* for external configuration tools.
|
|
|
|
*/
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
parseEnumAttr(struct OptInfoData *data, const XML_Char **attr)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i;
|
2003-10-21 07:05:39 +01:00
|
|
|
const XML_Char *value = NULL, *text = NULL;
|
|
|
|
driOptionValue v;
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t opt = data->curOption;
|
2003-10-21 07:05:39 +01:00
|
|
|
for (i = 0; attr[i]; i += 2) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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]);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
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))
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("illegal enum value: %s.", value);
|
2003-10-21 07:05:39 +01:00
|
|
|
if (!checkValue (&v, &data->cache->info[opt]))
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("enum value out of valid range: %s.", value);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Parse attributes of a description element.
|
|
|
|
*
|
|
|
|
* We're not actually interested in the data. Just make sure this is ok
|
|
|
|
* for external configuration tools.
|
|
|
|
*/
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
parseDescAttr(struct OptInfoData *data, const XML_Char **attr)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i;
|
2003-10-21 07:05:39 +01:00
|
|
|
const XML_Char *lang = NULL, *text = NULL;
|
|
|
|
for (i = 0; attr[i]; i += 2) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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]);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
if (!lang) XML_FATAL1 ("lang attribute missing in description.");
|
|
|
|
if (!text) XML_FATAL1 ("text attribute missing in description.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Parse attributes of an option element. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
parseOptInfoAttr(struct OptInfoData *data, const XML_Char **attr)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
enum OptAttr {OA_DEFAULT = 0, OA_NAME, OA_TYPE, OA_VALID, OA_COUNT};
|
|
|
|
static const XML_Char *optAttr[] = {"default", "name", "type", "valid"};
|
|
|
|
const XML_Char *attrVal[OA_COUNT] = {NULL, NULL, NULL, NULL};
|
|
|
|
const char *defaultVal;
|
|
|
|
driOptionCache *cache = data->cache;
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t opt, i;
|
2003-10-21 07:05:39 +01:00
|
|
|
for (i = 0; attr[i]; i += 2) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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];
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
if (!attrVal[OA_NAME]) XML_FATAL1 ("name attribute missing in option.");
|
|
|
|
if (!attrVal[OA_TYPE]) XML_FATAL1 ("type attribute missing in option.");
|
|
|
|
if (!attrVal[OA_DEFAULT]) XML_FATAL1 ("default attribute missing in option.");
|
|
|
|
|
|
|
|
opt = findOption (cache, attrVal[OA_NAME]);
|
|
|
|
if (cache->info[opt].name)
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("option %s redefined.", attrVal[OA_NAME]);
|
2003-10-21 07:05:39 +01:00
|
|
|
data->curOption = opt;
|
|
|
|
|
|
|
|
XSTRDUP (cache->info[opt].name, attrVal[OA_NAME]);
|
|
|
|
|
|
|
|
if (!strcmp (attrVal[OA_TYPE], "bool"))
|
2017-02-13 22:03:27 +00:00
|
|
|
cache->info[opt].type = DRI_BOOL;
|
2003-10-21 07:05:39 +01:00
|
|
|
else if (!strcmp (attrVal[OA_TYPE], "enum"))
|
2017-02-13 22:03:27 +00:00
|
|
|
cache->info[opt].type = DRI_ENUM;
|
2003-10-21 07:05:39 +01:00
|
|
|
else if (!strcmp (attrVal[OA_TYPE], "int"))
|
2017-02-13 22:03:27 +00:00
|
|
|
cache->info[opt].type = DRI_INT;
|
2003-10-21 07:05:39 +01:00
|
|
|
else if (!strcmp (attrVal[OA_TYPE], "float"))
|
2017-02-13 22:03:27 +00:00
|
|
|
cache->info[opt].type = DRI_FLOAT;
|
2014-03-06 11:02:44 +00:00
|
|
|
else if (!strcmp (attrVal[OA_TYPE], "string"))
|
2017-02-13 22:03:27 +00:00
|
|
|
cache->info[opt].type = DRI_STRING;
|
2003-10-21 07:05:39 +01:00
|
|
|
else
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("illegal type in option: %s.", attrVal[OA_TYPE]);
|
2003-10-21 07:05:39 +01:00
|
|
|
|
|
|
|
defaultVal = getenv (cache->info[opt].name);
|
|
|
|
if (defaultVal != NULL) {
|
|
|
|
/* don't use XML_WARNING, we want the user to see this! */
|
2019-11-26 01:05:47 +00:00
|
|
|
if (be_verbose()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ATTENTION: default value of option %s overridden by environment.\n",
|
|
|
|
cache->info[opt].name);
|
|
|
|
}
|
2003-10-21 07:05:39 +01:00
|
|
|
} else
|
2017-02-13 22:03:27 +00:00
|
|
|
defaultVal = attrVal[OA_DEFAULT];
|
2003-10-21 07:05:39 +01:00
|
|
|
if (!parseValue (&cache->values[opt], cache->info[opt].type, defaultVal))
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("illegal default value for %s: %s.", cache->info[opt].name, defaultVal);
|
2003-10-21 07:05:39 +01:00
|
|
|
|
|
|
|
if (attrVal[OA_VALID]) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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);
|
2003-10-21 07:05:39 +01:00
|
|
|
} else if (cache->info[opt].type == DRI_ENUM) {
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL1 ("valid attribute missing in option (mandatory for enums).");
|
2003-10-21 07:05:39 +01:00
|
|
|
} else {
|
2017-02-13 22:03:27 +00:00
|
|
|
cache->info[opt].nRanges = 0;
|
|
|
|
cache->info[opt].ranges = NULL;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Handler for start element events. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
optInfoStartElem(void *userData, const XML_Char *name, const XML_Char **attr)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
struct OptInfoData *data = (struct OptInfoData *)userData;
|
|
|
|
enum OptInfoElem elem = bsearchStr (name, OptInfoElems, OI_COUNT);
|
|
|
|
switch (elem) {
|
|
|
|
case OI_DRIINFO:
|
2017-02-13 22:03:27 +00:00
|
|
|
if (data->inDriInfo)
|
|
|
|
XML_FATAL1 ("nested <driinfo> elements.");
|
|
|
|
if (attr[0])
|
|
|
|
XML_FATAL1 ("attributes specified on <driinfo> element.");
|
|
|
|
data->inDriInfo = true;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_SECTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_DESCRIPTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_OPTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_ENUM:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
default:
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("unknown element: %s.", name);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Handler for end element events. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
optInfoEndElem(void *userData, const XML_Char *name)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
struct OptInfoData *data = (struct OptInfoData *)userData;
|
|
|
|
enum OptInfoElem elem = bsearchStr (name, OptInfoElems, OI_COUNT);
|
|
|
|
switch (elem) {
|
|
|
|
case OI_DRIINFO:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inDriInfo = false;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_SECTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inSection = false;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_DESCRIPTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inDesc = false;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_OPTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inOption = false;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OI_ENUM:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inEnum = false;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
default:
|
2017-02-13 22:03:27 +00:00
|
|
|
assert (0); /* should have been caught by StartElem */
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
void
|
|
|
|
driParseOptionInfo(driOptionCache *info, const char *configOptions)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
XML_Parser p;
|
|
|
|
int status;
|
|
|
|
struct OptInfoData userData;
|
|
|
|
struct OptInfoData *data = &userData;
|
2013-06-26 23:22:13 +01:00
|
|
|
|
|
|
|
/* Make the hash table big enough to fit more than the maximum number of
|
|
|
|
* config options we've ever seen in a driver.
|
|
|
|
*/
|
|
|
|
info->tableSize = 6;
|
|
|
|
info->info = calloc(1 << info->tableSize, sizeof (driOptionInfo));
|
|
|
|
info->values = calloc(1 << info->tableSize, sizeof (driOptionValue));
|
2003-10-21 07:05:39 +01:00
|
|
|
if (info->info == NULL || info->values == NULL) {
|
2017-02-13 22:03:27 +00:00
|
|
|
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__);
|
|
|
|
abort();
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
p = XML_ParserCreate ("UTF-8"); /* always UTF-8 */
|
|
|
|
XML_SetElementHandler (p, optInfoStartElem, optInfoEndElem);
|
|
|
|
XML_SetUserData (p, data);
|
|
|
|
|
|
|
|
userData.name = "__driConfigOptions";
|
|
|
|
userData.parser = p;
|
|
|
|
userData.cache = info;
|
2014-06-27 04:11:44 +01:00
|
|
|
userData.inDriInfo = false;
|
|
|
|
userData.inSection = false;
|
|
|
|
userData.inDesc = false;
|
|
|
|
userData.inOption = false;
|
|
|
|
userData.inEnum = false;
|
2003-10-21 07:05:39 +01:00
|
|
|
userData.curOption = -1;
|
|
|
|
|
2003-12-12 16:38:57 +00:00
|
|
|
status = XML_Parse (p, configOptions, strlen (configOptions), 1);
|
2003-10-21 07:05:39 +01:00
|
|
|
if (!status)
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_FATAL ("%s.", XML_ErrorString(XML_GetErrorCode(p)));
|
2003-10-21 07:05:39 +01:00
|
|
|
|
|
|
|
XML_ParserFree (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Parser context for configuration files. */
|
|
|
|
struct OptConfData {
|
|
|
|
const char *name;
|
|
|
|
XML_Parser parser;
|
|
|
|
driOptionCache *cache;
|
2014-06-27 04:11:44 +01:00
|
|
|
int screenNum;
|
2003-10-21 07:05:39 +01:00
|
|
|
const char *driverName, *execName;
|
2018-08-06 04:19:26 +01:00
|
|
|
const char *kernelDriverName;
|
2019-09-08 10:59:32 +01:00
|
|
|
const char *engineName;
|
2020-07-30 01:33:01 +01:00
|
|
|
const char *applicationName;
|
2019-09-08 10:59:32 +01:00
|
|
|
uint32_t engineVersion;
|
2020-07-30 01:33:01 +01:00
|
|
|
uint32_t applicationVersion;
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t ignoringDevice;
|
|
|
|
uint32_t ignoringApp;
|
|
|
|
uint32_t inDriConf;
|
|
|
|
uint32_t inDevice;
|
|
|
|
uint32_t inApp;
|
|
|
|
uint32_t inOption;
|
2003-10-21 07:05:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Elements in configuration files. */
|
|
|
|
enum OptConfElem {
|
2019-09-08 10:59:32 +01:00
|
|
|
OC_APPLICATION = 0, OC_DEVICE, OC_DRICONF, OC_ENGINE, OC_OPTION, OC_COUNT
|
2003-10-21 07:05:39 +01:00
|
|
|
};
|
|
|
|
static const XML_Char *OptConfElems[] = {
|
2017-07-18 12:22:21 +01:00
|
|
|
[OC_APPLICATION] = "application",
|
|
|
|
[OC_DEVICE] = "device",
|
|
|
|
[OC_DRICONF] = "driconf",
|
2019-09-08 10:59:32 +01:00
|
|
|
[OC_ENGINE] = "engine",
|
2017-07-18 12:22:21 +01:00
|
|
|
[OC_OPTION] = "option",
|
2003-10-21 07:05:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Parse attributes of a device element. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
parseDeviceAttr(struct OptConfData *data, const XML_Char **attr)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i;
|
2018-08-06 04:19:26 +01:00
|
|
|
const XML_Char *driver = NULL, *screen = NULL, *kernel = NULL;
|
2003-10-21 07:05:39 +01:00
|
|
|
for (i = 0; attr[i]; i += 2) {
|
2017-02-13 22:03:27 +00:00
|
|
|
if (!strcmp (attr[i], "driver")) driver = attr[i+1];
|
|
|
|
else if (!strcmp (attr[i], "screen")) screen = attr[i+1];
|
2018-08-06 04:19:26 +01:00
|
|
|
else if (!strcmp (attr[i], "kernel_driver")) kernel = attr[i+1];
|
2017-02-13 22:03:27 +00:00
|
|
|
else XML_WARNING("unknown device attribute: %s.", attr[i]);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
if (driver && strcmp (driver, data->driverName))
|
2017-02-13 22:03:27 +00:00
|
|
|
data->ignoringDevice = data->inDevice;
|
2018-08-06 04:19:26 +01:00
|
|
|
else if (kernel && (!data->kernelDriverName || strcmp (kernel, data->kernelDriverName)))
|
|
|
|
data->ignoringDevice = data->inDevice;
|
2003-10-21 07:05:39 +01:00
|
|
|
else if (screen) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 10:59:32 +01:00
|
|
|
static bool
|
|
|
|
valueInRanges(const driOptionInfo *info, uint32_t value)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < info->nRanges; i++) {
|
|
|
|
if (info->ranges[i].start._int <= value &&
|
|
|
|
info->ranges[i].end._int >= value)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
/** \brief Parse attributes of an application element. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
parseAppAttr(struct OptConfData *data, const XML_Char **attr)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i;
|
2011-07-15 20:09:02 +01:00
|
|
|
const XML_Char *exec = NULL;
|
2020-03-16 09:49:45 +00:00
|
|
|
const XML_Char *sha1 = NULL;
|
2020-07-30 01:33:01 +01:00
|
|
|
const XML_Char *application_name_match = NULL;
|
|
|
|
const XML_Char *application_versions = NULL;
|
|
|
|
driOptionInfo version_ranges = {
|
|
|
|
.type = DRI_INT,
|
|
|
|
};
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
for (i = 0; attr[i]; i += 2) {
|
2017-02-13 22:03:27 +00:00
|
|
|
if (!strcmp (attr[i], "name")) /* not needed here */;
|
|
|
|
else if (!strcmp (attr[i], "executable")) exec = attr[i+1];
|
2020-03-16 09:49:45 +00:00
|
|
|
else if (!strcmp (attr[i], "sha1")) sha1 = attr[i+1];
|
2020-07-30 01:33:01 +01:00
|
|
|
else if (!strcmp (attr[i], "application_name_match"))
|
|
|
|
application_name_match = attr[i+1];
|
|
|
|
else if (!strcmp (attr[i], "application_versions"))
|
|
|
|
application_versions = attr[i+1];
|
2017-02-13 22:03:27 +00:00
|
|
|
else XML_WARNING("unknown application attribute: %s.", attr[i]);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
2020-03-16 09:49:45 +00:00
|
|
|
if (exec && strcmp (exec, data->execName)) {
|
2017-02-13 22:03:27 +00:00
|
|
|
data->ignoringApp = data->inApp;
|
2020-03-16 09:49:45 +00:00
|
|
|
} else if (sha1) {
|
2020-04-03 08:25:05 +01:00
|
|
|
/* SHA1_DIGEST_STRING_LENGTH includes terminating null byte */
|
|
|
|
if (strlen(sha1) != (SHA1_DIGEST_STRING_LENGTH - 1)) {
|
2020-03-16 09:49:45 +00:00
|
|
|
XML_WARNING("Incorrect sha1 application attribute");
|
|
|
|
data->ignoringApp = data->inApp;
|
|
|
|
} else {
|
|
|
|
size_t len;
|
|
|
|
char* content;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
if (util_get_process_exec_path(path, ARRAY_SIZE(path)) > 0 &&
|
|
|
|
(content = os_read_file(path, &len))) {
|
2020-04-03 08:25:05 +01:00
|
|
|
uint8_t sha1x[SHA1_DIGEST_LENGTH];
|
|
|
|
char sha1s[SHA1_DIGEST_STRING_LENGTH];
|
2020-03-16 09:49:45 +00:00
|
|
|
_mesa_sha1_compute(content, len, sha1x);
|
|
|
|
_mesa_sha1_format((char*) sha1s, sha1x);
|
|
|
|
free(content);
|
|
|
|
|
2020-04-03 08:25:05 +01:00
|
|
|
if (strcmp(sha1, sha1s)) {
|
2020-03-16 09:49:45 +00:00
|
|
|
data->ignoringApp = data->inApp;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data->ignoringApp = data->inApp;
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 01:33:01 +01:00
|
|
|
} else if (application_name_match) {
|
|
|
|
regex_t re;
|
|
|
|
|
|
|
|
if (regcomp (&re, application_name_match, REG_EXTENDED|REG_NOSUB) == 0) {
|
|
|
|
if (regexec (&re, data->applicationName, 0, NULL, 0) == REG_NOMATCH)
|
|
|
|
data->ignoringApp = data->inApp;
|
|
|
|
regfree (&re);
|
|
|
|
} else
|
|
|
|
XML_WARNING ("Invalid application_name_match=\"%s\".", application_name_match);
|
|
|
|
}
|
|
|
|
if (application_versions) {
|
|
|
|
if (parseRanges (&version_ranges, application_versions) &&
|
|
|
|
!valueInRanges (&version_ranges, data->applicationVersion))
|
|
|
|
data->ignoringApp = data->inApp;
|
2020-03-16 09:49:45 +00:00
|
|
|
}
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
2019-09-08 10:59:32 +01:00
|
|
|
/** \brief Parse attributes of an application element. */
|
|
|
|
static void
|
|
|
|
parseEngineAttr(struct OptConfData *data, const XML_Char **attr)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
const XML_Char *engine_name_match = NULL, *engine_versions = NULL;
|
|
|
|
driOptionInfo version_ranges = {
|
|
|
|
.type = DRI_INT,
|
|
|
|
};
|
|
|
|
for (i = 0; attr[i]; i += 2) {
|
|
|
|
if (!strcmp (attr[i], "name")) /* not needed here */;
|
|
|
|
else if (!strcmp (attr[i], "engine_name_match")) engine_name_match = attr[i+1];
|
|
|
|
else if (!strcmp (attr[i], "engine_versions")) engine_versions = attr[i+1];
|
|
|
|
else XML_WARNING("unknown application attribute: %s.", attr[i]);
|
|
|
|
}
|
|
|
|
if (engine_name_match) {
|
|
|
|
regex_t re;
|
|
|
|
|
2019-09-16 15:47:12 +01:00
|
|
|
if (regcomp (&re, engine_name_match, REG_EXTENDED|REG_NOSUB) == 0) {
|
2019-09-08 10:59:32 +01:00
|
|
|
if (regexec (&re, data->engineName, 0, NULL, 0) == REG_NOMATCH)
|
|
|
|
data->ignoringApp = data->inApp;
|
|
|
|
regfree (&re);
|
|
|
|
} else
|
|
|
|
XML_WARNING ("Invalid engine_name_match=\"%s\".", engine_name_match);
|
|
|
|
}
|
|
|
|
if (engine_versions) {
|
|
|
|
if (parseRanges (&version_ranges, engine_versions) &&
|
|
|
|
!valueInRanges (&version_ranges, data->engineVersion))
|
|
|
|
data->ignoringApp = data->inApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(version_ranges.ranges);
|
|
|
|
}
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
/** \brief Parse attributes of an option element. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
parseOptConfAttr(struct OptConfData *data, const XML_Char **attr)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i;
|
2003-10-21 07:05:39 +01:00
|
|
|
const XML_Char *name = NULL, *value = NULL;
|
|
|
|
for (i = 0; attr[i]; i += 2) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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]);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
if (!name) XML_WARNING1 ("name attribute missing in option.");
|
|
|
|
if (!value) XML_WARNING1 ("value attribute missing in option.");
|
|
|
|
if (name && value) {
|
2017-02-13 22:03:27 +00:00
|
|
|
driOptionCache *cache = data->cache;
|
|
|
|
uint32_t opt = findOption (cache, name);
|
|
|
|
if (cache->info[opt].name == NULL)
|
2013-07-30 21:29:22 +01:00
|
|
|
/* don't use XML_WARNING, drirc defines options for all drivers,
|
|
|
|
* but not all drivers support them */
|
|
|
|
return;
|
2019-11-26 01:05:47 +00:00
|
|
|
else if (getenv (cache->info[opt].name)) {
|
2017-02-13 22:03:27 +00:00
|
|
|
/* don't use XML_WARNING, we want the user to see this! */
|
2019-11-26 01:05:47 +00:00
|
|
|
if (be_verbose()) {
|
|
|
|
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))
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_WARNING ("illegal option value: %s.", value);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Handler for start element events. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
optConfStartElem(void *userData, const XML_Char *name,
|
|
|
|
const XML_Char **attr)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
struct OptConfData *data = (struct OptConfData *)userData;
|
|
|
|
enum OptConfElem elem = bsearchStr (name, OptConfElems, OC_COUNT);
|
|
|
|
switch (elem) {
|
|
|
|
case OC_DRICONF:
|
2017-02-13 22:03:27 +00:00
|
|
|
if (data->inDriConf)
|
|
|
|
XML_WARNING1 ("nested <driconf> elements.");
|
|
|
|
if (attr[0])
|
|
|
|
XML_WARNING1 ("attributes specified on <driconf> element.");
|
|
|
|
data->inDriConf++;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OC_DEVICE:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OC_APPLICATION:
|
2017-02-13 22:03:27 +00:00
|
|
|
if (!data->inDevice)
|
|
|
|
XML_WARNING1 ("<application> should be inside <device>.");
|
|
|
|
if (data->inApp)
|
2019-09-08 10:59:32 +01:00
|
|
|
XML_WARNING1 ("nested <application> or <engine> elements.");
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inApp++;
|
|
|
|
if (!data->ignoringDevice && !data->ignoringApp)
|
|
|
|
parseAppAttr (data, attr);
|
|
|
|
break;
|
2019-09-08 10:59:32 +01:00
|
|
|
case OC_ENGINE:
|
|
|
|
if (!data->inDevice)
|
|
|
|
XML_WARNING1 ("<engine> should be inside <device>.");
|
|
|
|
if (data->inApp)
|
|
|
|
XML_WARNING1 ("nested <application> or <engine> elements.");
|
|
|
|
data->inApp++;
|
|
|
|
if (!data->ignoringDevice && !data->ignoringApp)
|
|
|
|
parseEngineAttr (data, attr);
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OC_OPTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
default:
|
2017-02-13 22:03:27 +00:00
|
|
|
XML_WARNING ("unknown element: %s.", name);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Handler for end element events. */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
optConfEndElem(void *userData, const XML_Char *name)
|
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
struct OptConfData *data = (struct OptConfData *)userData;
|
|
|
|
enum OptConfElem elem = bsearchStr (name, OptConfElems, OC_COUNT);
|
|
|
|
switch (elem) {
|
|
|
|
case OC_DRICONF:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inDriConf--;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OC_DEVICE:
|
2017-02-13 22:03:27 +00:00
|
|
|
if (data->inDevice-- == data->ignoringDevice)
|
|
|
|
data->ignoringDevice = 0;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OC_APPLICATION:
|
2019-09-08 10:59:32 +01:00
|
|
|
case OC_ENGINE:
|
2017-02-13 22:03:27 +00:00
|
|
|
if (data->inApp-- == data->ignoringApp)
|
|
|
|
data->ignoringApp = 0;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
case OC_OPTION:
|
2017-02-13 22:03:27 +00:00
|
|
|
data->inOption--;
|
|
|
|
break;
|
2003-10-21 07:05:39 +01:00
|
|
|
default:
|
2017-02-13 22:03:27 +00:00
|
|
|
/* unknown element, warning was produced on start tag */;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Initialize an option cache based on info */
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
|
|
|
initOptionCache(driOptionCache *cache, const driOptionCache *info)
|
|
|
|
{
|
2017-06-30 10:56:50 +01:00
|
|
|
unsigned i, size = 1 << info->tableSize;
|
2003-10-21 07:05:39 +01:00
|
|
|
cache->info = info->info;
|
|
|
|
cache->tableSize = info->tableSize;
|
2012-09-01 14:47:24 +01:00
|
|
|
cache->values = malloc((1<<info->tableSize) * sizeof (driOptionValue));
|
2003-10-21 07:05:39 +01:00
|
|
|
if (cache->values == NULL) {
|
2017-02-13 22:03:27 +00:00
|
|
|
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__);
|
|
|
|
abort();
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
memcpy (cache->values, info->values,
|
2017-02-13 22:03:27 +00:00
|
|
|
(1<<info->tableSize) * sizeof (driOptionValue));
|
2014-03-06 11:02:44 +00:00
|
|
|
for (i = 0; i < size; ++i) {
|
2017-02-13 22:03:27 +00:00
|
|
|
if (cache->info[i].type == DRI_STRING)
|
|
|
|
XSTRDUP(cache->values[i]._string, info->values[i]._string);
|
2014-03-06 11:02:44 +00:00
|
|
|
}
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
static void
|
2018-08-06 04:19:22 +01:00
|
|
|
_parseOneConfigFile(XML_Parser p)
|
2017-02-13 22:03:26 +00:00
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
#define BUF_SIZE 0x1000
|
|
|
|
struct OptConfData *data = (struct OptConfData *)XML_GetUserData (p);
|
|
|
|
int status;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if ((fd = open (data->name, O_RDONLY)) == -1) {
|
2017-02-13 22:03:27 +00:00
|
|
|
__driUtilMessage ("Can't open configuration file %s: %s.",
|
|
|
|
data->name, strerror (errno));
|
|
|
|
return;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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;
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
#undef BUF_SIZE
|
|
|
|
}
|
|
|
|
|
2018-08-06 04:19:22 +01:00
|
|
|
/** \brief Parse the named configuration file */
|
|
|
|
static void
|
|
|
|
parseOneConfigFile(struct OptConfData *data, const char *filename)
|
|
|
|
{
|
|
|
|
XML_Parser p;
|
|
|
|
|
|
|
|
p = XML_ParserCreate (NULL); /* use encoding specified by file */
|
|
|
|
XML_SetElementHandler (p, optConfStartElem, optConfEndElem);
|
|
|
|
XML_SetUserData (p, data);
|
|
|
|
data->parser = p;
|
|
|
|
data->name = filename;
|
|
|
|
data->ignoringDevice = 0;
|
|
|
|
data->ignoringApp = 0;
|
|
|
|
data->inDriConf = 0;
|
|
|
|
data->inDevice = 0;
|
|
|
|
data->inApp = 0;
|
|
|
|
data->inOption = 0;
|
|
|
|
|
|
|
|
_parseOneConfigFile (p);
|
|
|
|
XML_ParserFree (p);
|
|
|
|
}
|
|
|
|
|
2018-08-06 04:41:33 +01:00
|
|
|
static int
|
|
|
|
scandir_filter(const struct dirent *ent)
|
|
|
|
{
|
2018-10-06 00:34:35 +01:00
|
|
|
#ifndef DT_REG /* systems without d_type in dirent results */
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if ((lstat(ent->d_name, &st) != 0) ||
|
|
|
|
(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)))
|
|
|
|
return 0;
|
|
|
|
#else
|
2018-08-06 04:41:33 +01:00
|
|
|
if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
|
|
|
|
return 0;
|
2018-10-06 00:34:35 +01:00
|
|
|
#endif
|
2018-08-06 04:41:33 +01:00
|
|
|
|
|
|
|
if (fnmatch("*.conf", ent->d_name, 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Parse configuration files in a directory */
|
|
|
|
static void
|
|
|
|
parseConfigDir(struct OptConfData *data, const char *dirname)
|
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
struct dirent **entries = NULL;
|
|
|
|
|
|
|
|
count = scandir(dirname, &entries, scandir_filter, alphasort);
|
|
|
|
if (count < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
char filename[PATH_MAX];
|
|
|
|
|
|
|
|
snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name);
|
|
|
|
free(entries[i]);
|
|
|
|
|
|
|
|
parseOneConfigFile(data, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(entries);
|
|
|
|
}
|
|
|
|
|
2015-09-19 18:17:34 +01:00
|
|
|
#ifndef SYSCONFDIR
|
|
|
|
#define SYSCONFDIR "/etc"
|
|
|
|
#endif
|
|
|
|
|
2018-08-06 04:41:33 +01:00
|
|
|
#ifndef DATADIR
|
|
|
|
#define DATADIR "/usr/share"
|
|
|
|
#endif
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
void
|
|
|
|
driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
|
2018-08-06 04:19:26 +01:00
|
|
|
int screenNum, const char *driverName,
|
2019-09-08 10:59:32 +01:00
|
|
|
const char *kernelDriverName,
|
2020-07-30 01:33:01 +01:00
|
|
|
const char *applicationName, uint32_t applicationVersion,
|
2019-09-08 10:59:32 +01:00
|
|
|
const char *engineName, uint32_t engineVersion)
|
2017-02-13 22:03:26 +00:00
|
|
|
{
|
2003-10-21 07:05:39 +01:00
|
|
|
char *home;
|
|
|
|
struct OptConfData userData;
|
|
|
|
|
|
|
|
initOptionCache (cache, info);
|
|
|
|
|
|
|
|
userData.cache = cache;
|
|
|
|
userData.screenNum = screenNum;
|
|
|
|
userData.driverName = driverName;
|
2018-08-06 04:19:26 +01:00
|
|
|
userData.kernelDriverName = kernelDriverName;
|
2020-07-30 01:33:01 +01:00
|
|
|
userData.applicationName = applicationName ? applicationName : "";
|
|
|
|
userData.applicationVersion = applicationVersion;
|
2019-09-08 10:59:32 +01:00
|
|
|
userData.engineName = engineName ? engineName : "";
|
|
|
|
userData.engineVersion = engineVersion;
|
2018-07-03 19:07:05 +01:00
|
|
|
userData.execName = util_get_process_name();
|
2003-10-21 07:05:39 +01:00
|
|
|
|
2018-08-06 04:41:33 +01:00
|
|
|
parseConfigDir(&userData, DATADIR "/drirc.d");
|
2018-08-06 04:19:22 +01:00
|
|
|
parseOneConfigFile(&userData, SYSCONFDIR "/drirc");
|
|
|
|
|
2003-10-21 07:05:39 +01:00
|
|
|
if ((home = getenv ("HOME"))) {
|
2018-08-06 04:19:22 +01:00
|
|
|
char filename[PATH_MAX];
|
2003-10-21 07:05:39 +01:00
|
|
|
|
2018-08-06 04:19:22 +01:00
|
|
|
snprintf(filename, PATH_MAX, "%s/.drirc", home);
|
|
|
|
parseOneConfigFile(&userData, filename);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
void
|
|
|
|
driDestroyOptionInfo(driOptionCache *info)
|
|
|
|
{
|
|
|
|
driDestroyOptionCache(info);
|
2003-10-21 07:05:39 +01:00
|
|
|
if (info->info) {
|
2017-02-13 22:03:27 +00:00
|
|
|
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);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
void
|
|
|
|
driDestroyOptionCache(driOptionCache *cache)
|
|
|
|
{
|
2014-03-06 11:02:44 +00:00
|
|
|
if (cache->info) {
|
2017-06-30 10:56:50 +01:00
|
|
|
unsigned i, size = 1 << cache->tableSize;
|
2017-02-13 22:03:27 +00:00
|
|
|
for (i = 0; i < size; ++i) {
|
|
|
|
if (cache->info[i].type == DRI_STRING)
|
|
|
|
free(cache->values[i]._string);
|
|
|
|
}
|
2014-03-06 11:02:44 +00:00
|
|
|
}
|
2012-09-04 04:24:35 +01:00
|
|
|
free(cache->values);
|
2003-10-21 07:05:39 +01:00
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
unsigned char
|
|
|
|
driCheckOption(const driOptionCache *cache, const char *name,
|
|
|
|
driOptionType type)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i = findOption (cache, name);
|
2003-10-21 07:05:39 +01:00
|
|
|
return cache->info[i].name != NULL && cache->info[i].type == type;
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
unsigned char
|
|
|
|
driQueryOptionb(const driOptionCache *cache, const char *name)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i = findOption (cache, name);
|
2003-10-21 07:05:39 +01:00
|
|
|
/* make sure the option is defined and has the correct type */
|
|
|
|
assert (cache->info[i].name != NULL);
|
|
|
|
assert (cache->info[i].type == DRI_BOOL);
|
|
|
|
return cache->values[i]._bool;
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
int
|
|
|
|
driQueryOptioni(const driOptionCache *cache, const char *name)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i = findOption (cache, name);
|
2003-10-21 07:05:39 +01:00
|
|
|
/* make sure the option is defined and has the correct type */
|
|
|
|
assert (cache->info[i].name != NULL);
|
|
|
|
assert (cache->info[i].type == DRI_INT || cache->info[i].type == DRI_ENUM);
|
|
|
|
return cache->values[i]._int;
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
float
|
|
|
|
driQueryOptionf(const driOptionCache *cache, const char *name)
|
|
|
|
{
|
2014-06-27 04:11:44 +01:00
|
|
|
uint32_t i = findOption (cache, name);
|
2003-10-21 07:05:39 +01:00
|
|
|
/* make sure the option is defined and has the correct type */
|
|
|
|
assert (cache->info[i].name != NULL);
|
|
|
|
assert (cache->info[i].type == DRI_FLOAT);
|
|
|
|
return cache->values[i]._float;
|
|
|
|
}
|
2014-03-06 11:02:44 +00:00
|
|
|
|
2017-02-13 22:03:26 +00:00
|
|
|
char *
|
|
|
|
driQueryOptionstr(const driOptionCache *cache, const char *name)
|
|
|
|
{
|
2017-06-30 10:56:50 +01:00
|
|
|
uint32_t i = findOption (cache, name);
|
2014-03-06 11:02:44 +00:00
|
|
|
/* make sure the option is defined and has the correct type */
|
|
|
|
assert (cache->info[i].name != NULL);
|
|
|
|
assert (cache->info[i].type == DRI_STRING);
|
|
|
|
return cache->values[i]._string;
|
|
|
|
}
|