]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconv/gconv_int.h
Cleanup of configuration options
[thirdparty/glibc.git] / iconv / gconv_int.h
CommitLineData
7b503bcc 1/* Copyright (C) 1997-2005, 2006, 2007 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"
c5738211 24#include <stdlib.h> /* For alloca used in macro below. */
6111babe
RM
25#include <ctype.h> /* For __toupper_l used in macro below. */
26#include <string.h> /* For strlen et al used in macro below. */
9e26f129 27#include <bits/libc-lock.h>
e62c19f1
UD
28
29__BEGIN_DECLS
30
31
d6204268
UD
32/* Type to represent search path. */
33struct path_elem
34{
35 const char *name;
36 size_t len;
37};
38
39/* Variable with search path for `gconv' implementation. */
aa32f798 40extern struct path_elem *__gconv_path_elem attribute_hidden;
d6204268 41/* Maximum length of a single path element. */
aa32f798 42extern size_t __gconv_max_path_elem_len attribute_hidden;
d6204268
UD
43
44
9a321276 45/* Structure for alias definition. Simply two strings. */
e62c19f1
UD
46struct gconv_alias
47{
17427edd
UD
48 char *fromname;
49 char *toname;
e62c19f1
UD
50};
51
52
8619129f
UD
53/* How many character should be conveted in one call? */
54#define GCONV_NCHAR_GOAL 8160
e62c19f1
UD
55
56
0d9f6793
UD
57/* Structure describing one loaded shared object. This normally are
58 objects to perform conversation but as a special case the db shared
59 object is also handled. */
d64b6ad0 60struct __gconv_loaded_object
0d9f6793 61{
b79f74cd 62 /* Name of the object. It must be the first structure element. */
0d9f6793
UD
63 const char *name;
64
65 /* Reference counter for the db functionality. If no conversion is
66 needed we unload the db library. */
67 int counter;
68
69 /* The handle for the shared object. */
b3fc5f84 70 void *handle;
0d9f6793
UD
71
72 /* Pointer to the functions the module defines. */
d64b6ad0
UD
73 __gconv_fct fct;
74 __gconv_init_fct init_fct;
75 __gconv_end_fct end_fct;
0d9f6793
UD
76};
77
78
e62c19f1
UD
79/* Description for an available conversion module. */
80struct gconv_module
81{
d2dfc5de 82 const char *from_string;
0d9f6793 83 const char *to_string;
e62c19f1 84
fab6d621
UD
85 int cost_hi;
86 int cost_lo;
e62c19f1 87
0d9f6793 88 const char *module_name;
2bd60880
UD
89
90 struct gconv_module *left; /* Prefix smaller. */
91 struct gconv_module *same; /* List of entries with identical prefix. */
2bd60880 92 struct gconv_module *right; /* Prefix larger. */
e62c19f1
UD
93};
94
95
d6204268
UD
96/* Internal data structure to represent transliteration module. */
97struct trans_struct
98{
99 const char *name;
100 struct trans_struct *next;
101
102 const char **csnames;
103 size_t ncsnames;
104 __gconv_trans_fct trans_fct;
105 __gconv_trans_context_fct trans_context_fct;
106 __gconv_trans_init_fct trans_init_fct;
107 __gconv_trans_end_fct trans_end_fct;
108};
109
110
c90a2db6
UD
111/* Flags for `gconv_open'. */
112enum
113{
114 GCONV_AVOID_NOCONV = 1 << 0
115};
116
7b503bcc
UD
117/* When GCONV_AVOID_NOCONV is set and no conversion is needed,
118 __GCONV_NULCONV should be returned. */
119enum
120{
121 __GCONV_NULCONV = -1
122};
c90a2db6 123
e62c19f1
UD
124/* Global variables. */
125
126/* Database of alias names. */
230491f0 127extern void *__gconv_alias_db attribute_hidden;
e62c19f1
UD
128
129/* Array with available modules. */
130extern size_t __gconv_nmodules;
230491f0 131extern struct gconv_module *__gconv_modules_db attribute_hidden;
e62c19f1 132
6b98979f 133/* Value of the GCONV_PATH environment variable. */
aa32f798 134extern const char *__gconv_path_envvar attribute_hidden;
6b98979f 135
9e26f129 136/* Lock for the conversion database content. */
6f8a7dff 137__libc_lock_define (extern, __gconv_lock attribute_hidden)
9e26f129 138
e62c19f1 139
17c389fc
UD
140/* The gconv functions expects the name to be in upper case and complete,
141 including the trailing slashes if necessary. */
323fb88d 142#define norm_add_slashes(str,suffix) \
17c389fc
UD
143 ({ \
144 const char *cp = (str); \
145 char *result; \
146 char *tmp; \
147 size_t cnt = 0; \
db2f05ba 148 const size_t suffix_len = strlen (suffix); \
17c389fc
UD
149 \
150 while (*cp != '\0') \
151 if (*cp++ == '/') \
152 ++cnt; \
153 \
c5738211 154 tmp = result = __alloca (cp - (str) + 3 + suffix_len); \
17c389fc
UD
155 cp = (str); \
156 while (*cp != '\0') \
4b5b009c 157 *tmp++ = __toupper_l (*cp++, _nl_C_locobj_ptr); \
17c389fc
UD
158 if (cnt < 2) \
159 { \
160 *tmp++ = '/'; \
161 if (cnt < 1) \
323fb88d
UD
162 { \
163 *tmp++ = '/'; \
db2f05ba 164 if (suffix_len != 0) \
323fb88d
UD
165 tmp = __mempcpy (tmp, suffix, suffix_len); \
166 } \
17c389fc
UD
167 } \
168 *tmp = '\0'; \
169 result; \
170 })
171
172
e62c19f1 173/* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
55985355
UD
174extern int __gconv_open (const char *toset, const char *fromset,
175 __gconv_t *handle, int flags)
e62c19f1
UD
176 internal_function;
177
178/* Free resources associated with transformation descriptor CD. */
d64b6ad0 179extern int __gconv_close (__gconv_t cd)
e62c19f1
UD
180 internal_function;
181
182/* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
183 according to rules described by CD and place up to *OUTBYTESLEFT
63e04088 184 bytes in buffer starting at *OUTBUF. Return number of non-identical
38677ace 185 conversions in *IRREVERSIBLE if this pointer is not null. */
55985355
UD
186extern int __gconv (__gconv_t cd, const unsigned char **inbuf,
187 const unsigned char *inbufend, unsigned char **outbuf,
38677ace 188 unsigned char *outbufend, size_t *irreversible)
e62c19f1
UD
189 internal_function;
190
191/* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
192 the single steps necessary for transformation from FROMSET to TOSET. */
55985355
UD
193extern int __gconv_find_transform (const char *toset, const char *fromset,
194 struct __gconv_step **handle,
195 size_t *nsteps, int flags)
e62c19f1
UD
196 internal_function;
197
6b98979f
UD
198/* Search for transformation in cache data. */
199extern int __gconv_lookup_cache (const char *toset, const char *fromset,
200 struct __gconv_step **handle, size_t *nsteps,
201 int flags)
202 internal_function;
203
9a018f6c
UD
204/* Compare the two name for whether they are after alias expansion the
205 same. This function uses the cache and fails if none is
206 loaded. */
207extern int __gconv_compare_alias_cache (const char *name1, const char *name2,
208 int *result) internal_function;
209
6b98979f
UD
210/* Free data associated with a step's structure. */
211extern void __gconv_release_step (struct __gconv_step *step)
212 internal_function;
213
e62c19f1 214/* Read all the configuration data and cache it. */
dff07c4b 215extern void __gconv_read_conf (void) attribute_hidden;
e62c19f1 216
6b98979f
UD
217/* Try to read module cache file. */
218extern int __gconv_load_cache (void) internal_function;
219
230491f0
UD
220/* Retrieve pointer to internal cache. */
221extern void *__gconv_get_cache (void);
222
223/* Retrieve pointer to internal module database. */
224extern struct gconv_module *__gconv_get_modules_db (void);
225
226/* Retrieve pointer to internal alias database. */
227extern void *__gconv_get_alias_db (void);
228
d6204268 229/* Determine the directories we are looking in. */
dff07c4b 230extern void __gconv_get_path (void) internal_function;
d6204268 231
e62c19f1 232/* Comparison function to search alias. */
dff07c4b
UD
233extern int __gconv_alias_compare (const void *p1, const void *p2)
234 attribute_hidden;
e62c19f1
UD
235
236/* Clear reference to transformation step implementations which might
237 cause the code to be unloaded. */
55985355
UD
238extern int __gconv_close_transform (struct __gconv_step *steps,
239 size_t nsteps)
e62c19f1
UD
240 internal_function;
241
0db59742
UD
242/* Free all resources allocated for the transformation record when
243 using the cache. */
244extern void __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
245 internal_function;
246
e62c19f1
UD
247/* Load shared object named by NAME. If already loaded increment reference
248 count. */
55985355 249extern struct __gconv_loaded_object *__gconv_find_shlib (const char *name)
e62c19f1
UD
250 internal_function;
251
252/* Release shared object. If no further reference is available unload
253 the object. */
b79f74cd 254extern void __gconv_release_shlib (struct __gconv_loaded_object *handle)
e62c19f1
UD
255 internal_function;
256
257/* Fill STEP with information about builtin module with NAME. */
55985355
UD
258extern void __gconv_get_builtin_trans (const char *name,
259 struct __gconv_step *step)
e62c19f1
UD
260 internal_function;
261
d6204268
UD
262/* Try to load transliteration step module. */
263extern int __gconv_translit_find (struct trans_struct *trans)
264 internal_function;
265
55985355 266/* Transliteration using the locale's data. */
f1d5c60d
UD
267extern int __gconv_transliterate (struct __gconv_step *step,
268 struct __gconv_step_data *step_data,
d6204268 269 void *trans_data,
f1d5c60d
UD
270 __const unsigned char *inbufstart,
271 __const unsigned char **inbufp,
272 __const unsigned char *inbufend,
273 unsigned char **outbufstart,
dff07c4b 274 size_t *irreversible) attribute_hidden;
e62c19f1
UD
275
276
dd9423a6
UD
277/* If NAME is an codeset alias expand it. */
278extern int __gconv_compare_alias (const char *name1, const char *name2)
279 internal_function;
280
281
e62c19f1
UD
282/* Builtin transformations. */
283#ifdef _LIBC
f9ad060c 284# define __BUILTIN_TRANSFORM(Name) \
55985355
UD
285 extern int Name (struct __gconv_step *step, \
286 struct __gconv_step_data *data, \
287 const unsigned char **inbuf, \
f1d5c60d
UD
288 const unsigned char *inbufend, \
289 unsigned char **outbufstart, size_t *irreversible, \
290 int do_flush, int consume_incomplete)
e62c19f1 291
f9ad060c
UD
292__BUILTIN_TRANSFORM (__gconv_transform_ascii_internal);
293__BUILTIN_TRANSFORM (__gconv_transform_internal_ascii);
294__BUILTIN_TRANSFORM (__gconv_transform_utf8_internal);
295__BUILTIN_TRANSFORM (__gconv_transform_internal_utf8);
296__BUILTIN_TRANSFORM (__gconv_transform_ucs2_internal);
297__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2);
298__BUILTIN_TRANSFORM (__gconv_transform_ucs2reverse_internal);
299__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2reverse);
300__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4);
301__BUILTIN_TRANSFORM (__gconv_transform_ucs4_internal);
302__BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4le);
303__BUILTIN_TRANSFORM (__gconv_transform_ucs4le_internal);
304__BUILTIN_TRANSFORM (__gconv_transform_internal_utf16);
305__BUILTIN_TRANSFORM (__gconv_transform_utf16_internal);
306# undef __BUITLIN_TRANSFORM
307
308/* Specialized conversion function for a single byte to INTERNAL, recognizing
309 only ASCII characters. */
310extern wint_t __gconv_btwoc_ascii (struct __gconv_step *step, unsigned char c);
e62c19f1 311
e62c19f1
UD
312#endif
313
314__END_DECLS
315
316#endif /* gconv_int.h */