Blame m4/regex.m4

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