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.
15 gl_INCLUDED_REGEX([lib/regex.c])
18 dnl Usage: gl_INCLUDED_REGEX([lib/regex.c])
20 AC_DEFUN([gl_INCLUDED_REGEX],
23 [regcomp.c, regex.c, regex.h,
24 regex_internal.c, regex_internal.h, regexec.c])
26 dnl Even packages that don't use regex.c can use this macro.
27 dnl Of course, for them it doesn't do anything.
29 # Assume we'll default to using the included regex.c.
30 ac_use_included_regex=yes
32 # However, if the system regex support is good enough that it passes the
33 # the following run test, then default to *not* using the included regex.c.
34 # If cross compiling, assume the test would fail and use the included
35 # regex.c. The first failing regular expression is from `Spencer ere
36 # test #75' in grep-2.3.
37 AC_CACHE_CHECK([for working re_compile_pattern],
38 [gl_cv_func_working_re_compile_pattern],
47 static struct re_pattern_buffer regex;
49 struct re_registers regs;
50 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
51 memset (®ex, 0, sizeof (regex));
52 s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex);
53 /* This should fail with _Invalid character class name_ error. */
57 /* This should succeed, but does not for e.g. glibc-2.1.3. */
58 memset (®ex, 0, sizeof (regex));
59 s = re_compile_pattern ("{1", 2, ®ex);
64 /* The following example is derived from a problem report
65 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
66 memset (®ex, 0, sizeof (regex));
67 s = re_compile_pattern ("[an\371]*n", 7, ®ex);
71 /* This should match, but does not for e.g. glibc-2.2.1. */
72 if (re_match (®ex, "an", 2, 0, ®s) != 2)
75 memset (®ex, 0, sizeof (regex));
76 s = re_compile_pattern ("x", 1, ®ex);
80 /* The version of regex.c in e.g. GNU libc-2.2.93 did not
81 work with a negative RANGE argument. */
82 if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
85 /* The version of regex.c in older versions of gnulib
86 * ignored RE_ICASE. Detect that problem too. */
87 memset (®ex, 0, sizeof (regex));
88 re_set_syntax(RE_SYNTAX_EMACS|RE_ICASE);
89 s = re_compile_pattern ("x", 1, ®ex);
93 if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
96 /* REG_STARTEND was added to glibc on 2004-01-15.
97 Reject older versions. */
104 [gl_cv_func_working_re_compile_pattern=yes],
105 [gl_cv_func_working_re_compile_pattern=no],
106 dnl When crosscompiling, assume it is broken.
107 [gl_cv_func_working_re_compile_pattern=no])])
108 if test $gl_cv_func_working_re_compile_pattern = yes; then
109 ac_use_included_regex=no
112 test -n "$1" || AC_MSG_ERROR([missing argument])
113 m4_syscmd([test -f '$1'])
116 AC_ARG_WITH([included-regex],
117 [ --without-included-regex don't compile regex; this is the default on
118 systems with recent-enough versions of the GNU C
119 Library (use with caution on other systems)],
120 [gl_with_regex=$withval],
121 [gl_with_regex=$ac_use_included_regex])
122 if test "X$gl_with_regex" = Xyes; then
131 # Prerequisites of lib/regex.c and lib/regex_internal.c.
132 AC_DEFUN([gl_PREREQ_REGEX],
134 AC_REQUIRE([gl_C_RESTRICT])
135 AC_REQUIRE([AM_LANGINFO_CODESET])
136 AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
137 AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])