~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to jnlib/w32-gettext.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-03-08 22:46:47 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090308224647-gq17gatcl71lrc2k
Tags: 2.0.11-1
* New upstream release. (Closes: #496663)
* debian/control: Make the description a little more distinctive than
  gnupg v1's. Thanks Jari Aalto. (Closes: #496323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* w32-gettext.c  - A simplified version of gettext for use under W32.
2
 
 * Copyright (C) 1995, 1996, 1997, 1999, 2000, 2003,
3
 
 *               2005, 2007, 2088 Free Software Foundation, Inc.
4
 
 *
5
 
 * This file is part of JNLIB.
6
 
 *
7
 
 * JNLIB is free software; you can redistribute it and/or modify it
8
 
 * under the terms of the GNU Lesser General Public License as
9
 
 * published by the Free Software Foundation; either version 3 of
10
 
 * the License, or (at your option) any later version.
11
 
 *
12
 
 * JNLIB is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Lesser General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19
 
 */
20
 
 
21
 
/* 
22
 
   This is a simplified version of gettext written by Ulrich Drepper.
23
 
   It is used for the Win32 version of GnuPG becaise all the overhead
24
 
   of gettext is not needed and we have to do some special Win32
25
 
   stuff.  I decided that this is far easier than to tweak gettext for
26
 
   the special cases (I tried it but it is a lot of code). wk 15.09.99
27
 
 */
28
 
 
 
1
/* w32-gettext.h - A simple gettext implementation for Windows targets.
 
2
   Copyright (C) 1995, 1996, 1997, 1999, 2005, 2007,
 
3
                 2008 Free Software Foundation, Inc.
 
4
 
 
5
   This program is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Lesser General Public License
 
7
   as published by the Free Software Foundation; either version 2.1 of
 
8
   the License, or (at your option) any later version.
 
9
 
 
10
   This program is distributed in the hope that it will be useful, but
 
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Lesser General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Lesser General Public
 
16
   License along with this program; if not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#if HAVE_CONFIG_H
29
20
#include <config.h>
30
 
#ifdef USE_SIMPLE_GETTEXT
31
 
# if !defined (_WIN32) && !defined (__CYGWIN32__)
 
21
#endif
 
22
#if !defined (_WIN32) && !defined (__CYGWIN32__)
32
23
#  error This module may only be build for Windows or Cygwin32
33
 
# endif
34
 
 
35
 
# include <stdio.h>
36
 
# include <stdlib.h>
37
 
# include <string.h>
38
 
# include <ctype.h>
39
 
# include <errno.h>
40
 
# include <sys/types.h>
41
 
# include <sys/stat.h>
42
 
 
43
 
# include "libjnlib-config.h"
44
 
# include "types.h"
45
 
# include "stringhelp.h"
46
 
# include "utf8conv.h"
47
 
# include "w32help.h"
48
 
 
49
 
# include "windows.h" /* For GetModuleFileName.  */
50
 
 
51
 
 
52
 
 
53
 
/* The magic number of the GNU message catalog format.  */
54
 
#define MAGIC         0x950412de
55
 
#define MAGIC_SWAPPED 0xde120495
56
 
 
57
 
/* Revision number of the currently used .mo (binary) file format.  */
58
 
#define MO_REVISION_NUMBER 0
59
 
 
60
 
 
61
 
/* Header for binary .mo file format.  */
62
 
struct mo_file_header
63
 
{
64
 
  /* The magic number.  */
65
 
  u32 magic;
66
 
  /* The revision number of the file format.  */
67
 
  u32 revision;
68
 
  /* The number of strings pairs.  */
69
 
  u32 nstrings;
70
 
  /* Offset of table with start offsets of original strings.  */
71
 
  u32 orig_tab_offset;
72
 
  /* Offset of table with start offsets of translation strings.  */
73
 
  u32 trans_tab_offset;
74
 
  /* Size of hashing table.  */
75
 
  u32 hash_tab_size;
76
 
  /* Offset of first hashing entry.  */
77
 
  u32 hash_tab_offset;
78
 
};
79
 
 
80
 
struct string_desc
81
 
{
82
 
  /* Length of addressed string.  */
83
 
  u32 length;
84
 
  /* Offset of string in file.  */
85
 
  u32 offset;
86
 
};
87
 
 
88
 
 
89
 
struct overflow_space_s
90
 
{
91
 
  struct overflow_space_s *next;
92
 
  u32 idx;
93
 
  char d[1];
94
 
};
95
 
 
96
 
struct loaded_domain
97
 
{
98
 
  char *data;
99
 
  int must_swap;
100
 
  u32 nstrings;
101
 
  char *mapped;  /* 0 = not yet mapped, 1 = mapped,
102
 
                    2 = mapped to
103
 
                    overflow space */
104
 
  struct overflow_space_s *overflow_space;
105
 
  struct string_desc *orig_tab;
106
 
  struct string_desc *trans_tab;
107
 
  u32 hash_size;
108
 
  u32 *hash_tab;
109
 
};
110
 
 
111
 
 
112
 
static struct loaded_domain *the_domain;
113
 
static char *the_langid;
114
 
 
115
 
static __inline__ u32
116
 
do_swap_u32( u32 i )
117
 
{
118
 
  return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
119
 
}
120
 
 
121
 
#define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data) )
122
 
 
123
 
 
124
 
/* We assume to have `unsigned long int' value with at least 32 bits.  */
125
 
#define HASHWORDBITS 32
126
 
 
127
 
 
128
 
 
129
 
/* BEGIN parts of localname.c from gettext.  */
 
24
#endif
 
25
 
 
26
#include <stdlib.h>
 
27
#include <stdio.h>
 
28
#include <string.h>
 
29
#include <errno.h>
 
30
#include <ctype.h>
 
31
#include <sys/types.h>
 
32
#include <sys/stat.h>
 
33
#include <stdint.h>
 
34
#include <locale.h>
 
35
#include <windows.h>
 
36
 
 
37
#ifdef JNLIB_IN_JNLIB
 
38
#include "libjnlib-config.h"
 
39
#endif
 
40
 
 
41
#ifndef jnlib_malloc
 
42
# define jnlib_malloc(a)    malloc ((a))
 
43
# define jnlib_calloc(a,b)  calloc ((a), (b))
 
44
# define jnlib_free(a)      free ((a))
 
45
# define jnlib_xstrdup(a)   my_xstrdup(a)
 
46
#endif /*!jnlib_malloc*/
 
47
 
 
48
 
 
49
 
 
50
/* localname.c from gettext BEGIN.  */
 
51
 
 
52
/* Determine the current selected locale.
 
53
   Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
 
54
 
 
55
   This program is free software; you can redistribute it and/or modify it
 
56
   under the terms of the GNU Library General Public License as published
 
57
   by the Free Software Foundation; either version 2, or (at your option)
 
58
   any later version.
 
59
 
 
60
   This program is distributed in the hope that it will be useful,
 
61
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
62
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
63
   Library General Public License for more details.
 
64
 
 
65
   You should have received a copy of the GNU Library General Public
 
66
   License along with this program; if not, write to the Free Software
 
67
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
68
   USA.  */
130
69
 
131
70
/* Written by Ulrich Drepper <drepper@gnu.org>, 1995.  */
132
71
/* Win32 code written by Tor Lillqvist <tml@iki.fi>.  */
 
72
/* Renamed _nl_locale_name, removed unsed args, removed include files,
 
73
   non-W32 code and changed comments <wk@gnupg.org>.  */
133
74
 
134
 
/* List of language codes, sorted by value:
135
 
   0x01 LANG_ARABIC
136
 
   0x02 LANG_BULGARIAN
137
 
   0x03 LANG_CATALAN
138
 
   0x04 LANG_CHINESE
139
 
   0x05 LANG_CZECH
140
 
   0x06 LANG_DANISH
141
 
   0x07 LANG_GERMAN
142
 
   0x08 LANG_GREEK
143
 
   0x09 LANG_ENGLISH
144
 
   0x0a LANG_SPANISH
145
 
   0x0b LANG_FINNISH
146
 
   0x0c LANG_FRENCH
147
 
   0x0d LANG_HEBREW
148
 
   0x0e LANG_HUNGARIAN
149
 
   0x0f LANG_ICELANDIC
150
 
   0x10 LANG_ITALIAN
151
 
   0x11 LANG_JAPANESE
152
 
   0x12 LANG_KOREAN
153
 
   0x13 LANG_DUTCH
154
 
   0x14 LANG_NORWEGIAN
155
 
   0x15 LANG_POLISH
156
 
   0x16 LANG_PORTUGUESE
157
 
   0x17 LANG_RHAETO_ROMANCE
158
 
   0x18 LANG_ROMANIAN
159
 
   0x19 LANG_RUSSIAN
160
 
   0x1a LANG_CROATIAN == LANG_SERBIAN
161
 
   0x1b LANG_SLOVAK
162
 
   0x1c LANG_ALBANIAN
163
 
   0x1d LANG_SWEDISH
164
 
   0x1e LANG_THAI
165
 
   0x1f LANG_TURKISH
166
 
   0x20 LANG_URDU
167
 
   0x21 LANG_INDONESIAN
168
 
   0x22 LANG_UKRAINIAN
169
 
   0x23 LANG_BELARUSIAN
170
 
   0x24 LANG_SLOVENIAN
171
 
   0x25 LANG_ESTONIAN
172
 
   0x26 LANG_LATVIAN
173
 
   0x27 LANG_LITHUANIAN
174
 
   0x28 LANG_TAJIK
175
 
   0x29 LANG_FARSI
176
 
   0x2a LANG_VIETNAMESE
177
 
   0x2b LANG_ARMENIAN
178
 
   0x2c LANG_AZERI
179
 
   0x2d LANG_BASQUE
180
 
   0x2e LANG_SORBIAN
181
 
   0x2f LANG_MACEDONIAN
182
 
   0x30 LANG_SUTU
183
 
   0x31 LANG_TSONGA
184
 
   0x32 LANG_TSWANA
185
 
   0x33 LANG_VENDA
186
 
   0x34 LANG_XHOSA
187
 
   0x35 LANG_ZULU
188
 
   0x36 LANG_AFRIKAANS
189
 
   0x37 LANG_GEORGIAN
190
 
   0x38 LANG_FAEROESE
191
 
   0x39 LANG_HINDI
192
 
   0x3a LANG_MALTESE
193
 
   0x3b LANG_SAAMI
194
 
   0x3c LANG_GAELIC
195
 
   0x3d LANG_YIDDISH
196
 
   0x3e LANG_MALAY
197
 
   0x3f LANG_KAZAK
198
 
   0x40 LANG_KYRGYZ
199
 
   0x41 LANG_SWAHILI
200
 
   0x42 LANG_TURKMEN
201
 
   0x43 LANG_UZBEK
202
 
   0x44 LANG_TATAR
203
 
   0x45 LANG_BENGALI
204
 
   0x46 LANG_PUNJABI
205
 
   0x47 LANG_GUJARATI
206
 
   0x48 LANG_ORIYA
207
 
   0x49 LANG_TAMIL
208
 
   0x4a LANG_TELUGU
209
 
   0x4b LANG_KANNADA
210
 
   0x4c LANG_MALAYALAM
211
 
   0x4d LANG_ASSAMESE
212
 
   0x4e LANG_MARATHI
213
 
   0x4f LANG_SANSKRIT
214
 
   0x50 LANG_MONGOLIAN
215
 
   0x51 LANG_TIBETAN
216
 
   0x52 LANG_WELSH
217
 
   0x53 LANG_CAMBODIAN
218
 
   0x54 LANG_LAO
219
 
   0x55 LANG_BURMESE
220
 
   0x56 LANG_GALICIAN
221
 
   0x57 LANG_KONKANI
222
 
   0x58 LANG_MANIPURI
223
 
   0x59 LANG_SINDHI
224
 
   0x5a LANG_SYRIAC
225
 
   0x5b LANG_SINHALESE
226
 
   0x5c LANG_CHEROKEE
227
 
   0x5d LANG_INUKTITUT
228
 
   0x5e LANG_AMHARIC
229
 
   0x5f LANG_TAMAZIGHT
230
 
   0x60 LANG_KASHMIRI
231
 
   0x61 LANG_NEPALI
232
 
   0x62 LANG_FRISIAN
233
 
   0x63 LANG_PASHTO
234
 
   0x64 LANG_TAGALOG
235
 
   0x65 LANG_DIVEHI
236
 
   0x66 LANG_EDO
237
 
   0x67 LANG_FULFULDE
238
 
   0x68 LANG_HAUSA
239
 
   0x69 LANG_IBIBIO
240
 
   0x6a LANG_YORUBA
241
 
   0x70 LANG_IGBO
242
 
   0x71 LANG_KANURI
243
 
   0x72 LANG_OROMO
244
 
   0x73 LANG_TIGRINYA
245
 
   0x74 LANG_GUARANI
246
 
   0x75 LANG_HAWAIIAN
247
 
   0x76 LANG_LATIN
248
 
   0x77 LANG_SOMALI
249
 
   0x78 LANG_YI
250
 
   0x79 LANG_PAPIAMENTU
251
 
*/
252
75
/* Mingw headers don't have latest language and sublanguage codes.  */
253
 
# ifndef LANG_AFRIKAANS
254
 
# define LANG_AFRIKAANS 0x36
255
 
# endif
256
 
# ifndef LANG_ALBANIAN
257
 
# define LANG_ALBANIAN 0x1c
258
 
# endif
259
 
# ifndef LANG_AMHARIC
260
 
# define LANG_AMHARIC 0x5e
261
 
# endif
262
 
# ifndef LANG_ARABIC
263
 
# define LANG_ARABIC 0x01
264
 
# endif
265
 
# ifndef LANG_ARMENIAN
266
 
# define LANG_ARMENIAN 0x2b
267
 
# endif
268
 
# ifndef LANG_ASSAMESE
269
 
# define LANG_ASSAMESE 0x4d
270
 
# endif
271
 
# ifndef LANG_AZERI
272
 
# define LANG_AZERI 0x2c
273
 
# endif
274
 
# ifndef LANG_BASQUE
275
 
# define LANG_BASQUE 0x2d
276
 
# endif
277
 
# ifndef LANG_BELARUSIAN
278
 
# define LANG_BELARUSIAN 0x23
279
 
# endif
280
 
# ifndef LANG_BENGALI
281
 
# define LANG_BENGALI 0x45
282
 
# endif
283
 
# ifndef LANG_BURMESE
284
 
# define LANG_BURMESE 0x55
285
 
# endif
286
 
# ifndef LANG_CAMBODIAN
287
 
# define LANG_CAMBODIAN 0x53
288
 
# endif
289
 
# ifndef LANG_CATALAN
290
 
# define LANG_CATALAN 0x03
291
 
# endif
292
 
# ifndef LANG_CHEROKEE
293
 
# define LANG_CHEROKEE 0x5c
294
 
# endif
295
 
# ifndef LANG_DIVEHI
296
 
# define LANG_DIVEHI 0x65
297
 
# endif
298
 
# ifndef LANG_EDO
299
 
# define LANG_EDO 0x66
300
 
# endif
301
 
# ifndef LANG_ESTONIAN
302
 
# define LANG_ESTONIAN 0x25
303
 
# endif
304
 
# ifndef LANG_FAEROESE
305
 
# define LANG_FAEROESE 0x38
306
 
# endif
307
 
# ifndef LANG_FARSI
308
 
# define LANG_FARSI 0x29
309
 
# endif
310
 
# ifndef LANG_FRISIAN
311
 
# define LANG_FRISIAN 0x62
312
 
# endif
313
 
# ifndef LANG_FULFULDE
314
 
# define LANG_FULFULDE 0x67
315
 
# endif
316
 
# ifndef LANG_GAELIC
317
 
# define LANG_GAELIC 0x3c
318
 
# endif
319
 
# ifndef LANG_GALICIAN
320
 
# define LANG_GALICIAN 0x56
321
 
# endif
322
 
# ifndef LANG_GEORGIAN
323
 
# define LANG_GEORGIAN 0x37
324
 
# endif
325
 
# ifndef LANG_GUARANI
326
 
# define LANG_GUARANI 0x74
327
 
# endif
328
 
# ifndef LANG_GUJARATI
329
 
# define LANG_GUJARATI 0x47
330
 
# endif
331
 
# ifndef LANG_HAUSA
332
 
# define LANG_HAUSA 0x68
333
 
# endif
334
 
# ifndef LANG_HAWAIIAN
335
 
# define LANG_HAWAIIAN 0x75
336
 
# endif
337
 
# ifndef LANG_HEBREW
338
 
# define LANG_HEBREW 0x0d
339
 
# endif
340
 
# ifndef LANG_HINDI
341
 
# define LANG_HINDI 0x39
342
 
# endif
343
 
# ifndef LANG_IBIBIO
344
 
# define LANG_IBIBIO 0x69
345
 
# endif
346
 
# ifndef LANG_IGBO
347
 
# define LANG_IGBO 0x70
348
 
# endif
349
 
# ifndef LANG_INDONESIAN
350
 
# define LANG_INDONESIAN 0x21
351
 
# endif
352
 
# ifndef LANG_INUKTITUT
353
 
# define LANG_INUKTITUT 0x5d
354
 
# endif
355
 
# ifndef LANG_KANNADA
356
 
# define LANG_KANNADA 0x4b
357
 
# endif
358
 
# ifndef LANG_KANURI
359
 
# define LANG_KANURI 0x71
360
 
# endif
361
 
# ifndef LANG_KASHMIRI
362
 
# define LANG_KASHMIRI 0x60
363
 
# endif
364
 
# ifndef LANG_KAZAK
365
 
# define LANG_KAZAK 0x3f
366
 
# endif
367
 
# ifndef LANG_KONKANI
368
 
# define LANG_KONKANI 0x57
369
 
# endif
370
 
# ifndef LANG_KYRGYZ
371
 
# define LANG_KYRGYZ 0x40
372
 
# endif
373
 
# ifndef LANG_LAO
374
 
# define LANG_LAO 0x54
375
 
# endif
376
 
# ifndef LANG_LATIN
377
 
# define LANG_LATIN 0x76
378
 
# endif
379
 
# ifndef LANG_LATVIAN
380
 
# define LANG_LATVIAN 0x26
381
 
# endif
382
 
# ifndef LANG_LITHUANIAN
383
 
# define LANG_LITHUANIAN 0x27
384
 
# endif
385
 
# ifndef LANG_MACEDONIAN
386
 
# define LANG_MACEDONIAN 0x2f
387
 
# endif
388
 
# ifndef LANG_MALAY
389
 
# define LANG_MALAY 0x3e
390
 
# endif
391
 
# ifndef LANG_MALAYALAM
392
 
# define LANG_MALAYALAM 0x4c
393
 
# endif
394
 
# ifndef LANG_MALTESE
395
 
# define LANG_MALTESE 0x3a
396
 
# endif
397
 
# ifndef LANG_MANIPURI
398
 
# define LANG_MANIPURI 0x58
399
 
# endif
400
 
# ifndef LANG_MARATHI
401
 
# define LANG_MARATHI 0x4e
402
 
# endif
403
 
# ifndef LANG_MONGOLIAN
404
 
# define LANG_MONGOLIAN 0x50
405
 
# endif
406
 
# ifndef LANG_NEPALI
407
 
# define LANG_NEPALI 0x61
408
 
# endif
409
 
# ifndef LANG_ORIYA
410
 
# define LANG_ORIYA 0x48
411
 
# endif
412
 
# ifndef LANG_OROMO
413
 
# define LANG_OROMO 0x72
414
 
# endif
415
 
# ifndef LANG_PAPIAMENTU
416
 
# define LANG_PAPIAMENTU 0x79
417
 
# endif
418
 
# ifndef LANG_PASHTO
419
 
# define LANG_PASHTO 0x63
420
 
# endif
421
 
# ifndef LANG_PUNJABI
422
 
# define LANG_PUNJABI 0x46
423
 
# endif
424
 
# ifndef LANG_RHAETO_ROMANCE
425
 
# define LANG_RHAETO_ROMANCE 0x17
426
 
# endif
427
 
# ifndef LANG_SAAMI
428
 
# define LANG_SAAMI 0x3b
429
 
# endif
430
 
# ifndef LANG_SANSKRIT
431
 
# define LANG_SANSKRIT 0x4f
432
 
# endif
433
 
# ifndef LANG_SERBIAN
434
 
# define LANG_SERBIAN 0x1a
435
 
# endif
436
 
# ifndef LANG_SINDHI
437
 
# define LANG_SINDHI 0x59
438
 
# endif
439
 
# ifndef LANG_SINHALESE
440
 
# define LANG_SINHALESE 0x5b
441
 
# endif
442
 
# ifndef LANG_SLOVAK
443
 
# define LANG_SLOVAK 0x1b
444
 
# endif
445
 
# ifndef LANG_SOMALI
446
 
# define LANG_SOMALI 0x77
447
 
# endif
448
 
# ifndef LANG_SORBIAN
449
 
# define LANG_SORBIAN 0x2e
450
 
# endif
451
 
# ifndef LANG_SUTU
452
 
# define LANG_SUTU 0x30
453
 
# endif
454
 
# ifndef LANG_SWAHILI
455
 
# define LANG_SWAHILI 0x41
456
 
# endif
457
 
# ifndef LANG_SYRIAC
458
 
# define LANG_SYRIAC 0x5a
459
 
# endif
460
 
# ifndef LANG_TAGALOG
461
 
# define LANG_TAGALOG 0x64
462
 
# endif
463
 
# ifndef LANG_TAJIK
464
 
# define LANG_TAJIK 0x28
465
 
# endif
466
 
# ifndef LANG_TAMAZIGHT
467
 
# define LANG_TAMAZIGHT 0x5f
468
 
# endif
469
 
# ifndef LANG_TAMIL
470
 
# define LANG_TAMIL 0x49
471
 
# endif
472
 
# ifndef LANG_TATAR
473
 
# define LANG_TATAR 0x44
474
 
# endif
475
 
# ifndef LANG_TELUGU
476
 
# define LANG_TELUGU 0x4a
477
 
# endif
478
 
# ifndef LANG_THAI
479
 
# define LANG_THAI 0x1e
480
 
# endif
481
 
# ifndef LANG_TIBETAN
482
 
# define LANG_TIBETAN 0x51
483
 
# endif
484
 
# ifndef LANG_TIGRINYA
485
 
# define LANG_TIGRINYA 0x73
486
 
# endif
487
 
# ifndef LANG_TSONGA
488
 
# define LANG_TSONGA 0x31
489
 
# endif
490
 
# ifndef LANG_TSWANA
491
 
# define LANG_TSWANA 0x32
492
 
# endif
493
 
# ifndef LANG_TURKMEN
494
 
# define LANG_TURKMEN 0x42
495
 
# endif
496
 
# ifndef LANG_UKRAINIAN
497
 
# define LANG_UKRAINIAN 0x22
498
 
# endif
499
 
# ifndef LANG_URDU
500
 
# define LANG_URDU 0x20
501
 
# endif
502
 
# ifndef LANG_UZBEK
503
 
# define LANG_UZBEK 0x43
504
 
# endif
505
 
# ifndef LANG_VENDA
506
 
# define LANG_VENDA 0x33
507
 
# endif
508
 
# ifndef LANG_VIETNAMESE
509
 
# define LANG_VIETNAMESE 0x2a
510
 
# endif
511
 
# ifndef LANG_WELSH
512
 
# define LANG_WELSH 0x52
513
 
# endif
514
 
# ifndef LANG_XHOSA
515
 
# define LANG_XHOSA 0x34
516
 
# endif
517
 
# ifndef LANG_YI
518
 
# define LANG_YI 0x78
519
 
# endif
520
 
# ifndef LANG_YIDDISH
521
 
# define LANG_YIDDISH 0x3d
522
 
# endif
523
 
# ifndef LANG_YORUBA
524
 
# define LANG_YORUBA 0x6a
525
 
# endif
526
 
# ifndef LANG_ZULU
527
 
# define LANG_ZULU 0x35
528
 
# endif
529
 
# ifndef SUBLANG_ARABIC_SAUDI_ARABIA
530
 
# define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
531
 
# endif
532
 
# ifndef SUBLANG_ARABIC_IRAQ
533
 
# define SUBLANG_ARABIC_IRAQ 0x02
534
 
# endif
535
 
# ifndef SUBLANG_ARABIC_EGYPT
536
 
# define SUBLANG_ARABIC_EGYPT 0x03
537
 
# endif
538
 
# ifndef SUBLANG_ARABIC_LIBYA
539
 
# define SUBLANG_ARABIC_LIBYA 0x04
540
 
# endif
541
 
# ifndef SUBLANG_ARABIC_ALGERIA
542
 
# define SUBLANG_ARABIC_ALGERIA 0x05
543
 
# endif
544
 
# ifndef SUBLANG_ARABIC_MOROCCO
545
 
# define SUBLANG_ARABIC_MOROCCO 0x06
546
 
# endif
547
 
# ifndef SUBLANG_ARABIC_TUNISIA
548
 
# define SUBLANG_ARABIC_TUNISIA 0x07
549
 
# endif
550
 
# ifndef SUBLANG_ARABIC_OMAN
551
 
# define SUBLANG_ARABIC_OMAN 0x08
552
 
# endif
553
 
# ifndef SUBLANG_ARABIC_YEMEN
554
 
# define SUBLANG_ARABIC_YEMEN 0x09
555
 
# endif
556
 
# ifndef SUBLANG_ARABIC_SYRIA
557
 
# define SUBLANG_ARABIC_SYRIA 0x0a
558
 
# endif
559
 
# ifndef SUBLANG_ARABIC_JORDAN
560
 
# define SUBLANG_ARABIC_JORDAN 0x0b
561
 
# endif
562
 
# ifndef SUBLANG_ARABIC_LEBANON
563
 
# define SUBLANG_ARABIC_LEBANON 0x0c
564
 
# endif
565
 
# ifndef SUBLANG_ARABIC_KUWAIT
566
 
# define SUBLANG_ARABIC_KUWAIT 0x0d
567
 
# endif
568
 
# ifndef SUBLANG_ARABIC_UAE
569
 
# define SUBLANG_ARABIC_UAE 0x0e
570
 
# endif
571
 
# ifndef SUBLANG_ARABIC_BAHRAIN
572
 
# define SUBLANG_ARABIC_BAHRAIN 0x0f
573
 
# endif
574
 
# ifndef SUBLANG_ARABIC_QATAR
575
 
# define SUBLANG_ARABIC_QATAR 0x10
576
 
# endif
577
 
# ifndef SUBLANG_AZERI_LATIN
578
 
# define SUBLANG_AZERI_LATIN 0x01
579
 
# endif
580
 
# ifndef SUBLANG_AZERI_CYRILLIC
581
 
# define SUBLANG_AZERI_CYRILLIC 0x02
582
 
# endif
583
 
# ifndef SUBLANG_BENGALI_INDIA
584
 
# define SUBLANG_BENGALI_INDIA 0x01
585
 
# endif
586
 
# ifndef SUBLANG_BENGALI_BANGLADESH
587
 
# define SUBLANG_BENGALI_BANGLADESH 0x02
588
 
# endif
589
 
# ifndef SUBLANG_CHINESE_MACAU
590
 
# define SUBLANG_CHINESE_MACAU 0x05
591
 
# endif
592
 
# ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
593
 
# define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
594
 
# endif
595
 
# ifndef SUBLANG_ENGLISH_JAMAICA
596
 
# define SUBLANG_ENGLISH_JAMAICA 0x08
597
 
# endif
598
 
# ifndef SUBLANG_ENGLISH_CARIBBEAN
599
 
# define SUBLANG_ENGLISH_CARIBBEAN 0x09
600
 
# endif
601
 
# ifndef SUBLANG_ENGLISH_BELIZE
602
 
# define SUBLANG_ENGLISH_BELIZE 0x0a
603
 
# endif
604
 
# ifndef SUBLANG_ENGLISH_TRINIDAD
605
 
# define SUBLANG_ENGLISH_TRINIDAD 0x0b
606
 
# endif
607
 
# ifndef SUBLANG_ENGLISH_ZIMBABWE
608
 
# define SUBLANG_ENGLISH_ZIMBABWE 0x0c
609
 
# endif
610
 
# ifndef SUBLANG_ENGLISH_PHILIPPINES
611
 
# define SUBLANG_ENGLISH_PHILIPPINES 0x0d
612
 
# endif
613
 
# ifndef SUBLANG_ENGLISH_INDONESIA
614
 
# define SUBLANG_ENGLISH_INDONESIA 0x0e
615
 
# endif
616
 
# ifndef SUBLANG_ENGLISH_HONGKONG
617
 
# define SUBLANG_ENGLISH_HONGKONG 0x0f
618
 
# endif
619
 
# ifndef SUBLANG_ENGLISH_INDIA
620
 
# define SUBLANG_ENGLISH_INDIA 0x10
621
 
# endif
622
 
# ifndef SUBLANG_ENGLISH_MALAYSIA
623
 
# define SUBLANG_ENGLISH_MALAYSIA 0x11
624
 
# endif
625
 
# ifndef SUBLANG_ENGLISH_SINGAPORE
626
 
# define SUBLANG_ENGLISH_SINGAPORE 0x12
627
 
# endif
628
 
# ifndef SUBLANG_FRENCH_LUXEMBOURG
629
 
# define SUBLANG_FRENCH_LUXEMBOURG 0x05
630
 
# endif
631
 
# ifndef SUBLANG_FRENCH_MONACO
632
 
# define SUBLANG_FRENCH_MONACO 0x06
633
 
# endif
634
 
# ifndef SUBLANG_FRENCH_WESTINDIES
635
 
# define SUBLANG_FRENCH_WESTINDIES 0x07
636
 
# endif
637
 
# ifndef SUBLANG_FRENCH_REUNION
638
 
# define SUBLANG_FRENCH_REUNION 0x08
639
 
# endif
640
 
# ifndef SUBLANG_FRENCH_CONGO
641
 
# define SUBLANG_FRENCH_CONGO 0x09
642
 
# endif
643
 
# ifndef SUBLANG_FRENCH_SENEGAL
644
 
# define SUBLANG_FRENCH_SENEGAL 0x0a
645
 
# endif
646
 
# ifndef SUBLANG_FRENCH_CAMEROON
647
 
# define SUBLANG_FRENCH_CAMEROON 0x0b
648
 
# endif
649
 
# ifndef SUBLANG_FRENCH_COTEDIVOIRE
650
 
# define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
651
 
# endif
652
 
# ifndef SUBLANG_FRENCH_MALI
653
 
# define SUBLANG_FRENCH_MALI 0x0d
654
 
# endif
655
 
# ifndef SUBLANG_FRENCH_MOROCCO
656
 
# define SUBLANG_FRENCH_MOROCCO 0x0e
657
 
# endif
658
 
# ifndef SUBLANG_FRENCH_HAITI
659
 
# define SUBLANG_FRENCH_HAITI 0x0f
660
 
# endif
661
 
# ifndef SUBLANG_GERMAN_LUXEMBOURG
662
 
# define SUBLANG_GERMAN_LUXEMBOURG 0x04
663
 
# endif
664
 
# ifndef SUBLANG_GERMAN_LIECHTENSTEIN
665
 
# define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
666
 
# endif
667
 
# ifndef SUBLANG_KASHMIRI_INDIA
668
 
# define SUBLANG_KASHMIRI_INDIA 0x02
669
 
# endif
670
 
# ifndef SUBLANG_MALAY_MALAYSIA
671
 
# define SUBLANG_MALAY_MALAYSIA 0x01
672
 
# endif
673
 
# ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
674
 
# define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
675
 
# endif
676
 
# ifndef SUBLANG_NEPALI_INDIA
677
 
# define SUBLANG_NEPALI_INDIA 0x02
678
 
# endif
679
 
# ifndef SUBLANG_PUNJABI_INDIA
680
 
# define SUBLANG_PUNJABI_INDIA 0x01
681
 
# endif
682
 
# ifndef SUBLANG_ROMANIAN_ROMANIA
683
 
# define SUBLANG_ROMANIAN_ROMANIA 0x01
684
 
# endif
685
 
# ifndef SUBLANG_SERBIAN_LATIN
686
 
# define SUBLANG_SERBIAN_LATIN 0x02
687
 
# endif
688
 
# ifndef SUBLANG_SERBIAN_CYRILLIC
689
 
# define SUBLANG_SERBIAN_CYRILLIC 0x03
690
 
# endif
691
 
# ifndef SUBLANG_SINDHI_INDIA
692
 
# define SUBLANG_SINDHI_INDIA 0x00
693
 
# endif
694
 
# ifndef SUBLANG_SINDHI_PAKISTAN
695
 
# define SUBLANG_SINDHI_PAKISTAN 0x01
696
 
# endif
697
 
# ifndef SUBLANG_SPANISH_GUATEMALA
698
 
# define SUBLANG_SPANISH_GUATEMALA 0x04
699
 
# endif
700
 
# ifndef SUBLANG_SPANISH_COSTA_RICA
701
 
# define SUBLANG_SPANISH_COSTA_RICA 0x05
702
 
# endif
703
 
# ifndef SUBLANG_SPANISH_PANAMA
704
 
# define SUBLANG_SPANISH_PANAMA 0x06
705
 
# endif
706
 
# ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
707
 
# define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
708
 
# endif
709
 
# ifndef SUBLANG_SPANISH_VENEZUELA
710
 
# define SUBLANG_SPANISH_VENEZUELA 0x08
711
 
# endif
712
 
# ifndef SUBLANG_SPANISH_COLOMBIA
713
 
# define SUBLANG_SPANISH_COLOMBIA 0x09
714
 
# endif
715
 
# ifndef SUBLANG_SPANISH_PERU
716
 
# define SUBLANG_SPANISH_PERU 0x0a
717
 
# endif
718
 
# ifndef SUBLANG_SPANISH_ARGENTINA
719
 
# define SUBLANG_SPANISH_ARGENTINA 0x0b
720
 
# endif
721
 
# ifndef SUBLANG_SPANISH_ECUADOR
722
 
# define SUBLANG_SPANISH_ECUADOR 0x0c
723
 
# endif
724
 
# ifndef SUBLANG_SPANISH_CHILE
725
 
# define SUBLANG_SPANISH_CHILE 0x0d
726
 
# endif
727
 
# ifndef SUBLANG_SPANISH_URUGUAY
728
 
# define SUBLANG_SPANISH_URUGUAY 0x0e
729
 
# endif
730
 
# ifndef SUBLANG_SPANISH_PARAGUAY
731
 
# define SUBLANG_SPANISH_PARAGUAY 0x0f
732
 
# endif
733
 
# ifndef SUBLANG_SPANISH_BOLIVIA
734
 
# define SUBLANG_SPANISH_BOLIVIA 0x10
735
 
# endif
736
 
# ifndef SUBLANG_SPANISH_EL_SALVADOR
737
 
# define SUBLANG_SPANISH_EL_SALVADOR 0x11
738
 
# endif
739
 
# ifndef SUBLANG_SPANISH_HONDURAS
740
 
# define SUBLANG_SPANISH_HONDURAS 0x12
741
 
# endif
742
 
# ifndef SUBLANG_SPANISH_NICARAGUA
743
 
# define SUBLANG_SPANISH_NICARAGUA 0x13
744
 
# endif
745
 
# ifndef SUBLANG_SPANISH_PUERTO_RICO
746
 
# define SUBLANG_SPANISH_PUERTO_RICO 0x14
747
 
# endif
748
 
# ifndef SUBLANG_SWEDISH_FINLAND
749
 
# define SUBLANG_SWEDISH_FINLAND 0x02
750
 
# endif
751
 
# ifndef SUBLANG_TAMAZIGHT_ARABIC
752
 
# define SUBLANG_TAMAZIGHT_ARABIC 0x01
753
 
# endif
754
 
# ifndef SUBLANG_TAMAZIGHT_LATIN
755
 
# define SUBLANG_TAMAZIGHT_LATIN 0x02
756
 
# endif
757
 
# ifndef SUBLANG_TIGRINYA_ETHIOPIA
758
 
# define SUBLANG_TIGRINYA_ETHIOPIA 0x00
759
 
# endif
760
 
# ifndef SUBLANG_TIGRINYA_ERITREA
761
 
# define SUBLANG_TIGRINYA_ERITREA 0x01
762
 
# endif
763
 
# ifndef SUBLANG_URDU_PAKISTAN
764
 
# define SUBLANG_URDU_PAKISTAN 0x01
765
 
# endif
766
 
# ifndef SUBLANG_URDU_INDIA
767
 
# define SUBLANG_URDU_INDIA 0x02
768
 
# endif
769
 
# ifndef SUBLANG_UZBEK_LATIN
770
 
# define SUBLANG_UZBEK_LATIN 0x01
771
 
# endif
772
 
# ifndef SUBLANG_UZBEK_CYRILLIC
773
 
# define SUBLANG_UZBEK_CYRILLIC 0x02
774
 
# endif
775
 
 
776
 
 
777
 
/* Return an XPG style locale name language[_territory][@modifier].
 
76
#ifndef LANG_AFRIKAANS
 
77
#define LANG_AFRIKAANS 0x36
 
78
#endif
 
79
#ifndef LANG_ALBANIAN
 
80
#define LANG_ALBANIAN 0x1c
 
81
#endif
 
82
#ifndef LANG_AMHARIC
 
83
#define LANG_AMHARIC 0x5e
 
84
#endif
 
85
#ifndef LANG_ARABIC
 
86
#define LANG_ARABIC 0x01
 
87
#endif
 
88
#ifndef LANG_ARMENIAN
 
89
#define LANG_ARMENIAN 0x2b
 
90
#endif
 
91
#ifndef LANG_ASSAMESE
 
92
#define LANG_ASSAMESE 0x4d
 
93
#endif
 
94
#ifndef LANG_AZERI
 
95
#define LANG_AZERI 0x2c
 
96
#endif
 
97
#ifndef LANG_BASQUE
 
98
#define LANG_BASQUE 0x2d
 
99
#endif
 
100
#ifndef LANG_BELARUSIAN
 
101
#define LANG_BELARUSIAN 0x23
 
102
#endif
 
103
#ifndef LANG_BENGALI
 
104
#define LANG_BENGALI 0x45
 
105
#endif
 
106
#ifndef LANG_BURMESE
 
107
#define LANG_BURMESE 0x55
 
108
#endif
 
109
#ifndef LANG_CAMBODIAN
 
110
#define LANG_CAMBODIAN 0x53
 
111
#endif
 
112
#ifndef LANG_CATALAN
 
113
#define LANG_CATALAN 0x03
 
114
#endif
 
115
#ifndef LANG_CHEROKEE
 
116
#define LANG_CHEROKEE 0x5c
 
117
#endif
 
118
#ifndef LANG_DIVEHI
 
119
#define LANG_DIVEHI 0x65
 
120
#endif
 
121
#ifndef LANG_EDO
 
122
#define LANG_EDO 0x66
 
123
#endif
 
124
#ifndef LANG_ESTONIAN
 
125
#define LANG_ESTONIAN 0x25
 
126
#endif
 
127
#ifndef LANG_FAEROESE
 
128
#define LANG_FAEROESE 0x38
 
129
#endif
 
130
#ifndef LANG_FARSI
 
131
#define LANG_FARSI 0x29
 
132
#endif
 
133
#ifndef LANG_FRISIAN
 
134
#define LANG_FRISIAN 0x62
 
135
#endif
 
136
#ifndef LANG_FULFULDE
 
137
#define LANG_FULFULDE 0x67
 
138
#endif
 
139
#ifndef LANG_GAELIC
 
140
#define LANG_GAELIC 0x3c
 
141
#endif
 
142
#ifndef LANG_GALICIAN
 
143
#define LANG_GALICIAN 0x56
 
144
#endif
 
145
#ifndef LANG_GEORGIAN
 
146
#define LANG_GEORGIAN 0x37
 
147
#endif
 
148
#ifndef LANG_GUARANI
 
149
#define LANG_GUARANI 0x74
 
150
#endif
 
151
#ifndef LANG_GUJARATI
 
152
#define LANG_GUJARATI 0x47
 
153
#endif
 
154
#ifndef LANG_HAUSA
 
155
#define LANG_HAUSA 0x68
 
156
#endif
 
157
#ifndef LANG_HAWAIIAN
 
158
#define LANG_HAWAIIAN 0x75
 
159
#endif
 
160
#ifndef LANG_HEBREW
 
161
#define LANG_HEBREW 0x0d
 
162
#endif
 
163
#ifndef LANG_HINDI
 
164
#define LANG_HINDI 0x39
 
165
#endif
 
166
#ifndef LANG_IBIBIO
 
167
#define LANG_IBIBIO 0x69
 
168
#endif
 
169
#ifndef LANG_IGBO
 
170
#define LANG_IGBO 0x70
 
171
#endif
 
172
#ifndef LANG_INDONESIAN
 
173
#define LANG_INDONESIAN 0x21
 
174
#endif
 
175
#ifndef LANG_INUKTITUT
 
176
#define LANG_INUKTITUT 0x5d
 
177
#endif
 
178
#ifndef LANG_KANNADA
 
179
#define LANG_KANNADA 0x4b
 
180
#endif
 
181
#ifndef LANG_KANURI
 
182
#define LANG_KANURI 0x71
 
183
#endif
 
184
#ifndef LANG_KASHMIRI
 
185
#define LANG_KASHMIRI 0x60
 
186
#endif
 
187
#ifndef LANG_KAZAK
 
188
#define LANG_KAZAK 0x3f
 
189
#endif
 
190
#ifndef LANG_KONKANI
 
191
#define LANG_KONKANI 0x57
 
192
#endif
 
193
#ifndef LANG_KYRGYZ
 
194
#define LANG_KYRGYZ 0x40
 
195
#endif
 
196
#ifndef LANG_LAO
 
197
#define LANG_LAO 0x54
 
198
#endif
 
199
#ifndef LANG_LATIN
 
200
#define LANG_LATIN 0x76
 
201
#endif
 
202
#ifndef LANG_LATVIAN
 
203
#define LANG_LATVIAN 0x26
 
204
#endif
 
205
#ifndef LANG_LITHUANIAN
 
206
#define LANG_LITHUANIAN 0x27
 
207
#endif
 
208
#ifndef LANG_MACEDONIAN
 
209
#define LANG_MACEDONIAN 0x2f
 
210
#endif
 
211
#ifndef LANG_MALAY
 
212
#define LANG_MALAY 0x3e
 
213
#endif
 
214
#ifndef LANG_MALAYALAM
 
215
#define LANG_MALAYALAM 0x4c
 
216
#endif
 
217
#ifndef LANG_MALTESE
 
218
#define LANG_MALTESE 0x3a
 
219
#endif
 
220
#ifndef LANG_MANIPURI
 
221
#define LANG_MANIPURI 0x58
 
222
#endif
 
223
#ifndef LANG_MARATHI
 
224
#define LANG_MARATHI 0x4e
 
225
#endif
 
226
#ifndef LANG_MONGOLIAN
 
227
#define LANG_MONGOLIAN 0x50
 
228
#endif
 
229
#ifndef LANG_NEPALI
 
230
#define LANG_NEPALI 0x61
 
231
#endif
 
232
#ifndef LANG_ORIYA
 
233
#define LANG_ORIYA 0x48
 
234
#endif
 
235
#ifndef LANG_OROMO
 
236
#define LANG_OROMO 0x72
 
237
#endif
 
238
#ifndef LANG_PAPIAMENTU
 
239
#define LANG_PAPIAMENTU 0x79
 
240
#endif
 
241
#ifndef LANG_PASHTO
 
242
#define LANG_PASHTO 0x63
 
243
#endif
 
244
#ifndef LANG_PUNJABI
 
245
#define LANG_PUNJABI 0x46
 
246
#endif
 
247
#ifndef LANG_RHAETO_ROMANCE
 
248
#define LANG_RHAETO_ROMANCE 0x17
 
249
#endif
 
250
#ifndef LANG_SAAMI
 
251
#define LANG_SAAMI 0x3b
 
252
#endif
 
253
#ifndef LANG_SANSKRIT
 
254
#define LANG_SANSKRIT 0x4f
 
255
#endif
 
256
#ifndef LANG_SERBIAN
 
257
#define LANG_SERBIAN 0x1a
 
258
#endif
 
259
#ifndef LANG_SINDHI
 
260
#define LANG_SINDHI 0x59
 
261
#endif
 
262
#ifndef LANG_SINHALESE
 
263
#define LANG_SINHALESE 0x5b
 
264
#endif
 
265
#ifndef LANG_SLOVAK
 
266
#define LANG_SLOVAK 0x1b
 
267
#endif
 
268
#ifndef LANG_SOMALI
 
269
#define LANG_SOMALI 0x77
 
270
#endif
 
271
#ifndef LANG_SORBIAN
 
272
#define LANG_SORBIAN 0x2e
 
273
#endif
 
274
#ifndef LANG_SUTU
 
275
#define LANG_SUTU 0x30
 
276
#endif
 
277
#ifndef LANG_SWAHILI
 
278
#define LANG_SWAHILI 0x41
 
279
#endif
 
280
#ifndef LANG_SYRIAC
 
281
#define LANG_SYRIAC 0x5a
 
282
#endif
 
283
#ifndef LANG_TAGALOG
 
284
#define LANG_TAGALOG 0x64
 
285
#endif
 
286
#ifndef LANG_TAJIK
 
287
#define LANG_TAJIK 0x28
 
288
#endif
 
289
#ifndef LANG_TAMAZIGHT
 
290
#define LANG_TAMAZIGHT 0x5f
 
291
#endif
 
292
#ifndef LANG_TAMIL
 
293
#define LANG_TAMIL 0x49
 
294
#endif
 
295
#ifndef LANG_TATAR
 
296
#define LANG_TATAR 0x44
 
297
#endif
 
298
#ifndef LANG_TELUGU
 
299
#define LANG_TELUGU 0x4a
 
300
#endif
 
301
#ifndef LANG_THAI
 
302
#define LANG_THAI 0x1e
 
303
#endif
 
304
#ifndef LANG_TIBETAN
 
305
#define LANG_TIBETAN 0x51
 
306
#endif
 
307
#ifndef LANG_TIGRINYA
 
308
#define LANG_TIGRINYA 0x73
 
309
#endif
 
310
#ifndef LANG_TSONGA
 
311
#define LANG_TSONGA 0x31
 
312
#endif
 
313
#ifndef LANG_TSWANA
 
314
#define LANG_TSWANA 0x32
 
315
#endif
 
316
#ifndef LANG_TURKMEN
 
317
#define LANG_TURKMEN 0x42
 
318
#endif
 
319
#ifndef LANG_UKRAINIAN
 
320
#define LANG_UKRAINIAN 0x22
 
321
#endif
 
322
#ifndef LANG_URDU
 
323
#define LANG_URDU 0x20
 
324
#endif
 
325
#ifndef LANG_UZBEK
 
326
#define LANG_UZBEK 0x43
 
327
#endif
 
328
#ifndef LANG_VENDA
 
329
#define LANG_VENDA 0x33
 
330
#endif
 
331
#ifndef LANG_VIETNAMESE
 
332
#define LANG_VIETNAMESE 0x2a
 
333
#endif
 
334
#ifndef LANG_WELSH
 
335
#define LANG_WELSH 0x52
 
336
#endif
 
337
#ifndef LANG_XHOSA
 
338
#define LANG_XHOSA 0x34
 
339
#endif
 
340
#ifndef LANG_YI
 
341
#define LANG_YI 0x78
 
342
#endif
 
343
#ifndef LANG_YIDDISH
 
344
#define LANG_YIDDISH 0x3d
 
345
#endif
 
346
#ifndef LANG_YORUBA
 
347
#define LANG_YORUBA 0x6a
 
348
#endif
 
349
#ifndef LANG_ZULU
 
350
#define LANG_ZULU 0x35
 
351
#endif
 
352
#ifndef SUBLANG_ARABIC_SAUDI_ARABIA
 
353
#define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
 
354
#endif
 
355
#ifndef SUBLANG_ARABIC_IRAQ
 
356
#define SUBLANG_ARABIC_IRAQ 0x02
 
357
#endif
 
358
#ifndef SUBLANG_ARABIC_EGYPT
 
359
#define SUBLANG_ARABIC_EGYPT 0x03
 
360
#endif
 
361
#ifndef SUBLANG_ARABIC_LIBYA
 
362
#define SUBLANG_ARABIC_LIBYA 0x04
 
363
#endif
 
364
#ifndef SUBLANG_ARABIC_ALGERIA
 
365
#define SUBLANG_ARABIC_ALGERIA 0x05
 
366
#endif
 
367
#ifndef SUBLANG_ARABIC_MOROCCO
 
368
#define SUBLANG_ARABIC_MOROCCO 0x06
 
369
#endif
 
370
#ifndef SUBLANG_ARABIC_TUNISIA
 
371
#define SUBLANG_ARABIC_TUNISIA 0x07
 
372
#endif
 
373
#ifndef SUBLANG_ARABIC_OMAN
 
374
#define SUBLANG_ARABIC_OMAN 0x08
 
375
#endif
 
376
#ifndef SUBLANG_ARABIC_YEMEN
 
377
#define SUBLANG_ARABIC_YEMEN 0x09
 
378
#endif
 
379
#ifndef SUBLANG_ARABIC_SYRIA
 
380
#define SUBLANG_ARABIC_SYRIA 0x0a
 
381
#endif
 
382
#ifndef SUBLANG_ARABIC_JORDAN
 
383
#define SUBLANG_ARABIC_JORDAN 0x0b
 
384
#endif
 
385
#ifndef SUBLANG_ARABIC_LEBANON
 
386
#define SUBLANG_ARABIC_LEBANON 0x0c
 
387
#endif
 
388
#ifndef SUBLANG_ARABIC_KUWAIT
 
389
#define SUBLANG_ARABIC_KUWAIT 0x0d
 
390
#endif
 
391
#ifndef SUBLANG_ARABIC_UAE
 
392
#define SUBLANG_ARABIC_UAE 0x0e
 
393
#endif
 
394
#ifndef SUBLANG_ARABIC_BAHRAIN
 
395
#define SUBLANG_ARABIC_BAHRAIN 0x0f
 
396
#endif
 
397
#ifndef SUBLANG_ARABIC_QATAR
 
398
#define SUBLANG_ARABIC_QATAR 0x10
 
399
#endif
 
400
#ifndef SUBLANG_AZERI_LATIN
 
401
#define SUBLANG_AZERI_LATIN 0x01
 
402
#endif
 
403
#ifndef SUBLANG_AZERI_CYRILLIC
 
404
#define SUBLANG_AZERI_CYRILLIC 0x02
 
405
#endif
 
406
#ifndef SUBLANG_BENGALI_INDIA
 
407
#define SUBLANG_BENGALI_INDIA 0x01
 
408
#endif
 
409
#ifndef SUBLANG_BENGALI_BANGLADESH
 
410
#define SUBLANG_BENGALI_BANGLADESH 0x02
 
411
#endif
 
412
#ifndef SUBLANG_CHINESE_MACAU
 
413
#define SUBLANG_CHINESE_MACAU 0x05
 
414
#endif
 
415
#ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
 
416
#define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
 
417
#endif
 
418
#ifndef SUBLANG_ENGLISH_JAMAICA
 
419
#define SUBLANG_ENGLISH_JAMAICA 0x08
 
420
#endif
 
421
#ifndef SUBLANG_ENGLISH_CARIBBEAN
 
422
#define SUBLANG_ENGLISH_CARIBBEAN 0x09
 
423
#endif
 
424
#ifndef SUBLANG_ENGLISH_BELIZE
 
425
#define SUBLANG_ENGLISH_BELIZE 0x0a
 
426
#endif
 
427
#ifndef SUBLANG_ENGLISH_TRINIDAD
 
428
#define SUBLANG_ENGLISH_TRINIDAD 0x0b
 
429
#endif
 
430
#ifndef SUBLANG_ENGLISH_ZIMBABWE
 
431
#define SUBLANG_ENGLISH_ZIMBABWE 0x0c
 
432
#endif
 
433
#ifndef SUBLANG_ENGLISH_PHILIPPINES
 
434
#define SUBLANG_ENGLISH_PHILIPPINES 0x0d
 
435
#endif
 
436
#ifndef SUBLANG_ENGLISH_INDONESIA
 
437
#define SUBLANG_ENGLISH_INDONESIA 0x0e
 
438
#endif
 
439
#ifndef SUBLANG_ENGLISH_HONGKONG
 
440
#define SUBLANG_ENGLISH_HONGKONG 0x0f
 
441
#endif
 
442
#ifndef SUBLANG_ENGLISH_INDIA
 
443
#define SUBLANG_ENGLISH_INDIA 0x10
 
444
#endif
 
445
#ifndef SUBLANG_ENGLISH_MALAYSIA
 
446
#define SUBLANG_ENGLISH_MALAYSIA 0x11
 
447
#endif
 
448
#ifndef SUBLANG_ENGLISH_SINGAPORE
 
449
#define SUBLANG_ENGLISH_SINGAPORE 0x12
 
450
#endif
 
451
#ifndef SUBLANG_FRENCH_LUXEMBOURG
 
452
#define SUBLANG_FRENCH_LUXEMBOURG 0x05
 
453
#endif
 
454
#ifndef SUBLANG_FRENCH_MONACO
 
455
#define SUBLANG_FRENCH_MONACO 0x06
 
456
#endif
 
457
#ifndef SUBLANG_FRENCH_WESTINDIES
 
458
#define SUBLANG_FRENCH_WESTINDIES 0x07
 
459
#endif
 
460
#ifndef SUBLANG_FRENCH_REUNION
 
461
#define SUBLANG_FRENCH_REUNION 0x08
 
462
#endif
 
463
#ifndef SUBLANG_FRENCH_CONGO
 
464
#define SUBLANG_FRENCH_CONGO 0x09
 
465
#endif
 
466
#ifndef SUBLANG_FRENCH_SENEGAL
 
467
#define SUBLANG_FRENCH_SENEGAL 0x0a
 
468
#endif
 
469
#ifndef SUBLANG_FRENCH_CAMEROON
 
470
#define SUBLANG_FRENCH_CAMEROON 0x0b
 
471
#endif
 
472
#ifndef SUBLANG_FRENCH_COTEDIVOIRE
 
473
#define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
 
474
#endif
 
475
#ifndef SUBLANG_FRENCH_MALI
 
476
#define SUBLANG_FRENCH_MALI 0x0d
 
477
#endif
 
478
#ifndef SUBLANG_FRENCH_MOROCCO
 
479
#define SUBLANG_FRENCH_MOROCCO 0x0e
 
480
#endif
 
481
#ifndef SUBLANG_FRENCH_HAITI
 
482
#define SUBLANG_FRENCH_HAITI 0x0f
 
483
#endif
 
484
#ifndef SUBLANG_GERMAN_LUXEMBOURG
 
485
#define SUBLANG_GERMAN_LUXEMBOURG 0x04
 
486
#endif
 
487
#ifndef SUBLANG_GERMAN_LIECHTENSTEIN
 
488
#define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
 
489
#endif
 
490
#ifndef SUBLANG_KASHMIRI_INDIA
 
491
#define SUBLANG_KASHMIRI_INDIA 0x02
 
492
#endif
 
493
#ifndef SUBLANG_MALAY_MALAYSIA
 
494
#define SUBLANG_MALAY_MALAYSIA 0x01
 
495
#endif
 
496
#ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
 
497
#define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
 
498
#endif
 
499
#ifndef SUBLANG_NEPALI_INDIA
 
500
#define SUBLANG_NEPALI_INDIA 0x02
 
501
#endif
 
502
#ifndef SUBLANG_PUNJABI_INDIA
 
503
#define SUBLANG_PUNJABI_INDIA 0x01
 
504
#endif
 
505
#ifndef SUBLANG_ROMANIAN_ROMANIA
 
506
#define SUBLANG_ROMANIAN_ROMANIA 0x01
 
507
#endif
 
508
#ifndef SUBLANG_SERBIAN_LATIN
 
509
#define SUBLANG_SERBIAN_LATIN 0x02
 
510
#endif
 
511
#ifndef SUBLANG_SERBIAN_CYRILLIC
 
512
#define SUBLANG_SERBIAN_CYRILLIC 0x03
 
513
#endif
 
514
#ifndef SUBLANG_SINDHI_INDIA
 
515
#define SUBLANG_SINDHI_INDIA 0x00
 
516
#endif
 
517
#ifndef SUBLANG_SINDHI_PAKISTAN
 
518
#define SUBLANG_SINDHI_PAKISTAN 0x01
 
519
#endif
 
520
#ifndef SUBLANG_SPANISH_GUATEMALA
 
521
#define SUBLANG_SPANISH_GUATEMALA 0x04
 
522
#endif
 
523
#ifndef SUBLANG_SPANISH_COSTA_RICA
 
524
#define SUBLANG_SPANISH_COSTA_RICA 0x05
 
525
#endif
 
526
#ifndef SUBLANG_SPANISH_PANAMA
 
527
#define SUBLANG_SPANISH_PANAMA 0x06
 
528
#endif
 
529
#ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
 
530
#define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
 
531
#endif
 
532
#ifndef SUBLANG_SPANISH_VENEZUELA
 
533
#define SUBLANG_SPANISH_VENEZUELA 0x08
 
534
#endif
 
535
#ifndef SUBLANG_SPANISH_COLOMBIA
 
536
#define SUBLANG_SPANISH_COLOMBIA 0x09
 
537
#endif
 
538
#ifndef SUBLANG_SPANISH_PERU
 
539
#define SUBLANG_SPANISH_PERU 0x0a
 
540
#endif
 
541
#ifndef SUBLANG_SPANISH_ARGENTINA
 
542
#define SUBLANG_SPANISH_ARGENTINA 0x0b
 
543
#endif
 
544
#ifndef SUBLANG_SPANISH_ECUADOR
 
545
#define SUBLANG_SPANISH_ECUADOR 0x0c
 
546
#endif
 
547
#ifndef SUBLANG_SPANISH_CHILE
 
548
#define SUBLANG_SPANISH_CHILE 0x0d
 
549
#endif
 
550
#ifndef SUBLANG_SPANISH_URUGUAY
 
551
#define SUBLANG_SPANISH_URUGUAY 0x0e
 
552
#endif
 
553
#ifndef SUBLANG_SPANISH_PARAGUAY
 
554
#define SUBLANG_SPANISH_PARAGUAY 0x0f
 
555
#endif
 
556
#ifndef SUBLANG_SPANISH_BOLIVIA
 
557
#define SUBLANG_SPANISH_BOLIVIA 0x10
 
558
#endif
 
559
#ifndef SUBLANG_SPANISH_EL_SALVADOR
 
560
#define SUBLANG_SPANISH_EL_SALVADOR 0x11
 
561
#endif
 
562
#ifndef SUBLANG_SPANISH_HONDURAS
 
563
#define SUBLANG_SPANISH_HONDURAS 0x12
 
564
#endif
 
565
#ifndef SUBLANG_SPANISH_NICARAGUA
 
566
#define SUBLANG_SPANISH_NICARAGUA 0x13
 
567
#endif
 
568
#ifndef SUBLANG_SPANISH_PUERTO_RICO
 
569
#define SUBLANG_SPANISH_PUERTO_RICO 0x14
 
570
#endif
 
571
#ifndef SUBLANG_SWEDISH_FINLAND
 
572
#define SUBLANG_SWEDISH_FINLAND 0x02
 
573
#endif
 
574
#ifndef SUBLANG_TAMAZIGHT_ARABIC
 
575
#define SUBLANG_TAMAZIGHT_ARABIC 0x01
 
576
#endif
 
577
#ifndef SUBLANG_TAMAZIGHT_LATIN
 
578
#define SUBLANG_TAMAZIGHT_LATIN 0x02
 
579
#endif
 
580
#ifndef SUBLANG_TIGRINYA_ETHIOPIA
 
581
#define SUBLANG_TIGRINYA_ETHIOPIA 0x00
 
582
#endif
 
583
#ifndef SUBLANG_TIGRINYA_ERITREA
 
584
#define SUBLANG_TIGRINYA_ERITREA 0x01
 
585
#endif
 
586
#ifndef SUBLANG_URDU_PAKISTAN
 
587
#define SUBLANG_URDU_PAKISTAN 0x01
 
588
#endif
 
589
#ifndef SUBLANG_URDU_INDIA
 
590
#define SUBLANG_URDU_INDIA 0x02
 
591
#endif
 
592
#ifndef SUBLANG_UZBEK_LATIN
 
593
#define SUBLANG_UZBEK_LATIN 0x01
 
594
#endif
 
595
#ifndef SUBLANG_UZBEK_CYRILLIC
 
596
#define SUBLANG_UZBEK_CYRILLIC 0x02
 
597
#endif
 
598
 
 
599
/* Return an XPG style locale name 
 
600
     language[_territory[.codeset]][@modifier].
778
601
   Don't even bother determining the codeset; it's not useful in this
779
602
   context, because message catalogs are not specific to a single
780
 
   codeset.  */
 
603
   codeset.  The result must not be freed; it is statically
 
604
   allocated.  */
781
605
static const char *
782
 
_nl_locale_name (const char *categoryname)
 
606
my_nl_locale_name (const char *categoryname)
783
607
{
784
608
  const char *retval;
785
609
  LCID lcid;
1183
1007
    default: return "C";
1184
1008
    }
1185
1009
}
1186
 
