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],
43 [[static struct re_pattern_buffer regex;
45 struct re_registers regs;
46 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
47 memset (®ex, 0, sizeof (regex));
48 s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex);
49 /* This should fail with _Invalid character class name_ error. */
53 /* This should succeed, but does not for e.g. glibc-2.1.3. */
54 memset (®ex, 0, sizeof (regex));
55 s = re_compile_pattern ("{1", 2, ®ex);
60 /* The following example is derived from a problem report
61 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
62 memset (®ex, 0, sizeof (regex));
63 s = re_compile_pattern ("[an\371]*n", 7, ®ex);
67 /* This should match, but does not for e.g. glibc-2.2.1. */
68 if (re_match (®ex, "an", 2, 0, ®s) != 2)
71 memset (®ex, 0, sizeof (regex));
72 s = re_compile_pattern ("x", 1, ®ex);
76 /* The version of regex.c in e.g. GNU libc-2.2.93 did not
77 work with a negative RANGE argument. */
78 if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
81 /* The version of regex.c in older versions of gnulib
82 * ignored RE_ICASE. Detect that problem too. */
83 memset (®ex, 0, sizeof (regex));
84 re_set_syntax(RE_SYNTAX_EMACS|RE_ICASE);
85 s = re_compile_pattern ("x", 1, ®ex);
89 if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0)
92 /* REG_STARTEND was added to glibc on 2004-01-15.
93 Reject older versions. */
98 [gl_cv_func_working_re_compile_pattern=yes],
99 [gl_cv_func_working_re_compile_pattern=no],
100 dnl When crosscompiling, assume it is broken.
101 [gl_cv_func_working_re_compile_pattern=no])])
102 if test $gl_cv_func_working_re_compile_pattern = yes; then
103 ac_use_included_regex=no
106 test -n "$1" || AC_MSG_ERROR([missing argument])
107 m4_syscmd([test -f '$1'])
110 AC_ARG_WITH([included-regex],
111 [ --without-included-regex don't compile regex; this is the default on
112 systems with recent-enough versions of the GNU C
113 Library (use with caution on other systems)],
114 [gl_with_regex=$withval],
115 [gl_with_regex=$ac_use_included_regex])
116 if test "X$gl_with_regex" = Xyes; then
125 # Prerequisites of lib/regex.c and lib/regex_internal.c.
126 AC_DEFUN([gl_PREREQ_REGEX],
128 AC_REQUIRE([gl_C_RESTRICT])
129 AC_REQUIRE([AM_LANGINFO_CODESET])
130 AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
131 AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])