Debian Codegraph @

m4/iswdigit.m4

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