From 601093f95ddf6b49a79baa91dc51d4f163dfc8de Mon Sep 17 00:00:00 2001 From: Nicolai Hähnle Date: Fri, 30 Jun 2017 11:57:06 +0200 Subject: xmlconfig: move into src/util MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v2: attempt to fix Android build (Emil) v3: add missing include path Reviewed-by: Marek Olšák (v1) --- src/mesa/drivers/dri/common/Android.mk | 48 +- src/mesa/drivers/dri/common/Makefile.am | 13 +- src/mesa/drivers/dri/common/Makefile.sources | 7 +- src/mesa/drivers/dri/common/SConscript | 8 +- src/mesa/drivers/dri/common/dri_util.c | 2 +- src/mesa/drivers/dri/common/dri_util.h | 2 +- src/mesa/drivers/dri/common/drirc | 220 ---- src/mesa/drivers/dri/common/xmlconfig.c | 1113 -------------------- src/mesa/drivers/dri/common/xmlconfig.h | 179 ---- src/mesa/drivers/dri/common/xmlpool.h | 105 -- src/mesa/drivers/dri/common/xmlpool/.gitignore | 8 - src/mesa/drivers/dri/common/xmlpool/Makefile.am | 101 -- src/mesa/drivers/dri/common/xmlpool/SConscript | 14 - src/mesa/drivers/dri/common/xmlpool/ca.po | 348 ------ src/mesa/drivers/dri/common/xmlpool/de.po | 320 ------ src/mesa/drivers/dri/common/xmlpool/es.po | 332 ------ src/mesa/drivers/dri/common/xmlpool/fr.po | 310 ------ src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py | 203 ---- src/mesa/drivers/dri/common/xmlpool/nl.po | 311 ------ src/mesa/drivers/dri/common/xmlpool/sv.po | 309 ------ src/mesa/drivers/dri/common/xmlpool/t_options.h | 431 -------- 21 files changed, 9 insertions(+), 4375 deletions(-) delete mode 100644 src/mesa/drivers/dri/common/drirc delete mode 100644 src/mesa/drivers/dri/common/xmlconfig.c delete mode 100644 src/mesa/drivers/dri/common/xmlconfig.h delete mode 100644 src/mesa/drivers/dri/common/xmlpool.h delete mode 100644 src/mesa/drivers/dri/common/xmlpool/.gitignore delete mode 100644 src/mesa/drivers/dri/common/xmlpool/Makefile.am delete mode 100644 src/mesa/drivers/dri/common/xmlpool/SConscript delete mode 100644 src/mesa/drivers/dri/common/xmlpool/ca.po delete mode 100644 src/mesa/drivers/dri/common/xmlpool/de.po delete mode 100644 src/mesa/drivers/dri/common/xmlpool/es.po delete mode 100644 src/mesa/drivers/dri/common/xmlpool/fr.po delete mode 100644 src/mesa/drivers/dri/common/xmlpool/gen_xmlpool.py delete mode 100644 src/mesa/drivers/dri/common/xmlpool/nl.po delete mode 100644 src/mesa/drivers/dri/common/xmlpool/sv.po delete mode 100644 src/mesa/drivers/dri/common/xmlpool/t_options.h (limited to 'src/mesa/drivers/dri/common') diff --git a/src/mesa/drivers/dri/common/Android.mk b/src/mesa/drivers/dri/common/Android.mk index 8a21e630325..573189d88f6 100644 --- a/src/mesa/drivers/dri/common/Android.mk +++ b/src/mesa/drivers/dri/common/Android.mk @@ -44,53 +44,7 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \ $(intermediates) LOCAL_SRC_FILES := \ - $(DRI_COMMON_FILES) \ - $(XMLCONFIG_FILES) - -MESA_DRI_OPTIONS_H := $(intermediates)/xmlpool/options.h -LOCAL_GENERATED_SOURCES := $(MESA_DRI_OPTIONS_H) - -# -# Generate options.h from gettext translations. -# - -MESA_DRI_OPTIONS_LANGS := de es nl fr sv -POT := $(intermediates)/xmlpool.pot - -$(POT): $(LOCAL_PATH)/xmlpool/t_options.h - @mkdir -p $(dir $@) - xgettext -L C --from-code utf-8 -o $@ $< - -$(intermediates)/xmlpool/%.po: $(LOCAL_PATH)/xmlpool/%.po $(POT) - lang=$(basename $(notdir $@)); \ - mkdir -p $(dir $@); \ - if [ -f $< ]; then \ - msgmerge -o $@ $^; \ - else \ - msginit -i $(POT) \ - -o $@ \ - --locale=$$lang \ - --no-translator; \ - sed -i -e 's/charset=.*\\n/charset=UTF-8\\n/' $@; \ - fi - -PRIVATE_SCRIPT := $(LOCAL_PATH)/xmlpool/gen_xmlpool.py -PRIVATE_LOCALEDIR := $(intermediates)/xmlpool -PRIVATE_TEMPLATE_HEADER := $(LOCAL_PATH)/xmlpool/t_options.h -PRIVATE_MO_FILES := $(MESA_DRI_OPTIONS_LANGS:%=$(intermediates)/xmlpool/%/LC_MESSAGES/options.mo) - -LOCAL_GENERATED_SOURCES += $(PRIVATE_MO_FILES) - -$(PRIVATE_MO_FILES): $(intermediates)/xmlpool/%/LC_MESSAGES/options.mo: $(intermediates)/xmlpool/%.po - mkdir -p $(dir $@) - msgfmt -o $@ $< - -$(LOCAL_GENERATED_SOURCES): PRIVATE_PYTHON := $(MESA_PYTHON2) -$(LOCAL_GENERATED_SOURCES): PRIVATE_CUSTOM_TOOL = $(PRIVATE_PYTHON) $^ $(PRIVATE_TEMPLATE_HEADER) \ - $(PRIVATE_LOCALEDIR) $(MESA_DRI_OPTIONS_LANGS) > $@ - -$(MESA_DRI_OPTIONS_H): $(PRIVATE_SCRIPT) $(PRIVATE_TEMPLATE_HEADER) $(PRIVATE_MO_FILES) - $(transform-generated-source) + $(DRI_COMMON_FILES) include $(MESA_COMMON_MK) include $(BUILD_STATIC_LIBRARY) diff --git a/src/mesa/drivers/dri/common/Makefile.am b/src/mesa/drivers/dri/common/Makefile.am index c85c470a2fb..f26cc069381 100644 --- a/src/mesa/drivers/dri/common/Makefile.am +++ b/src/mesa/drivers/dri/common/Makefile.am @@ -19,11 +19,9 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -SUBDIRS = xmlpool - include Makefile.sources -EXTRA_DIST = drirc xmlpool.h SConscript +EXTRA_DIST = SConscript AM_CFLAGS = \ -I$(top_srcdir)/include \ @@ -32,22 +30,15 @@ AM_CFLAGS = \ -I$(top_srcdir)/src/mesa/ \ -I$(top_srcdir)/src/gallium/include \ -I$(top_srcdir)/src/gallium/auxiliary \ + -I$(top_builddir)/src/util/ \ $(LIBDRM_CFLAGS) \ $(DEFINES) \ - -DSYSCONFDIR=\"$(sysconfdir)\" \ $(VISIBILITY_CFLAGS) noinst_LTLIBRARIES = \ libdricommon.la \ - libxmlconfig.la \ libmegadriver_stub.la libdricommon_la_SOURCES = $(DRI_COMMON_FILES) -libxmlconfig_la_SOURCES = $(XMLCONFIG_FILES) -libxmlconfig_la_CFLAGS = $(AM_CFLAGS) $(EXPAT_CFLAGS) -libxmlconfig_la_LIBADD = $(EXPAT_LIBS) -lm - libmegadriver_stub_la_SOURCES = $(megadriver_stub_FILES) - -sysconf_DATA = drirc diff --git a/src/mesa/drivers/dri/common/Makefile.sources b/src/mesa/drivers/dri/common/Makefile.sources index 9d3cdd38ff0..d592e99b879 100644 --- a/src/mesa/drivers/dri/common/Makefile.sources +++ b/src/mesa/drivers/dri/common/Makefile.sources @@ -4,10 +4,6 @@ DRI_COMMON_FILES := \ dri_util.c \ dri_util.h -XMLCONFIG_FILES := \ - xmlconfig.c \ - xmlconfig.h - # Paths are relative to MESA_TOP. mesa_dri_common_INCLUDES := \ include \ @@ -15,7 +11,8 @@ mesa_dri_common_INCLUDES := \ src/egl/main \ src/mapi \ src/mesa \ - src/mesa/drivers/dri/common + src/mesa/drivers/dri/common \ + src/util megadriver_stub_FILES := \ megadriver_stub.c diff --git a/src/mesa/drivers/dri/common/SConscript b/src/mesa/drivers/dri/common/SConscript index 52d201f8913..06afecede34 100644 --- a/src/mesa/drivers/dri/common/SConscript +++ b/src/mesa/drivers/dri/common/SConscript @@ -7,7 +7,6 @@ drienv = env.Clone() drienv.Replace(CPPPATH = [ '#src/mesa/drivers/dri/common', - xmlpool_options.dir.dir, # Dir to generated xmlpool/options.h '#include', '#include/GL/internal', '#src', @@ -26,13 +25,10 @@ drienv.Replace(CPPPATH = [ '#src/mesa/swrast_setup', '#src/egl/main', '#src/egl/drivers/dri', + '#src/util', ]) -drienv.AppendUnique(LIBS = [ - 'expat', -]) - -sources = drienv.ParseSourceList('Makefile.sources', ['DRI_COMMON_FILES', 'XMLCONFIG_FILES' ]) +sources = drienv.ParseSourceList('Makefile.sources', ['DRI_COMMON_FILES']) dri_common = drienv.ConvenienceLibrary( target = 'dri_common', diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index bfae0209d18..39ecaf0658a 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -42,7 +42,7 @@ #include #include "dri_util.h" #include "utils.h" -#include "xmlpool.h" +#include "util/xmlpool.h" #include "main/mtypes.h" #include "main/framebuffer.h" #include "main/version.h" diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index 3e1ce624c7b..25a3ae47a23 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -56,7 +56,7 @@ #include #include #include "main/mtypes.h" -#include "xmlconfig.h" +#include "util/xmlconfig.h" #include /** diff --git a/src/mesa/drivers/dri/common/drirc b/src/mesa/drivers/dri/common/drirc deleted file mode 100644 index 30ac9c839be..00000000000 --- a/src/mesa/drivers/dri/common/drirc +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c deleted file mode 100644 index d3f47ecda0c..00000000000 --- a/src/mesa/drivers/dri/common/xmlconfig.c +++ /dev/null @@ -1,1113 +0,0 @@ -/* - * 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 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "xmlconfig.h" - -#undef GET_PROGRAM_NAME - -#if (defined(__GNU_LIBRARY__) || defined(__GLIBC__)) && !defined(__UCLIBC__) -# if !defined(__GLIBC__) || (__GLIBC__ < 2) -/* These aren't declared in any libc5 header */ -extern char *program_invocation_name, *program_invocation_short_name; -# endif -# define GET_PROGRAM_NAME() program_invocation_short_name -#elif defined(__CYGWIN__) -# define GET_PROGRAM_NAME() program_invocation_short_name -#elif defined(__FreeBSD__) && (__FreeBSD__ >= 2) -# include -# if (__FreeBSD_version >= 440000) -# include -# define GET_PROGRAM_NAME() getprogname() -# endif -#elif defined(__NetBSD__) && defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106000100) -# include -# define GET_PROGRAM_NAME() getprogname() -#elif defined(__DragonFly__) -# include -# define GET_PROGRAM_NAME() getprogname() -#elif defined(__APPLE__) -# include -# define GET_PROGRAM_NAME() getprogname() -#elif defined(__sun) -/* Solaris has getexecname() which returns the full path - return just - the basename to match BSD getprogname() */ -# include -# include - -static const char * -__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); - } - } - } - return progname; -} - -# define GET_PROGRAM_NAME() __getProgramName() -#endif - -#if !defined(GET_PROGRAM_NAME) -# if defined(__OpenBSD__) || defined(NetBSD) || defined(__UCLIBC__) || defined(ANDROID) -/* This is a hack. It's said to work on OpenBSD, NetBSD and GNU. - * Rogelio M.Serrano Jr. reported it's also working with UCLIBC. It's - * used as a last resort, if there is no documented facility available. */ -static const char * -__getProgramName() -{ - extern const char *__progname; - char * arg = strrchr(__progname, '/'); - if (arg) - return arg+1; - else - return __progname; -} -# define GET_PROGRAM_NAME() __getProgramName() -# else -# define GET_PROGRAM_NAME() "" -# warning "Per application configuration won't work with your OS version." -# endif -#endif - -/** \brief Find an option in an option cache with the name as key */ -static uint32_t -findOption(const driOptionCache *cache, const char *name) -{ - uint32_t len = strlen (name); - uint32_t size = 1 << cache->tableSize, mask = size - 1; - uint32_t hash = 0; - uint32_t i, shift; - - /* 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 *= 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; - } - /* this assertion fails if the hash table is full */ - assert (i < size); - - return hash; -} - -/** \brief Like strdup but using malloc and with error checking. */ -#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(); \ - } \ - memcpy (dest, source, len+1); \ -} 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. */ -static uint32_t -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; - else - return count; -} - -/** \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. */ -static int -strToI(const XML_Char *string, const XML_Char **tail, int base) -{ - int radix = base == 0 ? 10 : base; - int result = 0; - int sign = 1; - bool numberFound = false; - const XML_Char *start = string; - - assert (radix >= 2 && radix <= 36); - - if (*string == '-') { - sign = -1; - string++; - } else if (*string == '+') - string++; - if (base == 0 && *string == '0') { - 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; - } while (true); - *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 - * point and may occur at most once. Optionally the number may end in - * [eE], where 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. */ -static float -strToF(const XML_Char *string, const XML_Char **tail) -{ - int nDigits = 0, pointPos, exponent; - float sign = 1.0f, result = 0.0f, scale; - const XML_Char *start = string, *numStart; - - /* sign */ - if (*string == '-') { - sign = -1.0f; - string++; - } else if (*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++; - } - pointPos = nDigits; - if (*string == '.') { - string++; - while (*string >= '0' && *string <= '9') { - string++; - nDigits++; - } - } - if (nDigits == 0) { - /* 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; - } else - exponent = 0; - string = numStart; - - /* scale of the first digit */ - scale = sign * (float)pow (10.0, (double)(pointPos-1 + exponent)); - - /* second pass: parse digits */ - do { - if (*string != '.') { - assert (*string >= '0' && *string <= '9'); - result += scale * (float)(*string - '0'); - scale *= 0.1f; - nDigits--; - } - string++; - } while (nDigits > 0); - - return result; -} - -/** \brief Parse a value of a given type. */ -static unsigned char -parseValue(driOptionValue *v, driOptionType type, const XML_Char *string) -{ - const XML_Char *tail = NULL; - /* skip leading white-space */ - 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; - case DRI_ENUM: /* enum is just a special integer */ - case DRI_INT: - v->_int = strToI (string, &tail, 0); - break; - case DRI_FLOAT: - v->_float = strToF (string, &tail); - break; - case DRI_STRING: - free (v->_string); - v->_string = strndup(string, STRING_CONF_MAXLEN); - return true; - } - - if (tail == string) - return false; /* empty string (or containing only white-space) */ - /* skip trailing white space */ - if (*tail) - tail += strspn (tail, " \f\n\r\t\v"); - if (*tail) - return false; /* something left over that is not part of value */ - - return true; -} - -/** \brief Parse a list of ranges of type info->type. */ -static unsigned char -parseRanges(driOptionInfo *info, const XML_Char *string) -{ - XML_Char *cp, *range; - uint32_t nRanges, i; - driOptionRange *ranges; - - XSTRDUP (cp, string); - /* pass 1: determine the number of ranges (number of commas + 1) */ - range = cp; - for (nRanges = 1; *range; ++range) - if (*range == ',') - ++nRanges; - - if ((ranges = malloc(nRanges*sizeof(driOptionRange))) == NULL) { - 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; - } - free(cp); - if (i < nRanges) { - free(ranges); - return false; - } else - assert (range == NULL); - - info->nRanges = nRanges; - info->ranges = ranges; - return true; -} - -/** \brief Check if a value is in one of info->ranges. */ -static bool -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; - 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; - 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; - case DRI_STRING: - break; - default: - assert (0); /* should never happen */ - } - return false; -} - -/** - * 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; - const char *libgl_debug; - - libgl_debug=getenv("LIBGL_DEBUG"); - if (libgl_debug && !strstr(libgl_debug, "quiet")) { - fprintf(stderr, "libGL: "); - va_start(args, f); - vfprintf(stderr, f, args); - va_end(args); - fprintf(stderr, "\n"); - } -} - -/** \brief Output a warning message. */ -#define XML_WARNING1(msg) do {\ - __driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \ - (int) XML_GetCurrentLineNumber(data->parser), \ - (int) XML_GetCurrentColumnNumber(data->parser)); \ -} while (0) -#define XML_WARNING(msg,args...) do { \ - __driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \ - (int) XML_GetCurrentLineNumber(data->parser), \ - (int) XML_GetCurrentColumnNumber(data->parser), \ - args); \ -} while (0) -/** \brief Output an error message. */ -#define XML_ERROR1(msg) do { \ - __driUtilMessage ("Error in %s line %d, column %d: "msg, data->name, \ - (int) XML_GetCurrentLineNumber(data->parser), \ - (int) XML_GetCurrentColumnNumber(data->parser)); \ -} while (0) -#define XML_ERROR(msg,args...) do { \ - __driUtilMessage ("Error in %s line %d, column %d: "msg, data->name, \ - (int) XML_GetCurrentLineNumber(data->parser), \ - (int) XML_GetCurrentColumnNumber(data->parser), \ - args); \ -} 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, \ - (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), \ - args); \ - abort();\ -} while (0) - -/** \brief Parser context for __driConfigOptions. */ -struct OptInfoData { - const char *name; - XML_Parser parser; - driOptionCache *cache; - bool inDriInfo; - bool inSection; - bool inDesc; - bool inOption; - bool inEnum; - 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. - */ -static void -parseEnumAttr(struct OptInfoData *data, const XML_Char **attr) -{ - uint32_t i; - const XML_Char *value = NULL, *text = NULL; - 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 (!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); - if (!checkValue (&v, &data->cache->info[opt])) - XML_FATAL ("enum value out of valid range: %s.", value); -} - -/** \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. - */ -static void -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 (!lang) XML_FATAL1 ("lang attribute missing in description."); - if (!text) XML_FATAL1 ("text attribute missing in description."); -} - -/** \brief Parse attributes of an option element. */ -static void -parseOptInfoAttr(struct OptInfoData *data, const XML_Char **attr) -{ - 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; - 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]; - } - 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) - 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; - else if (!strcmp (attrVal[OA_TYPE], "enum")) - cache->info[opt].type = DRI_ENUM; - else if (!strcmp (attrVal[OA_TYPE], "int")) - cache->info[opt].type = DRI_INT; - else if (!strcmp (attrVal[OA_TYPE], "float")) - cache->info[opt].type = DRI_FLOAT; - else if (!strcmp (attrVal[OA_TYPE], "string")) - cache->info[opt].type = DRI_STRING; - else - 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); - } else - 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); - - 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); - } else if (cache->info[opt].type == DRI_ENUM) { - XML_FATAL1 ("valid attribute missing in option (mandatory for enums)."); - } else { - cache->info[opt].nRanges = 0; - cache->info[opt].ranges = NULL; - } -} - -/** \brief Handler for start element events. */ -static void -optInfoStartElem(void *userData, const XML_Char *name, const XML_Char **attr) -{ - struct OptInfoData *data = (struct OptInfoData *)userData; - enum OptInfoElem elem = bsearchStr (name, OptInfoElems, OI_COUNT); - switch (elem) { - case OI_DRIINFO: - if (data->inDriInfo) - XML_FATAL1 ("nested elements."); - if (attr[0]) - XML_FATAL1 ("attributes specified on element."); - data->inDriInfo = true; - break; - case OI_SECTION: - if (!data->inDriInfo) - XML_FATAL1 ("
must be inside ."); - if (data->inSection) - XML_FATAL1 ("nested
elements."); - if (attr[0]) - XML_FATAL1 ("attributes specified on
element."); - data->inSection = true; - break; - case OI_DESCRIPTION: - if (!data->inSection && !data->inOption) - XML_FATAL1 (" must be inside or inDesc) - XML_FATAL1 ("nested elements."); - data->inDesc = true; - parseDescAttr (data, attr); - break; - case OI_OPTION: - if (!data->inSection) - XML_FATAL1 ("