/* END parts of localname.c from gettext.  */
1187
 
 
1188
 
 
 
1010
 
 
1011
/* localname.c from gettext END.  */
 
1012
 
 
1013
 
 
1014
 
 
1015
/* Support functions.  */
 
1016
 
 
1017
static __inline__ uint32_t
 
1018
do_swap_u32 (uint32_t i)
 
1019
{
 
1020
  return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
 
1021
}
 
1022
 
 
1023
#define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data))
 
1024
 
 
1025
 
 
1026
/* We assume to have `unsigned long int' value with at least 32 bits.  */
 
1027
#define HASHWORDBITS 32
1189
1028
 
1190
1029
/* The so called `hashpjw' function by P.J. Weinberger
1191
1030
   [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
1192
1031
   1986, 1987 Bell Telephone Laboratories, Inc.]  */
1193
 
 
1194
 
static __inline__ ulong
1195
 
hash_string (const char *str_param)
 
1032
static __inline__ unsigned long
 
1033
hash_string( const char *str_param )
1196
1034
{
1197
1035
  unsigned long int hval, g;
1198
1036
  const char *str = str_param;
1212
1050
  return hval;
1213
1051
}
1214
1052
 
1215
 
 
 
1053
/* static char * */
 
1054
/* my_xstrdup (const char *s) */
 
