Use proper quoting so brackets appear in the test program.
[gnulib.git] / m4 / regex.m4
1 #serial 10
2
3 dnl Initially derived from code in GNU grep.
4 dnl Mostly written by Jim Meyering.
5
6 dnl Usage: jm_INCLUDED_REGEX([lib/regex.c])
7 dnl
8 AC_DEFUN(jm_INCLUDED_REGEX,
9   [
10     dnl Even packages that don't use regex.c can use this macro.
11     dnl Of course, for them it doesn't do anything.
12
13     # Assume we'll default to using the included regex.c.
14     ac_use_included_regex=yes
15
16     # However, if the system regex support is good enough that it passes the
17     # the following run test, then default to *not* using the included regex.c.
18     # If cross compiling, assume the test would fail and use the included
19     # regex.c.  The first failing regular expression is from `Spencer ere
20     # test #75' in grep-2.3.
21     AC_CACHE_CHECK([for working re_compile_pattern],
22                    jm_cv_func_working_re_compile_pattern,
23       AC_TRY_RUN(
24 [#include <stdio.h>
25 #include <regex.h>
26           int
27           main ()
28           {
29             static struct re_pattern_buffer regex;
30             const char *s;
31             struct re_registers regs;
32             re_set_syntax (RE_SYNTAX_POSIX_EGREP);
33             /* These two brackets, `[[' and the one in the comment below serve
34                to quote the brackets (unbalanced) in the following line.  */
35             s = re_compile_pattern ("a[[:]:]]b\n", 9, &regex);
36             /* This bracket `]' helps quote the unbalanced expression above.  */
37             /* This should fail with _Invalid character class name_ error.  */
38             if (!s)
39               exit (1);
40
41             /* This should succeed, but doesn't for e.g. glibc-2.1.3.  */
42             s = re_compile_pattern ("{1", 2, &regex);
43
44             if (s)
45               exit (1);
46
47             /* The following example is derived from a problem report
48                against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
49             s = re_compile_pattern ("[[anĂ¹]]*n", 7, &regex);
50             if (s)
51               exit (1);
52
53             /* This should match, but doesn't for e.g. glibc-2.2.1.  */
54             if (re_match (&regex, "an", 2, 0, &regs) != 2)
55               exit (1);
56
57             exit (0);
58           }
59         ],
60                jm_cv_func_working_re_compile_pattern=yes,
61                jm_cv_func_working_re_compile_pattern=no,
62                dnl When crosscompiling, assume it's broken.
63                jm_cv_func_working_re_compile_pattern=no))
64     if test $jm_cv_func_working_re_compile_pattern = yes; then
65       ac_use_included_regex=no
66     fi
67
68     test -n "$1" || AC_MSG_ERROR([missing argument])
69     m4_syscmd([test -f $1])
70     ifelse(m4_sysval, 0,
71       [
72         AC_ARG_WITH(included-regex,
73         [  --without-included-regex don't compile regex; this is the default on
74                           systems with version 2 of the GNU C library
75                           (use with caution on other system)],
76                     jm_with_regex=$withval,
77                     jm_with_regex=$ac_use_included_regex)
78         if test "$jm_with_regex" = yes; then
79           AC_LIBOBJ(regex)
80         fi
81       ],
82     )
83   ]
84 )