Update.
[platform/upstream/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 /* Structure for alias definition.  Simply to strings.  */
30 struct gconv_alias
31 {
32   const char *fromname;
33   const char *toname;
34 };
35
36
37 /* How many character should be conveted in one call?  */
38 #define GCONV_NCHAR_GOAL        8160
39
40
41 /* Structure describing one loaded shared object.  This normally are
42    objects to perform conversation but as a special case the db shared
43    object is also handled.  */
44 struct __gconv_loaded_object
45 {
46   /* Name of the object.  */
47   const char *name;
48
49   /* Reference counter for the db functionality.  If no conversion is
50      needed we unload the db library.  */
51   int counter;
52
53   /* The handle for the shared object.  */
54   void *handle;
55
56   /* Pointer to the functions the module defines.  */
57   __gconv_fct fct;
58   __gconv_init_fct init_fct;
59   __gconv_end_fct end_fct;
60 };
61
62
63 /* Description for an available conversion module.  */
64 struct gconv_module
65 {
66   const char *from_pattern;
67   const char *from_constpfx;
68   size_t from_constpfx_len;
69   const regex_t *from_regex;
70   regex_t from_regex_mem;
71
72   const char *to_string;
73
74   int cost_hi;
75   int cost_lo;
76
77   const char *module_name;
78
79   struct gconv_module *left;    /* Prefix smaller.  */
80   struct gconv_module *same;    /* List of entries with identical prefix.  */
81   struct gconv_module *matching;/* Next node with more specific prefix.  */
82   struct gconv_module *right;   /* Prefix larger.  */
83 };
84
85
86 /* Flags for `gconv_open'.  */
87 enum
88 {
89   GCONV_AVOID_NOCONV = 1 << 0
90 };
91
92
93 /* Global variables.  */
94
95 /* Database of alias names.  */
96 extern void *__gconv_alias_db;
97
98 /* Array with available modules.  */
99 extern size_t __gconv_nmodules;
100 extern struct gconv_module *__gconv_modules_db;
101
102
103 /* The gconv functions expects the name to be in upper case and complete,
104    including the trailing slashes if necessary.  */
105 #define norm_add_slashes(str) \
106   ({                                                                          \
107     const char *cp = (str);                                                   \
108     char *result;                                                             \
109     char *tmp;                                                                \
110     size_t cnt = 0;                                                           \
111                                                                               \
112     while (*cp != '\0')                                                       \
113       if (*cp++ == '/')                                                       \
114         ++cnt;                                                                \
115                                                                               \
116     tmp = result = alloca (cp - (str) + 3);                                   \
117     cp = (str);                                                               \
118     while (*cp != '\0')                                                       \
119       *tmp++ = _toupper (*cp++);                                              \
120     if (cnt < 2)                                                              \
121       {                                                                       \
122         *tmp++ = '/';                                                         \
123         if (cnt < 1)                                                          \
124           *tmp++ = '/';                                                       \
125       }                                                                       \
126     *tmp = '\0';                                                              \
127     result;                                                                   \
128   })
129
130
131 /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET.  */
132 extern int __gconv_open (const char *toset, const char *fromset,
133                          __gconv_t *handle, int flags)
134      internal_function;
135
136 /* Free resources associated with transformation descriptor CD.  */
137 extern int __gconv_close (__gconv_t cd)
138      internal_function;
139
140 /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
141    according to rules described by CD and place up to *OUTBYTESLEFT
142    bytes in buffer starting at *OUTBUF.  Return number of non-identical
143    conversions in *IRREVERSIBLE if this pointer is not null.  */
144 extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
145                     const unsigned char *inbufend, unsigned char **outbuf,
146                     unsigned char *outbufend, size_t *irreversible)
147      internal_function;
148
149 /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
150    the single steps necessary for transformation from FROMSET to TOSET.  */
151 extern int __gconv_find_transform (const char *toset, const char *fromset,
152                                    struct __gconv_step **handle,
153                                    size_t *nsteps, int flags)
154      internal_function;
155
156 /* Read all the configuration data and cache it.  */
157 extern void __gconv_read_conf (void);
158
159 /* Comparison function to search alias.  */
160 extern int __gconv_alias_compare (const void *p1, const void *p2);
161
162 /* Clear reference to transformation step implementations which might
163    cause the code to be unloaded.  */
164 extern int __gconv_close_transform (struct __gconv_step *steps,
165                                     size_t nsteps)
166      internal_function;
167
168 /* Load shared object named by NAME.  If already loaded increment reference
169    count.  */
170 extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
171      internal_function;
172
173 /* Release shared object.  If no further reference is available unload
174    the object.  */
175 extern int __gconv_release_shlib (struct __gconv_loaded_object *handle)
176      internal_function;
177
178 /* Fill STEP with information about builtin module with NAME.  */
179 extern void __gconv_get_builtin_trans (const char *name,
180                                        struct __gconv_step *step)
181      internal_function;
182
183 /* Transliteration using the locale's data.  */
184 extern int gconv_transliterate (struct __gconv_step *step,
185                                 struct __gconv_step_data *step_data,
186                                 __const unsigned char *inbufstart,
187                                 __const unsigned char **inbufp,
188                                 __const unsigned char *inbufend,
189                                 unsigned char *outbufstart,
190                                 unsigned char **outbufp,
191                                 unsigned char *outbufend,
192                                 size_t *irreversible);
193
194
195 /* Builtin transformations.  */
196 #ifdef _LIBC
197 # define __BUILTIN_TRANS(Name) \
198   extern int Name (struct __gconv_step *step,                                 \
199                    struct __gconv_step_data *data,                            \
200                    const unsigned char **inbuf,                               \
201                    const unsigned char *inbufend, unsigned char *outbufstart, \
202                    size_t *irreversible, int do_flush, int consume_incomplete)
203
204 __BUILTIN_TRANS (__gconv_transform_ascii_internal);
205 __BUILTIN_TRANS (__gconv_transform_internal_ascii);
206 __BUILTIN_TRANS (__gconv_transform_utf8_internal);
207 __BUILTIN_TRANS (__gconv_transform_internal_utf8);
208 __BUILTIN_TRANS (__gconv_transform_ucs2_internal);
209 __BUILTIN_TRANS (__gconv_transform_internal_ucs2);
210 __BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
211 __BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
212 __BUILTIN_TRANS (__gconv_transform_internal_ucs4);
213 __BUILTIN_TRANS (__gconv_transform_ucs4_internal);
214 __BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
215 __BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
216 __BUILTIN_TRANS (__gconv_transform_internal_utf16);
217 __BUILTIN_TRANS (__gconv_transform_utf16_internal);
218 # undef __BUITLIN_TRANS
219
220 #endif
221
222 __END_DECLS
223
224 #endif /* gconv_int.h */