Blame m4/wctype_h.m4

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