From db350988f0ab0b57f6a4aed0da20b5f41499690f Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 29 May 2012 10:45:44 +0200 Subject: first experiments with regexp'es in RainerScript --- grammar/rainerscript.c | 17 ++++++++++++++++- grammar/rainerscript.h | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'grammar') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 320e66d0..ce0298fb 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -839,6 +839,11 @@ doFuncCall(struct cnffunc *func, struct var *ret, void* usrptr) } ret->datatype = 'N'; break; + case CNFFUNC_RE_MATCH: + dbgprintf("TODO: implement re_match()\n"); + ret->d.n = 1; + ret->datatype = 'N'; + break; default: if(Debug) { fname = es_str2cstr(func->fname, NULL); @@ -892,7 +897,7 @@ cnfexprEval(struct cnfexpr *expr, struct var *ret, void* usrptr) int bMustFree, bMustFree2; long long n_r, n_l; - //dbgprintf("eval expr %p, type '%c'(%u)\n", expr, expr->nodetype, expr->nodetype); + dbgprintf("eval expr %p, type '%c'(%u)\n", expr, expr->nodetype, expr->nodetype); switch(expr->nodetype) { /* note: comparison operations are extremely similar. The code can be copyied, only * places flagged with "CMP" need to be changed. @@ -1450,6 +1455,9 @@ cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next) static inline enum cnffuncid funcName2ID(es_str_t *fname, unsigned short nParams) { +{ char *s;s=es_str2cstr(fname, NULL); +dbgprintf("ZZZZ: func: '%s', nParams: %d\n", s, nParams); +free(s);} if(!es_strbufcmp(fname, (unsigned char*)"strlen", sizeof("strlen") - 1)) { if(nParams != 1) { parser_errmsg("number of parameters for strlen() must be one " @@ -1485,6 +1493,13 @@ funcName2ID(es_str_t *fname, unsigned short nParams) return CNFFUNC_INVALID; } return CNFFUNC_CNUM; + } else if(!es_strbufcmp(fname, (unsigned char*)"re_match", sizeof("re_match") - 1)) { + if(nParams != 2) { + parser_errmsg("number of parameters for re_match() must be two " + "but is %d.", nParams); + return CNFFUNC_INVALID; + } + return CNFFUNC_RE_MATCH; } else { return CNFFUNC_INVALID; } diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index e11ae62f..07e6af0b 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -163,7 +163,8 @@ enum cnffuncid { CNFFUNC_GETENV, CNFFUNC_TOLOWER, CNFFUNC_CSTR, - CNFFUNC_CNUM + CNFFUNC_CNUM, + CNFFUNC_RE_MATCH }; struct cnffunc { -- cgit