citrus_stdenc.h revision 1.4.80.1 1 /* $NetBSD: citrus_stdenc.h,v 1.4.80.1 2017/07/14 15:53:07 perseant 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
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
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
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
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
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
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 int
120 _citrus_stdenc_wctocs(struct _citrus_stdenc *__restrict ce,
121 _csid_t * __restrict csid,
122 _index_t * __restrict idx, wchar_t wc)
123 {
124 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_wctocs);
125 return (*ce->ce_ops->eo_wctocs)(ce, csid, idx, wc);
126 }
127
128 static __inline int
129 _citrus_stdenc_cstowc(struct _citrus_stdenc * __restrict ce,
130 wchar_t * __restrict wc, _csid_t csid, _index_t idx)
131 {
132 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_cstowc);
133 return (*ce->ce_ops->eo_cstowc)(ce, wc, csid, idx);
134 }
135
136 static __inline size_t
137 _citrus_stdenc_get_state_size(struct _citrus_stdenc *ce)
138 {
139 _DIAGASSERT(ce && ce->ce_traits);
140 return ce->ce_traits->et_state_size;
141 }
142
143 static __inline size_t
144 _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce)
145 {
146 _DIAGASSERT(ce && ce->ce_traits);
147 return ce->ce_traits->et_mb_cur_max;
148 }
149
150 static __inline int
151 _citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce,
152 void * __restrict ps,
153 int id,
154 struct _citrus_stdenc_state_desc * __restrict d)
155 {
156
157 _DIAGASSERT(ce && ce->ce_ops && ce->ce_ops->eo_get_state_desc);
158
159 return (*ce->ce_ops->eo_get_state_desc)(ce, ps, id, d);
160 }
161
162 #endif
163