libintl.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /* Message catalogs for internationalization.
  2. Copyright (C) 1995-1997, 2000-2004 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU Library General Public License as published
  5. by the Free Software Foundation; either version 2, or (at your option)
  6. 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 GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  14. USA. */
  15. #ifndef _LIBINTL_H
  16. #define _LIBINTL_H 1
  17. #ifdef LIBINTL_STATIC
  18. #define LIBINTL_DLL_EXPORTED
  19. #else /* LIBINTL_STATIC */
  20. #ifdef BUILDING_LIBINTL
  21. #define LIBINTL_DLL_EXPORTED __declspec(dllexport)
  22. #else
  23. #define LIBINTL_DLL_EXPORTED __declspec(dllimport)
  24. #endif
  25. #endif /* LIBINTL_STATIC */
  26. #include <locale.h>
  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. /* We define an additional symbol to signal that we use the GNU
  38. implementation of gettext. */
  39. #define __USE_GNU_GETTEXT 1
  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. /* Resolve a platform specific conflict on DJGPP. GNU gettext takes
  45. precedence over _conio_gettext. */
  46. #ifdef __DJGPP__
  47. # undef gettext
  48. #endif
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. /* We redirect the functions to those prefixed with "libintl_". This is
  53. necessary, because some systems define gettext/textdomain/... in the C
  54. library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
  55. If we used the unprefixed names, there would be cases where the
  56. definition in the C library would override the one in the libintl.so
  57. shared library. Recall that on ELF systems, the symbols are looked
  58. up in the following order:
  59. 1. in the executable,
  60. 2. in the shared libraries specified on the link command line, in order,
  61. 3. in the dependencies of the shared libraries specified on the link
  62. command line,
  63. 4. in the dlopen()ed shared libraries, in the order in which they were
  64. dlopen()ed.
  65. The definition in the C library would override the one in libintl.so if
  66. either
  67. * -lc is given on the link command line and -lintl isn't, or
  68. * -lc is given on the link command line before -lintl, or
  69. * libintl.so is a dependency of a dlopen()ed shared library but not
  70. linked to the executable at link time.
  71. Since Solaris gettext() behaves differently than GNU gettext(), this
  72. would be unacceptable.
  73. The redirection happens by default through macros in C, so that &gettext
  74. is independent of the compilation unit, but through inline functions in
  75. C++, in order not to interfere with the name mangling of class fields or
  76. class methods called 'gettext'. */
  77. /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
  78. If he doesn't, we choose the method. A third possible method is
  79. _INTL_REDIRECT_ASM, supported only by GCC. */
  80. #if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
  81. # if __GNUC__ >= 2 && !defined __APPLE_CC__ && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus)
  82. # define _INTL_REDIRECT_ASM
  83. # else
  84. # ifdef __cplusplus
  85. # define _INTL_REDIRECT_INLINE
  86. # else
  87. # define _INTL_REDIRECT_MACROS
  88. # endif
  89. # endif
  90. #endif
  91. /* Auxiliary macros. */
  92. #ifdef _INTL_REDIRECT_ASM
  93. # define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
  94. # define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
  95. # define _INTL_STRINGIFY(prefix) #prefix
  96. #else
  97. # define _INTL_ASM(cname)
  98. #endif
  99. /* Look up MSGID in the current default message catalog for the current
  100. LC_MESSAGES locale. If not found, returns MSGID itself (the default
  101. text). */
  102. #ifdef _INTL_REDIRECT_INLINE
  103. extern LIBINTL_DLL_EXPORTED char *libintl_gettext (const char *__msgid);
  104. static inline char *gettext (const char *__msgid)
  105. {
  106. return libintl_gettext (__msgid);
  107. }
  108. #else
  109. #ifdef _INTL_REDIRECT_MACROS
  110. # define gettext libintl_gettext
  111. #endif
  112. extern LIBINTL_DLL_EXPORTED char *gettext (const char *__msgid)
  113. _INTL_ASM (libintl_gettext);
  114. #endif
  115. /* Look up MSGID in the DOMAINNAME message catalog for the current
  116. LC_MESSAGES locale. */
  117. #ifdef _INTL_REDIRECT_INLINE
  118. extern LIBINTL_DLL_EXPORTED char *libintl_dgettext (const char *__domainname, const char *__msgid);
  119. static inline char *dgettext (const char *__domainname, const char *__msgid)
  120. {
  121. return libintl_dgettext (__domainname, __msgid);
  122. }
  123. #else
  124. #ifdef _INTL_REDIRECT_MACROS
  125. # define dgettext libintl_dgettext
  126. #endif
  127. extern LIBINTL_DLL_EXPORTED char *dgettext (const char *__domainname, const char *__msgid)
  128. _INTL_ASM (libintl_dgettext);
  129. #endif
  130. /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
  131. locale. */
  132. #ifdef _INTL_REDIRECT_INLINE
  133. extern LIBINTL_DLL_EXPORTED char *libintl_dcgettext (const char *__domainname, const char *__msgid,
  134. int __category);
  135. static inline char *dcgettext (const char *__domainname, const char *__msgid,
  136. int __category)
  137. {
  138. return libintl_dcgettext (__domainname, __msgid, __category);
  139. }
  140. #else
  141. #ifdef _INTL_REDIRECT_MACROS
  142. # define dcgettext libintl_dcgettext
  143. #endif
  144. extern LIBINTL_DLL_EXPORTED char *dcgettext (const char *__domainname, const char *__msgid,
  145. int __category)
  146. _INTL_ASM (libintl_dcgettext);
  147. #endif
  148. /* Similar to `gettext' but select the plural form corresponding to the
  149. number N. */
  150. #ifdef _INTL_REDIRECT_INLINE
  151. extern LIBINTL_DLL_EXPORTED char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
  152. unsigned long int __n);
  153. static inline char *ngettext (const char *__msgid1, const char *__msgid2,
  154. unsigned long int __n)
  155. {
  156. return libintl_ngettext (__msgid1, __msgid2, __n);
  157. }
  158. #else
  159. #ifdef _INTL_REDIRECT_MACROS
  160. # define ngettext libintl_ngettext
  161. #endif
  162. extern LIBINTL_DLL_EXPORTED char *ngettext (const char *__msgid1, const char *__msgid2,
  163. unsigned long int __n)
  164. _INTL_ASM (libintl_ngettext);
  165. #endif
  166. /* Similar to `dgettext' but select the plural form corresponding to the
  167. number N. */
  168. #ifdef _INTL_REDIRECT_INLINE
  169. extern LIBINTL_DLL_EXPORTED char *libintl_dngettext (const char *__domainname, const char *__msgid1,
  170. const char *__msgid2, unsigned long int __n);
  171. static inline char *dngettext (const char *__domainname, const char *__msgid1,
  172. const char *__msgid2, unsigned long int __n)
  173. {
  174. return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
  175. }
  176. #else
  177. #ifdef _INTL_REDIRECT_MACROS
  178. # define dngettext libintl_dngettext
  179. #endif
  180. extern LIBINTL_DLL_EXPORTED char *dngettext (const char *__domainname,
  181. const char *__msgid1, const char *__msgid2,
  182. unsigned long int __n)
  183. _INTL_ASM (libintl_dngettext);
  184. #endif
  185. /* Similar to `dcgettext' but select the plural form corresponding to the
  186. number N. */
  187. #ifdef _INTL_REDIRECT_INLINE
  188. extern LIBINTL_DLL_EXPORTED char *libintl_dcngettext (const char *__domainname,
  189. const char *__msgid1, const char *__msgid2,
  190. unsigned long int __n, int __category);
  191. static inline char *dcngettext (const char *__domainname,
  192. const char *__msgid1, const char *__msgid2,
  193. unsigned long int __n, int __category)
  194. {
  195. return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
  196. }
  197. #else
  198. #ifdef _INTL_REDIRECT_MACROS
  199. # define dcngettext libintl_dcngettext
  200. #endif
  201. extern LIBINTL_DLL_EXPORTED char *dcngettext (const char *__domainname,
  202. const char *__msgid1, const char *__msgid2,
  203. unsigned long int __n, int __category)
  204. _INTL_ASM (libintl_dcngettext);
  205. #endif
  206. /* Set the current default message catalog to DOMAINNAME.
  207. If DOMAINNAME is null, return the current default.
  208. If DOMAINNAME is "", reset to the default of "messages". */
  209. #ifdef _INTL_REDIRECT_INLINE
  210. extern LIBINTL_DLL_EXPORTED char *libintl_textdomain (const char *__domainname);
  211. static inline char *textdomain (const char *__domainname)
  212. {
  213. return libintl_textdomain (__domainname);
  214. }
  215. #else
  216. #ifdef _INTL_REDIRECT_MACROS
  217. # define textdomain libintl_textdomain
  218. #endif
  219. extern LIBINTL_DLL_EXPORTED char *textdomain (const char *__domainname)
  220. _INTL_ASM (libintl_textdomain);
  221. #endif
  222. /* Specify that the DOMAINNAME message catalog will be found
  223. in DIRNAME rather than in the system locale data base. */
  224. #ifdef _INTL_REDIRECT_INLINE
  225. extern LIBINTL_DLL_EXPORTED char *libintl_bindtextdomain (const char *__domainname,
  226. const char *__dirname);
  227. static inline char *bindtextdomain (const char *__domainname,
  228. const char *__dirname)
  229. {
  230. return libintl_bindtextdomain (__domainname, __dirname);
  231. }
  232. #else
  233. #ifdef _INTL_REDIRECT_MACROS
  234. # define bindtextdomain libintl_bindtextdomain
  235. #endif
  236. extern LIBINTL_DLL_EXPORTED char *bindtextdomain (const char *__domainname, const char *__dirname)
  237. _INTL_ASM (libintl_bindtextdomain);
  238. #endif
  239. /* Specify the character encoding in which the messages from the
  240. DOMAINNAME message catalog will be returned. */
  241. #ifdef _INTL_REDIRECT_INLINE
  242. extern LIBINTL_DLL_EXPORTED char *libintl_bind_textdomain_codeset (const char *__domainname,
  243. const char *__codeset);
  244. static inline char *bind_textdomain_codeset (const char *__domainname,
  245. const char *__codeset)
  246. {
  247. return libintl_bind_textdomain_codeset (__domainname, __codeset);
  248. }
  249. #else
  250. #ifdef _INTL_REDIRECT_MACROS
  251. # define bind_textdomain_codeset libintl_bind_textdomain_codeset
  252. #endif
  253. extern LIBINTL_DLL_EXPORTED char *bind_textdomain_codeset (const char *__domainname,
  254. const char *__codeset)
  255. _INTL_ASM (libintl_bind_textdomain_codeset);
  256. #endif
  257. /* Support for format strings with positions in *printf(), following the
  258. POSIX/XSI specification.
  259. Note: These replacements for the *printf() functions are visible only
  260. in source files that #include <libintl.h> or #include "gettext.h".
  261. Packages that use *printf() in source files that don't refer to _()
  262. or gettext() but for which the format string could be the return value
  263. of _() or gettext() need to add this #include. Oh well. */
  264. #if 0
  265. #include <stdio.h>
  266. #include <stddef.h>
  267. /* Get va_list. */
  268. #if __STDC__ || defined __cplusplus || defined _MSC_VER
  269. # include <stdarg.h>
  270. #else
  271. # include <varargs.h>
  272. #endif
  273. #undef fprintf
  274. #define fprintf libintl_fprintf
  275. extern LIBINTL_DLL_EXPORTED int fprintf (FILE *, const char *, ...);
  276. #undef vfprintf
  277. #define vfprintf libintl_vfprintf
  278. extern LIBINTL_DLL_EXPORTED int vfprintf (FILE *, const char *, va_list);
  279. #undef printf
  280. #define printf libintl_printf
  281. extern LIBINTL_DLL_EXPORTED int printf (const char *, ...);
  282. #undef vprintf
  283. #define vprintf libintl_vprintf
  284. extern LIBINTL_DLL_EXPORTED int vprintf (const char *, va_list);
  285. #undef sprintf
  286. #define sprintf libintl_sprintf
  287. extern LIBINTL_DLL_EXPORTED int sprintf (char *, const char *, ...);
  288. #undef vsprintf
  289. #define vsprintf libintl_vsprintf
  290. extern LIBINTL_DLL_EXPORTED int vsprintf (char *, const char *, va_list);
  291. #if 0
  292. #undef snprintf
  293. #define snprintf libintl_snprintf
  294. extern LIBINTL_DLL_EXPORTED int snprintf (char *, size_t, const char *, ...);
  295. #undef vsnprintf
  296. #define vsnprintf libintl_vsnprintf
  297. extern LIBINTL_DLL_EXPORTED int vsnprintf (char *, size_t, const char *, va_list);
  298. #endif
  299. #if 0
  300. #undef asprintf
  301. #define asprintf libintl_asprintf
  302. extern LIBINTL_DLL_EXPORTED int asprintf (char **, const char *, ...);
  303. #undef vasprintf
  304. #define vasprintf libintl_vasprintf
  305. extern LIBINTL_DLL_EXPORTED int vasprintf (char **, const char *, va_list);
  306. #endif
  307. #if 1
  308. #undef fwprintf
  309. #define fwprintf libintl_fwprintf
  310. extern LIBINTL_DLL_EXPORTED int fwprintf (FILE *, const wchar_t *, ...);
  311. #undef vfwprintf
  312. #define vfwprintf libintl_vfwprintf
  313. extern LIBINTL_DLL_EXPORTED int vfwprintf (FILE *, const wchar_t *, va_list);
  314. #undef wprintf
  315. #define wprintf libintl_wprintf
  316. extern LIBINTL_DLL_EXPORTED int wprintf (const wchar_t *, ...);
  317. #undef vwprintf
  318. #define vwprintf libintl_vwprintf
  319. extern LIBINTL_DLL_EXPORTED int vwprintf (const wchar_t *, va_list);
  320. #undef swprintf
  321. #define swprintf libintl_swprintf
  322. extern LIBINTL_DLL_EXPORTED int swprintf (wchar_t *, size_t, const wchar_t *, ...);
  323. #undef vswprintf
  324. #define vswprintf libintl_vswprintf
  325. extern LIBINTL_DLL_EXPORTED int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
  326. #endif
  327. #endif
  328. /* Support for relocatable packages. */
  329. /* Sets the original and the current installation prefix of the package.
  330. Relocation simply replaces a pathname starting with the original prefix
  331. by the corresponding pathname with the current prefix instead. Both
  332. prefixes should be directory names without trailing slash (i.e. use ""
  333. instead of "/"). */
  334. #define libintl_set_relocation_prefix libintl_set_relocation_prefix
  335. extern LIBINTL_DLL_EXPORTED void
  336. libintl_set_relocation_prefix (const char *orig_prefix,
  337. const char *curr_prefix);
  338. #ifdef __cplusplus
  339. }
  340. #endif
  341. #endif /* libintl.h */