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