Blame gl/gettext.h

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