Blame lib/gettext.h

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