Blame src/gettext.h

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