Drizzled Public API Documentation

gettext.h

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002    vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003    Convenience header for conditional use of GNU <libintl.h>.
00004    Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published
00008    by the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public
00017    License along with this program; if not, write to the Free Software
00018    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019    USA.  */
00020 
00021 #pragma once
00022 
00023 /* NLS can be disabled through the configure --disable-nls option.  */
00024 #if defined(ENABLE_NLS)
00025 
00026 /* Get declarations of GNU message catalog functions.  */
00027 # include <libintl.h>
00028 
00029 /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
00030    the gettext() and ngettext() macros.  This is an alternative to calling
00031    textdomain(), and is useful for libraries.  */
00032 # ifdef DEFAULT_TEXT_DOMAIN
00033 #  undef gettext
00034 #  define gettext(Msgid) \
00035      dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
00036 #  undef ngettext
00037 #  define ngettext(Msgid1, Msgid2, N) \
00038      dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
00039 # endif
00040 
00041 #else
00042 
00043 /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
00044    chokes if dcgettext is defined as a macro.  So include it now, to make
00045    later inclusions of <locale.h> a NOP.  We don't include <libintl.h>
00046    as well because people using "gettext.h" will not include <libintl.h>,
00047    and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
00048    is OK.  */
00049 #if defined(__sun)
00050 # include <locale.h>
00051 #endif
00052 
00053 /* Many header files from the libstdc++ coming with g++ 3.3 or newer include
00054    <libintl.h>, which chokes if dcgettext is defined as a macro.  So include
00055    it now, to make later inclusions of <libintl.h> a NOP.  */
00056 #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
00057 # include <cstdlib>
00058 # if defined(__GLIBC__)
00059 #  if (__GLIBC__ >= 2) || defined(_GLIBCXX_HAVE_LIBINTL_H)
00060 #    include <libintl.h>
00061 #  endif
00062 # endif
00063 #endif
00064 
00065 #ifndef gettext
00066 /* Disabled NLS.
00067    The casts to 'const char *' serve the purpose of producing warnings
00068    for invalid uses of the value returned from these functions.
00069    On pre-ANSI systems without 'const', the config.h file is supposed to
00070    contain "#define const".  */
00071 # define gettext(Msgid) ((const char *) (Msgid))
00072 # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
00073 # define dcgettext(Domainname, Msgid, Category) \
00074     ((void) (Category), dgettext (Domainname, Msgid))
00075 # define ngettext(Msgid1, Msgid2, N) \
00076     ((N) == 1 \
00077      ? ((void) (Msgid2), (const char *) (Msgid1)) \
00078      : ((void) (Msgid1), (const char *) (Msgid2)))
00079 # define dngettext(Domainname, Msgid1, Msgid2, N) \
00080     ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
00081 # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
00082     ((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
00083 # define textdomain(Domainname) ((const char *) (Domainname))
00084 # define bindtextdomain(Domainname, Dirname) \
00085     ((void) (Domainname), (const char *) (Dirname))
00086 # define bind_textdomain_codeset(Domainname, Codeset) \
00087     ((void) (Domainname), (const char *) (Codeset))
00088 
00089 #endif
00090 #endif 
00091 /* A pseudo function call that serves as a marker for the automated
00092    extraction of messages, but does not call gettext().  The run-time
00093    translation is done at a different place in the code.
00094    The argument, String, should be a literal string.  Concatenated strings
00095    and other string expressions won't work.
00096    The macro's expansion is not parenthesized, so that it is suitable as
00097    initializer for static 'char[]' or 'const char[]' variables.  */
00098 #define gettext_noop(String) String
00099 
00100 /* The separator between msgctxt and msgid in a .mo file.  */
00101 #define GETTEXT_CONTEXT_GLUE "\004"
00102 
00103 /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
00104    MSGID.  MSGCTXT and MSGID must be string literals.  MSGCTXT should be
00105    short and rarely need to change.
00106    The letter 'p' stands for 'particular' or 'special'.  */
00107 #ifdef DEFAULT_TEXT_DOMAIN
00108 # define pgettext(Msgctxt, Msgid) \
00109    pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
00110 #else
00111 # define pgettext(Msgctxt, Msgid) \
00112    pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
00113 #endif
00114 #define dpgettext(Domainname, Msgctxt, Msgid) \
00115   pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
00116 #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
00117   pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
00118 #ifdef DEFAULT_TEXT_DOMAIN
00119 # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
00120    npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
00121 #else
00122 # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
00123    npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
00124 #endif
00125 #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
00126   npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
00127 #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
00128   npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
00129 
00130 #ifdef __GNUC__
00131 __inline
00132 #else
00133 #ifdef __cplusplus
00134 inline
00135 #endif
00136 #endif
00137 static const char *
00138 pgettext_aux (const char *domain,
00139         const char *msg_ctxt_id, const char *msgid,
00140         int category)
00141 {
00142   const char *translation = dcgettext (domain, msg_ctxt_id, category);
00143   if (translation == msg_ctxt_id)
00144     return msgid;
00145   else
00146     return translation;
00147 }
00148 
00149 #ifdef __GNUC__
00150 __inline
00151 #else
00152 #ifdef __cplusplus
00153 inline
00154 #endif
00155 #endif
00156 static const char *
00157 npgettext_aux (const char *domain,
00158          const char *msg_ctxt_id, const char *msgid,
00159          const char *msgid_plural, unsigned long int n,
00160          int category)
00161 {
00162   const char *translation =
00163     dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
00164   if (translation == msg_ctxt_id || translation == msgid_plural)
00165     return (n == 1 ? msgid : msgid_plural);
00166   else
00167     return translation;
00168 }
00169 
00170 /* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
00171    can be arbitrary expressions.  But for string literals these macros are
00172    less efficient than those above.  */
00173 
00174 #include <string.h>
00175 
00176 /* We need to turn these off explicitly for drizzle */
00177 #define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
00178 
00179 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
00180 #include <stdlib.h>
00181 #endif
00182 
00183 #define pgettext_expr(Msgctxt, Msgid) \
00184   dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
00185 #define dpgettext_expr(Domainname, Msgctxt, Msgid) \
00186   dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
00187 
00188 #ifdef __GNUC__
00189 __inline
00190 #else
00191 #ifdef __cplusplus
00192 inline
00193 #endif
00194 #endif
00195 static const char *
00196 dcpgettext_expr (const char *domain,
00197      const char *msgctxt, const char *msgid,
00198      int category)
00199 {
00200   size_t msgctxt_len = strlen (msgctxt) + 1;
00201   size_t msgid_len = strlen (msgid) + 1;
00202   const char *translation;
00203 #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
00204   char msg_ctxt_id[msgctxt_len + msgid_len];
00205 #else
00206   char buf[1024];
00207   char *msg_ctxt_id =
00208     (msgctxt_len + msgid_len <= sizeof (buf)
00209      ? buf
00210      : (char *) malloc (msgctxt_len + msgid_len));
00211   if (msg_ctxt_id != NULL)
00212 #endif
00213     {
00214       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
00215       msg_ctxt_id[msgctxt_len - 1] = '\004';
00216       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
00217       translation = dcgettext (domain, msg_ctxt_id, category);
00218 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
00219       if (msg_ctxt_id != buf)
00220   free (msg_ctxt_id);
00221 #endif
00222       if (translation != msg_ctxt_id)
00223   return translation;
00224     }
00225   return msgid;
00226 }
00227 
00228 #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
00229   dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
00230 #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
00231   dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
00232 
00233 #ifdef __GNUC__
00234 __inline
00235 #else
00236 #ifdef __cplusplus
00237 inline
00238 #endif
00239 #endif
00240 static const char *
00241 dcnpgettext_expr (const char *domain,
00242       const char *msgctxt, const char *msgid,
00243       const char *msgid_plural, unsigned long int n,
00244       int category)
00245 {
00246   size_t msgctxt_len = strlen (msgctxt) + 1;
00247   size_t msgid_len = strlen (msgid) + 1;
00248   const char *translation;
00249 #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
00250   char msg_ctxt_id[msgctxt_len + msgid_len];
00251 #else
00252   char buf[1024];
00253   char *msg_ctxt_id =
00254     (msgctxt_len + msgid_len <= sizeof (buf)
00255      ? buf
00256      : (char *) malloc (msgctxt_len + msgid_len));
00257   if (msg_ctxt_id != NULL)
00258 #endif
00259     {
00260       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
00261       msg_ctxt_id[msgctxt_len - 1] = '\004';
00262       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
00263       translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
00264 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
00265       if (msg_ctxt_id != buf)
00266   free (msg_ctxt_id);
00267 #endif
00268       if (!(translation == msg_ctxt_id || translation == msgid_plural))
00269   return translation;
00270     }
00271   return (n == 1 ? msgid : msgid_plural);
00272 }
00273 
00274 #define _(String)  gettext(String)
00275 #define N_(String) gettext_noop(String)