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