1# wctype_h.m4 serial 18
2
3dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
4
5dnl Copyright (C) 2006-2012 Free Software Foundation, Inc.
6dnl This file is free software; the Free Software Foundation
7dnl gives unlimited permission to copy and/or distribute it,
8dnl with or without modifications, as long as this notice is preserved.
9
10dnl Written by Paul Eggert.
11
12AC_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([gt_TYPE_WINT_T])
26  if test $gt_cv_c_wint_t = yes; then
27    HAVE_WINT_T=1
28  else
29    HAVE_WINT_T=0
30  fi
31  AC_SUBST([HAVE_WINT_T])
32
33  gl_CHECK_NEXT_HEADERS([wctype.h])
34  if test $ac_cv_header_wctype_h = yes; then
35    if test $ac_cv_func_iswcntrl = yes; then
36      dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
37      dnl The other functions are likely broken in the same way.
38      AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
39        [
40          AC_RUN_IFELSE(
41            [AC_LANG_SOURCE([[
42               /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
43                  included before <wchar.h>.
44                  BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
45                  must be included before <wchar.h>.  */
46               #include <stddef.h>
47               #include <stdio.h>
48               #include <time.h>
49               #include <wchar.h>
50               #include <wctype.h>
51               int main () { return iswprint ('x') == 0; }
52            ]])],
53            [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
54            [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
55                          #if __GNU_LIBRARY__ == 1
56                          Linux libc5 i18n is broken.
57                          #endif]], [])],
58              [gl_cv_func_iswcntrl_works="guessing yes"],
59              [gl_cv_func_iswcntrl_works="guessing no"])
60            ])
61        ])
62    fi
63    HAVE_WCTYPE_H=1
64  else
65    HAVE_WCTYPE_H=0
66  fi
67  AC_SUBST([HAVE_WCTYPE_H])
68
69  case "$gl_cv_func_iswcntrl_works" in
70    *yes) REPLACE_ISWCNTRL=0 ;;
71    *)    REPLACE_ISWCNTRL=1 ;;
72  esac
73  AC_SUBST([REPLACE_ISWCNTRL])
74
75  if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
76    dnl Redefine all of iswcntrl, ..., iswxdigit in <wctype.h>.
77    :
78  fi
79
80  if test $REPLACE_ISWCNTRL = 1; then
81    REPLACE_TOWLOWER=1
82  else
83    AC_CHECK_FUNCS([towlower])
84    if test $ac_cv_func_towlower = yes; then
85      REPLACE_TOWLOWER=0
86    else
87      AC_CHECK_DECLS([towlower],,,
88        [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
89             included before <wchar.h>.
90             BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
91             must be included before <wchar.h>.  */
92          #include <stddef.h>
93          #include <stdio.h>
94          #include <time.h>
95          #include <wchar.h>
96          #if HAVE_WCTYPE_H
97          # include <wctype.h>
98          #endif
99        ]])
100      if test $ac_cv_have_decl_towlower = yes; then
101        dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
102        dnl towupper() although it does not have the functions. Avoid a
103        dnl collision with gnulib's replacement.
104        REPLACE_TOWLOWER=1
105      else
106        REPLACE_TOWLOWER=0
107      fi
108    fi
109  fi
110  AC_SUBST([REPLACE_TOWLOWER])
111
112  if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
113    dnl Redefine towlower, towupper in <wctype.h>.
114    :
115  fi
116
117  dnl We assume that the wctype() and iswctype() functions exist if and only
118  dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
119  dnl exists.
120  dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
121  AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
122    [AC_COMPILE_IFELSE(
123       [AC_LANG_PROGRAM(
124          [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
125               included before <wchar.h>.
126               BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
127               must be included before <wchar.h>.  */
128            #include <stddef.h>
129            #include <stdio.h>
130            #include <time.h>
131            #include <wchar.h>
132            #if HAVE_WCTYPE_H
133            # include <wctype.h>
134            #endif
135            wctype_t a;
136          ]],
137          [[]])],
138       [gl_cv_type_wctype_t=yes],
139       [gl_cv_type_wctype_t=no])
140    ])
141  if test $gl_cv_type_wctype_t = no; then
142    HAVE_WCTYPE_T=0
143  fi
144
145  dnl We assume that the wctrans() and towctrans() functions exist if and only
146  dnl if the type wctrans_t is defined in <wctype.h>.
147  AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
148    [AC_COMPILE_IFELSE(
149       [AC_LANG_PROGRAM(
150          [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
151               included before <wchar.h>.
152               BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
153               must be included before <wchar.h>.  */
154            #include <stddef.h>
155            #include <stdio.h>
156            #include <time.h>
157            #include <wchar.h>
158            #include <wctype.h>
159            wctrans_t a;
160          ]],
161          [[]])],
162       [gl_cv_type_wctrans_t=yes],
163       [gl_cv_type_wctrans_t=no])
164    ])
165  if test $gl_cv_type_wctrans_t = no; then
166    HAVE_WCTRANS_T=0
167  fi
168
169  dnl Check for declarations of anything we want to poison if the
170  dnl corresponding gnulib module is not in use.
171  gl_WARN_ON_USE_PREPARE([[
172/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
173   <wchar.h>.
174   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
175   included before <wchar.h>.  */
176#if !(defined __GLIBC__ && !defined __UCLIBC__)
177# include <stddef.h>
178# include <stdio.h>
179# include <time.h>
180# include <wchar.h>
181#endif
182#include <wctype.h>
183    ]],
184    [wctype iswctype wctrans towctrans
185    ])
186])
187
188AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
189[
190  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
191  AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
192  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
193  dnl Define it also as a C macro, for the benefit of the unit tests.
194  gl_MODULE_INDICATOR_FOR_TESTS([$1])
195])
196
197AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
198[
199  GNULIB_ISWBLANK=0;    AC_SUBST([GNULIB_ISWBLANK])
200  GNULIB_WCTYPE=0;      AC_SUBST([GNULIB_WCTYPE])
201  GNULIB_ISWCTYPE=0;    AC_SUBST([GNULIB_ISWCTYPE])
202  GNULIB_WCTRANS=0;     AC_SUBST([GNULIB_WCTRANS])
203  GNULIB_TOWCTRANS=0;   AC_SUBST([GNULIB_TOWCTRANS])
204  dnl Assume proper GNU behavior unless another module says otherwise.
205  HAVE_ISWBLANK=1;      AC_SUBST([HAVE_ISWBLANK])
206  HAVE_WCTYPE_T=1;      AC_SUBST([HAVE_WCTYPE_T])
207  HAVE_WCTRANS_T=1;     AC_SUBST([HAVE_WCTRANS_T])
208  REPLACE_ISWBLANK=0;   AC_SUBST([REPLACE_ISWBLANK])
209])
210