PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/m4/regex.m4

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