libgnuintl.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /* Message catalogs for internationalization.
  2. Copyright (C) 1995-1997, 2000-2003 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
  14. USA. */
  15. #ifndef _LIBINTL_H
  16. #define _LIBINTL_H 1
  17. #include <locale.h>
  18. /* The LC_MESSAGES locale category is the category used by the functions
  19. gettext() and dgettext(). It is specified in POSIX, but not in ANSI C.
  20. On systems that don't define it, use an arbitrary value instead.
  21. On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
  22. then includes <libintl.h> (i.e. this file!) and then only defines
  23. LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES
  24. in this case. */
  25. #if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
  26. # define LC_MESSAGES 1729
  27. #endif
  28. /* We define an additional symbol to signal that we use the GNU
  29. implementation of gettext. */
  30. #define __USE_GNU_GETTEXT 1
  31. /* Provide information about the supported file formats. Returns the
  32. maximum minor revision number supported for a given major revision. */
  33. #define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
  34. ((major) == 0 ? 1 : -1)
  35. /* Resolve a platform specific conflict on DJGPP. GNU gettext takes
  36. precedence over _conio_gettext. */
  37. #ifdef __DJGPP__
  38. # undef gettext
  39. #endif
  40. /* Use _INTL_PARAMS, not PARAMS, in order to avoid clashes with identifiers
  41. used by programs. Similarly, test __PROTOTYPES, not PROTOTYPES. */
  42. #ifndef _INTL_PARAMS
  43. # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
  44. # define _INTL_PARAMS(args) args
  45. # else
  46. # define _INTL_PARAMS(args) ()
  47. # endif
  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 __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. /* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
  100. its n-th argument literally. This enables GCC to warn for example about
  101. printf (gettext ("foo %y")). */
  102. #if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && !(defined __clang__ && __clang__ && __clang_major__ >= 3) && defined __cplusplus)
  103. # define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
  104. #else
  105. # define _INTL_MAY_RETURN_STRING_ARG(n)
  106. #endif
  107. /* Look up MSGID in the current default message catalog for the current
  108. LC_MESSAGES locale. If not found, returns MSGID itself (the default
  109. text). */
  110. #ifdef _INTL_REDIRECT_INLINE
  111. extern char *libintl_gettext (const char *__msgid)
  112. _INTL_MAY_RETURN_STRING_ARG (1);
  113. static inline
  114. _INTL_MAY_RETURN_STRING_ARG (1)
  115. char *gettext (const char *__msgid)
  116. {
  117. return libintl_gettext (__msgid);
  118. }
  119. #else
  120. #ifdef _INTL_REDIRECT_MACROS
  121. # define gettext libintl_gettext
  122. #endif
  123. extern char *gettext _INTL_PARAMS ((const char *__msgid))
  124. _INTL_ASM (libintl_gettext)
  125. _INTL_MAY_RETURN_STRING_ARG (1);
  126. #endif
  127. /* Look up MSGID in the DOMAINNAME message catalog for the current
  128. LC_MESSAGES locale. */
  129. #ifdef _INTL_REDIRECT_INLINE
  130. extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
  131. _INTL_MAY_RETURN_STRING_ARG (2);
  132. static inline
  133. _INTL_MAY_RETURN_STRING_ARG (2)
  134. char *dgettext (const char *__domainname, const char *__msgid)
  135. {
  136. return libintl_dgettext (__domainname, __msgid);
  137. }
  138. #else
  139. #ifdef _INTL_REDIRECT_MACROS
  140. # define dgettext libintl_dgettext
  141. #endif
  142. extern char *dgettext _INTL_PARAMS ((const char *__domainname,
  143. const char *__msgid))
  144. _INTL_ASM (libintl_dgettext)
  145. _INTL_MAY_RETURN_STRING_ARG (2);
  146. #endif
  147. /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
  148. locale. */
  149. #ifdef _INTL_REDIRECT_INLINE
  150. extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
  151. int __category)
  152. _INTL_MAY_RETURN_STRING_ARG (2);
  153. static inline
  154. _INTL_MAY_RETURN_STRING_ARG (2)
  155. char *dcgettext (const char *__domainname, const char *__msgid, int __category)
  156. {
  157. return libintl_dcgettext (__domainname, __msgid, __category);
  158. }
  159. #else
  160. #ifdef _INTL_REDIRECT_MACROS
  161. # define dcgettext libintl_dcgettext
  162. #endif
  163. extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
  164. const char *__msgid,
  165. int __category))
  166. _INTL_ASM (libintl_dcgettext)
  167. _INTL_MAY_RETURN_STRING_ARG (2);
  168. #endif
  169. /* Similar to `gettext' but select the plural form corresponding to the
  170. number N. */
  171. #ifdef _INTL_REDIRECT_INLINE
  172. extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
  173. unsigned long int __n)
  174. _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
  175. static inline
  176. _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2)
  177. char *ngettext (const char *__msgid1, const char *__msgid2,
  178. unsigned long int __n)
  179. {
  180. return libintl_ngettext (__msgid1, __msgid2, __n);
  181. }
  182. #else
  183. #ifdef _INTL_REDIRECT_MACROS
  184. # define ngettext libintl_ngettext
  185. #endif
  186. extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
  187. const char *__msgid2,
  188. unsigned long int __n))
  189. _INTL_ASM (libintl_ngettext)
  190. _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
  191. #endif
  192. /* Similar to `dgettext' but select the plural form corresponding to the
  193. number N. */
  194. #ifdef _INTL_REDIRECT_INLINE
  195. extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
  196. const char *__msgid2, unsigned long int __n)
  197. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  198. static inline
  199. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
  200. char *dngettext (const char *__domainname, const char *__msgid1,
  201. const char *__msgid2, unsigned long int __n)
  202. {
  203. return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
  204. }
  205. #else
  206. #ifdef _INTL_REDIRECT_MACROS
  207. # define dngettext libintl_dngettext
  208. #endif
  209. extern char *dngettext _INTL_PARAMS ((const char *__domainname,
  210. const char *__msgid1,
  211. const char *__msgid2,
  212. unsigned long int __n))
  213. _INTL_ASM (libintl_dngettext)
  214. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  215. #endif
  216. /* Similar to `dcgettext' but select the plural form corresponding to the
  217. number N. */
  218. #ifdef _INTL_REDIRECT_INLINE
  219. extern char *libintl_dcngettext (const char *__domainname,
  220. const char *__msgid1, const char *__msgid2,
  221. unsigned long int __n, int __category)
  222. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  223. static inline
  224. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
  225. char *dcngettext (const char *__domainname,
  226. const char *__msgid1, const char *__msgid2,
  227. unsigned long int __n, int __category)
  228. {
  229. return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
  230. }
  231. #else
  232. #ifdef _INTL_REDIRECT_MACROS
  233. # define dcngettext libintl_dcngettext
  234. #endif
  235. extern char *dcngettext _INTL_PARAMS ((const char *__domainname,
  236. const char *__msgid1,
  237. const char *__msgid2,
  238. unsigned long int __n,
  239. int __category))
  240. _INTL_ASM (libintl_dcngettext)
  241. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  242. #endif
  243. /* Set the current default message catalog to DOMAINNAME.
  244. If DOMAINNAME is null, return the current default.
  245. If DOMAINNAME is "", reset to the default of "messages". */
  246. #ifdef _INTL_REDIRECT_INLINE
  247. extern char *libintl_textdomain (const char *__domainname);
  248. static inline char *textdomain (const char *__domainname)
  249. {
  250. return libintl_textdomain (__domainname);
  251. }
  252. #else
  253. #ifdef _INTL_REDIRECT_MACROS
  254. # define textdomain libintl_textdomain
  255. #endif
  256. extern char *textdomain _INTL_PARAMS ((const char *__domainname))
  257. _INTL_ASM (libintl_textdomain);
  258. #endif
  259. /* Specify that the DOMAINNAME message catalog will be found
  260. in DIRNAME rather than in the system locale data base. */
  261. #ifdef _INTL_REDIRECT_INLINE
  262. extern char *libintl_bindtextdomain (const char *__domainname,
  263. const char *__dirname);
  264. static inline char *bindtextdomain (const char *__domainname,
  265. const char *__dirname)
  266. {
  267. return libintl_bindtextdomain (__domainname, __dirname);
  268. }
  269. #else
  270. #ifdef _INTL_REDIRECT_MACROS
  271. # define bindtextdomain libintl_bindtextdomain
  272. #endif
  273. extern char *bindtextdomain _INTL_PARAMS ((const char *__domainname,
  274. const char *__dirname))
  275. _INTL_ASM (libintl_bindtextdomain);
  276. #endif
  277. /* Specify the character encoding in which the messages from the
  278. DOMAINNAME message catalog will be returned. */
  279. #ifdef _INTL_REDIRECT_INLINE
  280. extern char *libintl_bind_textdomain_codeset (const char *__domainname,
  281. const char *__codeset);
  282. static inline char *bind_textdomain_codeset (const char *__domainname,
  283. const char *__codeset)
  284. {
  285. return libintl_bind_textdomain_codeset (__domainname, __codeset);
  286. }
  287. #else
  288. #ifdef _INTL_REDIRECT_MACROS
  289. # define bind_textdomain_codeset libintl_bind_textdomain_codeset
  290. #endif
  291. extern char *bind_textdomain_codeset _INTL_PARAMS ((const char *__domainname,
  292. const char *__codeset))
  293. _INTL_ASM (libintl_bind_textdomain_codeset);
  294. #endif
  295. /* Support for relocatable packages. */
  296. /* Sets the original and the current installation prefix of the package.
  297. Relocation simply replaces a pathname starting with the original prefix
  298. by the corresponding pathname with the current prefix instead. Both
  299. prefixes should be directory names without trailing slash (i.e. use ""
  300. instead of "/"). */
  301. #define libintl_set_relocation_prefix libintl_set_relocation_prefix
  302. extern void
  303. libintl_set_relocation_prefix _INTL_PARAMS ((const char *orig_prefix,
  304. const char *curr_prefix));
  305. #ifdef __cplusplus
  306. }
  307. #endif
  308. #endif /* libintl.h */