2 * Copyright (c) 2003-2004, Artem B. Bityuckiy
3 * Copyright (c) 1999,2000, Konstantin Chuguev. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #ifndef __ICONV_UCS_CONVERSION_H__
27 #define __ICONV_UCS_CONVERSION_H__
31 #include <sys/types.h>
35 /* No enough space in output buffer */
36 #define ICONV_CES_NOSPACE 0
37 /* Invalid input character */
38 #define ICONV_CES_INVALID_CHARACTER -1
39 /* No corespondent character in destination encoding */
40 #define ICONV_CES_BAD_SEQUENCE -2
41 /* All unknown characters are marked by this code */
42 #define DEFAULT_CHARACTER 0x3f /* ASCII '?' */
46 * iconv_to_ucs_ces_handlers_t - "to UCS" CES converter handlers.
48 * Structure contains function pointers which should be provided by
49 * "to_ucs" CES converter.
51 * ============================================================================
56 * init - initialize CES converter.
59 * struct _reent *rptr - reent structure of current thread/process;
60 * _CONST char *encoding - encoding name.
63 * Initializes CES converter. CES converter may deal with a series of
64 * encodings, such as Table or EUC CES converters. 'encoding' parameter
65 * indicates which encoding CES converter should use.
68 * Returns CES-specific data pointer if success. In case of error returns
69 * NULL and sets current thread's/process's errno.
71 _VOID_PTR _EXPARM(init, (struct _reent *rptr,
72 _CONST char *encoding));
75 * close - close CES converter.
78 * struct _reent *rptr - reent structure of current thread/process;
79 * _VOID_PTR data - CES converter-specific data.
82 * Preforms CES converter closing. *
84 * Returns (size_t)0 if success. In case of error returns (size_t)-1 and
85 * sets current thread's/process's errno.
87 size_t _EXPARM(close, (struct _reent *rptr,
91 * get_mb_cur_max - get maximum character length in bytes.
94 * _VOID_PTR data - conversion-specific data;
97 * Returns encoding's maximum character length.
99 int _EXPARM(get_mb_cur_max, (_VOID_PTR data));
102 * get_state - get current shift state.
105 * _VOID_PTR data - conversion-specific data;
106 * mbstate_t *state - mbstate_t object where shift state will be stored;
109 * Returns encoding's current shift sequence.
111 _VOID _EXPARM(get_state, (_VOID_PTR data,
115 * set_state - set shift state.
118 * _VOID_PTR data - conversion-specific data;
119 * mbstate_t *state - mbstate_t value to which shift state will be set.
122 * Sets encoding's current shift state to 'state'. if 'state'
123 * object is zero-object - reset current shift state.
124 * Returns 0 if '*state' object has right format, -1 else.
126 int _EXPARM(set_state, (_VOID_PTR data,
130 * is_stateful - is encoding stateful state.
133 * _VOID_PTR data - conversion-specific data;
136 * Returns 0 if encoding is stateless, else returns 1.
138 int _EXPARM(is_stateful, (_VOID_PTR data));
141 * convert_to_ucs - convert character to UCS.
144 * _VOID_PTR data - CES converter-specific data;
145 * _CONST unsigned char **inbuf - buffer with input character byte sequence;
146 * size_t *inbytesleft - output buffer bytes count.
149 * Converts input characters into UCS encoding. 'inbuf' is
150 * incremented accordingly. 'bytesleft' is decremented accordingly. Should
151 * be provided by correspondent CES module.
154 * Returns resulting UCS code if success. If input character is invalid,
155 * returns ICONV_CES_INVALID_CHARACTER. If invalid or incomplete bytes
156 * sequence was met, returns ICONV_CES_BAD_SEQUENCE.
158 ucs4_t _EXPARM(convert_to_ucs, (_VOID_PTR data,
159 _CONST unsigned char **inbuf,
160 size_t *inbytesleft));
161 } iconv_to_ucs_ces_handlers_t;
165 * iconv_from_ucs_ces_handlers_t - "from UCS" CES converter handlers.
167 * Structure contains function pointers which should be provided by
168 * "from_ucs" CES converter.
170 * ============================================================================
174 /* Same as in iconv_to_ucs_ces_handlers_t */
175 _VOID_PTR _EXPARM(init, (struct _reent *rptr,
176 _CONST char *encoding));
178 /* Same as in iconv_to_ucs_ces_handlers_t */
179 size_t _EXPARM(close, (struct _reent *rptr,
182 /* Same as in iconv_to_ucs_ces_handlers_t */
183 int _EXPARM(get_mb_cur_max, (_VOID_PTR data));
185 /* Same as in iconv_to_ucs_ces_handlers_t */
186 _VOID _EXPARM(get_state, (_VOID_PTR data,
189 /* Same as in iconv_to_ucs_ces_handlers_t */
190 int _EXPARM(set_state, (_VOID_PTR data,
193 /* Same as in iconv_to_ucs_ces_handlers_t */
194 int _EXPARM(is_stateful, (_VOID_PTR data));
197 * convert_from_ucs - convert UCS character to destination encoding.
200 * _VOID_PTR data - CES converter-specific data;
201 * ucs4_t in - input UCS-4 character;
202 * unsigned char **outbuf - output buffer for the result;
203 * size_t *outbytesleft - output buffer bytes count.
206 * Converts input UCS characters to destination encoding and stores result
207 * in 'outbuf' if there is sufficient free space present. 'outbuf' is
208 * incremented accordingly. 'outbytesleft' is decremented accordingly. Should
209 * be provided by correspondent CES module.
210 * Output buffer always has at least 1 byte.
213 * Returns number of bytes that was written into output buffer if success.
214 * If there is no enough space in output buffer, returns ICONV_CES_NOSPACE.
215 * If there is no corresponding character in destination encoding, returns
216 * ICONV_CES_INVALID_CHARACTER.
218 size_t _EXPARM(convert_from_ucs, (_VOID_PTR data,
220 unsigned char **outbuf,
221 size_t *outbytesleft));
222 } iconv_from_ucs_ces_handlers_t;
226 * iconv_to_ucs_ces_desc_t - "to UCS" CES converter definition structure for
227 * usage in iconv_ucs_conversion_t conversion description structure.
229 * ============================================================================
233 /* CES converter handlers */
234 _CONST iconv_to_ucs_ces_handlers_t *handlers;
236 /* "to_ucs" CES converter-specific data. */
238 } iconv_to_ucs_ces_desc_t;
242 * iconv_from_ucs_ces_desc_t - "from UCS" CES converter definition structure for
243 * usage in iconv_ucs_conversion_t conversion description structure.
245 * ============================================================================
249 /* CES converter handlers */
250 _CONST iconv_from_ucs_ces_handlers_t *handlers;
252 /* "from_ucs" CES converter-specific data. */
254 } iconv_from_ucs_ces_desc_t;
258 * iconv_ucs_conversion_t - UCS-based conversion definition structure.
260 * Defines special type of conversion where every character is first
261 * converted into UCS-4 (UCS-2 for table-driven), and after this the
262 * resulting UCS character is converted to destination encoding.
263 * UCS-based conversion is composed of two *converters*, defined by
264 * iconv_ces_t structure. The iconv_ucs_conversion_t object is referred
265 * from iconv_conversion_t object using 'data' field.
267 * Structure contains two objects - 'to_ucs' and 'from_ucs' which define
268 * "source encoding to UCS" and "UCS to destination encoding" converters.
270 * ============================================================================
274 /* Source encoding -> CES converter. */
275 iconv_to_ucs_ces_desc_t to_ucs;
277 /* UCS -> destination encoding CES converter. */
278 iconv_from_ucs_ces_desc_t from_ucs;
279 } iconv_ucs_conversion_t;
283 * iconv_to_ucs_ces_t - defines "to UCS" CES converter.
285 * ============================================================================
290 * An array of encodings names, supported by CES converter.
291 * The end of array should be marked by NULL pointer.
295 /* CES converter description structure */
296 _CONST iconv_to_ucs_ces_handlers_t *handlers;
297 } iconv_to_ucs_ces_t;
301 * iconv_from_ucs_ces_t - defines "from UCS" CES converter.
303 * ============================================================================
308 * An array of encodings names, supported by CES converter.
309 * The end of array should be marked by NULL pointer.
313 /* CES converter description structure */
314 _CONST iconv_from_ucs_ces_handlers_t *handlers;
315 } iconv_from_ucs_ces_t;
318 /* List of "to UCS" linked-in CES converters. */
319 extern _CONST iconv_to_ucs_ces_t
322 /* List of "from UCS" linked-in CES converters. */
323 extern _CONST iconv_from_ucs_ces_t
324 _iconv_from_ucs_ces[];
326 #endif /* !__ICONV_UCS_CONVERSION_H__ */