xref: /dragonfly/lib/libc/citrus/citrus_mapper.h (revision dadd6466)
1 /* $FreeBSD: head/lib/libc/iconv/citrus_mapper.h 219019 2011-02-25 00:04:39Z gabor $ */
2 /* $NetBSD: citrus_mapper.h,v 1.3 2003/07/12 15:39:19 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 #ifndef _CITRUS_MAPPER_H_
31 #define _CITRUS_MAPPER_H_
32 
33 struct _citrus_mapper_area;
34 struct _citrus_mapper;
35 struct _citrus_mapper_ops;
36 struct _citrus_mapper_traits;
37 
38 __BEGIN_DECLS
39 int	 _citrus_mapper_create_area(
40 	    struct _citrus_mapper_area *__restrict *__restrict,
41 	    const char *__restrict);
42 int	 _citrus_mapper_open(struct _citrus_mapper_area *__restrict,
43 	    struct _citrus_mapper *__restrict *__restrict,
44 	    const char *__restrict);
45 int	 _citrus_mapper_open_direct(
46 	    struct _citrus_mapper_area *__restrict,
47 	    struct _citrus_mapper *__restrict *__restrict,
48 	    const char *__restrict, const char *__restrict);
49 void	 _citrus_mapper_close(struct _citrus_mapper *);
50 void	 _citrus_mapper_set_persistent(struct _citrus_mapper * __restrict);
51 __END_DECLS
52 
53 #include "citrus_mapper_local.h"
54 
55 /* return values of _citrus_mapper_convert */
56 #define _CITRUS_MAPPER_CONVERT_SUCCESS		(0)
57 #define _CITRUS_MAPPER_CONVERT_NONIDENTICAL	(1)
58 #define _CITRUS_MAPPER_CONVERT_SRC_MORE		(2)
59 #define _CITRUS_MAPPER_CONVERT_DST_MORE		(3)
60 #define _CITRUS_MAPPER_CONVERT_ILSEQ		(4)
61 #define _CITRUS_MAPPER_CONVERT_FATAL		(5)
62 
63 /*
64  * _citrus_mapper_convert:
65  *	convert an index.
66  *	- if the converter supports M:1 converter, the function may return
67  *	  _CITRUS_MAPPER_CONVERT_SRC_MORE and the storage pointed by dst
68  *	  may be unchanged in this case, although the internal status of
69  *	  the mapper is affected.
70  *	- if the converter supports 1:N converter, the function may return
71  *	  _CITRUS_MAPPER_CONVERT_DST_MORE. In this case, the contiguous
72  *	  call of this function ignores src and changes the storage pointed
73  *	  by dst.
74  *	- if the converter supports M:N converter, the function may behave
75  *	  the combination of the above.
76  *
77  */
78 static __inline int
79 _citrus_mapper_convert(struct _citrus_mapper * __restrict cm,
80     _citrus_index_t * __restrict dst, _citrus_index_t src,
81     void * __restrict ps)
82 {
83 
84 	return ((*cm->cm_ops->mo_convert)(cm, dst, src, ps));
85 }
86 
87 /*
88  * _citrus_mapper_init_state:
89  *	initialize the state.
90  */
91 static __inline void
92 _citrus_mapper_init_state(struct _citrus_mapper * __restrict cm)
93 {
94 
95 	(*cm->cm_ops->mo_init_state)();
96 }
97 
98 /*
99  * _citrus_mapper_get_state_size:
100  *	get the size of state storage.
101  */
102 static __inline size_t
103 _citrus_mapper_get_state_size(struct _citrus_mapper * __restrict cm)
104 {
105 
106 	return (cm->cm_traits->mt_state_size);
107 }
108 
109 /*
110  * _citrus_mapper_get_src_max:
111  *	get the maximum number of suspended sources.
112  */
113 static __inline size_t
114 _citrus_mapper_get_src_max(struct _citrus_mapper * __restrict cm)
115 {
116 
117 	return (cm->cm_traits->mt_src_max);
118 }
119 
120 /*
121  * _citrus_mapper_get_dst_max:
122  *	get the maximum number of suspended destinations.
123  */
124 static __inline size_t
125 _citrus_mapper_get_dst_max(struct _citrus_mapper * __restrict cm)
126 {
127 
128 	return (cm->cm_traits->mt_dst_max);
129 }
130 
131 #endif
132