X-Git-Url: https://git.distorted.org.uk/~mdw/anag/blobdiff_plain/0279756ef8eb60878927c9e325a9ad25a4b0f150..7c2b74abc8bbc3b009a233b65d4f8aa23219892d:/regexp.c diff --git a/regexp.c b/regexp.c index c930ea5..cd12f15 100644 --- a/regexp.c +++ b/regexp.c @@ -26,15 +26,8 @@ /*----- Header files ------------------------------------------------------*/ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifndef HAVE_REGCOMP - extern int dummy; -#else - #include "anag.h" + #include /*----- Data structures ---------------------------------------------------*/ @@ -52,19 +45,17 @@ typedef struct node_regexp { static int n_regexp(node *nn, const char *p, size_t sz) { node_regexp *n = (node_regexp *)nn; + char buf[256]; int e; switch (e = regexec(&n->rx, p, 0, 0, 0)) { - case 0: - return 1; - case REG_NOMATCH: - return 0; - default: { - char buf[256]; + case 0: return 1; + case REG_NOMATCH: return 0; + default: regerror(e, &n->rx, buf, sizeof(buf)); die("error matching regexp `%s' against `%s': %s", n->s, p, buf); - } break; + break; } return (0); } @@ -74,11 +65,12 @@ static int n_regexp(node *nn, const char *p, size_t sz) node *regexp(const char *const *av) { node_regexp *n = xmalloc(sizeof(*n)); + char buf[256]; int e; + n->n.func = n_regexp; if ((e = regcomp(&n->rx, av[0], REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) { - char buf[256]; regerror(e, &n->rx, buf, sizeof(buf)); die("bad regular expression `%s': %s", av[0], buf); } @@ -86,5 +78,3 @@ node *regexp(const char *const *av) } /*----- That's all, folks -------------------------------------------------*/ - -#endif