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