changeset 10892:67a8f53c94f0

New module 'mbsinit'.
author Bruno Haible <bruno@clisp.org>
date Wed, 17 Dec 2008 13:03:10 +0100
parents da1e292eb1e0
children 1223949523dd
files ChangeLog doc/posix-functions/mbsinit.texi lib/mbsinit.c lib/wchar.in.h m4/mbsinit.m4 m4/wchar.m4 modules/mbsinit modules/wchar
diffstat 8 files changed, 129 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Dec 17 01:56:49 2008 +0100
+++ b/ChangeLog	Wed Dec 17 13:03:10 2008 +0100
@@ -1,3 +1,16 @@
+2008-12-17  Bruno Haible  <bruno@clisp.org>
+
+	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  <bruno@clisp.org>
 
 	* lib/unistd.in.h: Add comment.
--- a/doc/posix-functions/mbsinit.texi	Wed Dec 17 01:56:49 2008 +0100
+++ b/doc/posix-functions/mbsinit.texi	Wed Dec 17 13:03:10 2008 +0100
@@ -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
-@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
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/mbsinit.c	Wed Dec 17 13:03:10 2008 +0100
@@ -0,0 +1,43 @@
+/* Test for initial conversion state.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+/* 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;
+}
--- a/lib/wchar.in.h	Wed Dec 17 01:56:49 2008 +0100
+++ b/lib/wchar.in.h	Wed Dec 17 13:03:10 2008 +0100
@@ -71,6 +71,20 @@
 #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@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/mbsinit.m4	Wed Dec 17 13:03:10 2008 +0100
@@ -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], [
+  :
+])
--- a/m4/wchar.m4	Wed Dec 17 01:56:49 2008 +0100
+++ b/m4/wchar.m4	Wed Dec 17 13:03:10 2008 +0100
@@ -7,7 +7,7 @@
 
 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_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])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/mbsinit	Wed Dec 17 13:03:10 2008 +0100
@@ -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:
+<wchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
--- a/modules/wchar	Wed Dec 17 01:56:49 2008 +0100
+++ b/modules/wchar	Wed Dec 17 13:03:10 2008 +0100
@@ -25,8 +25,10 @@
 	      -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)' \