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