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 /* Use the POSIX-compliant spelling with leading REG_,
40 rather than the traditional GNU spelling with leading RE_,
41 so that we reject older libc implementations. */
42 re_set_syntax (REG_SYNTAX_POSIX_EGREP);
43 memset (®ex, 0, sizeof (regex));
44 s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex);
45 /* This should fail with _Invalid character class name_ error. */
49 /* This should succeed, but does not for e.g. glibc-2.1.3. */
50 memset (®ex, 0, sizeof (regex));
51 s = re_compile_pattern ("{1", 2, ®ex);
56 /* The following example is derived from a problem report
57 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
58 memset (®ex, 0, sizeof (regex));
59 s = re_compile_pattern ("[an\371]*n", 7, ®ex);
63 /* This should match, but does not for e.g. glibc-2.2.1. */
64 if (re_match (®ex, "an", 2, 0, ®s) != 2)
67 memset (®ex, 0, sizeof (regex));
68 s = re_compile_pattern ("x", 1, ®ex);
72 /* The version of regex.c in e.g. GNU libc-2.2.93 did not
73 work with a negative RANGE argument. */
74 if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
77 /* The version of regex.c in older versions of gnulib
78 ignored REG_IGNORE_CASE (which was then called RE_ICASE).
79 Detect that problem too. */
80 memset (®ex, 0, sizeof (regex));
81 re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE);
82 s = re_compile_pattern ("x", 1, ®ex);
86 if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
89 /* REG_STARTEND was added to glibc on 2004-01-15.
90 Reject older versions. */
95 [gl_cv_func_working_re_compile_pattern=yes],
96 [gl_cv_func_working_re_compile_pattern=no],
97 dnl When crosscompiling, assume it is broken.
98 [gl_cv_func_working_re_compile_pattern=no])])
99 if test $gl_cv_func_working_re_compile_pattern = yes; then
100 ac_use_included_regex=no
103 AC_ARG_WITH([included-regex],
104 [ --without-included-regex don't compile regex; this is the default on
105 systems with recent-enough versions of the GNU C
106 Library (use with caution on other systems)],
107 [gl_with_regex=$withval],
108 [gl_with_regex=$ac_use_included_regex])
109 if test "X$gl_with_regex" = Xyes; then
115 # Prerequisites of lib/regex.c and lib/regex_internal.c.
116 AC_DEFUN([gl_PREREQ_REGEX],
118 AC_REQUIRE([AC_GNU_SOURCE])
119 AC_REQUIRE([gl_C_RESTRICT])
120 AC_REQUIRE([AM_LANGINFO_CODESET])
121 AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
122 AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])