xref: /netbsd-src/external/gpl2/texinfo/dist/intl/gettextP.h (revision 29619d2afe564e54d657b83e5a3ae89584f83720)
1 /*	$NetBSD: gettextP.h,v 1.1.1.1 2016/01/14 00:11:27 christos Exp $	*/
2 
3 /* Header describing internals of libintl library.
4    Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
5    Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
6 
7    This program is free software; you can redistribute it and/or modify it
8    under the terms of the GNU Library General Public License as published
9    by the Free Software Foundation; either version 2, or (at your option)
10    any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Library General Public License for more details.
16 
17    You should have received a copy of the GNU Library General Public
18    License along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20    USA.  */
21 
22 #ifndef _GETTEXTP_H
23 #define _GETTEXTP_H
24 
25 #include <stddef.h>		/* Get size_t.  */
26 
27 #ifdef _LIBC
28 # include "../iconv/gconv_int.h"
29 #else
30 # if HAVE_ICONV
31 #  include <iconv.h>
32 # endif
33 #endif
34 
35 #include "loadinfo.h"
36 
37 #include "gmo.h"		/* Get nls_uint32.  */
38 
39 /* @@ end of prolog @@ */
40 
41 #ifndef internal_function
42 # define internal_function
43 #endif
44 
45 #ifndef attribute_hidden
46 # define attribute_hidden
47 #endif
48 
49 /* Tell the compiler when a conditional or integer expression is
50    almost always true or almost always false.  */
51 #ifndef HAVE_BUILTIN_EXPECT
52 # define __builtin_expect(expr, val) (expr)
53 #endif
54 
55 #ifndef W
56 # define W(flag, data) ((flag) ? SWAP (data) : (data))
57 #endif
58 
59 
60 #ifdef _LIBC
61 # include <byteswap.h>
62 # define SWAP(i) bswap_32 (i)
63 #else
64 static inline nls_uint32
SWAP(i)65 SWAP (i)
66      nls_uint32 i;
67 {
68   return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
69 }
70 #endif
71 
72 
73 /* In-memory representation of system dependent string.  */
74 struct sysdep_string_desc
75 {
76   /* Length of addressed string, including the trailing NUL.  */
77   size_t length;
78   /* Pointer to addressed string.  */
79   const char *pointer;
80 };
81 
82 /* The representation of an opened message catalog.  */
83 struct loaded_domain
84 {
85   /* Pointer to memory containing the .mo file.  */
86   const char *data;
87   /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed.  */
88   int use_mmap;
89   /* Size of mmap()ed memory.  */
90   size_t mmap_size;
91   /* 1 if the .mo file uses a different endianness than this machine.  */
92   int must_swap;
93   /* Pointer to additional malloc()ed memory.  */
94   void *malloced;
95 
96   /* Number of static strings pairs.  */
97   nls_uint32 nstrings;
98   /* Pointer to descriptors of original strings in the file.  */
99   const struct string_desc *orig_tab;
100   /* Pointer to descriptors of translated strings in the file.  */
101   const struct string_desc *trans_tab;
102 
103   /* Number of system dependent strings pairs.  */
104   nls_uint32 n_sysdep_strings;
105   /* Pointer to descriptors of original sysdep strings.  */
106   const struct sysdep_string_desc *orig_sysdep_tab;
107   /* Pointer to descriptors of translated sysdep strings.  */
108   const struct sysdep_string_desc *trans_sysdep_tab;
109 
110   /* Size of hash table.  */
111   nls_uint32 hash_size;
112   /* Pointer to hash table.  */
113   const nls_uint32 *hash_tab;
114   /* 1 if the hash table uses a different endianness than this machine.  */
115   int must_swap_hash_tab;
116 
117   int codeset_cntr;
118 #ifdef _LIBC
119   __gconv_t conv;
120 #else
121 # if HAVE_ICONV
122   iconv_t conv;
123 # endif
124 #endif
125   char **conv_tab;
126 
127   struct expression *plural;
128   unsigned long int nplurals;
129 };
130 
131 /* We want to allocate a string at the end of the struct.  But ISO C
132    doesn't allow zero sized arrays.  */
133 #ifdef __GNUC__
134 # define ZERO 0
135 #else
136 # define ZERO 1
137 #endif
138 
139 /* A set of settings bound to a message domain.  Used to store settings
140    from bindtextdomain() and bind_textdomain_codeset().  */
141 struct binding
142 {
143   struct binding *next;
144   char *dirname;
145   int codeset_cntr;	/* Incremented each time codeset changes.  */
146   char *codeset;
147   char domainname[ZERO];
148 };
149 
150 /* A counter which is incremented each time some previous translations
151    become invalid.
152    This variable is part of the external ABI of the GNU libintl.  */
153 extern int _nl_msg_cat_cntr;
154 
155 #ifndef _LIBC
156 const char *_nl_locale_name (int category, const char *categoryname);
157 #endif
158 
159 struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale,
160 					 const char *__domainname,
161 					 struct binding *__domainbinding)
162      internal_function;
163 void _nl_load_domain (struct loaded_l10nfile *__domain,
164 		      struct binding *__domainbinding)
165      internal_function;
166 void _nl_unload_domain (struct loaded_domain *__domain)
167      internal_function;
168 const char *_nl_init_domain_conv (struct loaded_l10nfile *__domain_file,
169 				  struct loaded_domain *__domain,
170 				  struct binding *__domainbinding)
171      internal_function;
172 void _nl_free_domain_conv (struct loaded_domain *__domain)
173      internal_function;
174 
175 char *_nl_find_msg (struct loaded_l10nfile *domain_file,
176 		    struct binding *domainbinding, const char *msgid,
177 		    size_t *lengthp)
178      internal_function;
179 
180 #ifdef _LIBC
181 extern char *__gettext (const char *__msgid);
182 extern char *__dgettext (const char *__domainname, const char *__msgid);
183 extern char *__dcgettext (const char *__domainname, const char *__msgid,
184 			  int __category);
185 extern char *__ngettext (const char *__msgid1, const char *__msgid2,
186 			 unsigned long int __n);
187 extern char *__dngettext (const char *__domainname,
188 			  const char *__msgid1, const char *__msgid2,
189 			  unsigned long int n);
190 extern char *__dcngettext (const char *__domainname,
191 			   const char *__msgid1, const char *__msgid2,
192 			   unsigned long int __n, int __category);
193 extern char *__dcigettext (const char *__domainname,
194 			   const char *__msgid1, const char *__msgid2,
195 			   int __plural, unsigned long int __n,
196 			   int __category);
197 extern char *__textdomain (const char *__domainname);
198 extern char *__bindtextdomain (const char *__domainname,
199 			       const char *__dirname);
200 extern char *__bind_textdomain_codeset (const char *__domainname,
201 					const char *__codeset);
202 #else
203 /* Declare the exported libintl_* functions, in a way that allows us to
204    call them under their real name.  */
205 # undef _INTL_REDIRECT_INLINE
206 # undef _INTL_REDIRECT_MACROS
207 # define _INTL_REDIRECT_MACROS
208 # include "libgnuintl.h"
209 extern char *libintl_dcigettext (const char *__domainname,
210 				 const char *__msgid1, const char *__msgid2,
211 				 int __plural, unsigned long int __n,
212 				 int __category);
213 #endif
214 
215 /* @@ begin of epilog @@ */
216 
217 #endif /* gettextP.h  */
218