1 /* $NetBSD: citrus_none.c,v 1.17 2005/12/02 11:14:20 yamt Exp $ */
4 * Copyright (c)2002 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/types.h>
39 #include "citrus_namespace.h"
40 #include "citrus_types.h"
41 #include "citrus_module.h"
42 #include "citrus_ctype.h"
43 #include "citrus_none.h"
44 #include "citrus_stdenc.h"
46 /* ---------------------------------------------------------------------- */
48 _citrus_NONE_ctype_getops(_citrus_ctype_ops_rec_t *, size_t, uint32_t);
50 _citrus_NONE_stdenc_getops(struct _citrus_stdenc_ops *, size_t, uint32_t);
52 _CITRUS_CTYPE_DECLS(NONE);
53 _CITRUS_CTYPE_DEF_OPS(NONE);
56 /* ---------------------------------------------------------------------- */
59 _citrus_NONE_ctype_getops(_citrus_ctype_ops_rec_t *ops, size_t lenops,
60 uint32_t expected_version)
62 if (expected_version<_CITRUS_CTYPE_ABI_VERSION || lenops<sizeof(*ops))
65 memcpy(ops, &_citrus_NONE_ctype_ops, sizeof(_citrus_NONE_ctype_ops));
71 _citrus_NONE_stdenc_getops(struct _citrus_stdenc_ops *ops, size_t lenops,
72 uint32_t expected_version)
74 if (expected_version<_CITRUS_STDENC_ABI_VERSION || lenops<sizeof(*ops))
77 memcpy(ops, &_citrus_NONE_stdenc_ops, sizeof(_citrus_NONE_stdenc_ops));
84 _citrus_NONE_ctype_init(void ** __restrict cl, void * __restrict var __unused,
85 size_t lenvar __unused, size_t lenps __unused)
93 _citrus_NONE_ctype_uninit(void *cl __unused)
99 _citrus_NONE_ctype_get_mb_cur_max(void *cl __unused)
106 _citrus_NONE_ctype_mblen(void * __restrict cl __unused,
107 const char * __restrict s, size_t n,
108 int * __restrict nresult)
111 *nresult = 0; /* state independent */
118 *nresult = (*s == 0) ? 0 : 1;
124 _citrus_NONE_ctype_mbrlen(void * __restrict cl __unused,
125 const char * __restrict s, size_t n,
126 void * __restrict pspriv __unused,
127 size_t * __restrict nresult)
134 *nresult = (size_t)-2;
137 *nresult = (*s == 0) ? 0 : 1;
143 _citrus_NONE_ctype_mbrtowc(void * __restrict cl __unused,
144 wchar_t * __restrict pwc,
145 const char * __restrict s, size_t n,
146 void * __restrict pspriv __unused,
147 size_t * __restrict nresult)
154 *nresult = (size_t)-2;
159 *pwc = (wchar_t)(unsigned char) *s;
161 *nresult = *s == '\0' ? 0 : 1;
167 _citrus_NONE_ctype_mbsinit(void * __restrict cl __unused,
168 const void * __restrict pspriv __unused,
169 int * __restrict nresult)
171 *nresult = 1; /* always initial state */
177 _citrus_NONE_ctype_mbsrtowcs(void * __restrict cl __unused,
178 wchar_t * __restrict pwcs,
179 const char ** __restrict s, size_t n,
180 void * __restrict pspriv __unused,
181 size_t * __restrict nresult)
186 /* if pwcs is NULL, ignore n */
188 n = 1; /* arbitrary >0 value */
191 s0 = *s; /* to keep *s unchanged for now, use copy instead. */
194 *pwcs = (wchar_t)(unsigned char)*s0;
210 *nresult = (size_t)cnt;
216 _citrus_NONE_ctype_mbstowcs(void * __restrict cl, wchar_t * __restrict wcs,
217 const char * __restrict s, size_t n,
218 size_t * __restrict nresult)
220 const char *tmp_s = __DEQUALIFY(const char *, s);
222 return (_citrus_NONE_ctype_mbsrtowcs(cl, wcs, &tmp_s, n, NULL, nresult));
227 _citrus_NONE_ctype_mbtowc(void * __restrict cl __unused,
228 wchar_t * __restrict pwc,
229 const char * __restrict s, size_t n,
230 int * __restrict nresult)
234 *nresult = 0; /* state independent */
249 *pwc = (wchar_t)(unsigned char)*s;
250 *nresult = *s == '\0' ? 0 : 1;
257 _citrus_NONE_ctype_wcrtomb(void * __restrict cl __unused,
258 char * __restrict s, wchar_t wc,
259 void * __restrict pspriv __unused,
260 size_t * __restrict nresult)
262 if ((wc&~0xFFU) != 0) {
263 *nresult = (size_t)-1;
276 _citrus_NONE_ctype_wcsrtombs(void * __restrict cl __unused,
278 const wchar_t ** __restrict pwcs, size_t n,
279 void * __restrict pspriv __unused,
280 size_t * __restrict nresult)
283 const wchar_t *pwcs0;
292 if ((*pwcs0 & ~0xFFU) != 0) {
293 *nresult = (size_t)-1;
300 if (*pwcs0 == L'\0') {
316 _citrus_NONE_ctype_wcstombs(void * __restrict cl, char * __restrict s,
317 const wchar_t * __restrict pwcs, size_t n,
318 size_t * __restrict nresult)
320 const wchar_t *tmp_pwcs = __DEQUALIFY(const wchar_t *, pwcs);
322 return (_citrus_NONE_ctype_wcsrtombs(cl, s, &tmp_pwcs, n, NULL, nresult));
326 _citrus_NONE_ctype_wctomb(void * __restrict cl, char * __restrict s,
327 wchar_t wc, int * __restrict nresult)
334 * initialize state here.
335 * (nothing to do for us.)
337 *nresult = 0; /* we're state independent */
341 ret = _citrus_NONE_ctype_wcrtomb(cl, s, wc, NULL, &nr);
349 _citrus_NONE_ctype_btowc(_citrus_ctype_rec_t * __restrict cc __unused,
350 int c, wint_t * __restrict wcresult)
352 if (c == EOF || c & ~0xFF)
355 *wcresult = (wint_t)c;
361 _citrus_NONE_ctype_wctob(_citrus_ctype_rec_t * __restrict cc __unused,
362 wint_t wc, int * __restrict cresult)
364 if (wc == WEOF || wc & ~0xFF)
371 /* ---------------------------------------------------------------------- */
373 _CITRUS_STDENC_DECLS(NONE);
374 _CITRUS_STDENC_DEF_OPS(NONE);
375 struct _citrus_stdenc_traits _citrus_NONE_stdenc_traits = {
376 0, /* et_state_size */
382 _citrus_NONE_stdenc_init(struct _citrus_stdenc * __restrict ce,
383 const void *var __unused, size_t lenvar __unused,
384 struct _citrus_stdenc_traits * __restrict et)
387 et->et_state_size = 0;
388 et->et_mb_cur_max = 1;
390 ce->ce_closure = NULL;
397 _citrus_NONE_stdenc_uninit(struct _citrus_stdenc *ce __unused)
403 _citrus_NONE_stdenc_init_state(struct _citrus_stdenc * __restrict ce __unused,
404 void * __restrict ps __unused)
411 _citrus_NONE_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce __unused,
412 _csid_t *csid, _index_t *idx,
413 const char **s, size_t n,
414 void *ps __unused, size_t *nresult)
417 _DIAGASSERT(csid != NULL && idx != NULL);
420 *nresult = (size_t)-2;
425 *idx = (_index_t)(unsigned char)*(*s)++;
426 *nresult = *idx == 0 ? 0 : 1;
433 _citrus_NONE_stdenc_cstomb(struct _citrus_stdenc * __restrict ce __unused,
435 _csid_t csid, _index_t idx,
436 void *ps __unused, size_t *nresult)
439 if (csid == _CITRUS_CSID_INVALID) {
444 *nresult = (size_t)-1;
447 if (csid != 0 || (idx&0xFF) != idx)
458 _citrus_NONE_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce __unused,
459 _wc_t * __restrict pwc,
460 const char ** __restrict s, size_t n,
461 void * __restrict pspriv __unused,
462 size_t * __restrict nresult)
469 *nresult = (size_t)-2;
474 *pwc = (_wc_t)(unsigned char) **s;
476 *nresult = *s == '\0' ? 0 : 1;
482 _citrus_NONE_stdenc_wctomb(struct _citrus_stdenc * __restrict ce __unused,
483 char * __restrict s, size_t n, _wc_t wc,
484 void * __restrict pspriv __unused,
485 size_t * __restrict nresult)
487 if ((wc&~0xFFU) != 0) {
488 *nresult = (size_t)-1;
492 *nresult = (size_t)-1;
505 _citrus_NONE_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce __unused,
506 char * __restrict s __unused,
508 void * __restrict pspriv __unused,
509 size_t * __restrict nresult)
519 _citrus_NONE_stdenc_get_state_desc(struct _stdenc * __restrict ce,
520 void * __restrict ps,
522 struct _stdenc_state_desc * __restrict d)
527 case _STDENC_SDID_GENERIC:
528 d->u.generic.state = _STDENC_SDGEN_INITIAL;