From 8f8d09c041ffce812946f8bd6b4b388676e4e56e Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 9 Apr 2003 10:42:12 +0000 Subject: [PATCH] * libc/include/wchar.h: Add definitions for wcswidth and wcwidth. * libc/string/Makefile.am: Add wcswidth.c and wcwidth.c * libc/string/Makefile.in: Regenerated. * libc/string/wcswidth.c: New file. * libc/string/wcwidth.c: New file. * libc/string/wcstrings.tex: Add wcswidth and wcwidth. --- newlib/ChangeLog | 9 +++++ newlib/libc/include/wchar.h | 2 ++ newlib/libc/string/Makefile.am | 5 ++- newlib/libc/string/Makefile.in | 15 +++++---- newlib/libc/string/wcstrings.tex | 8 +++++ newlib/libc/string/wcswidth.c | 56 ++++++++++++++++++++++++++++++++ newlib/libc/string/wcwidth.c | 53 ++++++++++++++++++++++++++++++ 7 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 newlib/libc/string/wcswidth.c create mode 100644 newlib/libc/string/wcwidth.c diff --git a/newlib/ChangeLog b/newlib/ChangeLog index d66f67d00..6efbd70eb 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,12 @@ +2001-04-09 Corinna Vinschen + + * libc/include/wchar.h: Add definitions for wcswidth and wcwidth. + * libc/string/Makefile.am: Add wcswidth.c and wcwidth.c + * libc/string/Makefile.in: Regenerated. + * libc/string/wcswidth.c: New file. + * libc/string/wcwidth.c: New file. + * libc/string/wcstrings.tex: Add wcswidth and wcwidth. + Thu Apr 3 14:01:16 2003 J"orn Rennecke * libc/machine/sh/memset.S: Fix problem with alloco region diff --git a/newlib/libc/include/wchar.h b/newlib/libc/include/wchar.h index 9a25f0c7a..8d3e4d9ee 100644 --- a/newlib/libc/include/wchar.h +++ b/newlib/libc/include/wchar.h @@ -62,6 +62,8 @@ wchar_t *_EXFUN(wcspbrk, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcsrchr, (const wchar_t *, wchar_t)); size_t _EXFUN(wcsspn, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcsstr, (const wchar_t *, const wchar_t *)); +int _EXFUN(wcswidth, (const wchar_t *, size_t)); +int _EXFUN(wcwidth, (const wchar_t)); wchar_t *_EXFUN(wmemchr, (const wchar_t *, wchar_t, size_t)); int _EXFUN(wmemcmp, (const wchar_t *, const wchar_t *, size_t)); wchar_t *_EXFUN(wmemcpy, (wchar_t * , const wchar_t * , size_t)); diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index ea7cace9d..6066c9bbf 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -61,6 +61,8 @@ GENERAL_SOURCES = \ wcsrchr.c \ wcsspn.c \ wcsstr.c \ + wcswidth.c \ + wcwidth.c \ wmemchr.c \ wmemcmp.c \ wmemcpy.c \ @@ -109,7 +111,8 @@ wcscat.def wcschr.def wcscmp.def wcscoll.def \ wcscpy.def wcscspn.def \ wcslcat.def wcslcpy.def wcslen.def wcsncat.def wcsncmp.def \ wcsncpy.def wcspbrk.def wcsrchr.def wcsspn.def wcsstr.def \ -wmemchr.def wmemcmp.def wmemcpy.def wmemmove.def wmemset.def +wcswidth.def wcwidth.def wmemchr.def wmemcmp.def wmemcpy.def \ +wmemmove.def wmemset.def SUFFIXES = .def diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index d2a3c7bc7..b53356c9e 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -167,6 +167,8 @@ GENERAL_SOURCES = \ wcsrchr.c \ wcsspn.c \ wcsstr.c \ + wcswidth.c \ + wcwidth.c \ wmemchr.c \ wmemcmp.c \ wmemcpy.c \ @@ -207,7 +209,8 @@ wcscat.def wcschr.def wcscmp.def wcscoll.def \ wcscpy.def wcscspn.def \ wcslcat.def wcslcpy.def wcslen.def wcsncat.def wcsncmp.def \ wcsncpy.def wcspbrk.def wcsrchr.def wcsspn.def wcsstr.def \ -wmemchr.def wmemcmp.def wmemcpy.def wmemmove.def wmemset.def +wcswidth.def wcwidth.def wmemchr.def wmemcmp.def wmemcpy.def \ +wmemmove.def wmemset.def SUFFIXES = .def @@ -246,9 +249,9 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@wcslcpy.$(OBJEXT) wcslen.$(OBJEXT) wcsncat.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcsncmp.$(OBJEXT) wcsncpy.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcspbrk.$(OBJEXT) wcsrchr.$(OBJEXT) wcsspn.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wcsstr.$(OBJEXT) wmemchr.$(OBJEXT) wmemcmp.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wmemcpy.$(OBJEXT) wmemmove.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wmemset.$(OBJEXT) +@USE_LIBTOOL_FALSE@wcsstr.$(OBJEXT) wcswidth.$(OBJEXT) wcwidth.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemchr.$(OBJEXT) wmemcmp.$(OBJEXT) wmemcpy.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemmove.$(OBJEXT) wmemset.$(OBJEXT) LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@libstring_la_OBJECTS = bcopy.lo bzero.lo index.lo \ @@ -263,8 +266,8 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@wcscat.lo wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo \ @USE_LIBTOOL_TRUE@wcscspn.lo wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo \ @USE_LIBTOOL_TRUE@wcsncmp.lo wcsncpy.lo wcspbrk.lo wcsrchr.lo wcsspn.lo \ -@USE_LIBTOOL_TRUE@wcsstr.lo wmemchr.lo wmemcmp.lo wmemcpy.lo wmemmove.lo \ -@USE_LIBTOOL_TRUE@wmemset.lo +@USE_LIBTOOL_TRUE@wcsstr.lo wcswidth.lo wcwidth.lo wmemchr.lo wmemcmp.lo \ +@USE_LIBTOOL_TRUE@wmemcpy.lo wmemmove.lo wmemset.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/string/wcstrings.tex b/newlib/libc/string/wcstrings.tex index 7c72eab54..8f82e62c3 100644 --- a/newlib/libc/string/wcstrings.tex +++ b/newlib/libc/string/wcstrings.tex @@ -27,6 +27,8 @@ declarations are in @file{wchar.h}. * wcsrchr:: Reverse search for wide-character in string * wcsspn:: Find initial match in wide-character string * wcsstr:: Find wide-character string segment +* wcswidth:: Number of column positions of a wide-character string +* wcwidth:: Number of column positions of a wide-character code @end menu @page @@ -92,3 +94,9 @@ declarations are in @file{wchar.h}. @page @include string/wcsstr.def +@page +@include string/wcswidth.def + +@page +@include string/wcwidth.def + diff --git a/newlib/libc/string/wcswidth.c b/newlib/libc/string/wcswidth.c new file mode 100644 index 000000000..bd3d9bbad --- /dev/null +++ b/newlib/libc/string/wcswidth.c @@ -0,0 +1,56 @@ +/* +FUNCTION + <>---number of column positions of a wide-character string + +INDEX + wcswidth + +ANSI_SYNOPSIS + #include + int wcswidth(const wchar_t *<[pwcs]>, size_t <[n]>); + +TRAD_SYNOPSIS + #include + int wcswidth(<[pwcs]>, <[n]>) + wchar_t *<[wc]>; + size_t <[n]>; + +DESCRIPTION + The <> function shall determine the number of column + positions required for n wide-character codes (or fewer than n + wide-character codes if a null wide-character code is encountered + before n wide-character codes are exhausted) in the string pointed + to by pwcs. + +RETURNS + The <> function either shall return 0 (if pwcs points to a + null wide-character code), or return the number of column positions + to be occupied by the wide-character string pointed to by pwcs, or + return -1 (if any of the first n wide-character codes in the + wide-character string pointed to by pwcs is not a printable + wide-character code). + +PORTABILITY +<> has been introduced in the Single UNIX Specification Volume 2 +<> has been marked as extension in Single UNIX Specification Volume 3 +*/ + +#include <_ansi.h> +#include + +int +_DEFUN (wcswidth, (pwcs, n), + _CONST wchar_t *pwcs _AND + size_t n) + +{ + int w, len = 0; + if (!pwcs || n == 0) + return 0; + do { + if ((w = wcwidth (*pwcs)) < 0) + return -1; + len += w; + } while (*pwcs++ && --n > 0); + return len; +} diff --git a/newlib/libc/string/wcwidth.c b/newlib/libc/string/wcwidth.c new file mode 100644 index 000000000..2cbd59e18 --- /dev/null +++ b/newlib/libc/string/wcwidth.c @@ -0,0 +1,53 @@ +/* +FUNCTION + <>---number of column positions of a wide-character code + +INDEX + wcwidth + +ANSI_SYNOPSIS + #include + int wcwidth(const wchar_t <[wc]>); + +TRAD_SYNOPSIS + #include + int wcwidth(<[wc]>) + wchar_t *<[wc]>; + +DESCRIPTION + The <> function shall determine the number of column + positions required for the wide character wc. The application + shall ensure that the value of wc is a character representable + as a wchar_t, and is a wide-character code corresponding to a + valid character in the current locale. + +RETURNS + The <> function shall either return 0 (if wc is a null + wide-character code), or return the number of column positions to + be occupied by the wide-character code wc, or return -1 (if wc + does not correspond to a printable wide-character code). + + The current implementation of <> simply sets the width + of all printable characters to 1 since newlib has no character + tables around. + +PORTABILITY +<> has been introduced in the Single UNIX Specification Volume 2 +<> has been marked as extension in Single UNIX Specification Volume 3 +*/ + +#include <_ansi.h> +#include +#include + +int +_DEFUN (wcwidth, (wc), + _CONST wchar_t wc) + +{ + if (iswprint (wc)) + return 1; + if (iswcntrl (wc) || wc == L'\0') + return 0; + return -1; +}