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
21 #define _GCONV_INT_H 1
24 #include <libc-symbols.h>
29 /* Type to represent search path. */
36 /* Variable with search path for `gconv' implementation. */
37 extern struct path_elem *__gconv_path_elem;
38 /* Maximum length of a single path element. */
39 extern size_t __gconv_max_path_elem_len;
42 /* Structure for alias definition. Simply two strings. */
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. */
62 /* Reference counter for the db functionality. If no conversion is
63 needed we unload the db library. */
66 /* The handle for the shared object. */
69 /* Pointer to the functions the module defines. */
71 __gconv_init_fct init_fct;
72 __gconv_end_fct end_fct;
76 /* Description for an available conversion module. */
79 const char *from_string;
80 const char *to_string;
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. */
97 struct trans_struct *next;
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'. */
111 GCONV_AVOID_NOCONV = 1 << 0
115 /* Global variables. */
117 /* Database of alias names. */
118 extern void *__gconv_alias_db;
120 /* Array with available modules. */
121 extern size_t __gconv_nmodules;
122 extern struct gconv_module *__gconv_modules_db;
124 /* Value of the GCONV_PATH environment variable. */
125 extern const char *__gconv_path_envvar;
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) \
132 const char *cp = (str); \
136 size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix); \
138 while (*cp != '\0') \
142 tmp = result = alloca (cp - (str) + 3 + suffix_len); \
144 while (*cp != '\0') \
145 *tmp++ = __toupper_l (*cp++, &_nl_C_locobj); \
152 if (suffix != NULL) \
154 tmp = memcpy (tmp, suffix, suffix_len); \
164 /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
165 extern int __gconv_open (const char *toset, const char *fromset,
166 __gconv_t *handle, int flags)
169 /* Free resources associated with transformation descriptor CD. */
170 extern int __gconv_close (__gconv_t cd)
173 /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
174 according to rules described by CD and place up to *OUTBYTESLEFT
175 bytes in buffer starting at *OUTBUF. Return number of non-identical
176 conversions in *IRREVERSIBLE if this pointer is not null. */
177 extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
178 const unsigned char *inbufend, unsigned char **outbuf,
179 unsigned char *outbufend, size_t *irreversible)
182 /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
183 the single steps necessary for transformation from FROMSET to TOSET. */
184 extern int __gconv_find_transform (const char *toset, const char *fromset,
185 struct __gconv_step **handle,
186 size_t *nsteps, int flags)
189 /* Search for transformation in cache data. */
190 extern int __gconv_lookup_cache (const char *toset, const char *fromset,
191 struct __gconv_step **handle, size_t *nsteps,
195 /* Compare the two name for whether they are after alias expansion the
196 same. This function uses the cache and fails if none is
198 extern int __gconv_compare_alias_cache (const char *name1, const char *name2,
199 int *result) internal_function;
201 /* Free data associated with a step's structure. */
202 extern void __gconv_release_step (struct __gconv_step *step)
205 /* Read all the configuration data and cache it. */
206 extern void __gconv_read_conf (void);
208 /* Try to read module cache file. */
209 extern int __gconv_load_cache (void) internal_function;
211 /* Determine the directories we are looking in. */
212 extern void __gconv_get_path (void);
214 /* Comparison function to search alias. */
215 extern int __gconv_alias_compare (const void *p1, const void *p2);
217 /* Clear reference to transformation step implementations which might
218 cause the code to be unloaded. */
219 extern int __gconv_close_transform (struct __gconv_step *steps,
223 /* Free all resources allocated for the transformation record when
225 extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
228 /* Load shared object named by NAME. If already loaded increment reference
230 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
233 /* Release shared object. If no further reference is available unload
235 extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
238 /* Fill STEP with information about builtin module with NAME. */
239 extern void __gconv_get_builtin_trans (const char *name,
240 struct __gconv_step *step)
243 /* Try to load transliteration step module. */
244 extern int __gconv_translit_find (struct trans_struct *trans)
247 /* Transliteration using the locale's data. */
248 extern int __gconv_transliterate (struct __gconv_step *step,
249 struct __gconv_step_data *step_data,
251 __const unsigned char *inbufstart,
252 __const unsigned char **inbufp,
253 __const unsigned char *inbufend,
254 unsigned char **outbufstart,
255 size_t *irreversible);
258 /* Builtin transformations. */
260 # define __BUILTIN_TRANS(Name) \
261 extern int Name (struct __gconv_step *step, \
262 struct __gconv_step_data *data, \
263 const unsigned char **inbuf, \
264 const unsigned char *inbufend, \
265 unsigned char **outbufstart, size_t *irreversible, \
266 int do_flush, int consume_incomplete)
268 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
269 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
270 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
271 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
272 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
273 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
274 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
275 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
276 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
277 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
278 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
279 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
280 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
281 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
282 # undef __BUITLIN_TRANS
288 #endif /* gconv_int.h */