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)
v->_float <= info->ranges[i].end._float)
return true;
break;
+ case DRI_STRING:
+ break;
default:
assert (0); /* should never happen */
}
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]);
/** \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));
}
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 */
}
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);
}
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;
+}
#include <stdbool.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 */
bool _bool; /**< \brief Boolean */
int _int; /**< \brief Integer or Enum */
float _float; /**< \brief Floating-point */
+ char *_string; /**< \brief String */
} driOptionValue;
/** \brief Single range of valid values
int driQueryOptioni (const driOptionCache *cache, const char *name);
/** \brief Query a floating-point option value */
float driQueryOptionf (const driOptionCache *cache, const char *name);
+/** \brief Query a string option value */
+char *driQueryOptionstr (const driOptionCache *cache, const char *name);
#endif