/*----- Header files ------------------------------------------------------*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifndef HAVE_PCRE
- extern int dummy;
-#else
-
#include "anag.h"
+
#include <pcre.h>
/*----- Data structures ---------------------------------------------------*/
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 --- */
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