]> git.ipfire.org Git - thirdparty/glibc.git/blob - iconv/gconv_int.h
Update.
[thirdparty/glibc.git] / iconv / gconv_int.h
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.
4
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.
9
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.
14
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. */
19
20 #ifndef _GCONV_INT_H
21 #define _GCONV_INT_H 1
22
23 #include "gconv.h"
24
25 __BEGIN_DECLS
26
27
28 /* Type to represent search path. */
29 struct path_elem
30 {
31 const char *name;
32 size_t len;
33 };
34
35 /* Variable with search path for `gconv' implementation. */
36 extern struct path_elem *__gconv_path_elem attribute_hidden;
37 /* Maximum length of a single path element. */
38 extern size_t __gconv_max_path_elem_len attribute_hidden;
39
40
41 /* Structure for alias definition. Simply two strings. */
42 struct gconv_alias
43 {
44 char *fromname;
45 char *toname;
46 };
47
48
49 /* How many character should be conveted in one call? */
50 #define GCONV_NCHAR_GOAL 8160
51
52
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
57 {
58 /* Name of the object. It must be the first structure element. */
59 const char *name;
60
61 /* Reference counter for the db functionality. If no conversion is
62 needed we unload the db library. */
63 int counter;
64
65 /* The handle for the shared object. */
66 void *handle;
67
68 /* Pointer to the functions the module defines. */
69 __gconv_fct fct;
70 __gconv_init_fct init_fct;
71 __gconv_end_fct end_fct;
72 };
73
74
75 /* Description for an available conversion module. */
76 struct gconv_module
77 {
78 const char *from_string;
79 const char *to_string;
80
81 int cost_hi;
82 int cost_lo;
83
84 const char *module_name;
85
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. */
89 };
90
91
92 /* Internal data structure to represent transliteration module. */
93 struct trans_struct
94 {
95 const char *name;
96 struct trans_struct *next;
97
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;
104 };
105
106
107 /* Flags for `gconv_open'. */
108 enum
109 {
110 GCONV_AVOID_NOCONV = 1 << 0
111 };
112
113
114 /* Global variables. */
115
116 /* Database of alias names. */
117 extern void *__gconv_alias_db;
118
119 /* Array with available modules. */
120 extern size_t __gconv_nmodules;
121 extern struct gconv_module *__gconv_modules_db;
122
123 /* Value of the GCONV_PATH environment variable. */
124 extern const char *__gconv_path_envvar attribute_hidden;
125
126
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); \
136 \
137 while (*cp != '\0') \
138 if (*cp++ == '/') \
139 ++cnt; \
140 \
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) \
146 { \
147 *tmp++ = '/'; \
148 if (cnt < 1) \
149 { \
150 *tmp++ = '/'; \
151 if (suffix != NULL) \
152 tmp = __mempcpy (tmp, suffix, suffix_len); \
153 } \
154 } \
155 *tmp = '\0'; \
156 result; \
157 })
158
159
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;
164
165 /* Free resources associated with transformation descriptor CD. */
166 extern int __gconv_close (__gconv_t cd)
167 internal_function;
168
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;
177
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;
184
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;
190
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;
196
197 /* Free data associated with a step's structure. */
198 extern void __gconv_release_step (struct __gconv_step *step)
199 internal_function;
200
201 /* Read all the configuration data and cache it. */
202 extern void __gconv_read_conf (void);
203
204 /* Try to read module cache file. */
205 extern int __gconv_load_cache (void) internal_function;
206
207 /* Determine the directories we are looking in. */
208 extern void __gconv_get_path (void);
209
210 /* Comparison function to search alias. */
211 extern int __gconv_alias_compare (const void *p1, const void *p2);
212
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;
218
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;
223
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;
228
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;
233
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;
238
239 /* Try to load transliteration step module. */
240 extern int __gconv_translit_find (struct trans_struct *trans)
241 internal_function;
242
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);
252
253
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)
263
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
279
280 #endif
281
282 __END_DECLS
283
284 #endif /* gconv_int.h */