dnl CF_REGEX version: 16 updated: 2020/09/26 19:56:36
dnl --------
dnl Attempt to determine if we've got one of the flavors of regular-expression
dnl code that we can support.
AC_DEFUN([CF_REGEX],
[

cf_regex_func=no
cf_regex_libs=
case $host_os in
(mingw*)
	# -lsystre -ltre -lintl -liconv
	AC_CHECK_LIB(systre,regcomp,[
		AC_CHECK_LIB(iconv,libiconv_open,[CF_ADD_LIB(iconv)])
		AC_CHECK_LIB(intl,libintl_gettext,[CF_ADD_LIB(intl)])
		AC_CHECK_LIB(tre,tre_regcomp,[CF_ADD_LIB(tre)])
		CF_ADD_LIB(systre)
		cf_regex_func=regcomp
	],[
		AC_CHECK_LIB(gnurx,regcomp,[
			CF_ADD_LIB(gnurx)
			cf_regex_func=regcomp])
	])
	;;
(*)
	cf_regex_libs="regex re"
	AC_CHECK_FUNC(regcomp,[cf_regex_func=regcomp],[
		for cf_regex_lib in $cf_regex_libs
		do
			AC_CHECK_LIB($cf_regex_lib,regcomp,[
					CF_ADD_LIB($cf_regex_lib)
					cf_regex_func=regcomp
					break])
		done
	])
	;;
esac

if test "$cf_regex_func" = no ; then
	AC_CHECK_FUNC(compile,[cf_regex_func=compile],[
		AC_CHECK_LIB(gen,compile,[
				CF_ADD_LIB(gen)
				cf_regex_func=compile])])
fi

if test "$cf_regex_func" = no ; then
	AC_MSG_WARN(cannot find regular expression library)
fi

AC_CACHE_CHECK(for regular-expression headers,cf_cv_regex_hdrs,[

cf_cv_regex_hdrs=no
case $cf_regex_func in
(compile)
	for cf_regex_hdr in regexp.h regexpr.h
	do
		AC_TRY_LINK([#include <$cf_regex_hdr>],[
			char *p = compile("", "", "", 0);
			int x = step("", "");
			(void)p;
			(void)x;
		],[
			cf_cv_regex_hdrs=$cf_regex_hdr
			break
		])
	done
	;;
(*)
	for cf_regex_hdr in regex.h
	do
		AC_TRY_LINK([#include <sys/types.h>
#include <$cf_regex_hdr>],[
			regex_t *p = 0;
			int x = regcomp(p, "", 0);
			int y = regexec(p, "", 0, 0, 0);
			(void)x;
			(void)y;
			regfree(p);
		],[
			cf_cv_regex_hdrs=$cf_regex_hdr
			break
		])
	done
	;;
esac

])

case $cf_cv_regex_hdrs in
	(no)		AC_MSG_WARN(no regular expression header found) ;;
	(regex.h)	AC_DEFINE(HAVE_REGEX_H_FUNCS,1,[Define to 1 to include regex.h for regular expressions]) ;;
	(regexp.h)	AC_DEFINE(HAVE_REGEXP_H_FUNCS,1,[Define to 1 to include regexp.h for regular expressions]) ;;
	(regexpr.h) AC_DEFINE(HAVE_REGEXPR_H_FUNCS,1,[Define to 1 to include regexpr.h for regular expressions]) ;;
esac
])dnl
