Coverage Report

Created: 2024-09-08 06:20

/src/FreeRDP/libfreerdp/locale/keyboard_layout.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * Keyboard Layouts
4
 *
5
 * Copyright 2009-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
20
#include <freerdp/config.h>
21
22
#include <stdio.h>
23
#include <stdlib.h>
24
#include <string.h>
25
26
#include <winpr/crt.h>
27
#include <winpr/path.h>
28
#include <winpr/json.h>
29
30
#include "liblocale.h"
31
32
#include <freerdp/types.h>
33
#include <freerdp/scancode.h>
34
#include <freerdp/locale/keyboard.h>
35
36
#include <freerdp/log.h>
37
#define TAG FREERDP_TAG("locale.keyboard.layouts")
38
39
// #define DUMP_LAYOUTS_TO_JSON
40
41
struct LanguageIdentifier
42
{
43
  /* LanguageIdentifier = (SublangaugeIdentifier<<2) | PrimaryLanguageIdentifier
44
   * The table at
45
   * https://docs.microsoft.com/en-us/windows/win32/intl/language-identifier-constants-and-strings
46
   * is sometimes missing one or both of the entries.
47
   */
48
  const char* locale; /* en_US type strings for the locale */
49
  UINT16 LanguageIdentifier;
50
  const char* PrimaryLanguage;
51
  UINT8 PrimaryLanguageIdentifier;
52
  const char* PrimaryLanguageSymbol;
53
  const char* Sublanguage;
54
  UINT8 SublangaugeIdentifier;
55
  const char* SublanguageSymbol;
56
};
57
58
typedef struct
59
{
60
  DWORD code; /* Keyboard layout code */
61
  DWORD id;   /* Keyboard variant ID */
62
  char* name; /* Keyboard layout variant name */
63
} RDP_KEYBOARD_LAYOUT_VARIANT;
64
65
typedef struct
66
{
67
  DWORD code; /* Keyboard layout code */
68
  char* file; /* IME file */
69
  char* name; /* Keyboard layout name */
70
} RDP_KEYBOARD_IME;
71
72
static const struct LanguageIdentifier language_identifiers[] = {
73
  /*  [Language identifier]   [Primary language]    [Prim. lang. identifier]    [Prim.
74
     lang. symbol]    [Sublanguage]   [Sublang. identifier]   [Sublang. symbol] */
75
  { "", 0xc00, "Default custom locale language", 0x0, "LANG_NEUTRAL",
76
    "Default custom sublanguage", 0x3, "SUBLANG_CUSTOM_DEFAULT" },
77
  { "", 0x1400, "Default custom MUI locale language", 0x0, "LANG_NEUTRAL",
78
    "Default custom MUI sublanguage", 0x5, "SUBLANG_UI_CUSTOM_DEFAULT" },
79
  { "", 0x7f, "Invariant locale language", 0x7f, "LANG_INVARIANT", "Invariant sublanguage", 0x0,
80
    "SUBLANG_NEUTRAL" },
81
  { "", 0x0, "Neutral locale language", 0x0, "LANG_NEUTRAL", "Neutral sublanguage", 0x0,
82
    "SUBLANG_NEUTRAL" },
83
  { "", 0x800, "System default locale language", 0x2, "LANG_SYSTEM_DEFAULT",
84
    "System default sublanguage", 0x2, "SUBLANG_SYS_DEFAULT" },
85
  { "", 0x1000, "Unspecified custom locale language", 0x0, "LANG_NEUTRAL",
86
    "Unspecified custom sublanguage", 0x4, "SUBLANG_CUSTOM_UNSPECIFIED" },
87
  { "", 0x400, "User default locale language", 0x0, "LANG_USER_DEFAULT",
88
    "User default sublanguage", 0x1, "SUBLANG_DEFAULT" },
89
  { "af_ZA", 0x436, "Afrikaans (af)", 0x36, "LANG_AFRIKAANS", "South Africa (ZA)", 0x1,
90
    "SUBLANG_AFRIKAANS_SOUTH_AFRICA" },
91
  { "sq_AL", 0x41c, "Albanian (sq)", 0x1c, "LANG_ALBANIAN", "Albania (AL)", 0x1,
92
    "SUBLANG_ALBANIAN_ALBANIA" },
93
  { "gsw_FR", 0x484, "Alsatian (gsw)", 0x84, "LANG_ALSATIAN", "France (FR)", 0x1,
94
    "SUBLANG_ALSATIAN_FRANCE" },
95
  { "am_ET", 0x45e, "Amharic (am)", 0x5e, "LANG_AMHARIC", "Ethiopia (ET)", 0x1,
96
    "SUBLANG_AMHARIC_ETHIOPIA" },
97
  { "ar_DZ", 0x1401, "Arabic (ar)", 0x1, "LANG_ARABIC", "Algeria (DZ)", 0x5,
98
    "SUBLANG_ARABIC_ALGERIA" },
99
  { "ar_BH", 0x3c01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Bahrain (BH)", 0xf,
100
    "SUBLANG_ARABIC_BAHRAIN" },
101
  { "ar_EG", 0xc01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Egypt (EG)", 0x3,
102
    "SUBLANG_ARABIC_EGYPT" },
103
  { "ar_IQ", 0x801, "Arabic (ar)", 0x01, "LANG_ARABIC", "Iraq (IQ)", 0x2, "SUBLANG_ARABIC_IRAQ" },
104
  { "ar_JO", 0x2c01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Jordan (JO)", 0xb,
105
    "SUBLANG_ARABIC_JORDAN" },
106
  { "ar_KW", 0x3401, "Arabic (ar)", 0x01, "LANG_ARABIC", "Kuwait (KW)", 0xd,
107
    "SUBLANG_ARABIC_KUWAIT" },
108
  { "ar_LB", 0x3001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Lebanon (LB)", 0xc,
109
    "SUBLANG_ARABIC_LEBANON" },
110
  { "ar_LY", 0x1001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Libya (LY)", 0x4,
111
    "SUBLANG_ARABIC_LIBYA" },
112
  { "ar_MA", 0x1801, "Arabic (ar)", 0x01, "LANG_ARABIC", "Morocco (MA)", 0x6,
113
    "SUBLANG_ARABIC_MOROCCO" },
114
  { "ar_OM", 0x2001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Oman (OM)", 0x8,
115
    "SUBLANG_ARABIC_OMAN" },
116
  { "ar_QA", 0x4001, "Arabic (ar)", 0x01, "LANG_ARABIC", "Qatar (QA)", 0x10,
117
    "SUBLANG_ARABIC_QATAR" },
118
  { "ar_SA", 0x401, "Arabic (ar)", 0x01, "LANG_ARABIC", "Saudi Arabia (SA)", 0x1,
119
    "SUBLANG_ARABIC_SAUDI_ARABIA" },
120
  { "ar_SY", 0x2801, "Arabic (ar)", 0x01, "LANG_ARABIC", "Syria (SY)", 0xa,
121
    "SUBLANG_ARABIC_SYRIA" },
122
  { "ar_TN", 0x1c01, "Arabic (ar)", 0x01, "LANG_ARABIC", "Tunisia (TN)", 0x7,
123
    "SUBLANG_ARABIC_TUNISIA" },
124
  { "ar_AE", 0x3801, "Arabic (ar)", 0x01, "LANG_ARABIC", "U.A.E. (AE)", 0xe,
125
    "SUBLANG_ARABIC_UAE" },
126
  { "ar_YE", 0x2401, "Arabic (ar)", 0x01, "LANG_ARABIC", "Yemen (YE)", 0x9,
127
    "SUBLANG_ARABIC_YEMEN" },
128
  { "hy_AM", 0x42b, "Armenian (hy)", 0x2b, "LANG_ARMENIAN", "Armenia (AM)", 0x1,
129
    "SUBLANG_ARMENIAN_ARMENIA" },
130
  { "as_IN", 0x44d, "Assamese (as)", 0x4d, "LANG_ASSAMESE", "India (IN)", 0x1,
131
    "SUBLANG_ASSAMESE_INDIA" },
132
  { "az_AZ", 0x82c, "Azerbaijani (az)", 0x2c, "LANG_AZERI", "Azerbaijan, Cyrillic (AZ)", 0x2,
133
    "SUBLANG_AZERI_CYRILLIC" },
134
  { "az_AZ", 0x42c, "Azerbaijani (az)", 0x2c, "LANG_AZERI", "Azerbaijan, Latin (AZ)", 0x1,
135
    "SUBLANG_AZERI_LATIN" },
136
  { "bn_BD", 0x445, "Bangla (bn)", 0x45, "LANG_BANGLA", "Bangladesh (BD)", 0x2,
137
    "SUBLANG_BANGLA_BANGLADESH" },
138
  { "bn_IN", 0x445, "Bangla (bn)", 0x45, "LANG_BANGLA", "India (IN)", 0x1,
139
    "SUBLANG_BANGLA_INDIA" },
140
  { "ba_RU", 0x46d, "Bashkir (ba)", 0x6d, "LANG_BASHKIR", "Russia (RU)", 0x1,
141
    "SUBLANG_BASHKIR_RUSSIA" },
142
  { "", 0x42d, "Basque (Basque)", 0x2d, "LANG_BASQUE", "Basque (Basque)", 0x1,
143
    "SUBLANG_BASQUE_BASQUE" },
144
  { "be_BY", 0x423, "Belarusian (be)", 0x23, "LANG_BELARUSIAN", "Belarus (BY)", 0x1,
145
    "SUBLANG_BELARUSIAN_BELARUS" },
146
  { "bs", 0x781a, "Bosnian (bs)", 0x1a, "LANG_BOSNIAN_NEUTRAL", "Neutral", 0x1E, "" },
147
  { "bs_BA", 0x201a, "Bosnian (bs)", 0x1a, "LANG_BOSNIAN",
148
    "Bosnia and Herzegovina, Cyrillic (BA)", 0x8, "SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC" },
149
  { "bs_BA", 0x141a, "Bosnian (bs)", 0x1a, "LANG_BOSNIAN", "Bosnia and Herzegovina, Latin (BA)",
150
    0x5, "SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN" },
151
  { "br_FR", 0x47e, "Breton (br)", 0x7e, "LANG_BRETON", "France (FR)", 0x1,
152
    "SUBLANG_BRETON_FRANCE" },
153
  { "bg_BG", 0x402, "Bulgarian (bg)", 0x2, "LANG_BULGARIAN", "Bulgaria (BG)", 0x1,
154
    "SUBLANG_BULGARIAN_BULGARIA" },
155
  { "ku_IQ", 0x492, "Central Kurdish (ku)", 0x92, "LANG_CENTRAL_KURDISH", "Iraq (IQ)", 0x1,
156
    "SUBLANG_CENTRAL_KURDISH_IRAQ" },
157
  { "chr_US", 0x45c, "Cherokee (chr)", 0x5c, "LANG_CHEROKEE", "Cherokee (Cher)", 0x1,
158
    "SUBLANG_CHEROKEE_CHEROKEE" },
159
  { "ca_ES", 0x403, "Catalan (ca)", 0x3, "LANG_CATALAN", "Spain (ES)", 0x1,
160
    "SUBLANG_CATALAN_CATALAN" },
161
  { "zh_HK", 0xc04, "Chinese (zh)", 0x04, "LANG_CHINESE", "Hong Kong SAR, PRC (HK)", 0x3,
162
    "SUBLANG_CHINESE_HONGKONG" },
163
  { "zh_MO", 0x1404, "Chinese (zh)", 0x04, "LANG_CHINESE", "Macao SAR (MO)", 0x5,
164
    "SUBLANG_CHINESE_MACAU" },
165
  { "zh_SG", 0x1004, "Chinese (zh)", 0x04, "LANG_CHINESE", "Singapore (SG)", 0x4,
166
    "SUBLANG_CHINESE_SINGAPORE" },
167
  { "zh_CN", 0x4, "Chinese (zh)", 0x4, "LANG_CHINESE_SIMPLIFIED", "Simplified (Hans)", 0x2,
168
    "SUBLANG_CHINESE_SIMPLIFIED" },
169
  { "zh_CN", 0x7c04, "Chinese (zh)", 0x04, "LANG_CHINESE_TRADITIONAL", "Traditional (Hant)", 0x1,
170
    "SUBLANG_CHINESE_TRADITIONAL" },
171
  { "co_FR", 0x483, "Corsican (co)", 0x83, "LANG_CORSICAN", "France (FR)", 0x1,
172
    "SUBLANG_CORSICAN_FRANCE" },
173
  { "hr", 0x1a, "Croatian (hr)", 0x1a, "LANG_CROATIAN", "Neutral", 0x00, "" },
174
  { "hr_BA", 0x101a, "Croatian (hr)", 0x1a, "LANG_CROATIAN", "Bosnia and Herzegovina, Latin (BA)",
175
    0x4, "SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN" },
176
  { "hr_HR", 0x41a, "Croatian (hr)", 0x1a, "LANG_CROATIAN", "Croatia (HR)", 0x1,
177
    "SUBLANG_CROATIAN_CROATIA" },
178
  { "cs_CZ", 0x405, "Czech (cs)", 0x5, "LANG_CZECH", "Czech Republic (CZ)", 0x1,
179
    "SUBLANG_CZECH_CZECH_REPUBLIC" },
180
  { "da_DK", 0x406, "Danish (da)", 0x6, "LANG_DANISH", "Denmark (DK)", 0x1,
181
    "SUBLANG_DANISH_DENMARK" },
182
  { "prs_AF", 0x48c, "Dari (prs)", 0x8c, "LANG_DARI", "Afghanistan (AF)", 0x1,
183
    "SUBLANG_DARI_AFGHANISTAN" },
184
  { "dv_MV", 0x465, "Divehi (dv)", 0x65, "LANG_DIVEHI", "Maldives (MV)", 0x1,
185
    "SUBLANG_DIVEHI_MALDIVES" },
186
  { "nl_BE", 0x813, "Dutch (nl)", 0x13, "LANG_DUTCH", "Belgium (BE)", 0x2,
187
    "SUBLANG_DUTCH_BELGIAN" },
188
  { "nl_NL", 0x413, "Dutch (nl)", 0x13, "LANG_DUTCH", "Netherlands (NL)", 0x1, "SUBLANG_DUTCH" },
189
  { "en_AU", 0xc09, "English (en)", 0x9, "LANG_ENGLISH", "Australia (AU)", 0x3,
190
    "SUBLANG_ENGLISH_AUS" },
191
  { "en_BZ", 0x2809, "English (en)", 0x09, "LANG_ENGLISH", "Belize (BZ)", 0xa,
192
    "SUBLANG_ENGLISH_BELIZE" },
193
  { "en_CA", 0x1009, "English (en)", 0x09, "LANG_ENGLISH", "Canada (CA)", 0x4,
194
    "SUBLANG_ENGLISH_CAN" },
195
  { "en_CB", 0x2409, "English (en)", 0x09, "LANG_ENGLISH", "Caribbean (029)", 0x9,
196
    "SUBLANG_ENGLISH_CARIBBEAN" },
197
  { "en_IN", 0x4009, "English (en)", 0x09, "LANG_ENGLISH", "India (IN)", 0x10,
198
    "SUBLANG_ENGLISH_INDIA" },
199
  { "en_IE", 0x1809, "English (en)", 0x09, "LANG_ENGLISH", "Ireland (IE)", 0x6,
200
    "SUBLANG_ENGLISH_EIRE" },
201
  { "en_IE", 0x1809, "English (en)", 0x09, "LANG_ENGLISH", "Ireland (IE)", 0x6,
202
    "SUBLANG_ENGLISH_IRELAND" },
203
  { "en_JM", 0x2009, "English (en)", 0x09, "LANG_ENGLISH", "Jamaica (JM)", 0x8,
204
    "SUBLANG_ENGLISH_JAMAICA" },
205
  { "en_MY", 0x4409, "English (en)", 0x09, "LANG_ENGLISH", "Malaysia (MY)", 0x11,
206
    "SUBLANG_ENGLISH_MALAYSIA" },
207
  { "en_NZ", 0x1409, "English (en)", 0x09, "LANG_ENGLISH", "New Zealand (NZ)", 0x5,
208
    "SUBLANG_ENGLISH_NZ" },
209
  { "en_PH", 0x3409, "English (en)", 0x09, "LANG_ENGLISH", "Philippines (PH)", 0xd,
210
    "SUBLANG_ENGLISH_PHILIPPINES" },
211
  { "en_SG", 0x4809, "English (en)", 0x09, "LANG_ENGLISH", "Singapore (SG)", 0x12,
212
    "SUBLANG_ENGLISH_SINGAPORE" },
213
  { "en_ZA", 0x1c09, "English (en)", 0x09, "LANG_ENGLISH", "South Africa (ZA)", 0x7,
214
    "SUBLANG_ENGLISH_SOUTH_AFRICA" },
215
  { "en_TT", 0x2c09, "English (en)", 0x09, "LANG_ENGLISH", "Trinidad and Tobago (TT)", 0xb,
216
    "SUBLANG_ENGLISH_TRINIDAD" },
217
  { "en_GB", 0x809, "English (en)", 0x09, "LANG_ENGLISH", "United Kingdom (GB)", 0x2,
218
    "SUBLANG_ENGLISH_UK" },
219
  { "en_US", 0x409, "English (en)", 0x09, "LANG_ENGLISH", "United States (US)", 0x1,
220
    "SUBLANG_ENGLISH_US" },
221
  { "en_ZW", 0x3009, "English (en)", 0x09, "LANG_ENGLISH", "Zimbabwe (ZW)", 0xc,
222
    "SUBLANG_ENGLISH_ZIMBABWE" },
223
  { "et_EE", 0x425, "Estonian (et)", 0x25, "LANG_ESTONIAN", "Estonia (EE)", 0x1,
224
    "SUBLANG_ESTONIAN_ESTONIA" },
225
  { "fo_FO", 0x438, "Faroese (fo)", 0x38, "LANG_FAEROESE", "Faroe Islands (FO)", 0x1,
226
    "SUBLANG_FAEROESE_FAROE_ISLANDS" },
227
  { "fil_PH", 0x464, "Filipino (fil)", 0x64, "LANG_FILIPINO", "Philippines (PH)", 0x1,
228
    "SUBLANG_FILIPINO_PHILIPPINES" },
229
  { "fi_FI", 0x40b, "Finnish (fi)", 0xb, "LANG_FINNISH", "Finland (FI)", 0x1,
230
    "SUBLANG_FINNISH_FINLAND" },
231
  { "fr_BE", 0x80c, "French (fr)", 0xc, "LANG_FRENCH", "Belgium (BE)", 0x2,
232
    "SUBLANG_FRENCH_BELGIAN" },
233
  { "fr_CA", 0xc0c, "French (fr)", 0x0c, "LANG_FRENCH", "Canada (CA)", 0x3,
234
    "SUBLANG_FRENCH_CANADIAN" },
235
  { "fr_FR", 0x40c, "French (fr)", 0x0c, "LANG_FRENCH", "France (FR)", 0x1, "SUBLANG_FRENCH" },
236
  { "fr_LU", 0x140c, "French (fr)", 0x0c, "LANG_FRENCH", "Luxembourg (LU)", 0x5,
237
    "SUBLANG_FRENCH_LUXEMBOURG" },
238
  { "fr_MC", 0x180c, "French (fr)", 0x0c, "LANG_FRENCH", "Monaco (MC)", 0x6,
239
    "SUBLANG_FRENCH_MONACO" },
240
  { "fr_CH", 0x100c, "French (fr)", 0x0c, "LANG_FRENCH", "Switzerland (CH)", 0x4,
241
    "SUBLANG_FRENCH_SWISS" },
242
  { "fy_NL", 0x462, "Frisian (fy)", 0x62, "LANG_FRISIAN", "Netherlands (NL)", 0x1,
243
    "SUBLANG_FRISIAN_NETHERLANDS" },
244
  { "gl_ES", 0x456, "Galician (gl)", 0x56, "LANG_GALICIAN", "Spain (ES)", 0x1,
245
    "SUBLANG_GALICIAN_GALICIAN" },
246
  { "ka_GE", 0x437, "Georgian (ka)", 0x37, "LANG_GEORGIAN", "Georgia (GE)", 0x1,
247
    "SUBLANG_GEORGIAN_GEORGIA" },
248
  { "de_AT", 0xc07, "German (de)", 0x7, "LANG_GERMAN", "Austria (AT)", 0x3,
249
    "SUBLANG_GERMAN_AUSTRIAN" },
250
  { "de_DE", 0x407, "German (de)", 0x07, "LANG_GERMAN", "Germany (DE)", 0x1, "SUBLANG_GERMAN" },
251
  { "de_LI", 0x1407, "German (de)", 0x07, "LANG_GERMAN", "Liechtenstein (LI)", 0x5,
252
    "SUBLANG_GERMAN_LIECHTENSTEIN" },
253
  { "de_LU", 0x1007, "German (de)", 0x07, "LANG_GERMAN", "Luxembourg (LU)", 0x4,
254
    "SUBLANG_GERMAN_LUXEMBOURG" },
255
  { "de_CH", 0x807, "German (de)", 0x07, "LANG_GERMAN", "Switzerland (CH)", 0x2,
256
    "SUBLANG_GERMAN_SWISS" },
257
  { "el_GR", 0x408, "Greek (el)", 0x8, "LANG_GREEK", "Greece (GR)", 0x1, "SUBLANG_GREEK_GREECE" },
258
  { "kl_GL", 0x46f, "Greenlandic (kl)", 0x6f, "LANG_GREENLANDIC", "Greenland (GL)", 0x1,
259
    "SUBLANG_GREENLANDIC_GREENLAND" },
260
  { "gu_IN", 0x447, "Gujarati (gu)", 0x47, "LANG_GUJARATI", "India (IN)", 0x1,
261
    "SUBLANG_GUJARATI_INDIA" },
262
  { "ha_NG", 0x468, "Hausa (ha)", 0x68, "LANG_HAUSA", "Nigeria (NG)", 0x1,
263
    "SUBLANG_HAUSA_NIGERIA_LATIN" },
264
  { "haw_US", 0x475, "Hawiian (haw)", 0x75, "LANG_HAWAIIAN", "United States (US)", 0x1,
265
    "SUBLANG_HAWAIIAN_US" },
266
  { "he_IL", 0x40d, "Hebrew (he)", 0xd, "LANG_HEBREW", "Israel (IL)", 0x1,
267
    "SUBLANG_HEBREW_ISRAEL" },
268
  { "hi_IN", 0x439, "Hindi (hi)", 0x39, "LANG_HINDI", "India (IN)", 0x1, "SUBLANG_HINDI_INDIA" },
269
  { "hu_HU", 0x40e, "Hungarian (hu)", 0xe, "LANG_HUNGARIAN", "Hungary (HU)", 0x1,
270
    "SUBLANG_HUNGARIAN_HUNGARY" },
271
  { "is_IS", 0x40f, "Icelandic (is)", 0xf, "LANG_ICELANDIC", "Iceland (IS)", 0x1,
272
    "SUBLANG_ICELANDIC_ICELAND" },
273
  { "ig_NG", 0x470, "Igbo (ig)", 0x70, "LANG_IGBO", "Nigeria (NG)", 0x1, "SUBLANG_IGBO_NIGERIA" },
274
  { "id_ID", 0x421, "Indonesian (id)", 0x21, "LANG_INDONESIAN", "Indonesia (ID)", 0x1,
275
    "SUBLANG_INDONESIAN_INDONESIA" },
276
  { "iu_CA", 0x85d, "Inuktitut (iu)", 0x5d, "LANG_INUKTITUT", "Canada (CA), Latin", 0x2,
277
    "SUBLANG_INUKTITUT_CANADA_LATIN" },
278
  { "iu_CA", 0x45d, "Inuktitut (iu)", 0x5d, "LANG_INUKTITUT", "Canada (CA), Canadian Syllabics",
279
    0x1, "SUBLANG_INUKTITUT_CANADA" },
280
  { "ga_IE", 0x83c, "Irish (ga)", 0x3c, "LANG_IRISH", "Ireland (IE)", 0x2,
281
    "SUBLANG_IRISH_IRELAND" },
282
  { "xh_ZA", 0x434, "isiXhosa (xh)", 0x34, "LANG_XHOSA", "South Africa (ZA)", 0x1,
283
    "SUBLANG_XHOSA_SOUTH_AFRICA" },
284
  { "zu_ZA", 0x435, "isiZulu (zu)", 0x35, "LANG_ZULU", "South Africa (ZA)", 0x1,
285
    "SUBLANG_ZULU_SOUTH_AFRICA" },
286
  { "it_IT", 0x410, "Italian (it)", 0x10, "LANG_ITALIAN", "Italy (IT)", 0x1, "SUBLANG_ITALIAN" },
287
  { "it_CH", 0x810, "Italian (it)", 0x10, "LANG_ITALIAN", "Switzerland (CH)", 0x2,
288
    "SUBLANG_ITALIAN_SWISS" },
289
  { "ja_JP", 0x411, "Japanese (ja)", 0x11, "LANG_JAPANESE", "Japan (JP)", 0x1,
290
    "SUBLANG_JAPANESE_JAPAN" },
291
  { "kn_IN", 0x44b, "Kannada (kn)", 0x4b, "LANG_KANNADA", "India (IN)", 0x1,
292
    "SUBLANG_KANNADA_INDIA" },
293
  { "kk_KZ", 0x43f, "Kazakh (kk)", 0x3f, "LANG_KAZAK", "Kazakhstan (KZ)", 0x1,
294
    "SUBLANG_KAZAK_KAZAKHSTAN" },
295
  { "kh_KH", 0x453, "Khmer (kh)", 0x53, "LANG_KHMER", "Cambodia (KH)", 0x1,
296
    "SUBLANG_KHMER_CAMBODIA" },
297
  { "qut_GT", 0x486, "K'iche (qut)", 0x86, "LANG_KICHE", "Guatemala (GT)", 0x1,
298
    "SUBLANG_KICHE_GUATEMALA" },
299
  { "rw_RW", 0x487, "Kinyarwanda (rw)", 0x87, "LANG_KINYARWANDA", "Rwanda (RW)", 0x1,
300
    "SUBLANG_KINYARWANDA_RWANDA" },
301
  { "kok_IN", 0x457, "Konkani (kok)", 0x57, "LANG_KONKANI", "India (IN)", 0x1,
302
    "SUBLANG_KONKANI_INDIA" },
303
  { "ko_KR", 0x412, "Korean (ko)", 0x12, "LANG_KOREAN", "Korea (KR)", 0x1, "SUBLANG_KOREAN" },
304
  { "ky_KG", 0x440, "Kyrgyz (ky)", 0x40, "LANG_KYRGYZ", "Kyrgyzstan (KG)", 0x1,
305
    "SUBLANG_KYRGYZ_KYRGYZSTAN" },
306
  { "lo_LA", 0x454, "Lao (lo)", 0x54, "LANG_LAO", "Lao PDR (LA)", 0x1, "SUBLANG_LAO_LAO" },
307
  { "lv_LV", 0x426, "Latvian (lv)", 0x26, "LANG_LATVIAN", "Latvia (LV)", 0x1,
308
    "SUBLANG_LATVIAN_LATVIA" },
309
  { "lt_LT", 0x427, "Lithuanian (lt)", 0x27, "LANG_LITHUANIAN", "Lithuanian (LT)", 0x1,
310
    "SUBLANG_LITHUANIAN_LITHUANIA" },
311
  { "dsb_DE", 0x82e, "Lower Sorbian (dsb)", 0x2e, "LANG_LOWER_SORBIAN", "Germany (DE)", 0x2,
312
    "SUBLANG_LOWER_SORBIAN_GERMANY" },
313
  { "lb_LU", 0x46e, "Luxembourgish (lb)", 0x6e, "LANG_LUXEMBOURGISH", "Luxembourg (LU)", 0x1,
314
    "SUBLANG_LUXEMBOURGISH_LUXEMBOURG" },
315
  { "mk_MK", 0x42f, "Macedonian (mk)", 0x2f, "LANG_MACEDONIAN", "Macedonia (FYROM) (MK)", 0x1,
316
    "SUBLANG_MACEDONIAN_MACEDONIA" },
317
  { "ms_BN", 0x83e, "Malay (ms)", 0x3e, "LANG_MALAY", "Brunei Darassalam (BN)", 0x2,
318
    "SUBLANG_MALAY_BRUNEI_DARUSSALAM" },
319
  { "ms_MY", 0x43e, "Malay (ms)", 0x3e, "LANG_MALAY", "Malaysia (MY)", 0x1,
320
    "SUBLANG_MALAY_MALAYSIA" },
321
  { "ml_IN", 0x44c, "Malayalam (ml)", 0x4c, "LANG_MALAYALAM", "India (IN)", 0x1,
322
    "SUBLANG_MALAYALAM_INDIA" },
323
  { "mt_MT", 0x43a, "Maltese (mt)", 0x3a, "LANG_MALTESE", "Malta (MT)", 0x1,
324
    "SUBLANG_MALTESE_MALTA" },
325
  { "mi_NZ", 0x481, "Maori (mi)", 0x81, "LANG_MAORI", "New Zealand (NZ)", 0x1,
326
    "SUBLANG_MAORI_NEW_ZEALAND" },
327
  { "arn_CL", 0x47a, "Mapudungun (arn)", 0x7a, "LANG_MAPUDUNGUN", "Chile (CL)", 0x1,
328
    "SUBLANG_MAPUDUNGUN_CHILE" },
329
  { "mr_IN", 0x44e, "Marathi (mr)", 0x4e, "LANG_MARATHI", "India (IN)", 0x1,
330
    "SUBLANG_MARATHI_INDIA" },
331
  { "moh_CA", 0x47c, "Mohawk (moh)", 0x7c, "LANG_MOHAWK", "Canada (CA)", 0x1,
332
    "SUBLANG_MOHAWK_MOHAWK" },
333
  { "mn_MN", 0x450, "Mongolian (mn)", 0x50, "LANG_MONGOLIAN", "Mongolia, Cyrillic (MN)", 0x1,
334
    "SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA" },
335
  { "mn_MN", 0x850, "Mongolian (mn)", 0x50, "LANG_MONGOLIAN", "Mongolia, Mong (MN)", 0x2,
336
    "SUBLANG_MONGOLIAN_PRC" },
337
  { "ne_NP", 0x461, "Nepali (ne)", 0x61, "LANG_NEPALI", "Nepal (NP)", 0x1,
338
    "SUBLANG_NEPALI_NEPAL" },
339
  { "ne_IN", 0x861, "Nepali (ne)", 0x61, "LANG_NEPALI", "India (IN)", 0x2,
340
    "SUBLANG_NEPALI_INDIA" },
341
  { "no_NO", 0x414, "Norwegian (no)", 0x14, "LANG_NORWEGIAN", "Bokmål, Norway (NO)", 0x1,
342
    "SUBLANG_NORWEGIAN_BOKMAL" },
343
  { "no_NO", 0x814, "Norwegian (no)", 0x14, "LANG_NORWEGIAN", "Nynorsk, Norway (NO)", 0x2,
344
    "SUBLANG_NORWEGIAN_NYNORSK" },
345
  { "oc_FR", 0x482, "Occitan (oc)", 0x82, "LANG_OCCITAN", "France (FR)", 0x1,
346
    "SUBLANG_OCCITAN_FRANCE" },
347
  { "or_IN", 0x448, "Odia (or)", 0x48, "LANG_ORIYA", "India (IN)", 0x1, "SUBLANG_ORIYA_INDIA" },
348
  { "ps_AF", 0x463, "Pashto (ps)", 0x63, "LANG_PASHTO", "Afghanistan (AF)", 0x1,
349
    "SUBLANG_PASHTO_AFGHANISTAN" },
350
  { "fa_IR", 0x429, "Persian (fa)", 0x29, "LANG_PERSIAN", "Iran (IR)", 0x1,
351
    "SUBLANG_PERSIAN_IRAN" },
352
  { "pl_PL", 0x415, "Polish (pl)", 0x15, "LANG_POLISH", "Poland (PL)", 0x1,
353
    "SUBLANG_POLISH_POLAND" },
354
  { "pt_BR", 0x416, "Portuguese (pt)", 0x16, "LANG_PORTUGUESE", "Brazil (BR)", 0x1,
355
    "SUBLANG_PORTUGUESE_BRAZILIAN" },
356
  { "pt_PT", 0x816, "Portuguese (pt)", 0x16, "LANG_PORTUGUESE", "Portugal (PT)", 0x2,
357
    "SUBLANG_PORTUGUESE" },
358
  { "ff_SN", 0x867, "Pular (ff)", 0x67, "LANG_PULAR", "Senegal (SN)", 0x2,
359
    "SUBLANG_PULAR_SENEGAL" },
360
  { "pa_IN", 0x446, "Punjabi (pa)", 0x46, "LANG_PUNJABI", "India, Gurmukhi script (IN)", 0x1,
361
    "SUBLANG_PUNJABI_INDIA" },
362
  { "pa_PK", 0x846, "Punjabi (pa)", 0x46, "LANG_PUNJABI", "Pakistan, Arabic script(PK)", 0x2,
363
    "SUBLANG_PUNJABI_PAKISTAN" },
364
  { "quz_BO", 0x46b, "Quechua (quz)", 0x6b, "LANG_QUECHUA", "Bolivia (BO)", 0x1,
365
    "SUBLANG_QUECHUA_BOLIVIA" },
366
  { "quz_EC", 0x86b, "Quechua (quz)", 0x6b, "LANG_QUECHUA", "Ecuador (EC)", 0x2,
367
    "SUBLANG_QUECHUA_ECUADOR" },
368
  { "quz_PE", 0xc6b, "Quechua (quz)", 0x6b, "LANG_QUECHUA", "Peru (PE)", 0x3,
369
    "SUBLANG_QUECHUA_PERU" },
370
  { "ro_RO", 0x418, "Romanian (ro)", 0x18, "LANG_ROMANIAN", "Romania (RO)", 0x1,
371
    "SUBLANG_ROMANIAN_ROMANIA" },
372
  { "rm_CH", 0x417, "Romansh (rm)", 0x17, "LANG_ROMANSH", "Switzerland (CH)", 0x1,
373
    "SUBLANG_ROMANSH_SWITZERLAND" },
374
  { "ru_RU", 0x419, "Russian (ru)", 0x19, "LANG_RUSSIAN", "Russia (RU)", 0x1,
375
    "SUBLANG_RUSSIAN_RUSSIA" },
376
  { "sah_RU", 0x485, "Sakha (sah)", 0x85, "LANG_SAKHA", "Russia (RU)", 0x1,
377
    "SUBLANG_SAKHA_RUSSIA" },
378
  { "smn_FI", 0x243b, "Sami (smn)", 0x3b, "LANG_SAMI", "Inari, Finland (FI)", 0x9,
379
    "SUBLANG_SAMI_INARI_FINLAND" },
380
  { "smj_NO", 0x103b, "Sami (smj)", 0x3b, "LANG_SAMI", "Lule, Norway (NO)", 0x4,
381
    "SUBLANG_SAMI_LULE_NORWAY" },
382
  { "smj_SE", 0x143b, "Sami (smj)", 0x3b, "LANG_SAMI", "Lule, Sweden (SE)", 0x5,
383
    "SUBLANG_SAMI_LULE_SWEDEN" },
384
  { "se_FI", 0xc3b, "Sami (se)", 0x3b, "LANG_SAMI", "Northern, Finland (FI)", 0x3,
385
    "SUBLANG_SAMI_NORTHERN_FINLAND" },
386
  { "se_NO", 0x43b, "Sami (se)", 0x3b, "LANG_SAMI", "Northern, Norway (NO)", 0x1,
387
    "SUBLANG_SAMI_NORTHERN_NORWAY" },
388
  { "se_SE", 0x83b, "Sami (se)", 0x3b, "LANG_SAMI", "Northern, Sweden (SE)", 0x2,
389
    "SUBLANG_SAMI_NORTHERN_SWEDEN" },
390
  { "sms_FI", 0x203b, "Sami (sms)", 0x3b, "LANG_SAMI", "Skolt, Finland (FI)", 0x8,
391
    "SUBLANG_SAMI_SKOLT_FINLAND" },
392
  { "sma_NO", 0x183b, "Sami (sma)", 0x3b, "LANG_SAMI", "Southern, Norway (NO)", 0x6,
393
    "SUBLANG_SAMI_SOUTHERN_NORWAY" },
394
  { "sma_SE", 0x1c3b, "Sami (sma)", 0x3b, "LANG_SAMI", "Southern, Sweden (SE)", 0x7,
395
    "SUBLANG_SAMI_SOUTHERN_SWEDEN" },
396
  { "sa_IN", 0x44f, "Sanskrit (sa)", 0x4f, "LANG_SANSKRIT", "India (IN)", 0x1,
397
    "SUBLANG_SANSKRIT_INDIA" },
398
  { "sr", 0x7c1a, "Serbian (sr)", 0x1a, "LANG_SERBIAN_NEUTRAL", "Neutral", 0x00, "" },
399
  { "sr_BA", 0x1c1a, "Serbian (sr)", 0x1a, "LANG_SERBIAN",
400
    "Bosnia and Herzegovina, Cyrillic (BA)", 0x7, "SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC" },
401
  { "sr_BA", 0x181a, "Serbian (sr)", 0x1a, "LANG_SERBIAN", "Bosnia and Herzegovina, Latin (BA)",
402
    0x6, "SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN" },
403
  { "sr_HR", 0x41a, "Serbian (sr)", 0x1a, "LANG_SERBIAN", "Croatia (HR)", 0x1,
404
    "SUBLANG_SERBIAN_CROATIA" },
405
  { "sr_CS", 0xc1a, "Serbian (sr)", 0x1a, "LANG_SERBIAN",
406
    "Serbia and Montenegro (former), Cyrillic (CS)", 0x3, "SUBLANG_SERBIAN_CYRILLIC" },
407
  { "sr_CS", 0x81a, "Serbian (sr)", 0x1a, "LANG_SERBIAN",
408
    "Serbia and Montenegro (former), Latin (CS)", 0x2, "SUBLANG_SERBIAN_LATIN" },
409
  { "nso_ZA", 0x46c, "Sesotho sa Leboa (nso)", 0x6c, "LANG_SOTHO", "South Africa (ZA)", 0x1,
410
    "SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA" },
411
  { "tn_BW", 0x832, "Setswana / Tswana (tn)", 0x32, "LANG_TSWANA", "Botswana (BW)", 0x2,
412
    "SUBLANG_TSWANA_BOTSWANA" },
413
  { "tn_ZA", 0x432, "Setswana / Tswana (tn)", 0x32, "LANG_TSWANA", "South Africa (ZA)", 0x1,
414
    "SUBLANG_TSWANA_SOUTH_AFRICA" },
415
  { "", 0x859, "(reserved)", 0x59, "LANG_SINDHI", "(reserved)", 0x2,
416
    "SUBLANG_SINDHI_AFGHANISTAN" },
417
  { "", 0x459, "(reserved)", 0x59, "LANG_SINDHI", "(reserved)", 0x1, "SUBLANG_SINDHI_INDIA" },
418
  { "sd_PK", 0x859, "Sindhi (sd)", 0x59, "LANG_SINDHI", "Pakistan (PK)", 0x2,
419
    "SUBLANG_SINDHI_PAKISTAN" },
420
  { "si_LK", 0x45b, "Sinhala (si)", 0x5b, "LANG_SINHALESE", "Sri Lanka (LK)", 0x1,
421
    "SUBLANG_SINHALESE_SRI_LANKA" },
422
  { "sk_SK", 0x41b, "Slovak (sk)", 0x1b, "LANG_SLOVAK", "Slovakia (SK)", 0x1,
423
    "SUBLANG_SLOVAK_SLOVAKIA" },
424
  { "sl_SI", 0x424, "Slovenian (sl)", 0x24, "LANG_SLOVENIAN", "Slovenia (SI)", 0x1,
425
    "SUBLANG_SLOVENIAN_SLOVENIA" },
426
  { "es_AR", 0x2c0a, "Spanish (es)", 0xa, "LANG_SPANISH", "Argentina (AR)", 0xb,
427
    "SUBLANG_SPANISH_ARGENTINA" },
428
  { "es_BO", 0x400a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Bolivia (BO)", 0x10,
429
    "SUBLANG_SPANISH_BOLIVIA" },
430
  { "es_CL", 0x340a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Chile (CL)", 0xd,
431
    "SUBLANG_SPANISH_CHILE" },
432
  { "es_CO", 0x240a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Colombia (CO)", 0x9,
433
    "SUBLANG_SPANISH_COLOMBIA" },
434
  { "es_CR", 0x140a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Costa Rica (CR)", 0x5,
435
    "SUBLANG_SPANISH_COSTA_RICA" },
436
  { "es_DO", 0x1c0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Dominican Republic (DO)", 0x7,
437
    "SUBLANG_SPANISH_DOMINICAN_REPUBLIC" },
438
  { "es_EC", 0x300a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Ecuador (EC)", 0xc,
439
    "SUBLANG_SPANISH_ECUADOR" },
440
  { "es_SV", 0x440a, "Spanish (es)", 0x0a, "LANG_SPANISH", "El Salvador (SV)", 0x11,
441
    "SUBLANG_SPANISH_EL_SALVADOR" },
442
  { "es_GT", 0x100a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Guatemala (GT)", 0x4,
443
    "SUBLANG_SPANISH_GUATEMALA" },
444
  { "es_HN", 0x480a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Honduras (HN)", 0x12,
445
    "SUBLANG_SPANISH_HONDURAS" },
446
  { "es_MX", 0x80a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Mexico (MX)", 0x2,
447
    "SUBLANG_SPANISH_MEXICAN" },
448
  { "es_NI", 0x4c0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Nicaragua (NI)", 0x13,
449
    "SUBLANG_SPANISH_NICARAGUA" },
450
  { "es_PA", 0x180a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Panama (PA)", 0x6,
451
    "SUBLANG_SPANISH_PANAMA" },
452
  { "es_PY", 0x3c0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Paraguay (PY)", 0xf,
453
    "SUBLANG_SPANISH_PARAGUAY" },
454
  { "es_PE", 0x280a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Peru (PE)", 0xa,
455
    "SUBLANG_SPANISH_PERU" },
456
  { "es_PR", 0x500a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Puerto Rico (PR)", 0x14,
457
    "SUBLANG_SPANISH_PUERTO_RICO" },
458
  { "es_ES", 0xc0a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Spain, Modern Sort (ES)", 0x3,
459
    "SUBLANG_SPANISH_MODERN" },
460
  { "es_ES", 0x40a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Spain, Traditional Sort (ES)", 0x1,
461
    "SUBLANG_SPANISH" },
462
  { "es_US", 0x540a, "Spanish (es)", 0x0a, "LANG_SPANISH", "United States (US)", 0x15,
463
    "SUBLANG_SPANISH_US" },
464
  { "es_UY", 0x380a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Uruguay (UY)", 0xe,
465
    "SUBLANG_SPANISH_URUGUAY" },
466
  { "es_VE", 0x200a, "Spanish (es)", 0x0a, "LANG_SPANISH", "Venezuela (VE)", 0x8,
467
    "SUBLANG_SPANISH_VENEZUELA" },
468
  { "sw_KE", 0x441, "Swahili (sw)", 0x41, "LANG_SWAHILI", "Kenya (KE)", 0x1, "SUBLANG_SWAHILI" },
469
  { "sv_FI", 0x81d, "Swedish (sv)", 0x1d, "LANG_SWEDISH", "Finland (FI)", 0x2,
470
    "SUBLANG_SWEDISH_FINLAND" },
471
  { "sv_SE", 0x41d, "Swedish (sv)", 0x1d, "LANG_SWEDISH", "Sweden (SE);", 0x1,
472
    "SUBLANG_SWEDISH" },
473
  { "sv_SE", 0x41d, "Swedish (sv)", 0x1d, "LANG_SWEDISH", "Sweden (SE);", 0x1,
474
    "SUBLANG_SWEDISH_SWEDEN" },
475
  { "syr_SY", 0x45a, "Syriac (syr)", 0x5a, "LANG_SYRIAC", "Syria (SY)", 0x1, "SUBLANG_SYRIAC" },
476
  { "tg_TJ", 0x428, "Tajik (tg)", 0x28, "LANG_TAJIK", "Tajikistan, Cyrillic (TJ)", 0x1,
477
    "SUBLANG_TAJIK_TAJIKISTAN" },
478
  { "tzm_DZ", 0x85f, "Tamazight (tzm)", 0x5f, "LANG_TAMAZIGHT", "Algeria, Latin (DZ)", 0x2,
479
    "SUBLANG_TAMAZIGHT_ALGERIA_LATIN" },
480
  { "ta_IN", 0x449, "Tamil (ta)", 0x49, "LANG_TAMIL", "India (IN)", 0x1, "SUBLANG_TAMIL_INDIA" },
481
  { "ta_LK", 0x849, "Tamil (ta)", 0x49, "LANG_TAMIL", "Sri Lanka (LK)", 0x2,
482
    "SUBLANG_TAMIL_SRI_LANKA" },
483
  { "tt_RU", 0x444, "Tatar (tt)", 0x44, "LANG_TATAR", "Russia (RU)", 0x1,
484
    "SUBLANG_TATAR_RUSSIA" },
485
  { "te_IN", 0x44a, "Telugu (te)", 0x4a, "LANG_TELUGU", "India (IN)", 0x1,
486
    "SUBLANG_TELUGU_INDIA" },
487
  { "th_TH", 0x41e, "Thai (th)", 0x1e, "LANG_THAI", "Thailand (TH)", 0x1,
488
    "SUBLANG_THAI_THAILAND" },
489
  { "bo_CN", 0x451, "Tibetan (bo)", 0x51, "LANG_TIBETAN", "PRC (CN)", 0x1,
490
    "SUBLANG_TIBETAN_PRC" },
491
  { "ti_ER", 0x873, "Tigrinya (ti)", 0x73, "LANG_TIGRINYA", "Eritrea (ER)", 0x2,
492
    "SUBLANG_TIGRINYA_ERITREA" },
493
  { "ti_ET", 0x473, "Tigrinya (ti)", 0x73, "LANG_TIGRIGNA", "Ethiopia (ET)", 0x1,
494
    "SUBLANG_TIGRINYA_ETHIOPIA" },
495
  { "tr_TR", 0x41f, "Turkish (tr)", 0x1f, "LANG_TURKISH", "Turkey (TR)", 0x1,
496
    "SUBLANG_TURKISH_TURKEY" },
497
  { "tk_KM", 0x442, "Turkmen (tk)", 0x42, "LANG_TURKMEN", "Turkmenistan (TM)", 0x1,
498
    "SUBLANG_TURKMEN_TURKMENISTAN" },
499
  { "uk_UA", 0x422, "Ukrainian (uk)", 0x22, "LANG_UKRAINIAN", "Ukraine (UA)", 0x1,
500
    "SUBLANG_UKRAINIAN_UKRAINE" },
501
  { "hsb_DE", 0x42e, "Upper Sorbian (hsb)", 0x2e, "LANG_UPPER_SORBIAN", "Germany (DE)", 0x1,
502
    "SUBLANG_UPPER_SORBIAN_GERMANY" },
503
  { "ur", 0x820, "Urdu (ur)", 0x20, "LANG_URDU", "(reserved)", 0x2, "SUBLANG_URDU_INDIA" },
504
  { "ur_PK", 0x420, "Urdu (ur)", 0x20, "LANG_URDU", "Pakistan (PK)", 0x1,
505
    "SUBLANG_URDU_PAKISTAN" },
506
  { "ug_CN", 0x480, "Uyghur (ug)", 0x80, "LANG_UIGHUR", "PRC (CN)", 0x1, "SUBLANG_UIGHUR_PRC" },
507
  { "uz_UZ", 0x843, "Uzbek (uz)", 0x43, "LANG_UZBEK", "Uzbekistan, Cyrillic (UZ)", 0x2,
508
    "SUBLANG_UZBEK_CYRILLIC" },
509
  { "uz_UZ", 0x443, "Uzbek (uz)", 0x43, "LANG_UZBEK", "Uzbekistan, Latin (UZ)", 0x1,
510
    "SUBLANG_UZBEK_LATIN" },
511
  { "ca", 0x803, "Valencian (ca)", 0x3, "LANG_VALENCIAN", "Valencia (ES-Valencia)", 0x2,
512
    "SUBLANG_VALENCIAN_VALENCIA" },
513
  { "vi_VN", 0x42a, "Vietnamese (vi)", 0x2a, "LANG_VIETNAMESE", "Vietnam (VN)", 0x1,
514
    "SUBLANG_VIETNAMESE_VIETNAM" },
515
  { "cy_GB", 0x452, "Welsh (cy)", 0x52, "LANG_WELSH", "United Kingdom (GB)", 0x1,
516
    "SUBLANG_WELSH_UNITED_KINGDOM" },
517
  { "wo_SN", 0x488, "Wolof (wo)", 0x88, "LANG_WOLOF", "Senegal (SN)", 0x1,
518
    "SUBLANG_WOLOF_SENEGAL" },
519
  { "ii_CN", 0x478, "Yi (ii)", 0x78, "LANG_YI", "PRC (CN)", 0x1, "SUBLANG_YI_PRC" },
520
  { "yu_NG", 0x46a, "Yoruba (yo)", 0x6a, "LANG_YORUBA", "Nigeria (NG)", 0x1,
521
    "SUBLANG_YORUBA_NIGERIA" },
522
};
523
524
static BOOL reallocate_keyboard_layouts(RDP_KEYBOARD_LAYOUT** layouts, size_t* pcount,
525
                                        size_t to_add)
