1 | # wcwidth.m4 serial 34
|
---|
2 | dnl Copyright (C) 2006-2021 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 | #include <wchar.h>
|
---|
23 | ]])
|
---|
24 | if test $ac_cv_have_decl_wcwidth != yes; then
|
---|
25 | HAVE_DECL_WCWIDTH=0
|
---|
26 | fi
|
---|
27 |
|
---|
28 | if test $ac_cv_func_wcwidth != yes; then
|
---|
29 | AC_CACHE_CHECK([whether wcwidth is a macro],
|
---|
30 | [gl_cv_func_wcwidth_macro],
|
---|
31 | [AC_EGREP_CPP([wchar_header_defines_wcwidth], [
|
---|
32 | #include <wchar.h>
|
---|
33 | #ifdef wcwidth
|
---|
34 | wchar_header_defines_wcwidth
|
---|
35 | #endif],
|
---|
36 | [gl_cv_func_wcwidth_macro=yes],
|
---|
37 | [gl_cv_func_wcwidth_macro=no])
|
---|
38 | ])
|
---|
39 | fi
|
---|
40 |
|
---|
41 | if test $ac_cv_func_wcwidth = yes || test $gl_cv_func_wcwidth_macro = yes; then
|
---|
42 | HAVE_WCWIDTH=1
|
---|
43 | dnl On Mac OS X 10.3, wcwidth(0x0301) (COMBINING ACUTE ACCENT) returns 1.
|
---|
44 | dnl On NetBSD 9.0, OpenBSD 5.0, MidnightBSD 1.1,
|
---|
45 | dnl wcwidth(0x05B0) (HEBREW POINT SHEVA) returns 1.
|
---|
46 | dnl On NetBSD 9.0, MidnightBSD 1.1, OSF/1 5.1,
|
---|
47 | dnl wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
|
---|
48 | dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
|
---|
49 | dnl This leads to bugs in 'ls' (coreutils).
|
---|
50 | dnl On Solaris 11.4, wcwidth(0x2202) (PARTIAL DIFFERENTIAL) returns 2,
|
---|
51 | dnl even in Western locales.
|
---|
52 | AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
|
---|
53 | [gl_cv_func_wcwidth_works],
|
---|
54 | [
|
---|
55 | AC_RUN_IFELSE(
|
---|
56 | [AC_LANG_SOURCE([[
|
---|
57 | #include <locale.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, "en_US.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 | if (wcwidth (0xFF1A) == 0)
|
---|
78 | result |= 8;
|
---|
79 | if (wcwidth (0x2202) > 1)
|
---|
80 | result |= 16;
|
---|
81 | }
|
---|
82 | return result;
|
---|
83 | }]])],
|
---|
84 | [gl_cv_func_wcwidth_works=yes],
|
---|
85 | [gl_cv_func_wcwidth_works=no],
|
---|
86 | [
|
---|
87 | changequote(,)dnl
|
---|
88 | case "$host_os" in
|
---|
89 | # Guess yes on glibc systems.
|
---|
90 | *-gnu* | gnu*) gl_cv_func_wcwidth_works="guessing yes";;
|
---|
91 | # Guess yes on musl systems.
|
---|
92 | *-musl*) gl_cv_func_wcwidth_works="guessing yes";;
|
---|
93 | # Guess yes on AIX 7 systems.
|
---|
94 | aix[7-9]*) gl_cv_func_wcwidth_works="guessing yes";;
|
---|
95 | *) gl_cv_func_wcwidth_works="$gl_cross_guess_normal";;
|
---|
96 | esac
|
---|
97 | changequote([,])dnl
|
---|
98 | ])
|
---|
99 | ])
|
---|
100 | case "$gl_cv_func_wcwidth_works" in
|
---|
101 | *yes) ;;
|
---|
102 | *no) REPLACE_WCWIDTH=1 ;;
|
---|
103 | esac
|
---|
104 | else
|
---|
105 | HAVE_WCWIDTH=0
|
---|
106 | fi
|
---|
107 | dnl We don't substitute HAVE_WCWIDTH. We assume that if the system does not
|
---|
108 | dnl have the wcwidth function, then it does not declare it.
|
---|
109 | ])
|
---|
110 |
|
---|
111 | # Prerequisites of lib/wcwidth.c.
|
---|
112 | AC_DEFUN([gl_PREREQ_WCWIDTH], [
|
---|
113 | AC_REQUIRE([AC_C_INLINE])
|
---|
114 | :
|
---|
115 | ])
|
---|