43 #define PARAM_CREATE 0x01 94 #define PARM_MAGIC 0x20030815 109 #define PARM_HANDLE_FLAG_PRIVATE 0x01 110 #define PARM_HANDLE_FLAG_PARSE_ERROR 0x02 141 static char *
getFullName(
const char *sectionName,
const char *paramName);
187 static char *
getFullName (
const char *sectionName,
const char *paramName)
190 unsigned long len = strlen (sectionName) + strlen (paramName) + 2;
192 fullName = (
char *) malloc(strlen (sectionName) + strlen (paramName) + 2);
194 GfError (
"getFullName: malloc (%lu) failed", len);
197 snprintf(fullName, len,
"%s/%s", sectionName, paramName);
221 GfError (
"getParamByName: getFullName failed\n");
236 GfError (
"getParamByName: addSection failed\n");
267 GfError(
"removeParamByName: getFullName failed\n");
351 const unsigned long len =
sizeof (
struct param);
353 tmpVal = strdup (
value);
361 GfError (
"addParam: calloc (1, %lu) failed\n", len);
367 GfError (
"addParam: strdup (%s) failed\n", paramName);
373 GfError (
"addParam: getFullName failed\n");
447 tmpName = strdup (sectionName);
449 GfError (
"getParent: strdup (\"%s\") failed\n", sectionName);
453 s = strrchr (tmpName,
'/');
485 const unsigned long len =
sizeof (
struct section);
488 GfError (
"addSection: duplicate section [%s]\n", sectionName);
494 GfError (
"addSection: Problem with getParent for section [%s]\n", sectionName);
500 GfError (
"addSection: calloc (1, %lu) failed\n", len);
506 GfError (
"addSection: strdup (%s) failed\n", sectionName);
511 GfError (
"addSection: GfHashAddStr failed\n");
585 const unsigned long parmheadersize =
sizeof (
struct parmHeader);
586 const unsigned long sectionsize =
sizeof (
struct section);
588 conf = (
struct parmHeader *) calloc (1, parmheadersize);
590 GfError (
"gfParmReadFile: calloc (1, %lu) failed\n", parmheadersize);
598 GfError (
"gfParmReadFile: calloc (1, %lu) failed\n", sectionsize);
607 GfError (
"gfParmReadFile: GfHashCreate (paramHash) failed\n");
613 GfError (
"gfParmReadFile: GfHashCreate (sectionHash) failed\n");
619 GfError (
"gfParmReadFile: strdup (%s) failed\n", file);
652 if (!s1 || ! strlen (s1)) {
656 curWithin = (
struct within *) calloc (1,
sizeof (
struct within));
657 curWithin->
val = strdup (s1);
662 static int myStrcmp(
const void *s1,
const void * s2)
664 return strcmp((
const char *)s1, (
const char *)s2);
678 if (!str || !strlen (str)) {
682 if (strncmp (str,
"0x", 2) == 0) {
683 return (
tdble)strtol(str, NULL, 0);
686 sscanf (str,
"%g", &
val);
702 struct param *curParam;
709 const char *shortName;
727 nAtts = (
p - atts) >> 1;
729 qsort ((
void *)atts, nAtts,
sizeof(
char *) * 2,
myStrcmp);
732 if (!strcmp(
name,
"params")) {
738 GfError (
"xmlStartElement: strdup (\"\") failed\n");
745 if (!strcmp(s1,
"name")) {
747 conf->
name = strdup(s2);
749 GfError (
"xmlStartElement: strdup (\"%s\") failed\n", s2);
757 GfOut (
"xmlStartElement: Syntax error, missing \"name\" field in params definition\n");
761 }
else if (!strcmp(
name,
"section")) {
764 GfError (
"xmlStartElement: Syntax error, missing \"params\" tag\n");
773 if (!strcmp(s1,
"name")) {
780 GfError (
"xmlStartElement: Syntax error, missing \"name\" field in section definition\n");
788 GfError (
"xmlStartElement: malloc (%d) failed\n", len);
800 GfError (
"xmlStartElement: addSection failed\n");
804 }
else if (!strcmp(
name,
"attnum")) {
807 GfError (
"xmlStartElement: Syntax error, missing \"section\" tag\n");
818 if (!strcmp(s1,
"name")) {
820 }
else if (!strcmp(s1,
"val")) {
822 }
else if (!strcmp(s1,
"min")) {
824 }
else if (!strcmp(s1,
"max")) {
826 }
else if (!strcmp(s1,
"unit")) {
832 GfError (
"xmlStartElement: Syntax error, missing \"name\" field in %s definition\n",
name);
837 GfError (
"xmlStartElement: Syntax error, missing \"val\" field in %s definition\n",
name);
851 GfError (
"xmlStartElement: addParam failed\n");
875 }
else if (!strcmp(
name,
"attstr")) {
878 GfError (
"xmlStartElement: Syntax error, missing \"section\" tag\n");
889 if (!strcmp(s1,
"name")) {
891 }
else if (!strcmp(s1,
"val")) {
893 }
else if (!strcmp(s1,
"in")) {
899 GfError (
"xmlStartElement: Syntax error, missing \"name\" field in %s definition\n",
name);
904 GfError (
"xmlStartElement: Syntax error, missing \"val\" field in %s definition\n",
name);
910 GfError (
"xmlStartElement: addParam failed\n");
917 sb = strchr (sa,
',');
922 sb = strchr (sa,
',');
952 if (!strcmp(name,
"section")) {
954 GfError (
"xmlEndElement: Syntax error in \"%s\"\n", name);
994 if (systemId[0] ==
'/') {
995 strncpy (fin, systemId,
sizeof (fin));
1001 s = strrchr (fin,
'/');
1007 strncpy (s, systemId,
sizeof (fin) - (s - fin));
1011 in = fopen (fin,
"r");
1014 GfError (
"GfReadParmFile: file %s has pb\n", systemId);
1020 size_t len = fread (buf, 1,
sizeof(buf), in);
1021 done = len <
sizeof (buf);
1023 GfError (
"file: %s -> %s at line %d\n",
1052 GfError (
"parseXml: %s at line %d\n",
1095 const unsigned long parmhandlesize =
sizeof (
struct parmHandle);
1100 GfError (
"gfParmReadBuf: conf header creation failed\n");
1107 GfError (
"gfParmReadBuf: calloc (1, %lu) failed\n", parmhandlesize);
1117 GfError (
"gfParmReadBuf: parserInit failed\n");
1123 GfError (
"gfParmReadBuf: Parse failed for buffer\n");
1165 const unsigned long parmHandleSize =
sizeof (
struct parmHandle);
1174 GfError (
"gfParmReadFile: conf header creation failed\n");
1183 GfError (
"gfParmReadFile: calloc (1, %lu) failed\n", parmHandleSize);
1195 in = fopen (file,
"r");
1197 GfOut (
"gfParmReadFile: fopen \"%s\" failed\n", file);
1204 GfError (
"gfParmReadBuf: parserInit failed for file \"%s\"\n", file);
1209 len = fread (buf, 1,
sizeof(buf), in);
1210 done = len < (int)
sizeof(buf);
1212 GfError (
"gfParmReadFile: Parse failed in file \"%s\"\n", file);
1217 GfError (
"gfParmReadFile: Parse failed in file \"%s\"\n", file);
1257 int len = strlen(val);
1258 const char *replacement;
1262 for (i = 0; i < len; i++) {
1265 replacement =
"<";
break;
1267 replacement =
">";
break;
1269 replacement =
"&";
break;
1271 replacement =
"'";
break;
1273 replacement =
""";
break;
1278 if (replacement == 0) {
1279 replacement = &val[i];
1282 rlen = strlen(replacement);
1285 if (pos-buf < BUFSIZE - rlen) {
1286 memcpy(pos, replacement, rlen*
sizeof(
char));
1289 GfError(
"handleEntities: buffer too small to convert %s", val);
1310 while ((pos < BUFSIZE - 1) && (pos < blanks)) {
1325 static void createIn(
char *buf,
const int BUFSIZE, withinHead* head)
1327 const char* s =
" in=\"";
1330 bool separator =
false;
1333 while (curWithin != 0) {
1334 int len = strlen(s);
1335 if (pos < BUFSIZE - len - 1) {
1336 memcpy(buf, s, len*
sizeof(
char));
1345 if (curWithin != 0) {
1357 memcpy(buf,
"\"", 2*
sizeof(
char));
1378 struct param *curParam;
1380 const int BUFSIZE = 1024;
1382 const int INDENTSIZE = 1024;
1383 char indent[INDENTSIZE];
1384 const int INSIZE = 1024;
1386 const int NUMVALUE = 1024;
1387 char numvalue[NUMVALUE];
1390 switch (outCtrl->
state) {
1392 snprintf (buffer, size,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
1398 if (conf->
dtd == NULL) {
1399 conf->
dtd = strdup(
"params.dtd");
1401 if (conf->
header == NULL) {
1402 conf->
header = strdup(
"");
1404 snprintf (buffer, size,
"<!DOCTYPE params SYSTEM \"%s\">\n%s\n", conf->
dtd, conf->
header);
1423 snprintf (buffer, size,
"</params>\n");
1438 snprintf(buffer, size,
"%s<section name=\"%s\">\n", indent, buf);
1455 snprintf(buffer, size,
"%s<attstr name=\"%s\"%s val=\"%s\"/>\n", indent, curParam->
name, in, buf);
1460 if (curParam->
unit) {
1462 snprintf(numvalue, NUMVALUE,
" min=\"%g\" max=\"%g\" unit=\"%s\" val=\"%g\"/>\n",
1469 snprintf(numvalue, NUMVALUE,
" unit=\"%s\" val=\"%g\"/>\n",
1476 snprintf (numvalue, NUMVALUE,
" min=\"%g\" max=\"%g\" val=\"%g\"/>\n",
1482 snprintf (numvalue, NUMVALUE,
" val=\"%g\"/>\n", curParam->
valnum);
1487 snprintf (buffer, size,
"%s<attnum name=\"%s\"%s", indent, curParam->
name, numvalue);
1506 snprintf (buffer, size,
"%s</section>\n\n", indent);
1519 if (curSection->
parent) {
1522 snprintf (buffer, size,
"%s</section>\n\n", indent);
1563 len = strlen (line);
1564 if (len > curSize) {
1567 memcpy (s, line, len);
1625 GfError (
"gfParmWriteFile: bad file name\n");
1630 fout = fopen (file,
"wb");
1632 GfError (
"gfParmSetStr: fopen (%s, \"wb\") failed\n", file);
1649 GfOut (
"GfParmWriteFile: %s file written\n", file);
1678 GfError (
"GfParmCreateDirectory: bad file name\n");
1703 conf = handle->
conf;
1746 conf = handle->
conf;
1772 GfOut (
"parmReleaseHeader: refcount null free \"%s\"\n", conf->
filename);
1863 if (strcmp(unit,
"m") == 0)
return;
1864 if (strcmp(unit,
"kg") == 0)
return;
1865 if (strcmp(unit,
"s") == 0)
return;
1866 if (strcmp(unit,
"rad") == 0)
return;
1867 if (strcmp(unit,
"Pa") == 0)
return;
1869 if ((strcmp(unit,
"feet") == 0) || (strcmp(unit,
"ft") == 0)) {
1871 }
else if (strcmp(unit,
"deg") == 0) {
1872 coeff = (float) (M_PI/180.0);
1873 }
else if ((strcmp(unit,
"h") == 0) || (strcmp(unit,
"hour") == 0) || (strcmp(unit,
"hours") == 0)) {
1875 }
else if ((strcmp(unit,
"day") == 0) || (strcmp(unit,
"days") == 0)) {
1877 }
else if (strcmp(unit,
"km") == 0) {
1879 }
else if (strcmp(unit,
"mm") == 0) {
1881 }
else if (strcmp(unit,
"cm") == 0) {
1883 }
else if ((strcmp(unit,
"in") == 0) || (strcmp(unit,
"inch") == 0) || (strcmp(unit,
"inches") == 0)) {
1885 }
else if ((strcmp(unit,
"lbs") == 0) || (strcmp(unit,
"lb") == 0)) {
1886 coeff = 0.45359237f;
1887 }
else if (strcmp(unit,
"lbf") == 0) {
1888 coeff = 0.45359237f*
G;
1889 }
else if ((strcmp(unit,
"slug") == 0) || (strcmp(unit,
"slugs") == 0)) {
1890 coeff = 14.59484546f;
1891 }
else if (strcmp(unit,
"kPa") == 0) {
1893 }
else if (strcmp(unit,
"MPa") == 0) {
1895 }
else if ((strcmp(unit,
"PSI") == 0) || (strcmp(unit,
"psi") == 0)){
1897 }
else if ((strcmp(unit,
"rpm") == 0) || (strcmp(unit,
"RPM") == 0)) {
1898 coeff = 0.104719755f;
1899 }
else if ((strcmp(unit,
"percent") == 0) || (strcmp(unit,
"%") == 0)) {
1901 }
else if ((strcmp(unit,
"mph") == 0) || (strcmp(unit,
"MPH") == 0)) {
1952 if ((unit == NULL) || (strlen(unit) == 0))
return dest;
2006 if ((unit == NULL) || (strlen(unit) == 0))
return dest;
2235 GfOut (
"GfParmListClean: \"%s\" not found\n", path);
2354 const char*
GfParmGetCurStr(
void *handle,
const char *path,
const char *key,
const char *deflt)
2477 int GfParmSetStr(
void *handle,
const char *path,
const char *key,
const char *val)
2488 if (!val || !strlen (val)) {
2504 GfError (
"gfParmSetStr: strdup (%s) failed\n", val);
2549 if (!val || !strlen (val)) {
2564 GfError (
"gfParmSetStr: strdup (%s) failed\n", val);
2734 struct section *curSectionRef;
2735 struct section *nextSectionRef;
2736 struct param *curParamRef;
2737 struct param *curParam;
2738 struct within *curWithinRef;
2749 while (curSectionRef) {
2751 while (curParamRef) {
2755 if (curParamRef->
type != curParam->
type) {
2756 GfError(
"GfParmCheckHandle: type mismatch for parameter \"%s\" in (\"%s\" - \"%s\")\n",
2759 }
else if (curParamRef->
type ==
P_NUM) {
2760 if ((curParam->
valnum < curParamRef->
min) || (curParam->
valnum > curParamRef->
max)) {
2761 GfError(
"GfParmCheckHandle: parameter \"%s\" out of bounds: min:%g max:%g val:%g in (\"%s\" - \"%s\")\n",
2767 while (!found && curWithinRef) {
2768 if (!strcmp (curWithinRef->
val, curParam->
value)) {
2774 if (!found && strcmp (curParamRef->
value, curParam->
value)) {
2775 GfError(
"GfParmCheckHandle: parameter \"%s\" value:\"%s\" not allowed in (\"%s\" - \"%s\")\n",
2783 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
2784 while (!nextSectionRef) {
2785 nextSectionRef = curSectionRef->
parent;
2786 if (!nextSectionRef) {
2790 curSectionRef = nextSectionRef;
2791 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
2793 curSectionRef = nextSectionRef;
2817 struct param *paramNew;
2818 struct within *withinRef;
2836 num = paramRef->
min;
2840 paramNew->
min = num;
2843 num = paramRef->
max;
2847 paramNew->
max = num;
2850 if (num < paramNew->
min) {
2851 num = paramNew->
min;
2854 if (num > paramNew->
max) {
2855 num = paramNew->
max;
2886 str = paramRef->
value;
2889 paramNew->
value = strdup (str);
2909 struct param *paramNew;
2970 struct section *curSectionRef;
2971 struct section *nextSectionRef;
2972 struct section *curSectionTgt;
2973 struct section *nextSectionTgt;
2974 struct param *curParamRef;
2975 struct param *curParamTgt;
2976 const unsigned long parmHandleSize =
sizeof (
struct parmHandle);
2981 GfFatal (
"GfParmMergeHandles: bad handle (%p)\n", parmHandleRef);
2985 GfFatal (
"GfParmMergeHandles: bad handle (%p)\n", parmHandleTgt);
2992 GfError (
"gfParmReadBuf: conf header creation failed\n");
2997 parmHandleOut = (
struct parmHandle *) calloc (1, parmHandleSize);
2998 if (!parmHandleOut) {
2999 GfError (
"gfParmReadBuf: calloc (1, %lu) failed\n", parmHandleSize);
3005 parmHandleOut->
conf = confOut;
3011 while (curSectionRef) {
3013 while (curParamRef) {
3024 if (nextSectionRef) {
3025 curSectionRef = nextSectionRef;
3027 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
3028 while (!nextSectionRef) {
3029 nextSectionRef = curSectionRef->
parent;
3030 if (!nextSectionRef) {
3034 curSectionRef = nextSectionRef;
3035 nextSectionRef =
GF_TAILQ_NEXT (curSectionRef, linkSection);
3037 curSectionRef = nextSectionRef;
3045 while (curSectionTgt) {
3047 while (curParamTgt) {
3059 if (nextSectionTgt) {
3060 curSectionTgt = nextSectionTgt;
3062 nextSectionTgt =
GF_TAILQ_NEXT (curSectionTgt, linkSection);
3063 while (!nextSectionTgt) {
3064 nextSectionTgt = curSectionTgt->
parent;
3065 if (!nextSectionTgt) {
3069 curSectionTgt = nextSectionTgt;
3070 nextSectionTgt =
GF_TAILQ_NEXT (curSectionTgt, linkSection);
3072 curSectionTgt = nextSectionTgt;
3087 return (
void*)parmHandleOut;
struct parmHeader * conf
Header of the parameter set.
int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser)
void XMLPARSEAPI XML_SetUserData(XML_Parser parser, void *userData)
struct withinHead withinList
Linked list containing the options for legal string values.
static int myStrcmp(const void *s1, const void *s2)
#define GF_HASH_TYPE_STR
String key based hash table.
struct section * curSection
Current section, for iterations, see GfParmListSeekFirst and GfParmListSeekNext.
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle.
static void evalUnit(char *unit, tdble *dest, int flg)
Support function to multiply or divide dest with unit conversion factor.
static void removeParamByName(struct parmHeader *conf, const char *sectionName, const char *paramName)
Helper function to remove a parameter with given name paramName.
tdble GfParmUnit2SI(const char *unit, tdble val)
Convert a value given in unit to SI.
static void GfFatal(const char *fmt,...)
char * unit
Unit, see GfParmUnit2SI for supported units.
int GfParmCheckHandle(void *ref, void *tgt)
Check the values in the parameter set tgt against the min/max/within definitions in the ref parameter...
GF_TAILQ_ENTRY(struct within) linkWithin
Link to next entry.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
void XMLPARSEAPI XML_SetExternalEntityRefHandler(XML_Parser parser, XML_ExternalEntityRefHandler handler)
static int xmlGetOuputLine(struct parmHandle *parmHandle, char *buffer, int size)
Helper function to output one line of XML generated from the given parameter set. ...
Scalar max(Scalar x, Scalar y)
int GfParmListSeekNext(void *handle, const char *path)
Go the the next subsection element in the parameter set handle.
static void xmlStartElement(void *userData, const char *name, const char **atts)
Helper function to process opening XML elements.
static char * getFullName(const char *sectionName, const char *paramName)
Helper function to get the full name of a parameter (full name: "sectionName/paramName").
void * GfParmMergeHandles(void *ref, void *tgt, int mode)
Merge two parameter sets into a new one, either containing parameters from ref, tgt or from both sets...
static tdble getValNumFromStr(const char *str)
Helper function to parse number.
#define GF_TAILQ_INSERT_TAIL(head, elm, field)
Insert an element at the tail.
static struct section * addSection(struct parmHeader *conf, const char *sectionName)
Helper function to add a section to a parameter set.
struct parmOutput outCtrl
Ouput control structure used for serializing parameter set into XML.
Ouput control structure used for serializing parameter set into XML.
int GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max)
Set a numerical parameter in the parameter set handle including min and max.
GF_TAILQ_ENTRY(struct section) linkSection
Next section at the same level.
static char * 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...
#define PARM_HANDLE_FLAG_PRIVATE
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
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.
static struct parmHeader * createParmHeader(const char *file)
Helper function to create header for parameter set handle.
#define GF_TAILQ_INSERT_HEAD(head, elm, field)
Insert an element at the head.
Section header structure.
void GfHashRelease(void *hash, tfHashFree hashFree)
Release a hash table.
#define PARM_HANDLE_FLAG_PARSE_ERROR
void GfParmSetDTD(void *parmHandle, char *dtd, char *header)
Set the dtd path and header.
static int parserXmlInit(struct parmHandle *parmHandle)
Helper function to set up XML parser in parmHandle.
char * filename
Name of the output file.
static void createIn(char *buf, const int BUFSIZE, withinHead *head)
Helper function to support the serialization into the XML of the "within" attribute.
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
const void * GfHashGetStr(void *hash, const char *key)
Get the user data associated with a string key.
void XMLPARSEAPI XML_ParserFree(XML_Parser parser)
tdble GfParmSI2Unit(const char *unit, tdble val)
Convert a value from SI to given unit.
int GfParmCreateDirectory(const char *file, void *parmHandle)
Create directory for parameter set handle if it does not yet exist.
char * fullName
Name of the parameter including the full section name ('/' separated)
tdble valnum
Numeric value of the parameter.
void GfParmInit(void)
Parameter set library API initialization, set up parameter set handle cache.
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
#define GFPARM_MMODE_RELDST
release tgt after the merge
static void parmReleaseHeader(struct parmHeader *conf)
Helper function to release the parameter set if the reference counter is 0.
char * GfParmListGetCurEltName(void *handle, const char *path)
Get current subsection name of the parameter set handle during subsection iteration.
static struct parmHeader * getSharedHeader(const char *file, int mode)
Helper function for looking up parameter sets in the cache.
int GfParmListSeekFirst(void *handle, const char *path)
Go the the first subsection element in the parameter set handle.
static void parmClean(struct parmHeader *conf)
Helper function to release the parameter set content.
void * GfHashCreate(int type)
Create a new hash table.
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.
tdble max
Maximum for numeric value.
int XMLPARSEAPI XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
float tdble
Floating point type used in TORCS.
#define XML_GetUserData(parser)
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.
struct section * curSubSection
Current subsection, for iterations, see GfParmListSeekFirst and GfParmListSeekNext.
int magic
Magic number (to detect wrong type casts and such)
GF_TAILQ_HEAD(withinHead, struct within)
enum XML_Error XMLPARSEAPI XML_GetErrorCode(XML_Parser parser)
#define GFPARM_RMODE_REREAD
reread the parameters from file and release the previous ones
The Gaming Framework API.
Parameter set handle structure, multiple handles can reference the same parameter set...
void GfParmShutdown(void)
Parameter set library API shutdown, removes parameter set handle cache.
#define GF_TAILQ_INIT(head)
Head initialization (Mandatory)
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. ...
XML_Parser XMLPARSEAPI XML_ParserCreate(const XML_Char *encoding)
struct paramHead paramList
List of the parameters in this section.
Parameter header structure, a parameter can either carry a numeric or a string value, numeric value is constraint by min and max, string value by options in within.
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 int parseXml(struct parmHandle *parmHandle, char *buf, int len, int done)
Helper function to parse one line of XML.
const XML_LChar XMLPARSEAPI * XML_ErrorString(int code)
const void * GfHashRemStr(void *hash, char *key)
Remove an element with a string key from a hash table.
#define GFPARM_RMODE_PRIVATE
void GfParmClean(void *parmHandle)
Clean all the parameters of a parameter set.
#define GF_TAILQ_FIRST(head)
First element of a TAILQ.
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
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.
char * name
Name of the parameter.
static struct parmHead parmHandleList
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
static void xmlEndElement(void *userData, const XML_Char *name)
Helper function to process closing XML elements.
#define GF_TAILQ_REMOVE(head, elm, field)
Remove an element.
Scalar min(Scalar x, Scalar y)
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 GfParmListClean(void *handle, const char *path)
Remove all the subsections in a section in the parameter set handle.
GF_TAILQ_ENTRY(struct parmHandle) linkHandle
Next configuration handle.
int indent
Keep track of indentation.
struct section * parent
Parent section.
#define GF_TAILQ_END(head)
End of a TAILQ.
#define GFPARM_MMODE_RELSRC
release ref after the merge
int GfHashAddStr(void *hash, const char *key, const void *data)
Add an element with a string key to a hash table.
struct param * curParam
Current parameter.
void GfParmRemove(void *parmHandle, char *sectionName, char *paramName)
Remove a parameter from a parameter set.
struct section * curSection
Current section.
char * val
Value of within option.
#define GF_TAILQ_NEXT(elm, field)
Next element of a TAILQ.
void * GfParmReadBuf(char *buffer)
Read parameter set from memory buffer and return handle to parameter set.
int GfParmGetEltNb(void *handle, const char *path)
Count the number of subsections in a section in the parameter set handle.
static void removeParam(struct parmHeader *conf, struct section *section, struct param *param)
Helper function to remove given parameter.
int type
Type, either P_NUM or P_STR.
char * GfParmGetFileName(void *handle)
Get the filename property of the parameter set handle.
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...
#define GFPARM_MMODE_DST
use tgt and verify ref parameters
char * value
String value of the parameter.
static void cleanUnusedSection(struct parmHeader *conf, struct section *section)
Helper function to clean up unused (empty) sections starting with given section.
static void createIndent(char *buf, const int BUFSIZE, const int blanks)
Helper function for indentation in the XML.
char * fullName
Name of the section including full path ('/' separated)
static void removeSection(struct parmHeader *conf, struct section *section)
Helper function to remove a section and its contents (subsections, elements).
static void parmReleaseHandle(struct parmHandle *parmHandle)
Helper function to release the handle and eventually the referenced parameter set (if the reference c...
static void addWithin(struct param *curParam, char *s1)
Helper function to add "within" options to parameter curParam.
Structure to hold linked list of within options.
int GfParmWriteBuf(void *handle, char *buf, int size)
Write a parameter set into a memory buffer.
void XMLPARSEAPI XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
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.
int GfCreateDirForFile(const char *filenameandpath)
Create directory for given file path recursively, so all missing parent directories are created as we...
GF_TAILQ_ENTRY(struct param) linkParam
Next parameter in the same section.
char * GfParmGetName(void *handle)
Get the name property of the parameter set handle.
struct sectionHead subSectionList
List of sub-sections (linked by linkSection)
tdble min
Minimum for numeric value.
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).
#define GFPARM_RMODE_CREAT
Create the file if doesn't exist.
int flag
Flag (PARM_HANDLE_FLAG_PARSE_ERROR, PARM_HANDLE_FLAG_PRIVATE)
XML_Parser XMLPARSEAPI XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *encoding)
#define GFPARM_MMODE_SRC
use ref and modify existing parameters with tgt
static void insertParam(struct parmHandle *parmHandle, char *path, struct param *param)
Helper function to insert a parameter into a parameter set.