1055
/* { */
 
1056
/*   size_t n = strlen (s) + 1; */
 
1057
/*   char *p = jnlib_malloc (n); */
 
1058
/*   if (!p) */
 
1059
/*     abort (); */
 
1060
/*   strcpy (p, s); */
 
1061
/*   return p; */
 
1062
/* } */
 
1063
 
 
1064
 
 
1065
 
 
1066
/* Generic message catalog and gettext stuff.  */
 
1067
 
 
1068
/* The magic number of the GNU message catalog format.  */
 
1069
#define MAGIC         0x950412de
 
1070
#define MAGIC_SWAPPED 0xde120495
 
1071
 
 
1072
/* Revision number of the currently used .mo (binary) file format.  */
 
1073
#define MO_REVISION_NUMBER 0
 
1074
 
 
1075
 
 
1076
/* Header for binary .mo file format.  */
 
1077
struct mo_file_header
 
1078
{
 
1079
  /* The magic number.  */
 
1080
  uint32_t magic;
 
1081
  /* The revision number of the file format.  */
 
1082
  uint32_t revision;
 
1083
  /* The number of strings pairs.  */
 
1084
  uint32_t nstrings;
 
1085
  /* Offset of table with start offsets of original strings.  */
 
1086
  uint32_t orig_tab_offset;
 
1087
  /* Offset of table with start offsets of translation strings.  */
 
1088
  uint32_t trans_tab_offset;
 
1089
  /* Size of hashing table.  */
 
1090
  uint32_t hash_tab_size;
 
1091
  /* Offset of first hashing entry.  */
 
1092
  uint32_t hash_tab_offset;
 
1093
};
 
