3 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
4 # Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
10 dnl Initially derived from code in GNU grep.
11 dnl Mostly written by Jim Meyering.
16 [regcomp.c, regex.c, regex.h,
17 regex_internal.c, regex_internal.h, regexec.c])
19 dnl Even packages that don't use regex.c can use this macro.
20 dnl Of course, for them it doesn't do anything.
22 # Assume we'll default to using the included regex.c.
23 ac_use_included_regex=yes
25 # However, if the system regex support is good enough that it passes the
26 # the following run test, then default to *not* using the included regex.c.
27 # If cross compiling, assume the test would fail and use the included
28 # regex.c. The first failing regular expression is from `Spencer ere
29 # test #75' in grep-2.3.
30 AC_CACHE_CHECK([for working re_compile_pattern],
31 [gl_cv_func_working_re_compile_pattern],
36 [[static struct re_pattern_buffer regex;
38 struct re_registers regs;
39 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
40 memset (®ex, 0, sizeof (regex));
41 s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex);
42 /* This should fail with _Invalid character class name_ error. */
46 /* This should succeed, but does not for e.g. glibc-2.1.3. */
47 memset (®ex, 0, sizeof (regex));
48 s = re_compile_pattern ("{1", 2, ®ex);
53 /* The following example is derived from a problem report
54 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
55 memset (®ex, 0, sizeof (regex));
56 s = re_compile_pattern ("[an\371]*n", 7, ®ex);
60 /* This should match, but does not for e.g. glibc-2.2.1. */
61 if (re_match (®ex, "an", 2, 0, ®s) != 2)
64 memset (®ex, 0, sizeof (regex));
65 s = re_compile_pattern ("x", 1, ®ex);
69 /* The version of regex.c in e.g. GNU libc-2.2.93 did not
70 work with a negative RANGE argument. */
71 if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
74 /* The version of regex.c in older versions of gnulib
75 * ignored RE_ICASE. Detect that problem too. */
76 memset (®ex, 0, sizeof (regex));
77 re_set_syntax(RE_SYNTAX_EMACS|RE_ICASE);
78 s = re_compile_pattern ("x", 1, ®ex);
82 if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
85 /* REG_STARTEND was added to glibc on 2004-01-15.
86 Reject older versions. */
91 [gl_cv_func_working_re_compile_pattern=yes],
92 [gl_cv_func_working_re_compile_pattern=no],
93 dnl When crosscompiling, assume it is broken.
94 [gl_cv_func_working_re_compile_pattern=no])])
95 if test $gl_cv_func_working_re_compile_pattern = yes; then
96 ac_use_included_regex=no
99 AC_ARG_WITH([included-regex],
100 [ --without-included-regex don't compile regex; this is the default on
101 systems with recent-enough versions of the GNU C
102 Library (use with caution on other systems)],
103 [gl_with_regex=$withval],
104 [gl_with_regex=$ac_use_included_regex])
105 if test "X$gl_with_regex" = Xyes; then
111 # Prerequisites of lib/regex.c and lib/regex_internal.c.
112 AC_DEFUN([gl_PREREQ_REGEX],
114 AC_REQUIRE([AC_GNU_SOURCE])
115 AC_REQUIRE([gl_C_RESTRICT])
116 AC_REQUIRE([AM_LANGINFO_CODESET])
117 AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
118 AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])