Update to LGPL v2.1.
[jlayton/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 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;
37 /* Maximum length of a single path element.  */
38 extern size_t __gconv_max_path_elem_len;
39
40
41 /* Structure for alias definition.  Simply to 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
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);               \
133                                                                               \
134     while (*cp != '\0')                                                       \
135       if (*cp++ == '/')                                                       \
136         ++cnt;                                                                \
137                                                                               \
138     tmp = result = alloca (cp - (str) + 3 + suffix_len);                      \
139     cp = (str);                                                               \
140     while (*cp != '\0')                                                       \
141       *tmp++ = _toupper (*cp++);                                              \
142     if (cnt < 2)                                                              \
143       {                                                                       \
144         *tmp++ = '/';                                                         \
145         if (cnt < 1)                                                          \
146           {                                                                   \
147             *tmp++ = '/';                                                     \
148             if (suffix != NULL)                                               \
149               tmp = __mempcpy (tmp, suffix, suffix_len);                      \
150           }                                                                   \
151       }                                                                       \
152     *tmp = '\0';                                                              \
153     result;                                                                   \
154   })
155
156
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;
161
162 /* Free resources associated with transformation descriptor CD.  */
163 extern int __gconv_close (__gconv_t cd)
164      internal_function;
165
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;
174
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;
181
182 /* Read all the configuration data and cache it.  */
183 extern void __gconv_read_conf (void);
184
185 /* Determine the directories we are looking in.  */
186 extern void __gconv_get_path (void);
187
188 /* Comparison function to search alias.  */
189 extern int __gconv_alias_compare (const void *p1, const void *p2);
190
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;
196
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;
201
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;
206
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;
211
212 /* Try to load transliteration step module.  */
213 extern int __gconv_translit_find (struct trans_struct *trans)
214      internal_function;
215
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);
225
226
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)
236
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
252
253 #endif
254
255 __END_DECLS
256
257 #endif /* gconv_int.h */