Blame m4/wcwidth.m4

Packit 709fb3
# wcwidth.m4 serial 23
Packit 709fb3
dnl Copyright (C) 2006-2017 Free Software Foundation, Inc.
Packit 709fb3
dnl This file is free software; the Free Software Foundation
Packit 709fb3
dnl gives unlimited permission to copy and/or distribute it,
Packit 709fb3
dnl with or without modifications, as long as this notice is preserved.
Packit 709fb3
Packit 709fb3
AC_DEFUN([gl_FUNC_WCWIDTH],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit 709fb3
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 709fb3
Packit 709fb3
  dnl Persuade glibc <wchar.h> to declare wcwidth().
Packit 709fb3
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
Packit 709fb3
Packit 709fb3
  AC_REQUIRE([gt_TYPE_WCHAR_T])
Packit 709fb3
  AC_REQUIRE([gt_TYPE_WINT_T])
Packit 709fb3
Packit 709fb3
  AC_CHECK_HEADERS_ONCE([wchar.h])
Packit 709fb3
  AC_CHECK_FUNCS_ONCE([wcwidth])
Packit 709fb3
Packit 709fb3
  AC_CHECK_DECLS([wcwidth], [], [], [[
Packit 709fb3
/* AIX 3.2.5 declares wcwidth in <string.h>. */
Packit 709fb3
#include <string.h>
Packit 709fb3
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit 709fb3
   <wchar.h>.
Packit 709fb3
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
Packit 709fb3
   before <wchar.h>.  */
Packit 709fb3
#include <stddef.h>
Packit 709fb3
#include <stdio.h>
Packit 709fb3
#include <time.h>
Packit 709fb3
#include <wchar.h>
Packit 709fb3
]])
Packit 709fb3
  if test $ac_cv_have_decl_wcwidth != yes; then
Packit 709fb3
    HAVE_DECL_WCWIDTH=0
Packit 709fb3
  fi
Packit 709fb3
Packit 709fb3
  if test $ac_cv_func_wcwidth = yes; then
Packit 709fb3
    HAVE_WCWIDTH=1
Packit 709fb3
    dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
Packit 709fb3
    dnl On OpenBSD 5.0, wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
Packit 709fb3
    dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
Packit 709fb3
    dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
Packit 709fb3
    dnl This leads to bugs in 'ls' (coreutils).
Packit 709fb3
    AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
Packit 709fb3
      [gl_cv_func_wcwidth_works],
Packit 709fb3
      [
Packit 709fb3
        AC_RUN_IFELSE(
Packit 709fb3
          [AC_LANG_SOURCE([[
Packit 709fb3
#include <locale.h>
Packit 709fb3
/* AIX 3.2.5 declares wcwidth in <string.h>. */
Packit 709fb3
#include <string.h>
Packit 709fb3
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
Packit 709fb3
   <wchar.h>.
Packit 709fb3
   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
Packit 709fb3
   before <wchar.h>.  */
Packit 709fb3
#include <stddef.h>
Packit 709fb3
#include <stdio.h>
Packit 709fb3
#include <time.h>
Packit 709fb3
#include <wchar.h>
Packit 709fb3
#if !HAVE_DECL_WCWIDTH
Packit 709fb3
extern
Packit 709fb3
# ifdef __cplusplus
Packit 709fb3
"C"
Packit 709fb3
# endif
Packit 709fb3
int wcwidth (int);
Packit 709fb3
#endif
Packit 709fb3
int main ()
Packit 709fb3
{
Packit 709fb3
  int result = 0;
Packit 709fb3
  if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL)
Packit 709fb3
    {
Packit 709fb3
      if (wcwidth (0x0301) > 0)
Packit 709fb3
        result |= 1;
Packit 709fb3
      if (wcwidth (0x05B0) > 0)
Packit 709fb3
        result |= 2;
Packit 709fb3
      if (wcwidth (0x200B) > 0)
Packit 709fb3
        result |= 4;
Packit 709fb3
      if (wcwidth (0xFF1A) == 0)
Packit 709fb3
        result |= 8;
Packit 709fb3
    }
Packit 709fb3
  return result;
Packit 709fb3
}]])],
Packit 709fb3
          [gl_cv_func_wcwidth_works=yes],
Packit 709fb3
          [gl_cv_func_wcwidth_works=no],
Packit 709fb3
          [
Packit 709fb3
changequote(,)dnl
Packit 709fb3
           case "$host_os" in
Packit 709fb3
                     # Guess yes on glibc and AIX 7 systems.
Packit 709fb3
             *-gnu* | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
Packit 709fb3
             *)                  gl_cv_func_wcwidth_works="guessing no";;
Packit 709fb3
           esac
Packit 709fb3
changequote([,])dnl
Packit 709fb3
          ])
Packit 709fb3
      ])
Packit 709fb3
    case "$gl_cv_func_wcwidth_works" in
Packit 709fb3
      *yes) ;;
Packit 709fb3
      *no) REPLACE_WCWIDTH=1 ;;
Packit 709fb3
    esac
Packit 709fb3
  else
Packit 709fb3
    HAVE_WCWIDTH=0
Packit 709fb3
  fi
Packit 709fb3
  dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
Packit 709fb3
  dnl have the wcwidth function, then it does not declare it.
Packit 709fb3
])