libintl.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /* Message catalogs for internationalization.
  2. Copyright (C) 1995-1997, 2000-2016, 2018-2019 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 <https://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 0x001400
  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 __clang__ && __clang__ && __clang_major__ >= 3) && 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
  109. _INTL_MAY_RETURN_STRING_ARG (1)
  110. char *gettext (const char *__msgid)
  111. {
  112. return libintl_gettext (__msgid);
  113. }
  114. #else
  115. #ifdef _INTL_REDIRECT_MACROS
  116. # define gettext libintl_gettext
  117. #endif
  118. extern char *gettext (const char *__msgid)
  119. _INTL_ASM (libintl_gettext)
  120. _INTL_MAY_RETURN_STRING_ARG (1);
  121. #endif
  122. /* Look up MSGID in the DOMAINNAME message catalog for the current
  123. LC_MESSAGES locale. */
  124. #ifdef _INTL_REDIRECT_INLINE
  125. extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
  126. _INTL_MAY_RETURN_STRING_ARG (2);
  127. static inline
  128. _INTL_MAY_RETURN_STRING_ARG (2)
  129. char *dgettext (const char *__domainname, const char *__msgid)
  130. {
  131. return libintl_dgettext (__domainname, __msgid);
  132. }
  133. #else
  134. #ifdef _INTL_REDIRECT_MACROS
  135. # define dgettext libintl_dgettext
  136. #endif
  137. extern char *dgettext (const char *__domainname, const char *__msgid)
  138. _INTL_ASM (libintl_dgettext)
  139. _INTL_MAY_RETURN_STRING_ARG (2);
  140. #endif
  141. /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
  142. locale. */
  143. #ifdef _INTL_REDIRECT_INLINE
  144. extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
  145. int __category)
  146. _INTL_MAY_RETURN_STRING_ARG (2);
  147. static inline
  148. _INTL_MAY_RETURN_STRING_ARG (2)
  149. char *dcgettext (const char *__domainname, const char *__msgid, int __category)
  150. {
  151. return libintl_dcgettext (__domainname, __msgid, __category);
  152. }
  153. #else
  154. #ifdef _INTL_REDIRECT_MACROS
  155. # define dcgettext libintl_dcgettext
  156. #endif
  157. extern char *dcgettext (const char *__domainname, const char *__msgid,
  158. int __category)
  159. _INTL_ASM (libintl_dcgettext)
  160. _INTL_MAY_RETURN_STRING_ARG (2);
  161. #endif
  162. /* Similar to 'gettext' but select the plural form corresponding to the
  163. number N. */
  164. #ifdef _INTL_REDIRECT_INLINE
  165. extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
  166. unsigned long int __n)
  167. _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
  168. static inline
  169. _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2)
  170. char *ngettext (const char *__msgid1, const char *__msgid2,
  171. unsigned long int __n)
  172. {
  173. return libintl_ngettext (__msgid1, __msgid2, __n);
  174. }
  175. #else
  176. #ifdef _INTL_REDIRECT_MACROS
  177. # define ngettext libintl_ngettext
  178. #endif
  179. extern char *ngettext (const char *__msgid1, const char *__msgid2,
  180. unsigned long int __n)
  181. _INTL_ASM (libintl_ngettext)
  182. _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
  183. #endif
  184. /* Similar to 'dgettext' but select the plural form corresponding to the
  185. number N. */
  186. #ifdef _INTL_REDIRECT_INLINE
  187. extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
  188. const char *__msgid2, unsigned long int __n)
  189. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  190. static inline
  191. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
  192. char *dngettext (const char *__domainname, const char *__msgid1,
  193. const char *__msgid2, unsigned long int __n)
  194. {
  195. return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
  196. }
  197. #else
  198. #ifdef _INTL_REDIRECT_MACROS
  199. # define dngettext libintl_dngettext
  200. #endif
  201. extern char *dngettext (const char *__domainname,
  202. const char *__msgid1, const char *__msgid2,
  203. unsigned long int __n)
  204. _INTL_ASM (libintl_dngettext)
  205. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  206. #endif
  207. /* Similar to 'dcgettext' but select the plural form corresponding to the
  208. number N. */
  209. #ifdef _INTL_REDIRECT_INLINE
  210. extern char *libintl_dcngettext (const char *__domainname,
  211. const char *__msgid1, const char *__msgid2,
  212. unsigned long int __n, int __category)
  213. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  214. static inline
  215. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3)
  216. char *dcngettext (const char *__domainname,
  217. const char *__msgid1, const char *__msgid2,
  218. unsigned long int __n, int __category)
  219. {
  220. return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
  221. }
  222. #else
  223. #ifdef _INTL_REDIRECT_MACROS
  224. # define dcngettext libintl_dcngettext
  225. #endif
  226. extern char *dcngettext (const char *__domainname,
  227. const char *__msgid1, const char *__msgid2,
  228. unsigned long int __n, int __category)
  229. _INTL_ASM (libintl_dcngettext)
  230. _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
  231. #endif
  232. /* Set the current default message catalog to DOMAINNAME.
  233. If DOMAINNAME is null, return the current default.
  234. If DOMAINNAME is "", reset to the default of "messages". */
  235. #ifdef _INTL_REDIRECT_INLINE
  236. extern char *libintl_textdomain (const char *__domainname);
  237. static inline char *textdomain (const char *__domainname)
  238. {
  239. return libintl_textdomain (__domainname);
  240. }
  241. #else
  242. #ifdef _INTL_REDIRECT_MACROS
  243. # define textdomain libintl_textdomain
  244. #endif
  245. extern char *textdomain (const char *__domainname)
  246. _INTL_ASM (libintl_textdomain);
  247. #endif
  248. /* Specify that the DOMAINNAME message catalog will be found
  249. in DIRNAME rather than in the system locale data base. */
  250. #ifdef _INTL_REDIRECT_INLINE
  251. extern char *libintl_bindtextdomain (const char *__domainname,
  252. const char *__dirname);
  253. static inline char *bindtextdomain (const char *__domainname,
  254. const char *__dirname)
  255. {
  256. return libintl_bindtextdomain (__domainname, __dirname);
  257. }
  258. #else
  259. #ifdef _INTL_REDIRECT_MACROS
  260. # define bindtextdomain libintl_bindtextdomain
  261. #endif
  262. extern char *bindtextdomain (const char *__domainname, const char *__dirname)
  263. _INTL_ASM (libintl_bindtextdomain);
  264. #endif
  265. /* Specify the character encoding in which the messages from the
  266. DOMAINNAME message catalog will be returned. */
  267. #ifdef _INTL_REDIRECT_INLINE
  268. extern char *libintl_bind_textdomain_codeset (const char *__domainname,
  269. const char *__codeset);
  270. static inline char *bind_textdomain_codeset (const char *__domainname,
  271. const char *__codeset)
  272. {
  273. return libintl_bind_textdomain_codeset (__domainname, __codeset);
  274. }
  275. #else
  276. #ifdef _INTL_REDIRECT_MACROS
  277. # define bind_textdomain_codeset libintl_bind_textdomain_codeset
  278. #endif
  279. extern char *bind_textdomain_codeset (const char *__domainname,
  280. const char *__codeset)
  281. _INTL_ASM (libintl_bind_textdomain_codeset);
  282. #endif
  283. /* Support for format strings with positions in *printf(), following the
  284. POSIX/XSI specification.
  285. Note: These replacements for the *printf() functions are visible only
  286. in source files that #include <libintl.h> or #include "gettext.h".
  287. Packages that use *printf() in source files that don't refer to _()
  288. or gettext() but for which the format string could be the return value
  289. of _() or gettext() need to add this #include. Oh well. */
  290. #if !0
  291. #include <stdio.h>
  292. #include <stddef.h>
  293. /* Get va_list. */
  294. #if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER
  295. # include <stdarg.h>
  296. #else
  297. # include <varargs.h>
  298. #endif
  299. #if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */
  300. #undef fprintf
  301. #define fprintf libintl_fprintf
  302. extern int fprintf (FILE *, const char *, ...);
  303. #endif
  304. #if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */
  305. #undef vfprintf
  306. #define vfprintf libintl_vfprintf
  307. extern int vfprintf (FILE *, const char *, va_list);
  308. #endif
  309. #if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */
  310. #undef printf
  311. #if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__
  312. /* Don't break __attribute__((format(printf,M,N))).
  313. This redefinition is only possible because the libc in NetBSD, Cygwin,
  314. mingw does not have a function __printf__.
  315. Alternatively, we could have done this redirection only when compiling with
  316. __GNUC__, together with a symbol redirection:
  317. extern int printf (const char *, ...)
  318. __asm__ (#__USER_LABEL_PREFIX__ "libintl_printf");
  319. But doing it now would introduce a binary incompatibility with already
  320. distributed versions of libintl on these systems. */
  321. # define libintl_printf __printf__
  322. #endif
  323. #define printf libintl_printf
  324. extern int printf (const char *, ...);
  325. #endif
  326. #if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */
  327. #undef vprintf
  328. #define vprintf libintl_vprintf
  329. extern int vprintf (const char *, va_list);
  330. #endif
  331. #if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */
  332. #undef sprintf
  333. #define sprintf libintl_sprintf
  334. extern int sprintf (char *, const char *, ...);
  335. #endif
  336. #if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */
  337. #undef vsprintf
  338. #define vsprintf libintl_vsprintf
  339. extern int vsprintf (char *, const char *, va_list);
  340. #endif
  341. #if 1
  342. #if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */
  343. #undef snprintf
  344. #define snprintf libintl_snprintf
  345. extern int snprintf (char *, size_t, const char *, ...);
  346. #endif
  347. #if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */
  348. #undef vsnprintf
  349. #define vsnprintf libintl_vsnprintf
  350. extern int vsnprintf (char *, size_t, const char *, va_list);
  351. #endif
  352. #endif
  353. #if 1
  354. #if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */
  355. #undef asprintf
  356. #define asprintf libintl_asprintf
  357. extern int asprintf (char **, const char *, ...);
  358. #endif
  359. #if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */
  360. #undef vasprintf
  361. #define vasprintf libintl_vasprintf
  362. extern int vasprintf (char **, const char *, va_list);
  363. #endif
  364. #endif
  365. #if 1
  366. #undef fwprintf
  367. #define fwprintf libintl_fwprintf
  368. extern int fwprintf (FILE *, const wchar_t *, ...);
  369. #undef vfwprintf
  370. #define vfwprintf libintl_vfwprintf
  371. extern int vfwprintf (FILE *, const wchar_t *, va_list);
  372. #undef wprintf
  373. #define wprintf libintl_wprintf
  374. extern int wprintf (const wchar_t *, ...);
  375. #undef vwprintf
  376. #define vwprintf libintl_vwprintf
  377. extern int vwprintf (const wchar_t *, va_list);
  378. #undef swprintf
  379. #define swprintf libintl_swprintf
  380. extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);
  381. #undef vswprintf
  382. #define vswprintf libintl_vswprintf
  383. extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
  384. #endif
  385. #endif
  386. /* Support for retrieving the name of a locale_t object. */
  387. #if 0
  388. #ifndef GNULIB_defined_newlocale /* don't override gnulib */
  389. #undef newlocale
  390. #define newlocale libintl_newlocale
  391. extern locale_t newlocale (int, const char *, locale_t);
  392. #endif
  393. #ifndef GNULIB_defined_duplocale /* don't override gnulib */
  394. #undef duplocale
  395. #define duplocale libintl_duplocale
  396. extern locale_t duplocale (locale_t);
  397. #endif
  398. #ifndef GNULIB_defined_freelocale /* don't override gnulib */
  399. #undef freelocale
  400. #define freelocale libintl_freelocale
  401. extern void freelocale (locale_t);
  402. #endif
  403. #endif
  404. /* Support for the locale chosen by the user. */
  405. #if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__
  406. #ifndef GNULIB_defined_setlocale /* don't override gnulib */
  407. #undef setlocale
  408. #define setlocale libintl_setlocale
  409. extern char *setlocale (int, const char *);
  410. #endif
  411. #if 0
  412. #undef newlocale
  413. #define newlocale libintl_newlocale
  414. /* Declare newlocale() only if the system headers define the 'locale_t' type. */
  415. #if !(defined __CYGWIN__ && !defined LC_ALL_MASK)
  416. extern locale_t newlocale (int, const char *, locale_t);
  417. #endif
  418. #endif
  419. #endif
  420. /* Support for relocatable packages. */
  421. /* Sets the original and the current installation prefix of the package.
  422. Relocation simply replaces a pathname starting with the original prefix
  423. by the corresponding pathname with the current prefix instead. Both
  424. prefixes should be directory names without trailing slash (i.e. use ""
  425. instead of "/"). */
  426. #define libintl_set_relocation_prefix libintl_set_relocation_prefix
  427. extern void
  428. libintl_set_relocation_prefix (const char *orig_prefix,
  429. const char *curr_prefix);
  430. #ifdef __cplusplus
  431. }
  432. #endif
  433. #endif /* libintl.h */