1 /* $NetBSD: src/lib/libc/citrus/citrus_none.c,v 1.12 2004/01/18 03:57:30 yamt Exp $ */
2 /* $DragonFly: src/lib/libc/citrus/citrus_none.c,v 1.3 2005/04/26 14:03:57 joerg Exp $ */
5 * Copyright (c)2002 Citrus Project,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/types.h>
40 #include "citrus_namespace.h"
41 #include "citrus_types.h"
42 #include "citrus_module.h"
43 #include "citrus_ctype.h"
44 #include "citrus_none.h"
45 #include "citrus_stdenc.h"
47 /* ---------------------------------------------------------------------- */
49 _CITRUS_CTYPE_DECLS(NONE);
50 _CITRUS_CTYPE_DEF_OPS(NONE);
53 /* ---------------------------------------------------------------------- */
57 _citrus_NONE_ctype_init(void ** __restrict cl, void * __restrict var __unused,
58 size_t lenvar __unused, size_t lenps __unused)
66 _citrus_NONE_ctype_uninit(void *cl __unused)
72 _citrus_NONE_ctype_get_mb_cur_max(void *cl __unused)
79 _citrus_NONE_ctype_mblen(void * __restrict cl __unused,
80 const char * __restrict s, size_t n,
81 int * __restrict nresult)
84 *nresult = 0; /* state independent */
91 *nresult = (*s == 0) ? 0 : 1;
97 _citrus_NONE_ctype_mbrlen(void * __restrict cl __unused,
98 const char * __restrict s, size_t n,
99 void * __restrict pspriv __unused,
100 size_t * __restrict nresult)
107 *nresult = (size_t)-2;
110 *nresult = (*s == 0) ? 0 : 1;
116 _citrus_NONE_ctype_mbrtowc(void * __restrict cl __unused,
117 wchar_t * __restrict pwc,
118 const char * __restrict s, size_t n,
119 void * __restrict pspriv __unused,
120 size_t * __restrict nresult)
127 *nresult = (size_t)-2;
132 *pwc = (wchar_t)(unsigned char) *s;
134 *nresult = *s == '\0' ? 0 : 1;
140 _citrus_NONE_ctype_mbsinit(void * __restrict cl __unused,
141 const void * __restrict pspriv __unused,
142 int * __restrict nresult)
144 *nresult = 1; /* always initial state */
150 _citrus_NONE_ctype_mbsrtowcs(void * __restrict cl __unused,
151 wchar_t * __restrict pwcs,
152 const char ** __restrict s, size_t n,
153 void * __restrict pspriv __unused,
154 size_t * __restrict nresult)
159 /* if pwcs is NULL, ignore n */
161 n = 1; /* arbitrary >0 value */
164 s0 = *s; /* to keep *s unchanged for now, use copy instead. */
167 *pwcs = (wchar_t)(unsigned char)*s0;
183 *nresult = (size_t)cnt;
189 _citrus_NONE_ctype_mbstowcs(void * __restrict cl, wchar_t * __restrict wcs,
190 const char * __restrict s, size_t n,
191 size_t * __restrict nresult)
193 const char *tmp_s = __DEQUALIFY(const char *, s);
195 return (_citrus_NONE_ctype_mbsrtowcs(cl, wcs, &tmp_s, n, NULL, nresult));
200 _citrus_NONE_ctype_mbtowc(void * __restrict cl __unused,
201 wchar_t * __restrict pwc,
202 const char * __restrict s, size_t n,
203 int * __restrict nresult)
207 *nresult = 0; /* state independent */
223 *nresult = *s == '\0' ? 0 : 1;
230 _citrus_NONE_ctype_wcrtomb(void * __restrict cl __unused,
231 char * __restrict s, wchar_t wc,
232 void * __restrict pspriv __unused,
233 size_t * __restrict nresult)
235 if ((wc&~0xFFU) != 0) {
236 *nresult = (size_t)-1;
249 _citrus_NONE_ctype_wcsrtombs(void * __restrict cl __unused,
251 const wchar_t ** __restrict pwcs, size_t n,
252 void * __restrict pspriv __unused,
253 size_t * __restrict nresult)
256 const wchar_t *pwcs0;
265 if ((*pwcs0 & ~0xFFU) != 0) {
266 *nresult = (size_t)-1;
273 if (*pwcs0 == L'\0') {
289 _citrus_NONE_ctype_wcstombs(void * __restrict cl, char * __restrict s,
290 const wchar_t * __restrict pwcs, size_t n,
291 size_t * __restrict nresult)
293 const wchar_t *tmp_pwcs = __DEQUALIFY(const wchar_t *, pwcs);
295 return (_citrus_NONE_ctype_wcsrtombs(cl, s, &tmp_pwcs, n, NULL, nresult));
299 _citrus_NONE_ctype_wctomb(void * __restrict cl, char * __restrict s,
300 wchar_t wc, int * __restrict nresult)
307 * initialize state here.
308 * (nothing to do for us.)
310 *nresult = 0; /* we're state independent */
314 ret = _citrus_NONE_ctype_wcrtomb(cl, s, wc, NULL, &nr);
322 _citrus_NONE_ctype_btowc(_citrus_ctype_rec_t * __restrict cc __unused,
323 int c, wint_t * __restrict wcresult)
325 if (c == EOF || c & ~0xFF)
328 *wcresult = (wint_t)c;
334 _citrus_NONE_ctype_wctob(_citrus_ctype_rec_t * __restrict cc __unused,
335 wint_t wc, int * __restrict cresult)
337 if (wc == WEOF || wc & ~0xFF)
344 /* ---------------------------------------------------------------------- */
346 _CITRUS_STDENC_DECLS(NONE);
347 _CITRUS_STDENC_DEF_OPS(NONE);
348 struct _citrus_stdenc_traits _citrus_NONE_stdenc_traits = {
349 0, /* et_state_size */
355 _citrus_NONE_stdenc_init(struct _citrus_stdenc * __restrict ce,
356 const void *var __unused, size_t lenvar __unused,
357 struct _citrus_stdenc_traits * __restrict et)
360 et->et_state_size = 0;
361 et->et_mb_cur_max = 1;
363 ce->ce_closure = NULL;
370 _citrus_NONE_stdenc_uninit(struct _citrus_stdenc *ce __unused)
376 _citrus_NONE_stdenc_init_state(struct _citrus_stdenc * __restrict ce __unused,
377 void * __restrict ps __unused)
384 _citrus_NONE_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce __unused,
385 _csid_t *csid, _index_t *idx,
386 const char **s, size_t n,
387 void *ps __unused, size_t *nresult)
390 _DIAGASSERT(csid != NULL && idx != NULL);
393 *nresult = (size_t)-2;
398 *idx = (_index_t)(unsigned char)*(*s)++;
399 *nresult = *idx == 0 ? 0 : 1;
406 _citrus_NONE_stdenc_cstomb(struct _citrus_stdenc * __restrict ce __unused,
408 _csid_t csid, _index_t idx,
409 void *ps __unused, size_t *nresult)
412 if (csid == _CITRUS_CSID_INVALID) {
417 *nresult = (size_t)-1;
420 if (csid != 0 || (idx&0xFF) != idx)
431 _citrus_NONE_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce __unused,
432 _wc_t * __restrict pwc,
433 const char ** __restrict s, size_t n,
434 void * __restrict pspriv __unused,
435 size_t * __restrict nresult)
442 *nresult = (size_t)-2;
447 *pwc = (_wc_t)(unsigned char) **s;
449 *nresult = *s == '\0' ? 0 : 1;
455 _citrus_NONE_stdenc_wctomb(struct _citrus_stdenc * __restrict ce __unused,
456 char * __restrict s, size_t n, _wc_t wc,
457 void * __restrict pspriv __unused,
458 size_t * __restrict nresult)
460 if ((wc&~0xFFU) != 0) {
461 *nresult = (size_t)-1;
465 *nresult = (size_t)-1;
478 _citrus_NONE_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce __unused,
479 char * __restrict s __unused,
481 void * __restrict pspriv __unused,
482 size_t * __restrict nresult)