regex.m4 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #serial 42
  2. # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
  3. # 2006, 2007 Free Software Foundation, Inc.
  4. #
  5. # This file is free software; the Free Software Foundation
  6. # gives unlimited permission to copy and/or distribute it,
  7. # with or without modifications, as long as this notice is preserved.
  8. dnl Initially derived from code in GNU grep.
  9. dnl Mostly written by Jim Meyering.
  10. AC_PREREQ([2.50])
  11. AC_DEFUN([gl_REGEX],
  12. [
  13. AC_CHECK_HEADERS_ONCE([locale.h])
  14. AC_ARG_WITH([included-regex],
  15. [AC_HELP_STRING([--without-included-regex],
  16. [don't compile regex; this is the default on
  17. systems with recent-enough versions of the GNU C
  18. Library (use with caution on other systems)])])
  19. case $with_included_regex in #(
  20. yes|no) ac_use_included_regex=$with_included_regex
  21. ;;
  22. '')
  23. # If the system regex support is good enough that it passes the
  24. # following run test, then default to *not* using the included regex.c.
  25. # If cross compiling, assume the test would fail and use the included
  26. # regex.c. The first failing regular expression is from `Spencer ere
  27. # test #75' in grep-2.3.
  28. AC_CACHE_CHECK([for working re_compile_pattern],
  29. [gl_cv_func_re_compile_pattern_working],
  30. [AC_RUN_IFELSE(
  31. [AC_LANG_PROGRAM(
  32. [AC_INCLUDES_DEFAULT
  33. #if HAVE_LOCALE_H
  34. #include <locale.h>
  35. #endif
  36. #include <limits.h>
  37. #include <regex.h>
  38. ],
  39. [[static struct re_pattern_buffer regex;
  40. unsigned char folded_chars[UCHAR_MAX + 1];
  41. int i;
  42. const char *s;
  43. struct re_registers regs;
  44. #if HAVE_LOCALE_H
  45. /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
  46. This test needs valgrind to catch the bug on Debian
  47. GNU/Linux 3.1 x86, but it might catch the bug better
  48. on other platforms and it shouldn't hurt to try the
  49. test here. */
  50. if (setlocale (LC_ALL, "en_US.UTF-8"))
  51. {
  52. static char const pat[] = "insert into";
  53. static char const data[] =
  54. "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
  55. re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE
  56. | RE_ICASE);
  57. memset (&regex, 0, sizeof regex);
  58. s = re_compile_pattern (pat, sizeof pat - 1, &regex);
  59. if (s)
  60. return 1;
  61. if (re_search (&regex, data, sizeof data - 1,
  62. 0, sizeof data - 1, &regs)
  63. != -1)
  64. return 1;
  65. if (! setlocale (LC_ALL, "C"))
  66. return 1;
  67. }
  68. #endif
  69. re_set_syntax (RE_SYNTAX_POSIX_EGREP);
  70. memset (&regex, 0, sizeof (regex));
  71. for (i = 0; i <= UCHAR_MAX; i++)
  72. folded_chars[i] = i;
  73. regex.translate = folded_chars;
  74. s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
  75. /* This should fail with _Invalid character class name_ error. */
  76. if (!s)
  77. exit (1);
  78. /* This should succeed, but does not for e.g. glibc-2.1.3. */
  79. memset (&regex, 0, sizeof (regex));
  80. s = re_compile_pattern ("{1", 2, &regex);
  81. if (s)
  82. exit (1);
  83. /* The following example is derived from a problem report
  84. against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
  85. memset (&regex, 0, sizeof (regex));
  86. s = re_compile_pattern ("[an\371]*n", 7, &regex);
  87. if (s)
  88. exit (1);
  89. /* This should match, but does not for e.g. glibc-2.2.1. */
  90. if (re_match (&regex, "an", 2, 0, &regs) != 2)
  91. exit (1);
  92. memset (&regex, 0, sizeof (regex));
  93. s = re_compile_pattern ("x", 1, &regex);
  94. if (s)
  95. exit (1);
  96. /* The version of regex.c in e.g. GNU libc-2.2.93 did not
  97. work with a negative RANGE argument. */
  98. if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
  99. exit (1);
  100. /* The version of regex.c in older versions of gnulib
  101. ignored RE_ICASE. Detect that problem too. */
  102. memset (&regex, 0, sizeof (regex));
  103. re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
  104. s = re_compile_pattern ("x", 1, &regex);
  105. if (s)
  106. exit (1);
  107. if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
  108. exit (1);
  109. /* REG_STARTEND was added to glibc on 2004-01-15.
  110. Reject older versions. */
  111. if (! REG_STARTEND)
  112. exit (1);
  113. /* Reject hosts whose regoff_t values are too narrow.
  114. These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
  115. and 32-bit int. */
  116. if (sizeof (regoff_t) < sizeof (ptrdiff_t)
  117. || sizeof (regoff_t) < sizeof (ssize_t))
  118. exit (1);
  119. exit (0);]])],
  120. [gl_cv_func_re_compile_pattern_working=yes],
  121. [gl_cv_func_re_compile_pattern_working=no],
  122. dnl When crosscompiling, assume it is not working.
  123. [gl_cv_func_re_compile_pattern_working=no])])
  124. case $gl_cv_func_re_compile_pattern_working in #(
  125. yes) ac_use_included_regex=no;; #(
  126. no) ac_use_included_regex=yes;;
  127. esac
  128. ;;
  129. *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
  130. ;;
  131. esac
  132. if test $ac_use_included_regex = yes; then
  133. AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
  134. [Define if you want regoff_t to be at least as wide POSIX requires.])
  135. AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
  136. [Define to rpl_re_syntax_options if the replacement should be used.])
  137. AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
  138. [Define to rpl_re_set_syntax if the replacement should be used.])
  139. AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
  140. [Define to rpl_re_compile_pattern if the replacement should be used.])
  141. AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
  142. [Define to rpl_re_compile_fastmap if the replacement should be used.])
  143. AC_DEFINE([re_search], [rpl_re_search],
  144. [Define to rpl_re_search if the replacement should be used.])
  145. AC_DEFINE([re_search_2], [rpl_re_search_2],
  146. [Define to rpl_re_search_2 if the replacement should be used.])
  147. AC_DEFINE([re_match], [rpl_re_match],
  148. [Define to rpl_re_match if the replacement should be used.])
  149. AC_DEFINE([re_match_2], [rpl_re_match_2],
  150. [Define to rpl_re_match_2 if the replacement should be used.])
  151. AC_DEFINE([re_set_registers], [rpl_re_set_registers],
  152. [Define to rpl_re_set_registers if the replacement should be used.])
  153. AC_DEFINE([re_comp], [rpl_re_comp],
  154. [Define to rpl_re_comp if the replacement should be used.])
  155. AC_DEFINE([re_exec], [rpl_re_exec],
  156. [Define to rpl_re_exec if the replacement should be used.])
  157. AC_DEFINE([regcomp], [rpl_regcomp],
  158. [Define to rpl_regcomp if the replacement should be used.])
  159. AC_DEFINE([regexec], [rpl_regexec],
  160. [Define to rpl_regexec if the replacement should be used.])
  161. AC_DEFINE([regerror], [rpl_regerror],
  162. [Define to rpl_regerror if the replacement should be used.])
  163. AC_DEFINE([regfree], [rpl_regfree],
  164. [Define to rpl_regfree if the replacement should be used.])
  165. AC_LIBOBJ([regex])
  166. gl_PREREQ_REGEX
  167. fi
  168. ])
  169. # Prerequisites of lib/regex.c and lib/regex_internal.c.
  170. AC_DEFUN([gl_PREREQ_REGEX],
  171. [
  172. AC_REQUIRE([AC_GNU_SOURCE])
  173. AC_REQUIRE([AC_C_RESTRICT])
  174. AC_REQUIRE([AM_LANGINFO_CODESET])
  175. AC_CHECK_FUNCS_ONCE([iswctype mbrtowc mempcpy wcrtomb wcscoll])
  176. AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
  177. ])