citrus_none.c revision 1.3.2.4 1 1.3.2.4 nathanw /* $NetBSD: citrus_none.c,v 1.3.2.4 2002/06/21 18:18:05 nathanw Exp $ */
2 1.3.2.2 nathanw
3 1.3.2.2 nathanw /*-
4 1.3.2.2 nathanw * Copyright (c)2002 Citrus Project,
5 1.3.2.2 nathanw * All rights reserved.
6 1.3.2.2 nathanw *
7 1.3.2.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.3.2.2 nathanw * modification, are permitted provided that the following conditions
9 1.3.2.2 nathanw * are met:
10 1.3.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.3.2.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.3.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.3.2.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.3.2.2 nathanw *
16 1.3.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.3.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.3.2.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.3.2.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.3.2.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.3.2.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.3.2.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.3.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.3.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.3.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.3.2.2 nathanw * SUCH DAMAGE.
27 1.3.2.2 nathanw */
28 1.3.2.2 nathanw
29 1.3.2.2 nathanw #include <sys/cdefs.h>
30 1.3.2.2 nathanw #if defined(LIBC_SCCS) && !defined(lint)
31 1.3.2.4 nathanw __RCSID("$NetBSD: citrus_none.c,v 1.3.2.4 2002/06/21 18:18:05 nathanw Exp $");
32 1.3.2.2 nathanw #endif /* LIBC_SCCS and not lint */
33 1.3.2.2 nathanw
34 1.3.2.2 nathanw #include <assert.h>
35 1.3.2.2 nathanw #include <errno.h>
36 1.3.2.2 nathanw #include <string.h>
37 1.3.2.2 nathanw #include <stdio.h>
38 1.3.2.2 nathanw #include <stdlib.h>
39 1.3.2.2 nathanw #include <stddef.h>
40 1.3.2.2 nathanw #include <locale.h>
41 1.3.2.2 nathanw #include <wchar.h>
42 1.3.2.2 nathanw #include <sys/types.h>
43 1.3.2.2 nathanw #include "citrus_module.h"
44 1.3.2.2 nathanw #include "citrus_ctype.h"
45 1.3.2.2 nathanw #include "citrus_none.h"
46 1.3.2.2 nathanw
47 1.3.2.2 nathanw /* ---------------------------------------------------------------------- */
48 1.3.2.2 nathanw
49 1.3.2.2 nathanw _CITRUS_CTYPE_DECLS(NONE);
50 1.3.2.2 nathanw _CITRUS_CTYPE_DEF_OPS(NONE);
51 1.3.2.2 nathanw
52 1.3.2.2 nathanw
53 1.3.2.2 nathanw /* ---------------------------------------------------------------------- */
54 1.3.2.2 nathanw
55 1.3.2.2 nathanw static int
56 1.3.2.2 nathanw /*ARGSUSED*/
57 1.3.2.2 nathanw _citrus_NONE_ctype_init(void ** __restrict cl, void * __restrict var,
58 1.3.2.2 nathanw size_t lenvar, size_t lenps)
59 1.3.2.2 nathanw {
60 1.3.2.2 nathanw *cl = NULL;
61 1.3.2.2 nathanw return (0);
62 1.3.2.2 nathanw }
63 1.3.2.2 nathanw
64 1.3.2.2 nathanw static void
65 1.3.2.2 nathanw /*ARGSUSED*/
66 1.3.2.2 nathanw _citrus_NONE_ctype_uninit(void *cl)
67 1.3.2.2 nathanw {
68 1.3.2.2 nathanw }
69 1.3.2.2 nathanw
70 1.3.2.2 nathanw static unsigned
71 1.3.2.2 nathanw /*ARGSUSED*/
72 1.3.2.2 nathanw _citrus_NONE_ctype_get_mb_cur_max(void *cl)
73 1.3.2.2 nathanw {
74 1.3.2.2 nathanw return (1);
75 1.3.2.2 nathanw }
76 1.3.2.2 nathanw
77 1.3.2.2 nathanw static int
78 1.3.2.2 nathanw /*ARGSUSED*/
79 1.3.2.2 nathanw _citrus_NONE_ctype_mblen(void * __restrict cl, const char * __restrict s,
80 1.3.2.2 nathanw size_t n, int * __restrict nresult)
81 1.3.2.2 nathanw {
82 1.3.2.2 nathanw if (!s) {
83 1.3.2.2 nathanw *nresult = 0; /* state independent */
84 1.3.2.2 nathanw return (0);
85 1.3.2.2 nathanw }
86 1.3.2.2 nathanw if (n==0) {
87 1.3.2.2 nathanw *nresult = -1;
88 1.3.2.2 nathanw return (EILSEQ);
89 1.3.2.2 nathanw }
90 1.3.2.2 nathanw *nresult = (*s == 0) ? 0 : 1;
91 1.3.2.2 nathanw return (0);
92 1.3.2.2 nathanw }
93 1.3.2.2 nathanw
94 1.3.2.2 nathanw static int
95 1.3.2.2 nathanw /*ARGSUSED*/
96 1.3.2.2 nathanw _citrus_NONE_ctype_mbrlen(void * __restrict cl, const char * __restrict s,
97 1.3.2.2 nathanw size_t n, void * __restrict pspriv,
98 1.3.2.2 nathanw size_t * __restrict nresult)
99 1.3.2.2 nathanw {
100 1.3.2.2 nathanw if (!s) {
101 1.3.2.2 nathanw *nresult = 0;
102 1.3.2.2 nathanw return (0);
103 1.3.2.2 nathanw }
104 1.3.2.2 nathanw if (n==0) {
105 1.3.2.2 nathanw *nresult = (size_t)-2;
106 1.3.2.2 nathanw return (0);
107 1.3.2.2 nathanw }
108 1.3.2.2 nathanw *nresult = (*s == 0) ? 0 : 1;
109 1.3.2.2 nathanw return (0);
110 1.3.2.2 nathanw }
111 1.3.2.2 nathanw
112 1.3.2.2 nathanw static int
113 1.3.2.2 nathanw /*ARGSUSED*/
114 1.3.2.2 nathanw _citrus_NONE_ctype_mbrtowc(void * __restrict cl, wchar_t * __restrict pwc,
115 1.3.2.2 nathanw const char * __restrict s, size_t n,
116 1.3.2.2 nathanw void * __restrict pspriv,
117 1.3.2.2 nathanw size_t * __restrict nresult)
118 1.3.2.2 nathanw {
119 1.3.2.2 nathanw if (s == NULL) {
120 1.3.2.2 nathanw *nresult = 0;
121 1.3.2.2 nathanw return (0);
122 1.3.2.2 nathanw }
123 1.3.2.2 nathanw if (n == 0) {
124 1.3.2.2 nathanw *nresult = (size_t)-2;
125 1.3.2.2 nathanw return (0);
126 1.3.2.2 nathanw }
127 1.3.2.2 nathanw
128 1.3.2.2 nathanw if (pwc != NULL)
129 1.3.2.2 nathanw *pwc = (wchar_t)(unsigned char) *s;
130 1.3.2.2 nathanw
131 1.3.2.2 nathanw *nresult = *s == '\0' ? 0 : 1;
132 1.3.2.2 nathanw return (0);
133 1.3.2.2 nathanw }
134 1.3.2.2 nathanw
135 1.3.2.2 nathanw static int
136 1.3.2.2 nathanw /*ARGSUSED*/
137 1.3.2.2 nathanw _citrus_NONE_ctype_mbsinit(void * __restrict cl,
138 1.3.2.2 nathanw const void * __restrict pspriv,
139 1.3.2.2 nathanw int * __restrict nresult)
140 1.3.2.2 nathanw {
141 1.3.2.2 nathanw *nresult = 1; /* always initial state */
142 1.3.2.2 nathanw return (0);
143 1.3.2.2 nathanw }
144 1.3.2.2 nathanw
145 1.3.2.2 nathanw static int
146 1.3.2.2 nathanw /*ARGSUSED*/
147 1.3.2.2 nathanw _citrus_NONE_ctype_mbsrtowcs(void * __restrict cl, wchar_t * __restrict wcs,
148 1.3.2.2 nathanw const char ** __restrict s, size_t n,
149 1.3.2.2 nathanw void * __restrict pspriv,
150 1.3.2.2 nathanw size_t * __restrict nresult)
151 1.3.2.2 nathanw {
152 1.3.2.2 nathanw size_t count;
153 1.3.2.2 nathanw const char *s0;
154 1.3.2.2 nathanw
155 1.3.2.2 nathanw count = 0;
156 1.3.2.2 nathanw s0 = *s;
157 1.3.2.2 nathanw while (n>0) {
158 1.3.2.2 nathanw if (wcs != NULL)
159 1.3.2.2 nathanw *wcs++ = (wchar_t)(unsigned char)*s0;
160 1.3.2.2 nathanw if (*s0 == '\0') {
161 1.3.2.2 nathanw s0 = NULL;
162 1.3.2.2 nathanw break;
163 1.3.2.2 nathanw }
164 1.3.2.2 nathanw count++;
165 1.3.2.2 nathanw n--;
166 1.3.2.2 nathanw s0++;
167 1.3.2.2 nathanw }
168 1.3.2.2 nathanw if (*wcs)
169 1.3.2.2 nathanw *s = s0;
170 1.3.2.2 nathanw
171 1.3.2.2 nathanw *nresult = count;
172 1.3.2.2 nathanw
173 1.3.2.2 nathanw return (0);
174 1.3.2.2 nathanw }
175 1.3.2.2 nathanw
176 1.3.2.2 nathanw static int
177 1.3.2.2 nathanw _citrus_NONE_ctype_mbstowcs(void * __restrict cl, wchar_t * __restrict wcs,
178 1.3.2.2 nathanw const char * __restrict s, size_t n,
179 1.3.2.2 nathanw size_t * __restrict nresult)
180 1.3.2.2 nathanw {
181 1.3.2.4 nathanw return (_citrus_NONE_ctype_mbsrtowcs(cl, wcs, (const char **)&s, n, NULL, nresult));
182 1.3.2.2 nathanw }
183 1.3.2.2 nathanw
184 1.3.2.2 nathanw static int
185 1.3.2.2 nathanw /*ARGSUSED*/
186 1.3.2.2 nathanw _citrus_NONE_ctype_mbtowc(void * __restrict cl, wchar_t * __restrict pwc,
187 1.3.2.2 nathanw const char * __restrict s, size_t n,
188 1.3.2.2 nathanw int * __restrict nresult)
189 1.3.2.2 nathanw {
190 1.3.2.2 nathanw
191 1.3.2.2 nathanw if (s == NULL) {
192 1.3.2.2 nathanw *nresult = 0; /* state independent */
193 1.3.2.2 nathanw return (0);
194 1.3.2.2 nathanw }
195 1.3.2.2 nathanw if (n == 0) {
196 1.3.2.2 nathanw return (EILSEQ);
197 1.3.2.2 nathanw }
198 1.3.2.2 nathanw if (pwc == NULL) {
199 1.3.2.2 nathanw if (*s == '\0') {
200 1.3.2.2 nathanw *nresult = 0;
201 1.3.2.2 nathanw } else {
202 1.3.2.2 nathanw *nresult = 1;
203 1.3.2.2 nathanw }
204 1.3.2.2 nathanw return (0);
205 1.3.2.2 nathanw }
206 1.3.2.2 nathanw
207 1.3.2.2 nathanw *pwc = (wchar_t)*s;
208 1.3.2.2 nathanw *nresult = *s == '\0' ? 0 : 1;
209 1.3.2.2 nathanw
210 1.3.2.2 nathanw return (0);
211 1.3.2.2 nathanw }
212 1.3.2.2 nathanw
213 1.3.2.2 nathanw static int
214 1.3.2.2 nathanw /*ARGSUSED*/
215 1.3.2.2 nathanw _citrus_NONE_ctype_wcrtomb(void * __restrict cl, char * __restrict s,
216 1.3.2.2 nathanw wchar_t wc, void * __restrict pspriv,
217 1.3.2.2 nathanw size_t * __restrict nresult)
218 1.3.2.2 nathanw {
219 1.3.2.2 nathanw if ((wc&~0xFFU) != 0) {
220 1.3.2.2 nathanw *nresult = (size_t)-1;
221 1.3.2.2 nathanw return (EILSEQ);
222 1.3.2.2 nathanw }
223 1.3.2.2 nathanw
224 1.3.2.2 nathanw *nresult = 1;
225 1.3.2.2 nathanw if (s!=NULL)
226 1.3.2.2 nathanw *s = (char)wc;
227 1.3.2.2 nathanw
228 1.3.2.2 nathanw return (0);
229 1.3.2.2 nathanw }
230 1.3.2.2 nathanw
231 1.3.2.2 nathanw static int
232 1.3.2.2 nathanw /*ARGSUSED*/
233 1.3.2.2 nathanw _citrus_NONE_ctype_wcsrtombs(void * __restrict cl, char * __restrict s,
234 1.3.2.2 nathanw const wchar_t ** __restrict pwcs, size_t n,
235 1.3.2.2 nathanw void * __restrict pspriv,
236 1.3.2.2 nathanw size_t * __restrict nresult)
237 1.3.2.2 nathanw {
238 1.3.2.2 nathanw size_t count;
239 1.3.2.2 nathanw const wchar_t *pwcs0;
240 1.3.2.2 nathanw
241 1.3.2.2 nathanw pwcs0 = *pwcs;
242 1.3.2.2 nathanw count = 0;
243 1.3.2.3 nathanw
244 1.3.2.3 nathanw if (s == NULL)
245 1.3.2.3 nathanw n = 1;
246 1.3.2.3 nathanw
247 1.3.2.3 nathanw while (n > 0) {
248 1.3.2.2 nathanw if ((*pwcs0 & ~0xFFU) != 0) {
249 1.3.2.3 nathanw *nresult = (size_t)-1;
250 1.3.2.2 nathanw return (EILSEQ);
251 1.3.2.2 nathanw }
252 1.3.2.3 nathanw if (s != NULL) {
253 1.3.2.2 nathanw *s++ = (char)*pwcs0;
254 1.3.2.3 nathanw n--;
255 1.3.2.3 nathanw }
256 1.3.2.2 nathanw if (*pwcs0 == L'\0') {
257 1.3.2.2 nathanw pwcs0 = NULL;
258 1.3.2.2 nathanw break;
259 1.3.2.2 nathanw }
260 1.3.2.2 nathanw count++;
261 1.3.2.2 nathanw pwcs0++;
262 1.3.2.2 nathanw }
263 1.3.2.2 nathanw if (s != NULL)
264 1.3.2.2 nathanw *pwcs = pwcs0;
265 1.3.2.2 nathanw
266 1.3.2.2 nathanw *nresult = count;
267 1.3.2.2 nathanw
268 1.3.2.2 nathanw return (0);
269 1.3.2.2 nathanw }
270 1.3.2.2 nathanw
271 1.3.2.2 nathanw static int
272 1.3.2.2 nathanw _citrus_NONE_ctype_wcstombs(void * __restrict cl, char * __restrict s,
273 1.3.2.2 nathanw const wchar_t * __restrict pwcs, size_t n,
274 1.3.2.2 nathanw size_t * __restrict nresult)
275 1.3.2.2 nathanw {
276 1.3.2.4 nathanw return (_citrus_NONE_ctype_wcsrtombs(cl, s, (const wchar_t **)&pwcs, n, NULL, nresult));
277 1.3.2.2 nathanw }
278 1.3.2.2 nathanw
279 1.3.2.2 nathanw static int
280 1.3.2.2 nathanw _citrus_NONE_ctype_wctomb(void * __restrict cl, char * __restrict s,
281 1.3.2.2 nathanw wchar_t wc, int * __restrict nresult)
282 1.3.2.2 nathanw {
283 1.3.2.2 nathanw int ret;
284 1.3.2.2 nathanw size_t nr;
285 1.3.2.2 nathanw
286 1.3.2.2 nathanw ret = _citrus_NONE_ctype_wcrtomb(cl, s, wc, NULL, &nr);
287 1.3.2.2 nathanw *nresult = (int)nr;
288 1.3.2.2 nathanw
289 1.3.2.2 nathanw return (ret);
290 1.3.2.2 nathanw }
291