6df403b3a6e8d912bb12c7eafda5100076a43a64
[gnulib.git] / m4 / wctype_h.m4
1 # wctype_h.m4 serial 15
2
3 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
4
5 dnl Copyright (C) 2006-2011 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.
9
10 dnl Written by Paul Eggert.
11
12 AC_DEFUN([gl_WCTYPE_H],
13 [
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
19     HAVE_ISWCNTRL=1
20   else
21     HAVE_ISWCNTRL=0
22   fi
23   AC_SUBST([HAVE_ISWCNTRL])
24
25   AC_REQUIRE([AC_C_INLINE])
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   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],
41         [
42           AC_RUN_IFELSE(
43             [AC_LANG_SOURCE([[
44                /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
45                   included before <wchar.h>.
46                   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
47                   must be included before <wchar.h>.  */
48                #include <stddef.h>
49                #include <stdio.h>
50                #include <time.h>
51                #include <wchar.h>
52                #include <wctype.h>
53                int main () { return iswprint ('x') == 0; }
54             ]])],
55             [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
56             [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
57                           #if __GNU_LIBRARY__ == 1
58                           Linux libc5 i18n is broken.
59                           #endif]], [])],
60               [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no])
61             ])
62         ])
63     fi
64     HAVE_WCTYPE_H=1
65   else
66     HAVE_WCTYPE_H=0
67   fi
68   AC_SUBST([HAVE_WCTYPE_H])
69
70   if test "$gl_cv_func_iswcntrl_works" = no; then
71     REPLACE_ISWCNTRL=1
72   else
73     REPLACE_ISWCNTRL=0
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_DECLS([towlower],,,
86       [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
87            included before <wchar.h>.
88            BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
89            must be included before <wchar.h>.  */
90         #include <stddef.h>
91         #include <stdio.h>
92         #include <time.h>
93         #include <wchar.h>
94         #if HAVE_WCTYPE_H
95         # include <wctype.h>
96         #endif
97       ]])
98     if test $ac_cv_have_decl_towlower = yes; then
99       dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
100       dnl towupper() although it does not have the functions. Avoid a collision
101       dnl with gnulib's replacement.
102       REPLACE_TOWLOWER=1
103     else
104       REPLACE_TOWLOWER=0
105     fi
106   fi
107   AC_SUBST([REPLACE_TOWLOWER])
108
109   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
110     dnl Redefine towlower, towupper in <wctype.h>.
111     :
112   fi
113
114   dnl We assume that the wctype() and iswctype() functions exist if and only
115   dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
116   dnl exists.
117   dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
118   AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
119     [AC_COMPILE_IFELSE(
120        [AC_LANG_PROGRAM(
121           [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
122                included before <wchar.h>.
123                BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
124                must be included before <wchar.h>.  */
125             #include <stddef.h>
126             #include <stdio.h>
127             #include <time.h>
128             #include <wchar.h>
129             #if HAVE_WCTYPE_H
130             # include <wctype.h>
131             #endif
132             wctype_t a;
133           ]],
134           [[]])],
135        [gl_cv_type_wctype_t=yes],
136        [gl_cv_type_wctype_t=no])
137     ])
138   if test $gl_cv_type_wctype_t = no; then
139     HAVE_WCTYPE_T=0
140   fi
141
142   dnl We assume that the wctrans() and towctrans() functions exist if and only
143   dnl if the type wctrans_t is defined in <wctype.h>.
144   AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
145     [AC_COMPILE_IFELSE(
146        [AC_LANG_PROGRAM(
147           [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
148                included before <wchar.h>.
149                BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
150                must be included before <wchar.h>.  */
151             #include <stddef.h>
152             #include <stdio.h>
153             #include <time.h>
154             #include <wchar.h>
155             #include <wctype.h>
156             wctrans_t a;
157           ]],
158           [[]])],
159        [gl_cv_type_wctrans_t=yes],
160        [gl_cv_type_wctrans_t=no])
161     ])
162   if test $gl_cv_type_wctrans_t = no; then
163     HAVE_WCTRANS_T=0
164   fi
165
166   dnl Check for declarations of anything we want to poison if the
167   dnl corresponding gnulib module is not in use.
168   gl_WARN_ON_USE_PREPARE([[
169 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
170    <wchar.h>.
171    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
172    included before <wchar.h>.  */
173 #if !(defined __GLIBC__ && !defined __UCLIBC__)
174 # include <stddef.h>
175 # include <stdio.h>
176 # include <time.h>
177 # include <wchar.h>
178 #endif
179 #include <wctype.h>
180     ]],
181     [wctype iswctype wctrans towctrans
182     ])
183 ])
184
185 AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
186 [
187   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
188   AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
189   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
190   dnl Define it also as a C macro, for the benefit of the unit tests.
191   gl_MODULE_INDICATOR_FOR_TESTS([$1])
192 ])
193
194 AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
195 [
196   GNULIB_ISWBLANK=0;    AC_SUBST([GNULIB_ISWBLANK])
197   GNULIB_WCTYPE=0;      AC_SUBST([GNULIB_WCTYPE])
198   GNULIB_ISWCTYPE=0;    AC_SUBST([GNULIB_ISWCTYPE])
199   GNULIB_WCTRANS=0;     AC_SUBST([GNULIB_WCTRANS])
200   GNULIB_TOWCTRANS=0;   AC_SUBST([GNULIB_TOWCTRANS])
201   dnl Assume proper GNU behavior unless another module says otherwise.
202   HAVE_ISWBLANK=1;      AC_SUBST([HAVE_ISWBLANK])
203   HAVE_WCTYPE_T=1;      AC_SUBST([HAVE_WCTYPE_T])
204   HAVE_WCTRANS_T=1;     AC_SUBST([HAVE_WCTRANS_T])
205   REPLACE_ISWBLANK=0;   AC_SUBST([REPLACE_ISWBLANK])
206 ])