Update.
[glibc.git] / iconv / gconv_int.h
blobd9edcb079f1613dde0b87feb3079a68b8ce317c9
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 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"
25 __BEGIN_DECLS
28 /* Type to represent search path. */
29 struct path_elem
31 const char *name;
32 size_t len;
35 /* Variable with search path for `gconv' implementation. */
36 extern struct path_elem *__gconv_path_elem;
37 /* Maximum length of a single path element. */
38 extern size_t __gconv_max_path_elem_len;
41 /* Structure for alias definition. Simply two strings. */
42 struct gconv_alias
44 char *fromname;
45 char *toname;
49 /* How many character should be conveted in one call? */
50 #define GCONV_NCHAR_GOAL 8160
53 /* Structure describing one loaded shared object. This normally are
54 objects to perform conversation but as a special case the db shared
55 object is also handled. */
56 struct __gconv_loaded_object
58 /* Name of the object. It must be the first structure element. */
59 const char *name;
61 /* Reference counter for the db functionality. If no conversion is
62 needed we unload the db library. */
63 int counter;
65 /* The handle for the shared object. */
66 void *handle;
68 /* Pointer to the functions the module defines. */
69 __gconv_fct fct;
70 __gconv_init_fct init_fct;
71 __gconv_end_fct end_fct;
75 /* Description for an available conversion module. */
76 struct gconv_module
78 const char *from_string;
79 const char *to_string;
81 int cost_hi;
82 int cost_lo;
84 const char *module_name;
86 struct gconv_module *left; /* Prefix smaller. */
87 struct gconv_module *same; /* List of entries with identical prefix. */
88 struct gconv_module *right; /* Prefix larger. */
92 /* Internal data structure to represent transliteration module. */
93 struct trans_struct
95 const char *name;
96 struct trans_struct *next;
98 const char **csnames;
99 size_t ncsnames;
100 __gconv_trans_fct trans_fct;
101 __gconv_trans_context_fct trans_context_fct;
102 __gconv_trans_init_fct trans_init_fct;
103 __gconv_trans_end_fct trans_end_fct;
107 /* Flags for `gconv_open'. */
108 enum
110 GCONV_AVOID_NOCONV = 1 << 0
114 /* Global variables. */
116 /* Database of alias names. */
117 extern void *__gconv_alias_db;
119 /* Array with available modules. */
120 extern size_t __gconv_nmodules;
121 extern struct gconv_module *__gconv_modules_db;
123 /* Value of the GCONV_PATH environment variable. */
124 extern const char *__gconv_path_envvar;
127 /* The gconv functions expects the name to be in upper case and complete,
128 including the trailing slashes if necessary. */
129 #define norm_add_slashes(str,suffix) \
130 ({ \
131 const char *cp = (str); \
132 char *result; \
133 char *tmp; \
134 size_t cnt = 0; \
135 size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix); \
137 while (*cp != '\0') \
138 if (*cp++ == '/') \
139 ++cnt; \
141 tmp = result = alloca (cp - (str) + 3 + suffix_len); \
142 cp = (str); \
143 while (*cp != '\0') \
144 *tmp++ = __toupper_l (*cp++, &_nl_C_locobj); \
145 if (cnt < 2) \
147 *tmp++ = '/'; \
148 if (cnt < 1) \
150 *tmp++ = '/'; \
151 if (suffix != NULL) \
152 tmp = __mempcpy (tmp, suffix, suffix_len); \
155 *tmp = '\0'; \
156 result; \
160 /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
161 extern int __gconv_open (const char *toset, const char *fromset,
162 __gconv_t *handle, int flags)
163 internal_function;
165 /* Free resources associated with transformation descriptor CD. */
166 extern int __gconv_close (__gconv_t cd)
167 internal_function;
169 /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
170 according to rules described by CD and place up to *OUTBYTESLEFT
171 bytes in buffer starting at *OUTBUF. Return number of non-identical
172 conversions in *IRREVERSIBLE if this pointer is not null. */
173 extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
174 const unsigned char *inbufend, unsigned char **outbuf,
175 unsigned char *outbufend, size_t *irreversible)
176 internal_function;
178 /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
179 the single steps necessary for transformation from FROMSET to TOSET. */
180 extern int __gconv_find_transform (const char *toset, const char *fromset,
181 struct __gconv_step **handle,
182 size_t *nsteps, int flags)
183 internal_function;
185 /* Search for transformation in cache data. */
186 extern int __gconv_lookup_cache (const char *toset, const char *fromset,
187 struct __gconv_step **handle, size_t *nsteps,
188 int flags)
189 internal_function;
191 /* Compare the two name for whether they are after alias expansion the
192 same. This function uses the cache and fails if none is
193 loaded. */
194 extern int __gconv_compare_alias_cache (const char *name1, const char *name2,
195 int *result) internal_function;
197 /* Free data associated with a step's structure. */
198 extern void __gconv_release_step (struct __gconv_step *step)
199 internal_function;
201 /* Read all the configuration data and cache it. */
202 extern void __gconv_read_conf (void);
204 /* Try to read module cache file. */
205 extern int __gconv_load_cache (void) internal_function;
207 /* Determine the directories we are looking in. */
208 extern void __gconv_get_path (void);
210 /* Comparison function to search alias. */
211 extern int __gconv_alias_compare (const void *p1, const void *p2);
213 /* Clear reference to transformation step implementations which might
214 cause the code to be unloaded. */
215 extern int __gconv_close_transform (struct __gconv_step *steps,
216 size_t nsteps)
217 internal_function;
219 /* Free all resources allocated for the transformation record when
220 using the cache. */
221 extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
222 internal_function;
224 /* Load shared object named by NAME. If already loaded increment reference
225 count. */
226 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
227 internal_function;
229 /* Release shared object. If no further reference is available unload
230 the object. */
231 extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
232 internal_function;
234 /* Fill STEP with information about builtin module with NAME. */
235 extern void __gconv_get_builtin_trans (const char *name,
236 struct __gconv_step *step)
237 internal_function;
239 /* Try to load transliteration step module. */
240 extern int __gconv_translit_find (struct trans_struct *trans)
241 internal_function;
243 /* Transliteration using the locale's data. */
244 extern int __gconv_transliterate (struct __gconv_step *step,
245 struct __gconv_step_data *step_data,
246 void *trans_data,
247 __const unsigned char *inbufstart,
248 __const unsigned char **inbufp,
249 __const unsigned char *inbufend,
250 unsigned char **outbufstart,
251 size_t *irreversible);
254 /* Builtin transformations. */
255 #ifdef _LIBC
256 # define __BUILTIN_TRANS(Name) \
257 extern int Name (struct __gconv_step *step, \
258 struct __gconv_step_data *data, \
259 const unsigned char **inbuf, \
260 const unsigned char *inbufend, \
261 unsigned char **outbufstart, size_t *irreversible, \
262 int do_flush, int consume_incomplete)
264 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
265 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
266 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
267 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
268 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
269 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
270 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
271 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
272 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
273 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
274 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
275 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
276 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
277 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
278 # undef __BUITLIN_TRANS
280 #endif
282 __END_DECLS
284 #endif /* gconv_int.h */