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.
5
* This file is part of JNLIB.
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.
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.
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/>.
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
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.
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.
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.
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/>.
29
20
#include <config.h>
30
#ifdef USE_SIMPLE_GETTEXT
31
# if !defined (_WIN32) && !defined (__CYGWIN32__)
22
#if !defined (_WIN32) && !defined (__CYGWIN32__)
32
23
# error This module may only be build for Windows or Cygwin32
40
# include <sys/types.h>
41
# include <sys/stat.h>
43
# include "libjnlib-config.h"
45
# include "stringhelp.h"
46
# include "utf8conv.h"
49
# include "windows.h" /* For GetModuleFileName. */
53
/* The magic number of the GNU message catalog format. */
54
#define MAGIC 0x950412de
55
#define MAGIC_SWAPPED 0xde120495
57
/* Revision number of the currently used .mo (binary) file format. */
58
#define MO_REVISION_NUMBER 0
61
/* Header for binary .mo file format. */
64
/* The magic number. */
66
/* The revision number of the file format. */
68
/* The number of strings pairs. */
70
/* Offset of table with start offsets of original strings. */
72
/* Offset of table with start offsets of translation strings. */
74
/* Size of hashing table. */
76
/* Offset of first hashing entry. */
82
/* Length of addressed string. */
84
/* Offset of string in file. */
89
struct overflow_space_s
91
struct overflow_space_s *next;
101
char *mapped; /* 0 = not yet mapped, 1 = mapped,
104
struct overflow_space_s *overflow_space;
105
struct string_desc *orig_tab;
106
struct string_desc *trans_tab;
112
static struct loaded_domain *the_domain;
113
static char *the_langid;
115
static __inline__ u32
118
return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
121
#define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data) )
124
/* We assume to have `unsigned long int' value with at least 32 bits. */
125
#define HASHWORDBITS 32
129
/* BEGIN parts of localname.c from gettext. */
31
#include <sys/types.h>
38
#include "libjnlib-config.h"
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*/
50
/* localname.c from gettext BEGIN. */
52
/* Determine the current selected locale.
53
Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
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)
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.
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,
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>. */
134
/* List of language codes, sorted by value:
157
0x17 LANG_RHAETO_ROMANCE
160
0x1a LANG_CROATIAN == LANG_SERBIAN
252
75
/* Mingw headers don't have latest language and sublanguage codes. */
253
# ifndef LANG_AFRIKAANS
254
# define LANG_AFRIKAANS 0x36
256
# ifndef LANG_ALBANIAN
257
# define LANG_ALBANIAN 0x1c
259
# ifndef LANG_AMHARIC
260
# define LANG_AMHARIC 0x5e
263
# define LANG_ARABIC 0x01
265
# ifndef LANG_ARMENIAN
266
# define LANG_ARMENIAN 0x2b
268
# ifndef LANG_ASSAMESE
269
# define LANG_ASSAMESE 0x4d
272
# define LANG_AZERI 0x2c
275
# define LANG_BASQUE 0x2d
277
# ifndef LANG_BELARUSIAN
278
# define LANG_BELARUSIAN 0x23
280
# ifndef LANG_BENGALI
281
# define LANG_BENGALI 0x45
283
# ifndef LANG_BURMESE
284
# define LANG_BURMESE 0x55
286
# ifndef LANG_CAMBODIAN
287
# define LANG_CAMBODIAN 0x53
289
# ifndef LANG_CATALAN
290
# define LANG_CATALAN 0x03
292
# ifndef LANG_CHEROKEE
293
# define LANG_CHEROKEE 0x5c
296
# define LANG_DIVEHI 0x65
299
# define LANG_EDO 0x66
301
# ifndef LANG_ESTONIAN
302
# define LANG_ESTONIAN 0x25
304
# ifndef LANG_FAEROESE
305
# define LANG_FAEROESE 0x38
308
# define LANG_FARSI 0x29
310
# ifndef LANG_FRISIAN
311
# define LANG_FRISIAN 0x62
313
# ifndef LANG_FULFULDE
314
# define LANG_FULFULDE 0x67
317
# define LANG_GAELIC 0x3c
319
# ifndef LANG_GALICIAN
320
# define LANG_GALICIAN 0x56
322
# ifndef LANG_GEORGIAN
323
# define LANG_GEORGIAN 0x37
325
# ifndef LANG_GUARANI
326
# define LANG_GUARANI 0x74
328
# ifndef LANG_GUJARATI
329
# define LANG_GUJARATI 0x47
332
# define LANG_HAUSA 0x68
334
# ifndef LANG_HAWAIIAN
335
# define LANG_HAWAIIAN 0x75
338
# define LANG_HEBREW 0x0d
341
# define LANG_HINDI 0x39
344
# define LANG_IBIBIO 0x69
347
# define LANG_IGBO 0x70
349
# ifndef LANG_INDONESIAN
350
# define LANG_INDONESIAN 0x21
352
# ifndef LANG_INUKTITUT
353
# define LANG_INUKTITUT 0x5d
355
# ifndef LANG_KANNADA
356
# define LANG_KANNADA 0x4b
359
# define LANG_KANURI 0x71
361
# ifndef LANG_KASHMIRI
362
# define LANG_KASHMIRI 0x60
365
# define LANG_KAZAK 0x3f
367
# ifndef LANG_KONKANI
368
# define LANG_KONKANI 0x57
371
# define LANG_KYRGYZ 0x40
374
# define LANG_LAO 0x54
377
# define LANG_LATIN 0x76
379
# ifndef LANG_LATVIAN
380
# define LANG_LATVIAN 0x26
382
# ifndef LANG_LITHUANIAN
383
# define LANG_LITHUANIAN 0x27
385
# ifndef LANG_MACEDONIAN
386
# define LANG_MACEDONIAN 0x2f
389
# define LANG_MALAY 0x3e
391
# ifndef LANG_MALAYALAM
392
# define LANG_MALAYALAM 0x4c
394
# ifndef LANG_MALTESE
395
# define LANG_MALTESE 0x3a
397
# ifndef LANG_MANIPURI
398
# define LANG_MANIPURI 0x58
400
# ifndef LANG_MARATHI
401
# define LANG_MARATHI 0x4e
403
# ifndef LANG_MONGOLIAN
404
# define LANG_MONGOLIAN 0x50
407
# define LANG_NEPALI 0x61
410
# define LANG_ORIYA 0x48
413
# define LANG_OROMO 0x72
415
# ifndef LANG_PAPIAMENTU
416
# define LANG_PAPIAMENTU 0x79
419
# define LANG_PASHTO 0x63
421
# ifndef LANG_PUNJABI
422
# define LANG_PUNJABI 0x46
424
# ifndef LANG_RHAETO_ROMANCE
425
# define LANG_RHAETO_ROMANCE 0x17
428
# define LANG_SAAMI 0x3b
430
# ifndef LANG_SANSKRIT
431
# define LANG_SANSKRIT 0x4f
433
# ifndef LANG_SERBIAN
434
# define LANG_SERBIAN 0x1a
437
# define LANG_SINDHI 0x59
439
# ifndef LANG_SINHALESE
440
# define LANG_SINHALESE 0x5b
443
# define LANG_SLOVAK 0x1b
446
# define LANG_SOMALI 0x77
448
# ifndef LANG_SORBIAN
449
# define LANG_SORBIAN 0x2e
452
# define LANG_SUTU 0x30
454
# ifndef LANG_SWAHILI
455
# define LANG_SWAHILI 0x41
458
# define LANG_SYRIAC 0x5a
460
# ifndef LANG_TAGALOG
461
# define LANG_TAGALOG 0x64
464
# define LANG_TAJIK 0x28
466
# ifndef LANG_TAMAZIGHT
467
# define LANG_TAMAZIGHT 0x5f
470
# define LANG_TAMIL 0x49
473
# define LANG_TATAR 0x44
476
# define LANG_TELUGU 0x4a
479
# define LANG_THAI 0x1e
481
# ifndef LANG_TIBETAN
482
# define LANG_TIBETAN 0x51
484
# ifndef LANG_TIGRINYA
485
# define LANG_TIGRINYA 0x73
488
# define LANG_TSONGA 0x31
491
# define LANG_TSWANA 0x32
493
# ifndef LANG_TURKMEN
494
# define LANG_TURKMEN 0x42
496
# ifndef LANG_UKRAINIAN
497
# define LANG_UKRAINIAN 0x22
500
# define LANG_URDU 0x20
503
# define LANG_UZBEK 0x43
506
# define LANG_VENDA 0x33
508
# ifndef LANG_VIETNAMESE
509
# define LANG_VIETNAMESE 0x2a
512
# define LANG_WELSH 0x52
515
# define LANG_XHOSA 0x34
518
# define LANG_YI 0x78
520
# ifndef LANG_YIDDISH
521
# define LANG_YIDDISH 0x3d
524
# define LANG_YORUBA 0x6a
527
# define LANG_ZULU 0x35
529
# ifndef SUBLANG_ARABIC_SAUDI_ARABIA
530
# define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
532
# ifndef SUBLANG_ARABIC_IRAQ
533
# define SUBLANG_ARABIC_IRAQ 0x02
535
# ifndef SUBLANG_ARABIC_EGYPT
536
# define SUBLANG_ARABIC_EGYPT 0x03
538
# ifndef SUBLANG_ARABIC_LIBYA
539
# define SUBLANG_ARABIC_LIBYA 0x04
541
# ifndef SUBLANG_ARABIC_ALGERIA
542
# define SUBLANG_ARABIC_ALGERIA 0x05
544
# ifndef SUBLANG_ARABIC_MOROCCO
545
# define SUBLANG_ARABIC_MOROCCO 0x06
547
# ifndef SUBLANG_ARABIC_TUNISIA
548
# define SUBLANG_ARABIC_TUNISIA 0x07
550
# ifndef SUBLANG_ARABIC_OMAN
551
# define SUBLANG_ARABIC_OMAN 0x08
553
# ifndef SUBLANG_ARABIC_YEMEN
554
# define SUBLANG_ARABIC_YEMEN 0x09
556
# ifndef SUBLANG_ARABIC_SYRIA
557
# define SUBLANG_ARABIC_SYRIA 0x0a
559
# ifndef SUBLANG_ARABIC_JORDAN
560
# define SUBLANG_ARABIC_JORDAN 0x0b
562
# ifndef SUBLANG_ARABIC_LEBANON
563
# define SUBLANG_ARABIC_LEBANON 0x0c
565
# ifndef SUBLANG_ARABIC_KUWAIT
566
# define SUBLANG_ARABIC_KUWAIT 0x0d
568
# ifndef SUBLANG_ARABIC_UAE
569
# define SUBLANG_ARABIC_UAE 0x0e
571
# ifndef SUBLANG_ARABIC_BAHRAIN
572
# define SUBLANG_ARABIC_BAHRAIN 0x0f
574
# ifndef SUBLANG_ARABIC_QATAR
575
# define SUBLANG_ARABIC_QATAR 0x10
577
# ifndef SUBLANG_AZERI_LATIN
578
# define SUBLANG_AZERI_LATIN 0x01
580
# ifndef SUBLANG_AZERI_CYRILLIC
581
# define SUBLANG_AZERI_CYRILLIC 0x02
583
# ifndef SUBLANG_BENGALI_INDIA
584
# define SUBLANG_BENGALI_INDIA 0x01
586
# ifndef SUBLANG_BENGALI_BANGLADESH
587
# define SUBLANG_BENGALI_BANGLADESH 0x02
589
# ifndef SUBLANG_CHINESE_MACAU
590
# define SUBLANG_CHINESE_MACAU 0x05
592
# ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
593
# define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
595
# ifndef SUBLANG_ENGLISH_JAMAICA
596
# define SUBLANG_ENGLISH_JAMAICA 0x08
598
# ifndef SUBLANG_ENGLISH_CARIBBEAN
599
# define SUBLANG_ENGLISH_CARIBBEAN 0x09
601
# ifndef SUBLANG_ENGLISH_BELIZE
602
# define SUBLANG_ENGLISH_BELIZE 0x0a
604
# ifndef SUBLANG_ENGLISH_TRINIDAD
605
# define SUBLANG_ENGLISH_TRINIDAD 0x0b
607
# ifndef SUBLANG_ENGLISH_ZIMBABWE
608
# define SUBLANG_ENGLISH_ZIMBABWE 0x0c
610
# ifndef SUBLANG_ENGLISH_PHILIPPINES
611
# define SUBLANG_ENGLISH_PHILIPPINES 0x0d
613
# ifndef SUBLANG_ENGLISH_INDONESIA
614
# define SUBLANG_ENGLISH_INDONESIA 0x0e
616
# ifndef SUBLANG_ENGLISH_HONGKONG
617
# define SUBLANG_ENGLISH_HONGKONG 0x0f
619
# ifndef SUBLANG_ENGLISH_INDIA
620
# define SUBLANG_ENGLISH_INDIA 0x10
622
# ifndef SUBLANG_ENGLISH_MALAYSIA
623
# define SUBLANG_ENGLISH_MALAYSIA 0x11
625
# ifndef SUBLANG_ENGLISH_SINGAPORE
626
# define SUBLANG_ENGLISH_SINGAPORE 0x12
628
# ifndef SUBLANG_FRENCH_LUXEMBOURG
629
# define SUBLANG_FRENCH_LUXEMBOURG 0x05
631
# ifndef SUBLANG_FRENCH_MONACO
632
# define SUBLANG_FRENCH_MONACO 0x06
634
# ifndef SUBLANG_FRENCH_WESTINDIES
635
# define SUBLANG_FRENCH_WESTINDIES 0x07
637
# ifndef SUBLANG_FRENCH_REUNION
638
# define SUBLANG_FRENCH_REUNION 0x08
640
# ifndef SUBLANG_FRENCH_CONGO
641
# define SUBLANG_FRENCH_CONGO 0x09
643
# ifndef SUBLANG_FRENCH_SENEGAL
644
# define SUBLANG_FRENCH_SENEGAL 0x0a
646
# ifndef SUBLANG_FRENCH_CAMEROON
647
# define SUBLANG_FRENCH_CAMEROON 0x0b
649
# ifndef SUBLANG_FRENCH_COTEDIVOIRE
650
# define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
652
# ifndef SUBLANG_FRENCH_MALI
653
# define SUBLANG_FRENCH_MALI 0x0d
655
# ifndef SUBLANG_FRENCH_MOROCCO
656
# define SUBLANG_FRENCH_MOROCCO 0x0e
658
# ifndef SUBLANG_FRENCH_HAITI
659
# define SUBLANG_FRENCH_HAITI 0x0f
661
# ifndef SUBLANG_GERMAN_LUXEMBOURG
662
# define SUBLANG_GERMAN_LUXEMBOURG 0x04
664
# ifndef SUBLANG_GERMAN_LIECHTENSTEIN
665
# define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
667
# ifndef SUBLANG_KASHMIRI_INDIA
668
# define SUBLANG_KASHMIRI_INDIA 0x02
670
# ifndef SUBLANG_MALAY_MALAYSIA
671
# define SUBLANG_MALAY_MALAYSIA 0x01
673
# ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
674
# define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
676
# ifndef SUBLANG_NEPALI_INDIA
677
# define SUBLANG_NEPALI_INDIA 0x02
679
# ifndef SUBLANG_PUNJABI_INDIA
680
# define SUBLANG_PUNJABI_INDIA 0x01
682
# ifndef SUBLANG_ROMANIAN_ROMANIA
683
# define SUBLANG_ROMANIAN_ROMANIA 0x01
685
# ifndef SUBLANG_SERBIAN_LATIN
686
# define SUBLANG_SERBIAN_LATIN 0x02
688
# ifndef SUBLANG_SERBIAN_CYRILLIC
689
# define SUBLANG_SERBIAN_CYRILLIC 0x03
691
# ifndef SUBLANG_SINDHI_INDIA
692
# define SUBLANG_SINDHI_INDIA 0x00
694
# ifndef SUBLANG_SINDHI_PAKISTAN
695
# define SUBLANG_SINDHI_PAKISTAN 0x01
697
# ifndef SUBLANG_SPANISH_GUATEMALA
698
# define SUBLANG_SPANISH_GUATEMALA 0x04
700
# ifndef SUBLANG_SPANISH_COSTA_RICA
701
# define SUBLANG_SPANISH_COSTA_RICA 0x05
703
# ifndef SUBLANG_SPANISH_PANAMA
704
# define SUBLANG_SPANISH_PANAMA 0x06
706
# ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
707
# define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
709
# ifndef SUBLANG_SPANISH_VENEZUELA
710
# define SUBLANG_SPANISH_VENEZUELA 0x08
712
# ifndef SUBLANG_SPANISH_COLOMBIA
713
# define SUBLANG_SPANISH_COLOMBIA 0x09
715
# ifndef SUBLANG_SPANISH_PERU
716
# define SUBLANG_SPANISH_PERU 0x0a
718
# ifndef SUBLANG_SPANISH_ARGENTINA
719
# define SUBLANG_SPANISH_ARGENTINA 0x0b
721
# ifndef SUBLANG_SPANISH_ECUADOR
722
# define SUBLANG_SPANISH_ECUADOR 0x0c
724
# ifndef SUBLANG_SPANISH_CHILE
725
# define SUBLANG_SPANISH_CHILE 0x0d
727
# ifndef SUBLANG_SPANISH_URUGUAY
728
# define SUBLANG_SPANISH_URUGUAY 0x0e
730
# ifndef SUBLANG_SPANISH_PARAGUAY
731
# define SUBLANG_SPANISH_PARAGUAY 0x0f
733
# ifndef SUBLANG_SPANISH_BOLIVIA
734
# define SUBLANG_SPANISH_BOLIVIA 0x10
736
# ifndef SUBLANG_SPANISH_EL_SALVADOR
737
# define SUBLANG_SPANISH_EL_SALVADOR 0x11
739
# ifndef SUBLANG_SPANISH_HONDURAS
740
# define SUBLANG_SPANISH_HONDURAS 0x12
742
# ifndef SUBLANG_SPANISH_NICARAGUA
743
# define SUBLANG_SPANISH_NICARAGUA 0x13
745
# ifndef SUBLANG_SPANISH_PUERTO_RICO
746
# define SUBLANG_SPANISH_PUERTO_RICO 0x14
748
# ifndef SUBLANG_SWEDISH_FINLAND
749
# define SUBLANG_SWEDISH_FINLAND 0x02
751
# ifndef SUBLANG_TAMAZIGHT_ARABIC
752
# define SUBLANG_TAMAZIGHT_ARABIC 0x01
754
# ifndef SUBLANG_TAMAZIGHT_LATIN
755
# define SUBLANG_TAMAZIGHT_LATIN 0x02
757
# ifndef SUBLANG_TIGRINYA_ETHIOPIA
758
# define SUBLANG_TIGRINYA_ETHIOPIA 0x00
760
# ifndef SUBLANG_TIGRINYA_ERITREA
761
# define SUBLANG_TIGRINYA_ERITREA 0x01
763
# ifndef SUBLANG_URDU_PAKISTAN
764
# define SUBLANG_URDU_PAKISTAN 0x01
766
# ifndef SUBLANG_URDU_INDIA
767
# define SUBLANG_URDU_INDIA 0x02
769
# ifndef SUBLANG_UZBEK_LATIN
770
# define SUBLANG_UZBEK_LATIN 0x01
772
# ifndef SUBLANG_UZBEK_CYRILLIC
773
# define SUBLANG_UZBEK_CYRILLIC 0x02
777
/* Return an XPG style locale name language[_territory][@modifier].
76
#ifndef LANG_AFRIKAANS
77
#define LANG_AFRIKAANS 0x36
80
#define LANG_ALBANIAN 0x1c
83
#define LANG_AMHARIC 0x5e
86
#define LANG_ARABIC 0x01
89
#define LANG_ARMENIAN 0x2b
92
#define LANG_ASSAMESE 0x4d
95
#define LANG_AZERI 0x2c
98
#define LANG_BASQUE 0x2d
100
#ifndef LANG_BELARUSIAN
101
#define LANG_BELARUSIAN 0x23
104
#define LANG_BENGALI 0x45
107
#define LANG_BURMESE 0x55
109
#ifndef LANG_CAMBODIAN
110
#define LANG_CAMBODIAN 0x53
113
#define LANG_CATALAN 0x03
115
#ifndef LANG_CHEROKEE
116
#define LANG_CHEROKEE 0x5c
119
#define LANG_DIVEHI 0x65
122
#define LANG_EDO 0x66
124
#ifndef LANG_ESTONIAN
125
#define LANG_ESTONIAN 0x25
127
#ifndef LANG_FAEROESE
128
#define LANG_FAEROESE 0x38
131
#define LANG_FARSI 0x29
134
#define LANG_FRISIAN 0x62
136
#ifndef LANG_FULFULDE
137
#define LANG_FULFULDE 0x67
140
#define LANG_GAELIC 0x3c
142
#ifndef LANG_GALICIAN
143
#define LANG_GALICIAN 0x56
145
#ifndef LANG_GEORGIAN
146
#define LANG_GEORGIAN 0x37
149
#define LANG_GUARANI 0x74
151
#ifndef LANG_GUJARATI
152
#define LANG_GUJARATI 0x47
155
#define LANG_HAUSA 0x68
157
#ifndef LANG_HAWAIIAN
158
#define LANG_HAWAIIAN 0x75
161
#define LANG_HEBREW 0x0d
164
#define LANG_HINDI 0x39
167
#define LANG_IBIBIO 0x69
170
#define LANG_IGBO 0x70
172
#ifndef LANG_INDONESIAN
173
#define LANG_INDONESIAN 0x21
175
#ifndef LANG_INUKTITUT
176
#define LANG_INUKTITUT 0x5d
179
#define LANG_KANNADA 0x4b
182
#define LANG_KANURI 0x71
184
#ifndef LANG_KASHMIRI
185
#define LANG_KASHMIRI 0x60
188
#define LANG_KAZAK 0x3f
191
#define LANG_KONKANI 0x57
194
#define LANG_KYRGYZ 0x40
197
#define LANG_LAO 0x54
200
#define LANG_LATIN 0x76
203
#define LANG_LATVIAN 0x26
205
#ifndef LANG_LITHUANIAN
206
#define LANG_LITHUANIAN 0x27
208
#ifndef LANG_MACEDONIAN
209
#define LANG_MACEDONIAN 0x2f
212
#define LANG_MALAY 0x3e
214
#ifndef LANG_MALAYALAM
215
#define LANG_MALAYALAM 0x4c
218
#define LANG_MALTESE 0x3a
220
#ifndef LANG_MANIPURI
221
#define LANG_MANIPURI 0x58
224
#define LANG_MARATHI 0x4e
226
#ifndef LANG_MONGOLIAN
227
#define LANG_MONGOLIAN 0x50
230
#define LANG_NEPALI 0x61
233
#define LANG_ORIYA 0x48
236
#define LANG_OROMO 0x72
238
#ifndef LANG_PAPIAMENTU
239
#define LANG_PAPIAMENTU 0x79
242
#define LANG_PASHTO 0x63
245
#define LANG_PUNJABI 0x46
247
#ifndef LANG_RHAETO_ROMANCE
248
#define LANG_RHAETO_ROMANCE 0x17
251
#define LANG_SAAMI 0x3b
253
#ifndef LANG_SANSKRIT
254
#define LANG_SANSKRIT 0x4f
257
#define LANG_SERBIAN 0x1a
260
#define LANG_SINDHI 0x59
262
#ifndef LANG_SINHALESE
263
#define LANG_SINHALESE 0x5b
266
#define LANG_SLOVAK 0x1b
269
#define LANG_SOMALI 0x77
272
#define LANG_SORBIAN 0x2e
275
#define LANG_SUTU 0x30
278
#define LANG_SWAHILI 0x41
281
#define LANG_SYRIAC 0x5a
284
#define LANG_TAGALOG 0x64
287
#define LANG_TAJIK 0x28
289
#ifndef LANG_TAMAZIGHT
290
#define LANG_TAMAZIGHT 0x5f
293
#define LANG_TAMIL 0x49
296
#define LANG_TATAR 0x44
299
#define LANG_TELUGU 0x4a
302
#define LANG_THAI 0x1e
305
#define LANG_TIBETAN 0x51
307
#ifndef LANG_TIGRINYA
308
#define LANG_TIGRINYA 0x73
311
#define LANG_TSONGA 0x31
314
#define LANG_TSWANA 0x32
317
#define LANG_TURKMEN 0x42
319
#ifndef LANG_UKRAINIAN
320
#define LANG_UKRAINIAN 0x22
323
#define LANG_URDU 0x20
326
#define LANG_UZBEK 0x43
329
#define LANG_VENDA 0x33
331
#ifndef LANG_VIETNAMESE
332
#define LANG_VIETNAMESE 0x2a
335
#define LANG_WELSH 0x52
338
#define LANG_XHOSA 0x34
344
#define LANG_YIDDISH 0x3d
347
#define LANG_YORUBA 0x6a
350
#define LANG_ZULU 0x35
352
#ifndef SUBLANG_ARABIC_SAUDI_ARABIA
353
#define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
355
#ifndef SUBLANG_ARABIC_IRAQ
356
#define SUBLANG_ARABIC_IRAQ 0x02
358
#ifndef SUBLANG_ARABIC_EGYPT
359
#define SUBLANG_ARABIC_EGYPT 0x03
361
#ifndef SUBLANG_ARABIC_LIBYA
362
#define SUBLANG_ARABIC_LIBYA 0x04
364
#ifndef SUBLANG_ARABIC_ALGERIA
365
#define SUBLANG_ARABIC_ALGERIA 0x05
367
#ifndef SUBLANG_ARABIC_MOROCCO
368
#define SUBLANG_ARABIC_MOROCCO 0x06
370
#ifndef SUBLANG_ARABIC_TUNISIA
371
#define SUBLANG_ARABIC_TUNISIA 0x07
373
#ifndef SUBLANG_ARABIC_OMAN
374
#define SUBLANG_ARABIC_OMAN 0x08
376
#ifndef SUBLANG_ARABIC_YEMEN
377
#define SUBLANG_ARABIC_YEMEN 0x09
379
#ifndef SUBLANG_ARABIC_SYRIA
380
#define SUBLANG_ARABIC_SYRIA 0x0a
382
#ifndef SUBLANG_ARABIC_JORDAN
383
#define SUBLANG_ARABIC_JORDAN 0x0b
385
#ifndef SUBLANG_ARABIC_LEBANON
386
#define SUBLANG_ARABIC_LEBANON 0x0c
388
#ifndef SUBLANG_ARABIC_KUWAIT
389
#define SUBLANG_ARABIC_KUWAIT 0x0d
391
#ifndef SUBLANG_ARABIC_UAE
392
#define SUBLANG_ARABIC_UAE 0x0e
394
#ifndef SUBLANG_ARABIC_BAHRAIN
395
#define SUBLANG_ARABIC_BAHRAIN 0x0f
397
#ifndef SUBLANG_ARABIC_QATAR
398
#define SUBLANG_ARABIC_QATAR 0x10
400
#ifndef SUBLANG_AZERI_LATIN
401
#define SUBLANG_AZERI_LATIN 0x01
403
#ifndef SUBLANG_AZERI_CYRILLIC
404
#define SUBLANG_AZERI_CYRILLIC 0x02
406
#ifndef SUBLANG_BENGALI_INDIA
407
#define SUBLANG_BENGALI_INDIA 0x01
409
#ifndef SUBLANG_BENGALI_BANGLADESH
410
#define SUBLANG_BENGALI_BANGLADESH 0x02
412
#ifndef SUBLANG_CHINESE_MACAU
413
#define SUBLANG_CHINESE_MACAU 0x05
415
#ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
416
#define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
418
#ifndef SUBLANG_ENGLISH_JAMAICA
419
#define SUBLANG_ENGLISH_JAMAICA 0x08
421
#ifndef SUBLANG_ENGLISH_CARIBBEAN
422
#define SUBLANG_ENGLISH_CARIBBEAN 0x09
424
#ifndef SUBLANG_ENGLISH_BELIZE
425
#define SUBLANG_ENGLISH_BELIZE 0x0a
427
#ifndef SUBLANG_ENGLISH_TRINIDAD
428
#define SUBLANG_ENGLISH_TRINIDAD 0x0b
430
#ifndef SUBLANG_ENGLISH_ZIMBABWE
431
#define SUBLANG_ENGLISH_ZIMBABWE 0x0c
433
#ifndef SUBLANG_ENGLISH_PHILIPPINES
434
#define SUBLANG_ENGLISH_PHILIPPINES 0x0d
436
#ifndef SUBLANG_ENGLISH_INDONESIA
437
#define SUBLANG_ENGLISH_INDONESIA 0x0e
439
#ifndef SUBLANG_ENGLISH_HONGKONG
440
#define SUBLANG_ENGLISH_HONGKONG 0x0f
442
#ifndef SUBLANG_ENGLISH_INDIA
443
#define SUBLANG_ENGLISH_INDIA 0x10
445
#ifndef SUBLANG_ENGLISH_MALAYSIA
446
#define SUBLANG_ENGLISH_MALAYSIA 0x11
448
#ifndef SUBLANG_ENGLISH_SINGAPORE
449
#define SUBLANG_ENGLISH_SINGAPORE 0x12
451
#ifndef SUBLANG_FRENCH_LUXEMBOURG
452
#define SUBLANG_FRENCH_LUXEMBOURG 0x05
454
#ifndef SUBLANG_FRENCH_MONACO
455
#define SUBLANG_FRENCH_MONACO 0x06
457
#ifndef SUBLANG_FRENCH_WESTINDIES
458
#define SUBLANG_FRENCH_WESTINDIES 0x07
460
#ifndef SUBLANG_FRENCH_REUNION
461
#define SUBLANG_FRENCH_REUNION 0x08
463
#ifndef SUBLANG_FRENCH_CONGO
464
#define SUBLANG_FRENCH_CONGO 0x09
466
#ifndef SUBLANG_FRENCH_SENEGAL
467
#define SUBLANG_FRENCH_SENEGAL 0x0a
469
#ifndef SUBLANG_FRENCH_CAMEROON
470
#define SUBLANG_FRENCH_CAMEROON 0x0b
472
#ifndef SUBLANG_FRENCH_COTEDIVOIRE
473
#define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
475
#ifndef SUBLANG_FRENCH_MALI
476
#define SUBLANG_FRENCH_MALI 0x0d
478
#ifndef SUBLANG_FRENCH_MOROCCO
479
#define SUBLANG_FRENCH_MOROCCO 0x0e
481
#ifndef SUBLANG_FRENCH_HAITI
482
#define SUBLANG_FRENCH_HAITI 0x0f
484
#ifndef SUBLANG_GERMAN_LUXEMBOURG
485
#define SUBLANG_GERMAN_LUXEMBOURG 0x04
487
#ifndef SUBLANG_GERMAN_LIECHTENSTEIN
488
#define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
490
#ifndef SUBLANG_KASHMIRI_INDIA
491
#define SUBLANG_KASHMIRI_INDIA 0x02
493
#ifndef SUBLANG_MALAY_MALAYSIA
494
#define SUBLANG_MALAY_MALAYSIA 0x01
496
#ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
497
#define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
499
#ifndef SUBLANG_NEPALI_INDIA
500
#define SUBLANG_NEPALI_INDIA 0x02
502
#ifndef SUBLANG_PUNJABI_INDIA
503
#define SUBLANG_PUNJABI_INDIA 0x01
505
#ifndef SUBLANG_ROMANIAN_ROMANIA
506
#define SUBLANG_ROMANIAN_ROMANIA 0x01
508
#ifndef SUBLANG_SERBIAN_LATIN
509
#define SUBLANG_SERBIAN_LATIN 0x02
511
#ifndef SUBLANG_SERBIAN_CYRILLIC
512
#define SUBLANG_SERBIAN_CYRILLIC 0x03
514
#ifndef SUBLANG_SINDHI_INDIA
515
#define SUBLANG_SINDHI_INDIA 0x00
517
#ifndef SUBLANG_SINDHI_PAKISTAN
518
#define SUBLANG_SINDHI_PAKISTAN 0x01
520
#ifndef SUBLANG_SPANISH_GUATEMALA
521
#define SUBLANG_SPANISH_GUATEMALA 0x04
523
#ifndef SUBLANG_SPANISH_COSTA_RICA
524
#define SUBLANG_SPANISH_COSTA_RICA 0x05
526
#ifndef SUBLANG_SPANISH_PANAMA
527
#define SUBLANG_SPANISH_PANAMA 0x06
529
#ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
530
#define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
532
#ifndef SUBLANG_SPANISH_VENEZUELA
533
#define SUBLANG_SPANISH_VENEZUELA 0x08
535
#ifndef SUBLANG_SPANISH_COLOMBIA
536
#define SUBLANG_SPANISH_COLOMBIA 0x09
538
#ifndef SUBLANG_SPANISH_PERU
539
#define SUBLANG_SPANISH_PERU 0x0a
541
#ifndef SUBLANG_SPANISH_ARGENTINA
542
#define SUBLANG_SPANISH_ARGENTINA 0x0b
544
#ifndef SUBLANG_SPANISH_ECUADOR
545
#define SUBLANG_SPANISH_ECUADOR 0x0c
547
#ifndef SUBLANG_SPANISH_CHILE
548
#define SUBLANG_SPANISH_CHILE 0x0d
550
#ifndef SUBLANG_SPANISH_URUGUAY
551
#define SUBLANG_SPANISH_URUGUAY 0x0e
553
#ifndef SUBLANG_SPANISH_PARAGUAY
554
#define SUBLANG_SPANISH_PARAGUAY 0x0f
556
#ifndef SUBLANG_SPANISH_BOLIVIA
557
#define SUBLANG_SPANISH_BOLIVIA 0x10
559
#ifndef SUBLANG_SPANISH_EL_SALVADOR
560
#define SUBLANG_SPANISH_EL_SALVADOR 0x11
562
#ifndef SUBLANG_SPANISH_HONDURAS
563
#define SUBLANG_SPANISH_HONDURAS 0x12
565
#ifndef SUBLANG_SPANISH_NICARAGUA
566
#define SUBLANG_SPANISH_NICARAGUA 0x13
568
#ifndef SUBLANG_SPANISH_PUERTO_RICO
569
#define SUBLANG_SPANISH_PUERTO_RICO 0x14
571
#ifndef SUBLANG_SWEDISH_FINLAND
572
#define SUBLANG_SWEDISH_FINLAND 0x02
574
#ifndef SUBLANG_TAMAZIGHT_ARABIC
575
#define SUBLANG_TAMAZIGHT_ARABIC 0x01
577
#ifndef SUBLANG_TAMAZIGHT_LATIN
578
#define SUBLANG_TAMAZIGHT_LATIN 0x02
580
#ifndef SUBLANG_TIGRINYA_ETHIOPIA
581
#define SUBLANG_TIGRINYA_ETHIOPIA 0x00
583
#ifndef SUBLANG_TIGRINYA_ERITREA
584
#define SUBLANG_TIGRINYA_ERITREA 0x01
586
#ifndef SUBLANG_URDU_PAKISTAN
587
#define SUBLANG_URDU_PAKISTAN 0x01
589
#ifndef SUBLANG_URDU_INDIA
590
#define SUBLANG_URDU_INDIA 0x02
592
#ifndef SUBLANG_UZBEK_LATIN
593
#define SUBLANG_UZBEK_LATIN 0x01
595
#ifndef SUBLANG_UZBEK_CYRILLIC
596
#define SUBLANG_UZBEK_CYRILLIC 0x02
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
603
codeset. The result must not be freed; it is statically
781
605
static const char *
782
_nl_locale_name (const char *categoryname)
606
my_nl_locale_name (const char *categoryname)
784
608
const char *retval;
1274
1219
domain = jnlib_calloc (1, sizeof *domain);
1277
1222
jnlib_free (data);
1280
1225
domain->data = (char *) data;
1226
domain->data_native = (char *) data + size;
1281
1227
domain->must_swap = data->magic != MAGIC;
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))
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));
1244
/* This is an invalid revision. */
1246
jnlib_free (domain);
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)
1255
jnlib_free (domain);
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
1268
utf8_to_wchar (const char *string, size_t length, size_t *retlen)
1274
n = MultiByteToWideChar (CP_UTF8, 0, string, length, NULL, 0);
1275
if (n < 0 || (n+1) <= 0)
1278
nbytes = (size_t)(n+1) * sizeof(*result);
1279
if (nbytes / sizeof(*result) != (n+1))
1284
result = jnlib_malloc (nbytes);
1288
n = MultiByteToWideChar (CP_UTF8, 0, string, length, result, n);
1291
jnlib_free (result);
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
1304
wchar_to_native (const wchar_t *string, size_t length, size_t *retlen)
1309
n = WideCharToMultiByte (CP_ACP, 0, string, length, NULL, 0, NULL, NULL);
1310
if (n < 0 || (n+1) <= 0)
1313
result = jnlib_malloc (n+1);
1317
n = WideCharToMultiByte (CP_ACP, 0, string, length, result, n, NULL, NULL);
1320
jnlib_free (result);
1328
/* Convert UTF8 to the native codepage. Caller must free the return value. */
1330
utf8_to_native (const char *string, size_t length, size_t *retlen)
1336
wstring = utf8_to_wchar (string, length, &newlen);
1339
result = wchar_to_native (wstring, newlen, &newlen);
1340
jnlib_free (wstring);
1344
*retlen = result? newlen : 0;
1351
/* Specify that the DOMAINNAME message catalog will be found
1352
in DIRNAME rather than in the system locale data base. */
1354
bindtextdomain (const char *domainname, const char *dirname)
1356
struct loaded_domain *domain = NULL;
1357
const char *catval_full;
1361
/* DOMAINNAME is ignored. We only support one domain. */
1363
/* DIRNAME is "$INSTALLDIR\share\locale". */
1365
/* First find out the category value. */
1367
catval_full = my_nl_locale_name ("LC_MESSAGES");
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. */
1377
catval = jnlib_malloc (strlen (catval_full) + 1);
1380
strcpy (catval, catval_full);
1381
p = strchr (catval, '_');
1389
/* Now build the filename string. The complete filename is this:
1390
DIRNAME + \ + CATVAL + \LC_MESSAGES\ + DOMAINNAME + .mo */
1392
int len = strlen (dirname) + 1 + strlen (catval) + 13
1393
+ strlen (domainname) + 3 + 1;
1396
fname = jnlib_malloc (len);
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));
1297
default: /* This is an invalid revision. */
1299
jnlib_free( domain );
1399
jnlib_free (catval);
1303
/* Allocate an array to keep track of code page mappings. */
1304
domain->mapped = jnlib_calloc (1, domain->nstrings);
1305
if (!domain->mapped)
1308
jnlib_free (domain);
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
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.
1327
set_gettext_file ( const char *filename, const char *regkey )
1329
struct loaded_domain *domain = NULL;
1331
if ( filename && *filename )
1333
if ( filename[0] == '/'
1334
#ifdef HAVE_DRIVE_LETTERS
1335
|| ( isalpha(filename[0])
1336
&& filename[1] == ':'
1337
&& (filename[2] == '/' || filename[2] == '\\') )
1341
/* Absolute path - use it as is. */
1342
domain = load_domain( filename );
1344
else /* Standard. */
1346
char *pgmdir, *instdir, *langid, *fname;
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) )
1357
jnlib_free (pgmdir);
1358
return -1; /* Error getting the process' file name. */
1360
p = strrchr (pgmdir, DIRSEP_C);
1363
jnlib_free (pgmdir);
1364
return -1; /* Invalid file name returned. */
1371
for (pass=0; pass < 3 && !domain; pass++)
1373
jnlib_free (instdir);
1375
jnlib_free (langid);
1381
case 0: /* Pass 0: Try LANGUAGE. */
1382
if ((p = getenv ("LANGUAGE")) && *p)
1384
langid = jnlib_malloc (strlen (p)+1);
1388
/* We only make use of the first language
1389
given. Strip the rest. */
1390
p = strchr (langid, ':');
1397
case 1: /* Pass 1: Try registry. */
1400
instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE",
1402
"Install Directory");
1404
/* Try HKCU then HKLM. */
1405
langid = read_w32_registry_string (NULL,
1410
case 2: /* Pass 2: Try native local. */
1411
catval = _nl_locale_name ("LC_MESSAGES");
1413
!strcmp (catval, "C") || !strcmp (catval, "POSIX"))
1417
langid = jnlib_malloc (strlen (catval)+1);
1418
strcpy (langid, catval);
1427
continue; /* Next pass. */
1429
/* Strip stuff after a dot in case the user tried to
1430
enter the entire locale syntacs as usual for
1432
p = strchr (langid, '.');
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
1441
fname = jnlib_malloc (strlen (instdir? instdir:pgmdir) + 1
1442
+ strlen (filename) + 5
1443
+ strlen (langid) + 3 + 1);
1452
instdir?instdir:pgmdir),"\\"),
1453
filename), ".nls\\"),
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++)
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, '_')))
1472
if (domain && !the_langid)
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;
1483
jnlib_free (pgmdir);
1484
jnlib_free (instdir);
1485
jnlib_free (langid);
1495
struct overflow_space_s *os, *os2;
1497
jnlib_free ( the_domain->data );
1498
jnlib_free ( the_domain->mapped );
1499
for (os=the_domain->overflow_space; os; os = os2)
1504
jnlib_free ( the_domain );
1404
strcpy (p, dirname);
1405
p += strlen (dirname);
1408
p += strlen (catval);
1409
strcpy (p, "\\LC_MESSAGES\\");
1411
strcpy (p, domainname);
1412
p += strlen (domainname);
1416
domain = load_domain (fname);
1417
jnlib_free (catval);
1420
/* We should not be invoked twice, but this is how you would do
1421
it if it happened. */
1423
free_domain (the_domain);
1507
1424
the_domain = domain;
1426
/* For historic reasons we are not allowed to return a const char*. */
1427
return (char*)dirname;
1434
get_plural (const char *data, size_t datalen, unsigned long nplural)
1439
/* We only support the Germanic rule. */
1440
idx = (nplural == 1? 0 : 1);
1444
p = strchr (data, 0) + 1;
1445
if (p >= data+datalen)
1446
return "ERROR in GETTEXT (bad plural entry)";
1447
datalen -= (p-data);
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)
1515
1458
struct overflow_space_s *os;
1459
const char *trans; /* Pointer to the translated entry. */
1460
size_t translen; /* Length of that entry. */
1518
p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset);
1519
if (!domain->mapped[idx])
1521
size_t plen, buflen;
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);
1468
else if (!domain->mapped[idx])
1470
/* Not yet mapped. Map from utf-8 to native encoding now. */
1472
size_t plen_utf8, buflen;
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);
1479
buf = utf8_to_native (p_utf8, plen_utf8, &buflen);
1482
trans = "ERROR in GETTEXT MALLOC";
1485
else if (buflen <= plen_utf8 && buflen > 1)
1487
/* Copy into the DATA_NATIVE area. */
1527
buf = utf8_to_native (p, plen, -1);
1528
buflen = strlen (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;
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);
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;
1514
domain->mapped[idx] = 1;
1516
translen = os->length;
1547
p = "ERROR in GETTEXT MALLOC";
1520
trans = "ERROR in GETTEXT MALLOC";
1549
1524
jnlib_free (buf);
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)
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";
1558
return (const char*)p;
1535
translen = os->length;
1539
trans = "ERROR in GETTEXT (overflow space)\n";
1545
trans = (domain->data_native
1546
+ SWAPIT(domain->must_swap, domain->trans_tab[idx].offset));
1547
translen = domain->mapped[idx];
1550
if (use_plural && translen)
1551
return get_plural (trans, translen, nplural);
1564
gettext( const char *msgid )
1558
do_gettext (const char *msgid, const char *msgid2, unsigned long nplural)
1566
1560
struct loaded_domain *domain;
1561
uint32_t top, bottom, nstr;
1570
1563
if (!(domain = the_domain))
1571
1564
goto not_found;
1573
/* Locate the MSGID and its translation. */
1566
/* First try to use the hash table. */
1574
1567
if (domain->hash_size > 2 && domain->hash_tab)
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]);
1583
if ( !nstr ) /* Hash table entry is empty. */
1586
if (SWAPIT(domain->must_swap,
1587
domain->orig_tab[nstr - 1].length) == len
1589
domain->data + SWAPIT(domain->must_swap,
1590
domain->orig_tab[nstr-1].offset)))
1591
return get_string( domain, nstr - 1 );
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));
1575
while ( (nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx])) )
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))))
1585
return get_string (domain, nstr, !!msgid2, nplural);
1595
1588
if (idx >= domain->hash_size - incr)
1596
1589
idx -= domain->hash_size - incr;
1600
nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]);
1602
goto not_found; /* Hash table entry is empty. */
1604
if ( SWAPIT(domain->must_swap,
1605
domain->orig_tab[nstr - 1].length) == len
1608
+ SWAPIT(domain->must_swap,
1609
domain->orig_tab[nstr-1].offset)))
1610
return get_string( domain, nstr-1 );
1615
1595
/* Now we try the default method: binary search in the sorted array