wcwidth.m4 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # wcwidth.m4 serial 23
  2. dnl Copyright (C) 2006-2017 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 On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
  37. dnl This leads to bugs in 'ls' (coreutils).
  38. AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
  39. [gl_cv_func_wcwidth_works],
  40. [
  41. AC_RUN_IFELSE(
  42. [AC_LANG_SOURCE([[
  43. #include <locale.h>
  44. /* AIX 3.2.5 declares wcwidth in <string.h>. */
  45. #include <string.h>
  46. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  47. <wchar.h>.
  48. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
  49. before <wchar.h>. */
  50. #include <stddef.h>
  51. #include <stdio.h>
  52. #include <time.h>
  53. #include <wchar.h>
  54. #if !HAVE_DECL_WCWIDTH
  55. extern
  56. # ifdef __cplusplus
  57. "C"
  58. # endif
  59. int wcwidth (int);
  60. #endif
  61. int main ()
  62. {
  63. int result = 0;
  64. if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL)
  65. {
  66. if (wcwidth (0x0301) > 0)
  67. result |= 1;
  68. if (wcwidth (0x05B0) > 0)
  69. result |= 2;
  70. if (wcwidth (0x200B) > 0)
  71. result |= 4;
  72. if (wcwidth (0xFF1A) == 0)
  73. result |= 8;
  74. }
  75. return result;
  76. }]])],
  77. [gl_cv_func_wcwidth_works=yes],
  78. [gl_cv_func_wcwidth_works=no],
  79. [
  80. changequote(,)dnl
  81. case "$host_os" in
  82. # Guess yes on glibc and AIX 7 systems.
  83. *-gnu* | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
  84. *) gl_cv_func_wcwidth_works="guessing no";;
  85. esac
  86. changequote([,])dnl
  87. ])
  88. ])
  89. case "$gl_cv_func_wcwidth_works" in
  90. *yes) ;;
  91. *no) REPLACE_WCWIDTH=1 ;;
  92. esac
  93. else
  94. HAVE_WCWIDTH=0
  95. fi
  96. dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
  97. dnl have the wcwidth function, then it does not declare it.
  98. ])