1094
 
 
1095
 
 
1096
struct string_desc
 
1097
{
 
1098
  /* Length of addressed string.  */
 
1099
  uint32_t length;
 
1100
  /* Offset of string in file.  */
 
1101
  uint32_t offset;
 
1102
};
 
1103
 
 
1104
 
 
1105
struct overflow_space_s
 
1106
{
 
1107
  struct overflow_space_s *next;
 
1108
  uint32_t idx;
 
1109
  uint32_t length;
 
1110
  char d[1];
 
1111
};
 
1112
 
 
1113
struct loaded_domain
 
1114
{
 
1115
  char *data;
 
1116
  char *data_native; /* Data mapped to the native version of the
 
1117
                        string.  (Allocated along with DATA). */
 
1118
  int must_swap;
 
1119
  uint32_t nstrings;
 
1120
  uint32_t *mapped;  /* 0   := Not mapped (original utf8).
 
1121
                        1   := Mapped to native encoding in overflow space.
 
1122
                        >=2 := Mapped to native encoding. The values
 
1123
                               gives the length of the mapped string.
 
1124
                               becuase the 0 is included and an empty
 
1125
                               string is not allowed we will enver get
 
1126
                               values 0 and 1.  */
 
1127
  struct overflow_space_s *overflow_space;
 
1128
  struct string_desc *orig_tab;
 
1129
  struct string_desc *trans_tab;
 
1130
  uint32_t hash_size;
 
1131
  uint32_t *hash_tab;
 
1132
};
 