526
0
{
527
0
  WINPR_ASSERT(layouts);
528
0
  WINPR_ASSERT(pcount);
529
530
0
  RDP_KEYBOARD_LAYOUT* copy = (RDP_KEYBOARD_LAYOUT*)realloc(
531
0
      *layouts, (*pcount + to_add + 1) * sizeof(RDP_KEYBOARD_LAYOUT));
532
533
0
  if (!copy)
534
0
    return FALSE;
535
536
0
  memset(&copy[*pcount], 0, (to_add + 1) * sizeof(RDP_KEYBOARD_LAYOUT));
537
0
  *layouts = copy;
538
0
  *pcount += to_add;
539
0
  return TRUE;
540
0
}
541
542
#if !defined(WITH_KEYBOARD_LAYOUT_FROM_FILE)
543
/*
544
 * In Windows XP, this information is available in the system registry at
545
 * HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet001/Control/Keyboard Layouts/
546
 * https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values
547
 */
548
static const RDP_KEYBOARD_LAYOUT sRDP_KEYBOARD_LAYOUT_TABLE[] = {
549
  { 0x0000041c, "Albanian" },
550
  { 0x00000401, "Arabic (101)" },
551
  { 0x00010401, "Arabic (102)" },
552
  { 0x00020401, "Arabic (102) AZERTY" },
553
  { 0x0000042b, "Armenian Eastern" },
554
  { 0x0002042b, "Armenian Phonetic" },
555
  { 0x0003042b, "Armenian Typewriter" },
556
  { 0x0001042b, "Armenian Western" },
557
  { 0x0000044d, "Assamese - Inscript" },
558
  { 0x0001042c, "Azerbaijani (Standard)" },
559
  { 0x0000082c, "Azerbaijani Cyrillic" },
560
  { 0x0000042c, "Azerbaijani Latin" },
561
  { 0x0000046d, "Bashkir" },
562
  { 0x00000423, "Belarusian" },
563
  { 0x0001080c, "Belgian (Comma)" },
564
  { 0x00000813, "Belgian (Period)" },
565
  { 0x0000080c, "Belgian French" },
566
  { 0x00000445, "Bangla (Bangladesh)" },
567
  { 0x00020445, "Bangla (India)" },
568
  { 0x00010445, "Bangla (India - Legacy)" },
569
  { 0x0000201a, "Bosnian (Cyrillic)" },
570
  { 0x000b0c00, "Buginese" },
571
  { 0x00030402, "Bulgarian" },
572
  { 0x00010402, "Bulgarian (Latin)" },
573
  { 0x00020402, "Bulgarian (phonetic layout)" },
574
  { 0x00040402, "Bulgarian (phonetic traditional)" },
575
  { 0x00000402, "Bulgarian (Typewriter)" },
576
  { 0x00001009, "Canadian French" },
577
  { 0x00000c0c, "Canadian French (Legacy)" },
578
  { 0x00011009, "Canadian Multilingual Standard" },
579
  { 0x0000085f, "Central Atlas Tamazight" },
580
  { 0x00000429, "Central Kurdish" },
581
  { 0x0000045c, "Cherokee Nation" },
582
  { 0x0001045c, "Cherokee Nation Phonetic" },
583
  { 0x00000804, "Chinese (Simplified) - US Keyboard" },
584
  { 0x00000404, "Chinese (Traditional) - US Keyboard" },
585
  { 0x00000c04, "Chinese (Traditional, Hong Kong S.A.R.)" },
586
  { 0x00001404, "Chinese (Traditional Macao S.A.R.) US Keyboard" },
587
  { 0x00001004, "Chinese (Simplified, Singapore) - US keyboard" },
588
  { 0x0000041a, "Croatian" },
589
  { 0x00000405, "Czech" },
590
  { 0x00010405, "Czech (QWERTY)" },
591
  { 0x00020405, "Czech Programmers" },
592
  { 0x00000406, "Danish" },
593
  { 0x00000439, "Devanagari-INSCRIPT" },
594
  { 0x00000465, "Divehi Phonetic" },
595
  { 0x00010465, "Divehi Typewriter" },
596
  { 0x00000413, "Dutch" },
597
  { 0x00000c51, "Dzongkha" },
598
  { 0x00000425, "Estonian" },
599
  { 0x00000438, "Faeroese" },
600
  { 0x0000040b, "Finnish" },
601
  { 0x0001083b, "Finnish with Sami" },
602
  { 0x0000040c, "French" },
603
  { 0x00120c00, "Futhark" },
604
  { 0x00000437, "Georgian" },
605
  { 0x00020437, "Georgian (Ergonomic)" },
606
  { 0x00010437, "Georgian (QWERTY)" },
607
  { 0x00030437, "Georgian Ministry of Education and Science Schools" },
608
  { 0x00040437, "Georgian (Old Alphabets)" },
609
  { 0x00000407, "German" },
610
  { 0x00010407, "German (IBM)" },
611
  { 0x000c0c00, "Gothic" },
612
  { 0x00000408, "Greek" },
613
  { 0x00010408, "Greek (220)" },
614
  { 0x00030408, "Greek (220) Latin" },
615
  { 0x00020408, "Greek (319)" },
616
  { 0x00040408, "Greek (319) Latin" },
617
  { 0x00050408, "Greek Latin" },
618
  { 0x00060408, "Greek Polytonic" },
619
  { 0x0000046f, "Greenlandic" },
620
  { 0x00000474, "Guarani" },
621
  { 0x00000447, "Gujarati" },
622
  { 0x00000468, "Hausa" },
623
  { 0x0000040d, "Hebrew" },
624
  { 0x00010439, "Hindi Traditional" },
625
  { 0x0000040e, "Hungarian" },
626
  { 0x0001040e, "Hungarian 101-key" },
627
  { 0x0000040f, "Icelandic" },
628
  { 0x00000470, "Igbo" },
629
  { 0x00004009, "India" },
630
  { 0x0000085d, "Inuktitut - Latin" },
631
  { 0x0001045d, "Inuktitut - Naqittaut" },
632
  { 0x00001809, "Irish" },
633
  { 0x00000410, "Italian" },
634
  { 0x00010410, "Italian (142)" },
635
  { 0x00000411, "Japanese" },
636
  { 0x00110c00, "Javanese" },
637
  { 0x0000044b, "Kannada" },
638
  { 0x0000043f, "Kazakh" },
639
  { 0x00000453, "Khmer" },
640
  { 0x00010453, "Khmer (NIDA)" },
641
  { 0x00000412, "Korean" },
642
  { 0x00000440, "Kyrgyz Cyrillic" },
643
  { 0x00000454, "Lao" },
644
  { 0x0000080a, "Latin American" },
645
  { 0x00020426, "Latvian (Standard)" },
646
  { 0x00010426, "Latvian (Legacy)" },
647
  { 0x00070c00, "Lisu (Basic)" },
648
  { 0x00080c00, "Lisu (Standard)" },
649
  { 0x00010427, "Lithuanian" },
650
  { 0x00000427, "Lithuanian IBM" },
651
  { 0x00020427, "Lithuanian Standard" },
652
  { 0x0000046e, "Luxembourgish" },
653
  { 0x0000042f, "Macedonia (FYROM)" },
654
  { 0x0001042f, "Macedonia (FYROM) - Standard" },
655
  { 0x0000044c, "Malayalam" },
656
  { 0x0000043a, "Maltese 47-Key" },
657
  { 0x0001043a, "Maltese 48-key" },
658
  { 0x00000481, "Maori" },
659
  { 0x0000044e, "Marathi" },
660
  { 0x00000850, "Mongolian (Mongolian Script - Legacy)" },
661
  { 0x00020850, "Mongolian (Mongolian Script - Standard)" },
662
  { 0x00000450, "Mongolian Cyrillic" },
663
  { 0x00010c00, "Myanmar" },
664
  { 0x00090c00, "N'ko" },
665
  { 0x00000461, "Nepali" },
666
  { 0x00020c00, "New Tai Lue" },
667
  { 0x00000414, "Norwegian" },
668
  { 0x0000043b, "Norwegian with Sami" },
669
  { 0x00000448, "Odia" },
670
  { 0x000d0c00, "Ol Chiki" },
671
  { 0x000f0c00, "Old Italic" },
672
  { 0x000e0c00, "Osmanya" },
673
  { 0x00000463, "Pashto (Afghanistan)" },
674
  { 0x00000429, "Persian" },
675
  { 0x00050429, "Persian (Standard)" },
676
  { 0x000a0c00, "Phags-pa" },
677
  { 0x00010415, "Polish (214)" },
678
  { 0x00000415, "Polish (Programmers)" },
679
  { 0x00000816, "Portuguese" },
680
  { 0x00000416, "Portuguese (Brazilian ABNT)" },
681
  { 0x00010416, "Portuguese (Brazilian ABNT2)" },
682
  { 0x00000446, "Punjabi" },
683
  { 0x00000418, "Romanian (Legacy)" },
684
  { 0x00020418, "Romanian (Programmers)" },
685
  { 0x00010418, "Romanian (Standard)" },
686
  { 0x00000419, "Russian" },
687
  { 0x00020419, "Russian - Mnemonic" },
688
  { 0x00010419, "Russian (Typewriter)" },
689
  { 0x00000485, "Sakha" },
690
  { 0x0002083b, "Sami Extended Finland-Sweden" },
691
  { 0x0001043b, "Sami Extended Norway" },
692
  { 0x00011809, "Scottish Gaelic" },
693
  { 0x00000c1a, "Serbian (Cyrillic)" },
694
  { 0x0000081a, "Serbian (Latin)" },
695
  { 0x0000046c, "Sesotho sa Leboa" },
696
  { 0x00000432, "Setswana" },
697
  { 0x0000045b, "Sinhala" },
698
  { 0x0001045b, "Sinhala - wij 9" },
699
  { 0x0000041b, "Slovak" },
700
  { 0x0001041b, "Slovak (QWERTY)" },
701
  { 0x00000424, "Slovenian" },
702
  { 0x00100c00, "Sora" },
703
  { 0x0001042e, "Sorbian Extended" },
704
  { 0x0002042e, "Sorbian Standard" },
705
  { 0x0000042e, "Sorbian Standard (Legacy)" },
706
  { 0x0000040a, "Spanish" },
707
  { 0x0001040a, "Spanish Variation" },
708
  { 0x0000041d, "Swedish" },
709
  { 0x0000083b, "Swedish with Sami" },
710
  { 0x0000100c, "Swiss French" },
711
  { 0x00000807, "Swiss German" },
712
  { 0x0000045a, "Syriac" },
713
  { 0x0001045a, "Syriac Phonetic" },
714
  { 0x00030c00, "Tai Le" },
715
  { 0x00000428, "Tajik" },
716
  { 0x00000449, "Tamil" },
717
  { 0x00010444, "Tatar" },
718
  { 0x00000444, "Tatar (Legacy)" },
719
  { 0x0000044a, "Telugu" },
720
  { 0x0000041e, "Thai Kedmanee" },
721
  { 0x0002041e, "Thai Kedmanee (non-ShiftLock)" },
722
  { 0x0001041e, "Thai Pattachote" },
723
  { 0x0003041e, "Thai Pattachote (non-ShiftLock)" },
724
  { 0x00010451, "Tibetan (PRC - Standard)" },
725
  { 0x00000451, "Tibetan (PRC - Legacy)" },
726
  { 0x00050c00, "Tifinagh (Basic)" },
727
  { 0x00060c00, "Tifinagh (Full)" },
728
  { 0x0001041f, "Turkish F" },
729
  { 0x0000041f, "Turkish Q" },
730
  { 0x00000442, "Turkmen" },
731
  { 0x00010408, "Uyghur" },
732
  { 0x00000480, "Uyghur (Legacy)" },
733
  { 0x00000422, "Ukrainian" },
734
  { 0x00020422, "Ukrainian (Enhanced)" },
735
  { 0x00000809, "United Kingdom" },
736
  { 0x00000452, "United Kingdom Extended" },
737
  { 0x00010409, "United States - Dvorak" },
738
  { 0x00020409, "United States - International" },
739
  { 0x00030409, "United States-Dvorak for left hand" },
740
  { 0x00040409, "United States-Dvorak for right hand" },
741
  { 0x00000409, "United States - English" },
742
  { 0x00000420, "Urdu" },
743
  { 0x00010480, "Uyghur" },
744
  { 0x00000843, "Uzbek Cyrillic" },
745
  { 0x0000042a, "Vietnamese" },
746
  { 0x00000488, "Wolof" },
747
  { 0x00000485, "Yakut" },
748
  { 0x0000046a, "Yoruba" },
749
};
750
static const size_t sRDP_KEYBOARD_LAYOUT_TABLE_len = ARRAYSIZE(sRDP_KEYBOARD_LAYOUT_TABLE);
751
752
static const RDP_KEYBOARD_LAYOUT_VARIANT sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[] = {
753
  { KBD_ARABIC_102, 0x0028, "Arabic (102)" },
754
  { KBD_BULGARIAN_LATIN, 0x0004, "Bulgarian (Latin)" },
755
  { KBD_CZECH_QWERTY, 0x0005, "Czech (QWERTY)" },
756
  { KBD_GERMAN_IBM, 0x0012, "German (IBM)" },
757
  { KBD_GREEK_220, 0x0016, "Greek (220)" },
758
  { KBD_UNITED_STATES_DVORAK, 0x0002, "United States-Dvorak" },
759
  { KBD_SPANISH_VARIATION, 0x0086, "Spanish Variation" },
760
  { KBD_HUNGARIAN_101_KEY, 0x0006, "Hungarian 101-key" },
761
  { KBD_ITALIAN_142, 0x0003, "Italian (142)" },
762
  { KBD_POLISH_214, 0x0007, "Polish (214)" },
763
  { KBD_PORTUGUESE_BRAZILIAN_ABNT2, 0x001D, "Portuguese (Brazilian ABNT2)" },
764
  { KBD_RUSSIAN_TYPEWRITER, 0x0008, "Russian (Typewriter)" },
765
  { KBD_SLOVAK_QWERTY, 0x0013, "Slovak (QWERTY)" },
766
  { KBD_THAI_PATTACHOTE, 0x0021, "Thai Pattachote" },
767
  { KBD_TURKISH_F, 0x0014, "Turkish F" },
768
  { KBD_LATVIAN_QWERTY, 0x0015, "Latvian (QWERTY)" },
769
  { KBD_LITHUANIAN, 0x0027, "Lithuanian" },
770
  { KBD_ARMENIAN_WESTERN, 0x0025, "Armenian Western" },
771
  { KBD_HINDI_TRADITIONAL, 0x000C, "Hindi Traditional" },
772
  { KBD_MALTESE_48_KEY, 0x002B, "Maltese 48-key" },
773
  { KBD_SAMI_EXTENDED_NORWAY, 0x002C, "Sami Extended Norway" },
774
  { KBD_BENGALI_INSCRIPT, 0x002A, "Bengali (Inscript)" },
775
  { KBD_SYRIAC_PHONETIC, 0x000E, "Syriac Phonetic" },
776
  { KBD_DIVEHI_TYPEWRITER, 0x000D, "Divehi Typewriter" },
777
  { KBD_BELGIAN_COMMA, 0x001E, "Belgian (Comma)" },
778
  { KBD_FINNISH_WITH_SAMI, 0x002D, "Finnish with Sami" },
779
  { KBD_CANADIAN_MULTILINGUAL_STANDARD, 0x0020, "Canadian Multilingual Standard" },
780
  { KBD_GAELIC, 0x0026, "Gaelic" },
781
  { KBD_ARABIC_102_AZERTY, 0x0029, "Arabic (102) AZERTY" },
782
  { KBD_CZECH_PROGRAMMERS, 0x000A, "Czech Programmers" },
783
  { KBD_GREEK_319, 0x0018, "Greek (319)" },
784
  { KBD_UNITED_STATES_INTERNATIONAL, 0x0001, "United States-International" },
785
  { KBD_THAI_KEDMANEE_NON_SHIFTLOCK, 0x0022, "Thai Kedmanee (non-ShiftLock)" },
786
  { KBD_SAMI_EXTENDED_FINLAND_SWEDEN, 0x002E, "Sami Extended Finland-Sweden" },
787
  { KBD_GREEK_220_LATIN, 0x0017, "Greek (220) Latin" },
788
  { KBD_UNITED_STATES_DVORAK_FOR_LEFT_HAND, 0x001A, "United States-Dvorak for left hand" },
789
  { KBD_THAI_PATTACHOTE_NON_SHIFTLOCK, 0x0023, "Thai Pattachote (non-ShiftLock)" },
790
  { KBD_GREEK_319_LATIN, 0x0011, "Greek (319) Latin" },
791
  { KBD_UNITED_STATES_DVORAK_FOR_RIGHT_HAND, 0x001B, "United States-Dvorak for right hand" },
792
  { KBD_UNITED_STATES_DVORAK_PROGRAMMER, 0x001C, "United States-Programmer Dvorak" },
793
  { KBD_GREEK_LATIN, 0x0019, "Greek Latin" },
794
  { KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L, 0x000B, "US English Table for IBM Arabic 238_L" },
795
  { KBD_GREEK_POLYTONIC, 0x001F, "Greek Polytonic" },
796
  { KBD_FRENCH_BEPO, 0x00C0, "French Bépo" },
797
  { KBD_GERMAN_NEO, 0x00C0, "German Neo" }
798
};
799
static const size_t sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len =
800
    ARRAYSIZE(sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
801
802
/* Input Method Editor (IME) */
803
804
/* Global Input Method Editors (IME) */
805
806
static const RDP_KEYBOARD_IME sRDP_KEYBOARD_IME_TABLE[] = {
807
  { KBD_CHINESE_TRADITIONAL_PHONETIC, "phon.ime", "Chinese (Traditional) - Phonetic" },
808
  { KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002, "imjp81.ime", "Japanese Input System (MS-IME2002)" },
809
  { KBD_KOREAN_INPUT_SYSTEM_IME_2000, "imekr61.ime", "Korean Input System (IME 2000)" },
810
  { KBD_CHINESE_SIMPLIFIED_QUANPIN, "winpy.ime", "Chinese (Simplified) - QuanPin" },
811
  { KBD_CHINESE_TRADITIONAL_CHANGJIE, "chajei.ime", "Chinese (Traditional) - ChangJie" },
812
  { KBD_CHINESE_SIMPLIFIED_SHUANGPIN, "winsp.ime", "Chinese (Simplified) - ShuangPin" },
813
  { KBD_CHINESE_TRADITIONAL_QUICK, "quick.ime", "Chinese (Traditional) - Quick" },
814
  { KBD_CHINESE_SIMPLIFIED_ZHENGMA, "winzm.ime", "Chinese (Simplified) - ZhengMa" },
815
  { KBD_CHINESE_TRADITIONAL_BIG5_CODE, "winime.ime", "Chinese (Traditional) - Big5 Code" },
816
  { KBD_CHINESE_TRADITIONAL_ARRAY, "winar30.ime", "Chinese (Traditional) - Array" },
817
  { KBD_CHINESE_SIMPLIFIED_NEIMA, "wingb.ime", "Chinese (Simplified) - NeiMa" },
818
  { KBD_CHINESE_TRADITIONAL_DAYI, "dayi.ime", "Chinese (Traditional) - DaYi" },
819
  { KBD_CHINESE_TRADITIONAL_UNICODE, "unicdime.ime", "Chinese (Traditional) - Unicode" },
820
  { KBD_CHINESE_TRADITIONAL_NEW_PHONETIC, "TINTLGNT.IME",
821
    "Chinese (Traditional) - New Phonetic" },
822
  { KBD_CHINESE_TRADITIONAL_NEW_CHANGJIE, "CINTLGNT.IME",
823
    "Chinese (Traditional) - New ChangJie" },
824
  { KBD_CHINESE_TRADITIONAL_MICROSOFT_PINYIN_IME_3, "pintlgnt.ime",
825
    "Chinese (Traditional) - Microsoft Pinyin IME 3.0" },
826
  { KBD_CHINESE_TRADITIONAL_ALPHANUMERIC, "romanime.ime", "Chinese (Traditional) - Alphanumeric" }
827
};
828
static const size_t sRDP_KEYBOARD_IME_TABLE_len = ARRAYSIZE(sRDP_KEYBOARD_IME_TABLE);
829
830
#if defined(DUMP_LAYOUTS_TO_JSON)
831
static BOOL append_layout(WINPR_JSON* json)
832
{
833
  WINPR_JSON* array = WINPR_JSON_AddArrayToObject(json, "KeyboardLayouts");
834
  if (!array)
835
    return FALSE;
836
837
  for (size_t x = 0; x < sRDP_KEYBOARD_LAYOUT_TABLE_len; x++)
838
  {
839
    const RDP_KEYBOARD_LAYOUT* const ime = &sRDP_KEYBOARD_LAYOUT_TABLE[x];
840
    WINPR_JSON* obj = WINPR_JSON_CreateObject();
841
    if (!obj)
842
      return FALSE;
843
    WINPR_JSON_AddNumberToObject(obj, "code", ime->code);
844
    WINPR_JSON_AddStringToObject(obj, "name", ime->name);
845
846
    if (!WINPR_JSON_AddItemToArray(array, obj))
847
      return FALSE;
848
  }
849
850
  return TRUE;
851
}
852
853
static BOOL append_variant(WINPR_JSON* json)
854
{
855
  WINPR_JSON* array = WINPR_JSON_AddArrayToObject(json, "KeyboardVariants");
856
  if (!array)
857
    return FALSE;
858
859
  for (size_t x = 0; x < sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len; x++)
860
  {
861
    const RDP_KEYBOARD_LAYOUT_VARIANT* const ime = &sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[x];
862
    WINPR_JSON* obj = WINPR_JSON_CreateObject();
863
    if (!obj)
864
      return FALSE;
865
    WINPR_JSON_AddNumberToObject(obj, "code", ime->code);
866
    WINPR_JSON_AddNumberToObject(obj, "id", ime->id);
867
    WINPR_JSON_AddStringToObject(obj, "name", ime->name);
868
869
    if (!WINPR_JSON_AddItemToArray(array, obj))
870
      return FALSE;
871
  }
872
873
  return TRUE;
874
}
875
876
static BOOL append_ime(WINPR_JSON* json)
877
{
878
  WINPR_JSON* array = WINPR_JSON_AddArrayToObject(json, "KeyboardIme");
879
  if (!array)
880
    return FALSE;
881
882
  for (size_t x = 0; x < sRDP_KEYBOARD_IME_TABLE_len; x++)
883
  {
884
    const RDP_KEYBOARD_IME* const ime = &sRDP_KEYBOARD_IME_TABLE[x];
885
    WINPR_JSON* obj = WINPR_JSON_CreateObject();
886
    if (!obj)
887
      return FALSE;
888
    WINPR_JSON_AddNumberToObject(obj, "code", ime->code);
889
    WINPR_JSON_AddStringToObject(obj, "file", ime->file);
890
    WINPR_JSON_AddStringToObject(obj, "name", ime->name);
891
892
    if (!WINPR_JSON_AddItemToArray(array, obj))
893
      return FALSE;
894
  }
895
896
  return TRUE;
897
}
898
#endif
899
900
static BOOL load_layout_file(void)
901
0
{
902
#if defined(DUMP_LAYOUTS_TO_JSON)
903
  /* Dump to file in /tmp */
904
  char* str = NULL;
905
  WINPR_JSON* json = WINPR_JSON_CreateObject();
906
  if (!json)
907
    goto end;
908
909
  if (!append_layout(json))
910
    goto end;
911
  if (!append_variant(json))
912
    goto end;
913
  if (!append_ime(json))
914
    goto end;
915
916
  str = WINPR_JSON_Print(json);
917
  if (!str)
918
    goto end;
919
  {
920
    FILE* fp = winpr_fopen("/tmp/kbd.json", "w");
921
    if (!fp)
922
      goto end;
923
    (void)fprintf(fp, "%s", str);
924
    fclose(fp);
925
  }
926
end:
927
  free(str);
928
  WINPR_JSON_Delete(json);
929
#endif
930
0
  return TRUE;
931
0
}
932
#else
933
static RDP_KEYBOARD_LAYOUT* sRDP_KEYBOARD_LAYOUT_TABLE = NULL;
934
static size_t sRDP_KEYBOARD_LAYOUT_TABLE_len = 0;
935
936
static RDP_KEYBOARD_LAYOUT_VARIANT* sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE = NULL;
937
static size_t sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len = 0;
938
939
static RDP_KEYBOARD_IME* sRDP_KEYBOARD_IME_TABLE = NULL;
940
static size_t sRDP_KEYBOARD_IME_TABLE_len = 0;
941
942
static void clear_keyboard_layout(RDP_KEYBOARD_LAYOUT* layout)
943
{
944
  if (!layout)
945
    return;
946
947
  free(layout->name);
948
  const RDP_KEYBOARD_LAYOUT empty = { 0 };
949
  *layout = empty;
950
}
951
952
static void clear_keyboard_variant(RDP_KEYBOARD_LAYOUT_VARIANT* layout)
953
{
954
  if (!layout)
955
    return;
956
957
  free(layout->name);
958
  const RDP_KEYBOARD_LAYOUT_VARIANT empty = { 0 };
959
  *layout = empty;
960
}
961
962
static void clear_keyboard_ime(RDP_KEYBOARD_IME* layout)
963
{
964
  if (!layout)
965
    return;
966
967
  free(layout->file);
968
  free(layout->name);
969
  const RDP_KEYBOARD_IME empty = { 0 };
970
  *layout = empty;
971
}
972
973
static void clear_layout_tables(void)
974
{
975
  for (size_t x = 0; x < sRDP_KEYBOARD_LAYOUT_TABLE_len; x++)
976
  {
977
    RDP_KEYBOARD_LAYOUT* layout = &sRDP_KEYBOARD_LAYOUT_TABLE[x];
978
    clear_keyboard_layout(layout);
979
  }
980
981
  free(sRDP_KEYBOARD_LAYOUT_TABLE);
982
  sRDP_KEYBOARD_LAYOUT_TABLE = NULL;
983
  sRDP_KEYBOARD_LAYOUT_TABLE_len = 0;
984
985
  for (size_t x = 0; x < sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len; x++)
986
  {
987
    RDP_KEYBOARD_LAYOUT_VARIANT* variant = &sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[x];
988
    clear_keyboard_variant(variant);
989
  }
990
  free(sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
991
  sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE = NULL;
992
  sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len = 0;
993
994
  for (size_t x = 0; x < sRDP_KEYBOARD_IME_TABLE_len; x++)
995
  {
996
    RDP_KEYBOARD_IME* ime = &sRDP_KEYBOARD_IME_TABLE[x];
997
    clear_keyboard_ime(ime);
998
  }
999
  free(sRDP_KEYBOARD_IME_TABLE);
1000
  sRDP_KEYBOARD_IME_TABLE = NULL;
1001
  sRDP_KEYBOARD_IME_TABLE_len = 0;
1002
}
1003
1004
static WINPR_JSON* load_layouts_from_file(const char* filename)
1005
{
1006
  INT64 jstrlen = 0;
1007
  char* jstr = NULL;
1008
  WINPR_JSON* json = NULL;
1009
  FILE* fp = winpr_fopen(filename, "r");
1010
  if (!fp)
1011
  {
1012
    WLog_WARN(TAG, "resource file '%s' does not exist or is not readable", filename);
1013
    return NULL;
1014
  }
1015
1016
  if (_fseeki64(fp, 0, SEEK_END) < 0)
1017
  {
1018
    WLog_WARN(TAG, "resource file '%s' seek failed", filename);
1019
    goto end;
1020
  }
1021
  jstrlen = _ftelli64(fp);
1022
  if (jstrlen < 0)
1023
  {
1024
    WLog_WARN(TAG, "resource file '%s' invalid length %" PRId64, filename, jstrlen);
1025
    goto end;
1026
  }
1027
  if (_fseeki64(fp, 0, SEEK_SET) < 0)
1028
  {
1029
    WLog_WARN(TAG, "resource file '%s' seek failed", filename);
1030
    goto end;
1031
  }
1032
1033
  jstr = calloc(jstrlen + 1, sizeof(char));
1034
  if (!jstr)
1035
  {
1036
    WLog_WARN(TAG, "resource file '%s' failed to allocate buffer of size %" PRId64, filename,
1037
              jstrlen);
1038
    goto end;
1039
  }
1040
1041
  if (fread(jstr, jstrlen, sizeof(char), fp) != 1)
1042
  {
1043
    WLog_WARN(TAG, "resource file '%s' failed to read buffer of size %" PRId64, filename,
1044
              jstrlen);
1045
    goto end;
1046
  }
1047
1048
  json = WINPR_JSON_ParseWithLength(jstr, jstrlen);
1049
  if (!json)
1050
    WLog_WARN(TAG, "resource file '%s' is not a valid JSON file", filename);
1051
end:
1052
  fclose(fp);
1053
  free(jstr);
1054
  return json;
1055
}
1056
1057
static char* get_object_str(WINPR_JSON* json, size_t pos, const char* name)
1058
{
1059
  WINPR_ASSERT(json);
1060
  if (!WINPR_JSON_IsObject(json) || !WINPR_JSON_HasObjectItem(json, name))
1061
  {
1062
    WLog_WARN(TAG, "Invalid JSON entry at entry %" PRIuz ", missing an Object named '%s'", pos,
1063
              name);
1064
    return NULL;
1065
  }
1066
  WINPR_JSON* obj = WINPR_JSON_GetObjectItem(json, name);
1067
  WINPR_ASSERT(obj);
1068
  if (!WINPR_JSON_IsString(obj))
1069
  {
1070
    WLog_WARN(TAG,
1071
              "Invalid JSON entry at entry %" PRIuz ", Object named '%s': Not of type string",
1072
              pos, name);
1073
    return NULL;
1074
  }
1075
1076
  const char* str = WINPR_JSON_GetStringValue(obj);
1077
  if (!str)
1078
  {
1079
    WLog_WARN(TAG, "Invalid JSON entry at entry %" PRIuz ", Object named '%s': NULL string",
1080
              pos, name);
1081
    return NULL;
1082
  }
1083
1084
  return _strdup(str);
1085
}
1086
1087
static UINT32 get_object_integer(WINPR_JSON* json, size_t pos, const char* name)
1088
{
1089
  WINPR_ASSERT(json);
1090
  if (!WINPR_JSON_IsObject(json) || !WINPR_JSON_HasObjectItem(json, name))
1091
  {
1092
    WLog_WARN(TAG, "Invalid JSON entry at entry %" PRIuz ", missing an Object named '%s'", pos,
1093
              name);
1094
    return 0;
1095
  }
1096
  WINPR_JSON* obj = WINPR_JSON_GetObjectItem(json, name);
1097
  WINPR_ASSERT(obj);
1098
  if (!WINPR_JSON_IsNumber(obj))
1099
  {
1100
    WLog_WARN(TAG,
1101
              "Invalid JSON entry at entry %" PRIuz ", Object named '%s': Not of type string",
1102
              pos, name);
1103
    return 0;
1104
  }
1105
1106
  return WINPR_JSON_GetNumberValue(obj);
1107
}
1108
1109
static BOOL parse_json_layout_entry(WINPR_JSON* json, size_t pos, RDP_KEYBOARD_LAYOUT* entry)
1110
{
1111
  WINPR_ASSERT(entry);
1112
  if (!json || !WINPR_JSON_IsObject(json))
1113
  {
1114
    WLog_WARN(TAG, "Invalid JSON entry at entry %" PRIuz ", expected an array", pos);
1115
    return FALSE;
1116
  }
1117
1118
  entry->code = get_object_integer(json, pos, "code");
1119
  entry->name = get_object_str(json, pos, "name");
1120
  if (!entry->name)
1121
  {
1122
    clear_keyboard_layout(entry);
1123
    return FALSE;
1124
  }
1125
  return TRUE;
1126
}
1127
1128
static BOOL parse_layout_entries(WINPR_JSON* json, const char* filename)
1129
{
1130
  if (!WINPR_JSON_IsArray(json))
1131
  {
1132
    WLog_WARN(TAG, "Invalid top level JSON type in file %s, expected an array", filename);
1133
    return FALSE;
1134
  }
1135
  return TRUE;
1136
}
1137
1138
static BOOL parse_json_variant_entry(WINPR_JSON* json, size_t pos,
1139
                                     RDP_KEYBOARD_LAYOUT_VARIANT* entry)
1140
{
1141
  WINPR_ASSERT(entry);
1142
  if (!json || !WINPR_JSON_IsObject(json))
1143
  {
1144
    WLog_WARN(TAG, "Invalid JSON entry at entry %" PRIuz ", expected an array", pos);
1145
    return FALSE;
1146
  }
1147
1148
  entry->code = get_object_integer(json, pos, "code");
1149
  entry->id = get_object_integer(json, pos, "id");
1150
  entry->name = get_object_str(json, pos, "name");
1151
  if (!entry->name)
1152
  {
1153
    clear_keyboard_variant(entry);
1154
    return FALSE;
1155
  }
1156
  return TRUE;
1157
}
1158
1159
static BOOL parse_variant_entries(WINPR_JSON* json, const char* filename)
1160
{
1161
  if (!WINPR_JSON_IsArray(json))
1162
  {
1163
    WLog_WARN(TAG, "Invalid top level JSON type in file %s, expected an array", filename);
1164
    return FALSE;
1165
  }
1166
  WINPR_ASSERT(!sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
1167
  WINPR_ASSERT(sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len == 0);
1168
1169
  const size_t count = WINPR_JSON_GetArraySize(json);
1170
  sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE = calloc(count, sizeof(RDP_KEYBOARD_LAYOUT_VARIANT));
1171
  if (!sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE)
1172
    return FALSE;
1173
  sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len = count;
1174
1175
  for (size_t x = 0; x < count; x++)
1176
  {
1177
    WINPR_JSON* entry = WINPR_JSON_GetArrayItem(json, x);
1178
    if (!parse_json_variant_entry(entry, x, &sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[x]))
1179
      return FALSE;
1180
  }
1181
  return TRUE;
1182
}
1183
1184
static BOOL parse_json_ime_entry(WINPR_JSON* json, size_t pos, RDP_KEYBOARD_IME* entry)
1185
{
1186
  WINPR_ASSERT(entry);
1187
  if (!json || !WINPR_JSON_IsObject(json))
1188
  {
1189
    WLog_WARN(TAG, "Invalid JSON entry at entry %" PRIuz ", expected an array", pos);
1190
    return FALSE;
1191
  }
1192
1193
  entry->code = get_object_integer(json, pos, "code");
1194
  entry->file = get_object_str(json, pos, "file");
1195
  entry->name = get_object_str(json, pos, "name");
1196
  if (!entry->file || !entry->name)
1197
  {
1198
    clear_keyboard_ime(entry);
1199
    return FALSE;
1200
  }
1201
  return TRUE;
1202
}
1203
1204
static BOOL parse_ime_entries(WINPR_JSON* json, const char* filename)
1205
{
1206
  if (!WINPR_JSON_IsArray(json))
1207
  {
1208
    WLog_WARN(TAG, "Invalid top level JSON type in file %s, expected an array", filename);
1209
    return FALSE;
1210
  }
1211
  WINPR_ASSERT(!sRDP_KEYBOARD_IME_TABLE);
1212
  WINPR_ASSERT(sRDP_KEYBOARD_IME_TABLE_len == 0);
1213
1214
  const size_t count = WINPR_JSON_GetArraySize(json);
1215
  sRDP_KEYBOARD_IME_TABLE = calloc(count, sizeof(RDP_KEYBOARD_IME));
1216
  if (!sRDP_KEYBOARD_IME_TABLE)
1217
    return FALSE;
1218
  sRDP_KEYBOARD_IME_TABLE_len = count;
1219
1220
  for (size_t x = 0; x < count; x++)
1221
  {
1222
    WINPR_JSON* entry = WINPR_JSON_GetArrayItem(json, x);
1223
    if (!parse_json_ime_entry(entry, x, &sRDP_KEYBOARD_IME_TABLE[x]))
1224
      return FALSE;
1225
  }
1226
  return TRUE;
1227
}
1228
1229
static BOOL CALLBACK load_layouts(PINIT_ONCE once, PVOID param, PVOID* context)
1230
{
1231
  WINPR_UNUSED(once);
1232
  WINPR_UNUSED(param);
1233
  WINPR_UNUSED(context);
1234
1235
  WINPR_JSON* json = NULL;
1236
  char* filename = GetCombinedPath(FREERDP_RESOURCE_ROOT, "KeyboardLayoutMap.json");
1237
  if (!filename)
1238
  {
1239
    WLog_WARN(TAG, "Could not create WinPR timezone resource filename");
1240
    goto end;
1241
  }
1242
1243
  json = load_layouts_from_file(filename);
1244
  if (!json)
1245
    goto end;
1246
  if (!WINPR_JSON_IsObject(json))
1247
  {
1248
    WLog_WARN(TAG, "Invalid top level JSON type in file %s, expected an array", filename);
1249
    goto end;
1250
  }
1251
1252
  {
1253
    WINPR_JSON* obj = WINPR_JSON_GetObjectItem(json, "KeyboardLayouts");
1254
    if (!parse_layout_entries(obj, filename))
1255
      goto end;
1256
  }
1257
  {
1258
    WINPR_JSON* obj = WINPR_JSON_GetObjectItem(json, "KeyboardVariants");
1259
    if (!parse_variant_entries(obj, filename))
1260
      goto end;
1261
  }
1262
  {
1263
    WINPR_JSON* obj = WINPR_JSON_GetObjectItem(json, "KeyboardIme");
1264
    if (!parse_ime_entries(obj, filename))
1265
      goto end;
1266
  }
1267
1268
end:
1269
  free(filename);
1270
  WINPR_JSON_Delete(json);
1271
  (void)atexit(clear_layout_tables);
1272
  return TRUE;
1273
}
1274
1275
static BOOL load_layout_file(void)
1276
{
1277
  static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
1278
  InitOnceExecuteOnce(&once, load_layouts, NULL, NULL);
1279
  return TRUE;
1280
}
1281
1282
#endif
1283
1284
static UINT32 rdp_keyboard_layout_by_name(const char* name)
1285
0
{
1286
0
  WINPR_ASSERT(name);
1287
0
  load_layout_file();
1288
1289
0
  for (size_t i = 0; i < sRDP_KEYBOARD_LAYOUT_TABLE_len; i++)
1290
0
  {
1291
0
    const RDP_KEYBOARD_LAYOUT* const layout = &sRDP_KEYBOARD_LAYOUT_TABLE[i];
1292
0
    if (strcmp(layout->name, name) == 0)
1293
0
      return layout->code;
1294
0
  }
1295
0
  return 0;
1296
0
}
1297
1298
static UINT32 rdp_keyboard_variant_by_name(const char* name)
1299
0
{
1300
0
  WINPR_ASSERT(name);
1301
0
  load_layout_file();
1302
1303
0
  for (size_t i = 0; i < sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len; i++)
1304
0
  {
1305
0
    const RDP_KEYBOARD_LAYOUT_VARIANT* const variant = &sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i];
1306
0
    if (strcmp(variant->name, name) == 0)
1307
0
      return variant->code;
1308
0
  }
1309
0
  return 0;
1310
0
}
1311
1312
static UINT32 rdp_keyboard_ime_by_name(const char* name)
1313
0
{
1314
0
  WINPR_ASSERT(name);
1315
0
  load_layout_file();
1316
1317
0
  for (size_t i = 0; i < sRDP_KEYBOARD_IME_TABLE_len; i++)
1318
0
  {
1319
0
    const RDP_KEYBOARD_IME* const ime = &sRDP_KEYBOARD_IME_TABLE[i];
1320
0
    if (strcmp(ime->name, name) == 0)
1321
0
      return ime->code;
1322
0
  }
1323
0
  return 0;
1324
0
}
1325
1326
static const char* rdp_keyboard_layout_by_id(UINT32 id)
1327
0
{
1328
0
  load_layout_file();
1329
1330
0
  for (size_t i = 0; i < sRDP_KEYBOARD_LAYOUT_TABLE_len; i++)
1331
0
  {
1332
0
    const RDP_KEYBOARD_LAYOUT* const layout = &sRDP_KEYBOARD_LAYOUT_TABLE[i];
1333
0
    if (layout->code == id)
1334
0
      return layout->name;
1335
0
  }
1336
1337
0
  return 0;
1338
0
}
1339
1340
static const char* rdp_keyboard_variant_by_id(UINT32 id)
1341
0
{
1342
0
  load_layout_file();
1343
1344
0
  for (size_t i = 0; i < sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len; i++)
1345
0
  {
1346
0
    const RDP_KEYBOARD_LAYOUT_VARIANT* const variant = &sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i];
1347
0
    if (variant->code == id)
1348
0
      return variant->name;
1349
0
  }
1350
0
  return 0;
1351
0
}
1352
1353
static const char* rdp_keyboard_ime_by_id(UINT32 id)
1354
0
{
1355
0
  load_layout_file();
1356
1357
0
  for (size_t i = 0; i < sRDP_KEYBOARD_IME_TABLE_len; i++)
1358
0
  {
1359
0
    const RDP_KEYBOARD_IME* const ime = &sRDP_KEYBOARD_IME_TABLE[i];
1360
0
    if (ime->code == id)
1361
0
      return ime->name;
1362
0
  }
1363
0
  return NULL;
1364
0
}
1365
1366
static BOOL rdp_keyboard_layout_clone_append(RDP_KEYBOARD_LAYOUT** layouts, size_t* pcount)
1367
0
{
1368
0
  WINPR_ASSERT(layouts);
1369
0
  WINPR_ASSERT(pcount);
1370
1371
0
  load_layout_file();
1372
1373
0
  const size_t length = sRDP_KEYBOARD_LAYOUT_TABLE_len;
1374
0
  const size_t offset = *pcount;
1375
0
  if (!reallocate_keyboard_layouts(layouts, pcount, length))
1376
0
    return FALSE;
1377
1378
0
  for (size_t i = 0; i < length; i++)
1379
0
  {
1380
0
    const RDP_KEYBOARD_LAYOUT* const ime = &sRDP_KEYBOARD_LAYOUT_TABLE[i];
1381
0
    RDP_KEYBOARD_LAYOUT* layout = &(*layouts)[i + offset];
1382
0
    layout->code = ime->code;
1383
0
    if (ime->name)
1384
0
      layout->name = _strdup(ime->name);
1385
1386
0
    if (!layout->name)
1387
0
      return FALSE;
1388
0
  }
1389
0
  return TRUE;
1390
0
}
1391
1392
static BOOL rdp_keyboard_variant_clone_append(RDP_KEYBOARD_LAYOUT** layouts, size_t* pcount)
1393
0
{
1394
0
  WINPR_ASSERT(layouts);
1395
0
  WINPR_ASSERT(pcount);
1396
1397
0
  load_layout_file();
1398
1399
0
  const size_t length = sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE_len;
1400
0
  const size_t offset = *pcount;
1401
0
  if (!reallocate_keyboard_layouts(layouts, pcount, length))
1402
0
    return FALSE;
1403
1404
0
  for (size_t i = 0; i < length; i++)
1405
0
  {
1406
0
    const RDP_KEYBOARD_LAYOUT_VARIANT* const ime = &sRDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i];
1407
0
    RDP_KEYBOARD_LAYOUT* layout = &(*layouts)[i + offset];
1408
0
    layout->code = ime->code;
1409
0
    if (ime->name)
1410
0
      layout->name = _strdup(ime->name);
1411
1412
0
    if (!layout->name)
1413
0
      return FALSE;
1414
0
  }
1415
0
  return TRUE;
1416
0
}
1417
1418
static BOOL rdp_keyboard_ime_clone_append(RDP_KEYBOARD_LAYOUT** layouts, size_t* pcount)
1419
0
{
1420
0
  WINPR_ASSERT(layouts);
1421
0
  WINPR_ASSERT(pcount);
1422
1423
0
  load_layout_file();
1424
1425
0
  const size_t length = sRDP_KEYBOARD_IME_TABLE_len;
1426
0
  const size_t offset = *pcount;
1427
0
  if (!reallocate_keyboard_layouts(layouts, pcount, length))
1428
0
    return FALSE;
1429
1430
0
  for (size_t i = 0; i < length; i++)
1431
0
  {
1432
0
    const RDP_KEYBOARD_IME* const ime = &sRDP_KEYBOARD_IME_TABLE[i];
1433
0
    RDP_KEYBOARD_LAYOUT* layout = &(*layouts)[i + offset];
1434
0
    layout->code = ime->code;
1435
0
    if (ime->name)
1436
0
      layout->name = _strdup(ime->name);
1437
1438
0
    if (!layout->name)
1439
0
      return FALSE;
1440
0
  }
1441
0
  return TRUE;
1442
0
}
1443
1444
void freerdp_keyboard_layouts_free(RDP_KEYBOARD_LAYOUT* layouts, size_t count)
1445
0
{
1446
0
  if (!layouts)
1447
0
    return;
1448
1449
0
  for (size_t x = 0; x < count; x++)
1450
0
  {
1451
0
    RDP_KEYBOARD_LAYOUT* current = &layouts[x];
1452
0
    free(current->name);
1453
0
    current++;
1454
0
  }
1455
1456
0
  free(layouts);
1457
0
}
1458
1459
RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types, size_t* count)
1460
0
{
1461
0
  size_t num = 0;
1462
0
  RDP_KEYBOARD_LAYOUT* layouts = NULL;
1463
1464
0
  load_layout_file();
1465
1466
0
  num = 0;
1467
1468
0
  WINPR_ASSERT(count);
1469
0
  *count = 0;
1470
1471
0
  if ((types & RDP_KEYBOARD_LAYOUT_TYPE_STANDARD) != 0)
1472
0
  {
1473
0
    if (!rdp_keyboard_layout_clone_append(&layouts, &num))
1474
0
      goto fail;
1475
0
  }
1476
1477
0
  if ((types & RDP_KEYBOARD_LAYOUT_TYPE_VARIANT) != 0)
1478
0
  {
1479
0
    if (!rdp_keyboard_variant_clone_append(&layouts, &num))
1480
0
      goto fail;
1481
0
  }
1482
1483
0
  if ((types & RDP_KEYBOARD_LAYOUT_TYPE_IME) != 0)
1484
0
  {
1485
0
    if (!rdp_keyboard_ime_clone_append(&layouts, &num))
1486
0
      goto fail;
1487
0
  }
1488
1489
0
  *count = num;
1490
0
  return layouts;
1491
0
fail:
1492
0
  freerdp_keyboard_layouts_free(layouts, num);
1493
0
  return NULL;
1494
0
}
1495
1496
const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutID)
1497
0
{
1498
0
  const char* name = rdp_keyboard_layout_by_id(keyboardLayoutID);
1499
0
  if (name)
1500
0
    return name;
1501
1502
0
  name = rdp_keyboard_variant_by_id(keyboardLayoutID);
1503
0
  if (name)
1504
0
    return name;
1505
1506
0
  name = rdp_keyboard_ime_by_id(keyboardLayoutID);
1507
0
  if (name)
1508
0
    return name;
1509
1510
0
  return "unknown";
1511
0
}
1512
1513
DWORD freerdp_keyboard_get_layout_id_from_name(const char* name)
1514
0
{
1515
0
  DWORD rc = rdp_keyboard_layout_by_name(name);
1516
0
  if (rc != 0)
1517
0
    return rc;
1518
1519
0
  rc = rdp_keyboard_variant_by_name(name);
1520
0
  if (rc != 0)
1521
0
    return rc;
1522
1523
0
  return rdp_keyboard_ime_by_name(name);
1524
0
}
1525
1526
static void copy(const struct LanguageIdentifier* id, RDP_CODEPAGE* cp)
1527
0
{
1528
0
  cp->id = id->LanguageIdentifier;
1529
0
  cp->subId = id->SublangaugeIdentifier;
1530
0
  cp->primaryId = id->PrimaryLanguageIdentifier;
1531
0
  if (id->locale)
1532
0
    strncpy(cp->locale, id->locale, ARRAYSIZE(cp->locale) - 1);
1533
0
  if (id->PrimaryLanguage)
1534
0
    strncpy(cp->primaryLanguage, id->PrimaryLanguage, ARRAYSIZE(cp->primaryLanguage) - 1);
1535
0
  if (id->PrimaryLanguageSymbol)
1536
0
    strncpy(cp->primaryLanguageSymbol, id->PrimaryLanguageSymbol,
1537
0
            ARRAYSIZE(cp->primaryLanguageSymbol) - 1);
1538
0
  if (id->Sublanguage)
1539
0
    strncpy(cp->subLanguage, id->Sublanguage, ARRAYSIZE(cp->subLanguage) - 1);
1540
0
  if (id->SublanguageSymbol)
1541
0
    strncpy(cp->subLanguageSymbol, id->SublanguageSymbol, ARRAYSIZE(cp->subLanguageSymbol) - 1);
1542
0
}
1543
1544
static BOOL copyOnMatch(DWORD column, const char* filter, const struct LanguageIdentifier* cur,
1545
                        RDP_CODEPAGE* dst)
