]>
Commit | Line | Data |
---|---|---|
dd9423a6 | 1 | /* Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc. |
e62c19f1 UD |
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 | |
41bdb6e2 AJ |
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. | |
e62c19f1 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
e62c19f1 | 14 | |
41bdb6e2 AJ |
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. */ | |
e62c19f1 UD |
19 | |
20 | #ifndef _GCONV_INT_H | |
21 | #define _GCONV_INT_H 1 | |
22 | ||
23 | #include "gconv.h" | |
c5738211 | 24 | #include <stdlib.h> /* For alloca used in macro below. */ |
e62c19f1 UD |
25 | |
26 | __BEGIN_DECLS | |
27 | ||
28 | ||
d6204268 UD |
29 | /* Type to represent search path. */ |
30 | struct path_elem | |
31 | { | |
32 | const char *name; | |
33 | size_t len; | |
34 | }; | |
35 | ||
36 | /* Variable with search path for `gconv' implementation. */ | |
aa32f798 | 37 | extern struct path_elem *__gconv_path_elem attribute_hidden; |
d6204268 | 38 | /* Maximum length of a single path element. */ |
aa32f798 | 39 | extern size_t __gconv_max_path_elem_len attribute_hidden; |
d6204268 UD |
40 | |
41 | ||
9a321276 | 42 | /* Structure for alias definition. Simply two strings. */ |
e62c19f1 UD |
43 | struct gconv_alias |
44 | { | |
17427edd UD |
45 | char *fromname; |
46 | char *toname; | |
e62c19f1 UD |
47 | }; |
48 | ||
49 | ||
8619129f UD |
50 | /* How many character should be conveted in one call? */ |
51 | #define GCONV_NCHAR_GOAL 8160 | |
e62c19f1 UD |
52 | |
53 | ||
0d9f6793 UD |
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. */ | |
d64b6ad0 | 57 | struct __gconv_loaded_object |
0d9f6793 | 58 | { |
b79f74cd | 59 | /* Name of the object. It must be the first structure element. */ |
0d9f6793 UD |
60 | const char *name; |
61 | ||
62 | /* Reference counter for the db functionality. If no conversion is | |
63 | needed we unload the db library. */ | |
64 | int counter; | |
65 | ||
66 | /* The handle for the shared object. */ | |
b3fc5f84 | 67 | void *handle; |
0d9f6793 UD |
68 | |
69 | /* Pointer to the functions the module defines. */ | |
d64b6ad0 UD |
70 | __gconv_fct fct; |
71 | __gconv_init_fct init_fct; | |
72 | __gconv_end_fct end_fct; | |
0d9f6793 UD |
73 | }; |
74 | ||
75 | ||
e62c19f1 UD |
76 | /* Description for an available conversion module. */ |
77 | struct gconv_module | |
78 | { | |
d2dfc5de | 79 | const char *from_string; |
0d9f6793 | 80 | const char *to_string; |
e62c19f1 | 81 | |
fab6d621 UD |
82 | int cost_hi; |
83 | int cost_lo; | |
e62c19f1 | 84 | |
0d9f6793 | 85 | const char *module_name; |
2bd60880 UD |
86 | |
87 | struct gconv_module *left; /* Prefix smaller. */ | |
88 | struct gconv_module *same; /* List of entries with identical prefix. */ | |
2bd60880 | 89 | struct gconv_module *right; /* Prefix larger. */ |
e62c19f1 UD |
90 | }; |
91 | ||
92 | ||
d6204268 UD |
93 | /* Internal data structure to represent transliteration module. */ |
94 | struct trans_struct | |
95 | { | |
96 | const char *name; | |
97 | struct trans_struct *next; | |
98 | ||
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; | |
105 | }; | |
106 | ||
107 | ||
c90a2db6 UD |
108 | /* Flags for `gconv_open'. */ |
109 | enum | |
110 | { | |
111 | GCONV_AVOID_NOCONV = 1 << 0 | |
112 | }; | |
113 | ||
114 | ||
e62c19f1 UD |
115 | /* Global variables. */ |
116 | ||
117 | /* Database of alias names. */ | |
230491f0 | 118 | extern void *__gconv_alias_db attribute_hidden; |
e62c19f1 UD |
119 | |
120 | /* Array with available modules. */ | |
121 | extern size_t __gconv_nmodules; | |
230491f0 | 122 | extern struct gconv_module *__gconv_modules_db attribute_hidden; |
e62c19f1 | 123 | |
6b98979f | 124 | /* Value of the GCONV_PATH environment variable. */ |
aa32f798 | 125 | extern const char *__gconv_path_envvar attribute_hidden; |
6b98979f | 126 | |
e62c19f1 | 127 | |
17c389fc UD |
128 | /* The gconv functions expects the name to be in upper case and complete, |
129 | including the trailing slashes if necessary. */ | |
323fb88d | 130 | #define norm_add_slashes(str,suffix) \ |
17c389fc UD |
131 | ({ \ |
132 | const char *cp = (str); \ | |
133 | char *result; \ | |
134 | char *tmp; \ | |
135 | size_t cnt = 0; \ | |
282c98b0 | 136 | size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix); \ |
17c389fc UD |
137 | \ |
138 | while (*cp != '\0') \ | |
139 | if (*cp++ == '/') \ | |
140 | ++cnt; \ | |
141 | \ | |
c5738211 | 142 | tmp = result = __alloca (cp - (str) + 3 + suffix_len); \ |
17c389fc UD |
143 | cp = (str); \ |
144 | while (*cp != '\0') \ | |
5db91571 | 145 | *tmp++ = __toupper_l (*cp++, &_nl_C_locobj); \ |
17c389fc UD |
146 | if (cnt < 2) \ |
147 | { \ | |
148 | *tmp++ = '/'; \ | |
149 | if (cnt < 1) \ | |
323fb88d UD |
150 | { \ |
151 | *tmp++ = '/'; \ | |
152 | if (suffix != NULL) \ | |
153 | tmp = __mempcpy (tmp, suffix, suffix_len); \ | |
154 | } \ | |
17c389fc UD |
155 | } \ |
156 | *tmp = '\0'; \ | |
157 | result; \ | |
158 | }) | |
159 | ||
160 | ||
e62c19f1 | 161 | /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */ |
55985355 UD |
162 | extern int __gconv_open (const char *toset, const char *fromset, |
163 | __gconv_t *handle, int flags) | |
e62c19f1 UD |
164 | internal_function; |
165 | ||
166 | /* Free resources associated with transformation descriptor CD. */ | |
d64b6ad0 | 167 | extern int __gconv_close (__gconv_t cd) |
e62c19f1 UD |
168 | internal_function; |
169 | ||
170 | /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF | |
171 | according to rules described by CD and place up to *OUTBYTESLEFT | |
63e04088 | 172 | bytes in buffer starting at *OUTBUF. Return number of non-identical |
38677ace | 173 | conversions in *IRREVERSIBLE if this pointer is not null. */ |
55985355 UD |
174 | extern int __gconv (__gconv_t cd, const unsigned char **inbuf, |
175 | const unsigned char *inbufend, unsigned char **outbuf, | |
38677ace | 176 | unsigned char *outbufend, size_t *irreversible) |
e62c19f1 UD |
177 | internal_function; |
178 | ||
179 | /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing | |
180 | the single steps necessary for transformation from FROMSET to TOSET. */ | |
55985355 UD |
181 | extern int __gconv_find_transform (const char *toset, const char *fromset, |
182 | struct __gconv_step **handle, | |
183 | size_t *nsteps, int flags) | |
e62c19f1 UD |
184 | internal_function; |
185 | ||
6b98979f UD |
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; | |
191 | ||
9a018f6c UD |
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; | |
197 | ||
6b98979f UD |
198 | /* Free data associated with a step's structure. */ |
199 | extern void __gconv_release_step (struct __gconv_step *step) | |
200 | internal_function; | |
201 | ||
e62c19f1 | 202 | /* Read all the configuration data and cache it. */ |
dff07c4b | 203 | extern void __gconv_read_conf (void) attribute_hidden; |
e62c19f1 | 204 | |
6b98979f UD |
205 | /* Try to read module cache file. */ |
206 | extern int __gconv_load_cache (void) internal_function; | |
207 | ||
230491f0 UD |
208 | /* Retrieve pointer to internal cache. */ |
209 | extern void *__gconv_get_cache (void); | |
210 | ||
211 | /* Retrieve pointer to internal module database. */ | |
212 | extern struct gconv_module *__gconv_get_modules_db (void); | |
213 | ||
214 | /* Retrieve pointer to internal alias database. */ | |
215 | extern void *__gconv_get_alias_db (void); | |
216 | ||
d6204268 | 217 | /* Determine the directories we are looking in. */ |
dff07c4b | 218 | extern void __gconv_get_path (void) internal_function; |
d6204268 | 219 | |
e62c19f1 | 220 | /* Comparison function to search alias. */ |
dff07c4b UD |
221 | extern int __gconv_alias_compare (const void *p1, const void *p2) |
222 | attribute_hidden; | |
e62c19f1 UD |
223 | |
224 | /* Clear reference to transformation step implementations which might | |
225 | cause the code to be unloaded. */ | |
55985355 UD |
226 | extern int __gconv_close_transform (struct __gconv_step *steps, |
227 | size_t nsteps) | |
e62c19f1 UD |
228 | internal_function; |
229 | ||
0db59742 UD |
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; | |
234 | ||
e62c19f1 UD |
235 | /* Load shared object named by NAME. If already loaded increment reference |
236 | count. */ | |
55985355 | 237 | extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name) |
e62c19f1 UD |
238 | internal_function; |
239 | ||
240 | /* Release shared object. If no further reference is available unload | |
241 | the object. */ | |
b79f74cd | 242 | extern void __gconv_release_shlib (struct __gconv_loaded_object *handle) |
e62c19f1 UD |
243 | internal_function; |
244 | ||
245 | /* Fill STEP with information about builtin module with NAME. */ | |
55985355 UD |
246 | extern void __gconv_get_builtin_trans (const char *name, |
247 | struct __gconv_step *step) | |
e62c19f1 UD |
248 | internal_function; |
249 | ||
d6204268 UD |
250 | /* Try to load transliteration step module. */ |
251 | extern int __gconv_translit_find (struct trans_struct *trans) | |
252 | internal_function; | |
253 | ||
55985355 | 254 | /* Transliteration using the locale's data. */ |
f1d5c60d UD |
255 | extern int __gconv_transliterate (struct __gconv_step *step, |
256 | struct __gconv_step_data *step_data, | |
d6204268 | 257 | void *trans_data, |
f1d5c60d UD |
258 | __const unsigned char *inbufstart, |
259 | __const unsigned char **inbufp, | |
260 | __const unsigned char *inbufend, | |
261 | unsigned char **outbufstart, | |
dff07c4b | 262 | size_t *irreversible) attribute_hidden; |
e62c19f1 UD |
263 | |
264 | ||
dd9423a6 UD |
265 | /* If NAME is an codeset alias expand it. */ |
266 | extern int __gconv_compare_alias (const char *name1, const char *name2) | |
267 | internal_function; | |
268 | ||
269 | ||
e62c19f1 UD |
270 | /* Builtin transformations. */ |
271 | #ifdef _LIBC | |
f9ad060c | 272 | # define __BUILTIN_TRANSFORM(Name) \ |
55985355 UD |
273 | extern int Name (struct __gconv_step *step, \ |
274 | struct __gconv_step_data *data, \ | |
275 | const unsigned char **inbuf, \ | |
f1d5c60d UD |
276 | const unsigned char *inbufend, \ |
277 | unsigned char **outbufstart, size_t *irreversible, \ | |
278 | int do_flush, int consume_incomplete) | |
e62c19f1 | 279 | |
f9ad060c UD |
280 | __BUILTIN_TRANSFORM (__gconv_transform_ascii_internal); |
281 | __BUILTIN_TRANSFORM (__gconv_transform_internal_ascii); | |
282 | __BUILTIN_TRANSFORM (__gconv_transform_utf8_internal); | |
283 | __BUILTIN_TRANSFORM (__gconv_transform_internal_utf8); | |
284 | __BUILTIN_TRANSFORM (__gconv_transform_ucs2_internal); | |
285 | __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2); | |
286 | __BUILTIN_TRANSFORM (__gconv_transform_ucs2reverse_internal); | |
287 | __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2reverse); | |
288 | __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4); | |
289 | __BUILTIN_TRANSFORM (__gconv_transform_ucs4_internal); | |
290 | __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4le); | |
291 | __BUILTIN_TRANSFORM (__gconv_transform_ucs4le_internal); | |
292 | __BUILTIN_TRANSFORM (__gconv_transform_internal_utf16); | |
293 | __BUILTIN_TRANSFORM (__gconv_transform_utf16_internal); | |
294 | # undef __BUITLIN_TRANSFORM | |
295 | ||
296 | /* Specialized conversion function for a single byte to INTERNAL, recognizing | |
297 | only ASCII characters. */ | |
298 | extern wint_t __gconv_btwoc_ascii (struct __gconv_step *step, unsigned char c); | |
e62c19f1 | 299 | |
e62c19f1 UD |
300 | #endif |
301 | ||
302 | __END_DECLS | |
303 | ||
304 | #endif /* gconv_int.h */ |