1 /* Message catalogs for internationalization.
2 Copyright (C) 1995-1997, 2000-2015 Free Software Foundation,
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.
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.
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/>. */
22 #if (defined __APPLE__ && defined __MACH__) && @HAVE_NEWLOCALE@
26 /* The LC_MESSAGES locale category is the category used by the functions
27 gettext() and dgettext(). It is specified in POSIX, but not in ANSI C.
28 On systems that don't define it, use an arbitrary value instead.
29 On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
30 then includes <libintl.h> (i.e. this file!) and then only defines
31 LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES
33 #if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
34 # define LC_MESSAGES 1729
37 /* We define an additional symbol to signal that we use the GNU
38 implementation of gettext. */
39 #define __USE_GNU_GETTEXT 1
41 /* Provide information about the supported file formats. Returns the
42 maximum minor revision number supported for a given major revision. */
43 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
44 ((major) == 0 || (major) == 1 ? 1 : -1)
46 /* Resolve a platform specific conflict on DJGPP. GNU gettext takes
47 precedence over _conio_gettext. */
57 /* Version number: (major<<16) + (minor<<8) + subminor */
58 #define LIBINTL_VERSION 0x001307
59 extern int libintl_version;
62 /* We redirect the functions to those prefixed with "libintl_". This is
63 necessary, because some systems define gettext/textdomain/... in the C
64 library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
65 If we used the unprefixed names, there would be cases where the
66 definition in the C library would override the one in the libintl.so
67 shared library. Recall that on ELF systems, the symbols are looked
68 up in the following order:
70 2. in the shared libraries specified on the link command line, in order,
71 3. in the dependencies of the shared libraries specified on the link
73 4. in the dlopen()ed shared libraries, in the order in which they were
75 The definition in the C library would override the one in libintl.so if
77 * -lc is given on the link command line and -lintl isn't, or
78 * -lc is given on the link command line before -lintl, or
79 * libintl.so is a dependency of a dlopen()ed shared library but not
80 linked to the executable at link time.
81 Since Solaris gettext() behaves differently than GNU gettext(), this
82 would be unacceptable.
84 The redirection happens by default through macros in C, so that &gettext
85 is independent of the compilation unit, but through inline functions in
86 C++, in order not to interfere with the name mangling of class fields or
87 class methods called 'gettext'. */
89 /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
90 If he doesn't, we choose the method. A third possible method is
91 _INTL_REDIRECT_ASM, supported only by GCC. */
92 #if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
93 # if defined __GNUC__ && __GNUC__ >= 2 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus)
94 # define _INTL_REDIRECT_ASM
97 # define _INTL_REDIRECT_INLINE
99 # define _INTL_REDIRECT_MACROS
103 /* Auxiliary macros. */
104 #ifdef _INTL_REDIRECT_ASM
105 # define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
106 # define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
107 # define _INTL_STRINGIFY(prefix) #prefix
109 # define _INTL_ASM(cname)
112 /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
113 its n-th argument literally. This enables GCC to warn for example about
114 printf (gettext ("foo %y")). */
115 #if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && defined __cplusplus)
116 # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
118 # define _INTL_MAY_RETURN_STRING_ARG(n)
121 /* Look up MSGID in the current default message catalog for the current
122 LC_MESSAGES locale. If not found, returns MSGID itself (the default
124 #ifdef _INTL_REDIRECT_INLINE
125 extern char *libintl_gettext (const char *__msgid)
126 _INTL_MAY_RETURN_STRING_ARG (1);
127 static inline char *gettext (const char *__msgid)
129 return libintl_gettext (__msgid);
132 #ifdef _INTL_REDIRECT_MACROS
133 # define gettext libintl_gettext
135 extern char *gettext (const char *__msgid)
136 _INTL_ASM (libintl_gettext)
137 _INTL_MAY_RETURN_STRING_ARG (1);
140 /* Look up MSGID in the DOMAINNAME message catalog for the current
141 LC_MESSAGES locale. */
142 #ifdef _INTL_REDIRECT_INLINE
143 extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
144 _INTL_MAY_RETURN_STRING_ARG (2);
145 static inline char *dgettext (const char *__domainname, const char *__msgid)
147 return libintl_dgettext (__domainname, __msgid);
150 #ifdef _INTL_REDIRECT_MACROS
151 # define dgettext libintl_dgettext
153 extern char *dgettext (const char *__domainname, const char *__msgid)
154 _INTL_ASM (libintl_dgettext)
155 _INTL_MAY_RETURN_STRING_ARG (2);
158 /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
160 #ifdef _INTL_REDIRECT_INLINE
161 extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
163 _INTL_MAY_RETURN_STRING_ARG (2);
164 static inline char *dcgettext (const char *__domainname, const char *__msgid,
167 return libintl_dcgettext (__domainname, __msgid, __category);
170 #ifdef _INTL_REDIRECT_MACROS
171 # define dcgettext libintl_dcgettext
173 extern char *dcgettext (const char *__domainname, const char *__msgid,
175 _INTL_ASM (libintl_dcgettext)
176 _INTL_MAY_RETURN_STRING_ARG (2);
180 /* Similar to 'gettext' but select the plural form corresponding to the
182 #ifdef _INTL_REDIRECT_INLINE
183 extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
184 unsigned long int __n)
185 _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
186 static inline char *ngettext (const char *__msgid1, const char *__msgid2,
187 unsigned long int __n)
189 return libintl_ngettext (__msgid1, __msgid2, __n);
192 #ifdef _INTL_REDIRECT_MACROS
193 # define ngettext libintl_ngettext
195 extern char *ngettext (const char *__msgid1, const char *__msgid2,
196 unsigned long int __n)
197 _INTL_ASM (libintl_ngettext)
198 _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
201 /* Similar to 'dgettext' but select the plural form corresponding to the
203 #ifdef _INTL_REDIRECT_INLINE
204 extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
205 const char *__msgid2, unsigned long int __n)
206 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
207 static inline char *dngettext (const char *__domainname, const char *__msgid1,
208 const char *__msgid2, unsigned long int __n)
210 return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
213 #ifdef _INTL_REDIRECT_MACROS
214 # define dngettext libintl_dngettext
216 extern char *dngettext (const char *__domainname,
217 const char *__msgid1, const char *__msgid2,
218 unsigned long int __n)
219 _INTL_ASM (libintl_dngettext)
220 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
223 /* Similar to 'dcgettext' but select the plural form corresponding to the
225 #ifdef _INTL_REDIRECT_INLINE
226 extern char *libintl_dcngettext (const char *__domainname,
227 const char *__msgid1, const char *__msgid2,
228 unsigned long int __n, int __category)
229 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
230 static inline char *dcngettext (const char *__domainname,
231 const char *__msgid1, const char *__msgid2,
232 unsigned long int __n, int __category)
234 return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
237 #ifdef _INTL_REDIRECT_MACROS
238 # define dcngettext libintl_dcngettext
240 extern char *dcngettext (const char *__domainname,
241 const char *__msgid1, const char *__msgid2,
242 unsigned long int __n, int __category)
243 _INTL_ASM (libintl_dcngettext)
244 _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
248 #ifndef IN_LIBGLOCALE
250 /* Set the current default message catalog to DOMAINNAME.
251 If DOMAINNAME is null, return the current default.
252 If DOMAINNAME is "", reset to the default of "messages". */
253 #ifdef _INTL_REDIRECT_INLINE
254 extern char *libintl_textdomain (const char *__domainname);
255 static inline char *textdomain (const char *__domainname)
257 return libintl_textdomain (__domainname);
260 #ifdef _INTL_REDIRECT_MACROS
261 # define textdomain libintl_textdomain
263 extern char *textdomain (const char *__domainname)
264 _INTL_ASM (libintl_textdomain);
267 /* Specify that the DOMAINNAME message catalog will be found
268 in DIRNAME rather than in the system locale data base. */
269 #ifdef _INTL_REDIRECT_INLINE
270 extern char *libintl_bindtextdomain (const char *__domainname,
271 const char *__dirname);
272 static inline char *bindtextdomain (const char *__domainname,
273 const char *__dirname)
275 return libintl_bindtextdomain (__domainname, __dirname);
278 #ifdef _INTL_REDIRECT_MACROS
279 # define bindtextdomain libintl_bindtextdomain
281 extern char *bindtextdomain (const char *__domainname, const char *__dirname)
282 _INTL_ASM (libintl_bindtextdomain);
285 /* Specify the character encoding in which the messages from the
286 DOMAINNAME message catalog will be returned. */
287 #ifdef _INTL_REDIRECT_INLINE
288 extern char *libintl_bind_textdomain_codeset (const char *__domainname,
289 const char *__codeset);
290 static inline char *bind_textdomain_codeset (const char *__domainname,
291 const char *__codeset)
293 return libintl_bind_textdomain_codeset (__domainname, __codeset);
296 #ifdef _INTL_REDIRECT_MACROS
297 # define bind_textdomain_codeset libintl_bind_textdomain_codeset
299 extern char *bind_textdomain_codeset (const char *__domainname,
300 const char *__codeset)
301 _INTL_ASM (libintl_bind_textdomain_codeset);
304 #endif /* IN_LIBGLOCALE */
307 /* Support for format strings with positions in *printf(), following the
308 POSIX/XSI specification.
309 Note: These replacements for the *printf() functions are visible only
310 in source files that #include <libintl.h> or #include "gettext.h".
311 Packages that use *printf() in source files that don't refer to _()
312 or gettext() but for which the format string could be the return value
313 of _() or gettext() need to add this #include. Oh well. */
315 #if !@HAVE_POSIX_PRINTF@
321 #if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER
324 # include <varargs.h>
327 #if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */
329 #define fprintf libintl_fprintf
330 extern int fprintf (FILE *, const char *, ...);
332 #if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */
334 #define vfprintf libintl_vfprintf
335 extern int vfprintf (FILE *, const char *, va_list);
338 #if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */
340 #if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__
341 /* Don't break __attribute__((format(printf,M,N))).
342 This redefinition is only possible because the libc in NetBSD, Cygwin,
343 mingw does not have a function __printf__.
344 Alternatively, we could have done this redirection only when compiling with
345 __GNUC__, together with a symbol redirection:
346 extern int printf (const char *, ...)
347 __asm__ (#__USER_LABEL_PREFIX__ "libintl_printf");
348 But doing it now would introduce a binary incompatibility with already
349 distributed versions of libintl on these systems. */
350 # define libintl_printf __printf__
352 #define printf libintl_printf
353 extern int printf (const char *, ...);
355 #if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */
357 #define vprintf libintl_vprintf
358 extern int vprintf (const char *, va_list);
361 #if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */
363 #define sprintf libintl_sprintf
364 extern int sprintf (char *, const char *, ...);
366 #if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */
368 #define vsprintf libintl_vsprintf
369 extern int vsprintf (char *, const char *, va_list);
374 #if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */
376 #define snprintf libintl_snprintf
377 extern int snprintf (char *, size_t, const char *, ...);
379 #if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */
381 #define vsnprintf libintl_vsnprintf
382 extern int vsnprintf (char *, size_t, const char *, va_list);
389 #if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */
391 #define asprintf libintl_asprintf
392 extern int asprintf (char **, const char *, ...);
394 #if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */
396 #define vasprintf libintl_vasprintf
397 extern int vasprintf (char **, const char *, va_list);
405 #define fwprintf libintl_fwprintf
406 extern int fwprintf (FILE *, const wchar_t *, ...);
408 #define vfwprintf libintl_vfwprintf
409 extern int vfwprintf (FILE *, const wchar_t *, va_list);
412 #define wprintf libintl_wprintf
413 extern int wprintf (const wchar_t *, ...);
415 #define vwprintf libintl_vwprintf
416 extern int vwprintf (const wchar_t *, va_list);
419 #define swprintf libintl_swprintf
420 extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);
422 #define vswprintf libintl_vswprintf
423 extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
430 /* Support for the locale chosen by the user. */
431 #if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__
433 #ifndef GNULIB_defined_setlocale /* don't override gnulib */
435 #define setlocale libintl_setlocale
436 extern char *setlocale (int, const char *);
442 #define newlocale libintl_newlocale
443 extern locale_t newlocale (int, const char *, locale_t);
450 /* Support for relocatable packages. */
452 /* Sets the original and the current installation prefix of the package.
453 Relocation simply replaces a pathname starting with the original prefix
454 by the corresponding pathname with the current prefix instead. Both
455 prefixes should be directory names without trailing slash (i.e. use ""
457 #define libintl_set_relocation_prefix libintl_set_relocation_prefix
459 libintl_set_relocation_prefix (const char *orig_prefix,
460 const char *curr_prefix);
467 #endif /* libintl.h */