4
0

regex.m4 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #serial 31
  2. # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free
  3. # 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_REQUIRE([AC_SYS_LARGEFILE]) dnl for a sufficently-wide off_t
  14. AC_CACHE_CHECK([whether off_t can be used in a switch statement],
  15. [gl_cv_type_off_t_switch],
  16. [AC_COMPILE_IFELSE(
  17. [AC_LANG_PROGRAM(
  18. [AC_INCLUDES_DEFAULT],
  19. [[off_t o = -1;
  20. switch (o)
  21. {
  22. case -2:
  23. return 1;
  24. case -1:
  25. return 2;
  26. default:
  27. return 0;
  28. }
  29. ]])],
  30. [gl_cv_type_off_t_switch=yes],
  31. [gl_cv_type_off_t_switch=no])])
  32. if test $gl_cv_type_off_t_switch = yes; then
  33. AC_DEFINE([_REGEX_LARGE_OFFSETS], 1,
  34. [Define if you want regoff_t to be at least as wide POSIX requires.])
  35. fi
  36. AC_LIBSOURCES(
  37. [regcomp.c, regex.c, regex.h,
  38. regex_internal.c, regex_internal.h, regexec.c])
  39. AC_ARG_WITH([included-regex],
  40. [AC_HELP_STRING([--without-included-regex],
  41. [don't compile regex; this is the default on
  42. systems with recent-enough versions of the GNU C
  43. Library (use with caution on other systems)])])
  44. case $with_included_regex in
  45. yes|no) ac_use_included_regex=$with_included_regex
  46. ;;
  47. '')
  48. # If the system regex support is good enough that it passes the the
  49. # following run test, then default to *not* using the included regex.c.
  50. # If cross compiling, assume the test would fail and use the included
  51. # regex.c. The first failing regular expression is from `Spencer ere
  52. # test #75' in grep-2.3.
  53. AC_CACHE_CHECK([for working re_compile_pattern],
  54. [gl_cv_func_re_compile_pattern_broken],
  55. [AC_RUN_IFELSE(
  56. [AC_LANG_PROGRAM(
  57. [AC_INCLUDES_DEFAULT
  58. #include <regex.h>],
  59. [[static struct re_pattern_buffer regex;
  60. const char *s;
  61. struct re_registers regs;
  62. /* Use the POSIX-compliant spelling with leading REG_,
  63. rather than the traditional GNU spelling with leading RE_,
  64. so that we reject older libc implementations. */
  65. re_set_syntax (REG_SYNTAX_POSIX_EGREP);
  66. memset (&regex, 0, sizeof (regex));
  67. s = re_compile_pattern ("a[:@:>@:]b\n", 9, &regex);
  68. /* This should fail with _Invalid character class name_ error. */
  69. if (!s)
  70. exit (1);
  71. /* This should succeed, but does not for e.g. glibc-2.1.3. */
  72. memset (&regex, 0, sizeof (regex));
  73. s = re_compile_pattern ("{1", 2, &regex);
  74. if (s)
  75. exit (1);
  76. /* The following example is derived from a problem report
  77. against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
  78. memset (&regex, 0, sizeof (regex));
  79. s = re_compile_pattern ("[an\371]*n", 7, &regex);
  80. if (s)
  81. exit (1);
  82. /* This should match, but does not for e.g. glibc-2.2.1. */
  83. if (re_match (&regex, "an", 2, 0, &regs) != 2)
  84. exit (1);
  85. memset (&regex, 0, sizeof (regex));
  86. s = re_compile_pattern ("x", 1, &regex);
  87. if (s)
  88. exit (1);
  89. /* The version of regex.c in e.g. GNU libc-2.2.93 did not
  90. work with a negative RANGE argument. */
  91. if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
  92. exit (1);
  93. /* The version of regex.c in older versions of gnulib
  94. ignored REG_IGNORE_CASE (which was then called RE_ICASE).
  95. Detect that problem too. */
  96. memset (&regex, 0, sizeof (regex));
  97. re_set_syntax (REG_SYNTAX_EMACS | REG_IGNORE_CASE);
  98. s = re_compile_pattern ("x", 1, &regex);
  99. if (s)
  100. exit (1);
  101. if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
  102. exit (1);
  103. /* REG_STARTEND was added to glibc on 2004-01-15.
  104. Reject older versions. */
  105. if (! REG_STARTEND)
  106. exit (1);
  107. /* Reject hosts whose regoff_t values are too narrow.
  108. These include glibc 2.3.5 on hosts with 64-bit off_t
  109. and 32-bit int, and Solaris 10 on hosts with 32-bit int
  110. and _FILE_OFFSET_BITS=64. */
  111. if (sizeof (regoff_t) < sizeof (off_t))
  112. exit (1);
  113. exit (0);]])],
  114. [gl_cv_func_re_compile_pattern_broken=no],
  115. [gl_cv_func_re_compile_pattern_broken=yes],
  116. dnl When crosscompiling, assume it is broken.
  117. [gl_cv_func_re_compile_pattern_broken=yes])])
  118. ac_use_included_regex=$gl_cv_func_re_compile_pattern_broken
  119. ;;
  120. *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
  121. ;;
  122. esac
  123. if test $ac_use_included_regex = yes; then
  124. AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
  125. [Define to rpl_re_syntax_options if the replacement should be used.])
  126. AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
  127. [Define to rpl_re_set_syntax if the replacement should be used.])
  128. AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
  129. [Define to rpl_re_compile_pattern if the replacement should be used.])
  130. AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
  131. [Define to rpl_re_compile_fastmap if the replacement should be used.])
  132. AC_DEFINE([re_search], [rpl_re_search],
  133. [Define to rpl_re_search if the replacement should be used.])
  134. AC_DEFINE([re_search_2], [rpl_re_search_2],
  135. [Define to rpl_re_search_2 if the replacement should be used.])
  136. AC_DEFINE([re_match], [rpl_re_match],
  137. [Define to rpl_re_match if the replacement should be used.])
  138. AC_DEFINE([re_match_2], [rpl_re_match_2],
  139. [Define to rpl_re_match_2 if the replacement should be used.])
  140. AC_DEFINE([re_set_registers], [rpl_re_set_registers],
  141. [Define to rpl_re_set_registers if the replacement should be used.])
  142. AC_DEFINE([re_comp], [rpl_re_comp],
  143. [Define to rpl_re_comp if the replacement should be used.])
  144. AC_DEFINE([re_exec], [rpl_re_exec],
  145. [Define to rpl_re_exec if the replacement should be used.])
  146. AC_DEFINE([regcomp], [rpl_regcomp],
  147. [Define to rpl_regcomp if the replacement should be used.])
  148. AC_DEFINE([regexec], [rpl_regexec],
  149. [Define to rpl_regexec if the replacement should be used.])
  150. AC_DEFINE([regerror], [rpl_regerror],
  151. [Define to rpl_regerror if the replacement should be used.])
  152. AC_DEFINE([regfree], [rpl_regfree],
  153. [Define to rpl_regfree if the replacement should be used.])
  154. AC_LIBOBJ([regex])
  155. gl_PREREQ_REGEX
  156. fi
  157. ])
  158. # Prerequisites of lib/regex.c and lib/regex_internal.c.
  159. AC_DEFUN([gl_PREREQ_REGEX],
  160. [
  161. AC_REQUIRE([AC_GNU_SOURCE])
  162. AC_REQUIRE([gl_C_RESTRICT])
  163. AC_REQUIRE([AM_LANGINFO_CODESET])
  164. AC_CHECK_HEADERS_ONCE([locale.h wchar.h wctype.h])
  165. AC_CHECK_FUNCS_ONCE([isblank mbrtowc mempcpy wcrtomb wcscoll])
  166. ])