1 /*	$NetBSD: citrus_stdenc_local.h,v 1.4 2008/02/09 14:56:20 junyoung Exp $	*/
2 
3 /*-
4  * Copyright (c)2003 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_STDENC_LOCAL_H_
31 #define _CITRUS_STDENC_LOCAL_H_
32 
33 #define _CITRUS_STDENC_GETOPS_FUNC_BASE(n)			\
34 int n(struct _citrus_stdenc_ops *, size_t, uint32_t)
35 #define _CITRUS_STDENC_GETOPS_FUNC(_e_)					\
36 _CITRUS_STDENC_GETOPS_FUNC_BASE(_citrus_##_e_##_stdenc_getops)
37 typedef _CITRUS_STDENC_GETOPS_FUNC_BASE((*_citrus_stdenc_getops_t));
38 
39 
40 #define _CITRUS_STDENC_DECLS(_e_)					\
41 static int	_citrus_##_e_##_stdenc_init				\
42 	(struct _citrus_stdenc * __restrict, const void * __restrict,	\
43 	 size_t, struct _citrus_stdenc_traits * __restrict);		\
44 static void	_citrus_##_e_##_stdenc_uninit(struct _citrus_stdenc *);	\
45 static int	_citrus_##_e_##_stdenc_init_state			\
46 	(struct _citrus_stdenc * __restrict, void * __restrict);	\
47 static int	_citrus_##_e_##_stdenc_mbtocs				\
48 	(struct _citrus_stdenc * __restrict,				\
49 	 _citrus_csid_t * __restrict, _citrus_index_t * __restrict,	\
50 	 const char ** __restrict, size_t,				\
51 	 void * __restrict, size_t * __restrict);			\
52 static int	_citrus_##_e_##_stdenc_cstomb				\
53 	(struct _citrus_stdenc * __restrict, char * __restrict,		\
54 	 size_t, _citrus_csid_t, _citrus_index_t,			\
55 	 void * __restrict, size_t * __restrict);			\
56 static int	_citrus_##_e_##_stdenc_mbtowc				\
57 	(struct _citrus_stdenc * __restrict,				\
58 	 _citrus_wc_t * __restrict,					\
59 	 const char ** __restrict, size_t,				\
60 	 void * __restrict, size_t * __restrict);			\
61 static int	_citrus_##_e_##_stdenc_wctomb				\
62 	(struct _citrus_stdenc * __restrict, char * __restrict, size_t,	\
63 	 _citrus_wc_t, void * __restrict, size_t * __restrict);		\
64 static int	_citrus_##_e_##_stdenc_put_state_reset			\
65 	(struct _citrus_stdenc * __restrict, char * __restrict, size_t,	\
66 	 void * __restrict, size_t * __restrict);			\
67 static int	_citrus_##_e_##_stdenc_get_state_desc			\
68 	(struct _citrus_stdenc * __restrict, void * __restrict, int,	\
69 	 struct _citrus_stdenc_state_desc * __restrict)
70 
71 #define _CITRUS_STDENC_DEF_OPS(_e_)					\
72 struct _citrus_stdenc_ops _citrus_##_e_##_stdenc_ops = {		\
73 	/* eo_abi_version */	_CITRUS_STDENC_ABI_VERSION,		\
74 	/* eo_init */		&_citrus_##_e_##_stdenc_init,		\
75 	/* eo_uninit */		&_citrus_##_e_##_stdenc_uninit,		\
76 	/* eo_init_state */	&_citrus_##_e_##_stdenc_init_state,	\
77 	/* eo_mbtocs */		&_citrus_##_e_##_stdenc_mbtocs,		\
78 	/* eo_cstomb */		&_citrus_##_e_##_stdenc_cstomb,		\
79 	/* eo_mbtowc */		&_citrus_##_e_##_stdenc_mbtowc,		\
80 	/* eo_wctomb */		&_citrus_##_e_##_stdenc_wctomb,		\
81 	/* eo_put_state_reset */&_citrus_##_e_##_stdenc_put_state_reset,\
82 	/* eo_get_state_desc */	&_citrus_##_e_##_stdenc_get_state_desc	\
83 }
84 
85 typedef int	(*_citrus_stdenc_init_t)
86 	(struct _citrus_stdenc * __reatrict, const void * __restrict , size_t,
87 	 struct _citrus_stdenc_traits * __restrict);
88 typedef void	(*_citrus_stdenc_uninit_t)(struct _citrus_stdenc * __restrict);
89 typedef int	(*_citrus_stdenc_init_state_t)
90 	(struct _citrus_stdenc * __restrict, void * __restrict);
91 typedef int	(*_citrus_stdenc_mbtocs_t)
92 	(struct _citrus_stdenc * __restrict,
93 	 _citrus_csid_t * __restrict, _citrus_index_t * __restrict,
94 	 const char ** __restrict, size_t,
95 	 void * __restrict, size_t * __restrict);
96 typedef int	(*_citrus_stdenc_cstomb_t)
97 	(struct _citrus_stdenc *__restrict, char * __restrict, size_t,
98 	 _citrus_csid_t, _citrus_index_t, void * __restrict,
99 	 size_t * __restrict);
100 typedef int	(*_citrus_stdenc_mbtowc_t)
101 	(struct _citrus_stdenc * __restrict,
102 	 _citrus_wc_t * __restrict,
103 	 const char ** __restrict, size_t,
104 	 void * __restrict, size_t * __restrict);
105 typedef int	(*_citrus_stdenc_wctomb_t)
106 	(struct _citrus_stdenc *__restrict, char * __restrict, size_t,
107 	 _citrus_wc_t, void * __restrict, size_t * __restrict);
108 typedef int	(*_citrus_stdenc_put_state_reset_t)
109 	(struct _citrus_stdenc *__restrict, char * __restrict, size_t,
110 	 void * __restrict, size_t * __restrict);
111 typedef int	(*_citrus_stdenc_get_state_desc_t)
112 	(struct _citrus_stdenc * __restrict, void * __restrict, int,
113 	 struct _citrus_stdenc_state_desc * __restrict);
114 /*
115  * ABI version change log
116  *   0x00000001
117  *     initial version
118  */
119 #define _CITRUS_STDENC_ABI_VERSION	0x00000002
120 struct _citrus_stdenc_ops {
121 	uint32_t			eo_abi_version;
122 	/* version 0x00000001 */
123 	_citrus_stdenc_init_t		eo_init;
124 	_citrus_stdenc_uninit_t		eo_uninit;
125 	_citrus_stdenc_init_state_t	eo_init_state;
126 	_citrus_stdenc_mbtocs_t		eo_mbtocs;
127 	_citrus_stdenc_cstomb_t		eo_cstomb;
128 	_citrus_stdenc_mbtowc_t		eo_mbtowc;
129 	_citrus_stdenc_wctomb_t		eo_wctomb;
130 	_citrus_stdenc_put_state_reset_t eo_put_state_reset;
131 	/* version 0x00000002 */
132 	_citrus_stdenc_get_state_desc_t	eo_get_state_desc;
133 };
134 
135 struct _citrus_stdenc_traits {
136 	/* version 0x00000001 */
137 	size_t				et_state_size;
138 	size_t				et_mb_cur_max;
139 };
140 
141 struct _citrus_stdenc {
142 	/* public */
143 	/* version 0x00000001 */
144 	struct _citrus_stdenc_ops	*ce_ops;
145 	void				*ce_closure;
146 	/* private */
147 	_citrus_module_t		ce_module;
148 	struct _citrus_stdenc_traits	*ce_traits;
149 };
150 
151 #define _CITRUS_DEFAULT_STDENC_NAME		"NONE"
152 
153 #endif
154