hegyi@1
|
1 |
/* Convenience header for conditional use of GNU <libintl.h>.
|
ladanyi@5
|
2 |
Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
|
hegyi@1
|
3 |
|
hegyi@1
|
4 |
This program is free software; you can redistribute it and/or modify it
|
ladanyi@5
|
5 |
under the terms of the GNU General Public License as published
|
hegyi@1
|
6 |
by the Free Software Foundation; either version 2, or (at your option)
|
hegyi@1
|
7 |
any later version.
|
hegyi@1
|
8 |
|
hegyi@1
|
9 |
This program is distributed in the hope that it will be useful,
|
hegyi@1
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
hegyi@1
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
hegyi@1
|
12 |
Library General Public License for more details.
|
hegyi@1
|
13 |
|
ladanyi@5
|
14 |
You should have received a copy of the GNU General Public
|
hegyi@1
|
15 |
License along with this program; if not, write to the Free Software
|
hegyi@1
|
16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
hegyi@1
|
17 |
USA. */
|
hegyi@1
|
18 |
|
hegyi@1
|
19 |
#ifndef _LIBGETTEXT_H
|
hegyi@1
|
20 |
#define _LIBGETTEXT_H 1
|
hegyi@1
|
21 |
|
hegyi@1
|
22 |
/* NLS can be disabled through the configure --disable-nls option. */
|
hegyi@1
|
23 |
#if ENABLE_NLS
|
hegyi@1
|
24 |
|
hegyi@1
|
25 |
/* Get declarations of GNU message catalog functions. */
|
hegyi@1
|
26 |
# include <libintl.h>
|
hegyi@1
|
27 |
|
ladanyi@5
|
28 |
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
|
ladanyi@5
|
29 |
the gettext() and ngettext() macros. This is an alternative to calling
|
ladanyi@5
|
30 |
textdomain(), and is useful for libraries. */
|
ladanyi@5
|
31 |
# ifdef DEFAULT_TEXT_DOMAIN
|
ladanyi@5
|
32 |
# undef gettext
|
ladanyi@5
|
33 |
# define gettext(Msgid) \
|
ladanyi@5
|
34 |
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
|
ladanyi@5
|
35 |
# undef ngettext
|
ladanyi@5
|
36 |
# define ngettext(Msgid1, Msgid2, N) \
|
ladanyi@5
|
37 |
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
|
ladanyi@5
|
38 |
# endif
|
ladanyi@5
|
39 |
|
hegyi@1
|
40 |
#else
|
hegyi@1
|
41 |
|
hegyi@1
|
42 |
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
|
hegyi@1
|
43 |
chokes if dcgettext is defined as a macro. So include it now, to make
|
hegyi@1
|
44 |
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
|
hegyi@1
|
45 |
as well because people using "gettext.h" will not include <libintl.h>,
|
hegyi@1
|
46 |
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
|
hegyi@1
|
47 |
is OK. */
|
hegyi@1
|
48 |
#if defined(__sun)
|
hegyi@1
|
49 |
# include <locale.h>
|
hegyi@1
|
50 |
#endif
|
hegyi@1
|
51 |
|
hegyi@1
|
52 |
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
|
hegyi@1
|
53 |
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
|
hegyi@1
|
54 |
it now, to make later inclusions of <libintl.h> a NOP. */
|
hegyi@1
|
55 |
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
|
hegyi@1
|
56 |
# include <cstdlib>
|
hegyi@1
|
57 |
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
|
hegyi@1
|
58 |
# include <libintl.h>
|
hegyi@1
|
59 |
# endif
|
hegyi@1
|
60 |
#endif
|
hegyi@1
|
61 |
|
hegyi@1
|
62 |
/* Disabled NLS.
|
hegyi@1
|
63 |
The casts to 'const char *' serve the purpose of producing warnings
|
hegyi@1
|
64 |
for invalid uses of the value returned from these functions.
|
hegyi@1
|
65 |
On pre-ANSI systems without 'const', the config.h file is supposed to
|
hegyi@1
|
66 |
contain "#define const". */
|
hegyi@1
|
67 |
# define gettext(Msgid) ((const char *) (Msgid))
|
ladanyi@5
|
68 |
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
|
ladanyi@5
|
69 |
# define dcgettext(Domainname, Msgid, Category) \
|
ladanyi@5
|
70 |
((void) (Category), dgettext (Domainname, Msgid))
|
hegyi@1
|
71 |
# define ngettext(Msgid1, Msgid2, N) \
|
ladanyi@5
|
72 |
((N) == 1 \
|
ladanyi@5
|
73 |
? ((void) (Msgid2), (const char *) (Msgid1)) \
|
ladanyi@5
|
74 |
: ((void) (Msgid1), (const char *) (Msgid2)))
|
hegyi@1
|
75 |
# define dngettext(Domainname, Msgid1, Msgid2, N) \
|
ladanyi@5
|
76 |
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
|
hegyi@1
|
77 |
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
|
ladanyi@5
|
78 |
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
|
hegyi@1
|
79 |
# define textdomain(Domainname) ((const char *) (Domainname))
|
ladanyi@5
|
80 |
# define bindtextdomain(Domainname, Dirname) \
|
ladanyi@5
|
81 |
((void) (Domainname), (const char *) (Dirname))
|
ladanyi@5
|
82 |
# define bind_textdomain_codeset(Domainname, Codeset) \
|
ladanyi@5
|
83 |
((void) (Domainname), (const char *) (Codeset))
|
hegyi@1
|
84 |
|
hegyi@1
|
85 |
#endif
|
hegyi@1
|
86 |
|
hegyi@1
|
87 |
/* A pseudo function call that serves as a marker for the automated
|
hegyi@1
|
88 |
extraction of messages, but does not call gettext(). The run-time
|
hegyi@1
|
89 |
translation is done at a different place in the code.
|
hegyi@1
|
90 |
The argument, String, should be a literal string. Concatenated strings
|
hegyi@1
|
91 |
and other string expressions won't work.
|
hegyi@1
|
92 |
The macro's expansion is not parenthesized, so that it is suitable as
|
hegyi@1
|
93 |
initializer for static 'char[]' or 'const char[]' variables. */
|
hegyi@1
|
94 |
#define gettext_noop(String) String
|
hegyi@1
|
95 |
|
ladanyi@5
|
96 |
/* The separator between msgctxt and msgid in a .mo file. */
|
ladanyi@5
|
97 |
#define GETTEXT_CONTEXT_GLUE "\004"
|
ladanyi@5
|
98 |
|
ladanyi@5
|
99 |
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
|
ladanyi@5
|
100 |
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
|
ladanyi@5
|
101 |
short and rarely need to change.
|
ladanyi@5
|
102 |
The letter 'p' stands for 'particular' or 'special'. */
|
ladanyi@5
|
103 |
#ifdef DEFAULT_TEXT_DOMAIN
|
ladanyi@5
|
104 |
# define pgettext(Msgctxt, Msgid) \
|
ladanyi@5
|
105 |
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
ladanyi@5
|
106 |
#else
|
ladanyi@5
|
107 |
# define pgettext(Msgctxt, Msgid) \
|
ladanyi@5
|
108 |
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
ladanyi@5
|
109 |
#endif
|
ladanyi@5
|
110 |
#define dpgettext(Domainname, Msgctxt, Msgid) \
|
ladanyi@5
|
111 |
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
|
ladanyi@5
|
112 |
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
|
ladanyi@5
|
113 |
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
|
ladanyi@5
|
114 |
#ifdef DEFAULT_TEXT_DOMAIN
|
ladanyi@5
|
115 |
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
|
ladanyi@5
|
116 |
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
ladanyi@5
|
117 |
#else
|
ladanyi@5
|
118 |
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
|
ladanyi@5
|
119 |
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
ladanyi@5
|
120 |
#endif
|
ladanyi@5
|
121 |
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
|
ladanyi@5
|
122 |
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
|
ladanyi@5
|
123 |
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
|
ladanyi@5
|
124 |
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
|
ladanyi@5
|
125 |
|
ladanyi@5
|
126 |
#ifdef __GNUC__
|
ladanyi@5
|
127 |
__inline
|
ladanyi@5
|
128 |
#else
|
ladanyi@5
|
129 |
#ifdef __cplusplus
|
ladanyi@5
|
130 |
inline
|
ladanyi@5
|
131 |
#endif
|
ladanyi@5
|
132 |
#endif
|
ladanyi@5
|
133 |
static const char *
|
ladanyi@5
|
134 |
pgettext_aux (const char *domain,
|
ladanyi@5
|
135 |
const char *msg_ctxt_id, const char *msgid,
|
ladanyi@5
|
136 |
int category)
|
ladanyi@5
|
137 |
{
|
ladanyi@5
|
138 |
const char *translation = dcgettext (domain, msg_ctxt_id, category);
|
ladanyi@5
|
139 |
if (translation == msg_ctxt_id)
|
ladanyi@5
|
140 |
return msgid;
|
ladanyi@5
|
141 |
else
|
ladanyi@5
|
142 |
return translation;
|
ladanyi@5
|
143 |
}
|
ladanyi@5
|
144 |
|
ladanyi@5
|
145 |
#ifdef __GNUC__
|
ladanyi@5
|
146 |
__inline
|
ladanyi@5
|
147 |
#else
|
ladanyi@5
|
148 |
#ifdef __cplusplus
|
ladanyi@5
|
149 |
inline
|
ladanyi@5
|
150 |
#endif
|
ladanyi@5
|
151 |
#endif
|
ladanyi@5
|
152 |
static const char *
|
ladanyi@5
|
153 |
npgettext_aux (const char *domain,
|
ladanyi@5
|
154 |
const char *msg_ctxt_id, const char *msgid,
|
ladanyi@5
|
155 |
const char *msgid_plural, unsigned long int n,
|
ladanyi@5
|
156 |
int category)
|
ladanyi@5
|
157 |
{
|
ladanyi@5
|
158 |
const char *translation =
|
ladanyi@5
|
159 |
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
|
ladanyi@5
|
160 |
if (translation == msg_ctxt_id || translation == msgid_plural)
|
ladanyi@5
|
161 |
return (n == 1 ? msgid : msgid_plural);
|
ladanyi@5
|
162 |
else
|
ladanyi@5
|
163 |
return translation;
|
ladanyi@5
|
164 |
}
|
ladanyi@5
|
165 |
|
ladanyi@5
|
166 |
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
|
ladanyi@5
|
167 |
can be arbitrary expressions. But for string literals these macros are
|
ladanyi@5
|
168 |
less efficient than those above. */
|
ladanyi@5
|
169 |
|
ladanyi@5
|
170 |
#include <string.h>
|
ladanyi@5
|
171 |
|
ladanyi@5
|
172 |
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
|
ladanyi@5
|
173 |
(((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
|
ladanyi@5
|
174 |
/* || __STDC_VERSION__ >= 199901L */ )
|
ladanyi@5
|
175 |
|
ladanyi@5
|
176 |
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
ladanyi@5
|
177 |
#include <stdlib.h>
|
ladanyi@5
|
178 |
#endif
|
ladanyi@5
|
179 |
|
ladanyi@5
|
180 |
#define pgettext_expr(Msgctxt, Msgid) \
|
ladanyi@5
|
181 |
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
|
ladanyi@5
|
182 |
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
|
ladanyi@5
|
183 |
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
|
ladanyi@5
|
184 |
|
ladanyi@5
|
185 |
#ifdef __GNUC__
|
ladanyi@5
|
186 |
__inline
|
ladanyi@5
|
187 |
#else
|
ladanyi@5
|
188 |
#ifdef __cplusplus
|
ladanyi@5
|
189 |
inline
|
ladanyi@5
|
190 |
#endif
|
ladanyi@5
|
191 |
#endif
|
ladanyi@5
|
192 |
static const char *
|
ladanyi@5
|
193 |
dcpgettext_expr (const char *domain,
|
ladanyi@5
|
194 |
const char *msgctxt, const char *msgid,
|
ladanyi@5
|
195 |
int category)
|
ladanyi@5
|
196 |
{
|
ladanyi@5
|
197 |
size_t msgctxt_len = strlen (msgctxt) + 1;
|
ladanyi@5
|
198 |
size_t msgid_len = strlen (msgid) + 1;
|
ladanyi@5
|
199 |
const char *translation;
|
ladanyi@5
|
200 |
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
ladanyi@5
|
201 |
char msg_ctxt_id[msgctxt_len + msgid_len];
|
ladanyi@5
|
202 |
#else
|
ladanyi@5
|
203 |
char buf[1024];
|
ladanyi@5
|
204 |
char *msg_ctxt_id =
|
ladanyi@5
|
205 |
(msgctxt_len + msgid_len <= sizeof (buf)
|
ladanyi@5
|
206 |
? buf
|
ladanyi@5
|
207 |
: (char *) malloc (msgctxt_len + msgid_len));
|
ladanyi@5
|
208 |
if (msg_ctxt_id != NULL)
|
ladanyi@5
|
209 |
#endif
|
ladanyi@5
|
210 |
{
|
ladanyi@5
|
211 |
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
|
ladanyi@5
|
212 |
msg_ctxt_id[msgctxt_len - 1] = '\004';
|
ladanyi@5
|
213 |
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
|
ladanyi@5
|
214 |
translation = dcgettext (domain, msg_ctxt_id, category);
|
ladanyi@5
|
215 |
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
ladanyi@5
|
216 |
if (msg_ctxt_id != buf)
|
ladanyi@5
|
217 |
free (msg_ctxt_id);
|
ladanyi@5
|
218 |
#endif
|
ladanyi@5
|
219 |
if (translation != msg_ctxt_id)
|
ladanyi@5
|
220 |
return translation;
|
ladanyi@5
|
221 |
}
|
ladanyi@5
|
222 |
return msgid;
|
ladanyi@5
|
223 |
}
|
ladanyi@5
|
224 |
|
ladanyi@5
|
225 |
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
|
ladanyi@5
|
226 |
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
|
ladanyi@5
|
227 |
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
|
ladanyi@5
|
228 |
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
|
ladanyi@5
|
229 |
|
ladanyi@5
|
230 |
#ifdef __GNUC__
|
ladanyi@5
|
231 |
__inline
|
ladanyi@5
|
232 |
#else
|
ladanyi@5
|
233 |
#ifdef __cplusplus
|
ladanyi@5
|
234 |
inline
|
ladanyi@5
|
235 |
#endif
|
ladanyi@5
|
236 |
#endif
|
ladanyi@5
|
237 |
static const char *
|
ladanyi@5
|
238 |
dcnpgettext_expr (const char *domain,
|
ladanyi@5
|
239 |
const char *msgctxt, const char *msgid,
|
ladanyi@5
|
240 |
const char *msgid_plural, unsigned long int n,
|
ladanyi@5
|
241 |
int category)
|
ladanyi@5
|
242 |
{
|
ladanyi@5
|
243 |
size_t msgctxt_len = strlen (msgctxt) + 1;
|
ladanyi@5
|
244 |
size_t msgid_len = strlen (msgid) + 1;
|
ladanyi@5
|
245 |
const char *translation;
|
ladanyi@5
|
246 |
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
ladanyi@5
|
247 |
char msg_ctxt_id[msgctxt_len + msgid_len];
|
ladanyi@5
|
248 |
#else
|
ladanyi@5
|
249 |
char buf[1024];
|
ladanyi@5
|
250 |
char *msg_ctxt_id =
|
ladanyi@5
|
251 |
(msgctxt_len + msgid_len <= sizeof (buf)
|
ladanyi@5
|
252 |
? buf
|
ladanyi@5
|
253 |
: (char *) malloc (msgctxt_len + msgid_len));
|
ladanyi@5
|
254 |
if (msg_ctxt_id != NULL)
|
ladanyi@5
|
255 |
#endif
|
ladanyi@5
|
256 |
{
|
ladanyi@5
|
257 |
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
|
ladanyi@5
|
258 |
msg_ctxt_id[msgctxt_len - 1] = '\004';
|
ladanyi@5
|
259 |
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
|
ladanyi@5
|
260 |
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
|
ladanyi@5
|
261 |
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
|
ladanyi@5
|
262 |
if (msg_ctxt_id != buf)
|
ladanyi@5
|
263 |
free (msg_ctxt_id);
|
ladanyi@5
|
264 |
#endif
|
ladanyi@5
|
265 |
if (!(translation == msg_ctxt_id || translation == msgid_plural))
|
ladanyi@5
|
266 |
return translation;
|
ladanyi@5
|
267 |
}
|
ladanyi@5
|
268 |
return (n == 1 ? msgid : msgid_plural);
|
ladanyi@5
|
269 |
}
|
ladanyi@5
|
270 |
|
hegyi@1
|
271 |
#endif /* _LIBGETTEXT_H */
|