~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/gettext.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

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