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