~ubuntu-branches/ubuntu/saucy/gnutls26/saucy-security

« back to all changes in this revision

Viewing changes to lib/gl/gettext.h

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-12-06 18:29:32 UTC
  • mfrom: (12.1.33 sid)
  • Revision ID: package-import@ubuntu.com-20121206182932-iih7i83juh8cdotf
Tags: 2.12.20-2ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Build gnutls-bin from this source package rather than from gnutls28:
    gnutls28's licensing is currently too strict for many of the free
    software packages built against it in Ubuntu main and we only want to
    support a single version.  Bump its version to achieve this.
* Avoid assuming that gets is declared.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Convenience header for conditional use of GNU <libintl.h>.
2
 
   Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2011 Free Software
 
2
   Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2012 Free Software
3
3
   Foundation, Inc.
4
4
 
5
5
   This program is free software; you can redistribute it and/or modify
13
13
   GNU Lesser General Public License for more details.
14
14
 
15
15
   You should have received a copy of the GNU Lesser General Public License along
16
 
   with this program; if not, write to the Free Software Foundation,
17
 
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
16
   with this program; if not, see <http://www.gnu.org/licenses/>.  */
18
17
 
19
18
#ifndef _LIBGETTEXT_H
20
19
#define _LIBGETTEXT_H 1
178
177
    return translation;
179
178
}
180
179
 
 
180
/* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
 
181
   can be arbitrary expressions.  But for string literals these macros are
 
182
   less efficient than those above.  */
 
183
 
 
184
#include <string.h>
 
185
 
 
186
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
 
187
  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
 
188
   /* || __STDC_VERSION__ >= 199901L */ )
 
189
 
 
190
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
 
191
#include <stdlib.h>
 
192
#endif
 
193
 
 
194
#define pgettext_expr(Msgctxt, Msgid) \
 
195
  dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
 
196
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
 
197
  dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
 
198
 
 
199
#ifdef __GNUC__
 
200
__inline
 
201
#else
 
202
#ifdef __cplusplus
 
203
inline
 
204
#endif
 
205
#endif
 
206
static const char *
 
207
dcpgettext_expr (const char *domain,
 
208
                 const char *msgctxt, const char *msgid,
 
209
                 int category)
 
210
{
 
211
  size_t msgctxt_len = strlen (msgctxt) + 1;
 
212
  size_t msgid_len = strlen (msgid) + 1;
 
213
  const char *translation;
 
214
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
 
215
  char msg_ctxt_id[msgctxt_len + msgid_len];
 
216
#else
 
217
  char buf[1024];
 
218
  char *msg_ctxt_id =
 
219
    (msgctxt_len + msgid_len <= sizeof (buf)
 
220
     ? buf
 
221
     : (char *) malloc (msgctxt_len + msgid_len));
 
222
  if (msg_ctxt_id != NULL)
 
223
#endif
 
224
    {
 
225
      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
 
226
      msg_ctxt_id[msgctxt_len - 1] = '\004';
 
227
      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
 
228
      translation = dcgettext (domain, msg_ctxt_id, category);
 
229
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
 
230
      if (msg_ctxt_id != buf)
 
231
        free (msg_ctxt_id);
 
232
#endif
 
233
      if (translation != msg_ctxt_id)
 
234
        return translation;
 
235
    }
 
236
  return msgid;
 
237
}
 
238
 
 
239
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
 
240
  dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
 
241
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
 
242
  dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
 
243
 
 
244
#ifdef __GNUC__
 
245
__inline
 
246
#else
 
247
#ifdef __cplusplus
 
248
inline
 
249
#endif
 
250
#endif
 
251
static const char *
 
252
dcnpgettext_expr (const char *domain,
 
253
                  const char *msgctxt, const char *msgid,
 
254
                  const char *msgid_plural, unsigned long int n,
 
255
                  int category)
 
256
{
 
257
  size_t msgctxt_len = strlen (msgctxt) + 1;
 
258
  size_t msgid_len = strlen (msgid) + 1;
 
259
  const char *translation;
 
260
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
 
261
  char msg_ctxt_id[msgctxt_len + msgid_len];
 
262
#else
 
263
  char buf[1024];
 
264
  char *msg_ctxt_id =
 
265
    (msgctxt_len + msgid_len <= sizeof (buf)
 
266
     ? buf
 
267
     : (char *) malloc (msgctxt_len + msgid_len));
 
268
  if (msg_ctxt_id != NULL)
 
269
#endif
 
270
    {
 
271
      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
 
272
      msg_ctxt_id[msgctxt_len - 1] = '\004';
 
273
      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
 
274
      translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
 
275
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
 
276
      if (msg_ctxt_id != buf)
 
277
        free (msg_ctxt_id);
 
278
#endif
 
279
      if (!(translation == msg_ctxt_id || translation == msgid_plural))
 
280
        return translation;
 
281
    }
 
282
  return (n == 1 ? msgid : msgid_plural);
 
283
}
 
284
 
181
285
#endif /* _LIBGETTEXT_H */