From cdddb1e1f27b899a9580d3ad289539c3c124d045 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 Feb 2011 15:25:58 +0100 Subject: [PATCH] New module 'wcstok'. * modules/wcstok: New file. * lib/wchar.in.h (wcstok): New declaration. * lib/wcstok.c: New file. * lib/wcstok-impl.h: New file, from libutf8 with modifications. * m4/wcstok.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcstok is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSTOK, HAVE_WCSTOK. * modules/wchar (Makefile.am): Substitute GNULIB_WCSTOK, HAVE_WCSTOK. * tests/test-wchar-c++.cc: Test the declaration of wcstok. * doc/posix-functions/wcstok.texi: Mention the new module. --- ChangeLog | 14 +++++++++ doc/posix-functions/wcstok.texi | 8 +++--- lib/wchar.in.h | 18 ++++++++++++ lib/wcstok-impl.h | 50 +++++++++++++++++++++++++++++++++ lib/wcstok.c | 23 +++++++++++++++ m4/wchar_h.m4 | 4 ++- m4/wcstok.m4 | 15 ++++++++++ modules/wchar | 2 ++ modules/wcstok | 27 ++++++++++++++++++ tests/test-wchar-c++.cc | 5 ++++ 10 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 lib/wcstok-impl.h create mode 100644 lib/wcstok.c create mode 100644 m4/wcstok.m4 create mode 100644 modules/wcstok diff --git a/ChangeLog b/ChangeLog index 23694c5e01..c6b8a83cd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-02-06 Bruno Haible + + New module 'wcstok'. + * modules/wcstok: New file. + * lib/wchar.in.h (wcstok): New declaration. + * lib/wcstok.c: New file. + * lib/wcstok-impl.h: New file, from libutf8 with modifications. + * m4/wcstok.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcstok is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSTOK, HAVE_WCSTOK. + * modules/wchar (Makefile.am): Substitute GNULIB_WCSTOK, HAVE_WCSTOK. + * tests/test-wchar-c++.cc: Test the declaration of wcstok. + * doc/posix-functions/wcstok.texi: Mention the new module. + 2011-02-06 Bruno Haible New module 'wcsstr'. diff --git a/doc/posix-functions/wcstok.texi b/doc/posix-functions/wcstok.texi index 2d9c69ff44..d19fb432a1 100644 --- a/doc/posix-functions/wcstok.texi +++ b/doc/posix-functions/wcstok.texi @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcstok.html} -Gnulib module: --- +Gnulib module: wcstok Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +IRIX 5.3, Solaris 2.5.1, Cygwin 1.5.x. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -IRIX 5.3, Solaris 2.5.1, Cygwin 1.5.x. -@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/wchar.in.h b/lib/wchar.in.h index b175ab7ec5..13e4d7fed5 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -873,6 +873,24 @@ _GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - " #endif +/* Divide WCS into tokens separated by characters in DELIM. */ +#if @GNULIB_WCSTOK@ +# if !@HAVE_WCSTOK@ +_GL_FUNCDECL_SYS (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +# endif +_GL_CXXALIAS_SYS (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +_GL_CXXALIASWARN (wcstok); +#elif defined GNULIB_POSIXCHECK +# undef wcstok +# if HAVE_RAW_DECL_WCSTOK +_GL_WARN_ON_USE (wcstok, "wcstok is unportable - " + "use gnulib module wcstok for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif diff --git a/lib/wcstok-impl.h b/lib/wcstok-impl.h new file mode 100644 index 0000000000..afb9046fbf --- /dev/null +++ b/lib/wcstok-impl.h @@ -0,0 +1,50 @@ +/* Split a wide string into tokens. + Copyright (C) 1999, 2011 Free Software Foundation, Inc. + Written by Bruno Haible , 1999. + + 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 . */ + +wchar_t * +wcstok (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr) +{ + if (wcs == NULL) + { + wcs = *ptr; + if (wcs == NULL) + return NULL; /* reminder that end of token sequence has been reached */ + } + + /* Skip leading delimiters. */ + wcs += wcsspn (wcs, delim); + + /* Found a token? */ + if (*wcs == (wchar_t)'\0') + { + *ptr = NULL; + return NULL; + } + /* Move past the token. */ + { + wchar_t *token_end = wcspbrk (wcs, delim); + if (token_end) + { + /* NUL-terminate the token. */ + *token_end = (wchar_t)'\0'; + *ptr = token_end + 1; + } + else + *ptr = NULL; + } + return wcs; +} diff --git a/lib/wcstok.c b/lib/wcstok.c new file mode 100644 index 0000000000..e61a3ff624 --- /dev/null +++ b/lib/wcstok.c @@ -0,0 +1,23 @@ +/* Split a wide string into tokens. + 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 "wcstok-impl.h" diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index 9e5fbcdd5e..f320dd7931 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -53,7 +53,7 @@ AC_DEFUN([gl_WCHAR_H], wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr - wcscspn wcsspn wcspbrk wcsstr + wcscspn wcsspn wcspbrk wcsstr wcstok ]) ]) @@ -174,6 +174,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN]) GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK]) GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR]) + GNULIB_WCSTOK=0; AC_SUBST([GNULIB_WCSTOK]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -210,6 +211,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN]) HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK]) HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR]) + HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK]) HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB]) HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T]) diff --git a/m4/wcstok.m4 b/m4/wcstok.m4 new file mode 100644 index 0000000000..4c91c4f6fa --- /dev/null +++ b/m4/wcstok.m4 @@ -0,0 +1,15 @@ +# wcstok.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_WCSTOK], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([wcstok]) + if test $ac_cv_func_wcstok = no; then + HAVE_WCSTOK=0 + AC_LIBOBJ([wcstok]) + fi +]) diff --git a/modules/wchar b/modules/wchar index f2a4a0c373..bd9719fc76 100644 --- a/modules/wchar +++ b/modules/wchar @@ -67,6 +67,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_WCSSPN''@|$(GNULIB_WCSSPN)|g' \ -e 's|@''GNULIB_WCSPBRK''@|$(GNULIB_WCSPBRK)|g' \ -e 's|@''GNULIB_WCSSTR''@|$(GNULIB_WCSSTR)|g' \ + -e 's|@''GNULIB_WCSTOK''@|$(GNULIB_WCSTOK)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -103,6 +104,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_WCSSPN''@|$(HAVE_WCSSPN)|g' \ -e 's|@''HAVE_WCSPBRK''@|$(HAVE_WCSPBRK)|g' \ -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \ + -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \ -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \ -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \ diff --git a/modules/wcstok b/modules/wcstok new file mode 100644 index 0000000000..6f92b050b9 --- /dev/null +++ b/modules/wcstok @@ -0,0 +1,27 @@ +Description: +wcstok() function: split a wide string into tokens. + +Files: +lib/wcstok.c +lib/wcstok-impl.h +m4/wcstok.m4 + +Depends-on: +wchar +wcsspn +wcspbrk + +configure.ac: +gl_FUNC_WCSTOK +gl_WCHAR_MODULE_INDICATOR([wcstok]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc index 495a6b45e3..e8fd2ac95e 100644 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -202,6 +202,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsstr, wchar_t *, (const wchar_t *, const wchar_t *)); #endif +#if GNULIB_TEST_WCSTOK +SIGNATURE_CHECK (GNULIB_NAMESPACE::wcstok, wchar_t *, + (wchar_t *, const wchar_t *, wchar_t **)); +#endif + int main () -- 2.30.2