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