3 dnl Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004 Free
4 dnl Software Foundation, Inc.
6 dnl This file is free software; the Free Software Foundation
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl 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],
22 dnl Even packages that don't use regex.c can use this macro.
23 dnl Of course, for them it doesn't do anything.
25 # Assume we'll default to using the included regex.c.
26 ac_use_included_regex=yes
28 # However, if the system regex support is good enough that it passes the
29 # the following run test, then default to *not* using the included regex.c.
30 # If cross compiling, assume the test would fail and use the included
31 # regex.c. The first failing regular expression is from `Spencer ere
32 # test #75' in grep-2.3.
33 AC_CACHE_CHECK([for working re_compile_pattern],
34 jm_cv_func_working_re_compile_pattern,
42 static struct re_pattern_buffer regex;
44 struct re_registers regs;
45 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
46 memset (®ex, 0, sizeof (regex));
47 [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, ®ex);]
48 /* This should fail with _Invalid character class name_ error. */
52 /* This should succeed, but doesn't for e.g. glibc-2.1.3. */
53 memset (®ex, 0, sizeof (regex));
54 s = re_compile_pattern ("{1", 2, ®ex);
59 /* The following example is derived from a problem report
60 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
61 memset (®ex, 0, sizeof (regex));
62 s = re_compile_pattern ("[[an\371]]*n", 7, ®ex);
66 /* This should match, but doesn't for e.g. glibc-2.2.1. */
67 if (re_match (®ex, "an", 2, 0, ®s) != 2)
70 memset (®ex, 0, sizeof (regex));
71 s = re_compile_pattern ("x", 1, ®ex);
75 /* The version of regex.c in e.g. GNU libc-2.2.93 didn't
76 work with a negative RANGE argument. */
77 if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1)
83 jm_cv_func_working_re_compile_pattern=yes,
84 jm_cv_func_working_re_compile_pattern=no,
85 dnl When crosscompiling, assume it's broken.
86 jm_cv_func_working_re_compile_pattern=no))
87 if test $jm_cv_func_working_re_compile_pattern = yes; then
88 ac_use_included_regex=no
91 test -n "$1" || AC_MSG_ERROR([missing argument])
92 m4_syscmd([test -f $1])
95 AC_ARG_WITH(included-regex,
96 [ --without-included-regex don't compile regex; this is the default on
97 systems with version 2 of the GNU C library
98 (use with caution on other system)],
99 jm_with_regex=$withval,
100 jm_with_regex=$ac_use_included_regex)
101 if test "$jm_with_regex" = yes; then
110 # Prerequisites of lib/regex.c.
111 AC_DEFUN([gl_PREREQ_REGEX],
113 dnl FIXME: Maybe provide a btowc replacement someday: Solaris 2.5.1 lacks it.
114 dnl FIXME: Check for wctype and iswctype, and and add -lw if necessary
117 dnl Persuade glibc <string.h> to declare mempcpy().
118 AC_REQUIRE([AC_GNU_SOURCE])
120 AC_REQUIRE([gl_C_RESTRICT])
121 AC_REQUIRE([AC_FUNC_ALLOCA])
122 AC_REQUIRE([AC_HEADER_STDC])
123 AC_CHECK_HEADERS_ONCE(wchar.h wctype.h)
124 AC_CHECK_FUNCS_ONCE(isascii mempcpy)
125 AC_CHECK_FUNCS(btowc)