gettextP.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /* Header describing internals of libintl library.
  2. Copyright (C) 1995-1999, 2000-2007 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 it
  5. under the terms of the GNU Library General Public License as published
  6. by the Free Software Foundation; either version 2, or (at your option)
  7. 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 GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  15. USA. */
  16. #ifndef _GETTEXTP_H
  17. #define _GETTEXTP_H
  18. #include <stddef.h> /* Get size_t. */
  19. #ifdef _LIBC
  20. # include "../iconv/gconv_int.h"
  21. #else
  22. # if HAVE_ICONV
  23. # include <iconv.h>
  24. # endif
  25. #endif
  26. /* Handle multi-threaded applications. */
  27. #ifdef _LIBC
  28. # include <bits/libc-lock.h>
  29. # define gl_rwlock_define __libc_rwlock_define
  30. #else
  31. # include "lock.h"
  32. #endif
  33. #ifdef _LIBC
  34. extern char *__gettext (const char *__msgid);
  35. extern char *__dgettext (const char *__domainname, const char *__msgid);
  36. extern char *__dcgettext (const char *__domainname, const char *__msgid,
  37. int __category);
  38. extern char *__ngettext (const char *__msgid1, const char *__msgid2,
  39. unsigned long int __n);
  40. extern char *__dngettext (const char *__domainname,
  41. const char *__msgid1, const char *__msgid2,
  42. unsigned long int n);
  43. extern char *__dcngettext (const char *__domainname,
  44. const char *__msgid1, const char *__msgid2,
  45. unsigned long int __n, int __category);
  46. extern char *__dcigettext (const char *__domainname,
  47. const char *__msgid1, const char *__msgid2,
  48. int __plural, unsigned long int __n,
  49. int __category);
  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. internal_function 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 internal_function
  82. # define internal_function
  83. #endif
  84. #ifndef attribute_hidden
  85. # define attribute_hidden
  86. #endif
  87. /* Tell the compiler when a conditional or integer expression is
  88. almost always true or almost always false. */
  89. #ifndef HAVE_BUILTIN_EXPECT
  90. # define __builtin_expect(expr, val) (expr)
  91. #endif
  92. #ifndef W
  93. # define W(flag, data) ((flag) ? SWAP (data) : (data))
  94. #endif
  95. #ifdef _LIBC
  96. # include <byteswap.h>
  97. # define SWAP(i) bswap_32 (i)
  98. #else
  99. static inline nls_uint32
  100. # ifdef __cplusplus
  101. SWAP (nls_uint32 i)
  102. # else
  103. SWAP (i)
  104. nls_uint32 i;
  105. # endif
  106. {
  107. return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
  108. }
  109. #endif
  110. /* In-memory representation of system dependent string. */
  111. struct sysdep_string_desc
  112. {
  113. /* Length of addressed string, including the trailing NUL. */
  114. size_t length;
  115. /* Pointer to addressed string. */
  116. const char *pointer;
  117. };
  118. /* Cache of translated strings after charset conversion.
  119. Note: The strings are converted to the target encoding only on an as-needed
  120. basis. */
  121. struct converted_domain
  122. {
  123. /* The target encoding name. */
  124. const char *encoding;
  125. /* The descriptor for conversion from the message catalog's encoding to
  126. this target encoding. */
  127. #ifdef _LIBC
  128. __gconv_t conv;
  129. #else
  130. # if HAVE_ICONV
  131. iconv_t conv;
  132. # endif
  133. #endif
  134. /* The table of translated strings after charset conversion. */
  135. char **conv_tab;
  136. };
  137. /* The representation of an opened message catalog. */
  138. struct loaded_domain
  139. {
  140. /* Pointer to memory containing the .mo file. */
  141. const char *data;
  142. /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */
  143. int use_mmap;
  144. /* Size of mmap()ed memory. */
  145. size_t mmap_size;
  146. /* 1 if the .mo file uses a different endianness than this machine. */
  147. int must_swap;
  148. /* Pointer to additional malloc()ed memory. */
  149. void *malloced;
  150. /* Number of static strings pairs. */
  151. nls_uint32 nstrings;
  152. /* Pointer to descriptors of original strings in the file. */
  153. const struct string_desc *orig_tab;
  154. /* Pointer to descriptors of translated strings in the file. */
  155. const struct string_desc *trans_tab;
  156. /* Number of system dependent strings pairs. */
  157. nls_uint32 n_sysdep_strings;
  158. /* Pointer to descriptors of original sysdep strings. */
  159. const struct sysdep_string_desc *orig_sysdep_tab;
  160. /* Pointer to descriptors of translated sysdep strings. */
  161. const struct sysdep_string_desc *trans_sysdep_tab;
  162. /* Size of hash table. */
  163. nls_uint32 hash_size;
  164. /* Pointer to hash table. */
  165. const nls_uint32 *hash_tab;
  166. /* 1 if the hash table uses a different endianness than this machine. */
  167. int must_swap_hash_tab;
  168. /* Cache of charset conversions of the translated strings. */
  169. struct converted_domain *conversions;
  170. size_t nconversions;
  171. gl_rwlock_define (, conversions_lock)
  172. const struct expression *plural;
  173. unsigned long int nplurals;
  174. };
  175. /* We want to allocate a string at the end of the struct. But ISO C
  176. doesn't allow zero sized arrays. */
  177. #ifdef __GNUC__
  178. # define ZERO 0
  179. #else
  180. # define ZERO 1
  181. #endif
  182. /* A set of settings bound to a message domain. Used to store settings
  183. from bindtextdomain() and bind_textdomain_codeset(). */
  184. struct binding
  185. {
  186. struct binding *next;
  187. char *dirname;
  188. char *codeset;
  189. char domainname[ZERO];
  190. };
  191. /* A counter which is incremented each time some previous translations
  192. become invalid.
  193. This variable is part of the external ABI of the GNU libintl. */
  194. #ifdef IN_LIBGLOCALE
  195. # include <glocale/config.h>
  196. extern LIBGLOCALE_DLL_EXPORTED int _nl_msg_cat_cntr;
  197. #else
  198. extern LIBINTL_DLL_EXPORTED int _nl_msg_cat_cntr;
  199. #endif
  200. #ifndef _LIBC
  201. extern const char *_nl_language_preferences_default (void);
  202. # define gl_locale_name_canonicalize _nl_locale_name_canonicalize
  203. extern void _nl_locale_name_canonicalize (char *name);
  204. # define gl_locale_name_posix _nl_locale_name_posix
  205. extern const char *_nl_locale_name_posix (int category,
  206. const char *categoryname);
  207. # define gl_locale_name_default _nl_locale_name_default
  208. extern const char *_nl_locale_name_default (void);
  209. # define gl_locale_name _nl_locale_name
  210. extern const char *_nl_locale_name (int category, const char *categoryname);
  211. #endif
  212. struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale,
  213. const char *__domainname,
  214. struct binding *__domainbinding)
  215. internal_function;
  216. void _nl_load_domain (struct loaded_l10nfile *__domain,
  217. struct binding *__domainbinding)
  218. internal_function;
  219. #ifdef IN_LIBGLOCALE
  220. char *_nl_find_msg (struct loaded_l10nfile *domain_file,
  221. struct binding *domainbinding, const char *encoding,
  222. const char *msgid,
  223. size_t *lengthp)
  224. internal_function;
  225. #else
  226. char *_nl_find_msg (struct loaded_l10nfile *domain_file,
  227. struct binding *domainbinding, const char *msgid,
  228. int convert, size_t *lengthp)
  229. internal_function;
  230. #endif
  231. /* The internal variables in the standalone libintl.a must have different
  232. names than the internal variables in GNU libc, otherwise programs
  233. using libintl.a cannot be linked statically. */
  234. #if !defined _LIBC
  235. # define _nl_default_dirname libintl_nl_default_dirname
  236. # define _nl_domain_bindings libintl_nl_domain_bindings
  237. #endif
  238. /* Contains the default location of the message catalogs. */
  239. extern const char _nl_default_dirname[];
  240. #ifdef _LIBC
  241. libc_hidden_proto (_nl_default_dirname)
  242. #endif
  243. /* List with bindings of specific domains. */
  244. extern struct binding *_nl_domain_bindings;
  245. /* The internal variables in the standalone libintl.a must have different
  246. names than the internal variables in GNU libc, otherwise programs
  247. using libintl.a cannot be linked statically. */
  248. #if !defined _LIBC
  249. # define _nl_default_default_domain libintl_nl_default_default_domain
  250. # define _nl_current_default_domain libintl_nl_current_default_domain
  251. #endif
  252. /* Name of the default text domain. */
  253. extern const char _nl_default_default_domain[] attribute_hidden;
  254. /* Default text domain in which entries for gettext(3) are to be found. */
  255. extern const char *_nl_current_default_domain attribute_hidden;
  256. /* @@ begin of epilog @@ */
  257. #endif /* gettextP.h */