diff options
Diffstat (limited to 'src/fe-text')
-rw-r--r-- | src/fe-text/textbuffer.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 979a6104..ae4636a5 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -27,6 +27,10 @@ #include "textbuffer.h" +#ifndef USE_GREGEX +# include <regex.h> +#endif + #define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*)) TEXT_BUFFER_REC *textbuffer_create(void) @@ -533,7 +537,11 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, int before, int after, int regexp, int fullword, int case_sensitive) { +#ifdef USE_GREGEX GRegex *preg; +#else + regex_t preg; +#endif LINE_REC *line, *pre_line; GList *matches; GString *str; @@ -543,6 +551,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, g_return_val_if_fail(buffer != NULL, NULL); g_return_val_if_fail(text != NULL, NULL); +#ifdef USE_GREGEX preg = NULL; if (regexp) { @@ -551,6 +560,14 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, if (preg == NULL) return NULL; } +#else + if (regexp) { + int flags = REG_EXTENDED | REG_NOSUB | + (case_sensitive ? 0 : REG_ICASE); + if (regcomp(&preg, text, flags) != 0) + return NULL; + } +#endif matches = NULL; match_after = 0; str = g_string_new(NULL); @@ -571,8 +588,12 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, if (line_matched) { line_matched = regexp ? - g_regex_match(preg, str->str, 0, NULL) : - match_func(str->str, text) != NULL; +#ifdef USE_GREGEX + g_regex_match(preg, str->str, 0, NULL) +#else + regexec(&preg, str->str, 0, NULL, 0) == 0 +#endif + : match_func(str->str, text) != NULL; } } @@ -602,8 +623,12 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, } } +#ifdef USE_GREGEX if (preg != NULL) g_regex_unref(preg); +#else + if (regexp) regfree(&preg); +#endif g_string_free(str, TRUE); return matches; } |