0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef __EXPR_H
0037 #define __EXPR_H
0038
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042
0043
0044 #include <ubf.h>
0045 #include <ndrstandard.h>
0046 #include <sys/types.h>
0047 #include <regex.h>
0048 #include <ubf_int.h>
0049 #include <exhash.h>
0050
0051
0052
0053 #ifndef EXTRUE
0054 #define EXTRUE 1
0055 #endif
0056
0057 #ifndef EXFALSE
0058 #define EXFALSE 0
0059 #endif
0060
0061 #define MAX_TEXT 511
0062
0063 #define OCC_ANY -2
0064 #define MAX_FUNC_NAME 66
0065
0066 #define NDRX_CBFUNTYPE_NOARGS 1
0067 #define NDRX_CBFUNTYPE_ARG1 2
0068
0069 typedef long (*functionPtr_t)(UBFH *p_ub, char *funcname);
0070 typedef long (*functionPtr2_t)(UBFH *p_ub, char *funcname, char *arg1);
0071
0072
0073
0074 #define NODE_TYPE_OR 0
0075 #define NODE_TYPE_AND 1
0076 #define NODE_TYPE_XOR 2
0077 #define NODE_TYPE_EQOP 3
0078 #define NODE_TYPE_RELOP 4
0079 #define NODE_TYPE_ADDOP 5
0080 #define NODE_TYPE_MULTOP 6
0081 #define NODE_TYPE_UNARY 7
0082 #define NODE_TYPE_FLD 8
0083 #define NODE_TYPE_STR 9
0084 #define NODE_TYPE_FLOAT 10
0085 #define NODE_TYPE_LONG 11
0086 #define NODE_TYPE_FUNC 12
0087
0088
0089
0090
0091 #define NODE_SUB_TYPE_DEF 0
0092
0093 #define EQOP_EQUAL 1
0094 #define EQOP_NOT_EQUAL 2
0095 #define EQOP_REGEX_EQUAL 3
0096 #define EQOP_REGEX_NOT_EQUAL 4
0097
0098 #define RELOP_LESS 5
0099 #define RELOP_LESS_EQUAL 6
0100 #define RELOP_GREATER 7
0101 #define RELOP_GREATER_EQUAL 8
0102
0103 #define ADDOP_PLUS 9
0104 #define ADDOP_MINUS 10
0105
0106 #define UNARY_CMPL 11
0107 #define UNARY_INV 12
0108
0109 #define MULOP_DOT 13
0110 #define MULOP_DIV 14
0111 #define MULOP_MOD 15
0112
0113 #define SUB_OR_OP 16
0114 #define SUB_AND_OP 17
0115 #define SUB_XOR_OP 18
0116
0117
0118
0119 #define VALUE_TYPE_BOOL 0
0120 #define VALUE_TYPE_LONG 1
0121 #define VALUE_TYPE_FLOAT 2
0122
0123 #define VALUE_TYPE_FLD_STR 3
0124
0125 #define VALUE_TYPE_STRING 4
0126
0127
0128
0129
0130
0131
0132 typedef struct {
0133 char funcname[MAX_FUNC_NAME+1];
0134 char arg1[MAX_TEXT+1];
0135 } ndrx_symbfunc_t;
0136
0137
0138
0139 struct symbol
0140 {
0141 char *name;
0142 double value;
0143
0144 char strval[MAX_TEXT+1];
0145 ndrx_ubf_rfldid_t fld;
0146 ndrx_symbfunc_t *funccall;
0147 };
0148
0149
0150 struct func_hash {
0151 char name[MAX_FUNC_NAME+1];
0152 void *fptr;
0153 int functype;
0154 EX_hash_handle hh;
0155 };
0156 typedef struct func_hash func_hash_t;
0157
0158
0159
0160
0161 typedef struct {
0162 int compiled;
0163 regex_t re;
0164 } regex_compl_t;
0165
0166 struct ast {
0167 int nodetype;
0168 int sub_type;
0169 int nodeid;
0170 struct ast *l;
0171 struct ast *r;
0172 };
0173
0174 struct ast_fld {
0175 int nodetype;
0176 int sub_type;
0177 int nodeid;
0178 ndrx_ubf_rfldid_t fld;
0179 };
0180
0181
0182 struct ast_func {
0183 int nodetype;
0184 int sub_type;
0185 int nodeid;
0186 func_hash_t *f;
0187 ndrx_symbfunc_t* funcall;
0188 };
0189
0190 struct ast_string {
0191 int nodetype;
0192 int sub_type;
0193 int nodeid;
0194
0195 char *str;
0196 size_t str_bufsz;
0197 regex_compl_t regex;
0198 };
0199
0200 struct ast_long {
0201 int nodetype;
0202 int sub_type;
0203 int nodeid;
0204 long l;
0205 };
0206
0207 struct ast_float {
0208 int nodetype;
0209 int sub_type;
0210 int nodeid;
0211 double d;
0212 };
0213
0214 typedef struct {
0215 short dyn_alloc;
0216 short value_type;
0217 int is_null;
0218 short boolval;
0219 long longval;
0220 double floatval;
0221
0222 char *strval;
0223 } value_block_t;
0224
0225
0226 struct list_node {
0227 char *mem;
0228 struct list_node *next;
0229 };
0230
0231
0232
0233
0234
0235
0236 struct ast *newast(int nodetype, int sub_type, struct ast *l, struct ast *r);
0237
0238 struct ast *newfld(ndrx_ubf_rfldid_t f);
0239 struct ast *newstring(char *str);
0240 struct ast *newfloat(double d);
0241 struct ast *newlong(long l);
0242 struct ast *newfunc(ndrx_symbfunc_t *funcname);
0243
0244
0245 int eval(UBFH *p_ub, struct ast *a, value_block_t *v);
0246
0247
0248 void treefree(struct ast *);
0249
0250
0251 extern int yylineno;
0252 void yyerror(char *s, ...);
0253
0254 extern int debug;
0255 void dumpast(struct ast *a, int level);
0256
0257 extern char * ndrx_Bboolco (char * expr);
0258 extern int ndrx_Bboolev (UBFH * p_ub, char *tree);
0259 extern double ndrx_Bfloatev (UBFH * p_ub, char *tree);
0260 extern void ndrx_Btreefree (char *tree);
0261
0262 extern __thread struct ast *G_p_root_node;
0263 extern __thread int G_node_count;
0264 extern __thread int G_error;
0265
0266 #ifdef __cplusplus
0267 }
0268 #endif
0269
0270 #endif
0271