Evaluates an expression tree produced by cndxeval().
Declaration
COUNT cndxeval( PTREE Tree, pVOID Recptr, pConvMap Schema, VRLEN fixlen, VRLEN datlen )Description
Where:
- Tree - parse tree generated by cndxparse()
- Recptr - pointer to a record handle
- Schema - record schema
- fixlen - Fixed record length
- datlen - total record length
Evaluating your expression involves three steps:
- Allocate a run-time stack for the expression analyzer (first time only).
- Set up a buffer containing the field data used in the expression.
- Evaluate the expression.
If you wish, you can repeat steps b) and c) multiple times. Sample code to perform these steps is shown below. It is assumed the Get_Buffer() routine allocates a record buffer and initializes it with data conforming to the field definitions specified in the DODA.
Return Values
| Value | Symbolic Constant | Explanation |
|---|---|---|
| 1 | YES | Expression evaluated as true |
| 0 | NO | Expression evaluated as false |
Example
COUNT retcidx; /* Result of expression evaluation. */
pTEXT recbuf; /* Record buffer. */
/* Allocate a run-time stack for the expression analyzer (first time only). */
if (!ctcidxStk) {
ctcidxStk = (pVOID) getcndxmem(CNDX_MAX_STACK * ctSIZE(PLEAF));
if (!ctcidxStk) {
printf("Unable to allocate memory for run-time stack.\n");
ctrt_exit(1);
}
}
/* Set up a buffer containing the field data used in the expression. */
Get_Buffer(&recbuf);
/* Evaluate the expression. */
retcidx = cndxeval(ptree, recbuf, (pConvMap)schema);
if (retcidx < 0)
printf("The expression cannot be evaluated for this record
- error %d.\n", uerr_cod);
else if (retcidx)
printf("The expression evaluates to TRUE for this record.\n");
else
printf("The expression evaluates to FALSE for this record.\n");See also
cndxfree, cndxparse, ctparsedoda, cndxrun, getcndxmem, putcndxmem