| 1 | # iswdigit.m4 serial 3
|
|---|
| 2 | dnl Copyright (C) 2020-2021 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 (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
|
|---|
| 67 | {
|
|---|
| 68 | /* This fails on mingw, MSVC 14. */
|
|---|
| 69 | /* U+00B2 SUPERSCRIPT TWO */
|
|---|
| 70 | is = for_character ("\262", 1);
|
|---|
| 71 | if (!(is == 0))
|
|---|
| 72 | result |= 1;
|
|---|
| 73 | }
|
|---|
| 74 | if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
|
|---|
| 75 | {
|
|---|
| 76 | /* This fails on NetBSD 8.0. */
|
|---|
| 77 | /* U+FF11 FULLWIDTH DIGIT ONE */
|
|---|
| 78 | is = for_character ("\243\261", 2);
|
|---|
| 79 | if (!(is == 0))
|
|---|
| 80 | result |= 2;
|
|---|
| 81 | }
|
|---|
| 82 | if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
|
|---|
| 83 | {
|
|---|
| 84 | /* This fails on FreeBSD 13.0, NetBSD 8.0, MSVC 14. */
|
|---|
| 85 | /* U+0663 ARABIC-INDIC DIGIT THREE */
|
|---|
| 86 | is = for_character ("\331\243", 2);
|
|---|
| 87 | if (!(is == 0))
|
|---|
| 88 | result |= 4;
|
|---|
| 89 | /* This fails on FreeBSD 13.0, NetBSD 8.0, MSVC 14. */
|
|---|
| 90 | /* U+FF11 FULLWIDTH DIGIT ONE */
|
|---|
| 91 | is = for_character ("\357\274\221", 3);
|
|---|
| 92 | if (!(is == 0))
|
|---|
| 93 | result |= 8;
|
|---|
| 94 | }
|
|---|
| 95 | if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
|
|---|
| 96 | {
|
|---|
| 97 | /* This fails on NetBSD 8.0, Solaris 10, Solaris 11.4. */
|
|---|
| 98 | /* U+FF11 FULLWIDTH DIGIT ONE */
|
|---|
| 99 | is = for_character ("\243\261", 2);
|
|---|
| 100 | if (!(is == 0))
|
|---|
| 101 | result |= 16;
|
|---|
| 102 | }
|
|---|
| 103 | return result;
|
|---|
| 104 | }]])],
|
|---|
| 105 | [gl_cv_func_iswdigit_works=yes],
|
|---|
| 106 | [gl_cv_func_iswdigit_works=no],
|
|---|
| 107 | [:])
|
|---|
| 108 | fi
|
|---|
| 109 | ])
|
|---|
| 110 | case "$gl_cv_func_iswdigit_works" in
|
|---|
| 111 | *yes) ;;
|
|---|
| 112 | *) REPLACE_ISWDIGIT=1 ;;
|
|---|
| 113 | esac
|
|---|
| 114 | fi
|
|---|
| 115 | ])
|
|---|