PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/gdb-7/gdb/m4/regex.m4

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