bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'mbsinit'


From: Bruno Haible
Subject: new module 'mbsinit'
Date: Wed, 17 Dec 2008 13:09:23 +0100
User-agent: KMail/1.9.9

I'm starting to add support for ISO C 99 multibyte / wide character functions,
for systems such as HP-UX 11, IRIX 6.5, Solaris 2.6.

The first module is 'mbsinit'.

2008-12-17  Bruno Haible  <address@hidden>

        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.

============================ lib/mbsinit.c =============================
/* Test for initial conversion state.
   Copyright (C) 2008 Free Software Foundation, Inc.
   Written by Bruno Haible <address@hidden>, 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;
}
============================ m4/mbsinit.m4 =============================
# 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], [
  :
])
=========================== modules/mbsinit ============================
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

========================================================================
--- doc/posix-functions/mbsinit.texi.orig       2008-12-17 12:59:27.000000000 
+0100
+++ doc/posix-functions/mbsinit.texi    2008-12-17 12:36:37.000000000 +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
address@hidden
+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
address@hidden
-This function is missing on some platforms:
-HP-UX 11, IRIX 6.5, Solaris 2.6, Interix 3.5.
 @end itemize
--- lib/wchar.in.h.orig 2008-12-17 12:59:27.000000000 +0100
+++ lib/wchar.in.h      2008-12-17 12:28:03.000000000 +0100
@@ -71,6 +71,20 @@
 #endif
 
 
+/* Test whether *PS is in the initial state.  */
+#if @GNULIB_MBSINIT@
+# if address@hidden@
+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@
--- m4/wchar.m4.orig    2008-12-17 12:59:27.000000000 +0100
+++ m4/wchar.m4 2008-12-17 12:30:29.000000000 +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])
--- modules/wchar.orig  2008-12-17 12:59:27.000000000 +0100
+++ modules/wchar       2008-12-17 12:29:32.000000000 +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)' \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]