libintl.h
1 |
/* Message catalogs for internationalization.
|
---|---|
2 |
Copyright (C) 1995-1997, 2000-2016 Free Software Foundation, Inc.
|
3 |
This program is free software: you can redistribute it and/or modify
|
4 |
it under the terms of the GNU Lesser General Public License as published by
|
5 |
the Free Software Foundation; either version 2.1 of the License, or
|
6 |
(at your option) any later version.
|
7 |
This program is distributed in the hope that it will be useful,
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
10 |
GNU Lesser General Public License for more details.
|
11 |
You should have received a copy of the GNU Lesser General Public License
|
12 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
13 |
|
14 |
#ifndef _LIBINTL_H
|
15 |
#define _LIBINTL_H 1 |
16 |
|
17 |
#include <locale.h> |
18 |
#if (defined __APPLE__ && defined __MACH__) && 0 |
19 |
# include <xlocale.h> |
20 |
#endif
|
21 |
|
22 |
/* The LC_MESSAGES locale category is the category used by the functions
|
23 |
gettext() and dgettext(). It is specified in POSIX, but not in ANSI C.
|
24 |
On systems that don't define it, use an arbitrary value instead.
|
25 |
On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
|
26 |
then includes <libintl.h> (i.e. this file!) and then only defines
|
27 |
LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES
|
28 |
in this case. */
|
29 |
#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
|
30 |
# define LC_MESSAGES 1729 |
31 |
#endif
|
32 |
|
33 |
/* We define an additional symbol to signal that we use the GNU
|
34 |
implementation of gettext. */
|
35 |
#define __USE_GNU_GETTEXT 1 |
36 |
|
37 |
/* Provide information about the supported file formats. Returns the
|
38 |
maximum minor revision number supported for a given major revision. */
|
39 |
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
|
40 |
((major) == 0 || (major) == 1 ? 1 : -1) |
41 |
|
42 |
/* Resolve a platform specific conflict on DJGPP. GNU gettext takes
|
43 |
precedence over _conio_gettext. */
|
44 |
#ifdef __DJGPP__
|
45 |
# undef gettext
|
46 |
#endif
|
47 |
|
48 |
#ifdef __cplusplus
|
49 |
extern "C" { |
50 |
#endif
|
51 |
|
52 |
|
53 |
/* Version number: (major<<16) + (minor<<8) + subminor */
|
54 |
#define LIBINTL_VERSION 0x001308 |
55 |
extern int libintl_version; |
56 |
|
57 |
|
58 |
/* We redirect the functions to those prefixed with "libintl_". This is
|
59 |
necessary, because some systems define gettext/textdomain/... in the C
|
60 |
library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
|
61 |
If we used the unprefixed names, there would be cases where the
|
62 |
definition in the C library would override the one in the libintl.so
|
63 |
shared library. Recall that on ELF systems, the symbols are looked
|
64 |
up in the following order:
|
65 |
1. in the executable,
|
66 |
2. in the shared libraries specified on the link command line, in order,
|
67 |
3. in the dependencies of the shared libraries specified on the link
|
68 |
command line,
|
69 |
4. in the dlopen()ed shared libraries, in the order in which they were
|
70 |
dlopen()ed.
|
71 |
The definition in the C library would override the one in libintl.so if
|
72 |
either
|
73 |
* -lc is given on the link command line and -lintl isn't, or
|
74 |
* -lc is given on the link command line before -lintl, or
|
75 |
* libintl.so is a dependency of a dlopen()ed shared library but not
|
76 |
linked to the executable at link time.
|
77 |
Since Solaris gettext() behaves differently than GNU gettext(), this
|
78 |
would be unacceptable.
|
79 |
The redirection happens by default through macros in C, so that &gettext
|
80 |
is independent of the compilation unit, but through inline functions in
|
81 |
C++, in order not to interfere with the name mangling of class fields or
|
82 |
class methods called 'gettext'. */
|
83 |
|
84 |
/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
|
85 |
If he doesn't, we choose the method. A third possible method is
|
86 |
_INTL_REDIRECT_ASM, supported only by GCC. */
|
87 |
#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
|
88 |
# if defined __GNUC__ && __GNUC__ >= 2 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus) |
89 |
# define _INTL_REDIRECT_ASM
|
90 |
# else
|
91 |
# ifdef __cplusplus
|
92 |
# define _INTL_REDIRECT_INLINE
|
93 |
# else
|
94 |
# define _INTL_REDIRECT_MACROS
|
95 |
# endif
|
96 |
# endif
|
97 |
#endif
|
98 |
/* Auxiliary macros. */
|
99 |
#ifdef _INTL_REDIRECT_ASM
|
100 |
# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname)) |
101 |
# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
|
102 |
# define _INTL_STRINGIFY(prefix) #prefix |
103 |
#else
|
104 |
# define _INTL_ASM(cname)
|
105 |
#endif
|
106 |
|
107 |
/* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
|
108 |
its n-th argument literally. This enables GCC to warn for example about
|
109 |
printf (gettext ("foo %y")). */
|
110 |
#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && defined __cplusplus) |
111 |
# define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
|
112 |
#else
|
113 |
# define _INTL_MAY_RETURN_STRING_ARG(n)
|
114 |
#endif
|
115 |
|
116 |
/* Look up MSGID in the current default message catalog for the current
|
117 |
LC_MESSAGES locale. If not found, returns MSGID itself (the default
|
118 |
text). */
|
119 |
#ifdef _INTL_REDIRECT_INLINE
|
120 |
extern char *libintl_gettext (const char *__msgid) |
121 |
_INTL_MAY_RETURN_STRING_ARG (1);
|
122 |
static inline char *gettext (const char *__msgid) |
123 |
{ |
124 |
return libintl_gettext (__msgid);
|
125 |
} |
126 |
#else
|
127 |
#ifdef _INTL_REDIRECT_MACROS
|
128 |
# define gettext libintl_gettext
|
129 |
#endif
|
130 |
extern char *gettext (const char *__msgid) |
131 |
_INTL_ASM (libintl_gettext) |
132 |
_INTL_MAY_RETURN_STRING_ARG (1);
|
133 |
#endif
|
134 |
|
135 |
/* Look up MSGID in the DOMAINNAME message catalog for the current
|
136 |
LC_MESSAGES locale. */
|
137 |
#ifdef _INTL_REDIRECT_INLINE
|
138 |
extern char *libintl_dgettext (const char *__domainname, const char *__msgid) |
139 |
_INTL_MAY_RETURN_STRING_ARG (2);
|
140 |
static inline char *dgettext (const char *__domainname, const char *__msgid) |
141 |
{ |
142 |
return libintl_dgettext (__domainname, __msgid);
|
143 |
} |
144 |
#else
|
145 |
#ifdef _INTL_REDIRECT_MACROS
|
146 |
# define dgettext libintl_dgettext
|
147 |
#endif
|
148 |
extern char *dgettext (const char *__domainname, const char *__msgid) |
149 |
_INTL_ASM (libintl_dgettext) |
150 |
_INTL_MAY_RETURN_STRING_ARG (2);
|
151 |
#endif
|
152 |
|
153 |
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
|
154 |
locale. */
|
155 |
#ifdef _INTL_REDIRECT_INLINE
|
156 |
extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, |
157 |
int __category)
|
158 |
_INTL_MAY_RETURN_STRING_ARG (2);
|
159 |
static inline char *dcgettext (const char *__domainname, const char *__msgid, |
160 |
int __category)
|
161 |
{ |
162 |
return libintl_dcgettext (__domainname, __msgid, __category);
|
163 |
} |
164 |
#else
|
165 |
#ifdef _INTL_REDIRECT_MACROS
|
166 |
# define dcgettext libintl_dcgettext
|
167 |
#endif
|
168 |
extern char *dcgettext (const char *__domainname, const char *__msgid, |
169 |
int __category)
|
170 |
_INTL_ASM (libintl_dcgettext) |
171 |
_INTL_MAY_RETURN_STRING_ARG (2);
|
172 |
#endif
|
173 |
|
174 |
|
175 |
/* Similar to 'gettext' but select the plural form corresponding to the
|
176 |
number N. */
|
177 |
#ifdef _INTL_REDIRECT_INLINE
|
178 |
extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, |
179 |
unsigned long int __n) |
180 |
_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); |
181 |
static inline char *ngettext (const char *__msgid1, const char *__msgid2, |
182 |
unsigned long int __n) |
183 |
{ |
184 |
return libintl_ngettext (__msgid1, __msgid2, __n);
|
185 |
} |
186 |
#else
|
187 |
#ifdef _INTL_REDIRECT_MACROS
|
188 |
# define ngettext libintl_ngettext
|
189 |
#endif
|
190 |
extern char *ngettext (const char *__msgid1, const char *__msgid2, |
191 |
unsigned long int __n) |
192 |
_INTL_ASM (libintl_ngettext) |
193 |
_INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2); |
194 |
#endif
|
195 |
|
196 |
/* Similar to 'dgettext' but select the plural form corresponding to the
|
197 |
number N. */
|
198 |
#ifdef _INTL_REDIRECT_INLINE
|
199 |
extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, |
200 |
const char *__msgid2, unsigned long int __n) |
201 |
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
202 |
static inline char *dngettext (const char *__domainname, const char *__msgid1, |
203 |
const char *__msgid2, unsigned long int __n) |
204 |
{ |
205 |
return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
|
206 |
} |
207 |
#else
|
208 |
#ifdef _INTL_REDIRECT_MACROS
|
209 |
# define dngettext libintl_dngettext
|
210 |
#endif
|
211 |
extern char *dngettext (const char *__domainname, |
212 |
const char *__msgid1, const char *__msgid2, |
213 |
unsigned long int __n) |
214 |
_INTL_ASM (libintl_dngettext) |
215 |
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
216 |
#endif
|
217 |
|
218 |
/* Similar to 'dcgettext' but select the plural form corresponding to the
|
219 |
number N. */
|
220 |
#ifdef _INTL_REDIRECT_INLINE
|
221 |
extern char *libintl_dcngettext (const char *__domainname, |
222 |
const char *__msgid1, const char *__msgid2, |
223 |
unsigned long int __n, int __category) |
224 |
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
225 |
static inline char *dcngettext (const char *__domainname, |
226 |
const char *__msgid1, const char *__msgid2, |
227 |
unsigned long int __n, int __category) |
228 |
{ |
229 |
return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
|
230 |
} |
231 |
#else
|
232 |
#ifdef _INTL_REDIRECT_MACROS
|
233 |
# define dcngettext libintl_dcngettext
|
234 |
#endif
|
235 |
extern char *dcngettext (const char *__domainname, |
236 |
const char *__msgid1, const char *__msgid2, |
237 |
unsigned long int __n, int __category) |
238 |
_INTL_ASM (libintl_dcngettext) |
239 |
_INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3); |
240 |
#endif
|
241 |
|
242 |
|
243 |
|
244 |
/* Set the current default message catalog to DOMAINNAME.
|
245 |
If DOMAINNAME is null, return the current default.
|
246 |
If DOMAINNAME is "", reset to the default of "messages". */
|
247 |
#ifdef _INTL_REDIRECT_INLINE
|
248 |
extern char *libintl_textdomain (const char *__domainname); |
249 |
static inline char *textdomain (const char *__domainname) |
250 |
{ |
251 |
return libintl_textdomain (__domainname);
|
252 |
} |
253 |
#else
|
254 |
#ifdef _INTL_REDIRECT_MACROS
|
255 |
# define textdomain libintl_textdomain
|
256 |
#endif
|
257 |
extern char *textdomain (const char *__domainname) |
258 |
_INTL_ASM (libintl_textdomain); |
259 |
#endif
|
260 |
|
261 |
/* Specify that the DOMAINNAME message catalog will be found
|
262 |
in DIRNAME rather than in the system locale data base. */
|
263 |
#ifdef _INTL_REDIRECT_INLINE
|
264 |
extern char *libintl_bindtextdomain (const char *__domainname, |
265 |
const char *__dirname); |
266 |
static inline char *bindtextdomain (const char *__domainname, |
267 |
const char *__dirname) |
268 |
{ |
269 |
return libintl_bindtextdomain (__domainname, __dirname);
|
270 |
} |
271 |
#else
|
272 |
#ifdef _INTL_REDIRECT_MACROS
|
273 |
# define bindtextdomain libintl_bindtextdomain
|
274 |
#endif
|
275 |
extern char *bindtextdomain (const char *__domainname, const char *__dirname) |
276 |
_INTL_ASM (libintl_bindtextdomain); |
277 |
#endif
|
278 |
|
279 |
/* Specify the character encoding in which the messages from the
|
280 |
DOMAINNAME message catalog will be returned. */
|
281 |
#ifdef _INTL_REDIRECT_INLINE
|
282 |
extern char *libintl_bind_textdomain_codeset (const char *__domainname, |
283 |
const char *__codeset); |
284 |
static inline char *bind_textdomain_codeset (const char *__domainname, |
285 |
const char *__codeset) |
286 |
{ |
287 |
return libintl_bind_textdomain_codeset (__domainname, __codeset);
|
288 |
} |
289 |
#else
|
290 |
#ifdef _INTL_REDIRECT_MACROS
|
291 |
# define bind_textdomain_codeset libintl_bind_textdomain_codeset
|
292 |
#endif
|
293 |
extern char *bind_textdomain_codeset (const char *__domainname, |
294 |
const char *__codeset) |
295 |
_INTL_ASM (libintl_bind_textdomain_codeset); |
296 |
#endif
|
297 |
|
298 |
|
299 |
|
300 |
/* Support for format strings with positions in *printf(), following the
|
301 |
POSIX/XSI specification.
|
302 |
Note: These replacements for the *printf() functions are visible only
|
303 |
in source files that #include <libintl.h> or #include "gettext.h".
|
304 |
Packages that use *printf() in source files that don't refer to _()
|
305 |
or gettext() but for which the format string could be the return value
|
306 |
of _() or gettext() need to add this #include. Oh well. */
|
307 |
|
308 |
#if !0 |
309 |
|
310 |
#include <stdio.h> |
311 |
#include <stddef.h> |
312 |
|
313 |
/* Get va_list. */
|
314 |
#if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER
|
315 |
# include <stdarg.h> |
316 |
#else
|
317 |
# include <varargs.h> |
318 |
#endif
|
319 |
|
320 |
#if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
321 |
#undef fprintf
|
322 |
#define fprintf libintl_fprintf
|
323 |
extern int fprintf (FILE *, const char *, ...); |
324 |
#endif
|
325 |
#if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
326 |
#undef vfprintf
|
327 |
#define vfprintf libintl_vfprintf
|
328 |
extern int vfprintf (FILE *, const char *, va_list); |
329 |
#endif
|
330 |
|
331 |
#if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */ |
332 |
#undef printf
|
333 |
#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__ || defined _MSC_VER
|
334 |
/* Don't break __attribute__((format(printf,M,N))).
|
335 |
This redefinition is only possible because the libc in NetBSD, Cygwin,
|
336 |
mingw does not have a function __printf__.
|
337 |
Alternatively, we could have done this redirection only when compiling with
|
338 |
__GNUC__, together with a symbol redirection:
|
339 |
extern int printf (const char *, ...)
|
340 |
__asm__ (#__USER_LABEL_PREFIX__ "libintl_printf");
|
341 |
But doing it now would introduce a binary incompatibility with already
|
342 |
distributed versions of libintl on these systems. */
|
343 |
# define libintl_printf __printf__
|
344 |
#endif
|
345 |
#define printf libintl_printf
|
346 |
extern int printf (const char *, ...); |
347 |
#endif
|
348 |
#if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
349 |
#undef vprintf
|
350 |
#define vprintf libintl_vprintf
|
351 |
extern int vprintf (const char *, va_list); |
352 |
#endif
|
353 |
|
354 |
#if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
355 |
#undef sprintf
|
356 |
#define sprintf libintl_sprintf
|
357 |
extern int sprintf (char *, const char *, ...); |
358 |
#endif
|
359 |
#if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
360 |
#undef vsprintf
|
361 |
#define vsprintf libintl_vsprintf
|
362 |
extern int vsprintf (char *, const char *, va_list); |
363 |
#endif
|
364 |
|
365 |
#if 1 |
366 |
|
367 |
#if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
368 |
#undef snprintf
|
369 |
#define snprintf libintl_snprintf
|
370 |
extern int snprintf (char *, size_t, const char *, ...); |
371 |
#endif
|
372 |
#if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
373 |
#undef vsnprintf
|
374 |
#define vsnprintf libintl_vsnprintf
|
375 |
extern int vsnprintf (char *, size_t, const char *, va_list); |
376 |
#endif
|
377 |
|
378 |
#endif
|
379 |
|
380 |
#if 1 |
381 |
|
382 |
#if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
383 |
#undef asprintf
|
384 |
#define asprintf libintl_asprintf
|
385 |
extern int asprintf (char **, const char *, ...); |
386 |
#endif
|
387 |
#if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */ |
388 |
#undef vasprintf
|
389 |
#define vasprintf libintl_vasprintf
|
390 |
extern int vasprintf (char **, const char *, va_list); |
391 |
#endif
|
392 |
|
393 |
#endif
|
394 |
|
395 |
#if 0
|
396 |
|
397 |
#undef fwprintf
|
398 |
#define fwprintf libintl_fwprintf
|
399 |
extern int fwprintf (FILE *, const wchar_t *, ...);
|
400 |
#undef vfwprintf
|
401 |
#define vfwprintf libintl_vfwprintf
|
402 |
extern int vfwprintf (FILE *, const wchar_t *, va_list);
|
403 |
|
404 |
#undef wprintf
|
405 |
#define wprintf libintl_wprintf
|
406 |
extern int wprintf (const wchar_t *, ...);
|
407 |
#undef vwprintf
|
408 |
#define vwprintf libintl_vwprintf
|
409 |
extern int vwprintf (const wchar_t *, va_list);
|
410 |
|
411 |
#undef swprintf
|
412 |
#define swprintf libintl_swprintf
|
413 |
extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);
|
414 |
#undef vswprintf
|
415 |
#define vswprintf libintl_vswprintf
|
416 |
extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
|
417 |
|
418 |
#endif
|
419 |
|
420 |
#endif
|
421 |
|
422 |
|
423 |
/* Support for the locale chosen by the user. */
|
424 |
#if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__
|
425 |
|
426 |
#ifndef GNULIB_defined_setlocale /* don't override gnulib */ |
427 |
#undef setlocale
|
428 |
#define setlocale libintl_setlocale
|
429 |
extern char *setlocale (int, const char *); |
430 |
#endif
|
431 |
|
432 |
#if 0
|
433 |
|
434 |
#undef newlocale
|
435 |
#define newlocale libintl_newlocale
|
436 |
extern locale_t newlocale (int, const char *, locale_t);
|
437 |
|
438 |
#endif
|
439 |
|
440 |
#endif
|
441 |
|
442 |
|
443 |
/* Support for relocatable packages. */
|
444 |
|
445 |
/* Sets the original and the current installation prefix of the package.
|
446 |
Relocation simply replaces a pathname starting with the original prefix
|
447 |
by the corresponding pathname with the current prefix instead. Both
|
448 |
prefixes should be directory names without trailing slash (i.e. use ""
|
449 |
instead of "/"). */
|
450 |
#define libintl_set_relocation_prefix libintl_set_relocation_prefix
|
451 |
extern void |
452 |
libintl_set_relocation_prefix (const char *orig_prefix, |
453 |
const char *curr_prefix); |
454 |
|
455 |
|
456 |
#ifdef __cplusplus
|
457 |
} |
458 |
#endif
|
459 |
|
460 |
#endif /* libintl.h */ |