xref: /openbsd-src/gnu/gcc/intl/libgnuintl.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert /* Message catalogs for internationalization.
2*404b540aSrobert    Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc.
3*404b540aSrobert 
4*404b540aSrobert    This program is free software; you can redistribute it and/or modify it
5*404b540aSrobert    under the terms of the GNU Library General Public License as published
6*404b540aSrobert    by the Free Software Foundation; either version 2, or (at your option)
7*404b540aSrobert    any later version.
8*404b540aSrobert 
9*404b540aSrobert    This program is distributed in the hope that it will be useful,
10*404b540aSrobert    but WITHOUT ANY WARRANTY; without even the implied warranty of
11*404b540aSrobert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12*404b540aSrobert    Library General Public License for more details.
13*404b540aSrobert 
14*404b540aSrobert    You should have received a copy of the GNU Library General Public
15*404b540aSrobert    License along with this program; if not, write to the Free Software
16*404b540aSrobert    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
17*404b540aSrobert    USA.  */
18*404b540aSrobert 
19*404b540aSrobert #ifndef _LIBINTL_H
20*404b540aSrobert #define _LIBINTL_H	1
21*404b540aSrobert 
22*404b540aSrobert #include <locale.h>
23*404b540aSrobert 
24*404b540aSrobert /* The LC_MESSAGES locale category is the category used by the functions
25*404b540aSrobert    gettext() and dgettext().  It is specified in POSIX, but not in ANSI C.
26*404b540aSrobert    On systems that don't define it, use an arbitrary value instead.
27*404b540aSrobert    On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
28*404b540aSrobert    then includes <libintl.h> (i.e. this file!) and then only defines
29*404b540aSrobert    LC_MESSAGES.  To avoid a redefinition warning, don't define LC_MESSAGES
30*404b540aSrobert    in this case.  */
31*404b540aSrobert #if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
32*404b540aSrobert # define LC_MESSAGES 1729
33*404b540aSrobert #endif
34*404b540aSrobert 
35*404b540aSrobert /* We define an additional symbol to signal that we use the GNU
36*404b540aSrobert    implementation of gettext.  */
37*404b540aSrobert #define __USE_GNU_GETTEXT 1
38*404b540aSrobert 
39*404b540aSrobert /* Provide information about the supported file formats.  Returns the
40*404b540aSrobert    maximum minor revision number supported for a given major revision.  */
41*404b540aSrobert #define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
42*404b540aSrobert   ((major) == 0 ? 1 : -1)
43*404b540aSrobert 
44*404b540aSrobert /* Resolve a platform specific conflict on DJGPP.  GNU gettext takes
45*404b540aSrobert    precedence over _conio_gettext.  */
46*404b540aSrobert #ifdef __DJGPP__
47*404b540aSrobert # undef gettext
48*404b540aSrobert #endif
49*404b540aSrobert 
50*404b540aSrobert /* Use _INTL_PARAMS, not PARAMS, in order to avoid clashes with identifiers
51*404b540aSrobert    used by programs.  Similarly, test __PROTOTYPES, not PROTOTYPES.  */
52*404b540aSrobert #ifndef _INTL_PARAMS
53*404b540aSrobert # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
54*404b540aSrobert #  define _INTL_PARAMS(args) args
55*404b540aSrobert # else
56*404b540aSrobert #  define _INTL_PARAMS(args) ()
57*404b540aSrobert # endif
58*404b540aSrobert #endif
59*404b540aSrobert 
60*404b540aSrobert #ifdef __cplusplus
61*404b540aSrobert extern "C" {
62*404b540aSrobert #endif
63*404b540aSrobert 
64*404b540aSrobert 
65*404b540aSrobert /* We redirect the functions to those prefixed with "libintl_".  This is
66*404b540aSrobert    necessary, because some systems define gettext/textdomain/... in the C
67*404b540aSrobert    library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
68*404b540aSrobert    If we used the unprefixed names, there would be cases where the
69*404b540aSrobert    definition in the C library would override the one in the libintl.so
70*404b540aSrobert    shared library.  Recall that on ELF systems, the symbols are looked
71*404b540aSrobert    up in the following order:
72*404b540aSrobert      1. in the executable,
73*404b540aSrobert      2. in the shared libraries specified on the link command line, in order,
74*404b540aSrobert      3. in the dependencies of the shared libraries specified on the link
75*404b540aSrobert         command line,
76*404b540aSrobert      4. in the dlopen()ed shared libraries, in the order in which they were
77*404b540aSrobert         dlopen()ed.
78*404b540aSrobert    The definition in the C library would override the one in libintl.so if
79*404b540aSrobert    either
80*404b540aSrobert      * -lc is given on the link command line and -lintl isn't, or
81*404b540aSrobert      * -lc is given on the link command line before -lintl, or
82*404b540aSrobert      * libintl.so is a dependency of a dlopen()ed shared library but not
83*404b540aSrobert        linked to the executable at link time.
84*404b540aSrobert    Since Solaris gettext() behaves differently than GNU gettext(), this
85*404b540aSrobert    would be unacceptable.
86*404b540aSrobert 
87*404b540aSrobert    The redirection happens by default through macros in C, so that &gettext
88*404b540aSrobert    is independent of the compilation unit, but through inline functions in
89*404b540aSrobert    C++, in order not to interfere with the name mangling of class fields or
90*404b540aSrobert    class methods called 'gettext'.  */
91*404b540aSrobert 
92*404b540aSrobert /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
93*404b540aSrobert    If he doesn't, we choose the method.  A third possible method is
94*404b540aSrobert    _INTL_REDIRECT_ASM, supported only by GCC.  */
95*404b540aSrobert #if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
96*404b540aSrobert # if __GNUC__ >= 2 && !defined __APPLE_CC__ && (defined __STDC__ || defined __cplusplus)
97*404b540aSrobert #  define _INTL_REDIRECT_ASM
98*404b540aSrobert # else
99*404b540aSrobert #  ifdef __cplusplus
100*404b540aSrobert #   define _INTL_REDIRECT_INLINE
101*404b540aSrobert #  else
102*404b540aSrobert #   define _INTL_REDIRECT_MACROS
103*404b540aSrobert #  endif
104*404b540aSrobert # endif
105*404b540aSrobert #endif
106*404b540aSrobert /* Auxiliary macros.  */
107*404b540aSrobert #ifdef _INTL_REDIRECT_ASM
108*404b540aSrobert # define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
109*404b540aSrobert # define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
110*404b540aSrobert # define _INTL_STRINGIFY(prefix) #prefix
111*404b540aSrobert #else
112*404b540aSrobert # define _INTL_ASM(cname)
113*404b540aSrobert #endif
114*404b540aSrobert 
115*404b540aSrobert /* Look up MSGID in the current default message catalog for the current
116*404b540aSrobert    LC_MESSAGES locale.  If not found, returns MSGID itself (the default
117*404b540aSrobert    text).  */
118*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
119*404b540aSrobert extern char *libintl_gettext (const char *__msgid);
gettext(const char * __msgid)120*404b540aSrobert static inline char *gettext (const char *__msgid)
121*404b540aSrobert {
122*404b540aSrobert   return libintl_gettext (__msgid);
123*404b540aSrobert }
124*404b540aSrobert #else
125*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
126*404b540aSrobert # define gettext libintl_gettext
127*404b540aSrobert #endif
128*404b540aSrobert extern char *gettext _INTL_PARAMS ((const char *__msgid))
129*404b540aSrobert        _INTL_ASM (libintl_gettext);
130*404b540aSrobert #endif
131*404b540aSrobert 
132*404b540aSrobert /* Look up MSGID in the DOMAINNAME message catalog for the current
133*404b540aSrobert    LC_MESSAGES locale.  */
134*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
135*404b540aSrobert extern char *libintl_dgettext (const char *__domainname, const char *__msgid);
dgettext(const char * __domainname,const char * __msgid)136*404b540aSrobert static inline char *dgettext (const char *__domainname, const char *__msgid)
137*404b540aSrobert {
138*404b540aSrobert   return libintl_dgettext (__domainname, __msgid);
139*404b540aSrobert }
140*404b540aSrobert #else
141*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
142*404b540aSrobert # define dgettext libintl_dgettext
143*404b540aSrobert #endif
144*404b540aSrobert extern char *dgettext _INTL_PARAMS ((const char *__domainname,
145*404b540aSrobert 				     const char *__msgid))
146*404b540aSrobert        _INTL_ASM (libintl_dgettext);
147*404b540aSrobert #endif
148*404b540aSrobert 
149*404b540aSrobert /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
150*404b540aSrobert    locale.  */
151*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
152*404b540aSrobert extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
153*404b540aSrobert 				int __category);
dcgettext(const char * __domainname,const char * __msgid,int __category)154*404b540aSrobert static inline char *dcgettext (const char *__domainname, const char *__msgid,
155*404b540aSrobert 			       int __category)
156*404b540aSrobert {
157*404b540aSrobert   return libintl_dcgettext (__domainname, __msgid, __category);
158*404b540aSrobert }
159*404b540aSrobert #else
160*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
161*404b540aSrobert # define dcgettext libintl_dcgettext
162*404b540aSrobert #endif
163*404b540aSrobert extern char *dcgettext _INTL_PARAMS ((const char *__domainname,
164*404b540aSrobert 				      const char *__msgid,
165*404b540aSrobert 				      int __category))
166*404b540aSrobert        _INTL_ASM (libintl_dcgettext);
167*404b540aSrobert #endif
168*404b540aSrobert 
169*404b540aSrobert 
170*404b540aSrobert /* Similar to `gettext' but select the plural form corresponding to the
171*404b540aSrobert    number N.  */
172*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
173*404b540aSrobert extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
174*404b540aSrobert 			       unsigned long int __n);
ngettext(const char * __msgid1,const char * __msgid2,unsigned long int __n)175*404b540aSrobert static inline char *ngettext (const char *__msgid1, const char *__msgid2,
176*404b540aSrobert 			      unsigned long int __n)
177*404b540aSrobert {
178*404b540aSrobert   return libintl_ngettext (__msgid1, __msgid2, __n);
179*404b540aSrobert }
180*404b540aSrobert #else
181*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
182*404b540aSrobert # define ngettext libintl_ngettext
183*404b540aSrobert #endif
184*404b540aSrobert extern char *ngettext _INTL_PARAMS ((const char *__msgid1,
185*404b540aSrobert 				     const char *__msgid2,
186*404b540aSrobert 				     unsigned long int __n))
187*404b540aSrobert        _INTL_ASM (libintl_ngettext);
188*404b540aSrobert #endif
189*404b540aSrobert 
190*404b540aSrobert /* Similar to `dgettext' but select the plural form corresponding to the
191*404b540aSrobert    number N.  */
192*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
193*404b540aSrobert extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
194*404b540aSrobert 				const char *__msgid2, unsigned long int __n);
dngettext(const char * __domainname,const char * __msgid1,const char * __msgid2,unsigned long int __n)195*404b540aSrobert static inline char *dngettext (const char *__domainname, const char *__msgid1,
196*404b540aSrobert 			       const char *__msgid2, unsigned long int __n)
197*404b540aSrobert {
198*404b540aSrobert   return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
199*404b540aSrobert }
200*404b540aSrobert #else
201*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
202*404b540aSrobert # define dngettext libintl_dngettext
203*404b540aSrobert #endif
204*404b540aSrobert extern char *dngettext _INTL_PARAMS ((const char *__domainname,
205*404b540aSrobert 				      const char *__msgid1,
206*404b540aSrobert 				      const char *__msgid2,
207*404b540aSrobert 				      unsigned long int __n))
208*404b540aSrobert        _INTL_ASM (libintl_dngettext);
209*404b540aSrobert #endif
210*404b540aSrobert 
211*404b540aSrobert /* Similar to `dcgettext' but select the plural form corresponding to the
212*404b540aSrobert    number N.  */
213*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
214*404b540aSrobert extern char *libintl_dcngettext (const char *__domainname,
215*404b540aSrobert 				 const char *__msgid1, const char *__msgid2,
216*404b540aSrobert 				 unsigned long int __n, int __category);
dcngettext(const char * __domainname,const char * __msgid1,const char * __msgid2,unsigned long int __n,int __category)217*404b540aSrobert static inline char *dcngettext (const char *__domainname,
218*404b540aSrobert 				const char *__msgid1, const char *__msgid2,
219*404b540aSrobert 				unsigned long int __n, int __category)
220*404b540aSrobert {
221*404b540aSrobert   return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
222*404b540aSrobert }
223*404b540aSrobert #else
224*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
225*404b540aSrobert # define dcngettext libintl_dcngettext
226*404b540aSrobert #endif
227*404b540aSrobert extern char *dcngettext _INTL_PARAMS ((const char *__domainname,
228*404b540aSrobert 				       const char *__msgid1,
229*404b540aSrobert 				       const char *__msgid2,
230*404b540aSrobert 				       unsigned long int __n,
231*404b540aSrobert 				       int __category))
232*404b540aSrobert        _INTL_ASM (libintl_dcngettext);
233*404b540aSrobert #endif
234*404b540aSrobert 
235*404b540aSrobert 
236*404b540aSrobert /* Set the current default message catalog to DOMAINNAME.
237*404b540aSrobert    If DOMAINNAME is null, return the current default.
238*404b540aSrobert    If DOMAINNAME is "", reset to the default of "messages".  */
239*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
240*404b540aSrobert extern char *libintl_textdomain (const char *__domainname);
textdomain(const char * __domainname)241*404b540aSrobert static inline char *textdomain (const char *__domainname)
242*404b540aSrobert {
243*404b540aSrobert   return libintl_textdomain (__domainname);
244*404b540aSrobert }
245*404b540aSrobert #else
246*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
247*404b540aSrobert # define textdomain libintl_textdomain
248*404b540aSrobert #endif
249*404b540aSrobert extern char *textdomain _INTL_PARAMS ((const char *__domainname))
250*404b540aSrobert        _INTL_ASM (libintl_textdomain);
251*404b540aSrobert #endif
252*404b540aSrobert 
253*404b540aSrobert /* Specify that the DOMAINNAME message catalog will be found
254*404b540aSrobert    in DIRNAME rather than in the system locale data base.  */
255*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
256*404b540aSrobert extern char *libintl_bindtextdomain (const char *__domainname,
257*404b540aSrobert 				     const char *__dirname);
bindtextdomain(const char * __domainname,const char * __dirname)258*404b540aSrobert static inline char *bindtextdomain (const char *__domainname,
259*404b540aSrobert 				    const char *__dirname)
260*404b540aSrobert {
261*404b540aSrobert   return libintl_bindtextdomain (__domainname, __dirname);
262*404b540aSrobert }
263*404b540aSrobert #else
264*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
265*404b540aSrobert # define bindtextdomain libintl_bindtextdomain
266*404b540aSrobert #endif
267*404b540aSrobert extern char *bindtextdomain _INTL_PARAMS ((const char *__domainname,
268*404b540aSrobert 					   const char *__dirname))
269*404b540aSrobert        _INTL_ASM (libintl_bindtextdomain);
270*404b540aSrobert #endif
271*404b540aSrobert 
272*404b540aSrobert /* Specify the character encoding in which the messages from the
273*404b540aSrobert    DOMAINNAME message catalog will be returned.  */
274*404b540aSrobert #ifdef _INTL_REDIRECT_INLINE
275*404b540aSrobert extern char *libintl_bind_textdomain_codeset (const char *__domainname,
276*404b540aSrobert 					      const char *__codeset);
bind_textdomain_codeset(const char * __domainname,const char * __codeset)277*404b540aSrobert static inline char *bind_textdomain_codeset (const char *__domainname,
278*404b540aSrobert 					     const char *__codeset)
279*404b540aSrobert {
280*404b540aSrobert   return libintl_bind_textdomain_codeset (__domainname, __codeset);
281*404b540aSrobert }
282*404b540aSrobert #else
283*404b540aSrobert #ifdef _INTL_REDIRECT_MACROS
284*404b540aSrobert # define bind_textdomain_codeset libintl_bind_textdomain_codeset
285*404b540aSrobert #endif
286*404b540aSrobert extern char *bind_textdomain_codeset _INTL_PARAMS ((const char *__domainname,
287*404b540aSrobert 						    const char *__codeset))
288*404b540aSrobert        _INTL_ASM (libintl_bind_textdomain_codeset);
289*404b540aSrobert #endif
290*404b540aSrobert 
291*404b540aSrobert 
292*404b540aSrobert /* Support for relocatable packages.  */
293*404b540aSrobert 
294*404b540aSrobert /* Sets the original and the current installation prefix of the package.
295*404b540aSrobert    Relocation simply replaces a pathname starting with the original prefix
296*404b540aSrobert    by the corresponding pathname with the current prefix instead.  Both
297*404b540aSrobert    prefixes should be directory names without trailing slash (i.e. use ""
298*404b540aSrobert    instead of "/").  */
299*404b540aSrobert #define libintl_set_relocation_prefix libintl_set_relocation_prefix
300*404b540aSrobert extern void
301*404b540aSrobert        libintl_set_relocation_prefix _INTL_PARAMS ((const char *orig_prefix,
302*404b540aSrobert 						    const char *curr_prefix));
303*404b540aSrobert 
304*404b540aSrobert 
305*404b540aSrobert #ifdef __cplusplus
306*404b540aSrobert }
307*404b540aSrobert #endif
308*404b540aSrobert 
309*404b540aSrobert #endif /* libintl.h */
310