diff options
| author | Ian C <ianc@noddybox.co.uk> | 2003-12-07 01:46:44 +0000 |
|---|---|---|
| committer | Ian C <ianc@noddybox.co.uk> | 2003-12-07 01:46:44 +0000 |
| commit | 787bb7625c9abc6b09efbc6bbe004a19d4b96166 (patch) | |
| tree | 87b38cae639ced0b5a705a3d1e45d977ea419756 /src/rexp.c | |
| parent | f1658930db64af8fecff9c8697592f676114409c (diff) | |
Made RE compiled once and added memory release
Diffstat (limited to 'src/rexp.c')
| -rw-r--r-- | src/rexp.c | 33 |
1 files changed, 24 insertions, 9 deletions
@@ -31,32 +31,47 @@ static const char id[]="$Id$"; #include "global.h" #include "rexp.h" #include "config.h" +#include "util.h" /* ---------------------------------------- INTERFACES */ -RExpStatus RExpSearch(const char *regexpr, const char *string) +RE_Expression RECompile(const char *regexpr) { - regex_t re; + regex_t *re; int flags; - int res; + + re=Malloc(sizeof *re); flags=REG_EXTENDED|REG_NOSUB; if (!ConfigInt(CONFIG_CASESENSE)) flags|=REG_ICASE; - if (regcomp(&re,regexpr,flags)) - return RE_BadExpression; + if (regcomp(re,regexpr,flags)) + { + free(re); + re=NULL; + } + + return re; +} - res=regexec(&re,string,0,NULL,0); - regfree(&re); +int RESearch(const RE_Expression re, const char *string) +{ + return !regexec(re,string,0,NULL,0); +} - /* printf("RExpSearch(%s,%s)=%d\n",regexpr,string,res); */ - return res ? RE_NotFound : RE_Found; +void REFree(RE_Expression re) +{ + if (re) + { + regfree(re); + free(re); + } } |
