Blame m4/wcwidth.m4

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