gettextP.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* Header describing internals of libintl library.
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef _GETTEXTP_H
  15. #define _GETTEXTP_H
  16. #include <stddef.h> /* Get size_t. */
  17. #ifdef _LIBC
  18. # include "../iconv/gconv_int.h"
  19. #else
  20. # if HAVE_ICONV
  21. # include <iconv.h>
  22. # endif
  23. #endif
  24. /* Handle multi-threaded applications. */
  25. #ifdef _LIBC
  26. # include <libc-lock.h>
  27. # define gl_rwlock_define __libc_rwlock_define
  28. #else
  29. # include "lock.h"
  30. #endif
  31. #ifdef _LIBC
  32. struct loaded_domain;
  33. extern char *__gettext (const char *__msgid);
  34. extern char *__dgettext (const char *__domainname, const char *__msgid);
  35. extern char *__dcgettext (const char *__domainname, const char *__msgid,
  36. int __category);
  37. extern char *__ngettext (const char *__msgid1, const char *__msgid2,
  38. unsigned long int __n);
  39. extern char *__dngettext (const char *__domainname,
  40. const char *__msgid1, const char *__msgid2,
  41. unsigned long int n);
  42. extern char *__dcngettext (const char *__domainname,
  43. const char *__msgid1, const char *__msgid2,
  44. unsigned long int __n, int __category)
  45. attribute_hidden;
  46. extern char *__dcigettext (const char *__domainname,
  47. const char *__msgid1, const char *__msgid2,
  48. int __plural, unsigned long int __n,
  49. int __category) attribute_hidden;
  50. extern char *__textdomain (const char *__domainname);
  51. extern char *__bindtextdomain (const char *__domainname,
  52. const char *__dirname);
  53. extern char *__bind_textdomain_codeset (const char *__domainname,
  54. const char *__codeset);
  55. extern void _nl_finddomain_subfreeres (void) attribute_hidden;
  56. extern void _nl_unload_domain (struct loaded_domain *__domain)
  57. attribute_hidden;
  58. #else
  59. /* Declare the exported libintl_* functions, in a way that allows us to
  60. call them under their real name. */
  61. # undef _INTL_REDIRECT_INLINE
  62. # undef _INTL_REDIRECT_MACROS
  63. # define _INTL_REDIRECT_MACROS
  64. # include "libgnuintl.h"
  65. # ifdef IN_LIBGLOCALE
  66. extern char *gl_dcigettext (const char *__domainname,
  67. const char *__msgid1, const char *__msgid2,
  68. int __plural, unsigned long int __n,
  69. int __category,
  70. const char *__localename, const char *__encoding);
  71. # else
  72. extern char *libintl_dcigettext (const char *__domainname,
  73. const char *__msgid1, const char *__msgid2,
  74. int __plural, unsigned long int __n,
  75. int __category);
  76. # endif
  77. #endif
  78. #include "loadinfo.h"
  79. #include "gmo.h" /* Get nls_uint32. */
  80. /* @@ end of prolog @@ */
  81. #ifndef attribute_hidden
  82. # define attribute_hidden
  83. #endif
  84. /* Tell the compiler when a conditional or integer expression is
  85. almost always true or almost always false. */
  86. #ifndef HAVE_BUILTIN_EXPECT
  87. # define __builtin_expect(expr, val) (expr)
  88. #endif
  89. #ifndef W
  90. # define W(flag, data) ((flag) ? SWAP (data) : (data))
  91. #endif
  92. #ifdef _LIBC
  93. # include <byteswap.h>
  94. # define SWAP(i) bswap_32 (i)
  95. #else
  96. static inline nls_uint32
  97. # ifdef __cplusplus
  98. SWAP (nls_uint32 i)
  99. # else
  100. SWAP (i)
  101. nls_uint32 i;
  102. # endif
  103. {
  104. return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
  105. }
  106. #endif
  107. /* In-memory representation of system dependent string. */
  108. struct sysdep_string_desc
  109. {
  110. /* Length of addressed string, including the trailing NUL. */
  111. size_t length;
  112. /* Pointer to addressed string. */
  113. const char *pointer;
  114. };
  115. /* Cache of translated strings after charset conversion.
  116. Note: The strings are converted to the target encoding only on an as-needed
  117. basis. */
  118. struct converted_domain
  119. {
  120. /* The target encoding name. */
  121. const char *encoding;
  122. /* The descriptor for conversion from the message catalog's encoding to
  123. this target encoding. */
  124. #ifdef _LIBC
  125. __gconv_t conv;
  126. #else
  127. # if HAVE_ICONV
  128. iconv_t conv;
  129. # endif
  130. #endif
  131. /* The table of translated strings after charset conversion. */
  132. char **conv_tab;
  133. };
  134. /* The representation of an opened message catalog. */
  135. struct loaded_domain
  136. {
  137. /* Pointer to memory containing the .mo file. */
  138. const char *data;
  139. /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */
  140. int use_mmap;
  141. /* Size of mmap()ed memory. */
  142. size_t mmap_size;
  143. /* 1 if the .mo file uses a different endianness than this machine. */
  144. int must_swap;
  145. /* Pointer to additional malloc()ed memory. */
  146. void *malloced;
  147. /* Number of static strings pairs. */
  148. nls_uint32 nstrings;
  149. /* Pointer to descriptors of original strings in the file. */
  150. const struct string_desc *orig_tab;
  151. /* Pointer to descriptors of translated strings in the file. */
  152. const struct string_desc *trans_tab;
  153. /* Number of system dependent strings pairs. */
  154. nls_uint32 n_sysdep_strings;
  155. /* Pointer to descriptors of original sysdep strings. */
  156. const struct sysdep_string_desc *orig_sysdep_tab;
  157. /* Pointer to descriptors of translated sysdep strings. */
  158. const struct sysdep_string_desc *trans_sysdep_tab;
  159. /* Size of hash table. */
  160. nls_uint32 hash_size;
  161. /* Pointer to hash table. */
  162. const nls_uint32 *hash_tab;
  163. /* 1 if the hash table uses a different endianness than this machine. */
  164. int must_swap_hash_tab;
  165. /* Cache of charset conversions of the translated strings. */
  166. struct converted_domain *conversions;
  167. size_t nconversions;
  168. gl_rwlock_define (, conversions_lock)
  169. const struct expression *plural;
  170. unsigned long int nplurals;
  171. };
  172. /* We want to allocate a string at the end of the struct. But ISO C
  173. doesn't allow zero sized arrays. */
  174. #ifdef __GNUC__
  175. # define ZERO 0
  176. #else
  177. # define ZERO 1
  178. #endif
  179. /* A set of settings bound to a message domain. Used to store settings
  180. from bindtextdomain() and bind_textdomain_codeset(). */
  181. struct binding
  182. {
  183. struct binding *next;
  184. char *dirname;
  185. char *codeset;
  186. char domainname[ZERO];
  187. };
  188. /* A counter which is incremented each time some previous translations
  189. become invalid.
  190. This variable is part of the external ABI of the GNU libintl. */
  191. #ifdef IN_LIBGLOCALE
  192. # include <glocale/config.h>
  193. extern LIBGLOCALE_DLL_EXPORTED int _nl_msg_cat_cntr;
  194. #else
  195. extern LIBINTL_DLL_EXPORTED int _nl_msg_cat_cntr;
  196. #endif
  197. #ifndef _LIBC
  198. extern const char *_nl_language_preferences_default (void);
  199. # define gl_locale_name_canonicalize _nl_locale_name_canonicalize
  200. extern void _nl_locale_name_canonicalize (char *name);
  201. # define gl_locale_name_from_win32_LANGID _nl_locale_name_from_win32_LANGID
  202. /* extern const char *_nl_locale_name_from_win32_LANGID (LANGID langid); */
  203. # define gl_locale_name_from_win32_LCID _nl_locale_name_from_win32_LCID
  204. /* extern const char *_nl_locale_name_from_win32_LCID (LCID lcid); */
  205. # define gl_locale_name_thread_unsafe _nl_locale_name_thread_unsafe
  206. extern const char *_nl_locale_name_thread_unsafe (int category,
  207. const char *categoryname);
  208. # define gl_locale_name_thread _nl_locale_name_thread
  209. /* extern const char *_nl_locale_name_thread (int category,
  210. const char *categoryname); */
  211. # define gl_locale_name_posix _nl_locale_name_posix
  212. extern const char *_nl_locale_name_posix (int category,
  213. const char *categoryname);
  214. # define gl_locale_name_environ _nl_locale_name_environ
  215. extern const char *_nl_locale_name_environ (int category,
  216. const char *categoryname);
  217. # define gl_locale_name_default _nl_locale_name_default
  218. extern const char *_nl_locale_name_default (void);
  219. # define gl_locale_name _nl_locale_name
  220. /* extern const char *_nl_locale_name (int category,
  221. const char *categoryname); */
  222. #endif
  223. struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale,
  224. const char *__domainname,
  225. struct binding *__domainbinding)
  226. attribute_hidden;
  227. void _nl_load_domain (struct loaded_l10nfile *__domain,
  228. struct binding *__domainbinding)
  229. attribute_hidden;
  230. #ifdef IN_LIBGLOCALE
  231. char *_nl_find_msg (struct loaded_l10nfile *domain_file,
  232. struct binding *domainbinding, const char *encoding,
  233. const char *msgid,
  234. size_t *lengthp)
  235. attribute_hidden;
  236. #else
  237. char *_nl_find_msg (struct loaded_l10nfile *domain_file,
  238. struct binding *domainbinding, const char *msgid,
  239. int convert, size_t *lengthp)
  240. attribute_hidden;
  241. #endif
  242. /* The internal variables in the standalone libintl.a must have different
  243. names than the internal variables in GNU libc, otherwise programs
  244. using libintl.a cannot be linked statically. */
  245. #if !defined _LIBC
  246. # define _nl_default_dirname libintl_nl_default_dirname
  247. # define _nl_domain_bindings libintl_nl_domain_bindings
  248. #endif
  249. /* Contains the default location of the message catalogs. */
  250. extern const char _nl_default_dirname[];
  251. #ifdef _LIBC
  252. libc_hidden_proto (_nl_default_dirname)
  253. #endif
  254. /* List with bindings of specific domains. */
  255. extern struct binding *_nl_domain_bindings;
  256. /* The internal variables in the standalone libintl.a must have different
  257. names than the internal variables in GNU libc, otherwise programs
  258. using libintl.a cannot be linked statically. */
  259. #if !defined _LIBC
  260. # define _nl_default_default_domain libintl_nl_default_default_domain
  261. # define _nl_current_default_domain libintl_nl_current_default_domain
  262. #endif
  263. /* Name of the default text domain. */
  264. extern const char _nl_default_default_domain[] attribute_hidden;
  265. /* Default text domain in which entries for gettext(3) are to be found. */
  266. extern const char *_nl_current_default_domain attribute_hidden;
  267. /* @@ begin of epilog @@ */
  268. #endif /* gettextP.h */