PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/user/blkfin-apps/inetutils/inetutils-1.6/m4/regex.m4

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