summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-01-25 16:03:15 +0100
committerBruno Haible <bruno@clisp.org>2020-01-25 16:03:15 +0100
commit36a9ca3f924853f22af5ac5228c35ca81bddf6cf (patch)
tree757cb72c12b5682239eeda6b28dbdf652781a80e /m4
parent55cf4e2076fe42abbc111e750fbfc56302dae373 (diff)
downloadgnulib-36a9ca3f924853f22af5ac5228c35ca81bddf6cf.tar.gz
iswdigit: New module.
* m4/iswdigit.m4: New file. * lib/wctype.in.h (iswdigit): Potentially override. (iswdigit, rpl_iswdigit): Test REPLACE_ISWDIGIT, not REPLACE_ISWCNTRL. * lib/iswdigit.c: New file. * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize GNULIB_ISWDIGIT, REPLACE_ISWDIGIT. * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWDIGIT, REPLACE_ISWDIGIT. * modules/iswdigit: New file. * doc/posix-functions/iswdigit.texi: Mention the portability problem.
Diffstat (limited to 'm4')
-rw-r--r--m4/iswdigit.m4122
-rw-r--r--m4/wctype_h.m44
2 files changed, 125 insertions, 1 deletions
diff --git a/m4/iswdigit.m4 b/m4/iswdigit.m4
new file mode 100644
index 0000000000..5f15c39fb9
--- /dev/null
+++ b/m4/iswdigit.m4
@@ -0,0 +1,122 @@
+# iswdigit.m4 serial 1
+dnl Copyright (C) 2020 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_ISWDIGIT],
+[
+ AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
+ AC_REQUIRE([gl_WCTYPE_H])
+ AC_REQUIRE([gt_LOCALE_FR])
+ AC_REQUIRE([gt_LOCALE_JA])
+ AC_REQUIRE([gt_LOCALE_FR_UTF8])
+ AC_REQUIRE([gt_LOCALE_ZH_CN])
+
+ if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
+ dnl <wctype.h> redefines iswdigit already.
+ REPLACE_ISWDIGIT="$REPLACE_ISWCNTRL"
+ else
+ AC_CACHE_CHECK([whether iswdigit is ISO C compliant],
+ [gl_cv_func_iswdigit_works],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on FreeBSD, NetBSD, Solaris, native Windows.
+ freebsd* | dragonfly* | netbsd* | solaris* | mingw*)
+ gl_cv_func_iswdigit_works="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_iswdigit_works="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR != none || test $LOCALE_JA != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_ZH_CN != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+#include <wctype.h>
+
+/* Returns the value of iswdigit for the multibyte character s[0..n-1]. */
+static int
+for_character (const char *s, size_t n)
+{
+ mbstate_t state;
+ wchar_t wc;
+ size_t ret;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ wc = (wchar_t) 0xBADFACE;
+ ret = mbrtowc (&wc, s, n, &state);
+ if (ret != n)
+ abort ();
+
+ return iswdigit (wc);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int is;
+ int result = 0;
+
+ if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
+ {
+ /* This fails on mingw, MSVC 14. */
+ /* U+00B2 SUPERSCRIPT TWO */
+ is = for_character ("\262", 1);
+ if (!(is == 0))
+ result |= 1;
+ }
+ if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+ {
+ /* This fails on NetBSD 8.0. */
+ /* U+FF11 FULLWIDTH DIGIT ONE */
+ is = for_character ("\243\261", 2);
+ if (!(is == 0))
+ result |= 2;
+ }
+ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+ {
+ /* This fails on FreeBSD 12, NetBSD 8.0, MSVC 14. */
+ /* U+0663 ARABIC-INDIC DIGIT THREE */
+ is = for_character ("\331\243", 2);
+ if (!(is == 0))
+ result |= 4;
+ /* This fails on FreeBSD 12, NetBSD 8.0, MSVC 14. */
+ /* U+FF11 FULLWIDTH DIGIT ONE */
+ is = for_character ("\357\274\221", 3);
+ if (!(is == 0))
+ result |= 8;
+ }
+ if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+ {
+ /* This fails on NetBSD 8.0, Solaris 10, Solaris 11.4. */
+ /* U+FF11 FULLWIDTH DIGIT ONE */
+ is = for_character ("\243\261", 2);
+ if (!(is == 0))
+ result |= 16;
+ }
+ return result;
+}]])],
+ [gl_cv_func_iswdigit_works=yes],
+ [gl_cv_func_iswdigit_works=no],
+ [:])
+ fi
+ ])
+ case "$gl_cv_func_iswdigit_works" in
+ *yes) ;;
+ *) REPLACE_ISWDIGIT=1 ;;
+ esac
+ fi
+])
diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4
index dc854e6eac..24bad382ab 100644
--- a/m4/wctype_h.m4
+++ b/m4/wctype_h.m4
@@ -1,4 +1,4 @@
-# wctype_h.m4 serial 22
+# wctype_h.m4 serial 23
dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
@@ -204,6 +204,7 @@ AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
[
GNULIB_ISWBLANK=0; AC_SUBST([GNULIB_ISWBLANK])
+ GNULIB_ISWDIGIT=0; AC_SUBST([GNULIB_ISWDIGIT])
GNULIB_WCTYPE=0; AC_SUBST([GNULIB_WCTYPE])
GNULIB_ISWCTYPE=0; AC_SUBST([GNULIB_ISWCTYPE])
GNULIB_WCTRANS=0; AC_SUBST([GNULIB_WCTRANS])
@@ -213,4 +214,5 @@ AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T])
HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T])
REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK])
+ REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT])
])