/*----- Header files ------------------------------------------------------*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifndef HAVE_REGCOMP
- extern int dummy;
-#else
-
#include "anag.h"
+
#include <regex.h>
/*----- Data structures ---------------------------------------------------*/
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);
}
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);
}
}
/*----- That's all, folks -------------------------------------------------*/
-
-#endif