cndxparse
Creates an expression tree for later evaluation.
Declaration
PTREE cndxparse( pConvMap Schema, pTEXT Names, pTEXT InputText, NINT InputTextSize )
Description
You can use the FairCom DB expression parser/analyzer to evaluate expressions. For a complete sample program, see ctexpr.c in the ctree/source directory.
Where:
Using the FairCom DB expression parser/analyzer involves two steps:
Return Values
Returns a PTREE parse tree on success. NULL if error.
Example
#include "ctcndx.h" /* For PTREE type */
/* Define a DODA structure. */
DATOBJ doda[] = {
{"CustomerNumber", 0, CT_INT4U},
{"ZipCode", 4, CT_FSTRING, 9},
{"State", 13, CT_FSTRING, 2},
{"LastName", 15, CT_STRING, 37},
{"FirstName", 52, CT_STRING, 37},
{"Address", 89, CT_STRING, 49},
{"City", 138, CT_STRING, 37}
};
COUNT retval; /* Return code. */
pTEXT schema; /* Record schema. */
pTEXT names; /* Field name list. */
PTREE ptree; /* Expression tree. */
pTEXT expr; /* Expression string. */
/* Parse the DODA into a record schema and field name list. */
if ((retval = ctparsedoda(doda, 7, &schema, &names)) != 0)
printf("Error %d parsing DODA.\n", retval);
/* Parse your expression to produce an expression tree. */
expr = "stricmp(LastName, \"Smith\") == 0
&& CustomerNumber > 10000";
ptree = cndxparse(schema, names, expr, strlen(expr));
if (!ptree)
printf("Error: Unable to parse expression.\n");
else
printf("Successfully parsed expression.\n");
...
if ( ptree )
cndxfree (ptree);
See also
cndxeval, cndxfree, ctparsedoda, cndxrun, getcndxmem, putcndxmem