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