From: Bruno Haible Date: Wed, 17 Dec 2008 12:03:10 +0000 (+0100) Subject: New module 'mbsinit'. X-Git-Tag: v0.1~6593 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=7697f254b9de17ef9a777a6b8352a86445f831bf;p=gnulib.git New module 'mbsinit'. --- diff --git a/ChangeLog b/ChangeLog index 2a401a1e0..7b07b947e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-12-17 Bruno Haible + + New module 'mbsinit'. + * lib/wchar.in.h (mbsinit): New declaration. + * lib/mbsinit.c: New file. + * m4/mbsinit.m4: New file. + * modules/mbsinit: New file. + * m4/wchar.m4 (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_MBSINIT and + HAVE_MBSINIT. + * modules/wchar (Makefile.am): Substitute GNULIB_MBSINIT and + HAVE_MBSINIT. + * doc/posix-functions/mbsinit.texi: Document the new module. + 2008-12-16 Bruno Haible * lib/unistd.in.h: Add comment. diff --git a/doc/posix-functions/mbsinit.texi b/doc/posix-functions/mbsinit.texi index 5121415e1..71a1925da 100644 --- a/doc/posix-functions/mbsinit.texi +++ b/doc/posix-functions/mbsinit.texi @@ -4,15 +4,15 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/mbsinit.html} -Gnulib module: --- +Gnulib module: mbsinit Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +HP-UX 11, IRIX 6.5, Solaris 2.6, Interix 3.5. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -HP-UX 11, IRIX 6.5, Solaris 2.6, Interix 3.5. @end itemize diff --git a/lib/mbsinit.c b/lib/mbsinit.c new file mode 100644 index 000000000..2753b4175 --- /dev/null +++ b/lib/mbsinit.c @@ -0,0 +1,43 @@ +/* Test for initial conversion state. + Copyright (C) 2008 Free Software Foundation, Inc. + Written by Bruno Haible , 2008. + + 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 + +/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs() + and wcrtomb(), wcsrtombs(). + We assume that + - sizeof (mbstate_t) >= 4, + - only stateless encodings are supported (such as UTF-8 and EUC-JP, but + not ISO-2022 variants), + - for each encoding, the number of bytes for a wide character is <= 4. + (This maximum is attained for UTF-8, GB18030, EUC-TW.) + We define the meaning of mbstate_t as follows: + - In mb -> wc direction, mbstate_t's first byte contains the number of + buffered bytes (in the range 0..3), followed by up to 3 buffered bytes. + - In wc -> mb direction, mbstate_t contains no information. In other + words, it is always in the initial state. */ + +int +mbsinit (const mbstate_t *ps) +{ + const char *pstate = (const char *)ps; + + return pstate[0] == 0; +} diff --git a/lib/wchar.in.h b/lib/wchar.in.h index ceb62084f..f1bf17465 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -71,6 +71,20 @@ extern "C" { #endif +/* Test whether *PS is in the initial state. */ +#if @GNULIB_MBSINIT@ +# if !@HAVE_MBSINIT@ +extern int mbsinit (const mbstate_t *ps); +# endif +#elif defined GNULIB_POSIXCHECK +# undef mbsinit +# define mbsinit(p) \ + (GL_LINK_WARNING ("mbsinit is unportable - " \ + "use gnulib module mbsinit for portability"), \ + mbsinit (p)) +#endif + + /* Return the number of screen columns needed for WC. */ #if @GNULIB_WCWIDTH@ # if @REPLACE_WCWIDTH@ diff --git a/m4/mbsinit.m4 b/m4/mbsinit.m4 new file mode 100644 index 000000000..f19ec0c7a --- /dev/null +++ b/m4/mbsinit.m4 @@ -0,0 +1,23 @@ +# mbsinit.m4 serial 14 +dnl Copyright (C) 2008 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_MBSINIT], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + AC_REQUIRE([AC_TYPE_MBSTATE_T]) + AC_CHECK_FUNCS_ONCE([mbsinit]) + if test $ac_cv_func_mbsinit = no; then + HAVE_MBSINIT=0 + AC_LIBOBJ([mbsinit]) + gl_PREREQ_MBSINIT + fi +]) + +# Prerequisites of lib/mbsinit.c. +AC_DEFUN([gl_PREREQ_MBSINIT], [ + : +]) diff --git a/m4/wchar.m4 b/m4/wchar.m4 index 5c923fa0e..809402ef6 100644 --- a/m4/wchar.m4 +++ b/m4/wchar.m4 @@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. dnl Written by Eric Blake. -# wchar.m4 serial 6 +# wchar.m4 serial 7 AC_DEFUN([gl_WCHAR_H], [ @@ -61,8 +61,10 @@ AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], AC_DEFUN([gl_WCHAR_H_DEFAULTS], [ + GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT]) GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH]) dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) WCHAR_H=''; AC_SUBST([WCHAR_H]) diff --git a/modules/mbsinit b/modules/mbsinit new file mode 100644 index 000000000..e8a3ef97e --- /dev/null +++ b/modules/mbsinit @@ -0,0 +1,26 @@ +Description: +mbsinit() function: test for initial conversion state. + +Files: +lib/mbsinit.c +m4/mbsinit.m4 +m4/mbstate_t.m4 + +Depends-on: +wchar + +configure.ac: +gl_FUNC_MBSINIT +gl_WCHAR_MODULE_INDICATOR([mbsinit]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/wchar b/modules/wchar index 381f4758d..7b2200253 100644 --- a/modules/wchar +++ b/modules/wchar @@ -25,8 +25,10 @@ wchar.h: wchar.in.h -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \ -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \ + -e 's|@''GNULIB_MBSINIT''@|$(GNULIB_MBSINIT)|g' \ -e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \ -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ + -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \