3 # Copyright (C) 1996-2001, 2003-2016 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 dnl Initially derived from code in GNU grep.
10 dnl Mostly written by Jim Meyering.
16 AC_ARG_WITH([included-regex],
17 [AS_HELP_STRING([--without-included-regex],
18 [don't compile regex; this is the default on systems
19 with recent-enough versions of the GNU C Library
20 (use with caution on other systems).])])
22 case $with_included_regex in #(
23 yes|no) ac_use_included_regex=$with_included_regex
26 # If the system regex support is good enough that it passes the
27 # following run test, then default to *not* using the included regex.c.
28 # If cross compiling, assume the test would fail and use the included
30 AC_CHECK_DECLS_ONCE([alarm])
31 AC_CHECK_HEADERS_ONCE([malloc.h])
32 AC_CACHE_CHECK([for working re_compile_pattern],
33 [gl_cv_func_re_compile_pattern_working],
42 #if defined M_CHECK_ACTION || HAVE_DECL_ALARM
52 /* Exit with distinguishable exit code. */
53 static void sigabrt_no_core (int sig) { raise (SIGTERM); }
57 static struct re_pattern_buffer regex;
58 unsigned char folded_chars[UCHAR_MAX + 1];
61 struct re_registers regs;
63 /* Some builds of glibc go into an infinite loop on this
64 test. Use alarm to force death, and mallopt to avoid
65 malloc recursion in diagnosing the corrupted heap. */
67 signal (SIGALRM, SIG_DFL);
71 signal (SIGABRT, sigabrt_no_core);
72 mallopt (M_CHECK_ACTION, 2);
75 if (setlocale (LC_ALL, "en_US.UTF-8"))
78 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
79 This test needs valgrind to catch the bug on Debian
80 GNU/Linux 3.1 x86, but it might catch the bug better
81 on other platforms and it shouldn't hurt to try the
83 static char const pat[] = "insert into";
84 static char const data[] =
85 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
86 re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE
88 memset (®ex, 0, sizeof regex);
89 s = re_compile_pattern (pat, sizeof pat - 1, ®ex);
92 else if (re_search (®ex, data, sizeof data - 1,
93 0, sizeof data - 1, ®s)
100 /* This test is from glibc bug 15078.
101 The test case is from Andreas Schwab in
102 <http://www.sourceware.org/ml/libc-alpha/2013-01/msg00967.html>.
104 static char const pat[] = "[^x]x";
105 static char const data[] =
106 /* <U1000><U103B><U103D><U1014><U103A><U102F><U1015><U103A> */
117 memset (®ex, 0, sizeof regex);
118 s = re_compile_pattern (pat, sizeof pat - 1, ®ex);
123 i = re_search (®ex, data, sizeof data - 1,
124 0, sizeof data - 1, 0);
125 if (i != 0 && i != 21)
131 if (! setlocale (LC_ALL, "C"))
135 /* This test is from glibc bug 3957, reported by Andrew Mackey. */
136 re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
137 memset (®ex, 0, sizeof regex);
138 s = re_compile_pattern ("a[^x]b", 6, ®ex);
141 /* This should fail, but succeeds for glibc-2.5. */
142 else if (re_search (®ex, "a\nb", 3, 0, 3, ®s) != -1)
145 /* This regular expression is from Spencer ere test number 75
147 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
148 memset (®ex, 0, sizeof regex);
149 for (i = 0; i <= UCHAR_MAX; i++)
151 regex.translate = folded_chars;
152 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, ®ex);
153 /* This should fail with _Invalid character class name_ error. */
157 /* Ensure that [b-a] is diagnosed as invalid, when
158 using RE_NO_EMPTY_RANGES. */
159 re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES);
160 memset (®ex, 0, sizeof regex);
161 s = re_compile_pattern ("a[b-a]", 6, ®ex);
165 /* This should succeed, but does not for glibc-2.1.3. */
166 memset (®ex, 0, sizeof regex);
167 s = re_compile_pattern ("{1", 2, ®ex);
171 /* The following example is derived from a problem report
172 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
173 memset (®ex, 0, sizeof regex);
174 s = re_compile_pattern ("[an\371]*n", 7, ®ex);
177 /* This should match, but does not for glibc-2.2.1. */
178 else if (re_match (®ex, "an", 2, 0, ®s) != 2)
181 memset (®ex, 0, sizeof regex);
182 s = re_compile_pattern ("x", 1, ®ex);
185 /* glibc-2.2.93 does not work with a negative RANGE argument. */
186 else if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
189 /* The version of regex.c in older versions of gnulib
190 ignored RE_ICASE. Detect that problem too. */
191 re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
192 memset (®ex, 0, sizeof regex);
193 s = re_compile_pattern ("x", 1, ®ex);
196 else if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
199 /* Catch a bug reported by Vin Shelton in
200 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
202 re_set_syntax (RE_SYNTAX_POSIX_BASIC
203 & ~RE_CONTEXT_INVALID_DUP
204 & ~RE_NO_EMPTY_RANGES);
205 memset (®ex, 0, sizeof regex);
206 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, ®ex);
210 /* REG_STARTEND was added to glibc on 2004-01-15.
211 Reject older versions. */
216 /* It would be nice to reject hosts whose regoff_t values are too
217 narrow (including glibc on hosts with 64-bit ptrdiff_t and
218 32-bit int), but we should wait until glibc implements this
219 feature. Otherwise, support for equivalence classes and
220 multibyte collation symbols would always be broken except
221 when compiling --without-included-regex. */
222 if (sizeof (regoff_t) < sizeof (ptrdiff_t)
223 || sizeof (regoff_t) < sizeof (ssize_t))
229 [gl_cv_func_re_compile_pattern_working=yes],
230 [gl_cv_func_re_compile_pattern_working=no],
231 dnl When crosscompiling, assume it is not working.
232 [gl_cv_func_re_compile_pattern_working=no])])
233 case $gl_cv_func_re_compile_pattern_working in #(
234 yes) ac_use_included_regex=no;; #(
235 no) ac_use_included_regex=yes;;
238 *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
242 if test $ac_use_included_regex = yes; then
243 AC_DEFINE([_REGEX_INCLUDE_LIMITS_H], [1],
244 [Define if you want <regex.h> to include <limits.h>, so that it
245 consistently overrides <limits.h>'s RE_DUP_MAX.])
246 AC_DEFINE([_REGEX_LARGE_OFFSETS], [1],
247 [Define if you want regoff_t to be at least as wide POSIX requires.])
248 AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
249 [Define to rpl_re_syntax_options if the replacement should be used.])
250 AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
251 [Define to rpl_re_set_syntax if the replacement should be used.])
252 AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
253 [Define to rpl_re_compile_pattern if the replacement should be used.])
254 AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
255 [Define to rpl_re_compile_fastmap if the replacement should be used.])
256 AC_DEFINE([re_search], [rpl_re_search],
257 [Define to rpl_re_search if the replacement should be used.])
258 AC_DEFINE([re_search_2], [rpl_re_search_2],
259 [Define to rpl_re_search_2 if the replacement should be used.])
260 AC_DEFINE([re_match], [rpl_re_match],
261 [Define to rpl_re_match if the replacement should be used.])
262 AC_DEFINE([re_match_2], [rpl_re_match_2],
263 [Define to rpl_re_match_2 if the replacement should be used.])
264 AC_DEFINE([re_set_registers], [rpl_re_set_registers],
265 [Define to rpl_re_set_registers if the replacement should be used.])
266 AC_DEFINE([re_comp], [rpl_re_comp],
267 [Define to rpl_re_comp if the replacement should be used.])
268 AC_DEFINE([re_exec], [rpl_re_exec],
269 [Define to rpl_re_exec if the replacement should be used.])
270 AC_DEFINE([regcomp], [rpl_regcomp],
271 [Define to rpl_regcomp if the replacement should be used.])
272 AC_DEFINE([regexec], [rpl_regexec],
273 [Define to rpl_regexec if the replacement should be used.])
274 AC_DEFINE([regerror], [rpl_regerror],
275 [Define to rpl_regerror if the replacement should be used.])
276 AC_DEFINE([regfree], [rpl_regfree],
277 [Define to rpl_regfree if the replacement should be used.])
281 # Prerequisites of lib/regex.c and lib/regex_internal.c.
282 AC_DEFUN([gl_PREREQ_REGEX],
284 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
285 AC_REQUIRE([AC_C_INLINE])
286 AC_REQUIRE([AC_C_RESTRICT])
287 AC_REQUIRE([AC_TYPE_MBSTATE_T])
288 AC_REQUIRE([gl_EEMALLOC])
289 AC_REQUIRE([gl_GLIBC21])
290 AC_CHECK_HEADERS([libintl.h])
291 AC_CHECK_FUNCS_ONCE([isblank iswctype])
292 AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])