Blame m4/wctype_h.m4

Packit 33f14e
# wctype_h.m4 serial 20
Packit 33f14e
Packit 33f14e
dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
Packit 33f14e
Packit 33f14e
dnl Copyright (C) 2006-2017 Free Software Foundation, Inc.
Packit 33f14e
dnl This file is free software; the Free Software Foundation
Packit 33f14e
dnl gives unlimited permission to copy and/or distribute it,
Packit 33f14e
dnl with or without modifications, as long as this notice is preserved.
Packit 33f14e
Packit 33f14e
dnl Written by Paul Eggert.
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_WCTYPE_H],
Packit 33f14e
[
Packit 33f14e
  AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
Packit 33f14e
  AC_REQUIRE([AC_PROG_CC])
Packit 33f14e
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 33f14e
  AC_CHECK_FUNCS_ONCE([iswcntrl])
Packit 33f14e
  if test $ac_cv_func_iswcntrl = yes; then
Packit 33f14e
    HAVE_ISWCNTRL=1
Packit 33f14e
  else
Packit 33f14e
    HAVE_ISWCNTRL=0
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([HAVE_ISWCNTRL])
Packit 33f14e
Packit 33f14e
  AC_REQUIRE([gt_TYPE_WINT_T])
Packit 33f14e
  if test $gt_cv_c_wint_t = yes; then
Packit 33f14e
    HAVE_WINT_T=1
Packit 33f14e
  else
Packit 33f14e
    HAVE_WINT_T=0
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([HAVE_WINT_T])
Packit 33f14e
Packit 33f14e
  AC_REQUIRE([gl_TYPE_WINT_T_PREREQ])
Packit 33f14e
Packit 33f14e
  gl_CHECK_NEXT_HEADERS([wctype.h])
Packit 33f14e
  if test $ac_cv_header_wctype_h = yes; then
Packit 33f14e
    if test $ac_cv_func_iswcntrl = yes; then
Packit 33f14e
      dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
Packit 33f14e
      dnl The other functions are likely broken in the same way.
Packit 33f14e
      AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
Packit 33f14e
        [
Packit 33f14e
          AC_RUN_IFELSE(
Packit 33f14e
            [AC_LANG_SOURCE([[
Packit 33f14e
               /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
Packit 33f14e
                  included before <wchar.h>.
Packit 33f14e
                  BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
Packit 33f14e
                  must be included before <wchar.h>.  */
Packit 33f14e
               #include <stddef.h>
Packit 33f14e
               #include <stdio.h>
Packit 33f14e
               #include <time.h>
Packit 33f14e
               #include <wchar.h>
Packit 33f14e
               #include <wctype.h>
Packit 33f14e
               int main () { return iswprint ('x') == 0; }
Packit 33f14e
            ]])],
Packit 33f14e
            [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
Packit 33f14e
            [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
Packit 33f14e
                          #if __GNU_LIBRARY__ == 1
Packit 33f14e
                          Linux libc5 i18n is broken.
Packit 33f14e
                          #endif]], [])],
Packit 33f14e
              [gl_cv_func_iswcntrl_works="guessing yes"],
Packit 33f14e
              [gl_cv_func_iswcntrl_works="guessing no"])
Packit 33f14e
            ])
Packit 33f14e
        ])
Packit 33f14e
    fi
Packit 33f14e
    HAVE_WCTYPE_H=1
Packit 33f14e
  else
Packit 33f14e
    HAVE_WCTYPE_H=0
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([HAVE_WCTYPE_H])
Packit 33f14e
Packit 33f14e
  case "$gl_cv_func_iswcntrl_works" in
Packit 33f14e
    *yes) REPLACE_ISWCNTRL=0 ;;
Packit 33f14e
    *)    REPLACE_ISWCNTRL=1 ;;
Packit 33f14e
  esac
Packit 33f14e
  AC_SUBST([REPLACE_ISWCNTRL])
Packit 33f14e
Packit 33f14e
  if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
Packit 33f14e
    dnl Redefine all of iswcntrl, ..., iswxdigit in <wctype.h>.
Packit 33f14e
    :
Packit 33f14e
  fi
Packit 33f14e
Packit 33f14e
  if test $REPLACE_ISWCNTRL = 1; then
Packit 33f14e
    REPLACE_TOWLOWER=1
Packit 33f14e
  else
Packit 33f14e
    AC_CHECK_FUNCS([towlower])
Packit 33f14e
    if test $ac_cv_func_towlower = yes; then
Packit 33f14e
      REPLACE_TOWLOWER=0
Packit 33f14e
    else
Packit 33f14e
      AC_CHECK_DECLS([towlower],,,
Packit 33f14e
        [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
Packit 33f14e
             included before <wchar.h>.
Packit 33f14e
             BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
Packit 33f14e
             must be included before <wchar.h>.  */
Packit 33f14e
          #include <stddef.h>
Packit 33f14e
          #include <stdio.h>
Packit 33f14e
          #include <time.h>
Packit 33f14e
          #include <wchar.h>
Packit 33f14e
          #if HAVE_WCTYPE_H
Packit 33f14e
          # include <wctype.h>
Packit 33f14e
          #endif
Packit 33f14e
        ]])
Packit 33f14e
      if test $ac_cv_have_decl_towlower = yes; then
Packit 33f14e
        dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
Packit 33f14e
        dnl towupper() although it does not have the functions. Avoid a
Packit 33f14e
        dnl collision with gnulib's replacement.
Packit 33f14e
        REPLACE_TOWLOWER=1
