summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAilin Nemui <ailin@z30a.localdomain>2017-01-03 12:04:56 +0100
committerAilin Nemui <ailin@z30a.localdomain>2017-01-03 12:29:11 +0100
commitf5cbbebc2ee858e8792ab40eea6abc9fd7865a28 (patch)
treedf681ebf49587a386f7048ac994af8b2ebf9d405 /src/core
parent5dcf291f2144564363f734dba15760d3a82b61c2 (diff)
downloadirssi-f5cbbebc2ee858e8792ab40eea6abc9fd7865a28.zip
switch for gregex and regex.h
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ignore.c31
-rw-r--r--src/core/ignore.h9
-rw-r--r--src/core/misc.c4
3 files changed, 44 insertions, 0 deletions
diff --git a/src/core/ignore.c b/src/core/ignore.c
index cfcbd792..bf8db04f 100644
--- a/src/core/ignore.c
+++ b/src/core/ignore.c
@@ -67,8 +67,13 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
return FALSE;
if (rec->regexp) {
+#ifdef USE_GREGEX
return rec->preg != NULL &&
g_regex_match(rec->preg, text, 0, NULL);
+#else
+ return rec->regexp_compiled &&
+ regexec(&rec->preg, text, 0, NULL, 0) == 0;
+#endif
}
return rec->fullword ?
@@ -322,6 +327,7 @@ static void ignore_remove_config(IGNORE_REC *rec)
static void ignore_init_rec(IGNORE_REC *rec)
{
+#ifdef USE_GREGEX
if (rec->preg != NULL)
g_regex_unref(rec->preg);
@@ -335,6 +341,27 @@ static void ignore_init_rec(IGNORE_REC *rec)
g_error_free(re_error);
}
}
+#else
+ char *errbuf;
+ int errcode, errbuf_len;
+
+ 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);
+ } else {
+ rec->regexp_compiled = TRUE;
+ }
+ }
+#endif
}
void ignore_add_rec(IGNORE_REC *rec)
@@ -354,7 +381,11 @@ static void ignore_destroy(IGNORE_REC *rec, int send_signal)
if (send_signal)
signal_emit("ignore destroyed", 1, rec);
+#ifdef USE_GREGEX
if (rec->preg != NULL) g_regex_unref(rec->preg);
+#else
+ if (rec->regexp_compiled) regfree(&rec->preg);
+#endif
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 f37f8b28..80ae1d12 100644
--- a/src/core/ignore.h
+++ b/src/core/ignore.h
@@ -1,6 +1,10 @@
#ifndef __IGNORE_H
#define __IGNORE_H
+#ifndef USE_GREGEX
+# include <regex.h>
+#endif
+
typedef struct _IGNORE_REC IGNORE_REC;
struct _IGNORE_REC {
@@ -16,7 +20,12 @@ struct _IGNORE_REC {
unsigned int regexp:1;
unsigned int fullword:1;
unsigned int replies:1; /* ignore replies to nick in channel */
+#ifdef USE_GREGEX
GRegex *preg;
+#else
+ unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */
+ regex_t preg;
+#endif
};
extern GSList *ignores;
diff --git a/src/core/misc.c b/src/core/misc.c
index c59eb126..1cfa15b6 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -22,6 +22,10 @@
#include "misc.h"
#include "commands.h"
+#ifndef USE_GREGEX
+# include <regex.h>
+#endif
+
typedef struct {
int condition;
GInputFunction function;