mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
indent pass 2
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -25,244 +25,224 @@
|
||||
|
||||
|
||||
/* This routine will evaluate an expression */
|
||||
int exprEval(exprObj *obj, EXPRTYPE *val)
|
||||
{
|
||||
EXPRTYPE dummy;
|
||||
int exprEval(exprObj * obj, EXPRTYPE * val)
|
||||
{
|
||||
EXPRTYPE dummy;
|
||||
|
||||
if(val == NULL)
|
||||
val = &dummy;
|
||||
if (val == NULL)
|
||||
val = &dummy;
|
||||
|
||||
/* Make sure it was parsed successfully */
|
||||
if(!obj->parsedbad && obj->parsedgood && obj->headnode)
|
||||
{
|
||||
/* Do NOT reset the break count. Let is accumulate
|
||||
between calls until breaker function is called */
|
||||
return exprEvalNode(obj, obj->headnode, 0, val);
|
||||
}
|
||||
else
|
||||
return EXPR_ERROR_BADEXPR;
|
||||
}
|
||||
/* Make sure it was parsed successfully */
|
||||
if (!obj->parsedbad && obj->parsedgood && obj->headnode) {
|
||||
/* Do NOT reset the break count. Let is accumulate
|
||||
between calls until breaker function is called */
|
||||
return exprEvalNode(obj, obj->headnode, 0, val);
|
||||
} else
|
||||
return EXPR_ERROR_BADEXPR;
|
||||
}
|
||||
|
||||
/* Evaluate a node */
|
||||
int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val)
|
||||
{
|
||||
int err;
|
||||
int pos;
|
||||
EXPRTYPE d1, d2;
|
||||
int exprEvalNode(exprObj * obj, exprNode * nodes, int curnode, EXPRTYPE * val)
|
||||
{
|
||||
int err;
|
||||
int pos;
|
||||
EXPRTYPE d1, d2;
|
||||
|
||||
if(obj == NULL || nodes == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (obj == NULL || nodes == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
/* Update n to point to correct node */
|
||||
nodes += curnode;
|
||||
/* Update n to point to correct node */
|
||||
nodes += curnode;
|
||||
|
||||
/* Check breaker count */
|
||||
if(obj->breakcur-- <= 0)
|
||||
{
|
||||
/* Reset count before returning */
|
||||
obj->breakcur = obj->breakcount;
|
||||
|
||||
if(exprGetBreakResult(obj))
|
||||
{
|
||||
return EXPR_ERROR_BREAK;
|
||||
}
|
||||
}
|
||||
/* Check breaker count */
|
||||
if (obj->breakcur-- <= 0) {
|
||||
/* Reset count before returning */
|
||||
obj->breakcur = obj->breakcount;
|
||||
|
||||
switch(nodes->type)
|
||||
{
|
||||
case EXPR_NODETYPE_MULTI:
|
||||
{
|
||||
/* Multi for multiple expressions in one string */
|
||||
for(pos = 0; pos < nodes->data.oper.nodecount; pos++)
|
||||
{
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
|
||||
if(err)
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (exprGetBreakResult(obj)) {
|
||||
return EXPR_ERROR_BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
case EXPR_NODETYPE_ADD:
|
||||
{
|
||||
/* Addition */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
switch (nodes->type) {
|
||||
case EXPR_NODETYPE_MULTI:
|
||||
{
|
||||
/* Multi for multiple expressions in one string */
|
||||
for (pos = 0; pos < nodes->data.oper.nodecount; pos++) {
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
case EXPR_NODETYPE_ADD:
|
||||
{
|
||||
/* Addition */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
if(!err)
|
||||
*val = d1 + d2;
|
||||
else
|
||||
return err;
|
||||
if (!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
|
||||
break;
|
||||
}
|
||||
if (!err)
|
||||
*val = d1 + d2;
|
||||
else
|
||||
return err;
|
||||
|
||||
case EXPR_NODETYPE_SUBTRACT:
|
||||
{
|
||||
/* Subtraction */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
if(!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!err)
|
||||
*val = d1 - d2;
|
||||
else
|
||||
return err;
|
||||
case EXPR_NODETYPE_SUBTRACT:
|
||||
{
|
||||
/* Subtraction */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
break;
|
||||
}
|
||||
if (!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
|
||||
case EXPR_NODETYPE_MULTIPLY:
|
||||
{
|
||||
/* Multiplication */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
if (!err)
|
||||
*val = d1 - d2;
|
||||
else
|
||||
return err;
|
||||
|
||||
if(!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!err)
|
||||
*val = d1 * d2;
|
||||
else
|
||||
return err;
|
||||
case EXPR_NODETYPE_MULTIPLY:
|
||||
{
|
||||
/* Multiplication */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
break;
|
||||
}
|
||||
if (!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
|
||||
case EXPR_NODETYPE_DIVIDE:
|
||||
{
|
||||
/* Division */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
if (!err)
|
||||
*val = d1 * d2;
|
||||
else
|
||||
return err;
|
||||
|
||||
if(!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!err)
|
||||
{
|
||||
if(d2 != 0.0)
|
||||
*val = d1 / d2;
|
||||
else
|
||||
{
|
||||
case EXPR_NODETYPE_DIVIDE:
|
||||
{
|
||||
/* Division */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
if (!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
|
||||
if (!err) {
|
||||
if (d2 != 0.0)
|
||||
*val = d1 / d2;
|
||||
else {
|
||||
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
|
||||
return EXPR_ERROR_DIVBYZERO;
|
||||
return EXPR_ERROR_DIVBYZERO;
|
||||
#else
|
||||
*val = 0.0;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
*val = 0.0;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
return err;
|
||||
}
|
||||
} else
|
||||
return err;
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_NODETYPE_EXPONENT:
|
||||
{
|
||||
/* Exponent */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
case EXPR_NODETYPE_EXPONENT:
|
||||
{
|
||||
/* Exponent */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
if(!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
if (!err)
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||
|
||||
if(!err)
|
||||
{
|
||||
EXPR_RESET_ERR();
|
||||
*val = pow(d1, d2);
|
||||
EXPR_CHECK_ERR();
|
||||
}
|
||||
else
|
||||
return err;
|
||||
if (!err) {
|
||||
EXPR_RESET_ERR();
|
||||
*val = pow(d1, d2);
|
||||
EXPR_CHECK_ERR();
|
||||
} else
|
||||
return err;
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_NODETYPE_NEGATE:
|
||||
{
|
||||
/* Negative value */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
case EXPR_NODETYPE_NEGATE:
|
||||
{
|
||||
/* Negative value */
|
||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||
|
||||
if(!err)
|
||||
*val = -d1;
|
||||
else
|
||||
return err;
|
||||
|
||||
break;
|
||||
}
|
||||
if (!err)
|
||||
*val = -d1;
|
||||
else
|
||||
return err;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case EXPR_NODETYPE_VALUE:
|
||||
{
|
||||
/* Directly access the value */
|
||||
*val = nodes->data.value.value;
|
||||
break;
|
||||
}
|
||||
case EXPR_NODETYPE_VALUE:
|
||||
{
|
||||
/* Directly access the value */
|
||||
*val = nodes->data.value.value;
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_NODETYPE_VARIABLE:
|
||||
{
|
||||
/* Directly access the variable or constant */
|
||||
*val = *(nodes->data.variable.vaddr);
|
||||
break;
|
||||
}
|
||||
case EXPR_NODETYPE_VARIABLE:
|
||||
{
|
||||
/* Directly access the variable or constant */
|
||||
*val = *(nodes->data.variable.vaddr);
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_NODETYPE_ASSIGN:
|
||||
{
|
||||
/* Evaluate assignment subnode */
|
||||
err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
|
||||
case EXPR_NODETYPE_ASSIGN:
|
||||
{
|
||||
/* Evaluate assignment subnode */
|
||||
err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
|
||||
|
||||
if(!err)
|
||||
{
|
||||
/* Directly assign the variable */
|
||||
*(nodes->data.assign.vaddr) = *val;
|
||||
}
|
||||
else
|
||||
return err;
|
||||
|
||||
break;
|
||||
}
|
||||
if (!err) {
|
||||
/* Directly assign the variable */
|
||||
*(nodes->data.assign.vaddr) = *val;
|
||||
} else
|
||||
return err;
|
||||
|
||||
case EXPR_NODETYPE_FUNCTION:
|
||||
{
|
||||
/* Evaluate the function */
|
||||
if(nodes->data.function.fptr == NULL)
|
||||
{
|
||||
/* No function pointer means we are not using
|
||||
function solvers. See if the function has a
|
||||
type to solve directly. */
|
||||
switch(nodes->data.function.type)
|
||||
{
|
||||
/* This is to keep the file from being too crowded.
|
||||
See exprilfs.h for the definitions. */
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_NODETYPE_FUNCTION:
|
||||
{
|
||||
/* Evaluate the function */
|
||||
if (nodes->data.function.fptr == NULL) {
|
||||
/* No function pointer means we are not using
|
||||
function solvers. See if the function has a
|
||||
type to solve directly. */
|
||||
switch (nodes->data.function.type) {
|
||||
/* This is to keep the file from being too crowded.
|
||||
See exprilfs.h for the definitions. */
|
||||
#include "exprilfs.h"
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
return EXPR_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the correct function */
|
||||
return (*(nodes->data.function.fptr))(obj,
|
||||
nodes->data.function.nodes, nodes->data.function.nodecount,
|
||||
nodes->data.function.refs, nodes->data.function.refcount, val);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
/* Unknown node type */
|
||||
return EXPR_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
return EXPR_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Call the correct function */
|
||||
return (*(nodes->data.function.fptr)) (obj,
|
||||
nodes->data.function.nodes, nodes->data.function.nodecount,
|
||||
nodes->data.function.refs, nodes->data.function.refcount, val);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
/* Unknown node type */
|
||||
return EXPR_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
@@ -17,313 +17,296 @@
|
||||
|
||||
/* Internal functions */
|
||||
static exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax);
|
||||
static void exprFuncListFreeData(exprFunc *func);
|
||||
static void exprFuncListFreeData(exprFunc * func);
|
||||
|
||||
|
||||
/* This function creates the function list, */
|
||||
int exprFuncListCreate(exprFuncList **flist)
|
||||
{
|
||||
exprFuncList *tmp;
|
||||
int exprFuncListCreate(exprFuncList ** flist)
|
||||
{
|
||||
exprFuncList *tmp;
|
||||
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
*flist = NULL; /* Set to NULL initially */
|
||||
*flist = NULL; /* Set to NULL initially */
|
||||
|
||||
tmp = exprAllocMem(sizeof(exprFuncList));
|
||||
tmp = exprAllocMem(sizeof(exprFuncList));
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
||||
|
||||
/* Update pointer */
|
||||
*flist = tmp;
|
||||
/* Update pointer */
|
||||
*flist = tmp;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Add a function to the list */
|
||||
int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
|
||||
{
|
||||
exprFunc *tmp;
|
||||
exprFunc *cur;
|
||||
int result;
|
||||
int exprFuncListAdd(exprFuncList * flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
|
||||
{
|
||||
exprFunc *tmp;
|
||||
exprFunc *cur;
|
||||
int result;
|
||||
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
/* Make sure the name is valid */
|
||||
if(!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
/* Make sure the name is valid */
|
||||
if (!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
|
||||
/* Fix values only if none are negative (negative values mean no limit) */
|
||||
/* Fix values only if none are negative (negative values mean no limit) */
|
||||
|
||||
/* if both are neg, no min or max number of args */
|
||||
/* if min is neg, max pos, no min number of args but a maximum */
|
||||
/* if min is pos, max neg, there is a min number of args, but no max */
|
||||
/* if both pos, then a min and max limit. We swap to make sure it works
|
||||
right. I.E. Min of 3 and max of 2 would make function unusable */
|
||||
if(min >= 0 && max >= 0)
|
||||
{
|
||||
if(min > max)
|
||||
{
|
||||
result = min;
|
||||
min = max;
|
||||
max = result;
|
||||
}
|
||||
}
|
||||
/* if both are neg, no min or max number of args */
|
||||
/* if min is neg, max pos, no min number of args but a maximum */
|
||||
/* if min is pos, max neg, there is a min number of args, but no max */
|
||||
/* if both pos, then a min and max limit. We swap to make sure it works
|
||||
right. I.E. Min of 3 and max of 2 would make function unusable */
|
||||
if (min >= 0 && max >= 0) {
|
||||
if (min > max) {
|
||||
result = min;
|
||||
min = max;
|
||||
max = result;
|
||||
}
|
||||
}
|
||||
|
||||
if(refmin >= 0 && refmax >= 0)
|
||||
{
|
||||
if(refmin > refmax)
|
||||
{
|
||||
result = refmin;
|
||||
refmin = max;
|
||||
refmax = result;
|
||||
}
|
||||
}
|
||||
if (refmin >= 0 && refmax >= 0) {
|
||||
if (refmin > refmax) {
|
||||
result = refmin;
|
||||
refmin = max;
|
||||
refmax = result;
|
||||
}
|
||||
}
|
||||
|
||||
if(flist->head == NULL)
|
||||
{
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
||||
if (flist->head == NULL) {
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* See if it already exists */
|
||||
cur = flist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->fname);
|
||||
|
||||
if(result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* It did not exist, so add it at the head */
|
||||
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = flist->head;
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
/* See if it already exists */
|
||||
cur = flist->head;
|
||||
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->fname);
|
||||
|
||||
if (result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* It did not exist, so add it at the head */
|
||||
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
||||
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = flist->head;
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Add a function node type to the list
|
||||
This works pretty much the same way, except the function
|
||||
pointer is NULL and the node type specifies the function
|
||||
to do. exprEvalNode handles this, instead of calling
|
||||
a function solver. */
|
||||
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax)
|
||||
{
|
||||
exprFunc *tmp;
|
||||
exprFunc *cur;
|
||||
int result;
|
||||
int exprFuncListAddType(exprFuncList * flist, char *name, int type, int min, int max, int refmin, int refmax)
|
||||
{
|
||||
exprFunc *tmp;
|
||||
exprFunc *cur;
|
||||
int result;
|
||||
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
/* Make sure the name is valid */
|
||||
if(!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
/* Make sure the name is valid */
|
||||
if (!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
|
||||
/* Fix values only if none are negative (negative values mean no limit) */
|
||||
/* Fix values only if none are negative (negative values mean no limit) */
|
||||
|
||||
/* if both are neg, no min or max number of args */
|
||||
/* if min is neg, max pos, no min number of args but a maximum */
|
||||
/* if min is pos, max neg, there is a min number of args, but no max */
|
||||
/* if both pos, then a min and max limit. We swap to make sure it works
|
||||
right. I.E. Min of 3 and max of 2 would make function unusable */
|
||||
if(min >= 0 && max >= 0)
|
||||
{
|
||||
if(min > max)
|
||||
{
|
||||
result = min;
|
||||
min = max;
|
||||
max = result;
|
||||
}
|
||||
}
|
||||
/* if both are neg, no min or max number of args */
|
||||
/* if min is neg, max pos, no min number of args but a maximum */
|
||||
/* if min is pos, max neg, there is a min number of args, but no max */
|
||||
/* if both pos, then a min and max limit. We swap to make sure it works
|
||||
right. I.E. Min of 3 and max of 2 would make function unusable */
|
||||
if (min >= 0 && max >= 0) {
|
||||
if (min > max) {
|
||||
result = min;
|
||||
min = max;
|
||||
max = result;
|
||||
}
|
||||
}
|
||||
|
||||
if(refmin >= 0 && refmax >= 0)
|
||||
{
|
||||
if(refmin > refmax)
|
||||
{
|
||||
result = refmin;
|
||||
refmin = max;
|
||||
refmax = result;
|
||||
}
|
||||
}
|
||||
if (refmin >= 0 && refmax >= 0) {
|
||||
if (refmin > refmax) {
|
||||
result = refmin;
|
||||
refmin = max;
|
||||
refmax = result;
|
||||
}
|
||||
}
|
||||
|
||||
if(flist->head == NULL)
|
||||
{
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
||||
if (flist->head == NULL) {
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* See if it already exists */
|
||||
cur = flist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->fname);
|
||||
|
||||
if(result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* It did not exist, so add it at the head */
|
||||
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = flist->head;
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
/* See if it already exists */
|
||||
cur = flist->head;
|
||||
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->fname);
|
||||
|
||||
if (result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* It did not exist, so add it at the head */
|
||||
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
||||
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = flist->head;
|
||||
flist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Get the function from a list along with it's min an max data */
|
||||
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax)
|
||||
{
|
||||
exprFunc *cur;
|
||||
int result;
|
||||
int exprFuncListGet(exprFuncList * flist, char *name, exprFuncType * ptr, int *type, int *min, int *max, int *refmin, int *refmax)
|
||||
{
|
||||
exprFunc *cur;
|
||||
int result;
|
||||
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
if (name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
|
||||
/* Search for the item */
|
||||
cur = flist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->fname);
|
||||
/* Search for the item */
|
||||
cur = flist->head;
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
/* We found it. */
|
||||
*ptr = cur->fptr;
|
||||
*min = cur->min;
|
||||
*max = cur->max;
|
||||
*refmin = cur->refmin;
|
||||
*refmax = cur->refmax;
|
||||
*type = cur->type;
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->fname);
|
||||
|
||||
/* return now */
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
if (result == 0) {
|
||||
/* We found it. */
|
||||
*ptr = cur->fptr;
|
||||
*min = cur->min;
|
||||
*max = cur->max;
|
||||
*refmin = cur->refmin;
|
||||
*refmax = cur->refmax;
|
||||
*type = cur->type;
|
||||
|
||||
/* If we got here, we did not find the item in the list */
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
/* return now */
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* If we got here, we did not find the item in the list */
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
|
||||
/* This routine will free the function list */
|
||||
int exprFuncListFree(exprFuncList *flist)
|
||||
{
|
||||
/* Make sure it exists, if not it is not error */
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
int exprFuncListFree(exprFuncList * flist)
|
||||
{
|
||||
/* Make sure it exists, if not it is not error */
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
|
||||
/* Free the nodes */
|
||||
exprFuncListFreeData(flist->head);
|
||||
/* Free the nodes */
|
||||
exprFuncListFreeData(flist->head);
|
||||
|
||||
/* Free the container */
|
||||
exprFreeMem(flist);
|
||||
/* Free the container */
|
||||
exprFreeMem(flist);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* This routine will clear the function list */
|
||||
int exprFuncListClear(exprFuncList *flist)
|
||||
{
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
int exprFuncListClear(exprFuncList * flist)
|
||||
{
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
|
||||
/* Free the nodes only */
|
||||
if(flist->head)
|
||||
{
|
||||
exprFuncListFreeData(flist->head);
|
||||
/* Free the nodes only */
|
||||
if (flist->head) {
|
||||
exprFuncListFreeData(flist->head);
|
||||
|
||||
flist->head = NULL;
|
||||
}
|
||||
flist->head = NULL;
|
||||
}
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* This routine will free any child nodes, and then free itself */
|
||||
void exprFuncListFreeData(exprFunc *func)
|
||||
{
|
||||
exprFunc *next;
|
||||
|
||||
while(func)
|
||||
{
|
||||
/* Remember the next item */
|
||||
next = func->next;
|
||||
void exprFuncListFreeData(exprFunc * func)
|
||||
{
|
||||
exprFunc *next;
|
||||
|
||||
/* Free name */
|
||||
exprFreeMem(func->fname);
|
||||
while (func) {
|
||||
/* Remember the next item */
|
||||
next = func->next;
|
||||
|
||||
/* Free ourself */
|
||||
exprFreeMem(func);
|
||||
|
||||
func = next;
|
||||
}
|
||||
}
|
||||
/* Free name */
|
||||
exprFreeMem(func->fname);
|
||||
|
||||
/* Free ourself */
|
||||
exprFreeMem(func);
|
||||
|
||||
func = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* This routine will create the function object */
|
||||
exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax)
|
||||
{
|
||||
exprFunc *tmp;
|
||||
char *vtmp;
|
||||
{
|
||||
exprFunc *tmp;
|
||||
char *vtmp;
|
||||
|
||||
/* We already checked the name in exprFuncListAdd */
|
||||
/* We already checked the name in exprFuncListAdd */
|
||||
|
||||
/* Create it */
|
||||
tmp = exprAllocMem(sizeof(exprFunc));
|
||||
if(tmp == NULL)
|
||||
return NULL;
|
||||
/* Create it */
|
||||
tmp = exprAllocMem(sizeof(exprFunc));
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Allocate space for the name */
|
||||
vtmp = exprAllocMem(strlen(name) + 1);
|
||||
/* Allocate space for the name */
|
||||
vtmp = exprAllocMem(strlen(name) + 1);
|
||||
|
||||
if(vtmp == NULL)
|
||||
{
|
||||
exprFreeMem(tmp);
|
||||
return NULL;
|
||||
}
|
||||
if (vtmp == NULL) {
|
||||
exprFreeMem(tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Copy the data over */
|
||||
strcpy(vtmp, name);
|
||||
tmp->fname = vtmp;
|
||||
tmp->fptr = ptr;
|
||||
tmp->min = min;
|
||||
tmp->max = max;
|
||||
tmp->refmin = refmin;
|
||||
tmp->refmax = refmax;
|
||||
tmp->type = type;
|
||||
/* Copy the data over */
|
||||
strcpy(vtmp, name);
|
||||
tmp->fname = vtmp;
|
||||
tmp->fptr = ptr;
|
||||
tmp->min = min;
|
||||
tmp->max = max;
|
||||
tmp->refmin = refmin;
|
||||
tmp->refmax = refmax;
|
||||
tmp->type = type;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -26,90 +26,88 @@ if(err != EXPR_ERROR_NOERROR) \
|
||||
return err;
|
||||
|
||||
/* Call this function to initialize these functions into a function list */
|
||||
int exprFuncListInit(exprFuncList *flist)
|
||||
{
|
||||
int err;
|
||||
int exprFuncListInit(exprFuncList * flist)
|
||||
{
|
||||
int err;
|
||||
|
||||
if(flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (flist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
|
||||
EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
|
||||
EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
|
||||
EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1 ,1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
|
||||
EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
|
||||
EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
|
||||
EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1, 1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
|
||||
EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Call this function to initialize some constants into a value list */
|
||||
int exprValListInit(exprValList *vlist)
|
||||
{
|
||||
int err;
|
||||
int exprValListInit(exprValList * vlist)
|
||||
{
|
||||
int err;
|
||||
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
EXPR_ADDCONST("M_E", M_E);
|
||||
EXPR_ADDCONST("M_LOG2E", M_LOG2E);
|
||||
EXPR_ADDCONST("M_LOG10E", M_LOG10E);
|
||||
EXPR_ADDCONST("M_LN2", M_LN2);
|
||||
EXPR_ADDCONST("M_LN10", M_LN10);
|
||||
EXPR_ADDCONST("M_PI", M_PI);
|
||||
EXPR_ADDCONST("M_PI_2", M_PI_2);
|
||||
EXPR_ADDCONST("M_PI_4", M_PI_4);
|
||||
EXPR_ADDCONST("M_1_PI", M_1_PI);
|
||||
EXPR_ADDCONST("M_2_PI", M_2_PI);
|
||||
EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
|
||||
EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
|
||||
EXPR_ADDCONST("M_SQRT2", M_SQRT2);
|
||||
EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
EXPR_ADDCONST("M_E", M_E);
|
||||
EXPR_ADDCONST("M_LOG2E", M_LOG2E);
|
||||
EXPR_ADDCONST("M_LOG10E", M_LOG10E);
|
||||
EXPR_ADDCONST("M_LN2", M_LN2);
|
||||
EXPR_ADDCONST("M_LN10", M_LN10);
|
||||
EXPR_ADDCONST("M_PI", M_PI);
|
||||
EXPR_ADDCONST("M_PI_2", M_PI_2);
|
||||
EXPR_ADDCONST("M_PI_4", M_PI_4);
|
||||
EXPR_ADDCONST("M_1_PI", M_1_PI);
|
||||
EXPR_ADDCONST("M_2_PI", M_2_PI);
|
||||
EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
|
||||
EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
|
||||
EXPR_ADDCONST("M_SQRT2", M_SQRT2);
|
||||
EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
@@ -13,27 +13,26 @@
|
||||
#include "exprmem.h"
|
||||
|
||||
/* Allocate memory and zero it */
|
||||
void* exprAllocMem(size_t size)
|
||||
{
|
||||
void *data = malloc(size);
|
||||
|
||||
if(data)
|
||||
{
|
||||
memset(data, 0, size);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
void *exprAllocMem(size_t size)
|
||||
{
|
||||
void *data = malloc(size);
|
||||
|
||||
if (data) {
|
||||
memset(data, 0, size);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* Free memory */
|
||||
void exprFreeMem(void *data)
|
||||
{
|
||||
if(data)
|
||||
free(data);
|
||||
}
|
||||
{
|
||||
if (data)
|
||||
free(data);
|
||||
}
|
||||
|
||||
/* Allocate a list of nodes */
|
||||
exprNode *exprAllocNodes(size_t count)
|
||||
{
|
||||
return exprAllocMem(count * sizeof(exprNode));
|
||||
}
|
||||
{
|
||||
return exprAllocMem(count * sizeof(exprNode));
|
||||
}
|
||||
|
||||
@@ -14,224 +14,215 @@
|
||||
#include "exprmem.h"
|
||||
|
||||
/* Internal functions */
|
||||
static void exprFreeNodeData(exprNode *node);
|
||||
static void exprFreeNodeData(exprNode * node);
|
||||
|
||||
|
||||
/* Function to create an expression object */
|
||||
int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
|
||||
exprBreakFuncType breaker, void *userdata)
|
||||
{
|
||||
exprObj *tmp;
|
||||
int exprCreate(exprObj ** obj, exprFuncList * flist, exprValList * vlist, exprValList * clist, exprBreakFuncType breaker, void *userdata)
|
||||
{
|
||||
exprObj *tmp;
|
||||
|
||||
/* Allocate memory for the object */
|
||||
tmp = exprAllocMem(sizeof(exprObj));
|
||||
/* Allocate memory for the object */
|
||||
tmp = exprAllocMem(sizeof(exprObj));
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
|
||||
/* Assign data */
|
||||
tmp->flist = flist;
|
||||
tmp->vlist = vlist;
|
||||
tmp->clist = clist;
|
||||
tmp->breakerfunc = breaker;
|
||||
tmp->userdata = userdata;
|
||||
tmp->breakcount = 100000; /* Default breaker count setting */
|
||||
tmp->breakcur = 0;
|
||||
/* Assign data */
|
||||
tmp->flist = flist;
|
||||
tmp->vlist = vlist;
|
||||
tmp->clist = clist;
|
||||
tmp->breakerfunc = breaker;
|
||||
tmp->userdata = userdata;
|
||||
tmp->breakcount = 100000; /* Default breaker count setting */
|
||||
tmp->breakcur = 0;
|
||||
|
||||
/* Update pointer */
|
||||
*obj = tmp;
|
||||
/* Update pointer */
|
||||
*obj = tmp;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Free the expression */
|
||||
int exprFree(exprObj *obj)
|
||||
{
|
||||
if(obj == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
int exprFree(exprObj * obj)
|
||||
{
|
||||
if (obj == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
|
||||
/* First free the node data */
|
||||
exprFreeNodeData(obj->headnode);
|
||||
exprFreeMem(obj->headnode);
|
||||
/* First free the node data */
|
||||
exprFreeNodeData(obj->headnode);
|
||||
exprFreeMem(obj->headnode);
|
||||
|
||||
/* Free ourself */
|
||||
exprFreeMem(obj);
|
||||
/* Free ourself */
|
||||
exprFreeMem(obj);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Clear expression, keep lists, etc */
|
||||
int exprClear(exprObj *obj)
|
||||
{
|
||||
if(obj == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
int exprClear(exprObj * obj)
|
||||
{
|
||||
if (obj == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
|
||||
/* Free the node data only, keep function, variable, constant lists */
|
||||
exprFreeNodeData(obj->headnode);
|
||||
exprFreeMem(obj->headnode);
|
||||
/* Free the node data only, keep function, variable, constant lists */
|
||||
exprFreeNodeData(obj->headnode);
|
||||
exprFreeMem(obj->headnode);
|
||||
|
||||
obj->headnode = NULL;
|
||||
obj->parsedbad = 0;
|
||||
obj->parsedgood = 0;
|
||||
obj->headnode = NULL;
|
||||
obj->parsedbad = 0;
|
||||
obj->parsedgood = 0;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Get functions to get information about the expression object */
|
||||
|
||||
/* Get the function list */
|
||||
exprFuncList *exprGetFuncList(exprObj *obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->flist;
|
||||
}
|
||||
exprFuncList *exprGetFuncList(exprObj * obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->flist;
|
||||
}
|
||||
|
||||
/* Get the variable list */
|
||||
exprValList *exprGetVarList(exprObj *obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->vlist;
|
||||
}
|
||||
exprValList *exprGetVarList(exprObj * obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->vlist;
|
||||
}
|
||||
|
||||
/* Get the constant list */
|
||||
exprValList *exprGetConstList(exprObj *obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->clist;
|
||||
}
|
||||
exprValList *exprGetConstList(exprObj * obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->clist;
|
||||
}
|
||||
|
||||
/* Get the breaker function */
|
||||
exprBreakFuncType exprGetBreakFunc(exprObj *obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->breakerfunc;
|
||||
}
|
||||
exprBreakFuncType exprGetBreakFunc(exprObj * obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->breakerfunc;
|
||||
}
|
||||
|
||||
/* Check for break status */
|
||||
int exprGetBreakResult(exprObj *obj)
|
||||
{
|
||||
if(obj == NULL)
|
||||
return 0;
|
||||
int exprGetBreakResult(exprObj * obj)
|
||||
{
|
||||
if (obj == NULL)
|
||||
return 0;
|
||||
|
||||
if(obj->breakerfunc == NULL)
|
||||
return 0;
|
||||
if (obj->breakerfunc == NULL)
|
||||
return 0;
|
||||
|
||||
return (*(obj->breakerfunc))(obj);
|
||||
}
|
||||
return (*(obj->breakerfunc)) (obj);
|
||||
}
|
||||
|
||||
/* Get the user data */
|
||||
void *exprGetUserData(exprObj *obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->userdata;
|
||||
}
|
||||
void *exprGetUserData(exprObj * obj)
|
||||
{
|
||||
return (obj == NULL) ? NULL : obj->userdata;
|
||||
}
|
||||
|
||||
|
||||
/* Set functions to set certain data */
|
||||
|
||||
/* Set user data */
|
||||
void exprSetUserData(exprObj *obj, void *userdata)
|
||||
{
|
||||
if(obj)
|
||||
obj->userdata = userdata;
|
||||
}
|
||||
void exprSetUserData(exprObj * obj, void *userdata)
|
||||
{
|
||||
if (obj)
|
||||
obj->userdata = userdata;
|
||||
}
|
||||
|
||||
|
||||
/* Set breaker count */
|
||||
void exprSetBreakCount(exprObj *obj, int count)
|
||||
{
|
||||
if(obj)
|
||||
{
|
||||
/* If count is negative, make it positive */
|
||||
if(count < 0)
|
||||
count = -count;
|
||||
void exprSetBreakCount(exprObj * obj, int count)
|
||||
{
|
||||
if (obj) {
|
||||
/* If count is negative, make it positive */
|
||||
if (count < 0)
|
||||
count = -count;
|
||||
|
||||
obj->breakcount = count;
|
||||
obj->breakcount = count;
|
||||
|
||||
/* Make sure the current value is not bigger than count */
|
||||
if(obj->breakcur > count)
|
||||
obj->breakcur = count;
|
||||
}
|
||||
}
|
||||
/* Make sure the current value is not bigger than count */
|
||||
if (obj->breakcur > count)
|
||||
obj->breakcur = count;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get error position */
|
||||
void exprGetErrorPosition(exprObj *obj, int *start, int *end)
|
||||
{
|
||||
if(obj)
|
||||
{
|
||||
if(start)
|
||||
*start = obj->starterr;
|
||||
void exprGetErrorPosition(exprObj * obj, int *start, int *end)
|
||||
{
|
||||
if (obj) {
|
||||
if (start)
|
||||
*start = obj->starterr;
|
||||
|
||||
if(end)
|
||||
*end = obj->enderr;
|
||||
}
|
||||
}
|
||||
if (end)
|
||||
*end = obj->enderr;
|
||||
}
|
||||
}
|
||||
|
||||
/* This function will free a node's data */
|
||||
static void exprFreeNodeData(exprNode *node)
|
||||
{
|
||||
int pos;
|
||||
static void exprFreeNodeData(exprNode * node)
|
||||
{
|
||||
int pos;
|
||||
|
||||
if(node == NULL)
|
||||
return;
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
/* free data based on type */
|
||||
switch(node->type)
|
||||
{
|
||||
case EXPR_NODETYPE_ADD:
|
||||
case EXPR_NODETYPE_SUBTRACT:
|
||||
case EXPR_NODETYPE_MULTIPLY:
|
||||
case EXPR_NODETYPE_DIVIDE:
|
||||
case EXPR_NODETYPE_EXPONENT:
|
||||
case EXPR_NODETYPE_NEGATE:
|
||||
case EXPR_NODETYPE_MULTI:
|
||||
/* Free operation data */
|
||||
if(node->data.oper.nodes)
|
||||
{
|
||||
for(pos = 0; pos < node->data.oper.nodecount; pos++)
|
||||
exprFreeNodeData(&(node->data.oper.nodes[pos]));
|
||||
/* free data based on type */
|
||||
switch (node->type) {
|
||||
case EXPR_NODETYPE_ADD:
|
||||
case EXPR_NODETYPE_SUBTRACT:
|
||||
case EXPR_NODETYPE_MULTIPLY:
|
||||
case EXPR_NODETYPE_DIVIDE:
|
||||
case EXPR_NODETYPE_EXPONENT:
|
||||
case EXPR_NODETYPE_NEGATE:
|
||||
case EXPR_NODETYPE_MULTI:
|
||||
/* Free operation data */
|
||||
if (node->data.oper.nodes) {
|
||||
for (pos = 0; pos < node->data.oper.nodecount; pos++)
|
||||
exprFreeNodeData(&(node->data.oper.nodes[pos]));
|
||||
|
||||
exprFreeMem(node->data.oper.nodes);
|
||||
}
|
||||
exprFreeMem(node->data.oper.nodes);
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
|
||||
case EXPR_NODETYPE_VALUE:
|
||||
/* Nothing to free for value */
|
||||
break;
|
||||
case EXPR_NODETYPE_VALUE:
|
||||
/* Nothing to free for value */
|
||||
break;
|
||||
|
||||
case EXPR_NODETYPE_VARIABLE:
|
||||
/* Nothing to free for variable */
|
||||
break;
|
||||
case EXPR_NODETYPE_VARIABLE:
|
||||
/* Nothing to free for variable */
|
||||
break;
|
||||
|
||||
case EXPR_NODETYPE_FUNCTION:
|
||||
/* Free data of each subnode */
|
||||
if(node->data.function.nodes)
|
||||
{
|
||||
for(pos = 0; pos < node->data.function.nodecount; pos++)
|
||||
exprFreeNodeData(&(node->data.function.nodes[pos]));
|
||||
case EXPR_NODETYPE_FUNCTION:
|
||||
/* Free data of each subnode */
|
||||
if (node->data.function.nodes) {
|
||||
for (pos = 0; pos < node->data.function.nodecount; pos++)
|
||||
exprFreeNodeData(&(node->data.function.nodes[pos]));
|
||||
|
||||
/* Free the subnode array */
|
||||
exprFreeMem(node->data.function.nodes);
|
||||
}
|
||||
/* Free the subnode array */
|
||||
exprFreeMem(node->data.function.nodes);
|
||||
}
|
||||
|
||||
/* Free reference variable list */
|
||||
if(node->data.function.refs)
|
||||
exprFreeMem(node->data.function.refs);
|
||||
/* Free reference variable list */
|
||||
if (node->data.function.refs)
|
||||
exprFreeMem(node->data.function.refs);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case EXPR_NODETYPE_ASSIGN:
|
||||
/* Free subnode data */
|
||||
if(node->data.assign.node)
|
||||
{
|
||||
exprFreeNodeData(node->data.assign.node);
|
||||
|
||||
/* Free the subnode */
|
||||
exprFreeMem(node->data.assign.node);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
case EXPR_NODETYPE_ASSIGN:
|
||||
/* Free subnode data */
|
||||
if (node->data.assign.node) {
|
||||
exprFreeNodeData(node->data.assign.node);
|
||||
|
||||
/* Free the subnode */
|
||||
exprFreeMem(node->data.assign.node);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+1151
-1290
File diff suppressed because it is too large
Load Diff
@@ -15,29 +15,27 @@
|
||||
|
||||
/* Return the version number */
|
||||
void exprGetVersion(int *major, int *minor)
|
||||
{
|
||||
*major = EXPR_VERSIONMAJOR;
|
||||
*minor = EXPR_VERSIONMINOR;
|
||||
}
|
||||
{
|
||||
*major = EXPR_VERSIONMAJOR;
|
||||
*minor = EXPR_VERSIONMINOR;
|
||||
}
|
||||
|
||||
/* This utility function determines if an identifier is valid */
|
||||
int exprValidIdent(char *name)
|
||||
{
|
||||
if(name == NULL) /* Null string */
|
||||
return 0;
|
||||
{
|
||||
if (name == NULL) /* Null string */
|
||||
return 0;
|
||||
|
||||
/* First must be letter or underscore */
|
||||
if(isalpha(*name) || *name == '_')
|
||||
name++; /* Point to next letter */
|
||||
else
|
||||
return 0; /* Not letter or underscore, maybe empty*/
|
||||
|
||||
/* others can be letter, number, or underscore */
|
||||
while(isalnum(*name) || *name == '_')
|
||||
name++;
|
||||
|
||||
/* When the while breaks out, we should be at the end */
|
||||
return (*name == '\0') ? 1 : 0;
|
||||
}
|
||||
/* First must be letter or underscore */
|
||||
if (isalpha(*name) || *name == '_')
|
||||
name++; /* Point to next letter */
|
||||
else
|
||||
return 0; /* Not letter or underscore, maybe empty */
|
||||
|
||||
/* others can be letter, number, or underscore */
|
||||
while (isalnum(*name) || *name == '_')
|
||||
name++;
|
||||
|
||||
/* When the while breaks out, we should be at the end */
|
||||
return (*name == '\0') ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -15,381 +15,365 @@
|
||||
|
||||
|
||||
/* Internal functions */
|
||||
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr);
|
||||
static void exprValListFreeData(exprVal *val);
|
||||
static void exprValListResetData(exprVal *val);
|
||||
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE * addr);
|
||||
static void exprValListFreeData(exprVal * val);
|
||||
static void exprValListResetData(exprVal * val);
|
||||
|
||||
/* This function creates the value list, */
|
||||
int exprValListCreate(exprValList **vlist)
|
||||
{
|
||||
exprValList *tmp;
|
||||
int exprValListCreate(exprValList ** vlist)
|
||||
{
|
||||
exprValList *tmp;
|
||||
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
*vlist = NULL; /* Set to NULL initially */
|
||||
*vlist = NULL; /* Set to NULL initially */
|
||||
|
||||
tmp = exprAllocMem(sizeof(exprValList));
|
||||
tmp = exprAllocMem(sizeof(exprValList));
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
||||
|
||||
/* Update pointer */
|
||||
*vlist = tmp;
|
||||
/* Update pointer */
|
||||
*vlist = tmp;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Add a value to the list */
|
||||
int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val)
|
||||
{
|
||||
exprVal *tmp;
|
||||
exprVal *cur;
|
||||
int result;
|
||||
int exprValListAdd(exprValList * vlist, char *name, EXPRTYPE val)
|
||||
{
|
||||
exprVal *tmp;
|
||||
exprVal *cur;
|
||||
int result;
|
||||
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
/* Make sure the name is valid */
|
||||
if(!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
/* Make sure the name is valid */
|
||||
if (!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
|
||||
if(vlist->head == NULL)
|
||||
{
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateVal(name, val, NULL);
|
||||
if (vlist->head == NULL) {
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateVal(name, val, NULL);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
vlist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
vlist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* See if already exists */
|
||||
cur = vlist->head;
|
||||
/* See if already exists */
|
||||
cur = vlist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if(result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* We did not find it, create it and add it to the beginning */
|
||||
tmp = exprCreateVal(name, val, NULL);
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if (result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* We did not find it, create it and add it to the beginning */
|
||||
tmp = exprCreateVal(name, val, NULL);
|
||||
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = vlist->head;
|
||||
vlist->head = tmp;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = vlist->head;
|
||||
vlist->head = tmp;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Set a value in the list */
|
||||
int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val)
|
||||
{
|
||||
exprVal *cur;
|
||||
int result;
|
||||
int exprValListSet(exprValList * vlist, char *name, EXPRTYPE val)
|
||||
{
|
||||
exprVal *cur;
|
||||
int result;
|
||||
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
if (name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
|
||||
/* Find and set it */
|
||||
cur = vlist->head;
|
||||
/* Find and set it */
|
||||
cur = vlist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
if(cur->vptr)
|
||||
*(cur->vptr) = val;
|
||||
else
|
||||
cur->vval = val;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if (result == 0) {
|
||||
if (cur->vptr)
|
||||
*(cur->vptr) = val;
|
||||
else
|
||||
cur->vval = val;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
|
||||
/* Get the value from a list */
|
||||
int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val)
|
||||
{
|
||||
exprVal *cur;
|
||||
int result;
|
||||
int exprValListGet(exprValList * vlist, char *name, EXPRTYPE * val)
|
||||
{
|
||||
exprVal *cur;
|
||||
int result;
|
||||
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
if (name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
|
||||
/* Search for the item */
|
||||
cur = vlist->head;
|
||||
/* Search for the item */
|
||||
cur = vlist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->vname);
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
/* We found it. */
|
||||
if(cur->vptr)
|
||||
*val = *(cur->vptr);
|
||||
else
|
||||
*val = cur->vval;
|
||||
if (result == 0) {
|
||||
/* We found it. */
|
||||
if (cur->vptr)
|
||||
*val = *(cur->vptr);
|
||||
else
|
||||
*val = cur->vval;
|
||||
|
||||
/* return now */
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
/* return now */
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* If we got here, we did not find the item in the list */
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
|
||||
/* If we got here, we did not find the item in the list */
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
|
||||
/* Add an address to the list */
|
||||
int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr)
|
||||
{
|
||||
exprVal *tmp;
|
||||
exprVal *cur;
|
||||
int result;
|
||||
int exprValListAddAddress(exprValList * vlist, char *name, EXPRTYPE * addr)
|
||||
{
|
||||
exprVal *tmp;
|
||||
exprVal *cur;
|
||||
int result;
|
||||
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
/* Make sure the name is valid */
|
||||
if(!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
/* Make sure the name is valid */
|
||||
if (!exprValidIdent(name))
|
||||
return EXPR_ERROR_BADIDENTIFIER;
|
||||
|
||||
if(vlist->head == NULL)
|
||||
{
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
|
||||
if (vlist->head == NULL) {
|
||||
/* Create the node right here */
|
||||
tmp = exprCreateVal(name, (EXPRTYPE) 0.0, addr);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
vlist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
vlist->head = tmp;
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* See if it already exists */
|
||||
cur = vlist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->vname);
|
||||
/* See if it already exists */
|
||||
cur = vlist->head;
|
||||
|
||||
if(result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* Add it to the list */
|
||||
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if(tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = vlist->head;
|
||||
vlist->head = tmp;
|
||||
if (result == 0)
|
||||
return EXPR_ERROR_ALREADYEXISTS;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* Add it to the list */
|
||||
tmp = exprCreateVal(name, (EXPRTYPE) 0.0, addr);
|
||||
|
||||
if (tmp == NULL)
|
||||
return EXPR_ERROR_MEMORY;
|
||||
|
||||
tmp->next = vlist->head;
|
||||
vlist->head = tmp;
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* Get memory address of a variable value in a value list */
|
||||
int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr)
|
||||
{
|
||||
exprVal *cur;
|
||||
int result;
|
||||
int exprValListGetAddress(exprValList * vlist, char *name, EXPRTYPE ** addr)
|
||||
{
|
||||
exprVal *cur;
|
||||
int result;
|
||||
|
||||
/* Not found yet */
|
||||
*addr = NULL;
|
||||
/* Not found yet */
|
||||
*addr = NULL;
|
||||
|
||||
if(vlist == NULL || addr == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
if (vlist == NULL || addr == NULL)
|
||||
return EXPR_ERROR_NULLPOINTER;
|
||||
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
if (name == NULL || name[0] == '\0')
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
|
||||
/* Search for the item */
|
||||
cur = vlist->head;
|
||||
/* Search for the item */
|
||||
cur = vlist->head;
|
||||
|
||||
while(cur)
|
||||
{
|
||||
result = strcmp(name, cur->vname);
|
||||
while (cur) {
|
||||
result = strcmp(name, cur->vname);
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
/* We found it. */
|
||||
if(cur->vptr)
|
||||
*addr = cur->vptr;
|
||||
else
|
||||
*addr = &(cur->vval);
|
||||
if (result == 0) {
|
||||
/* We found it. */
|
||||
if (cur->vptr)
|
||||
*addr = cur->vptr;
|
||||
else
|
||||
*addr = &(cur->vval);
|
||||
|
||||
/* return now */
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
/* return now */
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/* If we got here, we did not find it in the list */
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
|
||||
/* If we got here, we did not find it in the list */
|
||||
return EXPR_ERROR_NOTFOUND;
|
||||
}
|
||||
|
||||
/* This function is used to enumerate the values in a value list */
|
||||
void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie)
|
||||
{
|
||||
exprVal *cur;
|
||||
|
||||
if(vlist == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Get the current item */
|
||||
cur = (exprVal*)cookie;
|
||||
|
||||
/* Find the next item */
|
||||
if(cur == NULL)
|
||||
cur = vlist->head;
|
||||
else
|
||||
cur = cur->next;
|
||||
|
||||
/* Set up the data */
|
||||
if(cur)
|
||||
{
|
||||
if(name)
|
||||
*name = cur->vname;
|
||||
|
||||
if(value)
|
||||
{
|
||||
if(cur->vptr)
|
||||
*value = *(cur->vptr);
|
||||
else
|
||||
*value = cur->vval;
|
||||
}
|
||||
|
||||
if(addr)
|
||||
{
|
||||
if(cur->vptr)
|
||||
*addr = cur->vptr;
|
||||
else
|
||||
*addr = &(cur->vval);
|
||||
}
|
||||
}
|
||||
|
||||
/* If there was no value, return NULL, otherwise, return the item */
|
||||
return (void*)cur;
|
||||
}
|
||||
void *exprValListGetNext(exprValList * vlist, char **name, EXPRTYPE * value, EXPRTYPE ** addr, void *cookie)
|
||||
{
|
||||
exprVal *cur;
|
||||
|
||||
if (vlist == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Get the current item */
|
||||
cur = (exprVal *) cookie;
|
||||
|
||||
/* Find the next item */
|
||||
if (cur == NULL)
|
||||
cur = vlist->head;
|
||||
else
|
||||
cur = cur->next;
|
||||
|
||||
/* Set up the data */
|
||||
if (cur) {
|
||||
if (name)
|
||||
*name = cur->vname;
|
||||
|
||||
if (value) {
|
||||
if (cur->vptr)
|
||||
*value = *(cur->vptr);
|
||||
else
|
||||
*value = cur->vval;
|
||||
}
|
||||
|
||||
if (addr) {
|
||||
if (cur->vptr)
|
||||
*addr = cur->vptr;
|
||||
else
|
||||
*addr = &(cur->vval);
|
||||
}
|
||||
}
|
||||
|
||||
/* If there was no value, return NULL, otherwise, return the item */
|
||||
return (void *) cur;
|
||||
}
|
||||
|
||||
/* This routine will free the value list */
|
||||
int exprValListFree(exprValList *vlist)
|
||||
{
|
||||
/* Make sure it exists, if not it is not error */
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
int exprValListFree(exprValList * vlist)
|
||||
{
|
||||
/* Make sure it exists, if not it is not error */
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
|
||||
/* Free the nodes */
|
||||
exprValListFreeData(vlist->head);
|
||||
/* Free the nodes */
|
||||
exprValListFreeData(vlist->head);
|
||||
|
||||
/* Freethe container */
|
||||
exprFreeMem(vlist);
|
||||
/* Freethe container */
|
||||
exprFreeMem(vlist);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* This routine will reset the value list to 0.0 */
|
||||
int exprValListClear(exprValList *vlist)
|
||||
{
|
||||
if(vlist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
int exprValListClear(exprValList * vlist)
|
||||
{
|
||||
if (vlist == NULL)
|
||||
return EXPR_ERROR_NOERROR;
|
||||
|
||||
exprValListResetData(vlist->head);
|
||||
exprValListResetData(vlist->head);
|
||||
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
return EXPR_ERROR_NOERROR;
|
||||
}
|
||||
|
||||
/* This routine will free any child nodes, and then free itself */
|
||||
static void exprValListFreeData(exprVal *val)
|
||||
{
|
||||
exprVal *next;
|
||||
|
||||
while(val)
|
||||
{
|
||||
/* Remember the next */
|
||||
next = val->next;
|
||||
|
||||
/* Free name */
|
||||
exprFreeMem(val->vname);
|
||||
static void exprValListFreeData(exprVal * val)
|
||||
{
|
||||
exprVal *next;
|
||||
|
||||
/* Free ourself */
|
||||
exprFreeMem(val);
|
||||
|
||||
val = next;
|
||||
}
|
||||
}
|
||||
while (val) {
|
||||
/* Remember the next */
|
||||
next = val->next;
|
||||
|
||||
/* Free name */
|
||||
exprFreeMem(val->vname);
|
||||
|
||||
/* Free ourself */
|
||||
exprFreeMem(val);
|
||||
|
||||
val = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* This routine will reset variables to 0.0 */
|
||||
static void exprValListResetData(exprVal *val)
|
||||
{
|
||||
while(val)
|
||||
{
|
||||
/* Reset data */
|
||||
if(val->vptr)
|
||||
*(val->vptr) = 0.0;
|
||||
|
||||
val->vval = 0.0;
|
||||
|
||||
val = val->next;
|
||||
}
|
||||
}
|
||||
static void exprValListResetData(exprVal * val)
|
||||
{
|
||||
while (val) {
|
||||
/* Reset data */
|
||||
if (val->vptr)
|
||||
*(val->vptr) = 0.0;
|
||||
|
||||
val->vval = 0.0;
|
||||
|
||||
val = val->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* This routine will create the value object */
|
||||
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr)
|
||||
{
|
||||
exprVal *tmp;
|
||||
char *vtmp;
|
||||
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE * addr)
|
||||
{
|
||||
exprVal *tmp;
|
||||
char *vtmp;
|
||||
|
||||
/* Name already tested in exprValListAdd */
|
||||
/* Name already tested in exprValListAdd */
|
||||
|
||||
/* Create it */
|
||||
tmp = exprAllocMem(sizeof(exprVal));
|
||||
if(tmp == NULL)
|
||||
return NULL;
|
||||
/* Create it */
|
||||
tmp = exprAllocMem(sizeof(exprVal));
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Allocate space for the name */
|
||||
vtmp = exprAllocMem(strlen(name) + 1);
|
||||
/* Allocate space for the name */
|
||||
vtmp = exprAllocMem(strlen(name) + 1);
|
||||
|
||||
if(vtmp == NULL)
|
||||
{
|
||||
exprFreeMem(tmp);
|
||||
return NULL;
|
||||
}
|
||||
if (vtmp == NULL) {
|
||||
exprFreeMem(tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Copy the data over */
|
||||
strcpy(vtmp, name);
|
||||
tmp->vname = vtmp;
|
||||
tmp->vval = val;
|
||||
tmp->vptr = addr;
|
||||
/* Copy the data over */
|
||||
strcpy(vtmp, name);
|
||||
tmp->vname = vtmp;
|
||||
tmp->vval = val;
|
||||
tmp->vptr = addr;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -33,145 +33,145 @@
|
||||
|
||||
/* Breaker function to break out of long expression functions
|
||||
such as the 'for' function */
|
||||
int breaker(exprObj *o)
|
||||
int breaker(exprObj * o)
|
||||
{
|
||||
/* Return nonzero to break out */
|
||||
return -1;
|
||||
/* Return nonzero to break out */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_STANDARD_API(expr_function)
|
||||
{
|
||||
exprObj *e = NULL;
|
||||
exprFuncList *f = NULL;
|
||||
exprValList *v = NULL;
|
||||
exprValList *c = NULL;
|
||||
EXPRTYPE last_expr;
|
||||
exprObj *e = NULL;
|
||||
exprFuncList *f = NULL;
|
||||
exprValList *v = NULL;
|
||||
exprValList *c = NULL;
|
||||
EXPRTYPE last_expr;
|
||||
const char *expr;
|
||||
int err;
|
||||
char val[512] = "", *p;
|
||||
char *m_cmd = NULL;
|
||||
size_t len;
|
||||
char val[512] = "", *p;
|
||||
char *m_cmd = NULL;
|
||||
size_t len;
|
||||
|
||||
if (switch_strlen_zero(cmd)) {
|
||||
goto error;
|
||||
}
|
||||
if (switch_strlen_zero(cmd)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = strlen(cmd) + 3;
|
||||
len = strlen(cmd) + 3;
|
||||
|
||||
|
||||
m_cmd = malloc(len);
|
||||
switch_assert(m_cmd);
|
||||
switch_copy_string(m_cmd, cmd, len);
|
||||
|
||||
for (p = m_cmd; p && *p; p++) {
|
||||
if (*p == '|') {
|
||||
*p = ';';
|
||||
}
|
||||
}
|
||||
m_cmd = malloc(len);
|
||||
switch_assert(m_cmd);
|
||||
switch_copy_string(m_cmd, cmd, len);
|
||||
|
||||
p = m_cmd + (strlen(m_cmd) - 1);
|
||||
if (*p != ';') {
|
||||
p++;
|
||||
*p = ';';
|
||||
p++;
|
||||
*p = '\0';
|
||||
}
|
||||
for (p = m_cmd; p && *p; p++) {
|
||||
if (*p == '|') {
|
||||
*p = ';';
|
||||
}
|
||||
}
|
||||
|
||||
expr = m_cmd;
|
||||
p = m_cmd + (strlen(m_cmd) - 1);
|
||||
if (*p != ';') {
|
||||
p++;
|
||||
*p = ';';
|
||||
p++;
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/* Create function list */
|
||||
err = exprFuncListCreate(&f);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
expr = m_cmd;
|
||||
|
||||
/* Init function list with internal functions */
|
||||
err = exprFuncListInit(f);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
/* Create function list */
|
||||
err = exprFuncListCreate(&f);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Add custom function */
|
||||
//err = exprFuncListAdd(f, my_func, "myfunc", 1, 1, 1, 1);
|
||||
//if (err != EXPR_ERROR_NOERROR)
|
||||
/* Init function list with internal functions */
|
||||
err = exprFuncListInit(f);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Add custom function */
|
||||
//err = exprFuncListAdd(f, my_func, "myfunc", 1, 1, 1, 1);
|
||||
//if (err != EXPR_ERROR_NOERROR)
|
||||
//goto error;
|
||||
|
||||
/* Create constant list */
|
||||
err = exprValListCreate(&c);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
/* Create constant list */
|
||||
err = exprValListCreate(&c);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Init constant list with internal constants */
|
||||
err = exprValListInit(c);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
/* Init constant list with internal constants */
|
||||
err = exprValListInit(c);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Create variable list */
|
||||
err = exprValListCreate(&v);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
/* Create variable list */
|
||||
err = exprValListCreate(&v);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Create expression object */
|
||||
err = exprCreate(&e, f, v, c, breaker, NULL);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
/* Create expression object */
|
||||
err = exprCreate(&e, f, v, c, breaker, NULL);
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Parse expression */
|
||||
err = exprParse(e, (char *)expr);
|
||||
/* Parse expression */
|
||||
err = exprParse(e, (char *) expr);
|
||||
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
if (err != EXPR_ERROR_NOERROR)
|
||||
goto error;
|
||||
|
||||
/* Enable soft errors */
|
||||
//exprSetSoftErrors(e, 1);
|
||||
|
||||
/* Enable soft errors */
|
||||
//exprSetSoftErrors(e, 1);
|
||||
|
||||
do {
|
||||
err = exprEval(e, &last_expr);
|
||||
} while (err);
|
||||
|
||||
switch_snprintf(val, sizeof(val), "%0.10f", last_expr);
|
||||
for (p = (val + strlen(val) - 1); p != val; p--) {
|
||||
if (*p != '0') {
|
||||
*(p+1) = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch_snprintf(val, sizeof(val), "%0.10f", last_expr);
|
||||
for (p = (val + strlen(val) - 1); p != val; p--) {
|
||||
if (*p != '0') {
|
||||
*(p + 1) = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p = val + strlen(val) - 1;
|
||||
if (*p == '.') {
|
||||
*p = '\0';
|
||||
}
|
||||
p = val + strlen(val) - 1;
|
||||
if (*p == '.') {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
stream->write_function(stream, "%s", val);
|
||||
stream->write_function(stream, "%s", val);
|
||||
|
||||
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
error:
|
||||
/* Alert user of error */
|
||||
stream->write_function(stream, "!err!");
|
||||
error:
|
||||
/* Alert user of error */
|
||||
stream->write_function(stream, "!err!");
|
||||
|
||||
|
||||
done:
|
||||
/* Do cleanup */
|
||||
if (e) {
|
||||
exprFree(e);
|
||||
}
|
||||
done:
|
||||
/* Do cleanup */
|
||||
if (e) {
|
||||
exprFree(e);
|
||||
}
|
||||
|
||||
if (f) {
|
||||
exprFuncListFree(f);
|
||||
}
|
||||
if (f) {
|
||||
exprFuncListFree(f);
|
||||
}
|
||||
|
||||
if (v) {
|
||||
exprValListFree(v);
|
||||
}
|
||||
if (v) {
|
||||
exprValListFree(v);
|
||||
}
|
||||
|
||||
if (c) {
|
||||
exprValListFree(c);
|
||||
}
|
||||
if (c) {
|
||||
exprValListFree(c);
|
||||
}
|
||||
|
||||
switch_safe_free(m_cmd);
|
||||
switch_safe_free(m_cmd);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -181,10 +181,10 @@ SWITCH_MODULE_DEFINITION(mod_expr, mod_expr_load, NULL, NULL);
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_expr_load)
|
||||
{
|
||||
switch_api_interface_t *commands_api_interface;
|
||||
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
SWITCH_ADD_API(commands_api_interface, "expr", "Eval an expession", expr_function, "<expr>");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user