From 9753b53d66393b9b0059ba04e0a6a9c0b326b1fb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 30 Aug 2023 02:18:06 +0200 Subject: [PATCH] iswpunct: New module. * lib/wctype.in.h (iswpunct): New declaration. * lib/iswpunct.c: New file. * m4/iswpunct.m4: New file. * m4/wctype_h.m4 (gl_WCTYPE_H_REQUIRE_DEFAULTS): Initialize GNULIB_ISWPUNCT. (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_ISWPUNCT. * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWPUNCT, REPLACE_ISWPUNCT. * modules/iswpunct: New file. * doc/posix-functions/iswpunct.texi: Mention the new module. --- ChangeLog | 12 ++++++++ doc/posix-functions/iswpunct.texi | 8 +++++- lib/iswpunct.c | 33 ++++++++++++++++++++++ lib/wctype.in.h | 12 +++++++- m4/iswpunct.m4 | 47 +++++++++++++++++++++++++++++++ m4/wctype_h.m4 | 4 ++- modules/iswpunct | 30 ++++++++++++++++++++ modules/wctype-h | 2 ++ 8 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 lib/iswpunct.c create mode 100644 m4/iswpunct.m4 create mode 100644 modules/iswpunct diff --git a/ChangeLog b/ChangeLog index 3824fd0ed4..abb5917a76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2023-08-29 Bruno Haible + iswpunct: New module. + * lib/wctype.in.h (iswpunct): New declaration. + * lib/iswpunct.c: New file. + * m4/iswpunct.m4: New file. + * m4/wctype_h.m4 (gl_WCTYPE_H_REQUIRE_DEFAULTS): Initialize + GNULIB_ISWPUNCT. + (gl_WCTYPE_H_DEFAULTS): Initialize REPLACE_ISWPUNCT. + * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWPUNCT, + REPLACE_ISWPUNCT. + * modules/iswpunct: New file. + * doc/posix-functions/iswpunct.texi: Mention the new module. + wctype-h tests: Add more tests. * tests/test-wctype-h.c (main): Add a sanity check of iswpunct. diff --git a/doc/posix-functions/iswpunct.texi b/doc/posix-functions/iswpunct.texi index bc0e65ac93..663f2cca61 100644 --- a/doc/posix-functions/iswpunct.texi +++ b/doc/posix-functions/iswpunct.texi @@ -4,7 +4,7 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/iswpunct.html} -Gnulib module: wctype-h +Gnulib module: iswpunct Portability problems fixed by Gnulib: @itemize @@ -15,6 +15,12 @@ Minix 3.1.8. This function cannot be called from plain inline or extern inline functions on some platforms: OS X 10.8. +@item +This function is inconsistent with the @code{ispunct} function, because it +returns false for the characters @code{'$'}, @code{'+'}, @code{'<'}, +@code{'='}, @code{'>'}, @code{'^'}, @code{'`'} , @code{'|'}, @code{'~'} +on some platforms: +Android 11. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/iswpunct.c b/lib/iswpunct.c new file mode 100644 index 0000000000..0d60cb71eb --- /dev/null +++ b/lib/iswpunct.c @@ -0,0 +1,33 @@ +/* Test wide character for being a punctuation or symbol character. + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include + +int +iswpunct (wint_t wc) +#undef iswpunct +{ +#if defined __ANDROID__ + if ((unsigned int) wc < 128) + return ispunct ((unsigned int) wc); +#endif + return iswpunct (wc); +} diff --git a/lib/wctype.in.h b/lib/wctype.in.h index fd52715a8a..6f1e7ef149 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -133,7 +133,7 @@ typedef unsigned int rpl_wint_t; Linux libc5 has and the functions but they are broken. mingw and MSVC have and the functions but they take a wchar_t as argument, not an rpl_wint_t. Additionally, the mingw iswprint function - is broken. + and the Android iswpunct function are broken. Assume all 11 functions (all isw* except iswblank) are implemented the same way, or not at all. */ # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@ @@ -494,6 +494,16 @@ _GL_FUNCDECL_RPL (iswdigit, int, (wint_t wc)); # endif # endif +# if @GNULIB_ISWPUNCT@ +# if @REPLACE_ISWPUNCT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef iswpunct +# define iswpunct rpl_iswpunct +# endif +_GL_FUNCDECL_RPL (iswpunct, int, (wint_t wc)); +# endif +# endif + # if @GNULIB_ISWXDIGIT@ # if @REPLACE_ISWXDIGIT@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/iswpunct.m4 b/m4/iswpunct.m4 new file mode 100644 index 0000000000..14691154cf --- /dev/null +++ b/m4/iswpunct.m4 @@ -0,0 +1,47 @@ +# iswpunct.m4 serial 1 +dnl Copyright (C) 2023 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_ISWPUNCT], +[ + AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) + AC_REQUIRE([gl_WCTYPE_H]) + + if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then + dnl redefines iswpunct already. + REPLACE_ISWPUNCT="$REPLACE_ISWCNTRL" + else + AC_CACHE_CHECK([whether iswpunct is consistent with ispunct], + [gl_cv_func_iswpunct_works], + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +int +main (int argc, char *argv[]) +{ + int result = 0; + /* This fails on Android 11. */ + if ((! iswpunct ('\`')) != (! ispunct ('\`'))) + result |= 1; + return result; +}]])], + [gl_cv_func_iswpunct_works=yes], + [gl_cv_func_iswpunct_works=no], + [case "$host_os" in + # Guess no on Android. + android*) gl_cv_func_iswpunct_works="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_iswpunct_works="guessing yes" ;; + esac + ]) + ]) + case "$gl_cv_func_iswpunct_works" in + *yes) ;; + *) REPLACE_ISWPUNCT=1 ;; + esac + fi +]) diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4 index 43a2d9cf10..ac9c35b2da 100644 --- a/m4/wctype_h.m4 +++ b/m4/wctype_h.m4 @@ -1,4 +1,4 @@ -# wctype_h.m4 serial 32 +# wctype_h.m4 serial 33 dnl A placeholder for ISO C99 , for platforms that lack it. @@ -178,6 +178,7 @@ AC_DEFUN([gl_WCTYPE_H_REQUIRE_DEFAULTS], m4_defun(GL_MODULE_INDICATOR_PREFIX[_WCTYPE_H_MODULE_INDICATOR_DEFAULTS], [ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWBLANK]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWDIGIT]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWPUNCT]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWXDIGIT]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTYPE]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISWCTYPE]) @@ -196,6 +197,7 @@ AC_DEFUN([gl_WCTYPE_H_DEFAULTS], HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T]) REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK]) REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT]) + REPLACE_ISWPUNCT=0; AC_SUBST([REPLACE_ISWPUNCT]) REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT]) REPLACE_WCTRANS=0; AC_SUBST([REPLACE_WCTRANS]) REPLACE_WCTYPE=0; AC_SUBST([REPLACE_WCTYPE]) diff --git a/modules/iswpunct b/modules/iswpunct new file mode 100644 index 0000000000..0abeb94e4e --- /dev/null +++ b/modules/iswpunct @@ -0,0 +1,30 @@ +Description: +iswpunct() function: test wide character for being a punctuation or symbol +character. + +Files: +lib/iswpunct.c +m4/iswpunct.m4 + +Depends-on: +wctype-h + +configure.ac: +gl_FUNC_ISWPUNCT +gl_CONDITIONAL([GL_COND_OBJ_ISWPUNCT], + [! { test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; } && test $REPLACE_ISWPUNCT = 1]) +gl_WCTYPE_MODULE_INDICATOR([iswpunct]) + +Makefile.am: +if GL_COND_OBJ_ISWPUNCT +lib_SOURCES += iswpunct.c +endif + +Include: + + +License: +LGPLv2+ + +Maintainer: +Bruno Haible diff --git a/modules/wctype-h b/modules/wctype-h index 99aba62d90..682ef51be0 100644 --- a/modules/wctype-h +++ b/modules/wctype-h @@ -39,6 +39,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \ -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \ -e 's/@''GNULIB_ISWDIGIT''@/$(GNULIB_ISWDIGIT)/g' \ + -e 's/@''GNULIB_ISWPUNCT''@/$(GNULIB_ISWPUNCT)/g' \ -e 's/@''GNULIB_ISWXDIGIT''@/$(GNULIB_ISWXDIGIT)/g' \ -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \ -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \ @@ -51,6 +52,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \ -e 's/@''REPLACE_ISWDIGIT''@/$(REPLACE_ISWDIGIT)/g' \ + -e 's/@''REPLACE_ISWPUNCT''@/$(REPLACE_ISWPUNCT)/g' \ -e 's/@''REPLACE_ISWXDIGIT''@/$(REPLACE_ISWXDIGIT)/g' \ -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \ -- 2.39.5