Mercurial > hg > octave-kai > gnulib-hg
changeset 14319:aef6efcc4045
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 06 Feb 2011 23:45:40 +0100 |
parents | 18ad0b0246fc |
children | 9a2d4c1b2034 |
files | ChangeLog doc/posix-functions/wctype.texi lib/wctype-impl.h lib/wctype.c lib/wctype.in.h m4/wctype.m4 m4/wctype_h.m4 modules/wctype modules/wctype-h tests/test-wctype-h-c++.cc |
diffstat | 10 files changed, 210 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-02-06 Bruno Haible <bruno@clisp.org> + + 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 <bruno@clisp.org> wctype-h: Ensure wctype_t and wctrans_t are defined.
--- 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{<wchar.h>}, not in @code{<wctype.h>}, 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
new file mode 100644 --- /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 <bruno@clisp.org>, 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 <http://www.gnu.org/licenses/>. */ + +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; +}
new file mode 100644 --- /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 <bruno@clisp.org>, 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 <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <wctype.h> + +#include <string.h> + +#include "wctype-impl.h"
--- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -384,6 +384,21 @@ # 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));
new file mode 100644 --- /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 +])
--- a/m4/wctype_h.m4 +++ b/m4/wctype_h.m4 @@ -130,6 +130,24 @@ 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: <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>. */ +#if !(defined __GLIBC__ && !defined __UCLIBC__) +# include <stddef.h> +# include <stdio.h> +# include <time.h> +# include <wchar.h> +#endif +#include <wctype.h> + ]], + [wctype + ]) ]) AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR], @@ -144,6 +162,7 @@ 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])
--- a/modules/wctype +++ b/modules/wctype @@ -1,12 +1,24 @@ Description: -A <wctype.h> 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:
--- a/modules/wctype-h +++ b/modules/wctype-h @@ -28,6 +28,7 @@ -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' \
--- a/tests/test-wctype-h-c++.cc +++ b/tests/test-wctype-h-c++.cc @@ -39,6 +39,10 @@ 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));