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