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