1133
 
 
1134
 
 
1135
/* The domain we use.  We only support one domain at this point.  This
 
1136
   is why this implementation can not be shared.  Bindtextdomain and
 
1137
   dgettext will simply cheat and always use this one domain.  */
 
1138
static struct loaded_domain *the_domain;
 
1139
 
 
1140
/* Global flag to switch gettext into an utf8 mode.  */
 
1141
static int want_utf8;
 
1142
 
 
1143
 
 
1144
 
 
1145
/* Free the domain data.  */
 
1146
static void
 
1147
free_domain (struct loaded_domain *domain)
 
1148
{
 
1149
  struct overflow_space_s *os, *os2;
 
1150
 
 
1151
  jnlib_free (domain->data);
 
1152
  jnlib_free (domain->mapped);
 
1153
  for (os = domain->overflow_space; os; os = os2)
 
1154
    {
 
1155
      os2 = os->next;
 
1156
      jnlib_free (os);
 
1157
    }
 
1158
  jnlib_free (domain);
 
1159
}
 
1160
 
 
1161
  
1216
1162
static struct loaded_domain *
1217
1163
load_domain (const char *filename)
1218
1164
{
1224
1170
  size_t to_read;
1225
1171
  char *read_ptr;
1226
1172
  
1227
 
  fp = fopen( filename, "rb" );
 
1173
  fp = fopen (filename, "rb");
1228
1174
  if (!fp)
1229
 
    return NULL; /* Can't open the file.  */
1230
 
  /* We need to know the size of the file.  */
1231
 
  if (fstat( fileno(fp ), &st )
1232
 
      || (size = (size_t)st.st_size) != st.st_size
1233
 
      || size < sizeof (struct mo_file_header) ) 
 
1175
    return NULL;
 
1176
 
 
1177
  /* Determine the file size.  */
 
1178
  if (fstat (fileno (fp), &st)
 
1179
      || (size = (size_t) st.st_size) != st.st_size
 
1180
      || size < sizeof (struct mo_file_header))
1234
1181
    {
1235
1182
      fclose (fp);
1236
1183
      return NULL;
1237
1184
    }
1238
1185
 
1239
 
  data = jnlib_malloc (size);
 
1186
  data = (2*size <= size)? NULL : jnlib_malloc (2*size);
1240
1187
  if (!data)
1241
1188
    {
1242
1189
      fclose (fp);
1243
 
      return NULL; /* Out of memory. */
 
1190
      return NULL;
1244
1191
    }
1245
1192
 
1246
1193
  to_read = size;
1247
1194
  read_ptr = (char *) data;
1248
1195
  do
1249
1196
    {
1250
 
      long int nb;
1251
 
 
1252
 
      nb = fread (read_ptr, 1, to_read, fp);
1253
 
      if (nb < to_read ) 
1254
 
        {
1255
 
          fclose (fp);
1256
 
          jnlib_free (data);
1257
 
          return NULL; /* Read error. */
 
1197
      long int nb = fread (read_ptr, 1, to_read, fp);
 
1198
      if (nb < to_read)
 
1199
        {
 
1200
          fclose (fp);
 
1201
          jnlib_free (data);
 
1202
          return NULL;
1258
1203
        }
1259
1204
      read_ptr += nb;
1260
1205
      to_read -= nb;
1261
 
    } 
 
1206
    }
1262
1207
  while (to_read > 0);
1263
1208
  fclose (fp);
1264
1209
 
1265
 
  /* Using the magic number we test whether it is really a message
 
1210
  /* Using the magic number we can test whether it really is a message
1266
1211
     catalog file.  */
1267
1212
  if (data->magic != MAGIC && data->magic != MAGIC_SWAPPED)
1268
1213
    {
1272
1217
    }
1273
1218
 
1274
1219
  domain = jnlib_calloc (1, sizeof *domain);
1275
 
  if (!domain) 
 
1220
  if (!domain)
1276
1221
    {
1277
1222
      jnlib_free (data);
1278
1223
      return NULL;
1279
1224
    }
1280
1225
  domain->data = (char *) data;
 
1226
  domain->data_native = (char *) data + size;
1281
1227
  domain->must_swap = data->magic != MAGIC;
1282
 
 
 
1228
  
1283
1229
  /* Fill in the information about the available tables.  */
1284
 
    switch (SWAPIT(domain->must_swap, data->revision))
 
1230
  switch (SWAPIT (domain->must_swap, data->revision))
 
1231
    {
 
1232
    case MO_REVISION_NUMBER:
 
1233
      domain->nstrings = SWAPIT (domain->must_swap, data->nstrings);
 
1234
      domain->orig_tab = (struct string_desc *)
 
1235
        ((char *) data + SWAPIT (domain->must_swap, data->orig_tab_offset));
 
1236
      domain->trans_tab = (struct string_desc *)
 
1237
        ((char *) data + SWAPIT (domain->must_swap, data->trans_tab_offset));
 
1238
      domain->hash_size = SWAPIT (domain->must_swap, data->hash_tab_size);
 
1239
      domain->hash_tab = (uint32_t *)
 
1240
        ((char *) data + SWAPIT (domain->must_swap, data->hash_tab_offset));
 
1241
      break;
 
1242
 
 
1243
    default:
 
1244
      /* This is an invalid revision.   */
 
1245
      jnlib_free (data);
 
1246
      jnlib_free (domain);
 
1247
      return NULL;
 
1248
    }
 
1249
 
 
1250
  /* Allocate an array to keep track of code page mappings.  */
 
1251
  domain->mapped = jnlib_calloc (domain->nstrings, sizeof *domain->mapped);
 
1252
  if (!domain->mapped)
 
1253
    {
 
1254
      jnlib_free (data);
 
1255
      jnlib_free (domain);
 
1256
      return NULL;
 
1257
    }
 
1258
 
 
1259
  return domain;
 
1260
}
 
