X-Git-Url: https://git.distorted.org.uk/~mdw/anag/blobdiff_plain/0279756ef8eb60878927c9e325a9ad25a4b0f150..7c2b74abc8bbc3b009a233b65d4f8aa23219892d:/pcre.c diff --git a/pcre.c b/pcre.c index f15e37a..5c5994c 100644 --- a/pcre.c +++ b/pcre.c @@ -26,15 +26,8 @@ /*----- Header files ------------------------------------------------------*/ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifndef HAVE_PCRE - extern int dummy; -#else - #include "anag.h" + #include /*----- Data structures ---------------------------------------------------*/ @@ -58,12 +51,9 @@ static int n_pcre(node *nn, const char *p, size_t sz) int e; e = pcre_exec(n->rx, n->rx_study, p, sz, 0, 0, n->ovec, n->ovecsz); - if (e >= 0) - return (1); - if (e == PCRE_ERROR_NOMATCH) - return (0); + if (e >= 0) return (1); + if (e == PCRE_ERROR_NOMATCH) return (0); die("unexpected PCRE error code %d", e); - return (-1); } /* --- Node creation --- */ @@ -76,17 +66,16 @@ node *pcrenode(const char *const *av) int c; n->n.func = n_pcre; - if ((n->rx = pcre_compile(av[0], PCRE_CASELESS, &e, &eo, 0)) == 0) - die("bad regular expression `%s': %s", av[0], e); + + n->rx = pcre_compile(av[0], PCRE_CASELESS, &e, &eo, 0); + if (!n->rx) die("bad regular expression `%s': %s", av[0], e); n->rx_study = pcre_study(n->rx, 0, &e); - if (e) - die("error studying pattern `%s': %s", av[0], e); - pcre_fullinfo(n->rx, n->rx_study, PCRE_INFO_BACKREFMAX, &c); - n->ovecsz = c * 2; - n->ovec = xmalloc(n->ovecsz * sizeof(*n->ovec)); + if (e) die("error studying pattern `%s': %s", av[0], e); + pcre_fullinfo(n->rx, n->rx_study, PCRE_INFO_CAPTURECOUNT, &c); + n->ovecsz = 2*c; + n->ovec = xmalloc(n->ovecsz*sizeof(*n->ovec)); + return (&n->n); } /*----- That's all, folks -------------------------------------------------*/ - -#endif