1546
0
{
1547
0
  const char* what = NULL;
1548
0
  switch (column)
1549
0
  {
1550
0
    case 0:
1551
0
      what = cur->locale;
1552
0
      break;
1553
0
    case 1:
1554
0
      what = cur->PrimaryLanguage;
1555
0
      break;
1556
0
    case 2:
1557
0
      what = cur->PrimaryLanguageSymbol;
1558
0
      break;
1559
0
    case 3:
1560
0
      what = cur->Sublanguage;
1561
0
      break;
1562
0
    case 4:
1563
0
      what = cur->SublanguageSymbol;
1564
0
      break;
1565
0
    default:
1566
0
      return FALSE;
1567
0
  }
1568
1569
0
  if (filter)
1570
0
  {
1571
0
    if (!strstr(what, filter))
1572
0
      return FALSE;
1573
0
  }
1574
0
  copy(cur, dst);
1575
0
  return TRUE;
1576
0
}
1577
1578
RDP_CODEPAGE* freerdp_keyboard_get_matching_codepages(DWORD column, const char* filter,
1579
                                                      size_t* count)
1580
0
{
1581
0
  size_t cnt = 0;
1582
0
  const size_t c = ARRAYSIZE(language_identifiers);
1583
0
  RDP_CODEPAGE* pages = calloc(ARRAYSIZE(language_identifiers), sizeof(RDP_CODEPAGE));
1584
1585
0
  if (!pages)
1586
0
    return NULL;
1587
1588
0
  if (count)
1589
0
    *count = 0;
1590
1591
0
  if (column > 4)
1592
0
    goto fail;
1593
1594
0
  for (size_t x = 0; x < c; x++)
1595
0
  {
1596
0
    const struct LanguageIdentifier* cur = &language_identifiers[x];
1597
0
    if (copyOnMatch(column, filter, cur, &pages[cnt]))
1598
0
      cnt++;
1599
0
  }
1600
1601
0
  if (cnt == 0)
1602
0
    goto fail;
1603
1604
0
  if (count)
1605
0
    *count = cnt;
1606
1607
0
  return pages;
1608
0
fail:
1609
0
  freerdp_codepages_free(pages);
1610
0
  return NULL;
1611
0
}
1612
1613
void freerdp_codepages_free(RDP_CODEPAGE* pages)
1614
0
{
1615
0
  free(pages);
1616
0
}