1261
 
 
1262
 
 
1263
/* Return a malloced wide char string from an UTF-8 encoded input
 
1264
   string STRING.  Caller must free this value. On failure returns
 
1265
   NULL.  The result of calling this function with STRING set to NULL
 
1266
   is not defined. */
 
1267
static wchar_t *
 
1268
utf8_to_wchar (const char *string, size_t length, size_t *retlen)
 
1269
{
 
1270
  int n;
 
1271
  wchar_t *result;
 
1272
  size_t nbytes;
 
1273
 
 
1274
  n = MultiByteToWideChar (CP_UTF8, 0, string, length, NULL, 0);
 
1275
  if (n < 0 || (n+1) <= 0)
 
1276
    return NULL;
 
1277
 
 
1278
  nbytes = (size_t)(n+1) * sizeof(*result);
 
1279
  if (nbytes / sizeof(*result) != (n+1)) 
 
1280
    {
 
1281
      errno = ENOMEM;
 
1282
      return NULL;
 
1283
    }
 
1284
  result = jnlib_malloc (nbytes);
 
1285
  if (!result)
 
1286
    return NULL;
 
1287
 
 
1288
  n = MultiByteToWideChar (CP_UTF8, 0, string, length, result, n);
 
1289
  if (n < 0)
 
1290
    {
 
1291
      jnlib_free (result);
 
1292
      return NULL;
 
1293
    }
 
1294
  *retlen = n;
 
1295
  return result;
 
1296
}
 
1297
 
 
1298
 
 
1299
/* Return a malloced string encoded in UTF-8 from the wide char input
 
1300
   string STRING.  Caller must free this value. On failure returns
 
1301
   NULL.  The result of calling this function with STRING set to NULL
 
1302
   is not defined. */
 
1303
static char *
 
1304
wchar_to_native (const wchar_t *string, size_t length, size_t *retlen)
 
1305
{
 
1306
  int n;
 
1307
  char *result;
 
1308
 
 
1309
  n = WideCharToMultiByte (CP_ACP, 0, string, length, NULL, 0, NULL, NULL);
 
1310
  if (n < 0 || (n+1) <= 0)
 
1311
    return NULL;
 
1312
 
 
1313
  result = jnlib_malloc (n+1);
 
1314
  if (!result)
 
1315
    return NULL;
 
1316
 
 
1317
  n = WideCharToMultiByte (CP_ACP, 0, string, length, result, n, NULL, NULL);
 
1318
  if (n < 0)
 
1319
    {
 
1320
      jnlib_free (result);
 
1321
      return NULL;
 
1322
    }
 
1323
  *retlen = n;
 
1324
  return result;
 
1325
}
 
1326
 
 
1327
 
 
1328
/* Convert UTF8 to the native codepage.  Caller must free the return value. */
 
1329
static char *
 
1330
utf8_to_native (const char *string, size_t length, size_t *retlen)
 
1331
{
 
1332
  wchar_t *wstring;
 
1333
  char *result;
 
1334
  size_t newlen;
 
1335
 
 
1336
  wstring = utf8_to_wchar (string, length, &newlen);
 
1337
  if (wstring)
 
1338
    {
 
1339
      result = wchar_to_native (wstring, newlen, &newlen);
 
1340
      jnlib_free (wstring);
 
1341
    }
 
1342
  else
 
1343
    result = NULL;
 
1344
  *retlen = result? newlen : 0;
 
1345
  return result;
 
1346
}
 
1347
 
 
1348
 
 
1349
 
 
1350
 
 
1351
/* Specify that the DOMAINNAME message catalog will be found
 
1352
   in DIRNAME rather than in the system locale data base.  */
 
1353
char *
 
1354
bindtextdomain (const char *domainname, const char *dirname)
 
