X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-lib%2Frx.c;h=8604ad5412292188fe3511998b31bd6ed27ca98d;hb=7e6ea12f3d017b6a04d86862e42ef3fd23780d8e;hp=d0a394238a59bfa9ff78e67fdf3674b68c0f706a;hpb=5a4df9d0e93209aeade80f632158036799f3e9bc;p=apps%2Fmadmutt.git diff --git a/lib-lib/rx.c b/lib-lib/rx.c index d0a3942..8604ad5 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -38,11 +38,32 @@ 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); }