summaryrefslogtreecommitdiff
path: root/src/rexp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rexp.c')
-rw-r--r--src/rexp.c33
1 files changed, 29 insertions, 4 deletions
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);
}
}