Blame m4/wcwidth.m4

Packit 8f70b4
# wcwidth.m4 serial 27
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
AC_DEFUN([gl_FUNC_WCWIDTH],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
Packit 8f70b4
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 8f70b4
Packit 8f70b4
  dnl Persuade glibc <wchar.h> to declare wcwidth().
Packit 8f70b4
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
Packit 8f70b4
Packit 8f70b4
  AC_REQUIRE([gt_TYPE_WCHAR_T])
Packit 8f70b4
  AC_REQUIRE([gt_TYPE_WINT_T])
Packit 8f70b4
Packit 8f70b4
  AC_CHECK_HEADERS_ONCE([wchar.h])
Packit 8f70b4
  AC_CHECK_FUNCS_ONCE([wcwidth])
Packit 8f70b4
Packit 8f70b4
  AC_CHECK_DECLS([wcwidth], [], [], [[
Packit 8f70b4
/* AIX 3.2.5 declares wcwidth in <string.h>. */
Packit 8f70b4
#include <string.h>
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 included
Packit 8f70b4
   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
]])
Packit 8f70b4
  if test $ac_cv_have_decl_wcwidth != yes; then
Packit 8f70b4
    HAVE_DECL_WCWIDTH=0
Packit 8f70b4
  fi
Packit 8f70b4
Packit 8f70b4
  if test $ac_cv_func_wcwidth != yes; then
Packit 8f70b4
    AC_CACHE_CHECK([whether wcwidth is a macro],
Packit 8f70b4
      [gl_cv_func_wcwidth_macro],
Packit 8f70b4
      [AC_EGREP_CPP([wchar_header_defines_wcwidth], [
Packit 8f70b4
#include <wchar.h>
Packit 8f70b4
#ifdef wcwidth
Packit 8f70b4
 wchar_header_defines_wcwidth
Packit 8f70b4
#endif],
Packit 8f70b4
         [gl_cv_func_wcwidth_macro=yes],
Packit 8f70b4
         [gl_cv_func_wcwidth_macro=no])
Packit 8f70b4
      ])
Packit 8f70b4
  fi
Packit 8f70b4
Packit 8f70b4
  if test $ac_cv_func_wcwidth = yes || test $gl_cv_func_wcwidth_macro = yes; then
Packit 8f70b4
    HAVE_WCWIDTH=1
Packit 8f70b4
    dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
Packit 8f70b4
    dnl On OpenBSD 5.0, wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
Packit 8f70b4
    dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
Packit 8f70b4
    dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
Packit 8f70b4
    dnl On Solaris 8, wcwidth(0x2022) (BULLET) returns 2.
Packit 8f70b4
    dnl This leads to bugs in 'ls' (coreutils).
Packit 8f70b4
    AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
Packit 8f70b4
      [gl_cv_func_wcwidth_works],
Packit 8f70b4
      [
Packit 8f70b4
        AC_RUN_IFELSE(
Packit 8f70b4
          [AC_LANG_SOURCE([[
Packit 8f70b4
#include <locale.h>
Packit 8f70b4
/* AIX 3.2.5 declares wcwidth in <string.h>. */
Packit 8f70b4
#include <string.h>
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 included
Packit 8f70b4
   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_DECL_WCWIDTH
Packit 8f70b4
extern
Packit 8f70b4
# ifdef __cplusplus
Packit 8f70b4
"C"
Packit 8f70b4
# endif
Packit 8f70b4
int wcwidth (int);
Packit 8f70b4
#endif
Packit 8f70b4
int main ()
Packit 8f70b4
{
Packit 8f70b4
  int result = 0;
Packit 8f70b4
  if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL
Packit 8f70b4
   || setlocale (LC_ALL, "en_US.UTF-8") != NULL)
Packit 8f70b4
    {
Packit 8f70b4
      if (wcwidth (0x0301) > 0)
Packit 8f70b4
        result |= 1;
Packit 8f70b4
      if (wcwidth (0x05B0) > 0)
Packit 8f70b4
        result |= 2;
Packit 8f70b4
      if (wcwidth (0x200B) > 0)
Packit 8f70b4
        result |= 4;
Packit 8f70b4
      if (wcwidth (0xFF1A) == 0)
Packit 8f70b4
        result |= 8;
Packit 8f70b4
      if (wcwidth (0x2022) != 1)
Packit 8f70b4
	result |= 16;
Packit 8f70b4
    }
Packit 8f70b4
  return result;
Packit 8f70b4
}]])],
Packit 8f70b4
          [gl_cv_func_wcwidth_works=yes],
Packit 8f70b4
          [gl_cv_func_wcwidth_works=no],
Packit 8f70b4
          [
Packit 8f70b4
changequote(,)dnl
Packit 8f70b4
           case "$host_os" in
Packit 8f70b4
                                        # Guess yes on glibc and AIX 7 systems.
Packit 8f70b4
             *-gnu* | gnu* | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
Packit 8f70b4
             *)                         gl_cv_func_wcwidth_works="guessing no";;
Packit 8f70b4
           esac
Packit 8f70b4
changequote([,])dnl
Packit 8f70b4
          ])
Packit 8f70b4
      ])
Packit 8f70b4
    case "$gl_cv_func_wcwidth_works" in
Packit 8f70b4
      *yes) ;;
Packit 8f70b4
      *no) REPLACE_WCWIDTH=1 ;;
Packit 8f70b4
    esac
Packit 8f70b4
  else
Packit 8f70b4
    HAVE_WCWIDTH=0
Packit 8f70b4
  fi
Packit 8f70b4
  dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
Packit 8f70b4
  dnl have the wcwidth function, then it does not declare it.
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Prerequisites of lib/wcwidth.c.
Packit 8f70b4
AC_DEFUN([gl_PREREQ_WCWIDTH], [
Packit 8f70b4
  AC_REQUIRE([AC_C_INLINE])
Packit 8f70b4
  :
Packit 8f70b4
])