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