X-Git-Url: https://git.distorted.org.uk/~mdw/anag/blobdiff_plain/345f33ea7a273e3196075b07fcc0bc28714793a5..7c2b74abc8bbc3b009a233b65d4f8aa23219892d:/pcre.c diff --git a/pcre.c b/pcre.c index 19fd85b..5c5994c 100644 --- a/pcre.c +++ b/pcre.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id: pcre.c,v 1.2 2004/04/08 01:36:19 mdw Exp $ - * * Matches Perl-compatible regular expressions * * (c) 2002 Mark Wooding */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Anag: a simple wordgame helper. * @@ -15,12 +13,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * Anag is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Anag; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -28,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 ---------------------------------------------------*/ @@ -60,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 --- */ @@ -78,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