Blame m4/regex.m4

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