4 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
6 dnl Copyright (C) 2006-2024 Free Software Foundation, Inc.
7 dnl This file is free software; the Free Software Foundation
8 dnl gives unlimited permission to copy and/or distribute it,
9 dnl with or without modifications, as long as this notice is preserved.
11 dnl Written by Paul Eggert.
13 AC_DEFUN_ONCE([gl_WCTYPE_H],
15 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
16 AC_REQUIRE([AC_PROG_CC])
17 AC_REQUIRE([AC_CANONICAL_HOST])
18 AC_CHECK_FUNCS_ONCE([iswcntrl])
19 if test $ac_cv_func_iswcntrl = yes; then
24 AC_SUBST([HAVE_ISWCNTRL])
26 AC_REQUIRE([gt_TYPE_WINT_T])
27 if test $gt_cv_c_wint_t = yes; then
32 AC_SUBST([HAVE_WINT_T])
34 AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
36 gl_CHECK_NEXT_HEADERS([wctype.h])
37 if test $ac_cv_header_wctype_h = yes; then
38 if test $ac_cv_func_iswcntrl = yes; then
39 dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
40 dnl The other functions are likely broken in the same way.
41 AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
47 int main () { return iswprint ('x') == 0; }
49 [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
50 [dnl Guess no on Linux libc5, yes otherwise.
51 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
52 #if __GNU_LIBRARY__ == 1
53 Linux libc5 i18n is broken.
55 [gl_cv_func_iswcntrl_works="guessing yes"],
56 [gl_cv_func_iswcntrl_works="guessing no"])
64 AC_SUBST([HAVE_WCTYPE_H])
66 if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
69 case "$gl_cv_func_iswcntrl_works" in
70 *yes) REPLACE_ISWCNTRL=0 ;;
71 *) REPLACE_ISWCNTRL=1 ;;
74 AC_SUBST([REPLACE_ISWCNTRL])
76 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
77 dnl Redefine all of iswcntrl, ..., iswxdigit in <wctype.h>.
81 if test $REPLACE_ISWCNTRL = 1; then
84 AC_CHECK_FUNCS([towlower])
85 if test $ac_cv_func_towlower = yes; then
88 AC_CHECK_DECLS([towlower],,,
94 if test $ac_cv_have_decl_towlower = yes; then
95 dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
96 dnl towupper() although it does not have the functions. Avoid a
97 dnl collision with gnulib's replacement.
104 AC_SUBST([REPLACE_TOWLOWER])
106 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
107 dnl Redefine towlower, towupper in <wctype.h>.
111 dnl We assume that the wctype() and iswctype() functions exist if and only
112 dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
114 dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
115 AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
125 [gl_cv_type_wctype_t=yes],
126 [gl_cv_type_wctype_t=no])
128 if test $gl_cv_type_wctype_t = no; then
132 dnl We assume that the wctrans() and towctrans() functions exist if and only
133 dnl if the type wctrans_t is defined in <wctype.h>.
134 AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
142 [gl_cv_type_wctrans_t=yes],
143 [gl_cv_type_wctrans_t=no])
145 if test $gl_cv_type_wctrans_t = no; then
149 dnl Check for declarations of anything we want to poison if the
150 dnl corresponding gnulib module is not in use.
151 gl_WARN_ON_USE_PREPARE([[
152 #if !(defined __GLIBC__ && !defined __UCLIBC__)
157 [wctype iswctype wctrans towctrans
161 # gl_WCTYPE_MODULE_INDICATOR([modulename])
162 # sets the shell variable that indicates the presence of the given module
163 # to a C preprocessor expression that will evaluate to 1.
164 # This macro invocation must not occur in macros that are AC_REQUIREd.
165 AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
167 dnl Ensure to expand the default settings once only.
168 gl_WCTYPE_H_REQUIRE_DEFAULTS
169 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
170 dnl Define it also as a C macro, for the benefit of the unit tests.
171 gl_MODULE_INDICATOR_FOR_TESTS([$1])
174 # Initializes the default values for AC_SUBSTed shell variables.
175 # This macro must not be AC_REQUIREd. It must only be invoked, and only
176 # outside of macros or in macros that are not AC_REQUIREd.
177 AC_DEFUN([gl_WCTYPE_H_REQUIRE_DEFAULTS],
179 m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS], [
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWBLANK])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWDIGIT])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWPUNCT])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWXDIGIT])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTYPE])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWCTYPE])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTRANS])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOWCTRANS])
189 m4_require(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS])
190 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
193 AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
195 dnl Assume proper GNU behavior unless another module says otherwise.
196 HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK])
197 HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T])
198 HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T])
199 REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK])
200 REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT])
201 REPLACE_ISWPUNCT=0; AC_SUBST([REPLACE_ISWPUNCT])
202 REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT])
203 REPLACE_WCTRANS=0; AC_SUBST([REPLACE_WCTRANS])
204 REPLACE_WCTYPE=0; AC_SUBST([REPLACE_WCTYPE])