Index: citrus/citrus_ctype.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/citrus/citrus_ctype.c,v retrieving revision 1.3 diff -u -r1.3 citrus_ctype.c --- citrus/citrus_ctype.c 26 Dec 2002 07:58:19 -0000 1.3 +++ citrus/citrus_ctype.c 1 Mar 2003 04:36:12 -0000 @@ -40,6 +40,7 @@ #include #include #include +#include #include "citrus_module.h" #include "citrus_ctype.h" #include "citrus_none.h" @@ -103,7 +104,9 @@ cc->cc_ops->co_wcrtomb == NULL || cc->cc_ops->co_wcsrtombs == NULL || cc->cc_ops->co_wcstombs == NULL || - cc->cc_ops->co_wctomb == NULL) + cc->cc_ops->co_wctomb == NULL || + cc->cc_ops->co_btowc == NULL || + cc->cc_ops->co_wctob == NULL) goto bad; /* init and get closure */ Index: citrus/citrus_ctype.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/citrus/citrus_ctype.h,v retrieving revision 1.1 diff -u -r1.1 citrus_ctype.h --- citrus/citrus_ctype.h 17 Mar 2002 22:14:19 -0000 1.1 +++ citrus/citrus_ctype.h 28 Feb 2003 20:01:45 -0000 @@ -149,6 +149,22 @@ return (*cc->cc_ops->co_wctomb)(cc->cc_closure, s, wc, nresult); } +static __inline int +_citrus_ctype_btowc(_citrus_ctype_t cc, int c, wint_t *nresult) +{ + + _DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_btowc && nresult); + return (*cc->cc_ops->co_btowc)(cc->cc_closure, c, nresult); +} + +static __inline int +_citrus_ctype_wctob(_citrus_ctype_t cc, wint_t c, int *nresult) +{ + + _DIAGASSERT(cc && cc->cc_ops && cc->cc_ops->co_wctob && nresult); + return (*cc->cc_ops->co_wctob)(cc->cc_closure, c, nresult); +} + extern _citrus_ctype_rec_t _citrus_ctype_default; #endif Index: citrus/citrus_ctype_local.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/citrus/citrus_ctype_local.h,v retrieving revision 1.1 diff -u -r1.1 citrus_ctype_local.h --- citrus/citrus_ctype_local.h 17 Mar 2002 22:14:19 -0000 1.1 +++ citrus/citrus_ctype_local.h 1 Mar 2003 04:32:26 -0000 @@ -83,7 +83,11 @@ size_t, size_t * __restrict); \ static int _citrus_##_e_##_ctype_wctomb(void * __restrict, \ char * __restrict, \ - wchar_t, int * __restrict) + wchar_t, int * __restrict); \ +static int _citrus_##_e_##_ctype_btowc(void * __restrict, \ + int, wint_t * __restrict); \ +static int _citrus_##_e_##_ctype_wctob(void * __restrict, \ + wint_t, int * __restrict) #define _CITRUS_CTYPE_DEF_OPS(_e_) \ _citrus_ctype_ops_rec_t _citrus_##_e_##_ctype_ops = { \ @@ -101,7 +105,9 @@ /* co_wcrtomb */ &_citrus_##_e_##_ctype_wcrtomb, \ /* co_wcsrtombs */ &_citrus_##_e_##_ctype_wcsrtombs, \ /* co_wcstombs */ &_citrus_##_e_##_ctype_wcstombs, \ - /* co_wctomb */ &_citrus_##_e_##_ctype_wctomb \ + /* co_wctomb */ &_citrus_##_e_##_ctype_wctomb, \ + /* co_btowc */ &_citrus_##_e_##_ctype_btowc, \ + /* co_wctob */ &_citrus_##_e_##_ctype_wctob \ } typedef int (*_citrus_ctype_init_t) @@ -139,6 +145,10 @@ size_t, size_t * __restrict); typedef int (*_citrus_ctype_wctomb_t) (void * __restrict, char * __restrict, wchar_t, int * __restrict); +typedef int (*_citrus_ctype_btowc_t) + (void * __restrict, int, wint_t * __restrict); +typedef int (*_citrus_ctype_wctob_t) + (void * __restrict, wint_t, int * __restrict); typedef struct _citrus_ctype_ops { u_int32_t co_abi_version; @@ -156,6 +166,8 @@ _citrus_ctype_wcsrtombs_t co_wcsrtombs; _citrus_ctype_wcstombs_t co_wcstombs; _citrus_ctype_wctomb_t co_wctomb; + _citrus_ctype_btowc_t co_btowc; + _citrus_ctype_wctob_t co_wctob; } _citrus_ctype_ops_rec_t; #define _CITRUS_CTYPE_ABI_VERSION 1 Index: citrus/citrus_ctype_template.h =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/citrus/citrus_ctype_template.h,v retrieving revision 1.20 diff -u -r1.20 citrus_ctype_template.h --- citrus/citrus_ctype_template.h 1 Jan 2003 15:57:12 -0000 1.20 +++ citrus/citrus_ctype_template.h 3 Mar 2003 07:54:38 -0000 @@ -658,3 +658,59 @@ return 0; } + +static int +_FUNCNAME(ctype_btowc)(void * __restrict cl, + int c, wint_t * __restrict nresult) +{ + _ENCODING_STATE state; + _ENCODING_INFO *ei; + char *s; + wchar_t wc; + size_t nr; + int err; + + _DIAGASSERT(cl != NULL); + + if (c == EOF) { + *nresult = WEOF; + return 0; + } + ei = _CEI_TO_EI(_TO_CEI(cl)); + _FUNCNAME(init_state)(ei, &state); + s = (char *)&c; + err = _FUNCNAME(mbrtowc_priv)(ei, &wc, (const char **)&s, 1, + &state, &nr); + if (!err && (nr == 0 || nr == 1)) + *nresult = wc; + else + *nresult = WEOF; + return 0; +} + +static int +_FUNCNAME(ctype_wctob)(void * __restrict cl, + wint_t c, int * __restrict nresult) +{ + _ENCODING_STATE state; + _ENCODING_INFO *ei; + char buf[MB_LEN_MAX]; + size_t nr; + int err; + + _DIAGASSERT(cl != NULL); + + if (c == WEOF) { + *nresult = WEOF; + return 0; + } + ei = _CEI_TO_EI(_TO_CEI(cl)); + _FUNCNAME(init_state)(ei, &state); + err = _FUNCNAME(wcrtomb_priv)(ei, buf, _ENCODING_MB_CUR_MAX(ei), + (wchar_t)c, &state, &nr); + if (!err && nr == 1) + *nresult = buf[0]; + else + *nresult = EOF; + return 0; +} Index: citrus/citrus_none.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/citrus/citrus_none.c,v retrieving revision 1.7 diff -u -r1.7 citrus_none.c --- citrus/citrus_none.c 1 Jan 2003 14:34:27 -0000 1.7 +++ citrus/citrus_none.c 3 Mar 2003 07:48:55 -0000 @@ -305,3 +305,27 @@ return (ret); } + +static int +/*ARGSUSED*/ +_citrus_NONE_ctype_btowc(void * __restrict cl, + int c, wint_t * __restrict nresult) +{ + if (c == EOF || c & ~0xFF) + *nresult = WEOF; + else + *nresult = (wint_t)c; + return (0); +} + +static int +/*ARGSUSED*/ +_citrus_NONE_ctype_wctob(void * __restrict cl, + wint_t c, int * __restrict nresult) +{ + if (c == WEOF || c & ~0xFF) + *nresult = EOF; + else + *nresult = (int)c; + return (0); +} Index: locale/Makefile.inc =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/Makefile.inc,v retrieving revision 1.39 diff -u -r1.39 Makefile.inc --- locale/Makefile.inc 18 Mar 2002 06:00:26 -0000 1.39 +++ locale/Makefile.inc 1 Mar 2003 06:03:29 -0000 @@ -33,7 +33,7 @@ MAN+= iswalnum.3 towlower.3 mblen.3 mbrlen.3 mbrtowc.3 mbsinit.3 \ mbsrtowcs.3 mbstowcs.3 mbtowc.3 wcrtomb.3 wcsrtombs.3 wcstombs.3 \ wctomb.3 - +MAN+= btowc.3 MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswblank.3 \ iswalnum.3 iswcntrl.3 iswalnum.3 iswdigit.3 \ @@ -42,3 +42,4 @@ iswalnum.3 iswspace.3 iswalnum.3 iswupper.3 \ iswalnum.3 iswxdigit.3 MLINKS+=towlower.3 towupper.3 +MLINKS+=btowc.3 wctob.3 Index: locale/btowc.3 =================================================================== RCS file: locale/btowc.3 diff -N locale/btowc.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ locale/btowc.3 1 Mar 2003 06:07:27 -0000 @@ -0,0 +1,73 @@ +.\" Copyright (c) 2002 Tim J. Robbins +.\" All rights reserved. +.\" +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD$ +.\" $NetBSD$ +.\" +.Dd August 3, 2002 +.Dt BTOWC 3 +.Os +.Sh NAME +.Nm btowc , +.Nm wctob +.Nd "convert between wide and single-byte characters" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In wchar.h +.Ft wint_t +.Fn btowc "int c" +.Ft int +.Fn wctob "wint_t c" +.Sh DESCRIPTION +The +.Fn btowc +function converts a single-byte character into a corresponding wide character. +If the character is +.Dv EOF +or not valid in the initial shift state, +.Fn btowc +returns +.Dv WEOF . +.Pp +The +.Fn wctob +function converts a wide character into a corresponding single-byte character. +If the wide character is +.Dv WEOF +or not able to be represented as a single byte in the initial shift state, +.Fn wctob +returns +.Dv WEOF . +.Sh SEE ALSO +.Xr mbrtowc 3 , +.Xr multibyte 3 , +.Xr wcrtomb 3 +.Sh STANDARDS +The +.Fn btowc +and +.Fn wctob +functions conform to +.St -p1003.1-2001 . Index: locale/multibyte_c90.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/multibyte_c90.c,v retrieving revision 1.3 diff -u -r1.3 multibyte_c90.c --- locale/multibyte_c90.c 26 Mar 2002 06:10:27 -0000 1.3 +++ locale/multibyte_c90.c 3 Mar 2003 09:14:03 -0000 @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,32 @@ int err0; err0 = _citrus_ctype_wctomb(_to_cur_ctype(), s, wc, &ret); + if (err0) + errno = err0; + + return ret; +} + +wint_t +btowc(int c) +{ + wint_t ret; + int err0; + + err0 = _citrus_ctype_btowc(_to_cur_ctype(), c, &ret); + if (err0) + errno = err0; + + return ret; +} + +int +wctob(wint_t c) +{ + int ret; + int err0; + + err0 = _citrus_ctype_wctob(_to_cur_ctype(), c, &ret); if (err0) errno = err0; Index: locale/multibyte_sb.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/multibyte_sb.c,v retrieving revision 1.2 diff -u -r1.2 multibyte_sb.c --- locale/multibyte_sb.c 3 Jan 2001 15:23:26 -0000 1.2 +++ locale/multibyte_sb.c 3 Mar 2003 07:47:40 -0000 @@ -249,3 +249,21 @@ return wcsrtombs(s, &pwcs, n, NULL); } + +wint_t +btowc(c) + int c; +{ + if (c == EOF || c & ~0xFF) + return WEOF; + return (wint_t)c; +} + +int +wctob(c) + wint_t c; +{ + if (c == WEOF || c & ~0xFF) + return EOF; + return (int)c; +} Index: locale/rune.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/rune.c,v retrieving revision 1.17 diff -u -r1.17 rune.c --- locale/rune.c 17 Nov 2002 20:40:59 -0000 1.17 +++ locale/rune.c 1 Mar 2003 04:46:36 -0000 @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include Index: locale/runetable.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/locale/runetable.c,v retrieving revision 1.9 diff -u -r1.9 runetable.c --- locale/runetable.c 3 Aug 2002 11:10:51 -0000 1.9 +++ locale/runetable.c 1 Mar 2003 04:47:34 -0000 @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include "rune.h" Index: string/Makefile.inc =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/string/Makefile.inc,v retrieving revision 1.52 diff -u -r1.52 Makefile.inc --- string/Makefile.inc 17 Apr 2002 16:23:09 -0000 1.52 +++ string/Makefile.inc 1 Mar 2003 06:35:13 -0000 @@ -13,6 +13,7 @@ wcslen.c wcsncat.c \ wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c wcsstr.c wcswidth.c \ wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c +SRCS+= wcswcs.c wcstok.c # namespace protection wrappers SRCS+= _strlcat.c _strlcpy.c @@ -53,6 +54,7 @@ string.3 strlcpy.3 strlen.3 strmode.3 strpbrk.3 strrchr.3 strsep.3 \ strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 \ wmemchr.3 +MAN+= wcstok.3 MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3 MLINKS+=strcasecmp.3 strncasecmp.3 Index: string/wcsstr.c =================================================================== RCS file: /home/cvs/NetBSD/src/lib/libc/string/wcsstr.c,v retrieving revision 1.2 diff -u -r1.2 wcsstr.c --- string/wcsstr.c 3 Jan 2001 14:29:37 -0000 1.2 +++ string/wcsstr.c 1 Mar 2003 06:42:16 -0000 @@ -37,7 +37,11 @@ #include wchar_t * +#ifdef WCSWCS +wcswcs(big, little) +#else wcsstr(big, little) +#endif const wchar_t *big; const wchar_t *little; { Index: string/wcstok.3 =================================================================== RCS file: string/wcstok.3 diff -N string/wcstok.3 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ string/wcstok.3 1 Mar 2003 06:10:17 -0000 @@ -0,0 +1,133 @@ +.\" Copyright (c) 1998 Softweyr LLC. All rights reserved. +.\" +.\" strtok_r, from Berkeley strtok +.\" Oct 13, 1998 by Wes Peters +.\" +.\" Copyright (c) 1988, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the American National Standards Committee X3, on Information +.\" Processing Systems. +.\" +.\" 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 +.\" notices, this list of conditions and the following disclaimer. +.\" +.\" 2. Redistributions in binary form must reproduce the above +.\" copyright notices, this list of conditions and the following +.\" disclaimer in the documentation and/or other materials provided +.\" with the distribution. +.\" +.\" 3. All advertising materials mentioning features or use of this +.\" software must display the following acknowledgement: +.\" +.\" This product includes software developed by Softweyr LLC, the +.\" University of California, Berkeley, and its contributors. +.\" +.\" 4. Neither the name of Softweyr LLC, the University 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 SOFTWEYR LLC, THE REGENTS 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 SOFTWEYR LLC, THE REGENTS, 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. +.\" +.\" $NetBSD$ +.\" +.Dd October 3, 2002 +.Dt WCSTOK 3 +.Os +.Sh NAME +.Nm wcstok +.Nd split wide-character string into tokens +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In wchar.h +.Ft wchar_t * +.Fn wcstok "wchar_t * restrict str" "const wchar_t * restrict sep" "wchar_t ** restrict last" +.Sh DESCRIPTION +The +.Fn wcstok +function +is used to isolate sequential tokens in a null-terminated wide character +string, +.Fa str . +These tokens are separated in the string by at least one of the +characters in +.Fa sep . +The first time that +.Fn wcstok +is called, +.Fa str +should be specified; subsequent calls, wishing to obtain further tokens +from the same string, should pass a null pointer instead. +The separator string, +.Fa sep , +must be supplied each time, and may change between calls. +The context pointer +.Fa last +must be provided on each call. +.Pp +The +.Fn wcstok +function is the wide character counterpart of the +.Fn strtok_r +function. +.Sh RETURN VALUES +The +.Fn wcstok +function +returns a pointer to the beginning of each subsequent token in the string, +after replacing the token itself with a null wide character (L'\e0'). +When no more tokens remain, a null pointer is returned. +.Sh EXAMPLES +The following code fragment splits a wide character string on +.Tn ASCII +space, tab and newline characters and writes the tokens to +standard output: +.Bd -literal -offset indent +const wchar_t *seps = L" \et\en"; +wchar_t *last, *tok, text[] = L" \enone\ettwo\et\etthree \en"; + +for (tok = wcstok(text, seps, &last); tok != NULL; + tok = wcstok(NULL, seps, &last)) + wprintf(L"%ls\en", tok); +.Ed +.Sh COMPATIBILITY +Some early implementations of +.Fn wcstok +omit the +context pointer argument, +.Fa last , +and maintain state across calls in a static variable like +.Fn strtok +does. +.Sh SEE ALSO +.Xr strtok 3 , +.Xr wcschr 3 , +.Xr wcscspn 3 , +.Xr wcspbrk 3 , +.Xr wcsrchr 3 , +.Xr wcsspn 3 +.Sh STANDARDS +The +.Fn wcstok +function +conforms to +.St -isoC99 . Index: string/wcstok.c =================================================================== RCS file: string/wcstok.c diff -N string/wcstok.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ string/wcstok.c 26 Feb 2003 13:41:42 -0000 @@ -0,0 +1,101 @@ +/* $NetBSD$ */ + +/*- + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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 + * notices, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notices, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Softweyr LLC, the + * University of California, Berkeley, and its contributors. + * 4. Neither the name of the University 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 SOFTWEYR LLC, THE REGENTS 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 SOFTWEYR LLC, THE + * REGENTS, 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD$"); +#endif + +#include +#include + +wchar_t * +wcstok(s, delim, last) + wchar_t * __restrict s; + const wchar_t * __restrict delim; + wchar_t ** __restrict last; +{ + const wchar_t *spanp; + wchar_t c, sc; + wchar_t *tok; + + /* s may be NULL */ + _DIAGASSERT(delin != NULL); + _DIAGASSERT(last != NULL); + + if (s == NULL && (s = *last) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = delim; (sc = *spanp++) != L'\0';) { + if (c == sc) + goto cont; + } + + if (c == L'\0') { /* no non-delimiter characters */ + *last = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == L'\0') + s = NULL; + else + s[-1] = L'\0'; + *last = s; + return (tok); + } + } while (sc != L'\0'); + } + /* NOTREACHED */ +} Index: string/wcswcs.c =================================================================== RCS file: string/wcswcs.c diff -N string/wcswcs.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ string/wcswcs.c 1 Mar 2003 06:30:07 -0000 @@ -0,0 +1,4 @@ +/* $NetBSD$ */ + +#define WCSWCS +#include "wcsstr.c"