pcb 4.1.1
An interactive printed circuit board layout editor.

gettext.h

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