Debian Codegraph @

m4/iswxdigit.m4

raw
1 # iswxdigit.m4 serial 4
2 dnl Copyright (C) 2020-2023 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_ISWXDIGIT],
8 [
9 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
10 AC_REQUIRE([gl_WCTYPE_H])
11 AC_REQUIRE([gt_LOCALE_JA])
12 AC_REQUIRE([gt_LOCALE_FR_UTF8])
13 AC_REQUIRE([gt_LOCALE_ZH_CN])
14
15 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
16 dnl <wctype.h> redefines iswxdigit already.
17 REPLACE_ISWXDIGIT="$REPLACE_ISWCNTRL"
18 else
19 AC_CACHE_CHECK([whether iswxdigit is ISO C compliant],
20 [gl_cv_func_iswxdigit_works],
21 [
22 dnl Initial guess, used when cross-compiling or when no suitable locale
23 dnl is present.
24 changequote(,)dnl
25 case "$host_os" in
26 # Guess no on FreeBSD, NetBSD, Solaris, native Windows.
27 freebsd* | dragonfly* | netbsd* | solaris* | mingw*)
28 gl_cv_func_iswxdigit_works="guessing no" ;;
29 # Guess yes otherwise.
30 *) gl_cv_func_iswxdigit_works="guessing yes" ;;
31 esac
32 changequote([,])dnl
33 if test $LOCALE_JA != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_ZH_CN != none; then
34 AC_RUN_IFELSE(
35 [AC_LANG_SOURCE([[
36 #include <locale.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <wchar.h>
40 #include <wctype.h>
41
42 /* Returns the value of iswxdigit for the multibyte character s[0..n-1]. */
43 static int
44 for_character (const char *s, size_t n)
45 {
46 mbstate_t state;
47 wchar_t wc;
48 size_t ret;
49
50 memset (&state, '\0', sizeof (mbstate_t));
51 wc = (wchar_t) 0xBADFACE;
52 ret = mbrtowc (&wc, s, n, &state);
53 if (ret != n)
54 abort ();
55
56 return iswxdigit (wc);
57 }
58
59 int
60 main (int argc, char *argv[])
61 {
62 int is;
63 int result = 0;
64
65 if (strcmp ("$LOCALE_JA", "none") != 0
66 && setlocale (LC_ALL, "$LOCALE_JA") != NULL)
67 {
68 /* This fails on NetBSD 8.0. */
69 /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */
70 is = for_character ("\243\301", 2);
71 if (!(is == 0))
72 result |= 1;
73 }
74 if (strcmp ("$LOCALE_FR_UTF8", "none") != 0
75 && setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
76 {
77 /* This fails on FreeBSD 13.0. */
78 /* U+0663 ARABIC-INDIC DIGIT THREE */
79 is = for_character ("\331\243", 2);
80 if (!(is == 0))
81 result |= 2;
82 /* This fails on MSVC 14. */
83 /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */
84 is = for_character ("\357\274\241", 3);
85 if (!(is == 0))
86 result |= 4;
87 }
88 if (strcmp ("$LOCALE_ZH_CN", "none") != 0
89 && setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
90 {
91 /* This fails on Solaris 10, Solaris 11.4. */
92 /* U+FF11 FULLWIDTH DIGIT ONE */
93 is = for_character ("\243\261", 2);
94 if (!(is == 0))
95 result |= 8;
96 }
97 return result;
98 }]])],
99 [gl_cv_func_iswxdigit_works=yes],
100 [gl_cv_func_iswxdigit_works=no],
101 [:])
102 fi
103 ])
104 case "$gl_cv_func_iswxdigit_works" in
105 *yes) ;;
106 *) REPLACE_ISWXDIGIT=1 ;;
107 esac
108 fi
109 ])