diff options
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | regexset.c | 8 | ||||
-rw-r--r-- | regexset.h | 2 |
3 files changed, 12 insertions, 2 deletions
@@ -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); @@ -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; @@ -5,7 +5,9 @@ struct regexset_t { pcre *text; + pcre_extra *text_e; pcre *join; + pcre_extra *join_e; }; void rs_init(); |