xref: /minix/lib/libc/citrus/citrus_ctype_local.h (revision 84d9c625)
1 /*	$NetBSD: citrus_ctype_local.h,v 1.4 2013/05/28 16:57:56 joerg Exp $	*/
2 
3 /*-
4  * Copyright (c)2002 Citrus Project,
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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
26  * SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef _CITRUS_CTYPE_LOCAL_H_
31 #define _CITRUS_CTYPE_LOCAL_H_
32 
33 #define _CITRUS_CTYPE_GETOPS_FUNC_BASE(_n_)				\
34 int _n_(_citrus_ctype_ops_rec_t *, size_t, uint32_t)
35 #define _CITRUS_CTYPE_GETOPS_FUNC(_n_)					\
36 _CITRUS_CTYPE_GETOPS_FUNC_BASE(_citrus_##_n_##_ctype_getops)
37 
38 #define _CITRUS_CTYPE_DECLS(_e_)					      \
39 static int	_citrus_##_e_##_ctype_init				      \
40 	(void ** __restrict, void * __restrict, size_t, size_t);	      \
41 static void	_citrus_##_e_##_ctype_uninit(void *);			      \
42 static unsigned	_citrus_##_e_##_ctype_get_mb_cur_max(void *);		      \
43 static int	_citrus_##_e_##_ctype_mblen(void * __restrict,		      \
44 				     const char * __restrict,		      \
45 				     size_t, int * __restrict);		      \
46 static int	_citrus_##_e_##_ctype_mbrlen(void * __restrict,		      \
47 				      const char * __restrict,		      \
48 				      size_t, void * __restrict,	      \
49 				      size_t * __restrict);		      \
50 static int	_citrus_##_e_##_ctype_mbrtowc(void * __restrict,	      \
51 				       wchar_t * __restrict,		      \
52 				       const char * __restrict, size_t,	      \
53 				       void * __restrict,		      \
54 				       size_t * __restrict);		      \
55 static int	_citrus_##_e_##_ctype_mbsinit(void * __restrict,	      \
56 				       void const * __restrict,		      \
57 				       int * __restrict);		      \
58 static int	_citrus_##_e_##_ctype_mbsrtowcs(void * __restrict,	      \
59 					 wchar_t * __restrict,		      \
60 					 const char ** __restrict,	      \
61 					 size_t, void * __restrict,	      \
62 					 size_t * __restrict);		      \
63 static int	_citrus_##_e_##_ctype_mbsnrtowcs(_citrus_ctype_rec_t * __restrict, \
64 					 wchar_t * __restrict,		      \
65 					 const char ** __restrict,	      \
66 					 size_t, size_t, void * __restrict,   \
67 					 size_t * __restrict);		      \
68 static int	_citrus_##_e_##_ctype_mbstowcs(void * __restrict,	      \
69 					wchar_t * __restrict,		      \
70 					const char * __restrict,	      \
71 					size_t, size_t * __restrict);	      \
72 static int	_citrus_##_e_##_ctype_mbtowc(void * __restrict,		      \
73 				      wchar_t * __restrict,		      \
74 				      const char * __restrict,		      \
75 				      size_t, int * __restrict);	      \
76 static int	_citrus_##_e_##_ctype_wcrtomb(void * __restrict,	      \
77 				       char * __restrict, wchar_t,	      \
78 				       void * __restrict,		      \
79 				       size_t * __restrict);		      \
80 static int	_citrus_##_e_##_ctype_wcsrtombs(void * __restrict,	      \
81 					 char * __restrict,		      \
82 					 const wchar_t ** __restrict,	      \
83 					 size_t, void * __restrict,	      \
84 					 size_t * __restrict);		      \
85 static int	_citrus_##_e_##_ctype_wcsnrtombs(_citrus_ctype_rec_t * __restrict, \
86 					 char * __restrict,		      \
87 					 const wchar_t ** __restrict,	      \
88 					 size_t, size_t, void * __restrict,   \
89 					 size_t * __restrict);		      \
90 static int	_citrus_##_e_##_ctype_wcstombs(void * __restrict,	      \
91 					char * __restrict,		      \
92 					const wchar_t * __restrict,	      \
93 					size_t, size_t * __restrict);	      \
94 static int	_citrus_##_e_##_ctype_wctomb(void * __restrict,		      \
95 				      char * __restrict,		      \
96 				      wchar_t, int * __restrict);	      \
97 static int	_citrus_##_e_##_ctype_btowc(_citrus_ctype_rec_t * __restrict, \
98 				      int, wint_t * __restrict);	      \
99 static int	_citrus_##_e_##_ctype_wctob(_citrus_ctype_rec_t * __restrict, \
100 				      wint_t, int * __restrict)
101 
102 #define _CITRUS_CTYPE_DEF_OPS(_e_)					\
103 _citrus_ctype_ops_rec_t _citrus_##_e_##_ctype_ops = {			\
104 	/* co_abi_version */	_CITRUS_CTYPE_ABI_VERSION,		\
105 	/* co_init */		&_citrus_##_e_##_ctype_init,		\
106 	/* co_uninit */		&_citrus_##_e_##_ctype_uninit,		\
107 	/* co_get_mb_cur_max */	&_citrus_##_e_##_ctype_get_mb_cur_max,	\
108 	/* co_mblen */		&_citrus_##_e_##_ctype_mblen,		\
109 	/* co_mbrlen */		&_citrus_##_e_##_ctype_mbrlen,		\
110 	/* co_mbrtowc */	&_citrus_##_e_##_ctype_mbrtowc,		\
111 	/* co_mbsinit */	&_citrus_##_e_##_ctype_mbsinit,		\
112 	/* co_mbsrtowcs */	&_citrus_##_e_##_ctype_mbsrtowcs,	\
113 	/* co_mbstowcs */	&_citrus_##_e_##_ctype_mbstowcs,	\
114 	/* co_mbtowc */		&_citrus_##_e_##_ctype_mbtowc,		\
115 	/* co_wcrtomb */	&_citrus_##_e_##_ctype_wcrtomb,		\
116 	/* co_wcsrtombs */	&_citrus_##_e_##_ctype_wcsrtombs,	\
117 	/* co_wcstombs */	&_citrus_##_e_##_ctype_wcstombs,	\
118 	/* co_wctomb */		&_citrus_##_e_##_ctype_wctomb,		\
119 	/* co_btowc */		&_citrus_##_e_##_ctype_btowc,		\
120 	/* co_wctob */		&_citrus_##_e_##_ctype_wctob,		\
121 	/* co_mbsnrtowcs */	&_citrus_##_e_##_ctype_mbsnrtowcs,	\
122 	/* co_wcsnrtombs */	&_citrus_##_e_##_ctype_wcsnrtombs,	\
123 }
124 
125 typedef struct _citrus_ctype_ops_rec	_citrus_ctype_ops_rec_t;
126 typedef struct _citrus_ctype_rec	_citrus_ctype_rec_t;
127 
128 typedef int	(*_citrus_ctype_init_t)
129 	(void ** __restrict, void * __restrict, size_t, size_t);
130 typedef void	(*_citrus_ctype_uninit_t)(void *);
131 typedef unsigned (*_citrus_ctype_get_mb_cur_max_t)(void *);
132 typedef int	(*_citrus_ctype_mblen_t)
133 	(void * __restrict, const char * __restrict, size_t, int * __restrict);
134 typedef int	(*_citrus_ctype_mbrlen_t)
135 	(void * __restrict, const char * __restrict, size_t,
136 	 void * __restrict, size_t * __restrict);
137 typedef int	(*_citrus_ctype_mbrtowc_t)
138 	(void * __restrict, wchar_t * __restrict, const char * __restrict,
139 	 size_t, void * __restrict, size_t * __restrict);
140 typedef int	(*_citrus_ctype_mbsinit_t)
141 	(void * __restrict, const void * __restrict, int * __restrict);
142 typedef int	(*_citrus_ctype_mbsrtowcs_t)
143 	(void * __restrict, wchar_t * __restrict, const char ** __restrict,
144 	 size_t, void * __restrict, size_t * __restrict);
145 typedef int	(*_citrus_ctype_mbsnrtowcs_t)
146 	(_citrus_ctype_rec_t * __restrict, wchar_t * __restrict,
147 	 const char ** __restrict, size_t, size_t, void * __restrict,
148 	 size_t * __restrict);
149 typedef int	(*_citrus_ctype_mbstowcs_t)
150 	(void * __restrict, wchar_t * __restrict, const char * __restrict,
151 	 size_t, size_t * __restrict);
152 typedef int	(*_citrus_ctype_mbtowc_t)
153 	(void * __restrict, wchar_t * __restrict, const char * __restrict,
154 	 size_t, int * __restrict);
155 typedef int	(*_citrus_ctype_wcrtomb_t)
156 	(void * __restrict, char * __restrict, wchar_t, void * __restrict,
157 	 size_t * __restrict);
158 typedef int	(*_citrus_ctype_wcsrtombs_t)
159 	(void * __restrict, char * __restrict, const wchar_t ** __restrict,
160 	 size_t, void * __restrict, size_t * __restrict);
161 typedef int	(*_citrus_ctype_wcsnrtombs_t)
162 	(_citrus_ctype_rec_t * __restrict, char * __restrict,
163 	 const wchar_t ** __restrict, size_t, size_t, void * __restrict,
164 	 size_t * __restrict);
165 typedef int	(*_citrus_ctype_wcstombs_t)
166 	(void * __restrict, char * __restrict, const wchar_t * __restrict,
167 	 size_t, size_t * __restrict);
168 typedef int	(*_citrus_ctype_wctomb_t)
169 	(void * __restrict, char * __restrict, wchar_t, int * __restrict);
170 typedef int	(*_citrus_ctype_btowc_t)
171 	(_citrus_ctype_rec_t * __restrict, int, wint_t * __restrict);
172 typedef int	(*_citrus_ctype_wctob_t)
173 	(_citrus_ctype_rec_t * __restrict, wint_t, int * __restrict);
174 #include "citrus_ctype_fallback.h"
175 
176 /*
177  * ABI Version change log:
178  *   0x00000001
179  *     initial version
180  *   0x00000002
181  *     ops record:	btowc and wctob added.
182  *     ctype record:	unchanged.
183  *   0x00000003
184  *     ops record:	mbsnrtowcs and wcsnrtombs added.
185  *     ctype record:	unchanged.
186  */
187 #define _CITRUS_CTYPE_ABI_VERSION	0x00000003
188 struct _citrus_ctype_ops_rec {
189 	uint32_t			co_abi_version;
190 	/* version 0x00000001 */
191 	_citrus_ctype_init_t		co_init;
192 	_citrus_ctype_uninit_t		co_uninit;
193 	_citrus_ctype_get_mb_cur_max_t	co_get_mb_cur_max;
194 	_citrus_ctype_mblen_t		co_mblen;
195 	_citrus_ctype_mbrlen_t		co_mbrlen;
196 	_citrus_ctype_mbrtowc_t		co_mbrtowc;
197 	_citrus_ctype_mbsinit_t		co_mbsinit;
198 	_citrus_ctype_mbsrtowcs_t	co_mbsrtowcs;
199 	_citrus_ctype_mbstowcs_t	co_mbstowcs;
200 	_citrus_ctype_mbtowc_t		co_mbtowc;
201 	_citrus_ctype_wcrtomb_t		co_wcrtomb;
202 	_citrus_ctype_wcsrtombs_t	co_wcsrtombs;
203 	_citrus_ctype_wcstombs_t	co_wcstombs;
204 	_citrus_ctype_wctomb_t		co_wctomb;
205 	/* version 0x00000002 */
206 	_citrus_ctype_btowc_t		co_btowc;
207 	_citrus_ctype_wctob_t		co_wctob;
208 	/* version 0x00000003 */
209 	_citrus_ctype_mbsnrtowcs_t	co_mbsnrtowcs;
210 	_citrus_ctype_wcsnrtombs_t	co_wcsnrtombs;
211 };
212 
213 #define _CITRUS_DEFAULT_CTYPE_NAME	"NONE"
214 #define _CITRUS_DEFAULT_CTYPE_OPS	_citrus_NONE_ctype_ops
215 #define _CITRUS_DEFAULT_CTYPE_HEADER	"citrus_none.h"
216 
217 typedef _CITRUS_CTYPE_GETOPS_FUNC_BASE((*_citrus_ctype_getops_t));
218 struct _citrus_ctype_rec {
219 	_citrus_ctype_ops_rec_t	*cc_ops;
220 	void			*cc_closure;
221 	_citrus_module_t	cc_module;
222 };
223 
224 #endif
225