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