From f3a485b283141787667ea98b8e0a8687f07d9062 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 1 Jan 2004 01:25:04 +0000 Subject: A few tweaks and added an extra variable (showmatch) --- src/rexp.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/rexp.c') diff --git a/src/rexp.c b/src/rexp.c index 3e51aa6..effa882 100644 --- a/src/rexp.c +++ b/src/rexp.c @@ -33,13 +33,23 @@ static const char id[]="$Id$"; #include "config.h" #include "util.h" +static const char header_id[]=KBS_REXP_H; + + +/* ---------------------------------------- TYPES +*/ +struct RE_Expression +{ + regex_t re; + char *expr; +}; /* ---------------------------------------- INTERFACES */ RE_Expression RECompile(const char *regexpr) { - regex_t *re; + RE_Expression re; int flags; re=Malloc(sizeof *re); @@ -49,11 +59,15 @@ RE_Expression RECompile(const char *regexpr) if (!ConfigInt(CONFIG_CASESENSE)) flags|=REG_ICASE; - if (regcomp(re,regexpr,flags)) + if (regcomp(&re->re,regexpr,flags)) { free(re); re=NULL; } + else + { + re->expr=CopyStr(regexpr); + } return re; } @@ -61,7 +75,17 @@ RE_Expression RECompile(const char *regexpr) int RESearch(const RE_Expression re, const char *string) { - return !regexec(re,string,0,NULL,0); + int ret; + + ret=regexec(&re->re,string,0,NULL,0); + + return !ret; +} + + +const char *REGetExpression(const RE_Expression re) +{ + return re->expr; } @@ -69,7 +93,8 @@ void REFree(RE_Expression re) { if (re) { - regfree(re); + regfree(&re->re); + free(re->expr); free(re); } } -- cgit v1.2.3