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, 24 insertions, 9 deletions
diff --git a/src/rexp.c b/src/rexp.c
index 0311c44..3e51aa6 100644
--- a/src/rexp.c
+++ b/src/rexp.c
@@ -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);
+ }
}