* regex.m4 (gl_REGEX): Fix a longstanding typo in the
[gnulib.git] / m4 / regex.m4
1 #serial 35
2
3 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
4 # 2006 Free Software Foundation, Inc.
5 #
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.
9
10 dnl Initially derived from code in GNU grep.
11 dnl Mostly written by Jim Meyering.
12
13 AC_PREREQ([2.50])
14
15 AC_DEFUN([gl_REGEX],
16 [
17   AC_LIBSOURCES(
18     [regcomp.c, regex.c, regex.h,
19      regex_internal.c, regex_internal.h, regexec.c])
20
21   AC_ARG_WITH([included-regex],
22     [AC_HELP_STRING([--without-included-regex],
23                     [don't compile regex; this is the default on
24                      systems with recent-enough versions of the GNU C
25                      Library (use with caution on other systems)])])
26
27   case $with_included_regex in #(
28   yes|no) ac_use_included_regex=$with_included_regex
29         ;;
30   '')
31     # If the system regex support is good enough that it passes the the
32     # following run test, then default to *not* using the included regex.c.
33     # If cross compiling, assume the test would fail and use the included
34     # regex.c.  The first failing regular expression is from `Spencer ere
35     # test #75' in grep-2.3.
36     AC_CACHE_CHECK([for working re_compile_pattern],
37                    [gl_cv_func_re_compile_pattern_working],
38       [AC_RUN_IFELSE(
39         [AC_LANG_PROGRAM(
40           [AC_INCLUDES_DEFAULT
41            #include <regex.h>
42            ],
43           [[static struct re_pattern_buffer regex;
44             const char *s;
45             struct re_registers regs;
46             re_set_syntax (RE_SYNTAX_POSIX_EGREP);
47             memset (&regex, 0, sizeof (regex));
48             s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
49             /* This should fail with _Invalid character class name_ error.  */
50             if (!s)
51               exit (1);
52
53             /* This should succeed, but does not for e.g. glibc-2.1.3.  */
54             memset (&regex, 0, sizeof (regex));
55             s = re_compile_pattern ("{1", 2, &regex);
56
57             if (s)
58               exit (1);
59
60             /* The following example is derived from a problem report
61                against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
62             memset (&regex, 0, sizeof (regex));
63             s = re_compile_pattern ("[an\371]*n", 7, &regex);
64             if (s)
65               exit (1);
66
67             /* This should match, but does not for e.g. glibc-2.2.1.  */
68             if (re_match (&regex, "an", 2, 0, &regs) != 2)
69               exit (1);
70
71             memset (&regex, 0, sizeof (regex));
72             s = re_compile_pattern ("x", 1, &regex);
73             if (s)
74               exit (1);
75
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 (&regex, "wxy", 3, 2, -2, &regs) != 1)
79               exit (1);
80
81             /* The version of regex.c in older versions of gnulib
82                ignored RE_ICASE.  Detect that problem too.  */
83             memset (&regex, 0, sizeof (regex));
84             re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
85             s = re_compile_pattern ("x", 1, &regex);
86             if (s)
87               exit (1);
88
89             if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
90               exit (1);
91
92             /* REG_STARTEND was added to glibc on 2004-01-15.
93                Reject older versions.  */
94             if (! REG_STARTEND)
95               exit (1);
96
97             /* Reject hosts whose regoff_t values are too narrow.
98                These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
99                and 32-bit int.  */
100             if (sizeof (regoff_t) < sizeof (ptrdiff_t)
101                 || sizeof (regoff_t) < sizeof (ssize_t))
102               exit (1);
103
104             exit (0);]])],
105        [gl_cv_func_re_compile_pattern_working=yes],
106        [gl_cv_func_re_compile_pattern_working=no],
107        dnl When crosscompiling, assume it is not working.
108        [gl_cv_func_re_compile_pattern_working=no])])
109     case $gl_cv_func_re_compile_pattern_working in #(
110     yes) ac_use_included_regex=no;; #(
111     no) ac_use_included_regex=yes;;
112     esac
113     ;;
114   *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
115     ;;
116   esac
117
118   if test $ac_use_included_regex = yes; then
119     AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
120       [Define if you want regoff_t to be at least as wide POSIX requires.])
121     AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
122       [Define to rpl_re_syntax_options if the replacement should be used.])
123     AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
124       [Define to rpl_re_set_syntax if the replacement should be used.])
125     AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
126       [Define to rpl_re_compile_pattern if the replacement should be used.])
127     AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
128       [Define to rpl_re_compile_fastmap if the replacement should be used.])
129     AC_DEFINE([re_search], [rpl_re_search],
130       [Define to rpl_re_search if the replacement should be used.])
131     AC_DEFINE([re_search_2], [rpl_re_search_2],
132       [Define to rpl_re_search_2 if the replacement should be used.])
133     AC_DEFINE([re_match], [rpl_re_match],
134       [Define to rpl_re_match if the replacement should be used.])
135     AC_DEFINE([re_match_2], [rpl_re_match_2],
136       [Define to rpl_re_match_2 if the replacement should be used.])
137     AC_DEFINE([re_set_registers], [rpl_re_set_registers],
138       [Define to rpl_re_set_registers if the replacement should be used.])
139     AC_DEFINE([re_comp], [rpl_re_comp],
140       [Define to rpl_re_comp if the replacement should be used.])
141     AC_DEFINE([re_exec], [rpl_re_exec],
142       [Define to rpl_re_exec if the replacement should be used.])
143     AC_DEFINE([regcomp], [rpl_regcomp],
144       [Define to rpl_regcomp if the replacement should be used.])
145     AC_DEFINE([regexec], [rpl_regexec],
146       [Define to rpl_regexec if the replacement should be used.])
147     AC_DEFINE([regerror], [rpl_regerror],
148       [Define to rpl_regerror if the replacement should be used.])
149     AC_DEFINE([regfree], [rpl_regfree],
150       [Define to rpl_regfree if the replacement should be used.])
151     AC_LIBOBJ([regex])
152     gl_PREREQ_REGEX
153   fi
154 ])
155
156 # Prerequisites of lib/regex.c and lib/regex_internal.c.
157 AC_DEFUN([gl_PREREQ_REGEX],
158 [
159   AC_REQUIRE([AC_GNU_SOURCE])
160   AC_REQUIRE([gl_C_RESTRICT])
161   AC_REQUIRE([AM_LANGINFO_CODESET])
162   AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
163   AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])
164 ])