summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c4
-rw-r--r--regexset.c8
-rw-r--r--regexset.h2
3 files changed, 12 insertions, 2 deletions
diff --git a/main.c b/main.c
index f5b743b..d32b091 100644
--- a/main.c
+++ b/main.c
@@ -46,7 +46,7 @@ int main(int argc, char **argv) {
int rc;
int ovector[30];
- rc = pcre_exec(rs->text, NULL, line, strlen(line), 0, 0, ovector, 30);
+ rc = pcre_exec(rs->text, rs->text_e, line, strlen(line), 0, 0, ovector, 30);
if(rc > 0) {
char nick[NICK_BUFFER_SIZE], text[TEXT_BUFFER_SIZE];
pcre_copy_named_substring(rs->text, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
@@ -85,7 +85,7 @@ int main(int argc, char **argv) {
continue;
}
- rc = pcre_exec(rs->join, NULL, line, strlen(line), 0, 0, ovector, 30);
+ rc = pcre_exec(rs->join, rs->join_e, line, strlen(line), 0, 0, ovector, 30);
if(rc > 0) {
char nick[NICK_BUFFER_SIZE];
pcre_copy_named_substring(rs->join, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
diff --git a/regexset.c b/regexset.c
index 657978a..c816217 100644
--- a/regexset.c
+++ b/regexset.c
@@ -39,15 +39,19 @@ struct regexset_t *rs_add(const char *text, const char *join) {
re_error("text", text, error, erroffset);
return NULL;
}
+ rs->text_e = pcre_study(rs->text, 0, &error);
/* Free compiled patterns from this point when failing. */
rs->join = pcre_compile(join, 0, &error, &erroffset, NULL);
if(rs->join == NULL) {
pcre_free(rs->text);
+ if(rs->text_e)
+ pcre_free(rs->text_e);
re_error("join", join, error, erroffset);
return NULL;
}
+ rs->join_e = pcre_study(rs->join, 0, &error);
return rs;
}
@@ -59,7 +63,11 @@ struct regexset_t *rs_get(int index) {
void rs_free() {
for(int i = 0; i < rs_count; i++) {
pcre_free(regexes[i].text);
+ if(regexes[i].text_e)
+ pcre_free(regexes[i].text_e);
pcre_free(regexes[i].join);
+ if(regexes[i].join_e)
+ pcre_free(regexes[i].join_e);
}
free(regexes);
regexes = NULL;
diff --git a/regexset.h b/regexset.h
index 14d158f..2c49e69 100644
--- a/regexset.h
+++ b/regexset.h
@@ -5,7 +5,9 @@
struct regexset_t {
pcre *text;
+ pcre_extra *text_e;
pcre *join;
+ pcre_extra *join_e;
};
void rs_init();