bin_PROGRAMS =
bin_SCRIPTS =
+LDADD =
+if HAVE_PCRE
+ LDADD += $(PCRE_LIBS)
+endif
+
###--------------------------------------------------------------------------
### Making substitutions.
anag_SOURCES += anagram.c
anag_SOURCES += longest.c
anag_SOURCES += mono.c
-anag_SOURCES += pcre.c
-anag_SOURCES += regexp.c
+if HAVE_PCRE
+ anag_SOURCES += pcre.c
+endif
+if HAVE_REGCOMP
+ anag_SOURCES += regexp.c
+endif
anag_SOURCES += trackword.c
anag_SOURCES += wildcard.c
extern node *wildcard(const char *const */*av*/);
extern node *trackword(const char *const */*av*/);
extern node *mono(const char *const */*av*/);
-extern node *regexp(const char *const */*av*/);
-extern node *pcrenode(const char *const */*av*/);
+#ifdef HAVE_REGCOMP
+ extern node *regexp(const char *const */*av*/);
+#endif
+#ifdef HAVE_PCRE
+ extern node *pcrenode(const char *const */*av*/);
+#endif
extern node *longest(const char *const */*av*/);
extern node *shortest(const char *const */*av*/);
dnl C programming environment.
AC_CHECK_FUNCS([regcomp])
-
-AC_SEARCH_LIBS([pcre_fullinfo], [pcre],
- [AC_DEFINE([HAVE_PCRE], [1], [Define if you have libpcre available.])])
+AM_CONDITIONAL([HAVE_REGCOMP], [test $ac_cv_func_regcomp = yes])
+
+mdw_have_pcre2=nil mdw_have_pcre=nil
+PKG_CHECK_MODULES([PCRE], [libpcre],
+ [mdw_have_pcre=t AM_CFLAGS="$AM_CFLAGS $PCRE_CFLAGS"], [])
+AM_CONDITIONAL([HAVE_PCRE], [test $mdw_have_pcre = t])
+case $mdw_have_pcre in
+ t) AC_DEFINE([HAVE_PCRE], [1], [PCRE library is available.]) ;;
+esac
dnl--------------------------------------------------------------------------
dnl Java.
/*----- 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
/*----- 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