X-Git-Url: https://git.distorted.org.uk/~mdw/anag/blobdiff_plain/345f33ea7a273e3196075b07fcc0bc28714793a5..HEAD:/regexp.c diff --git a/regexp.c b/regexp.c index 500c597..cd12f15 100644 --- a/regexp.c +++ b/regexp.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id: regexp.c,v 1.2 2004/04/08 01:36:19 mdw Exp $ - * * Matches 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_REGCOMP - extern int dummy; -#else - #include "anag.h" + #include /*----- Data structures ---------------------------------------------------*/ @@ -54,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); } @@ -76,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); } @@ -88,5 +78,3 @@ node *regexp(const char *const *av) } /*----- That's all, folks -------------------------------------------------*/ - -#endif