Update.
[glibc.git] / iconv / gconv_int.h
blob1ac878d900bbef0c3f3b70ea84f5e9281693aca1
1 /* Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _GCONV_INT_H
21 #define _GCONV_INT_H 1
23 #include "gconv.h"
24 #include <stdlib.h> /* For alloca used in macro below. */
26 __BEGIN_DECLS
29 /* Type to represent search path. */
30 struct path_elem
32 const char *name;
33 size_t len;
36 /* Variable with search path for `gconv' implementation. */
37 extern struct path_elem *__gconv_path_elem attribute_hidden;
38 /* Maximum length of a single path element. */
39 extern size_t __gconv_max_path_elem_len attribute_hidden;
42 /* Structure for alias definition. Simply two strings. */
43 struct gconv_alias
45 char *fromname;
46 char *toname;
50 /* How many character should be conveted in one call? */
51 #define GCONV_NCHAR_GOAL 8160
54 /* Structure describing one loaded shared object. This normally are
55 objects to perform conversation but as a special case the db shared
56 object is also handled. */
57 struct __gconv_loaded_object
59 /* Name of the object. It must be the first structure element. */
60 const char *name;
62 /* Reference counter for the db functionality. If no conversion is
63 needed we unload the db library. */
64 int counter;
66 /* The handle for the shared object. */
67 void *handle;
69 /* Pointer to the functions the module defines. */
70 __gconv_fct fct;
71 __gconv_init_fct init_fct;
72 __gconv_end_fct end_fct;
76 /* Description for an available conversion module. */
77 struct gconv_module
79 const char *from_string;
80 const char *to_string;
82 int cost_hi;
83 int cost_lo;
85 const char *module_name;
87 struct gconv_module *left; /* Prefix smaller. */
88 struct gconv_module *same; /* List of entries with identical prefix. */
89 struct gconv_module *right; /* Prefix larger. */
93 /* Internal data structure to represent transliteration module. */
94 struct trans_struct
96 const char *name;
97 struct trans_struct *next;
99 const char **csnames;
100 size_t ncsnames;
101 __gconv_trans_fct trans_fct;
102 __gconv_trans_context_fct trans_context_fct;
103 __gconv_trans_init_fct trans_init_fct;
104 __gconv_trans_end_fct trans_end_fct;
108 /* Flags for `gconv_open'. */
109 enum
111 GCONV_AVOID_NOCONV = 1 << 0
115 /* Global variables. */
117 /* Database of alias names. */
118 extern void *__gconv_alias_db attribute_hidden;
120 /* Array with available modules. */
121 extern size_t __gconv_nmodules;
122 extern struct gconv_module *__gconv_modules_db attribute_hidden;
124 /* Value of the GCONV_PATH environment variable. */
125 extern const char *__gconv_path_envvar attribute_hidden;
128 /* The gconv functions expects the name to be in upper case and complete,
129 including the trailing slashes if necessary. */
130 #define norm_add_slashes(str,suffix) \
131 ({ \
132 const char *cp = (str); \
133 char *result; \
134 char *tmp; \
135 size_t cnt = 0; \
136 size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix); \
138 while (*cp != '\0') \
139 if (*cp++ == '/') \
140 ++cnt; \
142 tmp = result = __alloca (cp - (str) + 3 + suffix_len); \
143 cp = (str); \
144 while (*cp != '\0') \
145 *tmp++ = __toupper_l (*cp++, &_nl_C_locobj); \
146 if (cnt < 2) \
148 *tmp++ = '/'; \
149 if (cnt < 1) \
151 *tmp++ = '/'; \
152 if (suffix != NULL) \
153 tmp = __mempcpy (tmp, suffix, suffix_len); \
156 *tmp = '\0'; \
157 result; \
161 /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
162 extern int __gconv_open (const char *toset, const char *fromset,
163 __gconv_t *handle, int flags)
164 internal_function;
166 /* Free resources associated with transformation descriptor CD. */
167 extern int __gconv_close (__gconv_t cd)
168 internal_function;
170 /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
171 according to rules described by CD and place up to *OUTBYTESLEFT
172 bytes in buffer starting at *OUTBUF. Return number of non-identical
173 conversions in *IRREVERSIBLE if this pointer is not null. */
174 extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
175 const unsigned char *inbufend, unsigned char **outbuf,
176 unsigned char *outbufend, size_t *irreversible)
177 internal_function;
179 /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
180 the single steps necessary for transformation from FROMSET to TOSET. */
181 extern int __gconv_find_transform (const char *toset, const char *fromset,
182 struct __gconv_step **handle,
183 size_t *nsteps, int flags)
184 internal_function;
186 /* Search for transformation in cache data. */
187 extern int __gconv_lookup_cache (const char *toset, const char *fromset,
188 struct __gconv_step **handle, size_t *nsteps,
189 int flags)
190 internal_function;
192 /* Compare the two name for whether they are after alias expansion the
193 same. This function uses the cache and fails if none is
194 loaded. */
195 extern int __gconv_compare_alias_cache (const char *name1, const char *name2,
196 int *result) internal_function;
198 /* Free data associated with a step's structure. */
199 extern void __gconv_release_step (struct __gconv_step *step)
200 internal_function;
202 /* Read all the configuration data and cache it. */
203 extern void __gconv_read_conf (void) attribute_hidden;
205 /* Try to read module cache file. */
206 extern int __gconv_load_cache (void) internal_function;
208 /* Retrieve pointer to internal cache. */
209 extern void *__gconv_get_cache (void);
211 /* Retrieve pointer to internal module database. */
212 extern struct gconv_module *__gconv_get_modules_db (void);
214 /* Retrieve pointer to internal alias database. */
215 extern void *__gconv_get_alias_db (void);
217 /* Determine the directories we are looking in. */
218 extern void __gconv_get_path (void) internal_function;
220 /* Comparison function to search alias. */
221 extern int __gconv_alias_compare (const void *p1, const void *p2)
222 attribute_hidden;
224 /* Clear reference to transformation step implementations which might
225 cause the code to be unloaded. */
226 extern int __gconv_close_transform (struct __gconv_step *steps,
227 size_t nsteps)
228 internal_function;
230 /* Free all resources allocated for the transformation record when
231 using the cache. */
232 extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
233 internal_function;
235 /* Load shared object named by NAME. If already loaded increment reference
236 count. */
237 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
238 internal_function;
240 /* Release shared object. If no further reference is available unload
241 the object. */
242 extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
243 internal_function;
245 /* Fill STEP with information about builtin module with NAME. */
246 extern void __gconv_get_builtin_trans (const char *name,
247 struct __gconv_step *step)
248 internal_function;
250 /* Try to load transliteration step module. */
251 extern int __gconv_translit_find (struct trans_struct *trans)
252 internal_function;
254 /* Transliteration using the locale's data. */
255 extern int __gconv_transliterate (struct __gconv_step *step,
256 struct __gconv_step_data *step_data,
257 void *trans_data,
258 __const unsigned char *inbufstart,
259 __const unsigned char **inbufp,
260 __const unsigned char *inbufend,
261 unsigned char **outbufstart,
262 size_t *irreversible) attribute_hidden;
265 /* Builtin transformations. */
266 #ifdef _LIBC
267 # define __BUILTIN_TRANS(Name) \
268 extern int Name (struct __gconv_step *step, \
269 struct __gconv_step_data *data, \
270 const unsigned char **inbuf, \
271 const unsigned char *inbufend, \
272 unsigned char **outbufstart, size_t *irreversible, \
273 int do_flush, int consume_incomplete)
275 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
276 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
277 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
278 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
279 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
280 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
281 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
282 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
283 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
284 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
285 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
286 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
287 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
288 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
289 # undef __BUITLIN_TRANS
291 #endif
293 __END_DECLS
295 #endif /* gconv_int.h */