aqhome: added function AQH_Vars_ReplaceVars()
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +38,7 @@ static AQH_VARS *_getPath(AQH_VARS *vt, const char *s, uint32_t flags);
|
||||
static void *_pathHandlerFn(const char *entry, void *data, int idx, uint32_t flags);
|
||||
static AQH_VARS *_getNodeByTypeAndName(const AQH_VARS *vt, AQH_VARS_DATATYPE dt, const char *name, int idx);
|
||||
static void _dumpElement(const AQH_VARS *vt, int indent, GWEN_BUFFER *dbuf);
|
||||
static int GWENHYWFAR_CB _replaceVarsCb(void *cbPtr, const char *name, int index, int maxLen, GWEN_BUFFER *dstBuf);
|
||||
|
||||
|
||||
|
||||
@@ -631,6 +633,51 @@ void _dumpElement(const AQH_VARS *vt, int indent, GWEN_BUFFER *dbuf)
|
||||
|
||||
|
||||
|
||||
int AQH_Vars_ReplaceVars(AQH_VARS *vars, const char *s, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv=GWEN_Text_ReplaceVars(s, dbuf, _replaceVarsCb, vars);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int GWENHYWFAR_CB _replaceVarsCb(void *cbPtr, const char *name, int index, GWEN_UNUSED int maxLen, GWEN_BUFFER *dstBuf)
|
||||
{
|
||||
AQH_VARS *vars;
|
||||
AQH_VARS *vtVariable;
|
||||
|
||||
vars=(AQH_VARS*) cbPtr;
|
||||
vtVariable=_getPath(vars, name, AQH_PATH_FLAGS_PATHMUSTEXIST | AQH_PATH_FLAGS_VARIABLE);
|
||||
if (vtVariable) {
|
||||
AQH_VARS *vtValue;
|
||||
|
||||
vtValue=_getValueNodeByIdx(vtVariable, index);
|
||||
if (vtValue) {
|
||||
switch(vtValue->dataType) {
|
||||
case AQH_Vars_DataType_ValueString: GWEN_Buffer_AppendArgs(dstBuf, "%s", vtValue->data.dataString); return 0;
|
||||
case AQH_Vars_DataType_ValueInt: GWEN_Buffer_AppendArgs(dstBuf, "%d", vtValue->data.dataInt); return 0;
|
||||
case AQH_Vars_DataType_ValueDouble: GWEN_Buffer_AppendArgs(dstBuf, "%f", vtValue->data.dataDouble); return 0;
|
||||
case AQH_Vars_DataType_Unknown:
|
||||
case AQH_Vars_DataType_Group:
|
||||
case AQH_Vars_DataType_Variable:
|
||||
break;
|
||||
}
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Unexpected data type \"%d\" (%s)", vtValue->dataType, AQH_Vars_DataTypeToString(vtValue->dataType));
|
||||
return GWEN_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "./vars-t.c"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user