wcwidth.m4 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # wcwidth.m4 serial 23
  2. dnl Copyright (C) 2006-2013 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_FUNC_WCWIDTH],
  7. [
  8. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  9. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  10. dnl Persuade glibc <wchar.h> to declare wcwidth().
  11. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  12. AC_REQUIRE([gt_TYPE_WCHAR_T])
  13. AC_REQUIRE([gt_TYPE_WINT_T])
  14. AC_CHECK_HEADERS_ONCE([wchar.h])
  15. AC_CHECK_FUNCS_ONCE([wcwidth])
  16. AC_CHECK_DECLS([wcwidth], [], [], [[
  17. /* AIX 3.2.5 declares wcwidth in <string.h>. */
  18. #include <string.h>
  19. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  20. <wchar.h>.
  21. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
  22. before <wchar.h>. */
  23. #include <stddef.h>
  24. #include <stdio.h>
  25. #include <time.h>
  26. #include <wchar.h>
  27. ]])
  28. if test $ac_cv_have_decl_wcwidth != yes; then
  29. HAVE_DECL_WCWIDTH=0
  30. fi
  31. if test $ac_cv_func_wcwidth = yes; then
  32. HAVE_WCWIDTH=1
  33. dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
  34. dnl On OpenBSD 5.0, wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
  35. dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
  36. dnl This leads to bugs in 'ls' (coreutils).
  37. AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
  38. [gl_cv_func_wcwidth_works],
  39. [
  40. AC_RUN_IFELSE(
  41. [AC_LANG_SOURCE([[
  42. #include <locale.h>
  43. /* AIX 3.2.5 declares wcwidth in <string.h>. */
  44. #include <string.h>
  45. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  46. <wchar.h>.
  47. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
  48. before <wchar.h>. */
  49. #include <stddef.h>
  50. #include <stdio.h>
  51. #include <time.h>
  52. #include <wchar.h>
  53. #if !HAVE_DECL_WCWIDTH
  54. extern
  55. # ifdef __cplusplus
  56. "C"
  57. # endif
  58. int wcwidth (int);
  59. #endif
  60. int main ()
  61. {
  62. int result = 0;
  63. if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL)
  64. {
  65. if (wcwidth (0x0301) > 0)
  66. result |= 1;
  67. if (wcwidth (0x05B0) > 0)
  68. result |= 2;
  69. if (wcwidth (0x200B) > 0)
  70. result |= 4;
  71. }
  72. return result;
  73. }]])],
  74. [gl_cv_func_wcwidth_works=yes],
  75. [gl_cv_func_wcwidth_works=no],
  76. [
  77. changequote(,)dnl
  78. case "$host_os" in
  79. # Guess yes on glibc and AIX 7 systems.
  80. *-gnu* | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
  81. *) gl_cv_func_wcwidth_works="guessing no";;
  82. esac
  83. changequote([,])dnl
  84. ])
  85. ])
  86. case "$gl_cv_func_wcwidth_works" in
  87. *yes) ;;
  88. *no) REPLACE_WCWIDTH=1 ;;
  89. esac
  90. else
  91. HAVE_WCWIDTH=0
  92. fi
  93. dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
  94. dnl have the wcwidth function, then it does not declare it.
  95. ])