Search
lxdream.org :: lxdream/src/gettext.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/gettext.h
changeset 968:6fb1481859a4
prev755:ab873907b00e
author nkeynes
date Mon Feb 09 00:13:46 2009 +0000 (11 years ago)
permissions -rw-r--r--
last change Fail cleanly if the display doesn't actually support GLX, rather than crashing horribly
view annotate diff log raw
     1 /* Convenience header for conditional use of GNU <libintl.h>.
     2    Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
     4    This program is free software; you can redistribute it and/or modify it
     5    under the terms of the GNU Library General Public License as published
     6    by the Free Software Foundation; either version 2, or (at your option)
     7    any later version.
     9    This program is distributed in the hope that it will be useful,
    10    but WITHOUT ANY WARRANTY; without even the implied warranty of
    11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12    Library General Public License for more details.
    14    You should have received a copy of the GNU Library General Public
    15    License along with this program; if not, write to the Free Software
    16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    17    USA.  */
    19 #ifndef _LIBGETTEXT_H
    20 #define _LIBGETTEXT_H 1
    22 #define _(String) gettext (String)
    23 #define Q_(String) g_strip_context ((String), gettext (String))
    24 #ifdef gettext_noop
    25 #define N_(String) gettext_noop (String)
    26 #else
    27 #define N_(String) (String)
    28 #endif
    30 /* NLS can be disabled through the configure --disable-nls option.  */
    31 #ifdef ENABLE_NLS
    33 /* Get declarations of GNU message catalog functions.  */
    34 # include <libintl.h>
    36 /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
    37    the gettext() and ngettext() macros.  This is an alternative to calling
    38    textdomain(), and is useful for libraries.  */
    39 # ifdef DEFAULT_TEXT_DOMAIN
    40 #  undef gettext
    41 #  define gettext(Msgid) \
    42      dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
    43 #  undef ngettext
    44 #  define ngettext(Msgid1, Msgid2, N) \
    45      dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
    46 # endif
    48 #else
    50 /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
    51    chokes if dcgettext is defined as a macro.  So include it now, to make
    52    later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
    53    as well because people using "gettext.h" will not include <libintl.h>,
    54    and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
    55    is OK.  */
    56 #if defined(__sun)
    57 # include <locale.h>
    58 #endif
    60 /* Many header files from the libstdc++ coming with g++ 3.3 or newer include
    61    <libintl.h>, which chokes if dcgettext is defined as a macro.  So include
    62    it now, to make later inclusions of <libintl.h> a NOP.  */
    63 #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
    64 # include <cstdlib>
    65 # if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
    66 #  include <libintl.h>
    67 # endif
    68 #endif
    70 /* Disabled NLS.
    71    The casts to 'const char *' serve the purpose of producing warnings
    72    for invalid uses of the value returned from these functions.
    73    On pre-ANSI systems without 'const', the config.h file is supposed to
    74    contain "#define const".  */
    75 # define gettext(Msgid) ((const char *) (Msgid))
    76 # define dgettext(Domainname, Msgid) ((const char *) (Msgid))
    77 # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
    78 # define ngettext(Msgid1, Msgid2, N) \
    79     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
    80 # define dngettext(Domainname, Msgid1, Msgid2, N) \
    81     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
    82 # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
    83     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
    84 # define textdomain(Domainname) ((const char *) (Domainname))
    85 # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
    86 # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
    88 #endif
    90 /* A pseudo function call that serves as a marker for the automated
    91    extraction of messages, but does not call gettext().  The run-time
    92    translation is done at a different place in the code.
    93    The argument, String, should be a literal string.  Concatenated strings
    94    and other string expressions won't work.
    95    The macro's expansion is not parenthesized, so that it is suitable as
    96    initializer for static 'char[]' or 'const char[]' variables.  */
    97 #define gettext_noop(String) String
    99 /* The separator between msgctxt and msgid in a .mo file.  */
   100 #define GETTEXT_CONTEXT_GLUE "\004"
   102 /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
   103    MSGID.  MSGCTXT and MSGID must be string literals.  MSGCTXT should be
   104    short and rarely need to change.
   105    The letter 'p' stands for 'particular' or 'special'.  */
   106 #ifdef DEFAULT_TEXT_DOMAIN
   107 # define pgettext(Msgctxt, Msgid) \
   108    pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
   109 #else
   110 # define pgettext(Msgctxt, Msgid) \
   111    pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
   112 #endif
   113 #define dpgettext(Domainname, Msgctxt, Msgid) \
   114   pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
   115 #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
   116   pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
   117 #ifdef DEFAULT_TEXT_DOMAIN
   118 # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
   119    npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
   120 #else
   121 # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
   122    npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
   123 #endif
   124 #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
   125   npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
   126 #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
   127   npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
   129 #ifdef __GNUC__
   130 __inline
   131 #else
   132 #ifdef __cplusplus
   133 inline
   134 #endif
   135 #endif
   136 static const char *
   137 pgettext_aux (const char *domain,
   138 	      const char *msg_ctxt_id, const char *msgid,
   139 	      int category)
   140 {
   141   const char *translation = dcgettext (domain, msg_ctxt_id, category);
   142   if (translation == msg_ctxt_id)
   143     return msgid;
   144   else
   145     return translation;
   146 }
   148 #ifdef __GNUC__
   149 __inline
   150 #else
   151 #ifdef __cplusplus
   152 inline
   153 #endif
   154 #endif
   155 static const char *
   156 npgettext_aux (const char *domain,
   157 	       const char *msg_ctxt_id, const char *msgid,
   158 	       const char *msgid_plural, unsigned long int n,
   159 	       int category)
   160 {
   161   const char *translation =
   162     dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
   163   if (translation == msg_ctxt_id || translation == msgid_plural)
   164     return (n == 1 ? msgid : msgid_plural);
   165   else
   166     return translation;
   167 }
   169 /* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
   170    can be arbitrary expressions.  But for string literals these macros are
   171    less efficient than those above.  */
   173 #include <string.h>
   175 #define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
   176   (__GNUC__ >= 3 || __GNUG__ >= 2 /* || __STDC_VERSION__ >= 199901L */ )
   178 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
   179 #include <stdlib.h>
   180 #endif
   182 #define pgettext_expr(Msgctxt, Msgid) \
   183   dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
   184 #define dpgettext_expr(Domainname, Msgctxt, Msgid) \
   185   dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
   187 #ifdef __GNUC__
   188 __inline
   189 #else
   190 #ifdef __cplusplus
   191 inline
   192 #endif
   193 #endif
   194 static const char *
   195 dcpgettext_expr (const char *domain,
   196 		 const char *msgctxt, const char *msgid,
   197 		 int category)
   198 {
   199   size_t msgctxt_len = strlen (msgctxt) + 1;
   200   size_t msgid_len = strlen (msgid) + 1;
   201   const char *translation;
   202 #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
   203   char msg_ctxt_id[msgctxt_len + msgid_len];
   204 #else
   205   char buf[1024];
   206   char *msg_ctxt_id =
   207     (msgctxt_len + msgid_len <= sizeof (buf)
   208      ? buf
   209      : (char *) malloc (msgctxt_len + msgid_len));
   210   if (msg_ctxt_id != NULL)
   211 #endif
   212     {
   213       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
   214       msg_ctxt_id[msgctxt_len - 1] = '\004';
   215       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
   216       translation = dcgettext (domain, msg_ctxt_id, category);
   217 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
   218       if (msg_ctxt_id != buf)
   219 	free (msg_ctxt_id);
   220 #endif
   221       if (translation != msg_ctxt_id)
   222 	return translation;
   223     }
   224   return msgid;
   225 }
   227 #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
   228   dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
   229 #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
   230   dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
   232 #ifdef __GNUC__
   233 __inline
   234 #else
   235 #ifdef __cplusplus
   236 inline
   237 #endif
   238 #endif
   239 static const char *
   240 dcnpgettext_expr (const char *domain,
   241 		  const char *msgctxt, const char *msgid,
   242 		  const char *msgid_plural, unsigned long int n,
   243 		  int category)
   244 {
   245   size_t msgctxt_len = strlen (msgctxt) + 1;
   246   size_t msgid_len = strlen (msgid) + 1;
   247   const char *translation;
   248 #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
   249   char msg_ctxt_id[msgctxt_len + msgid_len];
   250 #else
   251   char buf[1024];
   252   char *msg_ctxt_id =
   253     (msgctxt_len + msgid_len <= sizeof (buf)
   254      ? buf
   255      : (char *) malloc (msgctxt_len + msgid_len));
   256   if (msg_ctxt_id != NULL)
   257 #endif
   258     {
   259       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
   260       msg_ctxt_id[msgctxt_len - 1] = '\004';
   261       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
   262       translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
   263 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
   264       if (msg_ctxt_id != buf)
   265 	free (msg_ctxt_id);
   266 #endif
   267       if (!(translation == msg_ctxt_id || translation == msgid_plural))
   268 	return translation;
   269     }
   270   return (n == 1 ? msgid : msgid_plural);
   271 }
   273 #endif /* _LIBGETTEXT_H */
.