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