wctype_h.m4 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # wctype_h.m4 serial 30
  2. dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
  3. dnl Copyright (C) 2006-2023 Free Software Foundation, Inc.
  4. dnl This file is free software; the Free Software Foundation
  5. dnl gives unlimited permission to copy and/or distribute it,
  6. dnl with or without modifications, as long as this notice is preserved.
  7. dnl Written by Paul Eggert.
  8. AC_DEFUN_ONCE([gl_WCTYPE_H],
  9. [
  10. AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
  11. AC_REQUIRE([AC_PROG_CC])
  12. AC_REQUIRE([AC_CANONICAL_HOST])
  13. AC_CHECK_FUNCS_ONCE([iswcntrl])
  14. if test $ac_cv_func_iswcntrl = yes; then
  15. HAVE_ISWCNTRL=1
  16. else
  17. HAVE_ISWCNTRL=0
  18. fi
  19. AC_SUBST([HAVE_ISWCNTRL])
  20. AC_REQUIRE([gt_TYPE_WINT_T])
  21. if test $gt_cv_c_wint_t = yes; then
  22. HAVE_WINT_T=1
  23. else
  24. HAVE_WINT_T=0
  25. fi
  26. AC_SUBST([HAVE_WINT_T])
  27. AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
  28. gl_CHECK_NEXT_HEADERS([wctype.h])
  29. if test $ac_cv_header_wctype_h = yes; then
  30. if test $ac_cv_func_iswcntrl = yes; then
  31. dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
  32. dnl The other functions are likely broken in the same way.
  33. AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
  34. [
  35. AC_RUN_IFELSE(
  36. [AC_LANG_SOURCE([[
  37. #include <wchar.h>
  38. #include <wctype.h>
  39. int main () { return iswprint ('x') == 0; }
  40. ]])],
  41. [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
  42. [dnl Guess no on Linux libc5, yes otherwise.
  43. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
  44. #if __GNU_LIBRARY__ == 1
  45. Linux libc5 i18n is broken.
  46. #endif]], [[]])],
  47. [gl_cv_func_iswcntrl_works="guessing yes"],
  48. [gl_cv_func_iswcntrl_works="guessing no"])
  49. ])
  50. ])
  51. fi
  52. HAVE_WCTYPE_H=1
  53. else
  54. HAVE_WCTYPE_H=0
  55. fi
  56. AC_SUBST([HAVE_WCTYPE_H])
  57. if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
  58. REPLACE_ISWCNTRL=1
  59. else
  60. case "$gl_cv_func_iswcntrl_works" in
  61. *yes) REPLACE_ISWCNTRL=0 ;;
  62. *) REPLACE_ISWCNTRL=1 ;;
  63. esac
  64. fi
  65. AC_SUBST([REPLACE_ISWCNTRL])
  66. if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
  67. dnl Redefine all of iswcntrl, ..., iswxdigit in <wctype.h>.
  68. :
  69. fi
  70. if test $REPLACE_ISWCNTRL = 1; then
  71. REPLACE_TOWLOWER=1
  72. else
  73. AC_CHECK_FUNCS([towlower])
  74. if test $ac_cv_func_towlower = yes; then
  75. REPLACE_TOWLOWER=0
  76. else
  77. AC_CHECK_DECLS([towlower],,,
  78. [[#include <wchar.h>
  79. #if HAVE_WCTYPE_H
  80. # include <wctype.h>
  81. #endif
  82. ]])
  83. if test $ac_cv_have_decl_towlower = yes; then
  84. dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
  85. dnl towupper() although it does not have the functions. Avoid a
  86. dnl collision with gnulib's replacement.
  87. REPLACE_TOWLOWER=1
  88. else
  89. REPLACE_TOWLOWER=0
  90. fi
  91. fi
  92. fi
  93. AC_SUBST([REPLACE_TOWLOWER])
  94. if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
  95. dnl Redefine towlower, towupper in <wctype.h>.
  96. :
  97. fi
  98. dnl We assume that the wctype() and iswctype() functions exist if and only
  99. dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
  100. dnl exists.
  101. dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
  102. AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
  103. [AC_COMPILE_IFELSE(
  104. [AC_LANG_PROGRAM(
  105. [[#include <wchar.h>
  106. #if HAVE_WCTYPE_H
  107. # include <wctype.h>
  108. #endif
  109. wctype_t a;
  110. ]],
  111. [[]])],
  112. [gl_cv_type_wctype_t=yes],
  113. [gl_cv_type_wctype_t=no])
  114. ])
  115. if test $gl_cv_type_wctype_t = no; then
  116. HAVE_WCTYPE_T=0
  117. fi
  118. dnl We assume that the wctrans() and towctrans() functions exist if and only
  119. dnl if the type wctrans_t is defined in <wctype.h>.
  120. AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
  121. [AC_COMPILE_IFELSE(
  122. [AC_LANG_PROGRAM(
  123. [[#include <wchar.h>
  124. #include <wctype.h>
  125. wctrans_t a;
  126. ]],
  127. [[]])],
  128. [gl_cv_type_wctrans_t=yes],
  129. [gl_cv_type_wctrans_t=no])
  130. ])
  131. if test $gl_cv_type_wctrans_t = no; then
  132. HAVE_WCTRANS_T=0
  133. fi
  134. dnl Check for declarations of anything we want to poison if the
  135. dnl corresponding gnulib module is not in use.
  136. gl_WARN_ON_USE_PREPARE([[
  137. #if !(defined __GLIBC__ && !defined __UCLIBC__)
  138. # include <wchar.h>
  139. #endif
  140. #include <wctype.h>
  141. ]],
  142. [wctype iswctype wctrans towctrans
  143. ])
  144. ])
  145. # gl_WCTYPE_MODULE_INDICATOR([modulename])
  146. # sets the shell variable that indicates the presence of the given module
  147. # to a C preprocessor expression that will evaluate to 1.
  148. # This macro invocation must not occur in macros that are AC_REQUIREd.
  149. AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
  150. [
  151. dnl Ensure to expand the default settings once only.
  152. gl_WCTYPE_H_REQUIRE_DEFAULTS
  153. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  154. dnl Define it also as a C macro, for the benefit of the unit tests.
  155. gl_MODULE_INDICATOR_FOR_TESTS([$1])
  156. ])
  157. # Initializes the default values for AC_SUBSTed shell variables.
  158. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  159. # outside of macros or in macros that are not AC_REQUIREd.
  160. AC_DEFUN([gl_WCTYPE_H_REQUIRE_DEFAULTS],
  161. [
  162. m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS], [
  163. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWBLANK])
  164. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWDIGIT])
  165. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWXDIGIT])
  166. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTYPE])
  167. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWCTYPE])
  168. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTRANS])
  169. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOWCTRANS])
  170. ])
  171. m4_require(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS])
  172. AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
  173. ])
  174. AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
  175. [
  176. dnl Assume proper GNU behavior unless another module says otherwise.
  177. HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK])
  178. HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T])
  179. HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T])
  180. REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK])
  181. REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT])
  182. REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT])
  183. ])