OSDN Git Service

r288@cf-ppc-macosx: monabuilder | 2008-12-07 13:17:34 +0900
[pf3gnuchains/pf3gnuchains3x.git] / newlib / libc / sys / linux / iconv / gconv_int.h
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 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 #include <libc-symbols.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 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 two strings.  */
43 struct gconv_alias
44 {
45   char *fromname;
46   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.  It must be the first structure element.  */
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_string;
80   const char *to_string;
81
82   int cost_hi;
83   int cost_lo;
84
85   const char *module_name;
86
87   struct gconv_module *left;    /* Prefix smaller.  */
88   struct gconv_module *same;    /* List of entries with identical prefix.  */
89   struct gconv_module *right;   /* Prefix larger.  */
90 };
91
92
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
108 /* Flags for `gconv_open'.  */
109 enum
110 {
111   GCONV_AVOID_NOCONV = 1 << 0
112 };
113
114
115 /* Global variables.  */
116
117 /* Database of alias names.  */
118 extern void *__gconv_alias_db;
119
120 /* Array with available modules.  */
121 extern size_t __gconv_nmodules;
122 extern struct gconv_module *__gconv_modules_db;
123
124 /* Value of the GCONV_PATH environment variable.  */
125 extern const char *__gconv_path_envvar;
126
127
128 /* The gconv functions expects the name to be in upper case and complete,
129    including the trailing slashes if necessary.  */
130 #define norm_add_slashes(str,suffix) \
131   ({                                                                          \
132     const char *cp = (str);                                                   \
133     char *result;                                                             \
134     char *tmp;                                                                \
135     size_t cnt = 0;                                                           \
136     size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix);               \
137                                                                               \
138     while (*cp != '\0')                                                       \
139       if (*cp++ == '/')                                                       \
140         ++cnt;                                                                \
141                                                                               \
142     tmp = result = alloca (cp - (str) + 3 + suffix_len);                      \
143     cp = (str);                                                               \
144     while (*cp != '\0')                                                       \
145       *tmp++ = __toupper_l (*cp++, &_nl_C_locobj);                            \
146     if (cnt < 2)                                                              \
147       {                                                                       \
148         *tmp++ = '/';                                                         \
149         if (cnt < 1)                                                          \
150           {                                                                   \
151             *tmp++ = '/';                                                     \
152             if (suffix != NULL)                                               \
153             {                                                                 \
154               tmp = memcpy (tmp, suffix, suffix_len);                         \
155               tmp += suffix_len;                                              \
156             }                                                                 \
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 /* Search for transformation in cache data.  */
190 extern int __gconv_lookup_cache (const char *toset, const char *fromset,
191                                  struct __gconv_step **handle, size_t *nsteps,
192                                  int flags)
193      internal_function;
194
195 /* Compare the two name for whether they are after alias expansion the
196    same.  This function uses the cache and fails if none is
197    loaded.  */
198 extern int __gconv_compare_alias_cache (const char *name1, const char *name2,
199                                         int *result) internal_function;
200
201 /* Free data associated with a step's structure.  */
202 extern void __gconv_release_step (struct __gconv_step *step)
203      internal_function;
204
205 /* Read all the configuration data and cache it.  */
206 extern void __gconv_read_conf (void);
207
208 /* Try to read module cache file.  */
209 extern int __gconv_load_cache (void) internal_function;
210
211 /* Determine the directories we are looking in.  */
212 extern void __gconv_get_path (void);
213
214 /* Comparison function to search alias.  */
215 extern int __gconv_alias_compare (const void *p1, const void *p2);
216
217 /* Clear reference to transformation step implementations which might
218    cause the code to be unloaded.  */
219 extern int __gconv_close_transform (struct __gconv_step *steps,
220                                     size_t nsteps)
221      internal_function;
222
223 /* Free all resources allocated for the transformation record when
224    using the cache.  */
225 extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
226      internal_function;
227
228 /* Load shared object named by NAME.  If already loaded increment reference
229    count.  */
230 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
231      internal_function;
232
233 /* Release shared object.  If no further reference is available unload
234    the object.  */
235 extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
236      internal_function;
237
238 /* Fill STEP with information about builtin module with NAME.  */
239 extern void __gconv_get_builtin_trans (const char *name,
240                                        struct __gconv_step *step)
241      internal_function;
242
243 /* Try to load transliteration step module.  */
244 extern int __gconv_translit_find (struct trans_struct *trans)
245      internal_function;
246
247 /* Transliteration using the locale's data.  */
248 extern int __gconv_transliterate (struct __gconv_step *step,
249                                   struct __gconv_step_data *step_data,
250                                   void *trans_data,
251                                   __const unsigned char *inbufstart,
252                                   __const unsigned char **inbufp,
253                                   __const unsigned char *inbufend,
254                                   unsigned char **outbufstart,
255                                   size_t *irreversible);
256
257
258 /* Builtin transformations.  */
259 #ifdef _LIBC
260 # define __BUILTIN_TRANS(Name) \
261   extern int Name (struct __gconv_step *step,                                 \
262                    struct __gconv_step_data *data,                            \
263                    const unsigned char **inbuf,                               \
264                    const unsigned char *inbufend,                             \
265                    unsigned char **outbufstart, size_t *irreversible,         \
266                    int do_flush, int consume_incomplete)
267
268 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
269 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
270 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
271 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
272 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
273 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
274 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
275 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
276 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
277 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
278 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
279 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
280 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
281 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
282 # undef __BUITLIN_TRANS
283
284 #endif
285
286 __END_DECLS
287
288 #endif /* gconv_int.h */