PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/amanda/tags/3_3_0beta1/config/gnulib/regex.m4

#
m4 | 230 lines | 186 code | 25 blank | 19 comment | 0 complexity | 07ea1943c8f0bf31248065e781d50902 MD5 | raw file
  1. # serial 56
  2. # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
  3. # 2007, 2008, 2009, 2010 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. [AS_HELP_STRING([--without-included-regex],
  16. [don't compile regex; this is the default on systems
  17. with recent-enough versions of the GNU C Library
  18. (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.
  27. AC_CACHE_CHECK([for working re_compile_pattern],
  28. [gl_cv_func_re_compile_pattern_working],
  29. [AC_RUN_IFELSE(
  30. [AC_LANG_PROGRAM(
  31. [AC_INCLUDES_DEFAULT[
  32. #if HAVE_LOCALE_H
  33. #include <locale.h>
  34. #endif
  35. #include <limits.h>
  36. #include <regex.h>
  37. ]],
  38. [[static struct re_pattern_buffer regex;
  39. unsigned char folded_chars[UCHAR_MAX + 1];
  40. int i;
  41. const char *s;
  42. struct re_registers regs;
  43. #if HAVE_LOCALE_H
  44. /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
  45. This test needs valgrind to catch the bug on Debian
  46. GNU/Linux 3.1 x86, but it might catch the bug better
  47. on other platforms and it shouldn't hurt to try the
  48. test here. */
  49. if (setlocale (LC_ALL, "en_US.UTF-8"))
  50. {
  51. static char const pat[] = "insert into";
  52. static char const data[] =
  53. "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
  54. re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE
  55. | RE_ICASE);
  56. memset (&regex, 0, sizeof regex);
  57. s = re_compile_pattern (pat, sizeof pat - 1, &regex);
  58. if (s)
  59. return 1;
  60. if (re_search (&regex, data, sizeof data - 1,
  61. 0, sizeof data - 1, &regs)
  62. != -1)
  63. return 1;
  64. if (! setlocale (LC_ALL, "C"))
  65. return 1;
  66. }
  67. #endif
  68. /* This test is from glibc bug 3957, reported by Andrew Mackey. */
  69. re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
  70. memset (&regex, 0, sizeof regex);
  71. s = re_compile_pattern ("a[^x]b", 6, &regex);
  72. if (s)
  73. return 1;
  74. /* This should fail, but succeeds for glibc-2.5. */
  75. if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
  76. return 1;
  77. /* This regular expression is from Spencer ere test number 75
  78. in grep-2.3. */
  79. re_set_syntax (RE_SYNTAX_POSIX_EGREP);
  80. memset (&regex, 0, sizeof regex);
  81. for (i = 0; i <= UCHAR_MAX; i++)
  82. folded_chars[i] = i;
  83. regex.translate = folded_chars;
  84. s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
  85. /* This should fail with _Invalid character class name_ error. */
  86. if (!s)
  87. return 1;
  88. /* Ensure that [b-a] is diagnosed as invalid, when
  89. using RE_NO_EMPTY_RANGES. */
  90. re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES);
  91. memset (&regex, 0, sizeof regex);
  92. s = re_compile_pattern ("a[b-a]", 6, &regex);
  93. if (s == 0)
  94. return 1;
  95. /* This should succeed, but does not for glibc-2.1.3. */
  96. memset (&regex, 0, sizeof regex);
  97. s = re_compile_pattern ("{1", 2, &regex);
  98. if (s)
  99. return 1;
  100. /* The following example is derived from a problem report
  101. against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
  102. memset (&regex, 0, sizeof regex);
  103. s = re_compile_pattern ("[an\371]*n", 7, &regex);
  104. if (s)
  105. return 1;
  106. /* This should match, but does not for glibc-2.2.1. */
  107. if (re_match (&regex, "an", 2, 0, &regs) != 2)
  108. return 1;
  109. memset (&regex, 0, sizeof regex);
  110. s = re_compile_pattern ("x", 1, &regex);
  111. if (s)
  112. return 1;
  113. /* glibc-2.2.93 does not work with a negative RANGE argument. */
  114. if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
  115. return 1;
  116. /* The version of regex.c in older versions of gnulib
  117. ignored RE_ICASE. Detect that problem too. */
  118. re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
  119. memset (&regex, 0, sizeof regex);
  120. s = re_compile_pattern ("x", 1, &regex);
  121. if (s)
  122. return 1;
  123. if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
  124. return 1;
  125. /* Catch a bug reported by Vin Shelton in
  126. http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
  127. */
  128. re_set_syntax (RE_SYNTAX_POSIX_BASIC
  129. & ~RE_CONTEXT_INVALID_DUP
  130. & ~RE_NO_EMPTY_RANGES);
  131. memset (&regex, 0, sizeof regex);
  132. s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
  133. if (s)
  134. return 1;
  135. /* REG_STARTEND was added to glibc on 2004-01-15.
  136. Reject older versions. */
  137. if (! REG_STARTEND)
  138. return 1;
  139. /* Reject hosts whose regoff_t values are too narrow.
  140. These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t
  141. and 32-bit int. */
  142. if (sizeof (regoff_t) < sizeof (ptrdiff_t)
  143. || sizeof (regoff_t) < sizeof (ssize_t))
  144. return 1;
  145. return 0;]])],
  146. [gl_cv_func_re_compile_pattern_working=yes],
  147. [gl_cv_func_re_compile_pattern_working=no],
  148. dnl When crosscompiling, assume it is not working.
  149. [gl_cv_func_re_compile_pattern_working=no])])
  150. case $gl_cv_func_re_compile_pattern_working in #(
  151. yes) ac_use_included_regex=no;; #(
  152. no) ac_use_included_regex=yes;;
  153. esac
  154. ;;
  155. *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
  156. ;;
  157. esac
  158. if test $ac_use_included_regex = yes; then
  159. AC_DEFINE([_REGEX_LARGE_OFFSETS], [1],
  160. [Define if you want regoff_t to be at least as wide POSIX requires.])
  161. AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
  162. [Define to rpl_re_syntax_options if the replacement should be used.])
  163. AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
  164. [Define to rpl_re_set_syntax if the replacement should be used.])
  165. AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
  166. [Define to rpl_re_compile_pattern if the replacement should be used.])
  167. AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
  168. [Define to rpl_re_compile_fastmap if the replacement should be used.])
  169. AC_DEFINE([re_search], [rpl_re_search],
  170. [Define to rpl_re_search if the replacement should be used.])
  171. AC_DEFINE([re_search_2], [rpl_re_search_2],
  172. [Define to rpl_re_search_2 if the replacement should be used.])
  173. AC_DEFINE([re_match], [rpl_re_match],
  174. [Define to rpl_re_match if the replacement should be used.])
  175. AC_DEFINE([re_match_2], [rpl_re_match_2],
  176. [Define to rpl_re_match_2 if the replacement should be used.])
  177. AC_DEFINE([re_set_registers], [rpl_re_set_registers],
  178. [Define to rpl_re_set_registers if the replacement should be used.])
  179. AC_DEFINE([re_comp], [rpl_re_comp],
  180. [Define to rpl_re_comp if the replacement should be used.])
  181. AC_DEFINE([re_exec], [rpl_re_exec],
  182. [Define to rpl_re_exec if the replacement should be used.])
  183. AC_DEFINE([regcomp], [rpl_regcomp],
  184. [Define to rpl_regcomp if the replacement should be used.])
  185. AC_DEFINE([regexec], [rpl_regexec],
  186. [Define to rpl_regexec if the replacement should be used.])
  187. AC_DEFINE([regerror], [rpl_regerror],
  188. [Define to rpl_regerror if the replacement should be used.])
  189. AC_DEFINE([regfree], [rpl_regfree],
  190. [Define to rpl_regfree if the replacement should be used.])
  191. AC_LIBOBJ([regex])
  192. gl_PREREQ_REGEX
  193. fi
  194. ])
  195. # Prerequisites of lib/regex.c and lib/regex_internal.c.
  196. AC_DEFUN([gl_PREREQ_REGEX],
  197. [
  198. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  199. AC_REQUIRE([AC_C_INLINE])
  200. AC_REQUIRE([AC_C_RESTRICT])
  201. AC_REQUIRE([AC_TYPE_MBSTATE_T])
  202. AC_CHECK_HEADERS([libintl.h])
  203. AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll])
  204. AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
  205. ])