Packit 33f14e
      else
Packit 33f14e
        REPLACE_TOWLOWER=0
Packit 33f14e
      fi
Packit 33f14e
    fi
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([REPLACE_TOWLOWER])
Packit 33f14e
Packit 33f14e
  if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
Packit 33f14e
    dnl Redefine towlower, towupper in <wctype.h>.
Packit 33f14e
    :
Packit 33f14e
  fi
Packit 33f14e
Packit 33f14e
  dnl We assume that the wctype() and iswctype() functions exist if and only
Packit 33f14e
  dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
Packit 33f14e
  dnl exists.
Packit 33f14e
  dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
Packit 33f14e
  AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
Packit 33f14e
    [AC_COMPILE_IFELSE(
Packit 33f14e
       [AC_LANG_PROGRAM(
Packit 33f14e
          [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
Packit 33f14e
               included before <wchar.h>.
Packit 33f14e
               BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
Packit 33f14e
               must be included before <wchar.h>.  */
Packit 33f14e
            #include <stddef.h>
Packit 33f14e
            #include <stdio.h>
Packit 33f14e
            #include <time.h>
Packit 33f14e
            #include <wchar.h>
Packit 33f14e
            #if HAVE_WCTYPE_H
Packit 33f14e
            # include <wctype.h>
Packit 33f14e
            #endif
Packit 33f14e
            wctype_t a;
Packit 33f14e
          ]],
Packit 33f14e
          [[]])],
Packit 33f14e
       [gl_cv_type_wctype_t=yes],
Packit 33f14e
       [gl_cv_type_wctype_t=no])
Packit 33f14e
    ])
Packit 33f14e
  if test $gl_cv_type_wctype_t = no; then
Packit 33f14e
    HAVE_WCTYPE_T=0
Packit 33f14e
  fi
Packit 33f14e
Packit 33f14e
  dnl We assume that the wctrans() and towctrans() functions exist if and only
Packit 33f14e
  dnl if the type wctrans_t is defined in <wctype.h>.
Packit 33f14e
  AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
Packit 33f14e
    [AC_COMPILE_IFELSE(
Packit 33f14e
       [AC_LANG_PROGRAM(
Packit 33f14e
          [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
Packit 33f14e
               included before <wchar.h>.
Packit 33f14e
               BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
Packit 33f14e
               must be included before <wchar.h>.  */
Packit 33f14e
            #include <stddef.h>
Packit 33f14e
            #include <stdio.h>
Packit 33f14e
            #include <time.h>
Packit 33f14e
            #include <wchar.h>
Packit 33f14e
            #include <wctype.h>
Packit 33f14e
            wctrans_t a;
Packit 33f14e
          ]],
Packit 33f14e
          [[]])],
Packit 33f14e
       [gl_cv_type_wctrans_t=yes],
Packit 33f14e
       [gl_cv_type_wctrans_t=no])
Packit 33f14e
    ])
Packit 33f14e
  if test $gl_cv_type_wctrans_t = no; then
Packit 33f14e
    HAVE_WCTRANS_T=0
Packit 33f14e
  fi
Packit 33f14e
Packit 33f14e
  dnl Check for declarations of anything we want to poison if the
Packit 33f14e
  dnl corresponding gnulib module is not in use.
Packit 33f14e
  gl_WARN_ON_USE_PREPARE([[
Packit 33f14e
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit 33f14e
   <wchar.h>.
Packit 33f14e
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
Packit 33f14e
   included before <wchar.h>.  */
Packit 33f14e
#if !(defined __GLIBC__ && !defined __UCLIBC__)
Packit 33f14e
# include <stddef.h>
Packit 33f14e
# include <stdio.h>
Packit 33f14e
# include <time.h>
Packit 33f14e
# include <wchar.h>
Packit 33f14e
#endif
Packit 33f14e
#include <wctype.h>
Packit 33f14e
    ]],
Packit 33f14e
    [wctype iswctype wctrans towctrans
Packit 33f14e
    ])
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
Packit 33f14e
[
Packit 33f14e
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
Packit 33f14e
  AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
Packit 33f14e
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
Packit 33f14e
  dnl Define it also as a C macro, for the benefit of the unit tests.
Packit 33f14e
  gl_MODULE_INDICATOR_FOR_TESTS([$1])
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
Packit 33f14e
[
Packit 33f14e
  GNULIB_ISWBLANK=0;    AC_SUBST([GNULIB_ISWBLANK])
Packit 33f14e
  GNULIB_WCTYPE=0;      AC_SUBST([GNULIB_WCTYPE])
Packit 33f14e
  GNULIB_ISWCTYPE=0;    AC_SUBST([GNULIB_ISWCTYPE])
Packit 33f14e
  GNULIB_WCTRANS=0;     AC_SUBST([GNULIB_WCTRANS])
Packit 33f14e
  GNULIB_TOWCTRANS=0;   AC_SUBST([GNULIB_TOWCTRANS])
Packit 33f14e
  dnl Assume proper GNU behavior unless another module says otherwise.
Packit 33f14e
  HAVE_ISWBLANK=1;      AC_SUBST([HAVE_ISWBLANK])
Packit 33f14e
  HAVE_WCTYPE_T=1;      AC_SUBST([HAVE_WCTYPE_T])
Packit 33f14e
  HAVE_WCTRANS_T=1;     AC_SUBST([HAVE_WCTRANS_T])
Packit 33f14e
  REPLACE_ISWBLANK=0;   AC_SUBST([REPLACE_ISWBLANK])
Packit 33f14e
])