From 896cde703cb740a97353474e0156b46119b69640 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 Feb 2011 23:45:40 +0100 Subject: [PATCH] New module 'wctype'. * modules/wctype: Change to represent the wctype() substitute. * lib/wctype.in.h (wctype): New declaration. * lib/wctype.c: New file. * lib/wctype-impl.h: New file. * m4/wctype.m4: New file. * m4/wctype_h.m4 (gl_WCTYPE_H): Test whether wctype is declared. (gl_WCTYPE_H_DEFAULTS): Initialize GNULIB_WCTYPE. * modules/wctype-h (Makefile.am): Substitute GNULIB_WCTYPE. * tests/test-wctype-h-c++.cc: Test the declaration of wctype. * doc/posix-functions/wctype.texi: Mention the new module and the HP-UX 11.00 problem. --- ChangeLog | 15 ++++++ doc/posix-functions/wctype.texi | 12 +++-- lib/wctype-impl.h | 96 +++++++++++++++++++++++++++++++++ lib/wctype.c | 25 +++++++++ lib/wctype.in.h | 15 ++++++ m4/wctype.m4 | 14 +++++ m4/wctype_h.m4 | 19 +++++++ modules/wctype | 14 ++++- modules/wctype-h | 1 + tests/test-wctype-h-c++.cc | 4 ++ 10 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 lib/wctype-impl.h create mode 100644 lib/wctype.c create mode 100644 m4/wctype.m4 diff --git a/ChangeLog b/ChangeLog index fec236bd45..daf65354eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-02-06 Bruno Haible + + New module 'wctype'. + * modules/wctype: Change to represent the wctype() substitute. + * lib/wctype.in.h (wctype): New declaration. + * lib/wctype.c: New file. + * lib/wctype-impl.h: New file. + * m4/wctype.m4: New file. + * m4/wctype_h.m4 (gl_WCTYPE_H): Test whether wctype is declared. + (gl_WCTYPE_H_DEFAULTS): Initialize GNULIB_WCTYPE. + * modules/wctype-h (Makefile.am): Substitute GNULIB_WCTYPE. + * tests/test-wctype-h-c++.cc: Test the declaration of wctype. + * doc/posix-functions/wctype.texi: Mention the new module and the + HP-UX 11.00 problem. + 2011-02-06 Bruno Haible wctype-h: Ensure wctype_t and wctrans_t are defined. diff --git a/doc/posix-functions/wctype.texi b/doc/posix-functions/wctype.texi index 570b0e466c..bb52beda66 100644 --- a/doc/posix-functions/wctype.texi +++ b/doc/posix-functions/wctype.texi @@ -4,18 +4,22 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wctype.html} -Gnulib module: --- +Gnulib module: wctype Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +IRIX 5.3, Solaris 2.5.1. +@item +This function is declared in @code{}, not in @code{}, on +some platforms: +HP-UX 11.00. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -IRIX 5.3, Solaris 2.5.1, mingw. -@item On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot accommodate all Unicode characters. @end itemize diff --git a/lib/wctype-impl.h b/lib/wctype-impl.h new file mode 100644 index 0000000000..e2c3222304 --- /dev/null +++ b/lib/wctype-impl.h @@ -0,0 +1,96 @@ +/* Get descriptor for a wide character property. + Copyright (C) 2011 Free Software Foundation, Inc. + Written by Bruno Haible , 2011. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +wctype_t +wctype (const char* name) +{ + switch (name[0]) + { + case 'a': + switch (name[1]) + { + case 'l': + switch (name[2]) + { + case 'n': + if (strcmp (name + 3, "um") == 0) + return (wctype_t) iswalnum; + break; + case 'p': + if (strcmp (name + 3, "ha") == 0) + return (wctype_t) iswalpha; + break; + default: + break; + } + break; + default: + break; + } + break; + case 'b': + if (strcmp (name + 1, "lank") == 0) + return (wctype_t) iswblank; + break; + case 'c': + if (strcmp (name + 1, "ntrl") == 0) + return (wctype_t) iswcntrl; + break; + case 'd': + if (strcmp (name + 1, "igit") == 0) + return (wctype_t) iswdigit; + break; + case 'g': + if (strcmp (name + 1, "raph") == 0) + return (wctype_t) iswgraph; + break; + case 'l': + if (strcmp (name + 1, "ower") == 0) + return (wctype_t) iswlower; + break; + case 'p': + switch (name[1]) + { + case 'r': + if (strcmp (name + 2, "int") == 0) + return (wctype_t) iswprint; + break; + case 'u': + if (strcmp (name + 2, "nct") == 0) + return (wctype_t) iswpunct; + break; + default: + break; + } + break; + case 's': + if (strcmp (name + 1, "pace") == 0) + return (wctype_t) iswspace; + break; + case 'u': + if (strcmp (name + 1, "pper") == 0) + return (wctype_t) iswupper; + break; + case 'x': + if (strcmp (name + 1, "digit") == 0) + return (wctype_t) iswxdigit; + break; + default: + break; + } + return NULL; +} diff --git a/lib/wctype.c b/lib/wctype.c new file mode 100644 index 0000000000..968b36f7ce --- /dev/null +++ b/lib/wctype.c @@ -0,0 +1,25 @@ +/* Get descriptor for a wide character property. + Copyright (C) 2011 Free Software Foundation, Inc. + Written by Bruno Haible , 2011. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include + +#include "wctype-impl.h" diff --git a/lib/wctype.in.h b/lib/wctype.in.h index f72991aa45..f88e506b9e 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -384,6 +384,21 @@ typedef void * wctype_t; # endif #endif +/* Get a descriptor for a wide character property. */ +#if @GNULIB_WCTYPE@ +# if !@HAVE_WCTYPE_T@ +_GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name)); +# endif +_GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name)); +_GL_CXXALIASWARN (wctype); +#elif defined GNULIB_POSIXCHECK +# undef wctype +# if HAVE_RAW_DECL_WCTYPE +_GL_WARN_ON_USE (wctype, "wctype is unportable - " + "use gnulib module wctype for portability"); +# endif +#endif + #if @REPLACE_ISWCNTRL@ || defined __MINGW32__ _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc)); _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc)); diff --git a/m4/wctype.m4 b/m4/wctype.m4 new file mode 100644 index 0000000000..93c50d3fa1 --- /dev/null +++ b/m4/wctype.m4 @@ -0,0 +1,14 @@ +# wctype.m4 serial 1 +dnl Copyright (C) 2011 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_WCTYPE], +[ + AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) + AC_REQUIRE([gl_WCTYPE_H]) + if test $HAVE_WCTYPE_T = 0; then + AC_LIBOBJ([wctype]) + fi +]) diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4 index 307d5e1bea..23f91759cf 100644 --- a/m4/wctype_h.m4 +++ b/m4/wctype_h.m4 @@ -130,6 +130,24 @@ AC_DEFUN([gl_WCTYPE_H], if test $gl_cv_type_wctrans_t = no; then HAVE_WCTRANS_T=0 fi + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.0.1 has a bug: , and must be + included before . */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include +# include +# include +# include +#endif +#include + ]], + [wctype + ]) ]) AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR], @@ -144,6 +162,7 @@ AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR], AC_DEFUN([gl_WCTYPE_H_DEFAULTS], [ GNULIB_ISWBLANK=0; AC_SUBST([GNULIB_ISWBLANK]) + GNULIB_WCTYPE=0; AC_SUBST([GNULIB_WCTYPE]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK]) HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T]) diff --git a/modules/wctype b/modules/wctype index c3c0e808ba..d2481640a1 100644 --- a/modules/wctype +++ b/modules/wctype @@ -1,12 +1,24 @@ Description: -A that conforms better to C99. +wctype() function: get descriptor for a wide character property. + +Status: +obsolete + +Notice: +This module is obsolete. Files: +lib/wctype.c +lib/wctype-impl.h +m4/wctype.m4 Depends-on: wctype-h +iswblank configure.ac: +gl_FUNC_WCTYPE +gl_WCTYPE_MODULE_INDICATOR([wctype]) Makefile.am: diff --git a/modules/wctype-h b/modules/wctype-h index d6499c7bb2..4c3bdebf74 100644 --- a/modules/wctype-h +++ b/modules/wctype-h @@ -28,6 +28,7 @@ wctype.h: wctype.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \ + -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \ -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \ -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \ diff --git a/tests/test-wctype-h-c++.cc b/tests/test-wctype-h-c++.cc index ce731127a3..51e9213ceb 100644 --- a/tests/test-wctype-h-c++.cc +++ b/tests/test-wctype-h-c++.cc @@ -39,6 +39,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::iswspace, int, (wint_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::iswupper, int, (wint_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::iswxdigit, int, (wint_t)); +#if GNULIB_TEST_WCTYPE +SIGNATURE_CHECK (GNULIB_NAMESPACE::wctype, wctype_t, (const char *)); +#endif + SIGNATURE_CHECK (GNULIB_NAMESPACE::towlower, wint_t, (wint_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::towupper, wint_t, (wint_t)); -- 2.30.2