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