xref: /freebsd/lib/libc/iconv/citrus_stdenc.h (revision 02e9120893770924227138ba49df1edb3896112a)
1 /* $NetBSD: citrus_stdenc.h,v 1.4 2005/10/29 18:02:04 tshiozak Exp $ */
2 
3 /*-
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  * Copyright (c)2003 Citrus Project,
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  */
31 
32 #ifndef _CITRUS_STDENC_H_
33 #define _CITRUS_STDENC_H_
34 
35 struct _citrus_stdenc;
36 struct _citrus_stdenc_ops;
37 struct _citrus_stdenc_traits;
38 
39 #define _CITRUS_STDENC_SDID_GENERIC		0
40 struct _citrus_stdenc_state_desc
41 {
42 	union {
43 		struct {
44 			int	state;
45 #define _CITRUS_STDENC_SDGEN_UNKNOWN		0
46 #define _CITRUS_STDENC_SDGEN_INITIAL		1
47 #define _CITRUS_STDENC_SDGEN_STABLE		2
48 #define _CITRUS_STDENC_SDGEN_INCOMPLETE_CHAR	3
49 #define _CITRUS_STDENC_SDGEN_INCOMPLETE_SHIFT	4
50 		} generic;
51 	} u;
52 };
53 
54 #include "citrus_stdenc_local.h"
55 
56 __BEGIN_DECLS
57 int	 _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict,
58 	    char const * __restrict, const void * __restrict, size_t);
59 void	 _citrus_stdenc_close(struct _citrus_stdenc *);
60 __END_DECLS
61 
62 static __inline int
63 _citrus_stdenc_init_state(struct _citrus_stdenc * __restrict ce,
64     void * __restrict ps)
65 {
66 
67 	return ((*ce->ce_ops->eo_init_state)(ce, ps));
68 }
69 
70 static __inline int
71 _citrus_stdenc_mbtocs(struct _citrus_stdenc * __restrict ce,
72     _citrus_csid_t * __restrict csid, _citrus_index_t * __restrict idx,
73     char ** __restrict s, size_t n, void * __restrict ps,
74     size_t * __restrict nresult, struct iconv_hooks *hooks)
75 {
76 
77 	return ((*ce->ce_ops->eo_mbtocs)(ce, csid, idx, s, n, ps, nresult,
78 	    hooks));
79 }
80 
81 static __inline int
82 _citrus_stdenc_cstomb(struct _citrus_stdenc * __restrict ce,
83     char * __restrict s, size_t n, _citrus_csid_t csid, _citrus_index_t idx,
84     void * __restrict ps, size_t * __restrict nresult,
85     struct iconv_hooks *hooks)
86 {
87 
88 	return ((*ce->ce_ops->eo_cstomb)(ce, s, n, csid, idx, ps, nresult,
89 	    hooks));
90 }
91 
92 static __inline int
93 _citrus_stdenc_wctomb(struct _citrus_stdenc * __restrict ce,
94     char * __restrict s, size_t n, _citrus_wc_t wc, void * __restrict ps,
95     size_t * __restrict nresult, struct iconv_hooks *hooks)
96 {
97 
98 	return ((*ce->ce_ops->eo_wctomb)(ce, s, n, wc, ps, nresult, hooks));
99 }
100 
101 static __inline int
102 _citrus_stdenc_put_state_reset(struct _citrus_stdenc * __restrict ce,
103     char * __restrict s, size_t n, void * __restrict ps,
104     size_t * __restrict nresult)
105 {
106 
107 	return ((*ce->ce_ops->eo_put_state_reset)(ce, s, n, ps, nresult));
108 }
109 
110 static __inline size_t
111 _citrus_stdenc_get_state_size(struct _citrus_stdenc *ce)
112 {
113 
114 	return (ce->ce_traits->et_state_size);
115 }
116 
117 static __inline size_t
118 _citrus_stdenc_get_mb_cur_min(struct _citrus_stdenc *ce)
119 {
120 
121 	return (ce->ce_traits->et_mb_cur_min);
122 }
123 
124 static __inline size_t
125 _citrus_stdenc_get_mb_cur_max(struct _citrus_stdenc *ce)
126 {
127 
128 	return (ce->ce_traits->et_mb_cur_max);
129 }
130 
131 static __inline int
132 _citrus_stdenc_get_state_desc(struct _citrus_stdenc * __restrict ce,
133     void * __restrict ps, int id,
134     struct _citrus_stdenc_state_desc * __restrict d)
135 {
136 
137 	return ((*ce->ce_ops->eo_get_state_desc)(ce, ps, id, d));
138 }
139 #endif
140