X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-lib%2Frx.c;h=d0a394238a59bfa9ff78e67fdf3674b68c0f706a;hb=676b896e26b7aeef16d95aba7a5ea9322d2dc6e1;hp=6413f69c88fa81c9e4f962be07459986623a39ab;hpb=03fe827a7d4a7ad79ac235654414aa339a9a2c9a;p=apps%2Fmadmutt.git diff --git a/lib-lib/rx.c b/lib-lib/rx.c index 6413f69..d0a3942 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -22,13 +22,7 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include +#include "lib-lib.h" rx_t *rx_compile(const char *s, int flags) { @@ -52,32 +46,54 @@ void rx_delete(rx_t **p) p_delete(p); } -int rx_list_match(list2_t *l, const char *pat) +int rx_list_match(rx_t *l, const char *pat) { - int i; - - if (!pat || !*pat || list_empty(l)) + if (!pat || !*pat) return 0; - for (i = 0; i < l->length; i++) { - if (!REGEXEC(((rx_t*)l->data[i])->rx, pat)) + while (l) { + if (!REGEXEC(l->rx, pat)) return 1; + l = l->next; } return 0; } -int rx_lookup (list2_t *l, const char *pat) +rx_t **rx_lookup(rx_t **l, const char *pat) +{ + if (!pat || !*pat) + return NULL; + + while (*l) { + if (!strcmp((*l)->pattern, pat)) + return l; + l = &(*l)->next; + } + + return NULL; +} + +int rx_sanitize_string(char *dst, ssize_t n, const char *src) { - int i; + while (*src) { + if (n <= 1) + break; - if (!pat || !*pat || list_empty(l)) - return -1; + /* these characters must be escaped in regular expressions */ + if (strchr("^.[$()|*+?{\\", *src)) { + if (n <= 2) + break; - for (i = 0; i < l->length; i++) { - if (!strcmp(((rx_t*)l->data[i])->pattern, pat)) - return i; + *dst++ = '\\'; + n--; + } + + *dst++ = *src++; + n--; } - return -1; + *dst = '\0'; + + return *src ? -1 : 0; }