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