Debian Codegraph @

m4/wctype_h.m4

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