[patch] Add wcsxfrm

Jeff Johnston jjohnstn@redhat.com
Wed Jul 4 16:19:00 GMT 2007


Yes, please go ahead and apply.

-- Jeff J.

Corinna Vinschen wrote:
> Hi,
> 
> while all(?) other wide character functions are implemented in newlib,
> the functions wcsxfrm is missing.  Below is a simple replacement
> implementation which ignores locales like the other wide char functions.
> 
> I added wcsxfrm.c to GENERAL_SOURCES like the other wide char funcs,
> I hope that's ok.
> 
> Ok to apply?
> 
> 
> Corinna
> 
> 
> 	* libc/include/wchar.h: Add prototype for wcsxfrm.
> 	* libc/string/Makefile.am (GENERAL_SOURCES): Add wcsxfrm.c.
> 	(CHEWOUT_FILES): Add wcsxfrm.def.
> 	* libc/string/Makefile.in: Regenerate.
> 	* libc/string/wcsxfrm.c: New file.
> 
> 
> Index: libc/include/wchar.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v
> retrieving revision 1.13
> diff -u -p -r1.13 wchar.h
> --- libc/include/wchar.h	5 Dec 2003 20:51:57 -0000	1.13
> +++ libc/include/wchar.h	4 Jul 2007 10:55:25 -0000
> @@ -71,6 +71,7 @@ wchar_t	*_EXFUN(wcsrchr, (const 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));
> +size_t	_EXFUN(wcsxfrm, (wchar_t *, 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));
> Index: libc/string/Makefile.am
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/string/Makefile.am,v
> retrieving revision 1.17
> diff -u -p -r1.17 Makefile.am
> --- libc/string/Makefile.am	28 Jun 2007 17:07:23 -0000	1.17
> +++ libc/string/Makefile.am	4 Jul 2007 10:55:26 -0000
> @@ -63,6 +63,7 @@ GENERAL_SOURCES = \
>  	wcsspn.c \
>  	wcsstr.c \
>  	wcswidth.c \
> +	wcsxfrm.c \
>  	wcwidth.c \
>  	wmemchr.c \
>  	wmemcmp.c \
> @@ -113,7 +114,7 @@ wcscpy.def	wcscspn.def \
>  wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \
>  wcsncmp.def	wcsncpy.def	wcsnlen.def	wcspbrk.def \
>  wcsrchr.def	wcsspn.def	wcsstr.def \
> -wcswidth.def	wcwidth.def	wmemchr.def \
> +wcswidth.def	wcsxfrm.def	wcwidth.def	wmemchr.def \
>  wmemcmp.def	wmemcpy.def	wmemmove.def	wmemset.def
>  
>  SUFFIXES = .def
> Index: libc/string/Makefile.in
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/string/Makefile.in,v
> retrieving revision 1.29
> diff -u -p -r1.29 Makefile.in
> --- libc/string/Makefile.in	28 Jun 2007 17:07:23 -0000	1.29
> +++ libc/string/Makefile.in	4 Jul 2007 10:55:26 -0000
> @@ -84,9 +84,10 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) li
>  	lib_a-wcsnlen.$(OBJEXT) lib_a-wcspbrk.$(OBJEXT) \
>  	lib_a-wcsrchr.$(OBJEXT) lib_a-wcsspn.$(OBJEXT) \
>  	lib_a-wcsstr.$(OBJEXT) lib_a-wcswidth.$(OBJEXT) \
> -	lib_a-wcwidth.$(OBJEXT) lib_a-wmemchr.$(OBJEXT) \
> -	lib_a-wmemcmp.$(OBJEXT) lib_a-wmemcpy.$(OBJEXT) \
> -	lib_a-wmemmove.$(OBJEXT) lib_a-wmemset.$(OBJEXT)
> +	lib_a-wcsxfrm.$(OBJEXT) lib_a-wcwidth.$(OBJEXT) \
> +	lib_a-wmemchr.$(OBJEXT) lib_a-wmemcmp.$(OBJEXT) \
> +	lib_a-wmemcpy.$(OBJEXT) lib_a-wmemmove.$(OBJEXT) \
> +	lib_a-wmemset.$(OBJEXT)
>  @ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \
>  @ELIX_LEVEL_1_FALSE@	lib_a-memccpy.$(OBJEXT) \
>  @ELIX_LEVEL_1_FALSE@	lib_a-mempcpy.$(OBJEXT) \
> @@ -111,8 +112,8 @@ am__objects_3 = bcopy.lo bzero.lo index.
>  	wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo wcscspn.lo \
>  	wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo wcsncmp.lo \
>  	wcsncpy.lo wcsnlen.lo wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo \
> -	wcswidth.lo wcwidth.lo wmemchr.lo wmemcmp.lo wmemcpy.lo \
> -	wmemmove.lo wmemset.lo
> +	wcswidth.lo wcsxfrm.lo wcwidth.lo wmemchr.lo wmemcmp.lo \
> +	wmemcpy.lo wmemmove.lo wmemset.lo
>  @ELIX_LEVEL_1_FALSE@am__objects_4 = bcmp.lo memccpy.lo mempcpy.lo \
>  @ELIX_LEVEL_1_FALSE@	stpcpy.lo stpncpy.lo strndup.lo \
>  @ELIX_LEVEL_1_FALSE@	strcasestr.lo strndup_r.lo
> @@ -354,6 +355,7 @@ GENERAL_SOURCES = \
>  	wcsspn.c \
>  	wcsstr.c \
>  	wcswidth.c \
> +	wcsxfrm.c \
>  	wcwidth.c \
>  	wmemchr.c \
>  	wmemcmp.c \
> @@ -394,7 +396,7 @@ wcscpy.def	wcscspn.def \
>  wcslcat.def	wcslcpy.def	wcslen.def	wcsncat.def \
>  wcsncmp.def	wcsncpy.def	wcsnlen.def	wcspbrk.def \
>  wcsrchr.def	wcsspn.def	wcsstr.def \
> -wcswidth.def	wcwidth.def	wmemchr.def \
> +wcswidth.def	wcsxfrm.def	wcwidth.def	wmemchr.def \
>  wmemcmp.def	wmemcpy.def	wmemmove.def	wmemset.def
>  
>  SUFFIXES = .def
> @@ -816,6 +818,12 @@ lib_a-wcswidth.o: wcswidth.c
>  lib_a-wcswidth.obj: wcswidth.c
>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcswidth.obj `if test -f 'wcswidth.c'; then $(CYGPATH_W) 'wcswidth.c'; else $(CYGPATH_W) '$(srcdir)/wcswidth.c'; fi`
>  
> +lib_a-wcsxfrm.o: wcsxfrm.c
> +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcsxfrm.o `test -f 'wcsxfrm.c' || echo '$(srcdir)/'`wcsxfrm.c
> +
> +lib_a-wcsxfrm.obj: wcsxfrm.c
> +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcsxfrm.obj `if test -f 'wcsxfrm.c'; then $(CYGPATH_W) 'wcsxfrm.c'; else $(CYGPATH_W) '$(srcdir)/wcsxfrm.c'; fi`
> +
>  lib_a-wcwidth.o: wcwidth.c
>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcwidth.o `test -f 'wcwidth.c' || echo '$(srcdir)/'`wcwidth.c
>  
> Index: libc/string/wcstrings.tex
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/string/wcstrings.tex,v
> retrieving revision 1.5
> diff -u -p -r1.5 wcstrings.tex
> --- libc/string/wcstrings.tex	28 Oct 2005 21:33:23 -0000	1.5
> +++ libc/string/wcstrings.tex	4 Jul 2007 10:55:26 -0000
> @@ -29,6 +29,7 @@ declarations are in @file{wchar.h}.
>  * wcsspn::      Find initial match in wide-character string
>  * wcsstr::      Find wide-character string segment
>  * wcswidth::    Number of column positions of a wide-character string
> +* wcsxfrm::     Locale-specific wide-character string transformation
>  * wcwidth::     Number of column positions of a wide-character code
>  @end menu
>  
> @@ -102,5 +103,8 @@ declarations are in @file{wchar.h}.
>  @include string/wcswidth.def
>  
>  @page
> +@include string/wcsxfrm.def
> +
> +@page
>  @include string/wcwidth.def
>  
> Index: libc/string/wcsxfrm.c
> ===================================================================
> RCS file: libc/string/wcsxfrm.c
> diff -N libc/string/wcsxfrm.c
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ libc/string/wcsxfrm.c	4 Jul 2007 10:55:26 -0000
> @@ -0,0 +1,52 @@
> +/*
> +FUNCTION
> +	<<wcsxfrm>>---locale-specific wide-character string transformation
> +	
> +INDEX
> +	wcsxfrm
> +
> +ANSI_SYNOPSIS
> +	#include <wchar.h>
> +	int wcsxfrm(wchar_t *<[stra]>, const wchar_t * <[strb]>, size_t <[n]>);
> +
> +TRAD_SYNOPSIS
> +	#include <wchar.h>
> +	size_t wcsxfrm(<[stra]>, <[strb]>, <[n]>)
> +	wchar_t *<[stra]>;
> +	wchar_t *<[strb]>;
> +	size_t   <[n]>
> +
> +DESCRIPTION
> +	<<wcsxfrm>> transforms the wide-character string pointed to by
> +	<[strb]> to the wide-character string pointed to by <[stra]>,
> +	Comparing two transformed wide strings with <<wcscmp>> should return
> +	the same result as comparing the original strings with <<wcscoll>>.
> +	No more than <[n]> wide characters are transformed, including the
> +	trailing null character.
> +
> +	If <[n]> is 0, <[stra]> may be a NULL pointer.
> +
> +	The current implementation of <<wcsxfrm>> simply uses <<wcslcpy>>
> +	and does not support any language-specific transformations.
> +
> +RETURNS
> +	<<wcsxfrm>> returns the length of the transformed wide character
> +	string.  if the return value is greater or equal to <[n]>, the
> +	content of <[stra]> is undefined.
> +
> +PORTABILITY
> +<<wcsxfrm>> is ISO/IEC 9899/AMD1:1995 (ISO C).
> +*/
> +
> +#include <_ansi.h>
> +#include <wchar.h>
> +
> +size_t
> +_DEFUN (wcsxfrm, (a, b, n),
> +	wchar_t *a _AND
> +	_CONST wchar_t *b _AND
> +	size_t n)
> +
> +{
> +  return wcslcpy (a, b, n);
> +}



More information about the Newlib mailing list