Avoid "warning: The macro `AC_HELP_STRING' is obsolete".
[gnulib.git] / m4 / iswxdigit.m4
blob82190137f128938b849e4a11fa7d8e798a5cb754
1 # iswxdigit.m4 serial 1
2 dnl Copyright (C) 2020 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.
7 AC_DEFUN([gl_FUNC_ISWXDIGIT],
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])
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 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
40    <wchar.h>.
41    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
42    included before <wchar.h>.  */
43 #include <stddef.h>
44 #include <stdio.h>
45 #include <time.h>
46 #include <wchar.h>
47 #include <wctype.h>
49 /* Returns the value of iswxdigit for the multibyte character s[0..n-1].  */
50 static int
51 for_character (const char *s, size_t n)
53   mbstate_t state;
54   wchar_t wc;
55   size_t ret;
57   memset (&state, '\0', sizeof (mbstate_t));
58   wc = (wchar_t) 0xBADFACE;
59   ret = mbrtowc (&wc, s, n, &state);
60   if (ret != n)
61     abort ();
63   return iswxdigit (wc);
66 int
67 main (int argc, char *argv[])
69   int is;
70   int result = 0;
72   if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
73     {
74       /* This fails on NetBSD 8.0.  */
75       /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */
76       is = for_character ("\243\301", 2);
77       if (!(is == 0))
78         result |= 1;
79     }
80   if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
81     {
82       /* This fails on FreeBSD 12.  */
83       /* U+0663 ARABIC-INDIC DIGIT THREE */
84       is = for_character ("\331\243", 2);
85       if (!(is == 0))
86         result |= 2;
87       /* This fails on MSVC 14.  */
88       /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */
89       is = for_character ("\357\274\241", 3);
90       if (!(is == 0))
91         result |= 4;
92     }
93   if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
94     {
95       /* This fails on Solaris 10, Solaris 11.4.  */
96       /* U+FF11 FULLWIDTH DIGIT ONE */
97       is = for_character ("\243\261", 2);
98       if (!(is == 0))
99         result |= 8;
100     }
101   return result;
102 }]])],
103            [gl_cv_func_iswxdigit_works=yes],
104            [gl_cv_func_iswxdigit_works=no],
105            [:])
106        fi
107       ])
108     case "$gl_cv_func_iswxdigit_works" in
109       *yes) ;;
110       *) REPLACE_ISWXDIGIT=1 ;;
111     esac
112   fi