From 82b3be219d2636717f419e68ceaca40f3b5b8514 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 18 Dec 2008 00:19:07 +0100 Subject: [PATCH] New module 'btowc'. --- ChangeLog | 12 ++++++++++++ doc/posix-functions/btowc.texi | 8 ++++---- lib/btowc.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/wchar.in.h | 14 ++++++++++++++ m4/btowc.m4 | 22 ++++++++++++++++++++++ m4/wchar.m4 | 4 +++- modules/btowc | 25 +++++++++++++++++++++++++ modules/wchar | 2 ++ 8 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 lib/btowc.c create mode 100644 m4/btowc.m4 create mode 100644 modules/btowc diff --git a/ChangeLog b/ChangeLog index 7b07b947e..a9ee10ae2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2008-12-17 Bruno Haible + New module 'btowc'. + * lib/wchar.in.h (btowc): New declaration. + * lib/btowc.c: New file. + * m4/btowc.m4: New file. + * modules/btowc: New file. + * m4/wchar.m4 (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_BTOWC and + HAVE_BTOWC. + * modules/wchar (Makefile.am): Substitute GNULIB_BTOWC and HAVE_BTOWC. + * doc/posix-functions/btowc.texi: Document the new module. + +2008-12-17 Bruno Haible + New module 'mbsinit'. * lib/wchar.in.h (mbsinit): New declaration. * lib/mbsinit.c: New file. diff --git a/doc/posix-functions/btowc.texi b/doc/posix-functions/btowc.texi index 07f31cc19..816fabc58 100644 --- a/doc/posix-functions/btowc.texi +++ b/doc/posix-functions/btowc.texi @@ -4,18 +4,18 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/btowc.html} -Gnulib module: --- +Gnulib module: btowc Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +HP-UX 11, IRIX 5.3, Solaris 2.6, mingw, Interix 3.5. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -HP-UX 11, IRIX 5.3, Solaris 2.6, mingw, Interix 3.5. -@item On Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot accommodate all Unicode characters. @end itemize diff --git a/lib/btowc.c b/lib/btowc.c new file mode 100644 index 000000000..7f3b9663c --- /dev/null +++ b/lib/btowc.c @@ -0,0 +1,38 @@ +/* Convert unibyte character to wide character. + 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 + +#include + +wint_t +btowc (int c) +{ + if (c != EOF) + { + char buf[1]; + wchar_t wc; + + buf[0] = c; + if (mbtowc (&wc, buf, 1) >= 0) + return wc; + } + return WEOF; +} diff --git a/lib/wchar.in.h b/lib/wchar.in.h index f1bf17465..445530d4b 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -71,6 +71,20 @@ extern "C" { #endif +/* Convert a single-byte character to a wide character. */ +#if @GNULIB_BTOWC@ +# if !@HAVE_BTOWC@ +extern wint_t btowc (int c); +# endif +#elif defined GNULIB_POSIXCHECK +# undef btowc +# define btowc(c) \ + (GL_LINK_WARNING ("btowc is unportable - " \ + "use gnulib module btowc for portability"), \ + btowc (c)) +#endif + + /* Test whether *PS is in the initial state. */ #if @GNULIB_MBSINIT@ # if !@HAVE_MBSINIT@ diff --git a/m4/btowc.m4 b/m4/btowc.m4 new file mode 100644 index 000000000..98849d65a --- /dev/null +++ b/m4/btowc.m4 @@ -0,0 +1,22 @@ +# btowc.m4 serial 1 +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_BTOWC], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + + AC_CHECK_FUNCS_ONCE([btowc]) + if test $ac_cv_func_btowc = no; then + HAVE_BTOWC=0 + AC_LIBOBJ([btowc]) + gl_PREREQ_BTOWC + fi +]) + +# Prerequisites of lib/btowc.c. +AC_DEFUN([gl_PREREQ_BTOWC], [ + : +]) diff --git a/m4/wchar.m4 b/m4/wchar.m4 index 809402ef6..0f562822d 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 7 +# wchar.m4 serial 8 AC_DEFUN([gl_WCHAR_H], [ @@ -61,9 +61,11 @@ AC_DEFUN([gl_WCHAR_MODULE_INDICATOR], AC_DEFUN([gl_WCHAR_H_DEFAULTS], [ + GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC]) 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_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) diff --git a/modules/btowc b/modules/btowc new file mode 100644 index 000000000..f905b60aa --- /dev/null +++ b/modules/btowc @@ -0,0 +1,25 @@ +Description: +btowc() function: convert unibyte character to wide character. + +Files: +lib/btowc.c +m4/btowc.m4 + +Depends-on: +wchar + +configure.ac: +gl_FUNC_BTOWC +gl_WCHAR_MODULE_INDICATOR([btowc]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/wchar b/modules/wchar index 7b2200253..3f60ceaee 100644 --- a/modules/wchar +++ b/modules/wchar @@ -25,9 +25,11 @@ 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_BTOWC''@|$(GNULIB_BTOWC)|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_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ -- 2.11.0