]> 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 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #ifndef _GCONV_INT_H
21 #define _GCONV_INT_H 1
22
23 #include "gconv.h"
24 #include <regex.h>
25
26 __BEGIN_DECLS
27
28
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. */
37 extern const struct path_elem *__gconv_path_elem;
38 /* Maximum length of a single path element. */
39 extern size_t __gconv_max_path_elem_len;
40
41
42 /* Structure for alias definition. Simply to strings. */
43 struct gconv_alias
44 {
45 const char *fromname;
46 const char *toname;
47 };
48
49
50 /* How many character should be conveted in one call? */
51 #define GCONV_NCHAR_GOAL 8160
52
53
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
58 {
59 /* Name of the object. */
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. */
67 void *handle;
68
69 /* Pointer to the functions the module defines. */
70 __gconv_fct fct;
71 __gconv_init_fct init_fct;
72 __gconv_end_fct end_fct;
73 };
74
75
76 /* Description for an available conversion module. */
77 struct gconv_module
78 {
79 const char *from_pattern;
80 const char *from_constpfx;
81 size_t from_constpfx_len;
82 const regex_t *from_regex;
83 regex_t from_regex_mem;
84
85 const char *to_string;
86
87 int cost_hi;
88 int cost_lo;
89
90 const char *module_name;
91
92 struct gconv_module *left; /* Prefix smaller. */
93 struct gconv_module *same; /* List of entries with identical prefix. */
94 struct gconv_module *matching;/* Next node with more specific prefix. */
95 struct gconv_module *right; /* Prefix larger. */
96 };
97
98
99 /* Internal data structure to represent transliteration module. */
100 struct trans_struct
101 {
102 const char *name;
103 struct trans_struct *next;
104
105 const char **csnames;
106 size_t ncsnames;
107 __gconv_trans_fct trans_fct;
108 __gconv_trans_context_fct trans_context_fct;
109 __gconv_trans_init_fct trans_init_fct;
110 __gconv_trans_end_fct trans_end_fct;
111 };
112
113
114 /* Flags for `gconv_open'. */
115 enum
116 {
117 GCONV_AVOID_NOCONV = 1 << 0
118 };
119
120
121 /* Global variables. */
122
123 /* Database of alias names. */
124 extern void *__gconv_alias_db;
125
126 /* Array with available modules. */
127 extern size_t __gconv_nmodules;
128 extern struct gconv_module *__gconv_modules_db;
129
130
131 /* The gconv functions expects the name to be in upper case and complete,
132 including the trailing slashes if necessary. */
133 #define norm_add_slashes(str,suffix) \
134 ({ \
135 const char *cp = (str); \
136 char *result; \
137 char *tmp; \
138 size_t cnt = 0; \
139 size_t suffix_len = suffix == NULL ? 0 : strlen (suffix); \
140 \
141 while (*cp != '\0') \
142 if (*cp++ == '/') \
143 ++cnt; \
144 \
145 tmp = result = alloca (cp - (str) + 3 + suffix_len); \
146 cp = (str); \
147 while (*cp != '\0') \
148 *tmp++ = _toupper (*cp++); \
149 if (cnt < 2) \
150 { \
151 *tmp++ = '/'; \
152 if (cnt < 1) \
153 { \
154 *tmp++ = '/'; \
155 if (suffix != NULL) \
156 tmp = __mempcpy (tmp, suffix, suffix_len); \
157 } \
158 } \
159 *tmp = '\0'; \
160 result; \
161 })
162
163
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)
167 internal_function;
168
169 /* Free resources associated with transformation descriptor CD. */
170 extern int __gconv_close (__gconv_t cd)
171 internal_function;
172
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)
180 internal_function;
181
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)
187 internal_function;
188
189 /* Read all the configuration data and cache it. */
190 extern void __gconv_read_conf (void);
191
192 /* Determine the directories we are looking in. */
193 extern void __gconv_get_path (void);
194
195 /* Comparison function to search alias. */
196 extern int __gconv_alias_compare (const void *p1, const void *p2);
197
198 /* Clear reference to transformation step implementations which might
199 cause the code to be unloaded. */
200 extern int __gconv_close_transform (struct __gconv_step *steps,
201 size_t nsteps)
202 internal_function;
203
204 /* Load shared object named by NAME. If already loaded increment reference
205 count. */
206 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
207 internal_function;
208
209 /* Release shared object. If no further reference is available unload
210 the object. */
211 extern int __gconv_release_shlib (struct __gconv_loaded_object *handle)
212 internal_function;
213
214 /* Fill STEP with information about builtin module with NAME. */
215 extern void __gconv_get_builtin_trans (const char *name,
216 struct __gconv_step *step)
217 internal_function;
218
219 /* Try to load transliteration step module. */
220 extern int __gconv_translit_find (struct trans_struct *trans)
221 internal_function;
222
223 /* Transliteration using the locale's data. */
224 extern int __gconv_transliterate (struct __gconv_step *step,
225 struct __gconv_step_data *step_data,
226 void *trans_data,
227 __const unsigned char *inbufstart,
228 __const unsigned char **inbufp,
229 __const unsigned char *inbufend,
230 unsigned char **outbufstart,
231 size_t *irreversible);
232
233
234 /* Builtin transformations. */
235 #ifdef _LIBC
236 # define __BUILTIN_TRANS(Name) \
237 extern int Name (struct __gconv_step *step, \
238 struct __gconv_step_data *data, \
239 const unsigned char **inbuf, \
240 const unsigned char *inbufend, \
241 unsigned char **outbufstart, size_t *irreversible, \
242 int do_flush, int consume_incomplete)
243
244 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
245 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
246 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
247 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
248 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
249 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
250 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
251 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
252 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
253 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
254 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
255 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
256 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
257 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
258 # undef __BUITLIN_TRANS
259
260 #endif
261
262 __END_DECLS
263
264 #endif /* gconv_int.h */