Fix missing backslash in last change.
[glibc.git] / iconv / gconv_int.h
blob0c7a422e2e0e5d343d25633b371d16c6b36ce3f1
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.
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.
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.
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. */
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 to 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;
124 /* The gconv functions expects the name to be in upper case and complete,
125 including the trailing slashes if necessary. */
126 #define norm_add_slashes(str,suffix) \
127 ({ \
128 const char *cp = (str); \
129 char *result; \
130 char *tmp; \
131 size_t cnt = 0; \
132 size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix); \
134 while (*cp != '\0') \
135 if (*cp++ == '/') \
136 ++cnt; \
138 tmp = result = alloca (cp - (str) + 3 + suffix_len); \
139 cp = (str); \
140 while (*cp != '\0') \
141 *tmp++ = _toupper (*cp++); \
142 if (cnt < 2) \
144 *tmp++ = '/'; \
145 if (cnt < 1) \
147 *tmp++ = '/'; \
148 if (suffix != NULL) \
149 tmp = __mempcpy (tmp, suffix, suffix_len); \
152 *tmp = '\0'; \
153 result; \
157 /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
158 extern int __gconv_open (const char *toset, const char *fromset,
159 __gconv_t *handle, int flags)
160 internal_function;
162 /* Free resources associated with transformation descriptor CD. */
163 extern int __gconv_close (__gconv_t cd)
164 internal_function;
166 /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
167 according to rules described by CD and place up to *OUTBYTESLEFT
168 bytes in buffer starting at *OUTBUF. Return number of non-identical
169 conversions in *IRREVERSIBLE if this pointer is not null. */
170 extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
171 const unsigned char *inbufend, unsigned char **outbuf,
172 unsigned char *outbufend, size_t *irreversible)
173 internal_function;
175 /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
176 the single steps necessary for transformation from FROMSET to TOSET. */
177 extern int __gconv_find_transform (const char *toset, const char *fromset,
178 struct __gconv_step **handle,
179 size_t *nsteps, int flags)
180 internal_function;
182 /* Read all the configuration data and cache it. */
183 extern void __gconv_read_conf (void);
185 /* Determine the directories we are looking in. */
186 extern void __gconv_get_path (void);
188 /* Comparison function to search alias. */
189 extern int __gconv_alias_compare (const void *p1, const void *p2);
191 /* Clear reference to transformation step implementations which might
192 cause the code to be unloaded. */
193 extern int __gconv_close_transform (struct __gconv_step *steps,
194 size_t nsteps)
195 internal_function;
197 /* Load shared object named by NAME. If already loaded increment reference
198 count. */
199 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
200 internal_function;
202 /* Release shared object. If no further reference is available unload
203 the object. */
204 extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
205 internal_function;
207 /* Fill STEP with information about builtin module with NAME. */
208 extern void __gconv_get_builtin_trans (const char *name,
209 struct __gconv_step *step)
210 internal_function;
212 /* Try to load transliteration step module. */
213 extern int __gconv_translit_find (struct trans_struct *trans)
214 internal_function;
216 /* Transliteration using the locale's data. */
217 extern int __gconv_transliterate (struct __gconv_step *step,
218 struct __gconv_step_data *step_data,
219 void *trans_data,
220 __const unsigned char *inbufstart,
221 __const unsigned char **inbufp,
222 __const unsigned char *inbufend,
223 unsigned char **outbufstart,
224 size_t *irreversible);
227 /* Builtin transformations. */
228 #ifdef _LIBC
229 # define __BUILTIN_TRANS(Name) \
230 extern int Name (struct __gconv_step *step, \
231 struct __gconv_step_data *data, \
232 const unsigned char **inbuf, \
233 const unsigned char *inbufend, \
234 unsigned char **outbufstart, size_t *irreversible, \
235 int do_flush, int consume_incomplete)
237 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
238 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
239 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
240 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
241 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
242 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
243 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
244 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
245 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
246 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
247 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
248 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
249 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
250 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
251 # undef __BUITLIN_TRANS
253 #endif
255 __END_DECLS
257 #endif /* gconv_int.h */