1355
{
 
1356
  struct loaded_domain *domain = NULL;
 
1357
  const char *catval_full;
 
1358
  char *catval;
 
1359
  char *fname;
 
1360
 
 
1361
  /* DOMAINNAME is ignored.  We only support one domain.  */
 
1362
 
 
1363
  /* DIRNAME is "$INSTALLDIR\share\locale".  */
 
1364
 
 
1365
  /* First find out the category value.  */
 
1366
  catval = NULL;
 
1367
  catval_full = my_nl_locale_name ("LC_MESSAGES");
 
1368
 
 
1369
  /* Normally, we would have to loop over all returned locales, and
 
1370
     search for the right file.  See gettext intl/dcigettext.c for all
 
1371
     the gory details.  Here, we only support the basic category, and
 
1372
     ignore everything else.  */
 
1373
  if (catval_full)
 
1374
    {
 
1375
      char *p;
 
1376
 
 
1377
      catval = jnlib_malloc (strlen (catval_full) + 1);
 
1378
      if (catval)
 
1379
        {
 
1380
          strcpy (catval, catval_full);
 
1381
          p = strchr (catval, '_');
 
1382
          if (p)
 
1383
            *p = '\0';
 
1384
        }
 
1385
    }
 
1386
  if (!catval)
 
1387
    return NULL;
 
1388
 
 
1389
  /* Now build the filename string.  The complete filename is this:
 
1390
     DIRNAME + \ + CATVAL + \LC_MESSAGES\ + DOMAINNAME + .mo  */
 
1391
  {
 
1392
    int len = strlen (dirname) + 1 + strlen (catval) + 13
 
1393
      + strlen (domainname) + 3 + 1;
 
1394
    char *p;
 
1395
 
 
1396
    fname = jnlib_malloc (len);
 
1397
    if (!fname)
1285
1398
      {
1286
 
      case 0:
1287
 
        domain->nstrings = SWAPIT(domain->must_swap, data->nstrings);
1288
 
        domain->orig_tab = (struct string_desc *)
1289
 
          ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset));
1290
 
        domain->trans_tab = (struct string_desc *)
1291
 
          ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset));
1292
 
        domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size);
1293
 
        domain->hash_tab = (u32 *)
1294
 
          ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset));
1295
 
        break;
1296
 
        
1297
 
      default: /* This is an invalid revision.  */
1298
 
        jnlib_free( data );
1299
 
        jnlib_free( domain );
 
1399
        jnlib_free (catval);
1300
1400
        return NULL;
1301
 
    }
1302
 
 
1303
 
    /* Allocate an array to keep track of code page mappings. */
1304
 
    domain->mapped = jnlib_calloc (1, domain->nstrings);
1305
 
    if (!domain->mapped)
1306
 
      {
1307
 
        jnlib_free (data);
1308
 
        jnlib_free (domain);
1309
 
        return NULL;
1310
1401
      }
1311
1402
 
1312
 
    return domain;
1313
 
}
1314
 
 
1315
 
 
1316
 
/* Set the file used for translations.  Pass a NULL to disable
1317
 
   translation.  A new filename may be set at anytime.  WARNING: After
1318
 
   changing the filename you should not access any data retrieved by
1319
 
   gettext().
1320
 
 
1321
 
   If REGKEY is not NULL, the function tries to selected the language
1322
 
   the registry key "Lang" below that key.  If in addition the
1323
 
   environment variable LANGUAGE has been set, that value will
1324
 
   override a value set by the registry key.
1325
 
 */
1326
 
int
1327
 
set_gettext_file ( const char *filename, const char *regkey )
1328
 
{
1329
 
  struct loaded_domain *domain = NULL;
1330
 
 
1331
 
  if ( filename && *filename )
1332
 
    {
1333
 
      if ( filename[0] == '/'
1334
 
#ifdef HAVE_DRIVE_LETTERS
1335
 
           || ( isalpha(filename[0])
1336
 
                && filename[1] == ':'
1337
 
                && (filename[2] == '/' || filename[2] == '\\') )
1338
 
#endif
1339
 
           )
1340
 
        {
1341
 
          /* Absolute path - use it as is.  */
1342
 
          domain = load_domain( filename );
1343
 
        }
1344
 
      else  /* Standard.  */
1345
 
        {
1346
 
          char *pgmdir, *instdir, *langid, *fname;
1347
 
          char *p;
1348
 
          int pass = 0;
1349
 
          const char *catval;
1350
 
          
1351
 
          /* In the $LANGUAGE and native locale case we do not use the
1352
 
             registered installation directory but the one where the
1353
 
             gpg binary has been found.  */
1354
 
          pgmdir = jnlib_malloc (MAX_PATH+5);
1355
 
          if ( !pgmdir || !GetModuleFileName (NULL, pgmdir, MAX_PATH) )
1356
 
            {
1357
 
              jnlib_free (pgmdir);
1358
 
              return -1; /* Error getting the process' file name.  */
1359
 
            }
1360
 
          p = strrchr (pgmdir, DIRSEP_C);
1361
 
          if (!p)
1362
 
            {
1363
 
              jnlib_free (pgmdir);
1364
 
              return -1; /* Invalid file name returned.  */
1365
 
            }
1366
 
          *p = 0;
1367
 
          instdir = NULL;
1368
 
          langid = NULL;
1369
 
          fname = NULL;
1370
 
 
1371
 
          for (pass=0; pass < 3 && !domain; pass++)
1372
 
            {
1373
 
              jnlib_free (instdir);
1374
 
              instdir = NULL;
1375
 
              jnlib_free (langid);
1376
 
              langid = NULL;
1377
 
              jnlib_free (fname);
1378
 
              fname = NULL;
1379
 
              switch (pass)
1380
 
                {
1381
 
                case 0: /* Pass 0: Try LANGUAGE.  */
1382
 
                  if ((p = getenv ("LANGUAGE")) && *p)
1383
 
                    {
1384
 
                      langid = jnlib_malloc (strlen (p)+1);
1385
 
                      if (langid)
1386
 
                        {
1387
 
                          strcpy (langid, p);
1388
 
                          /* We only make use of the first language
1389
 
                             given.  Strip the rest.  */
1390
 
                          p = strchr (langid, ':');
1391
 
                          if (p)
1392
 
                            *p = 0;
1393
 
                        }
1394
 
                    }
1395
 
                  break;
1396
 
                  
1397
 
                case 1: /* Pass 1: Try registry. */
1398
 
                  if (regkey)
1399
 
                    {
1400
 
                      instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE",
1401
 
                                                          regkey,
1402
 
                                                          "Install Directory");
1403
 
                      if (instdir)
1404
 
                        /* Try HKCU then HKLM. */
1405
 
                        langid = read_w32_registry_string (NULL, 
1406
 
                                                           regkey, "Lang");
1407
 
                    }
1408
 
                  break;
1409
 
 
1410
 
                case 2: /* Pass 2: Try native local.  */
1411
 
                  catval = _nl_locale_name ("LC_MESSAGES");
1412
 
                  if (!catval ||
1413
 
                      !strcmp (catval, "C") || !strcmp (catval, "POSIX"))
1414
 
                    ;
1415
 
                  else
1416
 
                    {
1417
 
                      langid = jnlib_malloc (strlen (catval)+1);
1418
 
                      strcpy (langid, catval);
1419
 
                    }
1420
 
                  break;
1421
 
 
1422
 
                default:
1423
 
                  break;
1424
 
                }
1425
 
 
1426
 
              if (!langid)
1427
 
                continue; /* Next pass.  */
1428
 
 
1429
 
              /* Strip stuff after a dot in case the user tried to
1430
 
                 enter the entire locale syntacs as usual for
1431
 
                 POSIX.  */
1432
 
              p = strchr (langid, '.');
1433
 
              if (p)
1434
 
                *p = 0;
1435
 
                  
1436
 
              /* Build the key: "<instdir>/<domain>.nls/<langid>.mo".
1437
 
                 We use a directory below the installation directory
1438
 
                 with the domain included in case the software has
1439
 
                 been installed with other software altogether at the
1440
 
                 same place.  */
1441
 
              fname = jnlib_malloc (strlen (instdir? instdir:pgmdir) + 1
1442
 
                                    + strlen (filename) + 5
1443
 
                                    + strlen (langid) + 3 + 1);
1444
 
              if (fname)
1445
 
                {
1446
 
                next_fname:
1447
 
                  strcpy (stpcpy 
1448
 
                          (stpcpy
1449
 
                           (stpcpy 
1450
 
                            (stpcpy 
1451
 
                             (stpcpy (fname,
1452
 
                                      instdir?instdir:pgmdir),"\\"),
1453
 
                             filename), ".nls\\"), 
1454
 
                           langid), ".mo");
1455
 
                      
1456
 
                  /* Better make sure that we don't mix forward and
1457
 
                     backward slashes.  It seems that some Windoze
1458
 
                     versions don't accept this. */
1459
 
                  for (p=fname; *p; p++) 
1460
 
                    {
1461
 
                      if (*p == '/')
1462
 
                        *p = '\\';
1463
 
                    }
1464
 
                  domain = load_domain (fname);
1465
 
                  /* In case we did not found it, we try again with
1466
 
                     just the first part.  E.g. "pt_BR" -> "pt". */
1467
 
                  if (!domain && (p = strchr (langid, '_')))
1468
 
                    {
1469
 
                      *p = 0;
1470
 
                      goto next_fname;
1471
 
                    }
1472
 
                  if (domain && !the_langid)
1473
 
                    {
1474
 
                      /* We save the langid we found when setting up
1475
 
                         the first domain.  This yields more
1476
 
                         consistent results from gettext_localename(). */
1477
 
                      the_langid = langid;
1478
 
                      langid = NULL;
1479
 
                    }
1480
 
                }  
1481
 
            } /* End passes.  */
1482
 
 
1483
 
          jnlib_free (pgmdir);
1484
 
          jnlib_free (instdir);
1485
 
          jnlib_free (langid);
1486
 
          jnlib_free (fname);
1487
 
        } 
1488
 
      
1489
 
      if (!domain)
1490
 
        return -1;
1491
 
    }
1492
 
  
1493
 
  if ( the_domain )
1494
 
    {
1495
 
      struct overflow_space_s *os, *os2;
1496
 
 
1497
 
      jnlib_free ( the_domain->data );
1498
 
      jnlib_free ( the_domain->mapped );
1499
 
      for (os=the_domain->overflow_space; os; os = os2)
1500
 
        {
1501
 
          os2 = os->next;
1502
 
          jnlib_free (os);
1503
 
        }
1504
 
      jnlib_free ( the_domain );
1505
 
      the_domain = NULL;
1506
 
    }
 
1403
    p = fname;
 
1404
    strcpy (p, dirname);
 
1405
    p += strlen (dirname);
 
1406
    *(p++) = '\\';
 
1407
    strcpy (p, catval);
 
1408
    p += strlen (catval);
 
1409
    strcpy (p, "\\LC_MESSAGES\\");
 
1410
    p += 13;
 
1411
    strcpy (p, domainname);
 
1412
    p += strlen (domainname);
 
1413
    strcpy (p, ".mo");
 
1414
  }
 
1415
 
 
1416
  domain = load_domain (fname);
 
1417
  jnlib_free (catval);
 
1418
  jnlib_free (fname);
 
1419
 
 
1420
  /* We should not be invoked twice, but this is how you would do
 
1421
     it if it happened.  */
 
1422
  if (the_domain)
 
1423
    free_domain (the_domain);
1507
1424
  the_domain = domain;
1508
 
  return 0;
 
1425
 
 
1426
  /* For historic reasons we are not allowed to return a const char*. */
 
1427
  return (char*)dirname;
 
1428
}
 
1429
 
 
1430
 
 
1431
 
 
1432
 
 
1433
static const char *
 
1434
get_plural (const char *data, size_t datalen, unsigned long nplural)
 
1435
{
 
1436
  const char *p;
 
1437
  int idx;
 
1438
 
 
1439
  /* We only support the Germanic rule.  */
 
1440
  idx = (nplural == 1? 0 : 1);
 
1441
 
 
1442
  for (; idx; idx--)
 
1443
    {
 
1444
      p = strchr (data, 0) + 1;
 
1445
      if (p >= data+datalen)
 
1446
        return "ERROR in GETTEXT (bad plural entry)";
 
1447
      datalen -= (p-data);
 
1448
      data = p;
 
1449
    }
 
1450
  return data;
1509
1451
}
1510
1452
 
1511
1453
 
1512
1454
static const char*
1513
 
get_string( struct loaded_domain *domain, u32 idx )
 
1455
get_string (struct loaded_domain *domain, uint32_t idx,
 
1456
            int use_plural, unsigned long nplural)
1514
1457
{
1515
1458
  struct overflow_space_s *os;
1516
 
  char *p;
 
1459
  const char *trans;  /* Pointer to the translated entry.  */
 
1460
  size_t translen;    /* Length of that entry.  */
1517
1461
 
1518
 
  p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset);
