2N/A/* Convenience header for conditional use of GNU <libintl.h>.
2N/A Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2010 Free Software
2N/A Foundation, Inc.
2N/A
2N/A This program is free software; you can redistribute it and/or modify
2N/A it under the terms of the GNU General Public License as published by
2N/A the Free Software Foundation; either version 3, or (at your option)
2N/A any later version.
2N/A
2N/A This program is distributed in the hope that it will be useful,
2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A GNU General Public License for more details.
2N/A
2N/A You should have received a copy of the GNU General Public License along
2N/A with this program; if not, write to the Free Software Foundation,
2N/A Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
2N/A
2N/A#ifndef _LIBGETTEXT_H
2N/A#define _LIBGETTEXT_H 1
2N/A
2N/A/* NLS can be disabled through the configure --disable-nls option. */
2N/A#if ENABLE_NLS
2N/A
2N/A/* Get declarations of GNU message catalog functions. */
2N/A# include <libintl.h>
2N/A
2N/A/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
2N/A the gettext() and ngettext() macros. This is an alternative to calling
2N/A textdomain(), and is useful for libraries. */
2N/A# ifdef DEFAULT_TEXT_DOMAIN
2N/A# undef gettext
2N/A# define gettext(Msgid) \
2N/A dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
2N/A# undef ngettext
2N/A# define ngettext(Msgid1, Msgid2, N) \
2N/A dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
2N/A# endif
2N/A
2N/A#else
2N/A
2N/A/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
2N/A chokes if dcgettext is defined as a macro. So include it now, to make
2N/A later inclusions of <locale.h> a NOP. We don't include <libintl.h>
2N/A as well because people using "gettext.h" will not include <libintl.h>,
2N/A and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
2N/A is OK. */
2N/A#if defined(__sun)
2N/A# include <locale.h>
2N/A#endif
2N/A
2N/A/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
2N/A <libintl.h>, which chokes if dcgettext is defined as a macro. So include
2N/A it now, to make later inclusions of <libintl.h> a NOP. */
2N/A#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
2N/A# include <cstdlib>
2N/A# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
2N/A# include <libintl.h>
2N/A# endif
2N/A#endif
2N/A
2N/A/* Disabled NLS.
2N/A The casts to 'const char *' serve the purpose of producing warnings
2N/A for invalid uses of the value returned from these functions.
2N/A On pre-ANSI systems without 'const', the config.h file is supposed to
2N/A contain "#define const". */
2N/A# undef gettext
2N/A# define gettext(Msgid) ((const char *) (Msgid))
2N/A# undef dgettext
2N/A# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
2N/A# undef dcgettext
2N/A# define dcgettext(Domainname, Msgid, Category) \
2N/A ((void) (Category), dgettext (Domainname, Msgid))
2N/A# undef ngettext
2N/A# define ngettext(Msgid1, Msgid2, N) \
2N/A ((N) == 1 \
2N/A ? ((void) (Msgid2), (const char *) (Msgid1)) \
2N/A : ((void) (Msgid1), (const char *) (Msgid2)))
2N/A# undef dngettext
2N/A# define dngettext(Domainname, Msgid1, Msgid2, N) \
2N/A ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
2N/A# undef dcngettext
2N/A# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
2N/A ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
2N/A# undef textdomain
2N/A# define textdomain(Domainname) ((const char *) (Domainname))
2N/A# undef bindtextdomain
2N/A# define bindtextdomain(Domainname, Dirname) \
2N/A ((void) (Domainname), (const char *) (Dirname))
2N/A# undef bind_textdomain_codeset
2N/A# define bind_textdomain_codeset(Domainname, Codeset) \
2N/A ((void) (Domainname), (const char *) (Codeset))
2N/A
2N/A#endif
2N/A
2N/A/* A pseudo function call that serves as a marker for the automated
2N/A extraction of messages, but does not call gettext(). The run-time
2N/A translation is done at a different place in the code.
2N/A The argument, String, should be a literal string. Concatenated strings
2N/A and other string expressions won't work.
2N/A The macro's expansion is not parenthesized, so that it is suitable as
2N/A initializer for static 'char[]' or 'const char[]' variables. */
2N/A#define gettext_noop(String) String
2N/A
2N/A/* The separator between msgctxt and msgid in a .mo file. */
2N/A#define GETTEXT_CONTEXT_GLUE "\004"
2N/A
2N/A/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
2N/A MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
2N/A short and rarely need to change.
2N/A The letter 'p' stands for 'particular' or 'special'. */
2N/A#ifdef DEFAULT_TEXT_DOMAIN
2N/A# define pgettext(Msgctxt, Msgid) \
2N/A pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
2N/A#else
2N/A# define pgettext(Msgctxt, Msgid) \
2N/A pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
2N/A#endif
2N/A#define dpgettext(Domainname, Msgctxt, Msgid) \
2N/A pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
2N/A#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
2N/A pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
2N/A#ifdef DEFAULT_TEXT_DOMAIN
2N/A# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
2N/A npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
2N/A#else
2N/A# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
2N/A npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
2N/A#endif
2N/A#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
2N/A npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
2N/A#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
2N/A npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
2N/A
2N/A#ifdef __GNUC__
2N/A__inline
2N/A#else
2N/A#ifdef __cplusplus
2N/Ainline
2N/A#endif
2N/A#endif
2N/Astatic const char *
2N/Apgettext_aux (const char *domain,
2N/A const char *msg_ctxt_id, const char *msgid,
2N/A int category)
2N/A{
2N/A const char *translation = dcgettext (domain, msg_ctxt_id, category);
2N/A if (translation == msg_ctxt_id)
2N/A return msgid;
2N/A else
2N/A return translation;
2N/A}
2N/A
2N/A#ifdef __GNUC__
2N/A__inline
2N/A#else
2N/A#ifdef __cplusplus
2N/Ainline
2N/A#endif
2N/A#endif
2N/Astatic const char *
2N/Anpgettext_aux (const char *domain,
2N/A const char *msg_ctxt_id, const char *msgid,
2N/A const char *msgid_plural, unsigned long int n,
2N/A int category)
2N/A{
2N/A const char *translation =
2N/A dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
2N/A if (translation == msg_ctxt_id || translation == msgid_plural)
2N/A return (n == 1 ? msgid : msgid_plural);
2N/A else
2N/A return translation;
2N/A}
2N/A
2N/A/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
2N/A can be arbitrary expressions. But for string literals these macros are
2N/A less efficient than those above. */
2N/A
2N/A#include <string.h>
2N/A
2N/A#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
2N/A (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
2N/A /* || __STDC_VERSION__ >= 199901L */ )
2N/A
2N/A#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
2N/A#include <stdlib.h>
2N/A#endif
2N/A
2N/A#define pgettext_expr(Msgctxt, Msgid) \
2N/A dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
2N/A#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
2N/A dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
2N/A
2N/A#ifdef __GNUC__
2N/A__inline
2N/A#else
2N/A#ifdef __cplusplus
2N/Ainline
2N/A#endif
2N/A#endif
2N/Astatic const char *
2N/Adcpgettext_expr (const char *domain,
2N/A const char *msgctxt, const char *msgid,
2N/A int category)
2N/A{
2N/A size_t msgctxt_len = strlen (msgctxt) + 1;
2N/A size_t msgid_len = strlen (msgid) + 1;
2N/A const char *translation;
2N/A#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
2N/A char msg_ctxt_id[msgctxt_len + msgid_len];
2N/A#else
2N/A char buf[1024];
2N/A char *msg_ctxt_id =
2N/A (msgctxt_len + msgid_len <= sizeof (buf)
2N/A ? buf
2N/A : (char *) malloc (msgctxt_len + msgid_len));
2N/A if (msg_ctxt_id != NULL)
2N/A#endif
2N/A {
2N/A memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
2N/A msg_ctxt_id[msgctxt_len - 1] = '\004';
2N/A memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
2N/A translation = dcgettext (domain, msg_ctxt_id, category);
2N/A#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
2N/A if (msg_ctxt_id != buf)
2N/A free (msg_ctxt_id);
2N/A#endif
2N/A if (translation != msg_ctxt_id)
2N/A return translation;
2N/A }
2N/A return msgid;
2N/A}
2N/A
2N/A#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
2N/A dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
2N/A#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
2N/A dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
2N/A
2N/A#ifdef __GNUC__
2N/A__inline
2N/A#else
2N/A#ifdef __cplusplus
2N/Ainline
2N/A#endif
2N/A#endif
2N/Astatic const char *
2N/Adcnpgettext_expr (const char *domain,
2N/A const char *msgctxt, const char *msgid,
2N/A const char *msgid_plural, unsigned long int n,
2N/A int category)
2N/A{
2N/A size_t msgctxt_len = strlen (msgctxt) + 1;
2N/A size_t msgid_len = strlen (msgid) + 1;
2N/A const char *translation;
2N/A#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
2N/A char msg_ctxt_id[msgctxt_len + msgid_len];
2N/A#else
2N/A char buf[1024];
2N/A char *msg_ctxt_id =
2N/A (msgctxt_len + msgid_len <= sizeof (buf)
2N/A ? buf
2N/A : (char *) malloc (msgctxt_len + msgid_len));
2N/A if (msg_ctxt_id != NULL)
2N/A#endif
2N/A {
2N/A memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
2N/A msg_ctxt_id[msgctxt_len - 1] = '\004';
2N/A memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
2N/A translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
2N/A#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
2N/A if (msg_ctxt_id != buf)
2N/A free (msg_ctxt_id);
2N/A#endif
2N/A if (!(translation == msg_ctxt_id || translation == msgid_plural))
2N/A return translation;
2N/A }
2N/A return (n == 1 ? msgid : msgid_plural);
2N/A}
2N/A
2N/A#endif /* _LIBGETTEXT_H */