update COPYING.DOC to fdl version 1.2.
[gnulib.git] / m4 / regex.m4
1 #serial 13
2
3 dnl Initially derived from code in GNU grep.
4 dnl Mostly written by Jim Meyering.
5
6 AC_DEFUN([gl_REGEX],
7 [
8   jm_INCLUDED_REGEX([lib/regex.c])
9 ])
10
11 dnl Usage: jm_INCLUDED_REGEX([lib/regex.c])
12 dnl
13 AC_DEFUN([jm_INCLUDED_REGEX],
14   [
15     dnl Even packages that don't use regex.c can use this macro.
16     dnl Of course, for them it doesn't do anything.
17
18     # Assume we'll default to using the included regex.c.
19     ac_use_included_regex=yes
20
21     # However, if the system regex support is good enough that it passes the
22     # the following run test, then default to *not* using the included regex.c.
23     # If cross compiling, assume the test would fail and use the included
24     # regex.c.  The first failing regular expression is from `Spencer ere
25     # test #75' in grep-2.3.
26     AC_CACHE_CHECK([for working re_compile_pattern],
27                    jm_cv_func_working_re_compile_pattern,
28       AC_TRY_RUN(
29 [#include <stdio.h>
30 #include <regex.h>
31           int
32           main ()
33           {
34             static struct re_pattern_buffer regex;
35             const char *s;
36             struct re_registers regs;
37             re_set_syntax (RE_SYNTAX_POSIX_EGREP);
38             [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, &regex);]
39             /* This should fail with _Invalid character class name_ error.  */
40             if (!s)
41               exit (1);
42
43             /* This should succeed, but doesn't for e.g. glibc-2.1.3.  */
44             s = re_compile_pattern ("{1", 2, &regex);
45
46             if (s)
47               exit (1);
48
49             /* The following example is derived from a problem report
50                against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
51             s = re_compile_pattern ("[[anĂ¹]]*n", 7, &regex);
52             if (s)
53               exit (1);
54
55             /* This should match, but doesn't for e.g. glibc-2.2.1.  */
56             if (re_match (&regex, "an", 2, 0, &regs) != 2)
57               exit (1);
58
59             exit (0);
60           }
61         ],
62                jm_cv_func_working_re_compile_pattern=yes,
63                jm_cv_func_working_re_compile_pattern=no,
64                dnl When crosscompiling, assume it's broken.
65                jm_cv_func_working_re_compile_pattern=no))
66     if test $jm_cv_func_working_re_compile_pattern = yes; then
67       ac_use_included_regex=no
68     fi
69
70     test -n "$1" || AC_MSG_ERROR([missing argument])
71     m4_syscmd([test -f $1])
72     ifelse(m4_sysval, 0,
73       [
74         AC_ARG_WITH(included-regex,
75         [  --without-included-regex don't compile regex; this is the default on
76                           systems with version 2 of the GNU C library
77                           (use with caution on other system)],
78                     jm_with_regex=$withval,
79                     jm_with_regex=$ac_use_included_regex)
80         if test "$jm_with_regex" = yes; then
81           AC_LIBOBJ(regex)
82           jm_PREREQ_REGEX
83         fi
84       ],
85     )
86   ]
87 )
88
89 # Prerequisites of lib/regex.c.
90 AC_DEFUN([jm_PREREQ_REGEX],
91 [
92   dnl FIXME: Maybe provide a btowc replacement someday: solaris-2.5.1 lacks it.
93   dnl FIXME: Check for wctype and iswctype, and and add -lw if necessary
94   dnl to get them.
95
96   dnl Persuade glibc <string.h> to declare mempcpy().
97   AC_REQUIRE([AC_GNU_SOURCE])
98
99   AC_REQUIRE([AC_FUNC_ALLOCA])
100   AC_REQUIRE([AC_HEADER_STDC])
101   AC_CHECK_HEADERS_ONCE(limits.h string.h wchar.h wctype.h)
102   AC_CHECK_FUNCS_ONCE(isascii mempcpy)
103   AC_CHECK_FUNCS(btowc)
104 ])