X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Frx.c;h=8604ad5412292188fe3511998b31bd6ed27ca98d;hp=d0a394238a59bfa9ff78e67fdf3674b68c0f706a;hb=9fde23d2b9a4ba8076eb425a1af4342de1e485b5;hpb=c8b8b9539aaf11b48c4c1e5baba434db09722111;ds=sidebyside 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); }