X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmesa%2Fdrivers%2Fdri%2Fcommon%2Fxmlconfig.c;h=72483a42a5cae21b5f0bffb85fc76e12a8576a47;hb=1b77d2133c41c4eb475b81967a3e4d39196c7fe1;hp=f6ae75520c508b51e195adc644daadecd32a19cd;hpb=a8d1521f30766b6a4707aa9966e1f2f9c0b3ac00;p=mesa.git diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c index f6ae75520c5..72483a42a5c 100644 --- a/src/mesa/drivers/dri/common/xmlconfig.c +++ b/src/mesa/drivers/dri/common/xmlconfig.c @@ -27,7 +27,7 @@ * \author Felix Kuehling */ -#include "glheader.h" +#include "main/glheader.h" #include #include @@ -35,17 +35,10 @@ #include #include #include -#include "imports.h" -#include "dri_util.h" +#include "main/imports.h" +#include "utils.h" #include "xmlconfig.h" -/* - * OS dependent ways of getting the name of the running program - */ -#if (defined(__unix__) || defined(unix)) && !defined(USG) -#include -#endif - #undef GET_PROGRAM_NAME #if (defined(__GNU_LIBRARY__) || defined(__GLIBC__)) && !defined(__UCLIBC__) @@ -63,16 +56,37 @@ extern char *program_invocation_name, *program_invocation_short_name; #elif defined(__NetBSD__) && defined(__NetBSD_Version) && (__NetBSD_Version >= 106000100) # 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 -# define GET_PROGRAM_NAME() basename(getexecname()) + +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__) +# 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. */ @@ -128,10 +142,10 @@ static GLuint countOptions (const driOptionCache *cache) { return count; } -/** \brief Like strdup but using MALLOC and with error checking. */ +/** \brief Like strdup but using malloc and with error checking. */ #define XSTRDUP(dest,source) do { \ GLuint len = strlen (source); \ - if (!(dest = MALLOC (len+1))) { \ + if (!(dest = malloc(len+1))) { \ fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); \ abort(); \ } \ @@ -213,7 +227,7 @@ static GLint strToI (const XML_Char *string, const XML_Char **tail, int base) { * * Works similar to strtod. Leading space is NOT skipped. The input * number may have an optional sign. '.' is interpreted as decimal - * point and may occor at most once. Optionally the number may end in + * 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 @@ -333,7 +347,7 @@ static GLboolean parseRanges (driOptionInfo *info, const XML_Char *string) { if (*range == ',') ++nRanges; - if ((ranges = MALLOC (nRanges*sizeof(driOptionRange))) == NULL) { + if ((ranges = malloc(nRanges*sizeof(driOptionRange))) == NULL) { fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); abort(); } @@ -368,9 +382,9 @@ static GLboolean parseRanges (driOptionInfo *info, const XML_Char *string) { else range = NULL; } - FREE (cp); + free(cp); if (i < nRanges) { - FREE (ranges); + free(ranges); return GL_FALSE; } else assert (range == NULL); @@ -406,6 +420,28 @@ static GLboolean checkValue (const driOptionValue *v, const driOptionInfo *info) return GL_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; + + if (getenv("LIBGL_DEBUG")) { + 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, \ @@ -553,7 +589,7 @@ static void parseOptInfoAttr (struct OptInfoData *data, const XML_Char **attr) { } else defaultVal = attrVal[OA_DEFAULT]; if (!parseValue (&cache->values[opt], cache->info[opt].type, defaultVal)) - XML_FATAL ("illegal default value: %s.", 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) @@ -666,8 +702,8 @@ void driParseOptionInfo (driOptionCache *info, GLuint size, log2size; for (size = 1, log2size = 0; size < minSize; size <<= 1, ++log2size); info->tableSize = log2size; - info->info = CALLOC (size * sizeof (driOptionInfo)); - info->values = CALLOC (size * sizeof (driOptionValue)); + info->info = calloc(size, sizeof (driOptionInfo)); + info->values = calloc(size, sizeof (driOptionValue)); if (info->info == NULL || info->values == NULL) { fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); abort(); @@ -735,7 +771,7 @@ static void parseDeviceAttr (struct OptConfData *data, const XML_Char **attr) { 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("unkown device attribute: %s.", attr[i]); + else XML_WARNING("unknown device attribute: %s.", attr[i]); } if (driver && strcmp (driver, data->driverName)) data->ignoringDevice = data->inDevice; @@ -751,11 +787,11 @@ static void parseDeviceAttr (struct OptConfData *data, const XML_Char **attr) { /** \brief Parse attributes of an application element. */ static void parseAppAttr (struct OptConfData *data, const XML_Char **attr) { GLuint i; - const XML_Char *name = NULL, *exec = NULL; + const XML_Char *exec = NULL; for (i = 0; attr[i]; i += 2) { - if (!strcmp (attr[i], "name")) name = attr[i+1]; + if (!strcmp (attr[i], "name")) /* not needed here */; else if (!strcmp (attr[i], "executable")) exec = attr[i+1]; - else XML_WARNING("unkown application attribute: %s.", attr[i]); + else XML_WARNING("unknown application attribute: %s.", attr[i]); } if (exec && strcmp (exec, data->execName)) data->ignoringApp = data->inApp; @@ -768,7 +804,7 @@ static void parseOptConfAttr (struct OptConfData *data, const XML_Char **attr) { 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("unkown option attribute: %s.", attr[i]); + 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."); @@ -859,7 +895,7 @@ static void optConfEndElem (void *userData, const XML_Char *name) { static void initOptionCache (driOptionCache *cache, const driOptionCache *info) { cache->info = info->info; cache->tableSize = info->tableSize; - cache->values = MALLOC ((1<tableSize) * sizeof (driOptionValue)); + cache->values = malloc((1<tableSize) * sizeof (driOptionValue)); if (cache->values == NULL) { fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); abort(); @@ -923,7 +959,7 @@ void driParseConfigFiles (driOptionCache *cache, const driOptionCache *info, if ((home = getenv ("HOME"))) { GLuint len = strlen (home); - filenames[1] = MALLOC (len + 7+1); + filenames[1] = malloc(len + 7+1); if (filenames[1] == NULL) __driUtilMessage ("Can't allocate memory for %s/.drirc.", home); else { @@ -953,8 +989,7 @@ void driParseConfigFiles (driOptionCache *cache, const driOptionCache *info, XML_ParserFree (p); } - if (filenames[1]) - FREE (filenames[1]); + free(filenames[1]); } void driDestroyOptionInfo (driOptionCache *info) { @@ -963,18 +998,16 @@ void driDestroyOptionInfo (driOptionCache *info) { GLuint i, size = 1 << info->tableSize; for (i = 0; i < size; ++i) { if (info->info[i].name) { - FREE (info->info[i].name); - if (info->info[i].ranges) - FREE (info->info[i].ranges); + free(info->info[i].name); + free(info->info[i].ranges); } } - FREE (info->info); + free(info->info); } } void driDestroyOptionCache (driOptionCache *cache) { - if (cache->values) - FREE (cache->values); + free(cache->values); } GLboolean driCheckOption (const driOptionCache *cache, const char *name,