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