1 # wctype_h.m4 serial 30
3 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
5 dnl Copyright (C) 2006-2021 Free Software Foundation, Inc.
6 dnl This file is free software; the Free Software Foundation
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
10 dnl Written by Paul Eggert.
12 AC_DEFUN_ONCE([gl_WCTYPE_H],
14 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
15 AC_REQUIRE([AC_PROG_CC])
16 AC_REQUIRE([AC_CANONICAL_HOST])
17 AC_CHECK_FUNCS_ONCE([iswcntrl])
18 if test $ac_cv_func_iswcntrl = yes; then
23 AC_SUBST([HAVE_ISWCNTRL])
25 AC_REQUIRE([gt_TYPE_WINT_T])
26 if test $gt_cv_c_wint_t = yes; then
31 AC_SUBST([HAVE_WINT_T])
33 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
35 gl_CHECK_NEXT_HEADERS([wctype.h])
36 if test $ac_cv_header_wctype_h = yes; then
37 if test $ac_cv_func_iswcntrl = yes; then
38 dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
39 dnl The other functions are likely broken in the same way.
40 AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
46 int main () { return iswprint ('x') == 0; }
48 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
49 [dnl Guess no on Linux libc5, yes otherwise.
50 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
51 #if __GNU_LIBRARY__ == 1
52 Linux libc5 i18n is broken.
54 [gl_cv_func_iswcntrl_works="guessing yes"],
55 [gl_cv_func_iswcntrl_works="guessing no"])
63 AC_SUBST([HAVE_WCTYPE_H])
65 if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
68 case "$gl_cv_func_iswcntrl_works" in
69 *yes) REPLACE_ISWCNTRL=0 ;;
70 *) REPLACE_ISWCNTRL=1 ;;
73 AC_SUBST([REPLACE_ISWCNTRL])
75 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
76 dnl Redefine all of iswcntrl, ..., iswxdigit in <wctype.h>.
80 if test $REPLACE_ISWCNTRL = 1; then
83 AC_CHECK_FUNCS([towlower])
84 if test $ac_cv_func_towlower = yes; then
87 AC_CHECK_DECLS([towlower],,,
93 if test $ac_cv_have_decl_towlower = yes; then
94 dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
95 dnl towupper() although it does not have the functions. Avoid a
96 dnl collision with gnulib's replacement.
103 AC_SUBST([REPLACE_TOWLOWER])
105 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
106 dnl Redefine towlower, towupper in <wctype.h>.
110 dnl We assume that the wctype() and iswctype() functions exist if and only
111 dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
113 dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
114 AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
124 [gl_cv_type_wctype_t=yes],
125 [gl_cv_type_wctype_t=no])
127 if test $gl_cv_type_wctype_t = no; then
131 dnl We assume that the wctrans() and towctrans() functions exist if and only
132 dnl if the type wctrans_t is defined in <wctype.h>.
133 AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
141 [gl_cv_type_wctrans_t=yes],
142 [gl_cv_type_wctrans_t=no])
144 if test $gl_cv_type_wctrans_t = no; then
148 dnl Check for declarations of anything we want to poison if the
149 dnl corresponding gnulib module is not in use.
150 gl_WARN_ON_USE_PREPARE([[
151 #if !(defined __GLIBC__ && !defined __UCLIBC__)
156 [wctype iswctype wctrans towctrans
160 # gl_WCTYPE_MODULE_INDICATOR([modulename])
161 # sets the shell variable that indicates the presence of the given module
162 # to a C preprocessor expression that will evaluate to 1.
163 # This macro invocation must not occur in macros that are AC_REQUIREd.
164 AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
166 dnl Ensure to expand the default settings once only.
167 gl_WCTYPE_H_REQUIRE_DEFAULTS
168 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
169 dnl Define it also as a C macro, for the benefit of the unit tests.
170 gl_MODULE_INDICATOR_FOR_TESTS([$1])
173 # Initializes the default values for AC_SUBSTed shell variables.
174 # This macro must not be AC_REQUIREd. It must only be invoked, and only
175 # outside of macros or in macros that are not AC_REQUIREd.
176 AC_DEFUN([gl_WCTYPE_H_REQUIRE_DEFAULTS],
178 m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS], [
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWBLANK])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWDIGIT])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWXDIGIT])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTYPE])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWCTYPE])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTRANS])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOWCTRANS])
187 m4_require(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS])
188 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
191 AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
193 dnl Assume proper GNU behavior unless another module says otherwise.
194 HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK])
195 HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T])
196 HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T])
197 REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK])
198 REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT])
199 REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT])