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