1 /* $NetBSD: citrus_none.c,v 1.17 2005/12/02 11:14:20 yamt Exp $ */
2 /* $DragonFly: src/lib/libc/citrus/citrus_none.c,v 1.5 2008/04/10 10:21:01 hasso 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_NONE_ctype_getops(_citrus_ctype_ops_rec_t
*, size_t, uint32_t);
51 _citrus_NONE_stdenc_getops(struct _citrus_stdenc_ops
*, size_t, uint32_t);
53 _CITRUS_CTYPE_DECLS(NONE
);
54 _CITRUS_CTYPE_DEF_OPS(NONE
);
57 /* ---------------------------------------------------------------------- */
60 _citrus_NONE_ctype_getops(_citrus_ctype_ops_rec_t
*ops
, size_t lenops
,
61 uint32_t expected_version
)
63 if (expected_version
<_CITRUS_CTYPE_ABI_VERSION
|| lenops
<sizeof(*ops
))
66 memcpy(ops
, &_citrus_NONE_ctype_ops
, sizeof(_citrus_NONE_ctype_ops
));
72 _citrus_NONE_stdenc_getops(struct _citrus_stdenc_ops
*ops
, size_t lenops
,
73 uint32_t expected_version
)
75 if (expected_version
<_CITRUS_STDENC_ABI_VERSION
|| lenops
<sizeof(*ops
))
78 memcpy(ops
, &_citrus_NONE_stdenc_ops
, sizeof(_citrus_NONE_stdenc_ops
));
85 _citrus_NONE_ctype_init(void ** __restrict cl
, void * __restrict var __unused
,
86 size_t lenvar __unused
, size_t lenps __unused
)
94 _citrus_NONE_ctype_uninit(void *cl __unused
)
100 _citrus_NONE_ctype_get_mb_cur_max(void *cl __unused
)
107 _citrus_NONE_ctype_mblen(void * __restrict cl __unused
,
108 const char * __restrict s
, size_t n
,
109 int * __restrict nresult
)
112 *nresult
= 0; /* state independent */
119 *nresult
= (*s
== 0) ? 0 : 1;
125 _citrus_NONE_ctype_mbrlen(void * __restrict cl __unused
,
126 const char * __restrict s
, size_t n
,
127 void * __restrict pspriv __unused
,
128 size_t * __restrict nresult
)
135 *nresult
= (size_t)-2;
138 *nresult
= (*s
== 0) ? 0 : 1;
144 _citrus_NONE_ctype_mbrtowc(void * __restrict cl __unused
,
145 wchar_t * __restrict pwc
,
146 const char * __restrict s
, size_t n
,
147 void * __restrict pspriv __unused
,
148 size_t * __restrict nresult
)
155 *nresult
= (size_t)-2;
160 *pwc
= (wchar_t)(unsigned char) *s
;
162 *nresult
= *s
== '\0' ? 0 : 1;
168 _citrus_NONE_ctype_mbsinit(void * __restrict cl __unused
,
169 const void * __restrict pspriv __unused
,
170 int * __restrict nresult
)
172 *nresult
= 1; /* always initial state */
178 _citrus_NONE_ctype_mbsrtowcs(void * __restrict cl __unused
,
179 wchar_t * __restrict pwcs
,
180 const char ** __restrict s
, size_t n
,
181 void * __restrict pspriv __unused
,
182 size_t * __restrict nresult
)
187 /* if pwcs is NULL, ignore n */
189 n
= 1; /* arbitrary >0 value */
192 s0
= *s
; /* to keep *s unchanged for now, use copy instead. */
195 *pwcs
= (wchar_t)(unsigned char)*s0
;
211 *nresult
= (size_t)cnt
;
217 _citrus_NONE_ctype_mbstowcs(void * __restrict cl
, wchar_t * __restrict wcs
,
218 const char * __restrict s
, size_t n
,
219 size_t * __restrict nresult
)
221 const char *tmp_s
= __DEQUALIFY(const char *, s
);
223 return (_citrus_NONE_ctype_mbsrtowcs(cl
, wcs
, &tmp_s
, n
, NULL
, nresult
));
228 _citrus_NONE_ctype_mbtowc(void * __restrict cl __unused
,
229 wchar_t * __restrict pwc
,
230 const char * __restrict s
, size_t n
,
231 int * __restrict nresult
)
235 *nresult
= 0; /* state independent */
250 *pwc
= (wchar_t)(unsigned char)*s
;
251 *nresult
= *s
== '\0' ? 0 : 1;
258 _citrus_NONE_ctype_wcrtomb(void * __restrict cl __unused
,
259 char * __restrict s
, wchar_t wc
,
260 void * __restrict pspriv __unused
,
261 size_t * __restrict nresult
)
263 if ((wc
&~0xFFU
) != 0) {
264 *nresult
= (size_t)-1;
277 _citrus_NONE_ctype_wcsrtombs(void * __restrict cl __unused
,
279 const wchar_t ** __restrict pwcs
, size_t n
,
280 void * __restrict pspriv __unused
,
281 size_t * __restrict nresult
)
284 const wchar_t *pwcs0
;
293 if ((*pwcs0
& ~0xFFU
) != 0) {
294 *nresult
= (size_t)-1;
301 if (*pwcs0
== L
'\0') {
317 _citrus_NONE_ctype_wcstombs(void * __restrict cl
, char * __restrict s
,
318 const wchar_t * __restrict pwcs
, size_t n
,
319 size_t * __restrict nresult
)
321 const wchar_t *tmp_pwcs
= __DEQUALIFY(const wchar_t *, pwcs
);
323 return (_citrus_NONE_ctype_wcsrtombs(cl
, s
, &tmp_pwcs
, n
, NULL
, nresult
));
327 _citrus_NONE_ctype_wctomb(void * __restrict cl
, char * __restrict s
,
328 wchar_t wc
, int * __restrict nresult
)
335 * initialize state here.
336 * (nothing to do for us.)
338 *nresult
= 0; /* we're state independent */
342 ret
= _citrus_NONE_ctype_wcrtomb(cl
, s
, wc
, NULL
, &nr
);
350 _citrus_NONE_ctype_btowc(_citrus_ctype_rec_t
* __restrict cc __unused
,
351 int c
, wint_t * __restrict wcresult
)
353 if (c
== EOF
|| c
& ~0xFF)
356 *wcresult
= (wint_t)c
;
362 _citrus_NONE_ctype_wctob(_citrus_ctype_rec_t
* __restrict cc __unused
,
363 wint_t wc
, int * __restrict cresult
)
365 if (wc
== WEOF
|| wc
& ~0xFF)
372 /* ---------------------------------------------------------------------- */
374 _CITRUS_STDENC_DECLS(NONE
);
375 _CITRUS_STDENC_DEF_OPS(NONE
);
376 struct _citrus_stdenc_traits _citrus_NONE_stdenc_traits
= {
377 0, /* et_state_size */
383 _citrus_NONE_stdenc_init(struct _citrus_stdenc
* __restrict ce
,
384 const void *var __unused
, size_t lenvar __unused
,
385 struct _citrus_stdenc_traits
* __restrict et
)
388 et
->et_state_size
= 0;
389 et
->et_mb_cur_max
= 1;
391 ce
->ce_closure
= NULL
;
398 _citrus_NONE_stdenc_uninit(struct _citrus_stdenc
*ce __unused
)
404 _citrus_NONE_stdenc_init_state(struct _citrus_stdenc
* __restrict ce __unused
,
405 void * __restrict ps __unused
)
412 _citrus_NONE_stdenc_mbtocs(struct _citrus_stdenc
* __restrict ce __unused
,
413 _csid_t
*csid
, _index_t
*idx
,
414 const char **s
, size_t n
,
415 void *ps __unused
, size_t *nresult
)
418 _DIAGASSERT(csid
!= NULL
&& idx
!= NULL
);
421 *nresult
= (size_t)-2;
426 *idx
= (_index_t
)(unsigned char)*(*s
)++;
427 *nresult
= *idx
== 0 ? 0 : 1;
434 _citrus_NONE_stdenc_cstomb(struct _citrus_stdenc
* __restrict ce __unused
,
436 _csid_t csid
, _index_t idx
,
437 void *ps __unused
, size_t *nresult
)
440 if (csid
== _CITRUS_CSID_INVALID
) {
445 *nresult
= (size_t)-1;
448 if (csid
!= 0 || (idx
&0xFF) != idx
)
459 _citrus_NONE_stdenc_mbtowc(struct _citrus_stdenc
* __restrict ce __unused
,
460 _wc_t
* __restrict pwc
,
461 const char ** __restrict s
, size_t n
,
462 void * __restrict pspriv __unused
,
463 size_t * __restrict nresult
)
470 *nresult
= (size_t)-2;
475 *pwc
= (_wc_t
)(unsigned char) **s
;
477 *nresult
= *s
== '\0' ? 0 : 1;
483 _citrus_NONE_stdenc_wctomb(struct _citrus_stdenc
* __restrict ce __unused
,
484 char * __restrict s
, size_t n
, _wc_t wc
,
485 void * __restrict pspriv __unused
,
486 size_t * __restrict nresult
)
488 if ((wc
&~0xFFU
) != 0) {
489 *nresult
= (size_t)-1;
493 *nresult
= (size_t)-1;
506 _citrus_NONE_stdenc_put_state_reset(struct _citrus_stdenc
* __restrict ce __unused
,
507 char * __restrict s __unused
,
509 void * __restrict pspriv __unused
,
510 size_t * __restrict nresult
)
520 _citrus_NONE_stdenc_get_state_desc(struct _stdenc
* __restrict ce
,
521 void * __restrict ps
,
523 struct _stdenc_state_desc
* __restrict d
)
528 case _STDENC_SDID_GENERIC
:
529 d
->u
.generic
.state
= _STDENC_SDGEN_INITIAL
;