mirrored from https://gitlab.winehq.org/wine/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
locale.c
5843 lines (5128 loc) · 191 KB
/
locale.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Locale support
*
* Copyright 1995 Martin von Loewis
* Copyright 1998 David Lee Lambert
* Copyright 2000 Julio César Gázquez
* Copyright 2003 Jon Griffiths
* Copyright 2005 Dmitry Timoshkov
* Copyright 2002, 2019 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <stdlib.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winnls.h"
#include "winuser.h"
#include "winternl.h"
#include "kernelbase.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(nls);
#define CALINFO_MAX_YEAR 2029
extern UINT CDECL __wine_get_unix_codepage(void);
extern const unsigned int collation_table[] DECLSPEC_HIDDEN;
static HANDLE kernel32_handle;
static const struct registry_value
{
DWORD lctype;
const WCHAR *name;
} registry_values[] =
{
{ LOCALE_ICALENDARTYPE, L"iCalendarType" },
{ LOCALE_ICURRDIGITS, L"iCurrDigits" },
{ LOCALE_ICURRENCY, L"iCurrency" },
{ LOCALE_IDIGITS, L"iDigits" },
{ LOCALE_IFIRSTDAYOFWEEK, L"iFirstDayOfWeek" },
{ LOCALE_IFIRSTWEEKOFYEAR, L"iFirstWeekOfYear" },
{ LOCALE_ILZERO, L"iLZero" },
{ LOCALE_IMEASURE, L"iMeasure" },
{ LOCALE_INEGCURR, L"iNegCurr" },
{ LOCALE_INEGNUMBER, L"iNegNumber" },
{ LOCALE_IPAPERSIZE, L"iPaperSize" },
{ LOCALE_ITIME, L"iTime" },
{ LOCALE_S1159, L"s1159" },
{ LOCALE_S2359, L"s2359" },
{ LOCALE_SCURRENCY, L"sCurrency" },
{ LOCALE_SDATE, L"sDate" },
{ LOCALE_SDECIMAL, L"sDecimal" },
{ LOCALE_SGROUPING, L"sGrouping" },
{ LOCALE_SLIST, L"sList" },
{ LOCALE_SLONGDATE, L"sLongDate" },
{ LOCALE_SMONDECIMALSEP, L"sMonDecimalSep" },
{ LOCALE_SMONGROUPING, L"sMonGrouping" },
{ LOCALE_SMONTHOUSANDSEP, L"sMonThousandSep" },
{ LOCALE_SNEGATIVESIGN, L"sNegativeSign" },
{ LOCALE_SPOSITIVESIGN, L"sPositiveSign" },
{ LOCALE_SSHORTDATE, L"sShortDate" },
{ LOCALE_STHOUSAND, L"sThousand" },
{ LOCALE_STIME, L"sTime" },
{ LOCALE_STIMEFORMAT, L"sTimeFormat" },
{ LOCALE_SYEARMONTH, L"sYearMonth" },
/* The following are not listed under MSDN as supported,
* but seem to be used and also stored in the registry.
*/
{ LOCALE_SNAME, L"LocaleName" },
{ LOCALE_ICOUNTRY, L"iCountry" },
{ LOCALE_IDATE, L"iDate" },
{ LOCALE_ILDATE, L"iLDate" },
{ LOCALE_ITLZERO, L"iTLZero" },
{ LOCALE_SCOUNTRY, L"sCountry" },
{ LOCALE_SABBREVLANGNAME, L"sLanguage" },
{ LOCALE_IDIGITSUBSTITUTION, L"Numshape" },
{ LOCALE_SNATIVEDIGITS, L"sNativeDigits" },
{ LOCALE_ITIMEMARKPOSN, L"iTimePrefix" },
};
static WCHAR *registry_cache[ARRAY_SIZE(registry_values)];
static const struct { UINT cp; const WCHAR *name; } codepage_names[] =
{
{ 37, L"IBM EBCDIC US Canada" },
{ 424, L"IBM EBCDIC Hebrew" },
{ 437, L"OEM United States" },
{ 500, L"IBM EBCDIC International" },
{ 708, L"Arabic ASMO" },
{ 737, L"OEM Greek 437G" },
{ 775, L"OEM Baltic" },
{ 850, L"OEM Multilingual Latin 1" },
{ 852, L"OEM Slovak Latin 2" },
{ 855, L"OEM Cyrillic" },
{ 856, L"Hebrew PC" },
{ 857, L"OEM Turkish" },
{ 860, L"OEM Portuguese" },
{ 861, L"OEM Icelandic" },
{ 862, L"OEM Hebrew" },
{ 863, L"OEM Canadian French" },
{ 864, L"OEM Arabic" },
{ 865, L"OEM Nordic" },
{ 866, L"OEM Russian" },
{ 869, L"OEM Greek" },
{ 874, L"ANSI/OEM Thai" },
{ 875, L"IBM EBCDIC Greek" },
{ 878, L"Russian KOI8" },
{ 932, L"ANSI/OEM Japanese Shift-JIS" },
{ 936, L"ANSI/OEM Simplified Chinese GBK" },
{ 949, L"ANSI/OEM Korean Unified Hangul" },
{ 950, L"ANSI/OEM Traditional Chinese Big5" },
{ 1006, L"IBM Arabic" },
{ 1026, L"IBM EBCDIC Latin 5 Turkish" },
{ 1250, L"ANSI Eastern Europe" },
{ 1251, L"ANSI Cyrillic" },
{ 1252, L"ANSI Latin 1" },
{ 1253, L"ANSI Greek" },
{ 1254, L"ANSI Turkish" },
{ 1255, L"ANSI Hebrew" },
{ 1256, L"ANSI Arabic" },
{ 1257, L"ANSI Baltic" },
{ 1258, L"ANSI/OEM Viet Nam" },
{ 1361, L"Korean Johab" },
{ 10000, L"Mac Roman" },
{ 10001, L"Mac Japanese" },
{ 10002, L"Mac Traditional Chinese" },
{ 10003, L"Mac Korean" },
{ 10004, L"Mac Arabic" },
{ 10005, L"Mac Hebrew" },
{ 10006, L"Mac Greek" },
{ 10007, L"Mac Cyrillic" },
{ 10008, L"Mac Simplified Chinese" },
{ 10010, L"Mac Romanian" },
{ 10017, L"Mac Ukrainian" },
{ 10021, L"Mac Thai" },
{ 10029, L"Mac Latin 2" },
{ 10079, L"Mac Icelandic" },
{ 10081, L"Mac Turkish" },
{ 10082, L"Mac Croatian" },
{ 20127, L"US-ASCII (7bit)" },
{ 20866, L"Russian KOI8" },
{ 20932, L"EUC-JP" },
{ 21866, L"Ukrainian KOI8" },
{ 28591, L"ISO 8859-1 Latin 1" },
{ 28592, L"ISO 8859-2 Latin 2 (East European)" },
{ 28593, L"ISO 8859-3 Latin 3 (South European)" },
{ 28594, L"ISO 8859-4 Latin 4 (Baltic old)" },
{ 28595, L"ISO 8859-5 Cyrillic" },
{ 28596, L"ISO 8859-6 Arabic" },
{ 28597, L"ISO 8859-7 Greek" },
{ 28598, L"ISO 8859-8 Hebrew" },
{ 28599, L"ISO 8859-9 Latin 5 (Turkish)" },
{ 28600, L"ISO 8859-10 Latin 6 (Nordic)" },
{ 28601, L"ISO 8859-11 Latin (Thai)" },
{ 28603, L"ISO 8859-13 Latin 7 (Baltic)" },
{ 28604, L"ISO 8859-14 Latin 8 (Celtic)" },
{ 28605, L"ISO 8859-15 Latin 9 (Euro)" },
{ 28606, L"ISO 8859-16 Latin 10 (Balkan)" },
{ 65000, L"Unicode (UTF-7)" },
{ 65001, L"Unicode (UTF-8)" }
};
/* Unicode expanded ligatures */
static const WCHAR ligatures[][5] =
{
{ 0x00c6, 'A','E',0 },
{ 0x00de, 'T','H',0 },
{ 0x00df, 's','s',0 },
{ 0x00e6, 'a','e',0 },
{ 0x00fe, 't','h',0 },
{ 0x0132, 'I','J',0 },
{ 0x0133, 'i','j',0 },
{ 0x0152, 'O','E',0 },
{ 0x0153, 'o','e',0 },
{ 0x01c4, 'D',0x017d,0 },
{ 0x01c5, 'D',0x017e,0 },
{ 0x01c6, 'd',0x017e,0 },
{ 0x01c7, 'L','J',0 },
{ 0x01c8, 'L','j',0 },
{ 0x01c9, 'l','j',0 },
{ 0x01ca, 'N','J',0 },
{ 0x01cb, 'N','j',0 },
{ 0x01cc, 'n','j',0 },
{ 0x01e2, 0x0100,0x0112,0 },
{ 0x01e3, 0x0101,0x0113,0 },
{ 0x01f1, 'D','Z',0 },
{ 0x01f2, 'D','z',0 },
{ 0x01f3, 'd','z',0 },
{ 0x01fc, 0x00c1,0x00c9,0 },
{ 0x01fd, 0x00e1,0x00e9,0 },
{ 0x05f0, 0x05d5,0x05d5,0 },
{ 0x05f1, 0x05d5,0x05d9,0 },
{ 0x05f2, 0x05d9,0x05d9,0 },
{ 0xfb00, 'f','f',0 },
{ 0xfb01, 'f','i',0 },
{ 0xfb02, 'f','l',0 },
{ 0xfb03, 'f','f','i',0 },
{ 0xfb04, 'f','f','l',0 },
{ 0xfb05, 0x017f,'t',0 },
{ 0xfb06, 's','t',0 },
};
enum locationkind { LOCATION_NATION = 0, LOCATION_REGION, LOCATION_BOTH };
struct geoinfo
{
GEOID id;
WCHAR iso2W[3];
WCHAR iso3W[4];
GEOID parent;
int uncode;
enum locationkind kind;
};
static const struct geoinfo geoinfodata[] =
{
{ 2, L"AG", L"ATG", 10039880, 28 }, /* Antigua and Barbuda */
{ 3, L"AF", L"AFG", 47614, 4 }, /* Afghanistan */
{ 4, L"DZ", L"DZA", 42487, 12 }, /* Algeria */
{ 5, L"AZ", L"AZE", 47611, 31 }, /* Azerbaijan */
{ 6, L"AL", L"ALB", 47610, 8 }, /* Albania */
{ 7, L"AM", L"ARM", 47611, 51 }, /* Armenia */
{ 8, L"AD", L"AND", 47610, 20 }, /* Andorra */
{ 9, L"AO", L"AGO", 42484, 24 }, /* Angola */
{ 10, L"AS", L"ASM", 26286, 16 }, /* American Samoa */
{ 11, L"AR", L"ARG", 31396, 32 }, /* Argentina */
{ 12, L"AU", L"AUS", 10210825, 36 }, /* Australia */
{ 14, L"AT", L"AUT", 10210824, 40 }, /* Austria */
{ 17, L"BH", L"BHR", 47611, 48 }, /* Bahrain */
{ 18, L"BB", L"BRB", 10039880, 52 }, /* Barbados */
{ 19, L"BW", L"BWA", 10039883, 72 }, /* Botswana */
{ 20, L"BM", L"BMU", 23581, 60 }, /* Bermuda */
{ 21, L"BE", L"BEL", 10210824, 56 }, /* Belgium */
{ 22, L"BS", L"BHS", 10039880, 44 }, /* Bahamas, The */
{ 23, L"BD", L"BGD", 47614, 50 }, /* Bangladesh */
{ 24, L"BZ", L"BLZ", 27082, 84 }, /* Belize */
{ 25, L"BA", L"BIH", 47610, 70 }, /* Bosnia and Herzegovina */
{ 26, L"BO", L"BOL", 31396, 68 }, /* Bolivia */
{ 27, L"MM", L"MMR", 47599, 104 }, /* Myanmar */
{ 28, L"BJ", L"BEN", 42483, 204 }, /* Benin */
{ 29, L"BY", L"BLR", 47609, 112 }, /* Belarus */
{ 30, L"SB", L"SLB", 20900, 90 }, /* Solomon Islands */
{ 32, L"BR", L"BRA", 31396, 76 }, /* Brazil */
{ 34, L"BT", L"BTN", 47614, 64 }, /* Bhutan */
{ 35, L"BG", L"BGR", 47609, 100 }, /* Bulgaria */
{ 37, L"BN", L"BRN", 47599, 96 }, /* Brunei */
{ 38, L"BI", L"BDI", 47603, 108 }, /* Burundi */
{ 39, L"CA", L"CAN", 23581, 124 }, /* Canada */
{ 40, L"KH", L"KHM", 47599, 116 }, /* Cambodia */
{ 41, L"TD", L"TCD", 42484, 148 }, /* Chad */
{ 42, L"LK", L"LKA", 47614, 144 }, /* Sri Lanka */
{ 43, L"CG", L"COG", 42484, 178 }, /* Congo */
{ 44, L"CD", L"COD", 42484, 180 }, /* Congo (DRC) */
{ 45, L"CN", L"CHN", 47600, 156 }, /* China */
{ 46, L"CL", L"CHL", 31396, 152 }, /* Chile */
{ 49, L"CM", L"CMR", 42484, 120 }, /* Cameroon */
{ 50, L"KM", L"COM", 47603, 174 }, /* Comoros */
{ 51, L"CO", L"COL", 31396, 170 }, /* Colombia */
{ 54, L"CR", L"CRI", 27082, 188 }, /* Costa Rica */
{ 55, L"CF", L"CAF", 42484, 140 }, /* Central African Republic */
{ 56, L"CU", L"CUB", 10039880, 192 }, /* Cuba */
{ 57, L"CV", L"CPV", 42483, 132 }, /* Cape Verde */
{ 59, L"CY", L"CYP", 47611, 196 }, /* Cyprus */
{ 61, L"DK", L"DNK", 10039882, 208 }, /* Denmark */
{ 62, L"DJ", L"DJI", 47603, 262 }, /* Djibouti */
{ 63, L"DM", L"DMA", 10039880, 212 }, /* Dominica */
{ 65, L"DO", L"DOM", 10039880, 214 }, /* Dominican Republic */
{ 66, L"EC", L"ECU", 31396, 218 }, /* Ecuador */
{ 67, L"EG", L"EGY", 42487, 818 }, /* Egypt */
{ 68, L"IE", L"IRL", 10039882, 372 }, /* Ireland */
{ 69, L"GQ", L"GNQ", 42484, 226 }, /* Equatorial Guinea */
{ 70, L"EE", L"EST", 10039882, 233 }, /* Estonia */
{ 71, L"ER", L"ERI", 47603, 232 }, /* Eritrea */
{ 72, L"SV", L"SLV", 27082, 222 }, /* El Salvador */
{ 73, L"ET", L"ETH", 47603, 231 }, /* Ethiopia */
{ 75, L"CZ", L"CZE", 47609, 203 }, /* Czech Republic */
{ 77, L"FI", L"FIN", 10039882, 246 }, /* Finland */
{ 78, L"FJ", L"FJI", 20900, 242 }, /* Fiji Islands */
{ 80, L"FM", L"FSM", 21206, 583 }, /* Micronesia */
{ 81, L"FO", L"FRO", 10039882, 234 }, /* Faroe Islands */
{ 84, L"FR", L"FRA", 10210824, 250 }, /* France */
{ 86, L"GM", L"GMB", 42483, 270 }, /* Gambia, The */
{ 87, L"GA", L"GAB", 42484, 266 }, /* Gabon */
{ 88, L"GE", L"GEO", 47611, 268 }, /* Georgia */
{ 89, L"GH", L"GHA", 42483, 288 }, /* Ghana */
{ 90, L"GI", L"GIB", 47610, 292 }, /* Gibraltar */
{ 91, L"GD", L"GRD", 10039880, 308 }, /* Grenada */
{ 93, L"GL", L"GRL", 23581, 304 }, /* Greenland */
{ 94, L"DE", L"DEU", 10210824, 276 }, /* Germany */
{ 98, L"GR", L"GRC", 47610, 300 }, /* Greece */
{ 99, L"GT", L"GTM", 27082, 320 }, /* Guatemala */
{ 100, L"GN", L"GIN", 42483, 324 }, /* Guinea */
{ 101, L"GY", L"GUY", 31396, 328 }, /* Guyana */
{ 103, L"HT", L"HTI", 10039880, 332 }, /* Haiti */
{ 104, L"HK", L"HKG", 47600, 344 }, /* Hong Kong S.A.R. */
{ 106, L"HN", L"HND", 27082, 340 }, /* Honduras */
{ 108, L"HR", L"HRV", 47610, 191 }, /* Croatia */
{ 109, L"HU", L"HUN", 47609, 348 }, /* Hungary */
{ 110, L"IS", L"ISL", 10039882, 352 }, /* Iceland */
{ 111, L"ID", L"IDN", 47599, 360 }, /* Indonesia */
{ 113, L"IN", L"IND", 47614, 356 }, /* India */
{ 114, L"IO", L"IOT", 39070, 86 }, /* British Indian Ocean Territory */
{ 116, L"IR", L"IRN", 47614, 364 }, /* Iran */
{ 117, L"IL", L"ISR", 47611, 376 }, /* Israel */
{ 118, L"IT", L"ITA", 47610, 380 }, /* Italy */
{ 119, L"CI", L"CIV", 42483, 384 }, /* Côte d'Ivoire */
{ 121, L"IQ", L"IRQ", 47611, 368 }, /* Iraq */
{ 122, L"JP", L"JPN", 47600, 392 }, /* Japan */
{ 124, L"JM", L"JAM", 10039880, 388 }, /* Jamaica */
{ 125, L"SJ", L"SJM", 10039882, 744 }, /* Jan Mayen */
{ 126, L"JO", L"JOR", 47611, 400 }, /* Jordan */
{ 127, L"XX", L"XX", 161832256 }, /* Johnston Atoll */
{ 129, L"KE", L"KEN", 47603, 404 }, /* Kenya */
{ 130, L"KG", L"KGZ", 47590, 417 }, /* Kyrgyzstan */
{ 131, L"KP", L"PRK", 47600, 408 }, /* North Korea */
{ 133, L"KI", L"KIR", 21206, 296 }, /* Kiribati */
{ 134, L"KR", L"KOR", 47600, 410 }, /* Korea */
{ 136, L"KW", L"KWT", 47611, 414 }, /* Kuwait */
{ 137, L"KZ", L"KAZ", 47590, 398 }, /* Kazakhstan */
{ 138, L"LA", L"LAO", 47599, 418 }, /* Laos */
{ 139, L"LB", L"LBN", 47611, 422 }, /* Lebanon */
{ 140, L"LV", L"LVA", 10039882, 428 }, /* Latvia */
{ 141, L"LT", L"LTU", 10039882, 440 }, /* Lithuania */
{ 142, L"LR", L"LBR", 42483, 430 }, /* Liberia */
{ 143, L"SK", L"SVK", 47609, 703 }, /* Slovakia */
{ 145, L"LI", L"LIE", 10210824, 438 }, /* Liechtenstein */
{ 146, L"LS", L"LSO", 10039883, 426 }, /* Lesotho */
{ 147, L"LU", L"LUX", 10210824, 442 }, /* Luxembourg */
{ 148, L"LY", L"LBY", 42487, 434 }, /* Libya */
{ 149, L"MG", L"MDG", 47603, 450 }, /* Madagascar */
{ 151, L"MO", L"MAC", 47600, 446 }, /* Macao S.A.R. */
{ 152, L"MD", L"MDA", 47609, 498 }, /* Moldova */
{ 154, L"MN", L"MNG", 47600, 496 }, /* Mongolia */
{ 156, L"MW", L"MWI", 47603, 454 }, /* Malawi */
{ 157, L"ML", L"MLI", 42483, 466 }, /* Mali */
{ 158, L"MC", L"MCO", 10210824, 492 }, /* Monaco */
{ 159, L"MA", L"MAR", 42487, 504 }, /* Morocco */
{ 160, L"MU", L"MUS", 47603, 480 }, /* Mauritius */
{ 162, L"MR", L"MRT", 42483, 478 }, /* Mauritania */
{ 163, L"MT", L"MLT", 47610, 470 }, /* Malta */
{ 164, L"OM", L"OMN", 47611, 512 }, /* Oman */
{ 165, L"MV", L"MDV", 47614, 462 }, /* Maldives */
{ 166, L"MX", L"MEX", 27082, 484 }, /* Mexico */
{ 167, L"MY", L"MYS", 47599, 458 }, /* Malaysia */
{ 168, L"MZ", L"MOZ", 47603, 508 }, /* Mozambique */
{ 173, L"NE", L"NER", 42483, 562 }, /* Niger */
{ 174, L"VU", L"VUT", 20900, 548 }, /* Vanuatu */
{ 175, L"NG", L"NGA", 42483, 566 }, /* Nigeria */
{ 176, L"NL", L"NLD", 10210824, 528 }, /* Netherlands */
{ 177, L"NO", L"NOR", 10039882, 578 }, /* Norway */
{ 178, L"NP", L"NPL", 47614, 524 }, /* Nepal */
{ 180, L"NR", L"NRU", 21206, 520 }, /* Nauru */
{ 181, L"SR", L"SUR", 31396, 740 }, /* Suriname */
{ 182, L"NI", L"NIC", 27082, 558 }, /* Nicaragua */
{ 183, L"NZ", L"NZL", 10210825, 554 }, /* New Zealand */
{ 184, L"PS", L"PSE", 47611, 275 }, /* Palestinian Authority */
{ 185, L"PY", L"PRY", 31396, 600 }, /* Paraguay */
{ 187, L"PE", L"PER", 31396, 604 }, /* Peru */
{ 190, L"PK", L"PAK", 47614, 586 }, /* Pakistan */
{ 191, L"PL", L"POL", 47609, 616 }, /* Poland */
{ 192, L"PA", L"PAN", 27082, 591 }, /* Panama */
{ 193, L"PT", L"PRT", 47610, 620 }, /* Portugal */
{ 194, L"PG", L"PNG", 20900, 598 }, /* Papua New Guinea */
{ 195, L"PW", L"PLW", 21206, 585 }, /* Palau */
{ 196, L"GW", L"GNB", 42483, 624 }, /* Guinea-Bissau */
{ 197, L"QA", L"QAT", 47611, 634 }, /* Qatar */
{ 198, L"RE", L"REU", 47603, 638 }, /* Reunion */
{ 199, L"MH", L"MHL", 21206, 584 }, /* Marshall Islands */
{ 200, L"RO", L"ROU", 47609, 642 }, /* Romania */
{ 201, L"PH", L"PHL", 47599, 608 }, /* Philippines */
{ 202, L"PR", L"PRI", 10039880, 630 }, /* Puerto Rico */
{ 203, L"RU", L"RUS", 47609, 643 }, /* Russia */
{ 204, L"RW", L"RWA", 47603, 646 }, /* Rwanda */
{ 205, L"SA", L"SAU", 47611, 682 }, /* Saudi Arabia */
{ 206, L"PM", L"SPM", 23581, 666 }, /* St. Pierre and Miquelon */
{ 207, L"KN", L"KNA", 10039880, 659 }, /* St. Kitts and Nevis */
{ 208, L"SC", L"SYC", 47603, 690 }, /* Seychelles */
{ 209, L"ZA", L"ZAF", 10039883, 710 }, /* South Africa */
{ 210, L"SN", L"SEN", 42483, 686 }, /* Senegal */
{ 212, L"SI", L"SVN", 47610, 705 }, /* Slovenia */
{ 213, L"SL", L"SLE", 42483, 694 }, /* Sierra Leone */
{ 214, L"SM", L"SMR", 47610, 674 }, /* San Marino */
{ 215, L"SG", L"SGP", 47599, 702 }, /* Singapore */
{ 216, L"SO", L"SOM", 47603, 706 }, /* Somalia */
{ 217, L"ES", L"ESP", 47610, 724 }, /* Spain */
{ 218, L"LC", L"LCA", 10039880, 662 }, /* St. Lucia */
{ 219, L"SD", L"SDN", 42487, 736 }, /* Sudan */
{ 220, L"SJ", L"SJM", 10039882, 744 }, /* Svalbard */
{ 221, L"SE", L"SWE", 10039882, 752 }, /* Sweden */
{ 222, L"SY", L"SYR", 47611, 760 }, /* Syria */
{ 223, L"CH", L"CHE", 10210824, 756 }, /* Switzerland */
{ 224, L"AE", L"ARE", 47611, 784 }, /* United Arab Emirates */
{ 225, L"TT", L"TTO", 10039880, 780 }, /* Trinidad and Tobago */
{ 227, L"TH", L"THA", 47599, 764 }, /* Thailand */
{ 228, L"TJ", L"TJK", 47590, 762 }, /* Tajikistan */
{ 231, L"TO", L"TON", 26286, 776 }, /* Tonga */
{ 232, L"TG", L"TGO", 42483, 768 }, /* Togo */
{ 233, L"ST", L"STP", 42484, 678 }, /* São Tomé and Príncipe */
{ 234, L"TN", L"TUN", 42487, 788 }, /* Tunisia */
{ 235, L"TR", L"TUR", 47611, 792 }, /* Turkey */
{ 236, L"TV", L"TUV", 26286, 798 }, /* Tuvalu */
{ 237, L"TW", L"TWN", 47600, 158 }, /* Taiwan */
{ 238, L"TM", L"TKM", 47590, 795 }, /* Turkmenistan */
{ 239, L"TZ", L"TZA", 47603, 834 }, /* Tanzania */
{ 240, L"UG", L"UGA", 47603, 800 }, /* Uganda */
{ 241, L"UA", L"UKR", 47609, 804 }, /* Ukraine */
{ 242, L"GB", L"GBR", 10039882, 826 }, /* United Kingdom */
{ 244, L"US", L"USA", 23581, 840 }, /* United States */
{ 245, L"BF", L"BFA", 42483, 854 }, /* Burkina Faso */
{ 246, L"UY", L"URY", 31396, 858 }, /* Uruguay */
{ 247, L"UZ", L"UZB", 47590, 860 }, /* Uzbekistan */
{ 248, L"VC", L"VCT", 10039880, 670 }, /* St. Vincent and the Grenadines */
{ 249, L"VE", L"VEN", 31396, 862 }, /* Bolivarian Republic of Venezuela */
{ 251, L"VN", L"VNM", 47599, 704 }, /* Vietnam */
{ 252, L"VI", L"VIR", 10039880, 850 }, /* Virgin Islands */
{ 253, L"VA", L"VAT", 47610, 336 }, /* Vatican City */
{ 254, L"NA", L"NAM", 10039883, 516 }, /* Namibia */
{ 257, L"EH", L"ESH", 42487, 732 }, /* Western Sahara (disputed) */
{ 258, L"XX", L"XX", 161832256 }, /* Wake Island */
{ 259, L"WS", L"WSM", 26286, 882 }, /* Samoa */
{ 260, L"SZ", L"SWZ", 10039883, 748 }, /* Swaziland */
{ 261, L"YE", L"YEM", 47611, 887 }, /* Yemen */
{ 263, L"ZM", L"ZMB", 47603, 894 }, /* Zambia */
{ 264, L"ZW", L"ZWE", 47603, 716 }, /* Zimbabwe */
{ 269, L"CS", L"SCG", 47610, 891 }, /* Serbia and Montenegro (Former) */
{ 270, L"ME", L"MNE", 47610, 499 }, /* Montenegro */
{ 271, L"RS", L"SRB", 47610, 688 }, /* Serbia */
{ 273, L"CW", L"CUW", 10039880, 531 }, /* Curaçao */
{ 276, L"SS", L"SSD", 42487, 728 }, /* South Sudan */
{ 300, L"AI", L"AIA", 10039880, 660 }, /* Anguilla */
{ 301, L"AQ", L"ATA", 39070, 10 }, /* Antarctica */
{ 302, L"AW", L"ABW", 10039880, 533 }, /* Aruba */
{ 303, L"XX", L"XX", 343 }, /* Ascension Island */
{ 304, L"XX", L"XX", 10210825 }, /* Ashmore and Cartier Islands */
{ 305, L"XX", L"XX", 161832256 }, /* Baker Island */
{ 306, L"BV", L"BVT", 39070, 74 }, /* Bouvet Island */
{ 307, L"KY", L"CYM", 10039880, 136 }, /* Cayman Islands */
{ 308, L"XX", L"XX", 10210824, 830, LOCATION_BOTH }, /* Channel Islands */
{ 309, L"CX", L"CXR", 12, 162 }, /* Christmas Island */
{ 310, L"XX", L"XX", 27114 }, /* Clipperton Island */
{ 311, L"CC", L"CCK", 10210825, 166 }, /* Cocos (Keeling) Islands */
{ 312, L"CK", L"COK", 26286, 184 }, /* Cook Islands */
{ 313, L"XX", L"XX", 10210825 }, /* Coral Sea Islands */
{ 314, L"XX", L"XX", 114 }, /* Diego Garcia */
{ 315, L"FK", L"FLK", 31396, 238 }, /* Falkland Islands (Islas Malvinas) */
{ 317, L"GF", L"GUF", 31396, 254 }, /* French Guiana */
{ 318, L"PF", L"PYF", 26286, 258 }, /* French Polynesia */
{ 319, L"TF", L"ATF", 39070, 260 }, /* French Southern and Antarctic Lands */
{ 321, L"GP", L"GLP", 10039880, 312 }, /* Guadeloupe */
{ 322, L"GU", L"GUM", 21206, 316 }, /* Guam */
{ 323, L"XX", L"XX", 39070 }, /* Guantanamo Bay */
{ 324, L"GG", L"GGY", 308, 831 }, /* Guernsey */
{ 325, L"HM", L"HMD", 39070, 334 }, /* Heard Island and McDonald Islands */
{ 326, L"XX", L"XX", 161832256 }, /* Howland Island */
{ 327, L"XX", L"XX", 161832256 }, /* Jarvis Island */
{ 328, L"JE", L"JEY", 308, 832 }, /* Jersey */
{ 329, L"XX", L"XX", 161832256 }, /* Kingman Reef */
{ 330, L"MQ", L"MTQ", 10039880, 474 }, /* Martinique */
{ 331, L"YT", L"MYT", 47603, 175 }, /* Mayotte */
{ 332, L"MS", L"MSR", 10039880, 500 }, /* Montserrat */
{ 333, L"AN", L"ANT", 10039880, 530, LOCATION_BOTH }, /* Netherlands Antilles (Former) */
{ 334, L"NC", L"NCL", 20900, 540 }, /* New Caledonia */
{ 335, L"NU", L"NIU", 26286, 570 }, /* Niue */
{ 336, L"NF", L"NFK", 10210825, 574 }, /* Norfolk Island */
{ 337, L"MP", L"MNP", 21206, 580 }, /* Northern Mariana Islands */
{ 338, L"XX", L"XX", 161832256 }, /* Palmyra Atoll */
{ 339, L"PN", L"PCN", 26286, 612 }, /* Pitcairn Islands */
{ 340, L"XX", L"XX", 337 }, /* Rota Island */
{ 341, L"XX", L"XX", 337 }, /* Saipan */
{ 342, L"GS", L"SGS", 39070, 239 }, /* South Georgia and the South Sandwich Islands */
{ 343, L"SH", L"SHN", 42483, 654 }, /* St. Helena */
{ 346, L"XX", L"XX", 337 }, /* Tinian Island */
{ 347, L"TK", L"TKL", 26286, 772 }, /* Tokelau */
{ 348, L"XX", L"XX", 343 }, /* Tristan da Cunha */
{ 349, L"TC", L"TCA", 10039880, 796 }, /* Turks and Caicos Islands */
{ 351, L"VG", L"VGB", 10039880, 92 }, /* Virgin Islands, British */
{ 352, L"WF", L"WLF", 26286, 876 }, /* Wallis and Futuna */
{ 742, L"XX", L"XX", 39070, 2, LOCATION_REGION }, /* Africa */
{ 2129, L"XX", L"XX", 39070, 142, LOCATION_REGION }, /* Asia */
{ 10541, L"XX", L"XX", 39070, 150, LOCATION_REGION }, /* Europe */
{ 15126, L"IM", L"IMN", 10039882, 833 }, /* Man, Isle of */
{ 19618, L"MK", L"MKD", 47610, 807 }, /* Macedonia, Former Yugoslav Republic of */
{ 20900, L"XX", L"XX", 27114, 54, LOCATION_REGION }, /* Melanesia */
{ 21206, L"XX", L"XX", 27114, 57, LOCATION_REGION }, /* Micronesia */
{ 21242, L"XX", L"XX", 161832256 }, /* Midway Islands */
{ 23581, L"XX", L"XX", 10026358, 21, LOCATION_REGION }, /* Northern America */
{ 26286, L"XX", L"XX", 27114, 61, LOCATION_REGION }, /* Polynesia */
{ 27082, L"XX", L"XX", 161832257, 13, LOCATION_REGION }, /* Central America */
{ 27114, L"XX", L"XX", 39070, 9, LOCATION_REGION }, /* Oceania */
{ 30967, L"SX", L"SXM", 10039880, 534 }, /* Sint Maarten (Dutch part) */
{ 31396, L"XX", L"XX", 161832257, 5, LOCATION_REGION }, /* South America */
{ 31706, L"MF", L"MAF", 10039880, 663 }, /* Saint Martin (French part) */
{ 39070, L"XX", L"XX", 39070, 1, LOCATION_REGION }, /* World */
{ 42483, L"XX", L"XX", 742, 11, LOCATION_REGION }, /* Western Africa */
{ 42484, L"XX", L"XX", 742, 17, LOCATION_REGION }, /* Middle Africa */
{ 42487, L"XX", L"XX", 742, 15, LOCATION_REGION }, /* Northern Africa */
{ 47590, L"XX", L"XX", 2129, 143, LOCATION_REGION }, /* Central Asia */
{ 47599, L"XX", L"XX", 2129, 35, LOCATION_REGION }, /* South-Eastern Asia */
{ 47600, L"XX", L"XX", 2129, 30, LOCATION_REGION }, /* Eastern Asia */
{ 47603, L"XX", L"XX", 742, 14, LOCATION_REGION }, /* Eastern Africa */
{ 47609, L"XX", L"XX", 10541, 151, LOCATION_REGION }, /* Eastern Europe */
{ 47610, L"XX", L"XX", 10541, 39, LOCATION_REGION }, /* Southern Europe */
{ 47611, L"XX", L"XX", 2129, 145, LOCATION_REGION }, /* Middle East */
{ 47614, L"XX", L"XX", 2129, 34, LOCATION_REGION }, /* Southern Asia */
{ 7299303, L"TL", L"TLS", 47599, 626 }, /* Democratic Republic of Timor-Leste */
{ 9914689, L"XK", L"XKS", 47610, 906 }, /* Kosovo */
{ 10026358, L"XX", L"XX", 39070, 19, LOCATION_REGION }, /* Americas */
{ 10028789, L"AX", L"ALA", 10039882, 248 }, /* Åland Islands */
{ 10039880, L"XX", L"XX", 161832257, 29, LOCATION_REGION }, /* Caribbean */
{ 10039882, L"XX", L"XX", 10541, 154, LOCATION_REGION }, /* Northern Europe */
{ 10039883, L"XX", L"XX", 742, 18, LOCATION_REGION }, /* Southern Africa */
{ 10210824, L"XX", L"XX", 10541, 155, LOCATION_REGION }, /* Western Europe */
{ 10210825, L"XX", L"XX", 27114, 53, LOCATION_REGION }, /* Australia and New Zealand */
{ 161832015, L"BL", L"BLM", 10039880, 652 }, /* Saint Barthélemy */
{ 161832256, L"UM", L"UMI", 27114, 581 }, /* U.S. Minor Outlying Islands */
{ 161832257, L"XX", L"XX", 10026358, 419, LOCATION_REGION }, /* Latin America and the Caribbean */
};
/* NLS normalization file */
struct norm_table
{
WCHAR name[13]; /* 00 file name */
USHORT checksum[3]; /* 1a checksum? */
USHORT version[4]; /* 20 Unicode version */
USHORT form; /* 28 normalization form */
USHORT len_factor; /* 2a factor for length estimates */
USHORT unknown1; /* 2c */
USHORT decomp_size; /* 2e decomposition hash size */
USHORT comp_size; /* 30 composition hash size */
USHORT unknown2; /* 32 */
USHORT classes; /* 34 combining classes table offset */
USHORT props_level1; /* 36 char properties table level 1 offset */
USHORT props_level2; /* 38 char properties table level 2 offset */
USHORT decomp_hash; /* 3a decomposition hash table offset */
USHORT decomp_map; /* 3c decomposition character map table offset */
USHORT decomp_seq; /* 3e decomposition character sequences offset */
USHORT comp_hash; /* 40 composition hash table offset */
USHORT comp_seq; /* 42 composition character sequences offset */
/* BYTE[] combining class values */
/* BYTE[0x2200] char properties index level 1 */
/* BYTE[] char properties index level 2 */
/* WORD[] decomposition hash table */
/* WORD[] decomposition character map */
/* WORD[] decomposition character sequences */
/* WORD[] composition hash table */
/* WORD[] composition character sequences */
};
static NLSTABLEINFO nls_info;
static UINT mac_cp = 10000;
static HKEY intl_key;
static HKEY nls_key;
static HKEY tz_key;
static CPTABLEINFO codepages[128];
static unsigned int nb_codepages;
static struct norm_table *norm_info;
struct sortguid
{
GUID id; /* sort GUID */
DWORD flags; /* flags */
DWORD compr; /* offset to compression table */
DWORD except; /* exception table offset in sortkey table */
DWORD ling_except; /* exception table offset for linguistic casing */
DWORD casemap; /* linguistic casemap table offset */
};
#define FLAG_HAS_3_BYTE_WEIGHTS 0x01
#define FLAG_REVERSEDIACRITICS 0x10
#define FLAG_DOUBLECOMPRESSION 0x20
#define FLAG_INVERSECASING 0x40
static const struct sortguid *current_locale_sort;
static const GUID default_sort_guid = { 0x00000001, 0x57ee, 0x1e5c, { 0x00, 0xb4, 0xd0, 0x00, 0x0b, 0xb1, 0xe1, 0x1e }};
static struct
{
DWORD *keys; /* sortkey table, indexed by char */
USHORT *casemap; /* casemap table, in l_intl.nls format */
WORD *ctypes; /* CT_CTYPE1,2,3 values */
BYTE *ctype_idx; /* index to map char to ctypes array entry */
DWORD version; /* NLS version */
DWORD guid_count; /* number of sort GUIDs */
struct sortguid *guids; /* table of sort GUIDs */
} sort;
static CRITICAL_SECTION locale_section;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &locale_section,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": locale_section") }
};
static CRITICAL_SECTION locale_section = { &critsect_debug, -1, 0, 0, 0, 0 };
static void init_sortkeys( DWORD *ptr )
{
WORD *ctype;
DWORD *table;
sort.keys = (DWORD *)((char *)ptr + ptr[0]);
sort.casemap = (USHORT *)((char *)ptr + ptr[1]);
ctype = (WORD *)((char *)ptr + ptr[2]);
sort.ctypes = ctype + 2;
sort.ctype_idx = (BYTE *)ctype + ctype[1] + 2;
table = (DWORD *)((char *)ptr + ptr[3]);
sort.version = table[0];
sort.guid_count = table[1];
sort.guids = (struct sortguid *)(table + 2);
}
static const struct sortguid *find_sortguid( const GUID *guid )
{
int pos, ret, min = 0, max = sort.guid_count - 1;
while (min <= max)
{
pos = (min + max) / 2;
ret = memcmp( guid, &sort.guids[pos].id, sizeof(*guid) );
if (!ret) return &sort.guids[pos];
if (ret > 0) min = pos + 1;
else max = pos - 1;
}
ERR( "no sort found for %s\n", debugstr_guid( guid ));
return NULL;
}
static const struct sortguid *get_language_sort( const WCHAR *locale )
{
WCHAR *p, *end, buffer[LOCALE_NAME_MAX_LENGTH], guidstr[39];
const struct sortguid *ret;
UNICODE_STRING str;
GUID guid;
HKEY key = 0;
DWORD size, type;
if (locale == LOCALE_NAME_USER_DEFAULT)
{
if (current_locale_sort) return current_locale_sort;
GetUserDefaultLocaleName( buffer, ARRAY_SIZE( buffer ));
}
else lstrcpynW( buffer, locale, LOCALE_NAME_MAX_LENGTH );
if (buffer[0] && !RegOpenKeyExW( nls_key, L"Sorting\\Ids", 0, KEY_READ, &key ))
{
for (;;)
{
size = sizeof(guidstr);
if (!RegQueryValueExW( key, buffer, NULL, &type, (BYTE *)guidstr, &size ) && type == REG_SZ)
{
RtlInitUnicodeString( &str, guidstr );
if (!RtlGUIDFromString( &str, &guid ))
{
ret = find_sortguid( &guid );
goto done;
}
break;
}
for (p = end = buffer; *p; p++) if (*p == '-' || *p == '_') end = p;
if (end == buffer) break;
*end = 0;
}
}
ret = find_sortguid( &default_sort_guid );
done:
RegCloseKey( key );
return ret;
}
/***********************************************************************
* init_locale
*/
void init_locale(void)
{
UINT ansi_cp = 0, oem_cp = 0;
USHORT *ansi_ptr, *oem_ptr;
void *sort_ptr;
LCID lcid = GetUserDefaultLCID();
WCHAR bufferW[80];
DYNAMIC_TIME_ZONE_INFORMATION timezone;
GEOID geoid = GEOID_NOT_AVAILABLE;
DWORD count, dispos, i;
SIZE_T size;
HKEY hkey;
kernel32_handle = GetModuleHandleW( L"kernel32.dll" );
GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
(WCHAR *)&ansi_cp, sizeof(ansi_cp)/sizeof(WCHAR) );
GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
(WCHAR *)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
(WCHAR *)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
NtGetNlsSectionPtr( 9, 0, NULL, &sort_ptr, &size );
NtGetNlsSectionPtr( 12, NormalizationC, NULL, (void **)&norm_info, &size );
init_sortkeys( sort_ptr );
if (!ansi_cp || NtGetNlsSectionPtr( 11, ansi_cp, NULL, (void **)&ansi_ptr, &size ))
NtGetNlsSectionPtr( 11, 1252, NULL, (void **)&ansi_ptr, &size );
if (!oem_cp || NtGetNlsSectionPtr( 11, oem_cp, 0, (void **)&oem_ptr, &size ))
NtGetNlsSectionPtr( 11, 437, NULL, (void **)&oem_ptr, &size );
NtCurrentTeb()->Peb->AnsiCodePageData = ansi_ptr;
NtCurrentTeb()->Peb->OemCodePageData = oem_ptr;
NtCurrentTeb()->Peb->UnicodeCaseTableData = sort.casemap;
RtlInitNlsTables( ansi_ptr, oem_ptr, sort.casemap, &nls_info );
RtlResetRtlTranslations( &nls_info );
RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Nls",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &nls_key, NULL );
RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &tz_key, NULL );
RegCreateKeyExW( HKEY_CURRENT_USER, L"Control Panel\\International",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &intl_key, NULL );
current_locale_sort = get_language_sort( LOCALE_NAME_USER_DEFAULT );
if (GetDynamicTimeZoneInformation( &timezone ) != TIME_ZONE_ID_INVALID &&
!RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\TimeZoneInformation",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
{
RegSetValueExW( hkey, L"StandardName", 0, REG_SZ, (BYTE *)timezone.StandardName,
(lstrlenW(timezone.StandardName) + 1) * sizeof(WCHAR) );
RegSetValueExW( hkey, L"TimeZoneKeyName", 0, REG_SZ, (BYTE *)timezone.TimeZoneKeyName,
(lstrlenW(timezone.TimeZoneKeyName) + 1) * sizeof(WCHAR) );
RegCloseKey( hkey );
}
if (!RegCreateKeyExW( intl_key, L"Geo", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, &dispos ))
{
if (dispos == REG_CREATED_NEW_KEY)
{
GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IGEOID | LOCALE_RETURN_NUMBER,
(WCHAR *)&geoid, sizeof(geoid) / sizeof(WCHAR) );
SetUserGeoID( geoid );
}
RegCloseKey( hkey );
}
/* Update registry contents if the user locale has changed.
* This simulates the action of the Windows control panel. */
count = sizeof(bufferW);
if (!RegQueryValueExW( intl_key, L"Locale", NULL, NULL, (BYTE *)bufferW, &count ))
{
if (wcstoul( bufferW, NULL, 16 ) == lcid) return; /* already set correctly */
TRACE( "updating registry, locale changed %s -> %08x\n", debugstr_w(bufferW), lcid );
}
else TRACE( "updating registry, locale changed none -> %08x\n", lcid );
swprintf( bufferW, ARRAY_SIZE(bufferW), L"%08x", lcid );
RegSetValueExW( intl_key, L"Locale", 0, REG_SZ,
(BYTE *)bufferW, (lstrlenW(bufferW) + 1) * sizeof(WCHAR) );
for (i = 0; i < ARRAY_SIZE(registry_values); i++)
{
GetLocaleInfoW( LOCALE_USER_DEFAULT, registry_values[i].lctype | LOCALE_NOUSEROVERRIDE,
bufferW, ARRAY_SIZE( bufferW ));
RegSetValueExW( intl_key, registry_values[i].name, 0, REG_SZ,
(BYTE *)bufferW, (lstrlenW(bufferW) + 1) * sizeof(WCHAR) );
}
if (geoid == GEOID_NOT_AVAILABLE)
{
GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IGEOID | LOCALE_RETURN_NUMBER,
(WCHAR *)&geoid, sizeof(geoid) / sizeof(WCHAR) );
SetUserGeoID( geoid );
}
if (!RegCreateKeyExW( nls_key, L"Codepage",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
{
count = swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03d", ansi_cp );
RegSetValueExW( hkey, L"ACP", 0, REG_SZ, (BYTE *)bufferW, (count + 1) * sizeof(WCHAR) );
count = swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03d", oem_cp );
RegSetValueExW( hkey, L"OEMCP", 0, REG_SZ, (BYTE *)bufferW, (count + 1) * sizeof(WCHAR) );
count = swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03d", mac_cp );
RegSetValueExW( hkey, L"MACCP", 0, REG_SZ, (BYTE *)bufferW, (count + 1) * sizeof(WCHAR) );
RegCloseKey( hkey );
}
}
static inline USHORT get_table_entry( const USHORT *table, WCHAR ch )
{
return table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0xf)];
}
static inline WCHAR casemap( const USHORT *table, WCHAR ch )
{
return ch + table[table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + (ch & 0x0f)];
}
static inline WORD get_char_type( DWORD type, WCHAR ch )
{
const BYTE *ptr = sort.ctype_idx + ((const WORD *)sort.ctype_idx)[ch >> 8];
ptr = sort.ctype_idx + ((const WORD *)ptr)[(ch >> 4) & 0x0f] + (ch & 0x0f);
return sort.ctypes[*ptr * 3 + type / 2];
}
static BYTE rol( BYTE val, BYTE count )
{
return (val << count) | (val >> (8 - count));
}
static BYTE get_char_props( const struct norm_table *info, unsigned int ch )
{
const BYTE *level1 = (const BYTE *)((const USHORT *)info + info->props_level1);
const BYTE *level2 = (const BYTE *)((const USHORT *)info + info->props_level2);
BYTE off = level1[ch / 128];
if (!off || off >= 0xfb) return rol( off, 5 );
return level2[(off - 1) * 128 + ch % 128];
}
static const WCHAR *get_decomposition( WCHAR ch, unsigned int *ret_len )
{
const struct pair { WCHAR src; USHORT dst; } *pairs;
const USHORT *hash_table = (const USHORT *)norm_info + norm_info->decomp_hash;
const WCHAR *ret;
unsigned int i, pos, end, len, hash;
*ret_len = 1;
hash = ch % norm_info->decomp_size;
pos = hash_table[hash];
if (pos >> 13)
{
if (get_char_props( norm_info, ch ) != 0xbf) return NULL;
ret = (const USHORT *)norm_info + norm_info->decomp_seq + (pos & 0x1fff);
len = pos >> 13;
}
else
{
pairs = (const struct pair *)((const USHORT *)norm_info + norm_info->decomp_map);
/* find the end of the hash bucket */
for (i = hash + 1; i < norm_info->decomp_size; i++) if (!(hash_table[i] >> 13)) break;
if (i < norm_info->decomp_size) end = hash_table[i];
else for (end = pos; pairs[end].src; end++) ;
for ( ; pos < end; pos++)
{
if (pairs[pos].src != (WCHAR)ch) continue;
ret = (const USHORT *)norm_info + norm_info->decomp_seq + (pairs[pos].dst & 0x1fff);
len = pairs[pos].dst >> 13;
break;
}
if (pos >= end) return NULL;
}
if (len == 7) while (ret[len]) len++;
if (!ret[0]) len = 0; /* ignored char */
*ret_len = len;
return ret;
}
static WCHAR compose_chars( WCHAR ch1, WCHAR ch2 )
{
const USHORT *table = (const USHORT *)norm_info + norm_info->comp_hash;
const WCHAR *chars = (const USHORT *)norm_info + norm_info->comp_seq;
unsigned int hash, start, end, i;
WCHAR ch[3];
hash = (ch1 + 95 * ch2) % norm_info->comp_size;
start = table[hash];
end = table[hash + 1];
while (start < end)
{
for (i = 0; i < 3; i++, start++)
{
ch[i] = chars[start];
if (IS_HIGH_SURROGATE( ch[i] )) start++;
}
if (ch[0] == ch1 && ch[1] == ch2) return ch[2];
}
return 0;
}
static UINT get_lcid_codepage( LCID lcid, ULONG flags )
{
UINT ret = GetACP();
if (!(flags & LOCALE_USE_CP_ACP) && lcid != GetSystemDefaultLCID())
GetLocaleInfoW( lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
(WCHAR *)&ret, sizeof(ret)/sizeof(WCHAR) );
return ret;
}
static BOOL is_genitive_name_supported( LCTYPE lctype )
{
switch (LOWORD(lctype))
{
case LOCALE_SMONTHNAME1:
case LOCALE_SMONTHNAME2:
case LOCALE_SMONTHNAME3:
case LOCALE_SMONTHNAME4:
case LOCALE_SMONTHNAME5:
case LOCALE_SMONTHNAME6:
case LOCALE_SMONTHNAME7:
case LOCALE_SMONTHNAME8:
case LOCALE_SMONTHNAME9:
case LOCALE_SMONTHNAME10:
case LOCALE_SMONTHNAME11:
case LOCALE_SMONTHNAME12:
case LOCALE_SMONTHNAME13:
return TRUE;
default:
return FALSE;
}
}
static int get_value_base_by_lctype( LCTYPE lctype )
{
return lctype == LOCALE_ILANGUAGE || lctype == LOCALE_IDEFAULTLANGUAGE ? 16 : 10;
}
static const struct registry_value *get_locale_registry_value( DWORD lctype )
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE( registry_values ); i++)
if (registry_values[i].lctype == lctype) return ®istry_values[i];
return NULL;
}
static INT get_registry_locale_info( const struct registry_value *registry_value, LPWSTR buffer, INT len )
{
DWORD size, index = registry_value - registry_values;
INT ret;
RtlEnterCriticalSection( &locale_section );
if (!registry_cache[index])
{
size = len * sizeof(WCHAR);
ret = RegQueryValueExW( intl_key, registry_value->name, NULL, NULL, (BYTE *)buffer, &size );
if (!ret)
{
if (buffer && (registry_cache[index] = HeapAlloc( GetProcessHeap(), 0, size + sizeof(WCHAR) )))
{
memcpy( registry_cache[index], buffer, size );
registry_cache[index][size / sizeof(WCHAR)] = 0;
}
RtlLeaveCriticalSection( &locale_section );
return size / sizeof(WCHAR);
}
else
{
RtlLeaveCriticalSection( &locale_section );
if (ret == ERROR_FILE_NOT_FOUND) return -1;
if (ret == ERROR_MORE_DATA) SetLastError( ERROR_INSUFFICIENT_BUFFER );
else SetLastError( ret );
return 0;
}
}
ret = lstrlenW( registry_cache[index] ) + 1;
if (buffer)
{
if (ret > len)
{