38#include <portability.h>
42#define PARAM_CREATE 0x01
93#define PARM_MAGIC 0x20030815
108#define PARM_HANDLE_FLAG_PRIVATE 0x01
109#define PARM_HANDLE_FLAG_PARSE_ERROR 0x02
140static char *
getFullName(
const char *sectionName,
const char *paramName);
192static char *
getFullName (
const char *sectionName,
const char *paramName)
195 unsigned long len = strlen (sectionName) + strlen (paramName) + 2;
197 fullName = (
char *) malloc(strlen (sectionName) + strlen (paramName) + 2);
199 GfError (
"getFullName: malloc (%lu) failed", len);
202 snprintf(fullName, len,
"%s/%s", sectionName, paramName);
226 GfError (
"getParamByName: getFullName failed\n");
241 GfError (
"getParamByName: addSection failed\n");
272 GfError(
"removeParamByName: getFullName failed\n");
356 const unsigned long len =
sizeof (
struct param);
358 tmpVal = strdup (
value);
366 GfError (
"addParam: calloc (1, %lu) failed\n", len);
372 GfError (
"addParam: strdup (%s) failed\n", paramName);
378 GfError (
"addParam: getFullName failed\n");
452 tmpName = strdup (sectionName);
454 GfError (
"getParent: strdup (\"%s\") failed\n", sectionName);
458 s = strrchr (tmpName,
'/');
490 const unsigned long len =
sizeof (
struct section);
493 GfError (
"addSection: duplicate section [%s]\n", sectionName);
499 GfError (
"addSection: Problem with getParent for section [%s]\n", sectionName);
505 GfError (
"addSection: calloc (1, %lu) failed\n", len);
511 GfError (
"addSection: strdup (%s) failed\n", sectionName);
516 GfError (
"addSection: GfHashAddStr failed\n");
590 const unsigned long parmheadersize =
sizeof (
struct parmHeader);
591 const unsigned long sectionsize =
sizeof (
struct section);
593 conf = (
struct parmHeader *) calloc (1, parmheadersize);
595 GfError (
"gfParmReadFile: calloc (1, %lu) failed\n", parmheadersize);
603 GfError (
"gfParmReadFile: calloc (1, %lu) failed\n", sectionsize);
612 GfError (
"gfParmReadFile: GfHashCreate (paramHash) failed\n");
618 GfError (
"gfParmReadFile: GfHashCreate (sectionHash) failed\n");
624 GfError (
"gfParmReadFile: strdup (%s) failed\n", file);
657 if (!s1 || ! strlen (s1)) {
661 curWithin = (
struct within *) calloc (1,
sizeof (
struct within));
662 curWithin->
val = strdup (s1);
667static int myStrcmp(
const void *s1,
const void * s2)
669 return strcmp((
const char *)s1, (
const char *)s2);
683 if (!str || !strlen (str)) {
687 if (strncmp (str,
"0x", 2) == 0) {
688 return (
tdble)strtol(str, NULL, 0);
691 sscanf (str,
"%g", &
val);
707 struct param *curParam;
714 const char *shortName;
732 nAtts = (
p - atts) >> 1;
734 qsort ((
void *)atts, nAtts,
sizeof(
char *) * 2,
myStrcmp);
737 if (!strcmp(
name,
"params")) {
743 GfError (
"xmlStartElement: strdup (\"\") failed\n");
750 if (!strcmp(s1,
"name")) {
752 conf->
name = strdup(s2);
754 GfError (
"xmlStartElement: strdup (\"%s\") failed\n", s2);
762 GfOut (
"xmlStartElement: Syntax error, missing \"name\" field in params definition\n");
766 }
else if (!strcmp(
name,
"section")) {
769 GfError (
"xmlStartElement: Syntax error, missing \"params\" tag\n");
778 if (!strcmp(s1,
"name")) {
785 GfError (
"xmlStartElement: Syntax error, missing \"name\" field in section definition\n");
793 GfError (
"xmlStartElement: malloc (%d) failed\n", len);
805 GfError (
"xmlStartElement: addSection failed\n");
809 }
else if (!strcmp(
name,
"attnum")) {
812 GfError (
"xmlStartElement: Syntax error, missing \"section\" tag\n");
823 if (!strcmp(s1,
"name")) {
825 }
else if (!strcmp(s1,
"val")) {
827 }
else if (!strcmp(s1,
"min")) {
829 }
else if (!strcmp(s1,
"max")) {
831 }
else if (!strcmp(s1,
"unit")) {
837 GfError (
"xmlStartElement: Syntax error, missing \"name\" field in %s definition\n",
name);
842 GfError (
"xmlStartElement: Syntax error, missing \"val\" field in %s definition\n",
name);
856 GfError (
"xmlStartElement: addParam failed\n");
880 }
else if (!strcmp(
name,
"attstr")) {
883 GfError (
"xmlStartElement: Syntax error, missing \"section\" tag\n");
894 if (!strcmp(s1,
"name")) {
896 }
else if (!strcmp(s1,
"val")) {
898 }
else if (!strcmp(s1,
"in")) {
904 GfError (
"xmlStartElement: Syntax error, missing \"name\" field in %s definition\n",
name);
909 GfError (
"xmlStartElement: Syntax error, missing \"val\" field in %s definition\n",
name);
915 GfError (
"xmlStartElement: addParam failed\n");
922 sb = strchr (sa,
',');
927 sb = strchr (sa,
',');
957 if (!strcmp(name,
"section")) {
959 GfError (
"xmlEndElement: Syntax error in \"%s\"\n", name);
999 if (systemId[0] ==
'/') {
1000 strncpy (fin, systemId,
sizeof (fin));
1006 s = strrchr (fin,
'/');
1012 strncpy (s, systemId,
sizeof (fin) - (s - fin));
1016 in = fopen (fin,
"r");
1019 GfError (
"GfReadParmFile: file %s has pb\n", systemId);
1025 size_t len = fread (buf, 1,
sizeof(buf), in);
1026 done = len <
sizeof (buf);
1028 GfError (
"file: %s -> %s at line %d\n",
1057 GfError (
"parseXml: %s at line %d\n",
1103 const unsigned long parmhandlesize =
sizeof (
struct parmHandle);
1108 GfError (
"gfParmReadBuf: conf header creation failed\n");
1115 GfError (
"gfParmReadBuf: calloc (1, %lu) failed\n", parmhandlesize);
1125 GfError (
"gfParmReadBuf: parserInit failed\n");
1131 GfError (
"gfParmReadBuf: Parse failed for buffer\n");
1181 const unsigned long parmHandleSize =
sizeof (
struct parmHandle);
1190 GfError (
"gfParmReadFile: conf header creation failed\n");
1199 GfError (
"gfParmReadFile: calloc (1, %lu) failed\n", parmHandleSize);
1211 in = fopen (file,
"r");
1213 GfOut (
"gfParmReadFile: fopen \"%s\" failed\n", file);
1220 GfError (
"gfParmReadBuf: parserInit failed for file \"%s\"\n", file);
1225 len = fread (buf, 1,
sizeof(buf), in);
1226 done = len < (int)
sizeof(buf);
1228 GfError (
"gfParmReadFile: Parse failed in file \"%s\"\n", file);
1233 GfError (
"gfParmReadFile: Parse failed in file \"%s\"\n", file);
1280 GfError(
"formatXmlBuffer: invalid buffer size\n");
1284 va_start(args, format);
1285 len = vsnprintf(buf, size, format, args);
1288 if ((len < 0) || (len >= size)) {
1290 GfError(
"formatXmlBuffer: buffer too small for XML output\n");
1310 int len = strlen(val);
1311 const char *replacement;
1316 GfError(
"handleEntities: invalid buffer size\n");
1320 for (i = 0; i < len; i++) {
1323 replacement =
"<";
break;
1325 replacement =
">";
break;
1327 replacement =
"&";
break;
1329 replacement =
"'";
break;
1331 replacement =
""";
break;
1336 if (replacement == 0) {
1337 replacement = &val[i];
1340 rlen = strlen(replacement);
1343 if (pos-buf < BUFSIZE - rlen) {
1344 memcpy(pos, replacement, rlen*
sizeof(
char));
1348 GfError(
"handleEntities: buffer too small to convert %s\n", val);
1371 if ((BUFSIZE <= 0) || (blanks < 0) || (blanks >= BUFSIZE)) {
1375 GfError(
"createIndent: buffer too small for XML indentation\n");
1379 while (pos < blanks) {
1398static int createIn(
char *buf,
const int BUFSIZE, withinHead* head)
1400 const char* s =
" in=\"";
1403 bool separator =
false;
1406 GfError(
"createIn: invalid buffer size\n");
1412 while (curWithin != 0) {
1413 int len = strlen(s);
1414 if (pos < BUFSIZE - len - 1) {
1415 memcpy(buf, s, len*
sizeof(
char));
1419 GfError(
"createIn: buffer too small for XML within attribute\n");
1425 if (curWithin != 0) {
1437 memcpy(buf,
"\"", 2*
sizeof(
char));
1461 struct param *curParam;
1463 const int BUFSIZE = 1024;
1465 const int INDENTSIZE = 1024;
1466 char indent[INDENTSIZE];
1467 const int INSIZE = 1024;
1469 const int NUMVALUE = 1024;
1470 char numvalue[NUMVALUE];
1473 switch (outCtrl->
state) {
1475 if (
formatXmlBuffer(buffer, size,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") != 0) {
1483 if (conf->
dtd == NULL) {
1484 conf->
dtd = strdup(
"params.dtd");
1486 if (conf->
header == NULL) {
1487 conf->
header = strdup(
"");
1529 || (
formatXmlBuffer(buffer, size,
"%s<section name=\"%s\">\n", indent, buf) != 0)) {
1548 || (
formatXmlBuffer(buffer, size,
"%s<attstr name=\"%s\"%s val=\"%s\"/>\n", indent, curParam->
name, in, buf) != 0)) {
1555 if (curParam->
unit) {
1557 if (
formatXmlBuffer(numvalue, NUMVALUE,
" min=\"%g\" max=\"%g\" unit=\"%s\" val=\"%g\"/>\n",
1566 if (
formatXmlBuffer(numvalue, NUMVALUE,
" unit=\"%s\" val=\"%g\"/>\n",
1575 if (
formatXmlBuffer(numvalue, NUMVALUE,
" min=\"%g\" max=\"%g\" val=\"%g\"/>\n",
1590 || (
formatXmlBuffer(buffer, size,
"%s<attnum name=\"%s\"%s", indent, curParam->
name, numvalue) != 0)) {
1611 || (
formatXmlBuffer(buffer, size,
"%s</section>\n\n", indent) != 0)) {
1626 if (curSection->
parent) {
1629 || (
formatXmlBuffer(buffer, size,
"%s</section>\n\n", indent) != 0)) {
1680 len = strlen (line);
1681 if (len > curSize) {
1684 memcpy (s, line, len);
1748 GfError (
"gfParmWriteFile: bad file name\n");
1753 fout = fopen (file,
"wb");
1755 GfError (
"gfParmSetStr: fopen (%s, \"wb\") failed\n", file);
1768 while ((status =
xmlGetOuputLine (handle, line,
sizeof (line))) > 0) {
1776 GfOut (
"GfParmWriteFile: %s file written\n", file);
1806 GfError (
"GfParmCreateDirectory: bad file name\n");
1834 conf = handle->
conf;
1875 conf = handle->
conf;
1901 GfOut (
"parmReleaseHeader: refcount null free \"%s\"\n", conf->
filename);
1992 if (strcmp(unit,
"m") == 0)
return;
1993 if (strcmp(unit,
"kg") == 0)
return;
1994 if (strcmp(unit,
"s") == 0)
return;
1995 if (strcmp(unit,
"rad") == 0)
return;
1996 if (strcmp(unit,
"Pa") == 0)
return;
1998 if ((strcmp(unit,
"feet") == 0) || (strcmp(unit,
"ft") == 0)) {
2000 }
else if (strcmp(unit,
"deg") == 0) {
2001 coeff = (float) (M_PI/180.0);
2002 }
else if ((strcmp(unit,
"h") == 0) || (strcmp(unit,
"hour") == 0) || (strcmp(unit,
"hours") == 0)) {
2004 }
else if ((strcmp(unit,
"day") == 0) || (strcmp(unit,
"days") == 0)) {
2006 }
else if (strcmp(unit,
"km") == 0) {
2008 }
else if (strcmp(unit,
"mm") == 0) {
2010 }
else if (strcmp(unit,
"cm") == 0) {
2012 }
else if ((strcmp(unit,
"in") == 0) || (strcmp(unit,
"inch") == 0) || (strcmp(unit,
"inches") == 0)) {
2014 }
else if ((strcmp(unit,
"lbs") == 0) || (strcmp(unit,
"lb") == 0)) {
2015 coeff = 0.45359237f;
2016 }
else if (strcmp(unit,
"lbf") == 0) {
2017 coeff = 0.45359237f*
G;
2018 }
else if ((strcmp(unit,
"slug") == 0) || (strcmp(unit,
"slugs") == 0)) {
2019 coeff = 14.59484546f;
2020 }
else if (strcmp(unit,
"kPa") == 0) {
2022 }
else if (strcmp(unit,
"MPa") == 0) {
2024 }
else if ((strcmp(unit,
"PSI") == 0) || (strcmp(unit,
"psi") == 0)){
2026 }
else if ((strcmp(unit,
"rpm") == 0) || (strcmp(unit,
"RPM") == 0)) {
2027 coeff = 0.104719755f;
2028 }
else if ((strcmp(unit,
"percent") == 0) || (strcmp(unit,
"%") == 0)) {
2030 }
else if ((strcmp(unit,
"mph") == 0) || (strcmp(unit,
"MPH") == 0)) {
2087 if ((unit == NULL) || (strlen(unit) == 0))
return dest;
2141 if ((unit == NULL) || (strlen(unit) == 0))
return dest;
2376 GfOut (
"GfParmListClean: \"%s\" not found\n", path);
2496const char*
GfParmGetCurStr(
void *handle,
const char *path,
const char *key,
const char *deflt)
2623int GfParmSetStr(
void *handle,
const char *path,
const char *key,
const char *val)
2634 if (!val || !strlen (val)) {
2650 GfError (
"gfParmSetStr: strdup (%s) failed\n", val);
2699 if (!val || !strlen (val)) {
2714 GfError (
"gfParmSetStr: strdup (%s) failed\n", val);
2891 struct section *curSectionRef;
2892 struct section *nextSectionRef;
2893 struct param *curParamRef;
2894 struct param *curParam;
2895 struct within *curWithinRef;
2906 while (curSectionRef) {
2908 while (curParamRef) {
2912 if (curParamRef->
type != curParam->
type) {
2913 GfError(
"GfParmCheckHandle: type mismatch for parameter \"%s\" in (\"%s\" - \"%s\")\n",
2916 }
else if (curParamRef->
type ==
P_NUM) {
2917 if ((curParam->
valnum < curParamRef->
min) || (curParam->
valnum > curParamRef->
max)) {
2918 GfError(
"GfParmCheckHandle: parameter \"%s\" out of bounds: min:%g max:%g val:%g in (\"%s\" - \"%s\")\n",
2924 while (!found && curWithinRef) {
2925 if (!strcmp (curWithinRef->
val, curParam->
value)) {
2931 if (!found && strcmp (curParamRef->
value, curParam->
value)) {
2932 GfError(
"GfParmCheckHandle: parameter \"%s\" value:\"%s\" not allowed in (\"%s\" - \"%s\")\n",
2940 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
2941 while (!nextSectionRef) {
2942 nextSectionRef = curSectionRef->
parent;
2943 if (!nextSectionRef) {
2947 curSectionRef = nextSectionRef;
2948 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
2950 curSectionRef = nextSectionRef;
2974 struct param *paramNew;
2975 struct within *withinRef;
2993 num = paramRef->
min;
2997 paramNew->
min = num;
3000 num = paramRef->
max;
3004 paramNew->
max = num;
3007 if (num < paramNew->
min) {
3008 num = paramNew->
min;
3011 if (num > paramNew->
max) {
3012 num = paramNew->
max;
3043 str = paramRef->
value;
3046 paramNew->
value = strdup (str);
3066 struct param *paramNew;
3137 struct section *curSectionRef;
3138 struct section *nextSectionRef;
3139 struct section *curSectionTgt;
3140 struct section *nextSectionTgt;
3141 struct param *curParamRef;
3142 struct param *curParamTgt;
3143 const unsigned long parmHandleSize =
sizeof (
struct parmHandle);
3148 GfFatal (
"GfParmMergeHandles: bad handle (%p)\n", parmHandleRef);
3152 GfFatal (
"GfParmMergeHandles: bad handle (%p)\n", parmHandleTgt);
3159 GfError (
"gfParmReadBuf: conf header creation failed\n");
3164 parmHandleOut = (
struct parmHandle *) calloc (1, parmHandleSize);
3165 if (!parmHandleOut) {
3166 GfError (
"gfParmReadBuf: calloc (1, %lu) failed\n", parmHandleSize);
3172 parmHandleOut->
conf = confOut;
3178 while (curSectionRef) {
3180 while (curParamRef) {
3191 if (nextSectionRef) {
3192 curSectionRef = nextSectionRef;
3194 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
3195 while (!nextSectionRef) {
3196 nextSectionRef = curSectionRef->
parent;
3197 if (!nextSectionRef) {
3201 curSectionRef = nextSectionRef;
3202 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
3204 curSectionRef = nextSectionRef;
3212 while (curSectionTgt) {
3214 while (curParamTgt) {
3226 if (nextSectionTgt) {
3227 curSectionTgt = nextSectionTgt;
3229 nextSectionTgt =
GF_TAILQ_NEXT (curSectionTgt, linkSection);
3230 while (!nextSectionTgt) {
3231 nextSectionTgt = curSectionTgt->
parent;
3232 if (!nextSectionTgt) {
3236 curSectionTgt = nextSectionTgt;
3237 nextSectionTgt =
GF_TAILQ_NEXT (curSectionTgt, linkSection);
3239 curSectionTgt = nextSectionTgt;
3254 return (
void*)parmHandleOut;
Scalar min(Scalar x, Scalar y)
Scalar max(Scalar x, Scalar y)
void GfParmShutdown(void)
Parameter set library API shutdown, removes parameter set handle cache.
void GfParmInit(void)
Parameter set library API initialization, set up parameter set handle cache.
float tdble
Floating point type used in TORCS.
const void * GfHashRemStr(void *hash, char *key)
Remove an element with a string key from a hash table.
void GfHashRelease(void *hash, tfHashFree hashFree)
Release a hash table.
int GfHashAddStr(void *hash, const char *key, const void *data)
Add an element with a string key to a hash table.
const void * GfHashGetStr(void *hash, const char *key)
Get the user data associated with a string key.
void * GfHashCreate(int type)
Create a new hash table.
int GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max)
Set a numerical parameter and its bounds, creating it if necessary.
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
tdble GfParmUnit2SI(const char *unit, tdble val)
Convert a value given in unit to SI.
char * GfParmGetName(void *handle)
Get the name property of the parameter set handle.
tdble GfParmSI2Unit(const char *unit, tdble val)
Convert a value from SI to given unit.
int GfParmGetNumBoundaries(void *handle, const char *path, const char *key, tdble *min, tdble *max)
Get the min and max of a numerical parameter from the parameter set handle.
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
void GfParmRemove(void *parmHandle, char *sectionName, char *paramName)
Remove a parameter from a parameter set.
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
int GfParmCreateDirectory(const char *file, void *parmHandle)
Create directory for parameter set handle if it does not yet exist.
char * GfParmGetFileName(void *handle)
Get the filename property of the parameter set handle.
void GfParmClean(void *parmHandle)
Clean all the parameters of a parameter set.
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
int GfParmWriteBuf(void *handle, char *buf, int size)
Write a parameter set into a memory buffer.
int GfParmCheckHandle(void *ref, void *tgt)
Check the values in the parameter set tgt against the min/max/within definitions in the ref parameter...
void * GfParmMergeHandles(void *ref, void *tgt, int mode)
Merge two parameter sets into a new private set.
void GfParmSetDTD(void *parmHandle, char *dtd, char *header)
Set the dtd path and header.
void * GfParmReadBuf(char *buffer)
Read parameter set from memory buffer and return handle to parameter set.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
static struct parmHeader * getSharedHeader(const char *file, int mode)
Helper function for looking up parameter sets in the cache.
static void removeParamByName(struct parmHeader *conf, const char *sectionName, const char *paramName)
Helper function to remove a parameter with given name paramName.
static int handleEntities(char *buf, const int BUFSIZE, const char *val)
Helper function to convert the input line given in val into proper XML notation, the output goes into...
static void parmReleaseHeader(struct parmHeader *conf)
Helper function to release the parameter set if the reference counter is 0.
static int createIndent(char *buf, const int BUFSIZE, const int blanks)
Helper function for indentation in the XML.
static tdble getValNumFromStr(const char *str)
Helper function to parse number.
static void addWithin(struct param *curParam, char *s1)
Helper function to add "within" options to parameter curParam.
static int xmlGetOuputLine(struct parmHandle *parmHandle, char *buffer, int size)
Helper function to output one line of XML generated from the given parameter set.
static void xmlStartElement(void *userData, const char *name, const char **atts)
Helper function to process opening XML elements.
static void xmlEndElement(void *userData, const XML_Char *name)
Helper function to process closing XML elements.
static struct section * addSection(struct parmHeader *conf, const char *sectionName)
Helper function to add a section to a parameter set.
static void cleanUnusedSection(struct parmHeader *conf, struct section *section)
Helper function to clean up unused (empty) sections starting with given section.
static struct section * getParent(struct parmHeader *conf, const char *sectionName)
Helper function to get (or create if not found) parent section of section given in sectionName.
static void insertParam(struct parmHandle *parmHandle, char *path, struct param *param)
Helper function to insert a parameter into a parameter set.
static void removeParam(struct parmHeader *conf, struct section *section, struct param *param)
Helper function to remove given parameter.
static void evalUnit(char *unit, tdble *dest, int flg)
Support function to multiply or divide dest with unit conversion factor.
static struct parmHeader * createParmHeader(const char *file)
Helper function to create header for parameter set handle.
static int formatXmlBuffer(char *buf, const int size, const char *format,...)
Helper function to format text without truncating the output.
static void parmClean(struct parmHeader *conf)
Helper function to release the parameter set content.
static int xmlExternalEntityRefHandler(XML_Parser mainparser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
Helper function to handle external XML entities (XML referencing over multiple files/URI's).
static void removeSection(struct parmHeader *conf, struct section *section)
Helper function to remove a section and its contents (subsections, elements).
static int parserXmlInit(struct parmHandle *parmHandle)
Helper function to set up XML parser in parmHandle.
static int createIn(char *buf, const int BUFSIZE, withinHead *head)
Helper function to support the serialization into the XML of the "within" attribute.
static struct param * getParamByName(struct parmHeader *conf, const char *sectionName, const char *paramName, int flag)
Helper function to get (or create) a parameter by name.
static void parmReleaseHandle(struct parmHandle *parmHandle)
Helper function to release the handle and eventually the referenced parameter set (if the reference c...
static void insertParamMerge(struct parmHandle *parmHandle, char *path, struct param *paramRef, struct param *param)
Helper function to merge a parameter into a parameter set.
static char * getFullName(const char *sectionName, const char *paramName)
Helper function to get the full name of a parameter (full name: "sectionName/paramName").
static struct param * addParam(struct parmHeader *conf, struct section *section, const char *paramName, const char *value)
Helper function to add parameter, does not check for duplicated name.
static int parseXml(struct parmHandle *parmHandle, char *buf, int len, int done)
Helper function to parse one line of XML.
char * GfParmListGetCurEltName(void *handle, const char *path)
Get current subsection name of the parameter set handle during subsection iteration.
int GfParmListSeekNext(void *handle, const char *path)
Advance to the next immediate subsection.
int GfParmListClean(void *handle, const char *path)
Remove all the subsections in a section in the parameter set handle.
int GfParmListSeekFirst(void *handle, const char *path)
Select the first immediate subsection of a section.
int GfParmGetEltNb(void *handle, const char *path)
Count the number of subsections in a section in the parameter set handle.
int GfParmSetCurNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle based on subsection iteration.
int GfParmSetCurStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle based on subsection iteration.
tdble GfParmGetCurNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle based on subsection iteration.
const char * GfParmGetCurStr(void *handle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle based on subsection iteration.
#define GF_TAILQ_INSERT_TAIL(head, elm, field)
Insert an element at the tail.
#define GF_TAILQ_INIT(head)
Head initialization (Mandatory)
#define GF_TAILQ_HEAD(name, type)
Head type definition.
#define GF_TAILQ_END(head)
End of a TAILQ.
#define GF_TAILQ_NEXT(elm, field)
Next element of a TAILQ.
#define GF_TAILQ_REMOVE(head, elm, field)
Remove an element.
#define GF_TAILQ_FIRST(head)
First element of a TAILQ.
#define GF_TAILQ_INSERT_HEAD(head, elm, field)
Insert an element at the head.
#define PARM_HANDLE_FLAG_PRIVATE
#define PARM_HANDLE_FLAG_PARSE_ERROR
static struct parmHead parmHandleList
static int myStrcmp(const void *s1, const void *s2)
Parameter header structure, a parameter can either carry a numeric or a string value,...
tdble min
Minimum for numeric value.
char * unit
Unit, see GfParmUnit2SI for supported units.
int type
Type, either P_NUM or P_STR.
tdble max
Maximum for numeric value.
tdble valnum
Numeric value of the parameter.
char * fullName
Name of the parameter including the full section name ('/' separated)
GF_TAILQ_ENTRY(struct param) linkParam
Next parameter in the same section.
char * name
Name of the parameter.
char * value
String value of the parameter.
struct withinHead withinList
Linked list containing the options for legal string values.
Parameter set handle structure, multiple handles can reference the same parameter set.
GF_TAILQ_ENTRY(struct parmHandle) linkHandle
Next configuration handle.
int magic
Magic number (to detect wrong type casts and such)
struct section * curSection
Current section, for iterations, see GfParmListSeekFirst and GfParmListSeekNext.
struct parmHeader * conf
Header of the parameter set.
struct parmOutput outCtrl
Ouput control structure used for serializing parameter set into XML.
int flag
Flag (PARM_HANDLE_FLAG_PARSE_ERROR, PARM_HANDLE_FLAG_PRIVATE)
Ouput control structure used for serializing parameter set into XML.
int indent
Keep track of indentation.
struct param * curParam
Current parameter.
struct section * curSection
Current section.
char * filename
Name of the output file.
Section header structure.
struct section * parent
Parent section.
struct paramHead paramList
List of the parameters in this section.
struct section * curSubSection
Current subsection, for iterations, see GfParmListSeekFirst and GfParmListSeekNext.
char * fullName
Name of the section including full path ('/' separated)
struct sectionHead subSectionList
List of sub-sections (linked by linkSection)
GF_TAILQ_ENTRY(struct section) linkSection
Next section at the same level.
Structure to hold linked list of within options.
char * val
Value of within option.
GF_TAILQ_ENTRY(struct within) linkWithin
Link to next entry.
int GfCreateDirForFile(const char *filenameandpath)
Create directory for given file path recursively, so all missing parent directories are created as we...
The Gaming Framework API.
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
#define GFPARM_MMODE_RELSRC
release ref after the merge
#define GFPARM_MMODE_RELDST
release tgt after the merge
#define GFPARM_MMODE_SRC
Include ref attributes; merge common attributes using ref restrictions and tgt values.
#define GFPARM_RMODE_REREAD
Clear shared cached data and reread the file.
#define GF_HASH_TYPE_STR
String key based hash table.
static void GfFatal(const char *fmt,...)
#define GFPARM_MMODE_DST
Include tgt attributes; merge common attributes using ref restrictions and tgt values.
#define GFPARM_RMODE_PRIVATE
Private means the handle is not shared/cached.
void XMLPARSEAPI XML_SetExternalEntityRefHandler(XML_Parser parser, XML_ExternalEntityRefHandler handler)
enum XML_Error XMLPARSEAPI XML_GetErrorCode(XML_Parser parser)
void XMLPARSEAPI XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
#define XML_GetUserData(parser)
int XMLPARSEAPI XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
XML_Parser XMLPARSEAPI XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *encoding)
void XMLPARSEAPI XML_SetUserData(XML_Parser parser, void *userData)
const XML_LChar XMLPARSEAPI * XML_ErrorString(int code)
void XMLPARSEAPI XML_ParserFree(XML_Parser parser)
XML_Parser XMLPARSEAPI XML_ParserCreate(const XML_Char *encoding)
int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser)