1 |
#serial 24 |
#serial 31 |
2 |
|
|
3 |
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free |
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free |
4 |
# Software Foundation, Inc. |
# Software Foundation, Inc. |
10 |
dnl Initially derived from code in GNU grep. |
dnl Initially derived from code in GNU grep. |
11 |
dnl Mostly written by Jim Meyering. |
dnl Mostly written by Jim Meyering. |
12 |
|
|
13 |
|
AC_PREREQ([2.50]) |
14 |
|
|
15 |
AC_DEFUN([gl_REGEX], |
AC_DEFUN([gl_REGEX], |
16 |
[ |
[ |
17 |
gl_INCLUDED_REGEX([lib/regex.c]) |
AC_REQUIRE([AC_SYS_LARGEFILE]) dnl for a sufficently-wide off_t |
|
]) |
|
|
|
|
|
dnl Usage: gl_INCLUDED_REGEX([lib/regex.c]) |
|
|
dnl |
|
|
AC_DEFUN([gl_INCLUDED_REGEX], |
|
|
[ |
|
|
AC_LIBSOURCES( |
|
|
[regcomp.c, regex.c, regex.h, |
|
|
regex_internal.c, regex_internal.h, regexec.c]) |
|
18 |
|
|
19 |
dnl Even packages that don't use regex.c can use this macro. |
AC_CACHE_CHECK([whether off_t can be used in a switch statement], |
20 |
dnl Of course, for them it doesn't do anything. |
[gl_cv_type_off_t_switch], |
21 |
|
[AC_COMPILE_IFELSE( |
22 |
# Assume we'll default to using the included regex.c. |
[AC_LANG_PROGRAM( |
23 |
ac_use_included_regex=yes |
[AC_INCLUDES_DEFAULT], |
24 |
|
[[off_t o = -1; |
25 |
# However, if the system regex support is good enough that it passes the |
switch (o) |
26 |
# the following run test, then default to *not* using the included regex.c. |
{ |
27 |
|
case -2: |
28 |
|
return 1; |
29 |
|
case -1: |
30 |
|
return 2; |
31 |
|
default: |
32 |
|
return 0; |
33 |
|
} |
34 |
|
]])], |
35 |
|
[gl_cv_type_off_t_switch=yes], |
36 |
|
[gl_cv_type_off_t_switch=no])]) |
37 |
|
if test $gl_cv_type_off_t_switch = yes; then |
38 |
|
AC_DEFINE([_REGEX_LARGE_OFFSETS], 1, |
39 |
|
[Define if you want regoff_t to be at least as wide POSIX requires.]) |
40 |
|
fi |
41 |
|
|
42 |
|
AC_LIBSOURCES( |
43 |
|
[regcomp.c, regex.c, regex.h, |
44 |
|
regex_internal.c, regex_internal.h, regexec.c]) |
45 |
|
|
46 |
|
AC_ARG_WITH([included-regex], |
47 |
|
[AC_HELP_STRING([--without-included-regex], |
48 |
|
[don't compile regex; this is the default on |
49 |
|
systems with recent-enough versions of the GNU C |
50 |
|
Library (use with caution on other systems)])]) |
51 |
|
|
52 |
|
case $with_included_regex in |
53 |
|
yes|no) ac_use_included_regex=$with_included_regex |
54 |
|
;; |
55 |
|
'') |
56 |
|
# If the system regex support is good enough that it passes the the |
57 |
|
# following run test, then default to *not* using the included regex.c. |
58 |
# If cross compiling, assume the test would fail and use the included |
# If cross compiling, assume the test would fail and use the included |
59 |
# regex.c. The first failing regular expression is from `Spencer ere |
# regex.c. The first failing regular expression is from `Spencer ere |
60 |
# test #75' in grep-2.3. |
# test #75' in grep-2.3. |
61 |
AC_CACHE_CHECK([for working re_compile_pattern], |
AC_CACHE_CHECK([for working re_compile_pattern], |
62 |
[gl_cv_func_working_re_compile_pattern], |
[gl_cv_func_re_compile_pattern_broken], |
63 |
[AC_RUN_IFELSE( |
[AC_RUN_IFELSE( |
64 |
[AC_LANG_PROGRAM( |
[AC_LANG_PROGRAM( |
65 |
[AC_INCLUDES_DEFAULT |
[AC_INCLUDES_DEFAULT |
66 |
#include <regex.h>], |
#include <regex.h>], |
67 |
[[static struct re_pattern_buffer regex; |
[[static struct re_pattern_buffer regex; |
68 |
const char *s; |
const char *s; |
69 |
struct re_registers regs; |
struct re_registers regs; |
70 |
re_set_syntax (RE_SYNTAX_POSIX_EGREP); |
/* Use the POSIX-compliant spelling with leading REG_, |
71 |
memset (®ex, 0, sizeof (regex)); |
rather than the traditional GNU spelling with leading RE_, |
72 |
s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex); |
so that we reject older libc implementations. */ |
73 |
/* This should fail with _Invalid character class name_ error. */ |
re_set_syntax (REG_SYNTAX_POSIX_EGREP); |
74 |
if (!s) |
memset (®ex, 0, sizeof (regex)); |
75 |
exit (1); |
s = re_compile_pattern ("a[:@:>@:]b\n", 9, ®ex); |
76 |
|
/* This should fail with _Invalid character class name_ error. */ |
77 |
/* This should succeed, but does not for e.g. glibc-2.1.3. */ |
if (!s) |
78 |
memset (®ex, 0, sizeof (regex)); |
exit (1); |
79 |
s = re_compile_pattern ("{1", 2, ®ex); |
|
80 |
|
/* This should succeed, but does not for e.g. glibc-2.1.3. */ |
81 |
if (s) |
memset (®ex, 0, sizeof (regex)); |
82 |
exit (1); |
s = re_compile_pattern ("{1", 2, ®ex); |
83 |
|
|
84 |
/* The following example is derived from a problem report |
if (s) |
85 |
against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ |
exit (1); |
86 |
memset (®ex, 0, sizeof (regex)); |
|
87 |
s = re_compile_pattern ("[an\371]*n", 7, ®ex); |
/* The following example is derived from a problem report |
88 |
if (s) |
against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ |
89 |
exit (1); |
memset (®ex, 0, sizeof (regex)); |
90 |
|
s = re_compile_pattern ("[an\371]*n", 7, ®ex); |
91 |
/* This should match, but does not for e.g. glibc-2.2.1. */ |
if (s) |
92 |
if (re_match (®ex, "an", 2, 0, ®s) != 2) |
exit (1); |
93 |
exit (1); |
|
94 |
|
/* This should match, but does not for e.g. glibc-2.2.1. */ |
95 |
memset (®ex, 0, sizeof (regex)); |
if (re_match (®ex, "an", 2, 0, ®s) != 2) |
96 |
s = re_compile_pattern ("x", 1, ®ex); |
exit (1); |
97 |
if (s) |
|
98 |
exit (1); |
memset (®ex, 0, sizeof (regex)); |
99 |
|
s = re_compile_pattern ("x", 1, ®ex); |
100 |
/* The version of regex.c in e.g. GNU libc-2.2.93 did not |
if (s) |
101 |
work with a negative RANGE argument. */ |
exit (1); |
102 |
if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) |
|
103 |
exit (1); |
/* The version of regex.c in e.g. GNU libc-2.2.93 did not |
104 |
|
work with a negative RANGE argument. */ |
105 |
/* The version of regex.c in older versions of gnulib |
if (re_search (®ex, "wxy", 3, 2, -2, ®s) != 1) |
106 |
* ignored RE_ICASE. Detect that problem too. */ |
exit (1); |
107 |
memset (®ex, 0, sizeof (regex)); |
|
108 |
re_set_syntax(RE_SYNTAX_EMACS|RE_ICASE); |
/* The version of regex.c in older versions of gnulib |
109 |
s = re_compile_pattern ("x", 1, ®ex); |
ignored REG_IGNORE_CASE (which was then called RE_ICASE). |
110 |
if (s) |
Detect that problem too. */ |
111 |
exit (1); |
memset (®ex, 0, sizeof (regex)); |
112 |
|
re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE); |
113 |
if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0) |
s = re_compile_pattern ("x", 1, ®ex); |
114 |
exit (1); |
if (s) |
115 |
|
exit (1); |
116 |
/* REG_STARTEND was added to glibc on 2004-01-15. |
|
117 |
Reject older versions. */ |
if (re_search (®ex, "WXY", 3, 0, 3, ®s) < 0) |
118 |
if (! REG_STARTEND) |
exit (1); |
119 |
exit (1); |
|
120 |
|
/* REG_STARTEND was added to glibc on 2004-01-15. |
121 |
exit (0);]])], |
Reject older versions. */ |
122 |
[gl_cv_func_working_re_compile_pattern=yes], |
if (! REG_STARTEND) |
123 |
[gl_cv_func_working_re_compile_pattern=no], |
exit (1); |
124 |
dnl When crosscompiling, assume it is broken. |
|
125 |
[gl_cv_func_working_re_compile_pattern=no])]) |
/* Reject hosts whose regoff_t values are too narrow. |
126 |
if test $gl_cv_func_working_re_compile_pattern = yes; then |
These include glibc 2.3.5 on hosts with 64-bit off_t |
127 |
ac_use_included_regex=no |
and 32-bit int, and Solaris 10 on hosts with 32-bit int |
128 |
fi |
and _FILE_OFFSET_BITS=64. */ |
129 |
|
if (sizeof (regoff_t) < sizeof (off_t)) |
130 |
test -n "$1" || AC_MSG_ERROR([missing argument]) |
exit (1); |
131 |
m4_syscmd([test -f '$1']) |
|
132 |
ifelse(m4_sysval, 0, |
exit (0);]])], |
133 |
[ |
[gl_cv_func_re_compile_pattern_broken=no], |
134 |
AC_ARG_WITH([included-regex], |
[gl_cv_func_re_compile_pattern_broken=yes], |
135 |
[ --without-included-regex don't compile regex; this is the default on |
dnl When crosscompiling, assume it is broken. |
136 |
systems with recent-enough versions of the GNU C |
[gl_cv_func_re_compile_pattern_broken=yes])]) |
137 |
Library (use with caution on other systems)], |
ac_use_included_regex=$gl_cv_func_re_compile_pattern_broken |
138 |
[gl_with_regex=$withval], |
;; |
139 |
[gl_with_regex=$ac_use_included_regex]) |
*) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex]) |
140 |
if test "X$gl_with_regex" = Xyes; then |
;; |
141 |
AC_LIBOBJ([regex]) |
esac |
142 |
gl_PREREQ_REGEX |
|
143 |
fi |
if test $ac_use_included_regex = yes; then |
144 |
], |
AC_DEFINE([re_syntax_options], [rpl_re_syntax_options], |
145 |
) |
[Define to rpl_re_syntax_options if the replacement should be used.]) |
146 |
] |
AC_DEFINE([re_set_syntax], [rpl_re_set_syntax], |
147 |
) |
[Define to rpl_re_set_syntax if the replacement should be used.]) |
148 |
|
AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern], |
149 |
|
[Define to rpl_re_compile_pattern if the replacement should be used.]) |
150 |
|
AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap], |
151 |
|
[Define to rpl_re_compile_fastmap if the replacement should be used.]) |
152 |
|
AC_DEFINE([re_search], [rpl_re_search], |
153 |
|
[Define to rpl_re_search if the replacement should be used.]) |
154 |
|
AC_DEFINE([re_search_2], [rpl_re_search_2], |
155 |
|
[Define to rpl_re_search_2 if the replacement should be used.]) |
156 |
|
AC_DEFINE([re_match], [rpl_re_match], |
157 |
|
[Define to rpl_re_match if the replacement should be used.]) |
158 |
|
AC_DEFINE([re_match_2], [rpl_re_match_2], |
159 |
|
[Define to rpl_re_match_2 if the replacement should be used.]) |
160 |
|
AC_DEFINE([re_set_registers], [rpl_re_set_registers], |
161 |
|
[Define to rpl_re_set_registers if the replacement should be used.]) |
162 |
|
AC_DEFINE([re_comp], [rpl_re_comp], |
163 |
|
[Define to rpl_re_comp if the replacement should be used.]) |
164 |
|
AC_DEFINE([re_exec], [rpl_re_exec], |
165 |
|
[Define to rpl_re_exec if the replacement should be used.]) |
166 |
|
AC_DEFINE([regcomp], [rpl_regcomp], |
167 |
|
[Define to rpl_regcomp if the replacement should be used.]) |
168 |
|
AC_DEFINE([regexec], [rpl_regexec], |
169 |
|
[Define to rpl_regexec if the replacement should be used.]) |
170 |
|
AC_DEFINE([regerror], [rpl_regerror], |
171 |
|
[Define to rpl_regerror if the replacement should be used.]) |
172 |
|
AC_DEFINE([regfree], [rpl_regfree], |
173 |
|
[Define to rpl_regfree if the replacement should be used.]) |
174 |
|
AC_LIBOBJ([regex]) |
175 |
|
gl_PREREQ_REGEX |
176 |
|
fi |
177 |
|
]) |
178 |
|
|
179 |
# Prerequisites of lib/regex.c and lib/regex_internal.c. |
# Prerequisites of lib/regex.c and lib/regex_internal.c. |
180 |
AC_DEFUN([gl_PREREQ_REGEX], |
AC_DEFUN([gl_PREREQ_REGEX], |
181 |
[ |
[ |
182 |
|
AC_REQUIRE([AC_GNU_SOURCE]) |
183 |
AC_REQUIRE([gl_C_RESTRICT]) |
AC_REQUIRE([gl_C_RESTRICT]) |
184 |
AC_REQUIRE([AM_LANGINFO_CODESET]) |
AC_REQUIRE([AM_LANGINFO_CODESET]) |
185 |
AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h]) |
AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h]) |