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