diff options
author | LemonBoy <thatlemon@gmail.com> | 2016-01-14 14:10:00 +0100 |
---|---|---|
committer | Ailin Nemui <ailin@z30a.localdomain> | 2017-01-02 17:50:14 +0100 |
commit | 8e5db471e4d8b052f072ce8a351222c6edb42d19 (patch) | |
tree | d2eb11ae5ef3440db5e23ffbfcb433bb220f29d7 /src/core | |
parent | 91f48c6f0e03e53c0968a5433d672ea966006e59 (diff) | |
download | irssi-8e5db471e4d8b052f072ce8a351222c6edb42d19.zip |
Use GLib's regexp interface (backed by PCRE)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ignore.c | 35 | ||||
-rw-r--r-- | src/core/ignore.h | 8 | ||||
-rw-r--r-- | src/core/misc.c | 4 |
3 files changed, 14 insertions, 33 deletions
diff --git a/src/core/ignore.c b/src/core/ignore.c index 2047dc9d..2b8299bd 100644 --- a/src/core/ignore.c +++ b/src/core/ignore.c @@ -67,12 +67,8 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text) return FALSE; if (rec->regexp) { -#ifdef HAVE_REGEX_H return rec->regexp_compiled && - regexec(&rec->preg, text, 0, NULL, 0) == 0; -#else - return FALSE; -#endif + g_regex_match(rec->preg, text, 0, NULL); } return rec->fullword ? @@ -326,26 +322,23 @@ static void ignore_remove_config(IGNORE_REC *rec) static void ignore_init_rec(IGNORE_REC *rec) { -#ifdef HAVE_REGEX_H - char *errbuf; - int errcode, errbuf_len; + if (rec->regexp_compiled) { + g_regex_unref(rec->preg); + rec->regexp_compiled = FALSE; + } - if (rec->regexp_compiled) regfree(&rec->preg); - rec->regexp_compiled = FALSE; if (rec->regexp && rec->pattern != NULL) { - errcode = regcomp(&rec->preg, rec->pattern, - REG_EXTENDED|REG_ICASE|REG_NOSUB); - if (errcode != 0) { - errbuf_len = regerror(errcode, &rec->preg, 0, 0); - errbuf = g_malloc(errbuf_len); - regerror(errcode, &rec->preg, errbuf, errbuf_len); - g_warning("Failed to compile regexp '%s': %s", rec->pattern, errbuf); - g_free(errbuf); + GError *re_error; + + rec->preg = g_regex_new(rec->pattern, G_REGEX_CASELESS, 0, &re_error); + + if (rec->preg == NULL) { + g_warning("Failed to compile regexp '%s': %s", rec->pattern, re_error->message); + g_error_free(re_error); } else { rec->regexp_compiled = TRUE; } } -#endif } void ignore_add_rec(IGNORE_REC *rec) @@ -365,9 +358,7 @@ static void ignore_destroy(IGNORE_REC *rec, int send_signal) if (send_signal) signal_emit("ignore destroyed", 1, rec); -#ifdef HAVE_REGEX_H - if (rec->regexp_compiled) regfree(&rec->preg); -#endif + if (rec->regexp_compiled) g_regex_unref(rec->preg); if (rec->channels != NULL) g_strfreev(rec->channels); g_free_not_null(rec->mask); g_free_not_null(rec->servertag); diff --git a/src/core/ignore.h b/src/core/ignore.h index f889740f..6c9797f5 100644 --- a/src/core/ignore.h +++ b/src/core/ignore.h @@ -1,10 +1,6 @@ #ifndef __IGNORE_H #define __IGNORE_H -#ifdef HAVE_REGEX_H -# include <regex.h> -#endif - typedef struct _IGNORE_REC IGNORE_REC; struct _IGNORE_REC { @@ -20,10 +16,8 @@ struct _IGNORE_REC { unsigned int regexp:1; unsigned int fullword:1; unsigned int replies:1; /* ignore replies to nick in channel */ -#ifdef HAVE_REGEX_H unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */ - regex_t preg; -#endif + GRegex *preg; }; extern GSList *ignores; diff --git a/src/core/misc.c b/src/core/misc.c index 0bb1f7e6..c59eb126 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -22,10 +22,6 @@ #include "misc.h" #include "commands.h" -#ifdef HAVE_REGEX_H -# include <regex.h> -#endif - typedef struct { int condition; GInputFunction function; |