1 /* Header describing internals of libintl library.
2 Copyright (C) 1995-1999, 2000-2007, 2009-2010 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #ifndef _GETTEXTP_H
19 #define _GETTEXTP_H
20
21 #include <stddef.h> /* Get size_t. */
22
23 #ifdef _LIBC
24 # include "../iconv/gconv_int.h"
25 #else
26 # if HAVE_ICONV
27 # include <iconv.h>
28 # endif
29 #endif
30
31 /* Handle multi-threaded applications. */
32 #ifdef _LIBC
33 # include <bits/libc-lock.h>
34 # define gl_rwlock_define __libc_rwlock_define
35 #else
36 # include "lock.h"
37 #endif
38
39 #ifdef _LIBC
40 extern char *__gettext (const char *__msgid);
41 extern char *__dgettext (const char *__domainname, const char *__msgid);
42 extern char *__dcgettext (const char *__domainname, const char *__msgid,
43 int __category);
44 extern char *__ngettext (const char *__msgid1, const char *__msgid2,
45 unsigned long int __n);
46 extern char *__dngettext (const char *__domainname,
47 const char *__msgid1, const char *__msgid2,
48 unsigned long int n);
49 extern char *__dcngettext (const char *__domainname,
50 const char *__msgid1, const char *__msgid2,
51 unsigned long int __n, int __category);
52 extern char *__dcigettext (const char *__domainname,
53 const char *__msgid1, const char *__msgid2,
54 int __plural, unsigned long int __n,
55 int __category);
56 extern char *__textdomain (const char *__domainname);
57 extern char *__bindtextdomain (const char *__domainname,
58 const char *__dirname);
59 extern char *__bind_textdomain_codeset (const char *__domainname,
60 const char *__codeset);
61 extern void _nl_finddomain_subfreeres (void) attribute_hidden;
62 extern void _nl_unload_domain (struct loaded_domain *__domain)
63 internal_function attribute_hidden;
64 #else
65 /* Declare the exported libintl_* functions, in a way that allows us to
66 call them under their real name. */
67 # undef _INTL_REDIRECT_INLINE
68 # undef _INTL_REDIRECT_MACROS
69 # define _INTL_REDIRECT_MACROS
70 # include "libgnuintl.h"
71 # ifdef IN_LIBGLOCALE
72 extern char *gl_dcigettext (const char *__domainname,
73 const char *__msgid1, const char *__msgid2,
74 int __plural, unsigned long int __n,
75 int __category,
76 const char *__localename, const char *__encoding);
77 # else
78 extern char *libintl_dcigettext (const char *__domainname,
79 const char *__msgid1, const char *__msgid2,
80 int __plural, unsigned long int __n,
81 int __category);
82 # endif
83 #endif
84
85 #include "loadinfo.h"
86
87 #include "gmo.h" /* Get nls_uint32. */
88
89 /* @@ end of prolog @@ */
90
91 #ifndef internal_function
92 # define internal_function
93 #endif
94
95 #ifndef attribute_hidden
96 # define attribute_hidden
97 #endif
98
99 /* Tell the compiler when a conditional or integer expression is
100 almost always true or almost always false. */
101 #ifndef HAVE_BUILTIN_EXPECT
102 # define __builtin_expect(expr, val) (expr)
103 #endif
104
105 #ifndef W
106 # define W(flag, data) ((flag) ? SWAP (data) : (data))
107 #endif
108
109
110 #ifdef _LIBC
111 # include <byteswap.h>
112 # define SWAP(i) bswap_32 (i)
113 #else
114 static inline nls_uint32
115 # ifdef __cplusplus
SWAP(nls_uint32 i)116 SWAP (nls_uint32 i)
117 # else
118 SWAP (i)
119 nls_uint32 i;
120 # endif
121 {
122 return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
123 }
124 #endif
125
126
127 /* In-memory representation of system dependent string. */
128 struct sysdep_string_desc
129 {
130 /* Length of addressed string, including the trailing NUL. */
131 size_t length;
132 /* Pointer to addressed string. */
133 const char *pointer;
134 };
135
136 /* Cache of translated strings after charset conversion.
137 Note: The strings are converted to the target encoding only on an as-needed
138 basis. */
139 struct converted_domain
140 {
141 /* The target encoding name. */
142 const char *encoding;
143 /* The descriptor for conversion from the message catalog's encoding to
144 this target encoding. */
145 #ifdef _LIBC
146 __gconv_t conv;
147 #else
148 # if HAVE_ICONV
149 iconv_t conv;
150 # endif
151 #endif
152 /* The table of translated strings after charset conversion. */
153 char **conv_tab;
154 };
155
156 /* The representation of an opened message catalog. */
157 struct loaded_domain
158 {
159 /* Pointer to memory containing the .mo file. */
160 const char *data;
161 /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */
162 int use_mmap;
163 /* Size of mmap()ed memory. */
164 size_t mmap_size;
165 /* 1 if the .mo file uses a different endianness than this machine. */
166 int must_swap;
167 /* Pointer to additional malloc()ed memory. */
168 void *malloced;
169
170 /* Number of static strings pairs. */
171 nls_uint32 nstrings;
172 /* Pointer to descriptors of original strings in the file. */
173 const struct string_desc *orig_tab;
174 /* Pointer to descriptors of translated strings in the file. */
175 const struct string_desc *trans_tab;
176
177 /* Number of system dependent strings pairs. */
178 nls_uint32 n_sysdep_strings;
179 /* Pointer to descriptors of original sysdep strings. */
180 const struct sysdep_string_desc *orig_sysdep_tab;
181 /* Pointer to descriptors of translated sysdep strings. */
182 const struct sysdep_string_desc *trans_sysdep_tab;
183
184 /* Size of hash table. */
185 nls_uint32 hash_size;
186 /* Pointer to hash table. */
187 const nls_uint32 *hash_tab;
188 /* 1 if the hash table uses a different endianness than this machine. */
189 int must_swap_hash_tab;
190
191 /* Cache of charset conversions of the translated strings. */
192 struct converted_domain *conversions;
193 size_t nconversions;
194 gl_rwlock_define (, conversions_lock)
195
196 const struct expression *plural;
197 unsigned long int nplurals;
198 };
199
200 /* We want to allocate a string at the end of the struct. But ISO C
201 doesn't allow zero sized arrays. */
202 #ifdef __GNUC__
203 # define ZERO 0
204 #else
205 # define ZERO 1
206 #endif
207
208 /* A set of settings bound to a message domain. Used to store settings
209 from bindtextdomain() and bind_textdomain_codeset(). */
210 struct binding
211 {
212 struct binding *next;
213 char *dirname;
214 char *codeset;
215 char domainname[ZERO];
216 };
217
218 /* A counter which is incremented each time some previous translations
219 become invalid.
220 This variable is part of the external ABI of the GNU libintl. */
221 #ifdef IN_LIBGLOCALE
222 # include <glocale/config.h>
223 extern LIBGLOCALE_DLL_EXPORTED int _nl_msg_cat_cntr;
224 #else
225 extern LIBINTL_DLL_EXPORTED int _nl_msg_cat_cntr;
226 #endif
227
228 #ifndef _LIBC
229 extern const char *_nl_language_preferences_default (void);
230 # define gl_locale_name_canonicalize _nl_locale_name_canonicalize
231 extern void _nl_locale_name_canonicalize (char *name);
232 # define gl_locale_name_from_win32_LANGID _nl_locale_name_from_win32_LANGID
233 /* extern const char *_nl_locale_name_from_win32_LANGID (LANGID langid); */
234 # define gl_locale_name_from_win32_LCID _nl_locale_name_from_win32_LCID
235 /* extern const char *_nl_locale_name_from_win32_LCID (LCID lcid); */
236 # define gl_locale_name_thread_unsafe _nl_locale_name_thread_unsafe
237 extern const char *_nl_locale_name_thread_unsafe (int category,
238 const char *categoryname);
239 # define gl_locale_name_thread _nl_locale_name_thread
240 /* extern const char *_nl_locale_name_thread (int category,
241 const char *categoryname); */
242 # define gl_locale_name_posix _nl_locale_name_posix
243 extern const char *_nl_locale_name_posix (int category,
244 const char *categoryname);
245 # define gl_locale_name_environ _nl_locale_name_environ
246 extern const char *_nl_locale_name_environ (int category,
247 const char *categoryname);
248 # define gl_locale_name_default _nl_locale_name_default
249 extern const char *_nl_locale_name_default (void);
250 # define gl_locale_name _nl_locale_name
251 /* extern const char *_nl_locale_name (int category,
252 const char *categoryname); */
253 #endif
254
255 struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale,
256 const char *__domainname,
257 struct binding *__domainbinding)
258 internal_function;
259 void _nl_load_domain (struct loaded_l10nfile *__domain,
260 struct binding *__domainbinding)
261 internal_function;
262
263 #ifdef IN_LIBGLOCALE
264 char *_nl_find_msg (struct loaded_l10nfile *domain_file,
265 struct binding *domainbinding, const char *encoding,
266 const char *msgid,
267 size_t *lengthp)
268 internal_function;
269 #else
270 char *_nl_find_msg (struct loaded_l10nfile *domain_file,
271 struct binding *domainbinding, const char *msgid,
272 int convert, size_t *lengthp)
273 internal_function;
274 #endif
275
276 /* The internal variables in the standalone libintl.a must have different
277 names than the internal variables in GNU libc, otherwise programs
278 using libintl.a cannot be linked statically. */
279 #if !defined _LIBC
280 # define _nl_default_dirname libintl_nl_default_dirname
281 # define _nl_domain_bindings libintl_nl_domain_bindings
282 #endif
283
284 /* Contains the default location of the message catalogs. */
285 extern const char _nl_default_dirname[];
286 #ifdef _LIBC
287 libc_hidden_proto (_nl_default_dirname)
288 #endif
289
290 /* List with bindings of specific domains. */
291 extern struct binding *_nl_domain_bindings;
292
293 /* The internal variables in the standalone libintl.a must have different
294 names than the internal variables in GNU libc, otherwise programs
295 using libintl.a cannot be linked statically. */
296 #if !defined _LIBC
297 # define _nl_default_default_domain libintl_nl_default_default_domain
298 # define _nl_current_default_domain libintl_nl_current_default_domain
299 #endif
300
301 /* Name of the default text domain. */
302 extern const char _nl_default_default_domain[] attribute_hidden;
303
304 /* Default text domain in which entries for gettext(3) are to be found. */
305 extern const char *_nl_current_default_domain attribute_hidden;
306
307 /* @@ begin of epilog @@ */
308
309 #endif /* gettextP.h */
310