From c83400e6736152439e1ed1e45cbad78e85ca8827 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sun, 21 Feb 2021 13:41:30 -0800 Subject: [PATCH] xmlconfig: Reshuffle to keep attr processing For the static-table alternative to WITH_XMLCONFIG, we are going to want to re-use the element attribute processing, to avoid duplicating things like engine name regexp matching and version range matching. This just shuffles things around a bit so we can re-use useful parts in the next patch. Signed-off-by: Rob Clark Reviewed-by: Alyssa Rosenzweig Part-of: --- src/util/xmlconfig.c | 74 +++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c index bf469f2..df3119c 100644 --- a/src/util/xmlconfig.c +++ b/src/util/xmlconfig.c @@ -42,8 +42,8 @@ #include #include #include -#include #endif +#include #include #include #include "strndup.h" @@ -520,8 +520,6 @@ driGetOptionsXml(const driOptionDescription *configOptions, unsigned numOptions) return output; } -#if WITH_XMLCONFIG - /** * Print message to \c stderr if the \c LIBGL_DEBUG environment variable * is set. @@ -546,6 +544,12 @@ __driUtilMessage(const char *f, ...) } } +/* We don't have real line/column # info in static-config case: */ +#if !WITH_XML_CONFIG +# define XML_GetCurrentLineNumber(p) -1 +# define XML_GetCurrentColumnNumber(p) -1 +#endif + /** \brief Output a warning message. */ #define XML_WARNING1(msg) do { \ __driUtilMessage("Warning in %s line %d, column %d: "msg, data->name, \ @@ -574,7 +578,9 @@ __driUtilMessage(const char *f, ...) /** \brief Parser context for configuration files. */ struct OptConfData { const char *name; +#if WITH_XMLCONFIG XML_Parser parser; +#endif driOptionCache *cache; int screenNum; const char *driverName, *execName; @@ -591,33 +597,6 @@ struct OptConfData { uint32_t inOption; }; -/** \brief Elements in configuration files. */ -enum OptConfElem { - OC_APPLICATION = 0, OC_DEVICE, OC_DRICONF, OC_ENGINE, OC_OPTION, OC_COUNT -}; -static const char *OptConfElems[] = { - [OC_APPLICATION] = "application", - [OC_DEVICE] = "device", - [OC_DRICONF] = "driconf", - [OC_ENGINE] = "engine", - [OC_OPTION] = "option", -}; - -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 char *name, const char *elems[], uint32_t count) -{ - const char **found; - found = bsearch(&name, elems, count, sizeof(char *), compare); - if (found) - return found - elems; - else - return count; -} - /** \brief Parse a list of ranges of type info->type. */ static unsigned char parseRange(driOptionInfo *info, const char *string) @@ -820,6 +799,35 @@ parseOptConfAttr(struct OptConfData *data, const char **attr) } } +#if WITH_XMLCONFIG + +/** \brief Elements in configuration files. */ +enum OptConfElem { + OC_APPLICATION = 0, OC_DEVICE, OC_DRICONF, OC_ENGINE, OC_OPTION, OC_COUNT +}; +static const char *OptConfElems[] = { + [OC_APPLICATION] = "application", + [OC_DEVICE] = "device", + [OC_DRICONF] = "driconf", + [OC_ENGINE] = "engine", + [OC_OPTION] = "option", +}; + +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 char *name, const char *elems[], uint32_t count) +{ + const char **found; + found = bsearch(&name, elems, count, sizeof(char *), compare); + if (found) + return found - elems; + else + return count; +} + /** \brief Handler for start element events. */ static void optConfStartElem(void *userData, const char *name, @@ -1061,9 +1069,6 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, const char *engineName, uint32_t engineVersion) { initOptionCache(cache, info); - -#if WITH_XMLCONFIG - char *home; struct OptConfData userData; userData.cache = cache; @@ -1076,6 +1081,9 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, userData.engineVersion = engineVersion; userData.execName = execname ?: util_get_process_name(); +#if WITH_XMLCONFIG + char *home; + parseConfigDir(&userData, datadir); parseOneConfigFile(&userData, SYSCONFDIR "/drirc"); -- 2.7.4