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