X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Frx.c;h=8604ad5412292188fe3511998b31bd6ed27ca98d;hp=f2b672070143adac3b230a6b4da101b3da5f1507;hb=8336b26fc23c7943bf6681ba2c290bb5cd2c54b8;hpb=230399f9632c37b66c1c117a17e8327eae6b3235 diff --git a/lib-lib/rx.c b/lib-lib/rx.c index f2b6720..8604ad5 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -22,11 +22,7 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include +#include "lib-lib.h" rx_t *rx_compile(const char *s, int flags) { @@ -42,42 +38,61 @@ rx_t *rx_compile(const char *s, int flags) return pp; } +void rx_set_template(rx_t *rx, const char *tpl) +{ + const char *p = tpl; + + m_strreplace(&rx->template, tpl); + rx->nmatch = 0; + + while ((p = strchr(p, '%'))) { + if (isdigit(*++p)) { + int n = strtol(p, (char **)&p, 10); + rx->nmatch = MAX(n, rx->nmatch); + } else { + if (*p == '%') + p++; + } + } + + rx->nmatch++; /* match 0 is always the whole expr */ +} + void rx_delete(rx_t **p) { p_delete(&(*p)->pattern); regfree((*p)->rx); p_delete(&(*p)->rx); + p_delete(&(*p)->template); 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) { - int i; - - if (!pat || !*pat || list_empty(l)) - return -1; + if (!pat || !*pat) + return NULL; - for (i = 0; i < l->length; i++) { - if (!strcmp(((rx_t*)l->data[i])->pattern, pat)) - return i; + while (*l) { + if (!strcmp((*l)->pattern, pat)) + return l; + l = &(*l)->next; } - return -1; + return NULL; } int rx_sanitize_string(char *dst, ssize_t n, const char *src)