1519
 
  if (!domain->mapped[idx]) 
1520
 
    {
1521
 
      size_t plen, buflen;
 
1462
  if (want_utf8)
 
1463
    {
 
1464
      trans = (domain->data
 
1465
               + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
 
1466
      translen = SWAPIT(domain->must_swap, domain->trans_tab[idx].length);
 
1467
    }
 
1468
  else if (!domain->mapped[idx]) 
 
1469
    {
 
1470
      /* Not yet mapped.  Map from utf-8 to native encoding now.  */
 
1471
      const char *p_utf8;
 
1472
      size_t plen_utf8, buflen;
1522
1473
      char *buf;
1523
1474
 
1524
 
      domain->mapped[idx] = 1;
 
1475
      p_utf8 = (domain->data 
 
1476
                + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
 
1477
      plen_utf8 = SWAPIT(domain->must_swap, domain->trans_tab[idx].length);
 
1478
      
 
1479
      buf = utf8_to_native (p_utf8, plen_utf8, &buflen);
 
1480
      if (!buf)
 
1481
        {
 
1482
          trans = "ERROR in GETTEXT MALLOC";
 
1483
          translen = 0;
 
1484
        }
 
1485
      else if (buflen <= plen_utf8 && buflen > 1)
 
1486
        {
 
1487
          /* Copy into the DATA_NATIVE area. */
 
1488
          char *p_tmp;
1525
1489
 
1526
 
      plen = strlen (p);
1527
 
      buf = utf8_to_native (p, plen, -1);
1528
 
      buflen = strlen (buf);
1529
 
      if (buflen <= plen)
1530
 
        strcpy (p, buf);
 
1490
          p_tmp = (domain->data_native 
 
1491
                   + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
 
1492
          memcpy (p_tmp, buf, buflen);
 
1493
          domain->mapped[idx] = buflen;
 
1494
          trans = p_tmp;
 
1495
          translen = buflen;
 
1496
        }
1531
1497
      else
1532
1498
        {
1533
 
          /* There is not enough space for the translation - store it
1534
 
             in the overflow_space else and mark that in the mapped
1535
 
             array.  Because we expect that this won't happen too
1536
 
             often, we use a simple linked list.  */
 
1499
          /* There is not enough space for the translation (or for
 
1500
             whatever reason an empry string is used): Store it in the
 
1501
             overflow_space and mark that in the mapped array.
 
1502
             Because UTF-8 strings are in general longer than the
 
1503
             Windows 2 byte encodings, we expect that this won't
 
1504
             happen too often (if at all) and thus we use a linked
 
1505
             list to manage this space. */
1537
1506
          os = jnlib_malloc (sizeof *os + buflen);
1538
1507
          if (os)
1539
1508
            {
1540
1509
              os->idx = idx;
1541
 
              strcpy (os->d, buf);
 
1510
              memcpy (os->d, buf, buflen);
 
1511
              os->length = buflen;
1542
1512
              os->next = domain->overflow_space;
1543
1513
              domain->overflow_space = os;
1544
 
              p = os->d;
 
1514
              domain->mapped[idx] = 1;
 
1515
              trans = os->d;
 
1516
              translen = os->length;
1545
1517
            }
1546
1518
          else
1547
 
            p = "ERROR in GETTEXT MALLOC";
 
1519
            {
 
1520
              trans = "ERROR in GETTEXT MALLOC";
 
1521
              translen = 0;
 
1522
            }
1548
1523
        }
1549
1524
      jnlib_free (buf);
1550
1525
    }
1551
 
  else if (domain->mapped[idx] == 2) 
1552
 
    { /* We need to get the string from the overflow_space. */
 
1526
  else if (domain->mapped[idx] == 1) 
 
1527
    {
 
1528
      /* The translated string is in the overflow_space. */
1553
1529
      for (os=domain->overflow_space; os; os = os->next)
1554
1530
        if (os->idx == idx)
1555
 
          return (const char*)os->d;
1556
 
      p = "ERROR in GETTEXT\n";
1557
 
    }
1558
 
  return (const char*)p;
 
1531
          break;
 
1532
      if (os)
 
1533
        {
 
1534
          trans = os->d;
 
1535
          translen = os->length;
 
1536
        }
 
1537
      else
 
1538
        {
 
1539
          trans = "ERROR in GETTEXT (overflow space)\n";
 
1540
          translen = 0;
 
1541
        }
 
1542
    }
 
1543
  else 
 
1544
    { 
 
1545
      trans = (domain->data_native
 
1546
               + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
 
1547
      translen = domain->mapped[idx];
 
1548
    }
 
1549
 
 
1550
  if (use_plural && translen)
 
1551
    return get_plural (trans, translen, nplural);
 
1552
  else
 
1553
    return trans;
1559
1554
}
1560
1555
 
1561
1556
 
1562
 
 
1563
 
const char *
1564
 
gettext( const char *msgid )
 
1557
static const char *
 
1558
do_gettext (const char *msgid, const char *msgid2, unsigned long nplural)
1565
1559
{
1566
1560
  struct loaded_domain *domain;
1567
 
  size_t act = 0;
1568
 
  size_t top, bottom;
 
1561
  uint32_t top, bottom, nstr;
1569
1562
  
1570
1563
  if (!(domain = the_domain))
1571
1564
    goto not_found;
1572
 
  
1573
 
  /* Locate the MSGID and its translation.  */
 
1565
 
 
1566
  /* First try to use the hash table.  */
1574
1567
  if (domain->hash_size > 2 && domain->hash_tab)
1575
1568
    {
1576
1569
      /* Use the hashing table.  */
1577
 
      u32 len = strlen (msgid);
1578
 
      u32 hash_val = hash_string (msgid);
1579
 
      u32 idx = hash_val % domain->hash_size;
1580
 
      u32 incr = 1 + (hash_val % (domain->hash_size - 2));
1581
 
      u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]);
1582
 
 
1583
 
      if ( !nstr ) /* Hash table entry is empty.  */
1584
 
        goto not_found;
1585
 
      
1586
 
      if (SWAPIT(domain->must_swap,
1587
 
                 domain->orig_tab[nstr - 1].length) == len
1588
 
          && !strcmp (msgid,
1589
 
                      domain->data + SWAPIT(domain->must_swap,
1590
 
                                            domain->orig_tab[nstr-1].offset)))
1591
 
        return get_string( domain, nstr - 1 );
1592
 
 
1593
 
      for (;;) 
 
1570
      uint32_t len = strlen (msgid);
 
1571
      uint32_t hash_val = hash_string (msgid);
 
1572
      uint32_t idx = hash_val % domain->hash_size;
 
1573
      uint32_t incr = 1 + (hash_val % (domain->hash_size - 2));
 
1574
 
 
1575
      while ( (nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx])) )
1594
1576
        {
 
1577
          nstr--;
 
1578
          if (nstr < domain->nstrings
 
1579
              && SWAPIT(domain->must_swap, 
 
1580
                        domain->orig_tab[nstr].length) >= len
 
1581
              && !strcmp (msgid, (domain->data
 
1582
                                  + SWAPIT(domain->must_swap,
 
1583
                                           domain->orig_tab[nstr].offset))))
 
1584
            {
 
1585
              return get_string (domain, nstr, !!msgid2, nplural);
 
1586
            }
 
1587
 
1595
1588
          if (idx >= domain->hash_size - incr)
1596
1589
            idx -= domain->hash_size - incr;
1597
1590
          else
1598
1591
            idx += incr;
1599
 
          
1600
 
          nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]);
1601
 
          if (!nstr)
1602
 
            goto not_found; /* Hash table entry is empty.  */
1603
 
 
1604
 
          if ( SWAPIT(domain->must_swap,
1605
 
                      domain->orig_tab[nstr - 1].length) == len
1606
 
               && !strcmp (msgid,
1607
 
                           domain->data 
1608
 
                           + SWAPIT(domain->must_swap,
1609
 
                                    domain->orig_tab[nstr-1].offset)))
1610
 
            return get_string( domain, nstr-1 );
1611
1592
        }
1612
 
      /*NOTREACHED*/
1613
1593
    }
1614
1594
 
1615
1595
  /* Now we try the default method: binary search in the sorted array
1620
1600
    {
1621
1601
      int cmp_val;
1622
1602
      
1623
 
      act = (bottom + top) / 2;
1624
 
      cmp_val = strcmp(msgid, domain->data
1625
 
                       + SWAPIT(domain->must_swap,
1626
 
                                domain->orig_tab[act].offset));
 
1603
      nstr = (bottom + top) / 2;
 
1604
      cmp_val = strcmp (msgid, (domain->data
 
1605
                                + SWAPIT(domain->must_swap,
 
1606
                                         domain->orig_tab[nstr].offset)));
1627
1607
      if (cmp_val < 0)
1628
 
        top = act;
 
1608
        top = nstr;
1629
1609
      else if (cmp_val > 0)
1630
 
        bottom = act + 1;
 
1610
        bottom = nstr + 1;
1631
1611
      else
1632
 
        return get_string (domain, act);
 
1612
        return get_string (domain, nstr, !!msgid2, nplural);
1633
1613
    }
1634
 
  
 
1614
 
1635
1615
 not_found:
1636
 
  return msgid;
1637
 
}
1638
 
 
 
1616
  /* We use the standard Germanic rule if plural has been requested.  */
 
1617
  return msgid2? (nplural == 1? msgid : msgid2) : msgid;
 
1618
}
 
1619
 
 
1620
 
 
1621
char *
 
1622
textdomain (const char *domainname)
 
1623
{
 
1624
  /* For now, support only one domain.  */
 
1625
  return (char*)domainname;
 
1626
}
 
1627
 
 
1628
 
 
1629
const char *
 
1630
gettext (const char *msgid)
 
1631
{
 
1632
  return do_gettext (msgid, NULL, 0);
 
1633
}
 
1634
 
 
1635
char *
 
1636
dgettext (const char *domainname, const char *msgid)
 
1637
{
 
1638
  (void)domainname;
 
1639
 
 
1640
  /* For now, support only one domain.  */
 
1641
  return (char*)do_gettext (msgid, NULL, 0);
 
1642
}
1639
1643
 
1640
1644
const char *
1641
1645
ngettext (const char *msgid1, const char *msgid2, unsigned long int n)
1642
1646
{
1643
 
  /* We use the simple Germanic plural rule. */
1644
 
  return gettext (n==1? msgid1 : msgid2);
 
1647
  /* We use the simple Germanic plural rule.  */
 
1648
  return do_gettext (msgid1, msgid2, n);
1645
1649
}
1646
1650
 
1647
1651
 
1652
1656
{
1653
1657
  const char *s;
1654
1658
 
1655
 
  if (the_langid)
1656
 
    s = the_langid;
1657
 
  else
1658
 
    s = _nl_locale_name ("LC_MESSAGES");
 
1659
  s = my_nl_locale_name ("LC_MESSAGES");
1659
1660
  return s? s:"";
1660
1661
}
1661
1662
 
1662
 
 
1663
 
#endif /* USE_SIMPLE_GETTEXT */
 
1663
void
 
1664
gettext_select_utf8 (int value)
 
1665
{
 
1666
  want_utf8 = value;
 
1667
}
 
1668
 
 
1669
 
 
1670
#ifdef TEST
 
1671
int
 
1672
main (int argc, char **argv)
 
1673
{
 
1674
  const char atext1[] = 
 
1675
    "Warning: You have entered an insecure passphrase.%%0A"
 
1676
    "A passphrase should be at least %u character long.";
 
1677
  const char atext2[] = 
 
1678
    "Warning: You have entered an insecure passphrase.%%0A"
 
1679
    "A passphrase should be at least %u characters long.";
 
1680
 
 
1681
  if (argc)
 
1682
    {
 
1683
      argc--;
 
1684
      argv++;
 
1685
    }
 
1686
  
 
1687
  bindtextdomain ("gnupg2", "c:/programme/gnu/gnupg/share/locale");
 
1688
 
 
1689
  printf ("locale is `%s'\n", gettext_localename ());
 
1690
  fputs ("text with N=1:\n", stdout);
 
1691
  fputs (ngettext (atext1, atext2, 1), stdout);
 
1692
  fputs ("\n\ntext with N=2:\n", stdout);
 
1693
  fputs (ngettext (atext1, atext2, 2), stdout);
 
1694
  fputs ("\nready\n", stdout);
 
1695
 
 
1696
  return 0;
 
1697
}
 
1698
/*
 
1699
 * Local Variables:
 
1700
 *  compile-command: "i586-mingw32msvc-gcc -DTEST -Wall -g w32-gettext.c"
 
1701
 * End:
 
1702
 */
 
1703
#endif /*TEST*/