From 214aca197fc1b600e119e0fbae8cf196b48c5276 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 Feb 2011 13:52:11 +0100 Subject: [PATCH] New module 'wcschr'. * modules/wcschr: New file. * lib/wchar.in.h (wcschr): New declaration. * lib/wcschr.c: New file. * lib/wcschr-impl.h: New file, from libutf8 with modifications. * m4/wcschr.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcschr is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSCHR, HAVE_WCSCHR. * modules/wchar (Makefile.am): Substitute GNULIB_WCSCHR, HAVE_WCSCHR. * tests/test-wchar-c++.cc: Test the declaration of wcschr. * doc/posix-functions/wcschr.texi: Mention the new module. --- ChangeLog | 14 ++++++++++++++ doc/posix-functions/wcschr.texi | 8 ++++---- lib/wchar.in.h | 16 ++++++++++++++++ lib/wcschr-impl.h | 32 ++++++++++++++++++++++++++++++++ lib/wcschr.c | 23 +++++++++++++++++++++++ m4/wchar_h.m4 | 4 +++- m4/wcschr.m4 | 15 +++++++++++++++ modules/wchar | 2 ++ modules/wcschr | 31 +++++++++++++++++++++++++++++++ tests/test-wchar-c++.cc | 5 +++++ 10 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 lib/wcschr-impl.h create mode 100644 lib/wcschr.c create mode 100644 m4/wcschr.m4 create mode 100644 modules/wcschr diff --git a/ChangeLog b/ChangeLog index 8411e083e..b2875e942 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-02-06 Bruno Haible + New module 'wcschr'. + * modules/wcschr: New file. + * lib/wchar.in.h (wcschr): New declaration. + * lib/wcschr.c: New file. + * lib/wcschr-impl.h: New file, from libutf8 with modifications. + * m4/wcschr.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcschr is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSCHR, HAVE_WCSCHR. + * modules/wchar (Makefile.am): Substitute GNULIB_WCSCHR, HAVE_WCSCHR. + * tests/test-wchar-c++.cc: Test the declaration of wcschr. + * doc/posix-functions/wcschr.texi: Mention the new module. + +2011-02-06 Bruno Haible + New module 'wcsdup'. * modules/wcsdup: New file. * lib/wchar.in.h (wcsdup): New declaration. diff --git a/doc/posix-functions/wcschr.texi b/doc/posix-functions/wcschr.texi index 3744e2484..3480cc488 100644 --- a/doc/posix-functions/wcschr.texi +++ b/doc/posix-functions/wcschr.texi @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcschr.html} -Gnulib module: --- +Gnulib module: wcschr Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +IRIX 5.3, Solaris 2.5.1. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -IRIX 5.3, Solaris 2.5.1. -@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 ff55f5479..815180f11 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -771,6 +771,22 @@ _GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - " #endif +/* Find the first occurrence of WC in WCS. */ +#if @GNULIB_WCSCHR@ +# if !@HAVE_WCSCHR@ +_GL_FUNCDECL_SYS (wcschr, wchar_t *, (const wchar_t *wcs, wchar_t wc)); +# endif +_GL_CXXALIAS_SYS (wcschr, wchar_t *, (const wchar_t *wcs, wchar_t wc)); +_GL_CXXALIASWARN (wcschr); +#elif defined GNULIB_POSIXCHECK +# undef wcschr +# if HAVE_RAW_DECL_WCSCHR +_GL_WARN_ON_USE (wcschr, "wcschr is unportable - " + "use gnulib module wcschr for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif diff --git a/lib/wcschr-impl.h b/lib/wcschr-impl.h new file mode 100644 index 000000000..2d146d383 --- /dev/null +++ b/lib/wcschr-impl.h @@ -0,0 +1,32 @@ +/* Search wide string for a wide character. + 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 * +wcschr (const wchar_t *wcs, wchar_t wc) +{ + for (;; wcs++) + { + if (*wcs == wc) + break; + if (*wcs == (wchar_t)'\0') + goto notfound; + } + return (wchar_t *) wcs; + + notfound: + return NULL; +} diff --git a/lib/wcschr.c b/lib/wcschr.c new file mode 100644 index 000000000..988b89725 --- /dev/null +++ b/lib/wcschr.c @@ -0,0 +1,23 @@ +/* Search wide string for a wide character. + 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 "wcschr-impl.h" diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index ab6f553c5..bbc124a68 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -52,7 +52,7 @@ AC_DEFUN([gl_WCHAR_H], [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp - wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup + wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr ]) ]) @@ -167,6 +167,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], GNULIB_WCSCOLL=0; AC_SUBST([GNULIB_WCSCOLL]) GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM]) GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP]) + GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -197,6 +198,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], HAVE_WCSCOLL=1; AC_SUBST([HAVE_WCSCOLL]) HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM]) HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP]) + HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR]) 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/wcschr.m4 b/m4/wcschr.m4 new file mode 100644 index 000000000..1813a06f4 --- /dev/null +++ b/m4/wcschr.m4 @@ -0,0 +1,15 @@ +# wcschr.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_WCSCHR], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([wcschr]) + if test $ac_cv_func_wcschr = no; then + HAVE_WCSCHR=0 + AC_LIBOBJ([wcschr]) + fi +]) diff --git a/modules/wchar b/modules/wchar index ee967a5c2..78d8c661a 100644 --- a/modules/wchar +++ b/modules/wchar @@ -61,6 +61,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_WCSCOLL''@|$(GNULIB_WCSCOLL)|g' \ -e 's|@''GNULIB_WCSXFRM''@|$(GNULIB_WCSXFRM)|g' \ -e 's|@''GNULIB_WCSDUP''@|$(GNULIB_WCSDUP)|g' \ + -e 's|@''GNULIB_WCSCHR''@|$(GNULIB_WCSCHR)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -91,6 +92,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_WCSCOLL''@|$(HAVE_WCSCOLL)|g' \ -e 's|@''HAVE_WCSXFRM''@|$(HAVE_WCSXFRM)|g' \ -e 's|@''HAVE_WCSDUP''@|$(HAVE_WCSDUP)|g' \ + -e 's|@''HAVE_WCSCHR''@|$(HAVE_WCSCHR)|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/wcschr b/modules/wcschr new file mode 100644 index 000000000..a84a91a86 --- /dev/null +++ b/modules/wcschr @@ -0,0 +1,31 @@ +Description: +wcschr() function: search wide string for a wide character. + +Status: +obsolete + +Notice: +This module is obsolete. + +Files: +lib/wcschr.c +lib/wcschr-impl.h +m4/wcschr.m4 + +Depends-on: +wchar + +configure.ac: +gl_FUNC_WCSCHR +gl_WCHAR_MODULE_INDICATOR([wcschr]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc index 79c9b3bc6..25583017b 100644 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -172,6 +172,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsxfrm, size_t, SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsdup, wchar_t *, (const wchar_t *)); #endif +#if GNULIB_TEST_WCSCHR +SIGNATURE_CHECK (GNULIB_NAMESPACE::wcschr, wchar_t *, + (const wchar_t *, wchar_t)); +#endif + int main () -- 2.11.0