]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconv/gconv_int.h
(struct builtin_map): Remove init and end elements. (BUILTIN_TRANSFORMATION): Remove...
[thirdparty/glibc.git] / iconv / gconv_int.h
CommitLineData
63e04088 1/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
e62c19f1
UD
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
41bdb6e2
AJ
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.
e62c19f1
UD
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
41bdb6e2 13 Lesser General Public License for more details.
e62c19f1 14
41bdb6e2
AJ
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. */
e62c19f1
UD
19
20#ifndef _GCONV_INT_H
21#define _GCONV_INT_H 1
22
23#include "gconv.h"
e62c19f1
UD
24
25__BEGIN_DECLS
26
27
d6204268
UD
28/* Type to represent search path. */
29struct path_elem
30{
31 const char *name;
32 size_t len;
33};
34
35/* Variable with search path for `gconv' implementation. */
17427edd 36extern struct path_elem *__gconv_path_elem;
d6204268
UD
37/* Maximum length of a single path element. */
38extern size_t __gconv_max_path_elem_len;
39
40
9a321276 41/* Structure for alias definition. Simply two strings. */
e62c19f1
UD
42struct gconv_alias
43{
17427edd
UD
44 char *fromname;
45 char *toname;
e62c19f1
UD
46};
47
48
8619129f
UD
49/* How many character should be conveted in one call? */
50#define GCONV_NCHAR_GOAL 8160
e62c19f1
UD
51
52
0d9f6793
UD
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. */
d64b6ad0 56struct __gconv_loaded_object
0d9f6793 57{
b79f74cd 58 /* Name of the object. It must be the first structure element. */
0d9f6793
UD
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. */
b3fc5f84 66 void *handle;
0d9f6793
UD
67
68 /* Pointer to the functions the module defines. */
d64b6ad0
UD
69 __gconv_fct fct;
70 __gconv_init_fct init_fct;
71 __gconv_end_fct end_fct;
0d9f6793
UD
72};
73
74
e62c19f1
UD
75/* Description for an available conversion module. */
76struct gconv_module
77{
d2dfc5de 78 const char *from_string;
0d9f6793 79 const char *to_string;
e62c19f1 80
fab6d621
UD
81 int cost_hi;
82 int cost_lo;
e62c19f1 83
0d9f6793 84 const char *module_name;
2bd60880
UD
85
86 struct gconv_module *left; /* Prefix smaller. */
87 struct gconv_module *same; /* List of entries with identical prefix. */
2bd60880 88 struct gconv_module *right; /* Prefix larger. */
e62c19f1
UD
89};
90
91
d6204268
UD
92/* Internal data structure to represent transliteration module. */
93struct 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
c90a2db6
UD
107/* Flags for `gconv_open'. */
108enum
109{
110 GCONV_AVOID_NOCONV = 1 << 0
111};
112
113
e62c19f1
UD
114/* Global variables. */
115
116/* Database of alias names. */
117extern void *__gconv_alias_db;
118
119/* Array with available modules. */
120extern size_t __gconv_nmodules;
2bd60880 121extern struct gconv_module *__gconv_modules_db;
e62c19f1
UD
122
123
17c389fc
UD
124/* The gconv functions expects the name to be in upper case and complete,
125 including the trailing slashes if necessary. */
323fb88d 126#define norm_add_slashes(str,suffix) \
17c389fc
UD
127 ({ \
128 const char *cp = (str); \
129 char *result; \
130 char *tmp; \
131 size_t cnt = 0; \
282c98b0 132 size_t suffix_len = (suffix) == NULL ? 0 : strlen (suffix); \
17c389fc
UD
133 \
134 while (*cp != '\0') \
135 if (*cp++ == '/') \
136 ++cnt; \
137 \
323fb88d 138 tmp = result = alloca (cp - (str) + 3 + suffix_len); \
17c389fc
UD
139 cp = (str); \
140 while (*cp != '\0') \
141 *tmp++ = _toupper (*cp++); \
142 if (cnt < 2) \
143 { \
144 *tmp++ = '/'; \
145 if (cnt < 1) \
323fb88d
UD
146 { \
147 *tmp++ = '/'; \
148 if (suffix != NULL) \
149 tmp = __mempcpy (tmp, suffix, suffix_len); \
150 } \
17c389fc
UD
151 } \
152 *tmp = '\0'; \
153 result; \
154 })
155
156
e62c19f1 157/* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
55985355
UD
158extern int __gconv_open (const char *toset, const char *fromset,
159 __gconv_t *handle, int flags)
e62c19f1
UD
160 internal_function;
161
162/* Free resources associated with transformation descriptor CD. */
d64b6ad0 163extern int __gconv_close (__gconv_t cd)
e62c19f1
UD
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
63e04088 168 bytes in buffer starting at *OUTBUF. Return number of non-identical
38677ace 169 conversions in *IRREVERSIBLE if this pointer is not null. */
55985355
UD
170extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
171 const unsigned char *inbufend, unsigned char **outbuf,
38677ace 172 unsigned char *outbufend, size_t *irreversible)
e62c19f1
UD
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. */
55985355
UD
177extern int __gconv_find_transform (const char *toset, const char *fromset,
178 struct __gconv_step **handle,
179 size_t *nsteps, int flags)
e62c19f1
UD
180 internal_function;
181
182/* Read all the configuration data and cache it. */
00995ca9 183extern void __gconv_read_conf (void);
e62c19f1 184
d6204268
UD
185/* Determine the directories we are looking in. */
186extern void __gconv_get_path (void);
187
e62c19f1 188/* Comparison function to search alias. */
55985355 189extern int __gconv_alias_compare (const void *p1, const void *p2);
e62c19f1
UD
190
191/* Clear reference to transformation step implementations which might
192 cause the code to be unloaded. */
55985355
UD
193extern int __gconv_close_transform (struct __gconv_step *steps,
194 size_t nsteps)
e62c19f1
UD
195 internal_function;
196
197/* Load shared object named by NAME. If already loaded increment reference
198 count. */
55985355 199extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
e62c19f1
UD
200 internal_function;
201
202/* Release shared object. If no further reference is available unload
203 the object. */
b79f74cd 204extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
e62c19f1
UD
205 internal_function;
206
207/* Fill STEP with information about builtin module with NAME. */
55985355
UD
208extern void __gconv_get_builtin_trans (const char *name,
209 struct __gconv_step *step)
e62c19f1
UD
210 internal_function;
211
d6204268
UD
212/* Try to load transliteration step module. */
213extern int __gconv_translit_find (struct trans_struct *trans)
214 internal_function;
215
55985355 216/* Transliteration using the locale's data. */
f1d5c60d
UD
217extern int __gconv_transliterate (struct __gconv_step *step,
218 struct __gconv_step_data *step_data,
d6204268 219 void *trans_data,
f1d5c60d
UD
220 __const unsigned char *inbufstart,
221 __const unsigned char **inbufp,
222 __const unsigned char *inbufend,
223 unsigned char **outbufstart,
224 size_t *irreversible);
e62c19f1
UD
225
226
227/* Builtin transformations. */
228#ifdef _LIBC
229# define __BUILTIN_TRANS(Name) \
55985355
UD
230 extern int Name (struct __gconv_step *step, \
231 struct __gconv_step_data *data, \
232 const unsigned char **inbuf, \
f1d5c60d
UD
233 const unsigned char *inbufend, \
234 unsigned char **outbufstart, size_t *irreversible, \
235 int do_flush, int consume_incomplete)
e62c19f1 236
f1fa8b68
UD
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);
8d617a71
UD
243__BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal);
244__BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse);
f1fa8b68 245__BUILTIN_TRANS (__gconv_transform_internal_ucs4);
4a069c33 246__BUILTIN_TRANS (__gconv_transform_ucs4_internal);
8d617a71 247__BUILTIN_TRANS (__gconv_transform_internal_ucs4le);
4a069c33 248__BUILTIN_TRANS (__gconv_transform_ucs4le_internal);
62ece32b
UD
249__BUILTIN_TRANS (__gconv_transform_internal_utf16);
250__BUILTIN_TRANS (__gconv_transform_utf16_internal);
e62c19f1
UD
251# undef __BUITLIN_TRANS
252
e62c19f1
UD
253#endif
254
255__END_DECLS
256
257#endif /* gconv_int.h */