Sync Citrus iconv support with NetBSD.
[dragonfly.git] / lib / libc / citrus / citrus_mapper.h
blob2fe4f67e7f766250e60c047e0d87c32baa5afdd5
1 /* $NetBSD: src/lib/libc/citrus/citrus_mapper.h,v 1.3 2003/07/12 15:39:19 tshiozak Exp $ */
2 /* $DragonFly: src/lib/libc/citrus/citrus_mapper.h,v 1.2 2008/04/10 10:21:01 hasso Exp $ */
4 /*-
5 * Copyright (c)2003 Citrus Project,
6 * All rights reserved.
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.
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.
30 #ifndef _CITRUS_MAPPER_H_
31 #define _CITRUS_MAPPER_H_
33 struct _citrus_mapper_area;
34 struct _citrus_mapper;
35 struct _citrus_mapper_ops;
36 struct _citrus_mapper_traits;
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
53 #include "citrus_mapper_local.h"
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)
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.
78 static __inline int
79 _citrus_mapper_convert(struct _citrus_mapper * __restrict cm,
80 _citrus_index_t * __restrict dst,
81 _citrus_index_t src,
82 void * __restrict ps)
85 _DIAGASSERT(cm && cm->cm_ops && cm->cm_ops->mo_convert && dst);
87 return (*cm->cm_ops->mo_convert)(cm, dst, src, ps);
91 * _citrus_mapper_init_state:
92 * initialize the state.
94 static __inline void
95 _citrus_mapper_init_state(struct _citrus_mapper * __restrict cm,
96 void * __restrict ps)
99 _DIAGASSERT(cm && cm->cm_ops && cm->cm_ops->mo_init_state);
101 (*cm->cm_ops->mo_init_state)(cm, ps);
105 * _citrus_mapper_get_state_size:
106 * get the size of state storage.
108 static __inline size_t
109 _citrus_mapper_get_state_size(struct _citrus_mapper * __restrict cm)
112 _DIAGASSERT(cm && cm->cm_traits);
114 return cm->cm_traits->mt_state_size;
118 * _citrus_mapper_get_src_max:
119 * get the maximum number of suspended sources.
121 static __inline size_t
122 _citrus_mapper_get_src_max(struct _citrus_mapper * __restrict cm)
125 _DIAGASSERT(cm && cm->cm_traits);
127 return cm->cm_traits->mt_src_max;
131 * _citrus_mapper_get_dst_max:
132 * get the maximum number of suspended destinations.
134 static __inline size_t
135 _citrus_mapper_get_dst_max(struct _citrus_mapper * __restrict cm)
138 _DIAGASSERT(cm && cm->cm_traits);
140 return cm->cm_traits->mt_dst_max;
143 #endif