2N/A# serial 56
2N/A
2N/A# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
2N/A# 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
2N/A#
2N/A# This file is free software; the Free Software Foundation
2N/A# gives unlimited permission to copy and/or distribute it,
2N/A# with or without modifications, as long as this notice is preserved.
2N/A
2N/Adnl Initially derived from code in GNU grep.
2N/Adnl Mostly written by Jim Meyering.
2N/A
2N/AAC_PREREQ([2.50])
2N/A
2N/AAC_DEFUN([gl_REGEX],
2N/A[
2N/A AC_CHECK_HEADERS_ONCE([locale.h])
2N/A
2N/A AC_ARG_WITH([included-regex],
2N/A [AS_HELP_STRING([--without-included-regex],
2N/A [don't compile regex; this is the default on systems
2N/A with recent-enough versions of the GNU C Library
2N/A (use with caution on other systems).])])
2N/A
2N/A case $with_included_regex in #(
2N/A yes|no) ac_use_included_regex=$with_included_regex
2N/A ;;
2N/A '')
2N/A # If the system regex support is good enough that it passes the
2N/A # following run test, then default to *not* using the included regex.c.
2N/A # If cross compiling, assume the test would fail and use the included
2N/A # regex.c.
2N/A AC_CACHE_CHECK([for working re_compile_pattern],
2N/A [gl_cv_func_re_compile_pattern_working],
2N/A [AC_RUN_IFELSE(
2N/A [AC_LANG_PROGRAM(
2N/A [AC_INCLUDES_DEFAULT[
2N/A #if HAVE_LOCALE_H
2N/A #include <locale.h>
2N/A #endif
2N/A #include <limits.h>
2N/A #include <regex.h>
2N/A ]],
2N/A [[static struct re_pattern_buffer regex;
2N/A unsigned char folded_chars[UCHAR_MAX + 1];
2N/A int i;
2N/A const char *s;
2N/A struct re_registers regs;
2N/A
2N/A #if HAVE_LOCALE_H
2N/A /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
2N/A This test needs valgrind to catch the bug on Debian
2N/A GNU/Linux 3.1 x86, but it might catch the bug better
2N/A on other platforms and it shouldn't hurt to try the
2N/A test here. */
2N/A if (setlocale (LC_ALL, "en_US.UTF-8"))
2N/A {
2N/A static char const pat[] = "insert into";
2N/A static char const data[] =
2N/A "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
2N/A re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE
2N/A | RE_ICASE);
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern (pat, sizeof pat - 1, &regex);
2N/A if (s)
2N/A return 1;
2N/A if (re_search (&regex, data, sizeof data - 1,
2N/A 0, sizeof data - 1, &regs)
2N/A != -1)
2N/A return 1;
2N/A if (! setlocale (LC_ALL, "C"))
2N/A return 1;
2N/A }
2N/A #endif
2N/A
2N/A /* This test is from glibc bug 3957, reported by Andrew Mackey. */
2N/A re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("a[^x]b", 6, &regex);
2N/A if (s)
2N/A return 1;
2N/A
2N/A /* This should fail, but succeeds for glibc-2.5. */
2N/A if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
2N/A return 1;
2N/A
2N/A /* This regular expression is from Spencer ere test number 75
2N/A in grep-2.3. */
2N/A re_set_syntax (RE_SYNTAX_POSIX_EGREP);
2N/A memset (&regex, 0, sizeof regex);
2N/A for (i = 0; i <= UCHAR_MAX; i++)
2N/A folded_chars[i] = i;
2N/A regex.translate = folded_chars;
2N/A s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
2N/A /* This should fail with _Invalid character class name_ error. */
2N/A if (!s)
2N/A return 1;
2N/A
2N/A /* Ensure that [b-a] is diagnosed as invalid, when
2N/A using RE_NO_EMPTY_RANGES. */
2N/A re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES);
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("a[b-a]", 6, &regex);
2N/A if (s == 0)
2N/A return 1;
2N/A
2N/A /* This should succeed, but does not for glibc-2.1.3. */
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("{1", 2, &regex);
2N/A
2N/A if (s)
2N/A return 1;
2N/A
2N/A /* The following example is derived from a problem report
2N/A against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("[an\371]*n", 7, &regex);
2N/A if (s)
2N/A return 1;
2N/A
2N/A /* This should match, but does not for glibc-2.2.1. */
2N/A if (re_match (&regex, "an", 2, 0, &regs) != 2)
2N/A return 1;
2N/A
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("x", 1, &regex);
2N/A if (s)
2N/A return 1;
2N/A
2N/A /* glibc-2.2.93 does not work with a negative RANGE argument. */
2N/A if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
2N/A return 1;
2N/A
2N/A /* The version of regex.c in older versions of gnulib
2N/A ignored RE_ICASE. Detect that problem too. */
2N/A re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("x", 1, &regex);
2N/A if (s)
2N/A return 1;
2N/A
2N/A if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
2N/A return 1;
2N/A
2N/A /* Catch a bug reported by Vin Shelton in
2N/A http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
2N/A */
2N/A re_set_syntax (RE_SYNTAX_POSIX_BASIC
2N/A & ~RE_CONTEXT_INVALID_DUP
2N/A & ~RE_NO_EMPTY_RANGES);
2N/A memset (&regex, 0, sizeof regex);
2N/A s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
2N/A if (s)
2N/A return 1;
2N/A
2N/A /* REG_STARTEND was added to glibc on 2004-01-15.
2N/A Reject older versions. */
2N/A if (! REG_STARTEND)
2N/A return 1;
2N/A
2N/A#if 0
2N/A /* It would be nice to reject hosts whose regoff_t values are too
2N/A narrow (including glibc on hosts with 64-bit ptrdiff_t and
2N/A 32-bit int), but we should wait until glibc implements this
2N/A feature. Otherwise, support for equivalence classes and
2N/A multibyte collation symbols would always be broken except
2N/A when compiling --without-included-regex. */
2N/A if (sizeof (regoff_t) < sizeof (ptrdiff_t)
2N/A || sizeof (regoff_t) < sizeof (ssize_t))
2N/A return 1;
2N/A#endif
2N/A
2N/A return 0;]])],
2N/A [gl_cv_func_re_compile_pattern_working=yes],
2N/A [gl_cv_func_re_compile_pattern_working=no],
2N/A dnl When crosscompiling, assume it is not working.
2N/A [gl_cv_func_re_compile_pattern_working=no])])
2N/A case $gl_cv_func_re_compile_pattern_working in #(
2N/A yes) ac_use_included_regex=no;; #(
2N/A no) ac_use_included_regex=yes;;
2N/A esac
2N/A ;;
2N/A *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
2N/A ;;
2N/A esac
2N/A
2N/A if test $ac_use_included_regex = yes; then
2N/A AC_DEFINE([_REGEX_LARGE_OFFSETS], [1],
2N/A [Define if you want regoff_t to be at least as wide POSIX requires.])
2N/A AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
2N/A [Define to rpl_re_syntax_options if the replacement should be used.])
2N/A AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
2N/A [Define to rpl_re_set_syntax if the replacement should be used.])
2N/A AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
2N/A [Define to rpl_re_compile_pattern if the replacement should be used.])
2N/A AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
2N/A [Define to rpl_re_compile_fastmap if the replacement should be used.])
2N/A AC_DEFINE([re_search], [rpl_re_search],
2N/A [Define to rpl_re_search if the replacement should be used.])
2N/A AC_DEFINE([re_search_2], [rpl_re_search_2],
2N/A [Define to rpl_re_search_2 if the replacement should be used.])
2N/A AC_DEFINE([re_match], [rpl_re_match],
2N/A [Define to rpl_re_match if the replacement should be used.])
2N/A AC_DEFINE([re_match_2], [rpl_re_match_2],
2N/A [Define to rpl_re_match_2 if the replacement should be used.])
2N/A AC_DEFINE([re_set_registers], [rpl_re_set_registers],
2N/A [Define to rpl_re_set_registers if the replacement should be used.])
2N/A AC_DEFINE([re_comp], [rpl_re_comp],
2N/A [Define to rpl_re_comp if the replacement should be used.])
2N/A AC_DEFINE([re_exec], [rpl_re_exec],
2N/A [Define to rpl_re_exec if the replacement should be used.])
2N/A AC_DEFINE([regcomp], [rpl_regcomp],
2N/A [Define to rpl_regcomp if the replacement should be used.])
2N/A AC_DEFINE([regexec], [rpl_regexec],
2N/A [Define to rpl_regexec if the replacement should be used.])
2N/A AC_DEFINE([regerror], [rpl_regerror],
2N/A [Define to rpl_regerror if the replacement should be used.])
2N/A AC_DEFINE([regfree], [rpl_regfree],
2N/A [Define to rpl_regfree if the replacement should be used.])
2N/A AC_LIBOBJ([regex])
2N/A gl_PREREQ_REGEX
2N/A fi
2N/A])
2N/A
2N/A# Prerequisites of lib/regex.c and lib/regex_internal.c.
2N/AAC_DEFUN([gl_PREREQ_REGEX],
2N/A[
2N/A AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
2N/A AC_REQUIRE([AC_C_INLINE])
2N/A AC_REQUIRE([AC_C_RESTRICT])
2N/A AC_REQUIRE([AC_TYPE_MBSTATE_T])
2N/A AC_CHECK_HEADERS([libintl.h])
2N/A AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll])
2N/A AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
2N/A])