libintl.h 16 KB

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