Use an all-permissive copyright notice, recommended by RMS.
[gnulib.git] / m4 / regex.m4
1 #serial 22
2
3 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004 Free
4 # 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_DEFUN([gl_REGEX],
14 [
15   gl_INCLUDED_REGEX([lib/regex.c])
16 ])
17
18 dnl Usage: gl_INCLUDED_REGEX([lib/regex.c])
19 dnl
20 AC_DEFUN([gl_INCLUDED_REGEX],
21   [
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.
24
25     # Assume we'll default to using the included regex.c.
26     ac_use_included_regex=yes
27
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,
35       AC_TRY_RUN(
36 [#include <stdio.h>
37 #include <string.h>
38 #include <regex.h>
39           int
40           main ()
41           {
42             static struct re_pattern_buffer regex;
43             const char *s;
44             struct re_registers regs;
45             re_set_syntax (RE_SYNTAX_POSIX_EGREP);
46             memset (&regex, 0, sizeof (regex));
47             [s = re_compile_pattern ("a[[:@:>@:]]b\n", 9, &regex);]
48             /* This should fail with _Invalid character class name_ error.  */
49             if (!s)
50               exit (1);
51
52             /* This should succeed, but doesn't for e.g. glibc-2.1.3.  */
53             memset (&regex, 0, sizeof (regex));
54             s = re_compile_pattern ("{1", 2, &regex);
55
56             if (s)
57               exit (1);
58
59             /* The following example is derived from a problem report
60                against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>.  */
61             memset (&regex, 0, sizeof (regex));
62             s = re_compile_pattern ("[[an\371]]*n", 7, &regex);
63             if (s)
64               exit (1);
65
66             /* This should match, but doesn't for e.g. glibc-2.2.1.  */
67             if (re_match (&regex, "an", 2, 0, &regs) != 2)
68               exit (1);
69
70             memset (&regex, 0, sizeof (regex));
71             s = re_compile_pattern ("x", 1, &regex);
72             if (s)
73               exit (1);
74
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 (&regex, "wxy", 3, 2, -2, &regs) != 1)
78               exit (1);
79
80             exit (0);
81           }
82         ],
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
89     fi
90
91     test -n "$1" || AC_MSG_ERROR([missing argument])
92     m4_syscmd([test -f $1])
93     ifelse(m4_sysval, 0,
94       [
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
102           AC_LIBOBJ(regex)
103           gl_PREREQ_REGEX
104         fi
105       ],
106     )
107   ]
108 )
109
110 # Prerequisites of lib/regex.c.
111 AC_DEFUN([gl_PREREQ_REGEX],
112 [
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
115   dnl to get them.
116
117   dnl Persuade glibc <string.h> to declare mempcpy().
118   AC_REQUIRE([AC_GNU_SOURCE])
119
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)
126 ])