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