xref: /netbsd/lib/libc/citrus/citrus_stdenc.h (revision 1beef8fe)
1 /*	$NetBSD: citrus_stdenc.h,v 1.4 2005/10/29 18:02:04 tshiozak 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_H_
31 #define _CITRUS_STDENC_H_
32 
33 struct _citrus_stdenc;
34 struct _citrus_stdenc_ops;
35 struct _citrus_stdenc_traits;
36 
37 #define _CITRUS_STDENC_SDID_GENERIC		0
38 struct _citrus_stdenc_state_desc
39 {
40 	union {
41 		struct {
42 			int	state;
43 #define _CITRUS_STDENC_SDGEN_UNKNOWN		0
44 #define _CITRUS_STDENC_SDGEN_INITIAL		1
45 #define _CITRUS_STDENC_SDGEN_STABLE		2
46 #define _CITRUS_STDENC_SDGEN_INCOMPLETE_CHAR	3
47 #define _CITRUS_STDENC_SDGEN_INCOMPLETE_SHIFT	4
48 		} generic;
49 	} u;
50 };
51 
52 #include "citrus_stdenc_local.h"
53 
54 __BEGIN_DECLS
55 int _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict,
56 			char const * __restrict,
57 			const void * __restrict, size_t);
58 void _citrus_stdenc_close(struct _citrus_stdenc *);
59 __END_DECLS
60 
61 static __inline int
_citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,void * __restrict ps)62 _citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,
63 			  void * __restrict ps)
64 {
65 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_init_state);
66 	return (*ce->ce_ops->eo_init_state)(ce, ps);
67 }
68 
69 static __inline int
_citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,_citrus_csid_t * __restrict csid,_citrus_index_t * __restrict idx,const char ** __restrict s,size_t n,void * __restrict ps,size_t * __restrict nresult)70 _citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,
71 		      _citrus_csid_t * __restrict csid,
72 		      _citrus_index_t * __restrict idx,
73 		      const char ** __restrict s, size_t n,
74 		      void * __restrict ps, size_t * __restrict nresult)
75 {
76 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
77 	return (*ce->ce_ops->eo_mbtocs)(ce, csid, idx, s, n, ps, nresult);
78 }
79 
80 static __inline int
_citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,char * __restrict s,size_t n,_citrus_csid_t csid,_citrus_index_t idx,void * __restrict ps,size_t * __restrict nresult)81 _citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,
82 		      char * __restrict s, size_t n,
83 		      _citrus_csid_t csid, _citrus_index_t idx,
84 		      void * __restrict ps, size_t * __restrict nresult)
85 {
86 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
87 	return (*ce->ce_ops->eo_cstomb)(ce, s, n, csid, idx, ps, nresult);
88 }
89 
90 static __inline int
_citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce,_citrus_wc_t * __restrict wc,const char ** __restrict s,size_t n,void * __restrict ps,size_t * __restrict nresult)91 _citrus_stdenc_mbtowc(struct _citrus_stdenc * __restrict ce,
92 		      _citrus_wc_t * __restrict wc,
93 		      const char ** __restrict s, size_t n,
94 		      void * __restrict ps, size_t * __restrict nresult)
95 {
96 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_mbtocs);
97 	return (*ce->ce_ops->eo_mbtowc)(ce, wc, s, n, ps, nresult);
98 }
99 
100 static __inline int
_citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,char * __restrict s,size_t n,_citrus_wc_t wc,void * __restrict ps,size_t * __restrict nresult)101 _citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,
102 		      char * __restrict s, size_t n, _citrus_wc_t wc,
103 		      void * __restrict ps, size_t * __restrict nresult)
104 {
105 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstomb);
106 	return (*ce->ce_ops->eo_wctomb)(ce, s, n, wc, ps, nresult);
107 }
108 
109 static __inline int
_citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,char * __restrict s,size_t n,void * __restrict ps,size_t * __restrict nresult)110 _citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,
111 			       char * __restrict s, size_t n,
112 			       void * __restrict ps,
113 			       size_t * __restrict nresult)
114 {
115 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_put_state_reset);
116 	return (*ce->ce_ops->eo_put_state_reset)(ce, s, n, ps, nresult);
117 }
118 
119 static __inline size_t
_citrus_stdenc_get_state_size(struct _citrus_stdenc * ce)120 _citrus_stdenc_get_state_size(struct _citrus_stdenc *ce)
121 {
122 	_DIAGASSERT(ce && ce->ce_traits);
123 	return ce->ce_traits->et_state_size;
124 }
125 
126 static __inline size_t
_citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc * ce)127 _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce)
128 {
129 	_DIAGASSERT(ce && ce->ce_traits);
130 	return ce->ce_traits->et_mb_cur_max;
131 }
132 
133 static __inline int
_citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce,void * __restrict ps,int id,struct _citrus_stdenc_state_desc * __restrict d)134 _citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce,
135 			      void * __restrict ps,
136 			      int id,
137 			      struct _citrus_stdenc_state_desc * __restrict d)
138 {
139 
140 	_DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_get_state_desc);
141 
142 	return (*ce->ce_ops->eo_get_state_desc)(ce, ps, id, d);
143 }
144 
145 #endif
146