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