1 /* Header describing internals of libintl library.
2 Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #ifndef _GETTEXTP_H
22 #define _GETTEXTP_H
23
24 #include <stddef.h> /* Get size_t. */
25 #include <libc-symbols.h>
26
27 #ifdef _GLIBC
28 # include "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 "gettext.h" /* Get nls_uint32. */
38
39 /* @@ end of prolog @@ */
40
41 #ifndef PARAMS
42 # if __STDC__
43 # define PARAMS(args) args
44 # else
45 # define PARAMS(args) ()
46 # endif
47 #endif
48
49 #ifndef internal_function
50 # define internal_function
51 #endif
52
53 /* Tell the compiler when a conditional or integer expression is
54 almost always true or almost always false. */
55 #ifndef HAVE_BUILTIN_EXPECT
56 # define __builtin_expect(expr, val) (expr)
57 #endif
58
59 #ifndef W
60 # define W(flag, data) ((flag) ? SWAP (data) : (data))
61 #endif
62
63
64 #ifdef _LIBC
65 # include <byteswap.h>
66 # define SWAP(i) bswap_32 (i)
67 #else
68 static nls_uint32 SWAP PARAMS ((nls_uint32 i));
69
70 static inline nls_uint32
SWAP(i)71 SWAP (i)
72 nls_uint32 i;
73 {
74 return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
75 }
76 #endif
77
78
79 /* This is the representation of the expressions to determine the
80 plural form. */
81 struct expression
82 {
83 int nargs; /* Number of arguments. */
84 enum operator
85 {
86 /* Without arguments: */
87 var, /* The variable "n". */
88 num, /* Decimal number. */
89 /* Unary operators: */
90 lnot, /* Logical NOT. */
91 /* Binary operators: */
92 mult, /* Multiplication. */
93 divide, /* Division. */
94 module, /* Module operation. */
95 plus, /* Addition. */
96 minus, /* Subtraction. */
97 less_than, /* Comparison. */
98 greater_than, /* Comparison. */
99 less_or_equal, /* Comparison. */
100 greater_or_equal, /* Comparison. */
101 equal, /* Comparision for equality. */
102 not_equal, /* Comparision for inequality. */
103 land, /* Logical AND. */
104 lor, /* Logical OR. */
105 /* Ternary operators: */
106 qmop /* Question mark operator. */
107 } operation;
108 union
109 {
110 unsigned long int num; /* Number value for `num'. */
111 struct expression *args[3]; /* Up to three arguments. */
112 } val;
113 };
114
115 /* This is the data structure to pass information to the parser and get
116 the result in a thread-safe way. */
117 struct parse_args
118 {
119 const char *cp;
120 struct expression *res;
121 };
122
123
124 /* The representation of an opened message catalog. */
125 struct loaded_domain
126 {
127 const char *data;
128 int use_mmap;
129 size_t mmap_size;
130 int must_swap;
131 nls_uint32 nstrings;
132 struct string_desc *orig_tab;
133 struct string_desc *trans_tab;
134 nls_uint32 hash_size;
135 nls_uint32 *hash_tab;
136 int codeset_cntr;
137 #ifdef _GLIBC
138 __gconv_t conv;
139 #else
140 # if HAVE_ICONV
141 iconv_t conv;
142 # endif
143 #endif
144 char **conv_tab;
145
146 struct expression *plural;
147 unsigned long int nplurals;
148 };
149
150 /* We want to allocate a string at the end of the struct. But ISO C
151 doesn't allow zero sized arrays. */
152 #ifdef __GNUC__
153 # define ZERO 0
154 #else
155 # define ZERO 1
156 #endif
157
158 /* A set of settings bound to a message domain. Used to store settings
159 from bindtextdomain() and bind_textdomain_codeset(). */
160 struct binding
161 {
162 struct binding *next;
163 char *dirname;
164 int codeset_cntr; /* Incremented each time codeset changes. */
165 char *codeset;
166 char domainname[ZERO];
167 };
168
169 /* A counter which is incremented each time some previous translations
170 become invalid.
171 This variable is part of the external ABI of the GNU libintl. */
172 extern int _nl_msg_cat_cntr;
173
174 struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname,
175 char *__locale,
176 const char *__domainname,
177 struct binding *__domainbinding))
178 internal_function;
179 void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain,
180 struct binding *__domainbinding))
181 internal_function;
182 void _nl_unload_domain PARAMS ((struct loaded_domain *__domain))
183 internal_function;
184 const char *_nl_init_domain_conv PARAMS ((struct loaded_l10nfile *__domain_file,
185 struct loaded_domain *__domain,
186 struct binding *__domainbinding))
187 internal_function;
188 void _nl_free_domain_conv PARAMS ((struct loaded_domain *__domain))
189 internal_function;
190
191 char *_nl_find_msg PARAMS ((struct loaded_l10nfile *domain_file,
192 struct binding *domainbinding,
193 const char *msgid, size_t *lengthp))
194 internal_function;
195
196 #ifdef _LIBC
197 extern char *__gettext PARAMS ((const char *__msgid));
198 extern char *__dgettext PARAMS ((const char *__domainname,
199 const char *__msgid));
200 extern char *__dcgettext PARAMS ((const char *__domainname,
201 const char *__msgid, int __category));
202 extern char *__ngettext PARAMS ((const char *__msgid1, const char *__msgid2,
203 unsigned long int __n));
204 extern char *__dngettext PARAMS ((const char *__domainname,
205 const char *__msgid1, const char *__msgid2,
206 unsigned long int n));
207 extern char *__dcngettext PARAMS ((const char *__domainname,
208 const char *__msgid1, const char *__msgid2,
209 unsigned long int __n, int __category));
210 extern char *__dcigettext PARAMS ((const char *__domainname,
211 const char *__msgid1, const char *__msgid2,
212 int __plural, unsigned long int __n,
213 int __category));
214 extern char *__textdomain PARAMS ((const char *__domainname));
215 extern char *__bindtextdomain PARAMS ((const char *__domainname,
216 const char *__dirname));
217 extern char *__bind_textdomain_codeset PARAMS ((const char *__domainname,
218 const char *__codeset));
219 #else
220 extern char *gettext__ PARAMS ((const char *__msgid));
221 extern char *dgettext__ PARAMS ((const char *__domainname,
222 const char *__msgid));
223 extern char *dcgettext__ PARAMS ((const char *__domainname,
224 const char *__msgid, int __category));
225 extern char *ngettext__ PARAMS ((const char *__msgid1, const char *__msgid2,
226 unsigned long int __n));
227 extern char *dngettext__ PARAMS ((const char *__domainname,
228 const char *__msgid1, const char *__msgid2,
229 unsigned long int __n));
230 extern char *dcngettext__ PARAMS ((const char *__domainname,
231 const char *__msgid1, const char *__msgid2,
232 unsigned long int __n, int __category));
233 extern char *dcigettext__ PARAMS ((const char *__domainname,
234 const char *__msgid1, const char *__msgid2,
235 int __plural, unsigned long int __n,
236 int __category));
237 extern char *textdomain__ PARAMS ((const char *__domainname));
238 extern char *bindtextdomain__ PARAMS ((const char *__domainname,
239 const char *__dirname));
240 extern char *bind_textdomain_codeset__ PARAMS ((const char *__domainname,
241 const char *__codeset));
242 #endif
243
244 #ifdef _LIBC
245 extern void __gettext_free_exp PARAMS ((struct expression *exp))
246 internal_function;
247 extern int __gettextparse PARAMS ((void *arg));
248 #else
249 extern void gettext_free_exp__ PARAMS ((struct expression *exp))
250 internal_function;
251 extern int gettextparse__ PARAMS ((void *arg));
252 #endif
253
254 /* @@ begin of epilog @@ */
255
256 #endif /* gettextP.h */
257