Search
lxdream.org :: lxdream/src/gettext.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gettext.h
changeset 755:ab873907b00e
next968:6fb1481859a4
author nkeynes
date Mon Jul 21 00:08:34 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Add gettext.h and build sanely without libintl if it's not available
Remove x86dasm's config.h & opintl.h (no longer needed and actually wrong)
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gettext.h Mon Jul 21 00:08:34 2008 +0000
1.3 @@ -0,0 +1,273 @@
1.4 +/* Convenience header for conditional use of GNU <libintl.h>.
1.5 + Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
1.6 +
1.7 + This program is free software; you can redistribute it and/or modify it
1.8 + under the terms of the GNU Library General Public License as published
1.9 + by the Free Software Foundation; either version 2, or (at your option)
1.10 + any later version.
1.11 +
1.12 + This program is distributed in the hope that it will be useful,
1.13 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 + Library General Public License for more details.
1.16 +
1.17 + You should have received a copy of the GNU Library General Public
1.18 + License along with this program; if not, write to the Free Software
1.19 + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1.20 + USA. */
1.21 +
1.22 +#ifndef _LIBGETTEXT_H
1.23 +#define _LIBGETTEXT_H 1
1.24 +
1.25 +#define _(String) gettext (String)
1.26 +#define Q_(String) g_strip_context ((String), gettext (String))
1.27 +#ifdef gettext_noop
1.28 +#define N_(String) gettext_noop (String)
1.29 +#else
1.30 +#define N_(String) (String)
1.31 +#endif
1.32 +
1.33 +/* NLS can be disabled through the configure --disable-nls option. */
1.34 +#if ENABLE_NLS
1.35 +
1.36 +/* Get declarations of GNU message catalog functions. */
1.37 +# include <libintl.h>
1.38 +
1.39 +/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
1.40 + the gettext() and ngettext() macros. This is an alternative to calling
1.41 + textdomain(), and is useful for libraries. */
1.42 +# ifdef DEFAULT_TEXT_DOMAIN
1.43 +# undef gettext
1.44 +# define gettext(Msgid) \
1.45 + dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
1.46 +# undef ngettext
1.47 +# define ngettext(Msgid1, Msgid2, N) \
1.48 + dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
1.49 +# endif
1.50 +
1.51 +#else
1.52 +
1.53 +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
1.54 + chokes if dcgettext is defined as a macro. So include it now, to make
1.55 + later inclusions of <locale.h> a NOP. We don't include <libintl.h>
1.56 + as well because people using "gettext.h" will not include <libintl.h>,
1.57 + and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
1.58 + is OK. */
1.59 +#if defined(__sun)
1.60 +# include <locale.h>
1.61 +#endif
1.62 +
1.63 +/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
1.64 + <libintl.h>, which chokes if dcgettext is defined as a macro. So include
1.65 + it now, to make later inclusions of <libintl.h> a NOP. */
1.66 +#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
1.67 +# include <cstdlib>
1.68 +# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
1.69 +# include <libintl.h>
1.70 +# endif
1.71 +#endif
1.72 +
1.73 +/* Disabled NLS.
1.74 + The casts to 'const char *' serve the purpose of producing warnings
1.75 + for invalid uses of the value returned from these functions.
1.76 + On pre-ANSI systems without 'const', the config.h file is supposed to
1.77 + contain "#define const". */
1.78 +# define gettext(Msgid) ((const char *) (Msgid))
1.79 +# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
1.80 +# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
1.81 +# define ngettext(Msgid1, Msgid2, N) \
1.82 + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
1.83 +# define dngettext(Domainname, Msgid1, Msgid2, N) \
1.84 + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
1.85 +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
1.86 + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
1.87 +# define textdomain(Domainname) ((const char *) (Domainname))
1.88 +# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
1.89 +# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
1.90 +
1.91 +#endif
1.92 +
1.93 +/* A pseudo function call that serves as a marker for the automated
1.94 + extraction of messages, but does not call gettext(). The run-time
1.95 + translation is done at a different place in the code.
1.96 + The argument, String, should be a literal string. Concatenated strings
1.97 + and other string expressions won't work.
1.98 + The macro's expansion is not parenthesized, so that it is suitable as
1.99 + initializer for static 'char[]' or 'const char[]' variables. */
1.100 +#define gettext_noop(String) String
1.101 +
1.102 +/* The separator between msgctxt and msgid in a .mo file. */
1.103 +#define GETTEXT_CONTEXT_GLUE "\004"
1.104 +
1.105 +/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
1.106 + MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
1.107 + short and rarely need to change.
1.108 + The letter 'p' stands for 'particular' or 'special'. */
1.109 +#ifdef DEFAULT_TEXT_DOMAIN
1.110 +# define pgettext(Msgctxt, Msgid) \
1.111 + pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
1.112 +#else
1.113 +# define pgettext(Msgctxt, Msgid) \
1.114 + pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
1.115 +#endif
1.116 +#define dpgettext(Domainname, Msgctxt, Msgid) \
1.117 + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
1.118 +#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
1.119 + pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
1.120 +#ifdef DEFAULT_TEXT_DOMAIN
1.121 +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
1.122 + npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
1.123 +#else
1.124 +# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
1.125 + npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
1.126 +#endif
1.127 +#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
1.128 + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
1.129 +#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
1.130 + npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
1.131 +
1.132 +#ifdef __GNUC__
1.133 +__inline
1.134 +#else
1.135 +#ifdef __cplusplus
1.136 +inline
1.137 +#endif
1.138 +#endif
1.139 +static const char *
1.140 +pgettext_aux (const char *domain,
1.141 + const char *msg_ctxt_id, const char *msgid,
1.142 + int category)
1.143 +{
1.144 + const char *translation = dcgettext (domain, msg_ctxt_id, category);
1.145 + if (translation == msg_ctxt_id)
1.146 + return msgid;
1.147 + else
1.148 + return translation;
1.149 +}
1.150 +
1.151 +#ifdef __GNUC__
1.152 +__inline
1.153 +#else
1.154 +#ifdef __cplusplus
1.155 +inline
1.156 +#endif
1.157 +#endif
1.158 +static const char *
1.159 +npgettext_aux (const char *domain,
1.160 + const char *msg_ctxt_id, const char *msgid,
1.161 + const char *msgid_plural, unsigned long int n,
1.162 + int category)
1.163 +{
1.164 + const char *translation =
1.165 + dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
1.166 + if (translation == msg_ctxt_id || translation == msgid_plural)
1.167 + return (n == 1 ? msgid : msgid_plural);
1.168 + else
1.169 + return translation;
1.170 +}
1.171 +
1.172 +/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
1.173 + can be arbitrary expressions. But for string literals these macros are
1.174 + less efficient than those above. */
1.175 +
1.176 +#include <string.h>
1.177 +
1.178 +#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
1.179 + (__GNUC__ >= 3 || __GNUG__ >= 2 /* || __STDC_VERSION__ >= 199901L */ )
1.180 +
1.181 +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
1.182 +#include <stdlib.h>
1.183 +#endif
1.184 +
1.185 +#define pgettext_expr(Msgctxt, Msgid) \
1.186 + dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
1.187 +#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
1.188 + dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
1.189 +
1.190 +#ifdef __GNUC__
1.191 +__inline
1.192 +#else
1.193 +#ifdef __cplusplus
1.194 +inline
1.195 +#endif
1.196 +#endif
1.197 +static const char *
1.198 +dcpgettext_expr (const char *domain,
1.199 + const char *msgctxt, const char *msgid,
1.200 + int category)
1.201 +{
1.202 + size_t msgctxt_len = strlen (msgctxt) + 1;
1.203 + size_t msgid_len = strlen (msgid) + 1;
1.204 + const char *translation;
1.205 +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
1.206 + char msg_ctxt_id[msgctxt_len + msgid_len];
1.207 +#else
1.208 + char buf[1024];
1.209 + char *msg_ctxt_id =
1.210 + (msgctxt_len + msgid_len <= sizeof (buf)
1.211 + ? buf
1.212 + : (char *) malloc (msgctxt_len + msgid_len));
1.213 + if (msg_ctxt_id != NULL)
1.214 +#endif
1.215 + {
1.216 + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
1.217 + msg_ctxt_id[msgctxt_len - 1] = '\004';
1.218 + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
1.219 + translation = dcgettext (domain, msg_ctxt_id, category);
1.220 +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
1.221 + if (msg_ctxt_id != buf)
1.222 + free (msg_ctxt_id);
1.223 +#endif
1.224 + if (translation != msg_ctxt_id)
1.225 + return translation;
1.226 + }
1.227 + return msgid;
1.228 +}
1.229 +
1.230 +#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
1.231 + dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
1.232 +#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
1.233 + dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
1.234 +
1.235 +#ifdef __GNUC__
1.236 +__inline
1.237 +#else
1.238 +#ifdef __cplusplus
1.239 +inline
1.240 +#endif
1.241 +#endif
1.242 +static const char *
1.243 +dcnpgettext_expr (const char *domain,
1.244 + const char *msgctxt, const char *msgid,
1.245 + const char *msgid_plural, unsigned long int n,
1.246 + int category)
1.247 +{
1.248 + size_t msgctxt_len = strlen (msgctxt) + 1;
1.249 + size_t msgid_len = strlen (msgid) + 1;
1.250 + const char *translation;
1.251 +#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
1.252 + char msg_ctxt_id[msgctxt_len + msgid_len];
1.253 +#else
1.254 + char buf[1024];
1.255 + char *msg_ctxt_id =
1.256 + (msgctxt_len + msgid_len <= sizeof (buf)
1.257 + ? buf
1.258 + : (char *) malloc (msgctxt_len + msgid_len));
1.259 + if (msg_ctxt_id != NULL)
1.260 +#endif
1.261 + {
1.262 + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
1.263 + msg_ctxt_id[msgctxt_len - 1] = '\004';
1.264 + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
1.265 + translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
1.266 +#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
1.267 + if (msg_ctxt_id != buf)
1.268 + free (msg_ctxt_id);
1.269 +#endif
1.270 + if (!(translation == msg_ctxt_id || translation == msgid_plural))
1.271 + return translation;
1.272 + }
1.273 + return (n == 1 ? msgid : msgid_plural);
1.274 +}
1.275 +
1.276 +#endif /* _LIBGETTEXT_H */
.