[Mesa-dev] [PATCH 05/11] drirc: Add string support

Axel Davy axel.davy at ens.fr
Tue May 27 17:55:10 PDT 2014


Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
 src/mesa/drivers/dri/common/xmlconfig.c | 29 +++++++++++++++++++++++++++++
 src/mesa/drivers/dri/common/xmlconfig.h |  7 ++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c
index b95e452..d41d2b2 100644
--- a/src/mesa/drivers/dri/common/xmlconfig.c
+++ b/src/mesa/drivers/dri/common/xmlconfig.c
@@ -311,6 +311,11 @@ static GLboolean parseValue (driOptionValue *v, driOptionType type,
       case DRI_FLOAT:
 	v->_float = strToF (string, &tail);
 	break;
+      case DRI_STRING:
+	if (v->_string)
+	    free (v->_string);
+	v->_string = strndup(string, STRING_CONF_MAXLEN);
+	return GL_TRUE;
     }
 
     if (tail == string)
@@ -404,6 +409,8 @@ static GLboolean checkValue (const driOptionValue *v, const driOptionInfo *info)
 		v->_float <= info->ranges[i].end._float)
 		return GL_TRUE;
 	break;
+      case DRI_STRING:
+	break;
       default:
 	assert (0); /* should never happen */
     }
@@ -567,6 +574,8 @@ static void parseOptInfoAttr (struct OptInfoData *data, const XML_Char **attr) {
 	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]);
 
@@ -867,6 +876,7 @@ static void optConfEndElem (void *userData, const XML_Char *name) {
 
 /** \brief Initialize an option cache based on info */
 static void initOptionCache (driOptionCache *cache, const driOptionCache *info) {
+    GLuint i, size = 1 << info->tableSize;
     cache->info = info->info;
     cache->tableSize = info->tableSize;
     cache->values = malloc((1<<info->tableSize) * sizeof (driOptionValue));
@@ -876,6 +886,10 @@ static void initOptionCache (driOptionCache *cache, const driOptionCache *info)
     }
     memcpy (cache->values, info->values,
 	    (1<<info->tableSize) * sizeof (driOptionValue));
+    for (i = 0; i < size; ++i) {
+	if (cache->info[i].type == DRI_STRING)
+	    XSTRDUP(cache->values[i]._string, info->values[i]._string);
+    }
 }
 
 /** \brief Parse the named configuration file */
@@ -981,6 +995,13 @@ void driDestroyOptionInfo (driOptionCache *info) {
 }
 
 void driDestroyOptionCache (driOptionCache *cache) {
+    if (cache->info) {
+	GLuint i, size = 1 << cache->tableSize;
+	for (i = 0; i < size; ++i) {
+	    if (cache->info[i].type == DRI_STRING)
+		free(cache->values[i]._string);
+	}
+    }
     free(cache->values);
 }
 
@@ -1013,3 +1034,11 @@ GLfloat driQueryOptionf (const driOptionCache *cache, const char *name) {
     assert (cache->info[i].type == DRI_FLOAT);
     return cache->values[i]._float;
 }
+
+char *driQueryOptionstr (const driOptionCache *cache, const char *name) {
+    GLuint i = findOption (cache, name);
+  /* 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;
+}
diff --git a/src/mesa/drivers/dri/common/xmlconfig.h b/src/mesa/drivers/dri/common/xmlconfig.h
index d0ad42c..786caae 100644
--- a/src/mesa/drivers/dri/common/xmlconfig.h
+++ b/src/mesa/drivers/dri/common/xmlconfig.h
@@ -30,9 +30,11 @@
 #ifndef __XMLCONFIG_H
 #define __XMLCONFIG_H
 
+#define STRING_CONF_MAXLEN 25
+
 /** \brief Option data types */
 typedef enum driOptionType {
-    DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT
+    DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT, DRI_STRING
 } driOptionType;
 
 /** \brief Option value */
@@ -40,6 +42,7 @@ typedef union driOptionValue {
     GLboolean _bool; /**< \brief Boolean */
     GLint _int;      /**< \brief Integer or Enum */
     GLfloat _float;  /**< \brief Floating-point */
+    char *_string;   /**< \brief String */
 } driOptionValue;
 
 /** \brief Single range of valid values
@@ -118,5 +121,7 @@ GLboolean driQueryOptionb (const driOptionCache *cache, const char *name);
 GLint driQueryOptioni (const driOptionCache *cache, const char *name);
 /** \brief Query a floating-point option value */
 GLfloat driQueryOptionf (const driOptionCache *cache, const char *name);
+/** \brief Query a string option value */
+char *driQueryOptionstr (const driOptionCache *cache, const char *name);
 
 #endif
-- 
1.9.1



More information about the mesa-dev mailing list