diff --git a/include/wchar.h b/include/wchar.h index 805521fa2c..7fd721d7ef 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -48,7 +48,7 @@ #include /* REVISIT: Moving the idempotence to this location resolves a circular - * dependency problem with stdlib.h which gets included indirectory and + * dependency problem with stdlib.h which gets included indirectly and * needs wchar_t. */ diff --git a/libc/libc.csv b/libc/libc.csv index c150080de9..e54fa5a7df 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -60,6 +60,19 @@ "inet_ntoa","arpa/inet.h","defined(CONFIG_NET_IPv4) && defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","struct in_addr" "inet_ntop","arpa/inet.h","","FAR const char","int","FAR const void *","FAR char *","socklen_t" "inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *" +"iswalnum","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswalpha","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswblank","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswcntrl","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswctype","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t", "wctype_t" +"iswdigit","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswgraph","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswlower","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswprint","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswpunct","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswspace","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswupper","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" +"iswxdigit","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t" "labs","stdlib.h","","long int","long int" "lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int" "lio_listio","aio.h","defined(CONFIG_FS_AIO)","int","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR struct sigevent *" @@ -166,6 +179,8 @@ "tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" "telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR *" "time","time.h","","time_t","time_t *" +"towlower","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","wint_t" +"towupper","wchar.h","defined(CONFIG_LIBC_WCHAR)","wint_t","wint_t" "ub16divub16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t","ub16_t" "ub16mulub16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t","ub16_t" "ub16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t" @@ -181,6 +196,7 @@ "wcrtomb","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","wchar_t","mbstate_t *" "wcscmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *" "wcscoll","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *" +"wcsftime","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t", "FAR wchar_t *", "size_t", "FAR const wchar_t *", "FAR const struct tm *" "wcslcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *","FAR const wchar_t *","size_t" "wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *" "wcsxfrm","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","FAR const wchar_t *","size_t" diff --git a/libc/wchar/Make.defs b/libc/wchar/Make.defs index f6788f592d..dbede3342a 100644 --- a/libc/wchar/Make.defs +++ b/libc/wchar/Make.defs @@ -37,9 +37,10 @@ ifeq ($(CONFIG_LIBC_WCHAR),y) # Add the internal C files to the build -CSRCS += lib_wcscmp.c lib_wcslen.c lib_wmemchr.c lib_wmemcmp.c lib_wmemcpy.c -CSRCS += lib_wmemmove.c lib_wmemset.c lib_btowc.c lib_mbrtowc.c lib_wctob.c -CSRCS +=lib_wcslcpy.c lib_wcsxfrm.c lib_wcrtomb.c +CSRCS += lib_wcscmp.c lib_wcslen.c lib_wmemchr.c lib_wmemcmp.c +CSRCS += lib_wmemcpy.c lib_wmemmove.c lib_wmemset.c lib_btowc.c +CSRCS += lib_mbrtowc.c lib_wctob.c lib_wcslcpy.c lib_wcsxfrm.c +CSRCS += lib_wcrtomb.c lib_wcsftime.c lib_wcscoll.c # Add the wchar directory to the build diff --git a/libc/wchar/lib_wcsftime.c b/libc/wchar/lib_wcsftime.c new file mode 100644 index 0000000000..70d3b55237 --- /dev/null +++ b/libc/wchar/lib_wcsftime.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * libc/wchar/lib_wcsftime.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_LIBC_WCHAR +size_t wcsftime(FAR wchar_t *s, size_t maxsize, FAR const wchar_t *format, + FAR const struct tm *tim_p) +{ + /* REVISIT: We can't just use the wide character string... We need to + * convert it to a normal C string first. + */ + + return strftime((FAR char *)s, maxsize, (FAR char *)format, tim_p); +} +#endif diff --git a/libc/wchar/lib_wcsxfrm.c b/libc/wchar/lib_wcsxfrm.c index 303a540b32..b083eaf013 100644 --- a/libc/wchar/lib_wcsxfrm.c +++ b/libc/wchar/lib_wcsxfrm.c @@ -7,6 +7,7 @@ * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright diff --git a/libc/wctype/Make.defs b/libc/wctype/Make.defs index c48e619b64..aa94e9716b 100644 --- a/libc/wctype/Make.defs +++ b/libc/wctype/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_LIBC_WCHAR),y) # Add the internal C files to the build -CSRCS += lib_wctype.c +CSRCS += lib_wctype.c lib_iswctype.c lib_towlower.c lib_towupper.c # Add the wctype directory to the build @@ -45,4 +45,3 @@ DEPPATH += --dep-path wctype VPATH += :wctype endif - diff --git a/libc/wctype/lib_iswctype.c b/libc/wctype/lib_iswctype.c new file mode 100644 index 0000000000..8c3185250d --- /dev/null +++ b/libc/wctype/lib_iswctype.c @@ -0,0 +1,161 @@ +/**************************************************************************** + * libc/wctype/lib_iswctype.c + * + * Copyright (c) 2002 Red Hat Incorporated. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * The name of Red Hat Incorporated may not be used to endorse + * or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int iswalnum(wint_t c) +{ + return (iswalpha(c) || iswdigit(c)); +} + +int iswalpha(wint_t c) +{ + return (c < (wint_t)0x100 ? isalpha(c) : 0); +} + +int iswblank(wint_t c) +{ + return (c < (wint_t)0x100 ? isblank(c) : 0); +} + +int iswcntrl(wint_t c) +{ + return (c < (wint_t)0x100 ? iscntrl(c) : 0); +} + +int iswdigit(wint_t c) +{ + return (c >= (wint_t)'0' && c <= (wint_t)'9'); +} + +int iswgraph(wint_t c) +{ + return (iswprint(c) && !iswspace(c)); +} + +int iswlower(wint_t c) +{ + return (towupper(c) != c); +} + +int iswprint(wint_t c) +{ + return (c < (wint_t) 0x100 ? isprint(c) : 0); +} + +int iswpunct(wint_t c) +{ + return (!iswalnum(c) && iswgraph(c)); +} + +int iswspace(wint_t c) +{ + return (c < 0x100 ? isspace(c) : 0); +} + +int iswupper(wint_t c) +{ + return (towlower(c) != c); +} + +int iswxdigit(wint_t c) +{ + return ((c >= (wint_t)'0' && c <= (wint_t)'9') || + (c >= (wint_t)'a' && c <= (wint_t)'f') || + (c >= (wint_t)'A' && c <= (wint_t)'F')); +} + +int iswctype(wint_t c, wctype_t desc) +{ + switch (desc) + { + case WC_ALNUM: + return iswalnum(c); + + case WC_ALPHA: + return iswalpha(c); + + case WC_BLANK: + return iswblank(c); + + case WC_CNTRL: + return iswcntrl(c); + + case WC_DIGIT: + return iswdigit(c); + + case WC_GRAPH: + return iswgraph(c); + + case WC_LOWER: + return iswlower(c); + + case WC_PRINT: + return iswprint(c); + + case WC_PUNCT: + return iswpunct(c); + + case WC_SPACE: + return iswspace(c); + + case WC_UPPER: + return iswupper(c); + + case WC_XDIGIT: + return iswxdigit(c); + + default: + return 0; /* eliminate warning */ + } + + /* Otherwise unknown */ + + return 0; +} +#endif diff --git a/libc/wctype/lib_towlower.c b/libc/wctype/lib_towlower.c new file mode 100644 index 0000000000..0da9c37748 --- /dev/null +++ b/libc/wctype/lib_towlower.c @@ -0,0 +1,66 @@ +/**************************************************************************** + * libc/wchar/lib_towlower.c + * + * Copyright (c) 2002 Red Hat Incorporated. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * The name of Red Hat Incorporated may not be used to endorse + * or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: towlower + * + * Description: + * The towlower() function is the wide-character equivalent of the + * tolower() function. If c is an uppercase wide character, and there + * exists a lowercase equivalent in the current locale, it returns the + * lowercase equivalent of c. This current code don't use locale. + * + ****************************************************************************/ + +wint_t towlower(wint_t c) +{ + return (c < (wint_t)0x00ff ? (wint_t)tolower((int)c) : c); +} +#endif diff --git a/libc/wctype/lib_towupper.c b/libc/wctype/lib_towupper.c new file mode 100644 index 0000000000..ee86a56dad --- /dev/null +++ b/libc/wctype/lib_towupper.c @@ -0,0 +1,66 @@ +/**************************************************************************** + * libc/wchar/lib_towupper.c + * + * Copyright (c) 2002 Red Hat Incorporated. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * The name of Red Hat Incorporated may not be used to endorse + * or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: towupper + * + * Description: + * The towupper() function is the wide-character equivalent of the + * toupper() function. If c is an lowercase wide character, and there + * exists a uppercase equivalent in the current locale, it returns the + * uppercase equivalent of c. This current code don't use locale. + * + ****************************************************************************/ + +wint_t towupper(wint_t c) +{ + return (c < (wint_t)0x00ff ? (wint_t)toupper((int)c) : c); +} +#endif diff --git a/libc/wctype/lib_wctype.c b/libc/wctype/lib_wctype.c index 8ba10f06f7..99df9453ad 100644 --- a/libc/wctype/lib_wctype.c +++ b/libc/wctype/lib_wctype.c @@ -35,6 +35,8 @@ * Included Files ****************************************************************************/ +#include + #include #include #include