771
|
1 /* Win32 internationalization functions.
|
|
2 Copyright (C) 2000, 2001, 2002 Ben Wing.
|
|
3 Copyright (C) 2000 IKEYAMA Tomonori.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Authorship:
|
|
25
|
|
26 Current primary author: Ben Wing <ben@xemacs.org>
|
|
27
|
|
28 Created summer 2000 by Ben Wing. Almost completely written by Ben Wing.
|
|
29 Little bits of code in some of the Lisp primitives from FSF Emacs.
|
|
30 Versions of wcscpy, wcsncpy from Cygwin newlib.
|
|
31
|
|
32 Coding systems written by Ben Wing in file-coding.c; moved here Sep 2001.
|
|
33 */
|
|
34
|
|
35 #include <config.h>
|
|
36 #include "lisp.h"
|
|
37
|
|
38 #include "elhash.h"
|
|
39 #include "faces.h"
|
|
40 #include "file-coding.h"
|
872
|
41 #include "frame-impl.h"
|
|
42 #include "window-impl.h"
|
771
|
43
|
872
|
44 #include "console-msw-impl.h"
|
|
45 #include "objects-msw-impl.h"
|
771
|
46
|
|
47 #ifndef CYGWIN_HEADERS
|
|
48 # include <mbctype.h>
|
|
49 #elif defined (MINGW)
|
|
50 int _setmbcp (int);
|
|
51 int _getmbcp (void);
|
|
52 #else
|
|
53 # define NO_EXT_MULTIBYTE_FEATURES
|
|
54 #endif
|
|
55
|
2286
|
56 #ifdef MULE
|
|
57 #define USED_IF_MULE(decl) decl
|
|
58 #else
|
|
59 #define USED_IF_MULE(decl) UNUSED (decl)
|
|
60 #endif
|
|
61
|
771
|
62 Lisp_Object Qmswindows_multibyte, Qmswindows_multibyte_to_unicode;
|
|
63 Lisp_Object Qmswindows_tstr, Qmswindows_unicode;
|
|
64 Lisp_Object Qmswindows_multibyte_system_default;
|
|
65
|
|
66 Lisp_Object Qansi, Qoem, Qmac, Qebcdic;
|
|
67 /* Qcode_page, Qlocale, Qcurrent, Quser_default, Qsystem_default in
|
|
68 general-slots.h */
|
|
69
|
|
70 #ifdef MULE
|
|
71
|
|
72 static Lisp_Object Vmswindows_charset_code_page_table;
|
872
|
73 static Lisp_Object Vmswindows_charset_registry_table;
|
771
|
74
|
|
75 LCID current_locale;
|
|
76
|
|
77
|
|
78 /************************************************************************/
|
|
79 /* Language/locale/code page conversion functions */
|
|
80 /************************************************************************/
|
|
81
|
|
82 /* There are various different ways of representing the vague concept
|
|
83 of "language", and it can be very confusing. So:
|
|
84
|
|
85 -- The C library has the concept of "locale", which is a
|
|
86 combination of language and country, and which controls the way
|
|
87 currency and dates are displayed, the encoding of data, etc.
|
|
88
|
|
89 -- XEmacs has the concept of "language environment", more or less
|
|
90 like a locale; although currently in most cases it just refers to
|
|
91 the language, and no sub-language distinctions are
|
|
92 made. (Exceptions are with Chinese, which has different language
|
|
93 environments for Taiwan and mainland China, due to the different
|
|
94 encodings and writing systems.)
|
|
95
|
|
96 -- Windows has a number of different language concepts:
|
|
97
|
|
98 1. There are "languages" and "sublanguages", which correspond to
|
|
99 the languages and countries of the C library -- e.g. LANG_ENGLISH
|
|
100 and SUBLANG_ENGLISH_US. These are identified by 8-bit integers,
|
|
101 called the "primary language identifier" and "sublanguage
|
|
102 identifier", respectively. These are combined into a 16-bit
|
|
103 integer or "language identifier" by MAKELANGID().
|
|
104
|
|
105 2. The language identifier in turn is combined with a "sort
|
|
106 identifier" (and optionally a "sort version") to yield a 32-bit
|
|
107 integer called a "locale identifier" (type LCID), which identifies
|
|
108 locales -- the primary means of distinguishing language/regional
|
|
109 settings and similar to C library locales.
|
|
110
|
|
111 3. "Code pages" identify different text encodings (i.e. a set of
|
|
112 supported characters, an enumeration of those characters [i.e. an
|
|
113 association of character with number or number pair; there may be
|
|
114 disjoint ranges of numbers supported]), and a way of encoding a
|
|
115 stream of those characters into an 8-bit data stream). All of the
|
|
116 encodings are either one-byte or mixed one-byte/two-byte encodings,
|
|
117 all non-modal; in the mixed encodings, two-byte characters have the
|
|
118 first byte >= 128, although the second byte may or may not be
|
|
119 restricted to this range, depending on the encoding. Code pages
|
|
120 are similar to XEmacs "charsets"; the latter also define a set of
|
|
121 supported characters and an enumeration of those characters (but
|
|
122 code pages in additionally define an encoding, which charsets don't
|
|
123 do). Code pages often function in Windows like charsets in XEmacs.
|
|
124
|
|
125 4. Every Windows locale has a specific code page associated with
|
|
126 it; more than one locale can share a code page -- e.g. all the
|
|
127 Western European languages, including English, do.
|
|
128
|
|
129 5. Windows also has an "input locale identifier" (aka "keyboard
|
|
130 layout id") or HKL, which is a 32-bit integer composed of the
|
|
131 16-bit language identifier and a 16-bit "device identifier", which
|
|
132 originally specified a particular keyboard layout (e.g. the locale
|
|
133 "US English" can have the QWERTY layout, the Dvorak layout, etc.),
|
|
134 but has been expanded to include speech-to-text converters and
|
|
135 other non-keyboard ways of inputting text. Note that both the HKL
|
|
136 and LCID share the language identifier in the lower 16 bits, and in
|
|
137 both cases a 0 in the upper 16 bits means "default" (sort order or
|
|
138 device), providing a way to convert between HKL's, LCID's, and
|
|
139 language identifiers (i.e. language/sublanguage pairs). The
|
|
140 default keyboard layout for a language is (as far as I can
|
|
141 determine) established using the Regional Settings control panel
|
|
142 applet, where you can add input locales as combinations of language
|
|
143 (actually language/sublanguage) and layout; presumably if you list
|
|
144 only one input locale with a particular language, the corresponding
|
|
145 layout is the default for that language. But what if you list more
|
|
146 than one? You can specify a single default input locale, but there
|
|
147 appears to be no way to do so on a per-language basis.
|
|
148 */
|
|
149
|
|
150 struct lang_to_string
|
|
151 {
|
|
152 int code;
|
|
153 char *string;
|
|
154 };
|
|
155
|
|
156 struct lang_to_string lang_to_string_table[] =
|
|
157 {
|
|
158 /* These names change from version to version of VC++, so it's easiest
|
|
159 just to bracket them all with ifdefs. */
|
|
160 #ifdef LANG_AFRIKAANS
|
|
161 { LANG_AFRIKAANS, "AFRIKAANS" },
|
|
162 #endif
|
|
163 #ifdef LANG_ALBANIAN
|
|
164 { LANG_ALBANIAN, "ALBANIAN" },
|
|
165 #endif
|
|
166 #ifdef LANG_ARABIC
|
|
167 { LANG_ARABIC, "ARABIC" },
|
|
168 #endif
|
|
169 #ifdef LANG_ARMENIAN
|
|
170 { LANG_ARMENIAN, "ARMENIAN" },
|
|
171 #endif
|
|
172 #ifdef LANG_ASSAMESE
|
|
173 { LANG_ASSAMESE, "ASSAMESE" },
|
|
174 #endif
|
|
175 #ifdef LANG_AZERI
|
|
176 { LANG_AZERI, "AZERI" },
|
|
177 #endif
|
|
178 #ifdef LANG_BASQUE
|
|
179 { LANG_BASQUE, "BASQUE" },
|
|
180 #endif
|
|
181 #ifdef LANG_BELARUSIAN
|
|
182 { LANG_BELARUSIAN, "BELARUSIAN" },
|
|
183 #endif
|
|
184 #ifdef LANG_BENGALI
|
|
185 { LANG_BENGALI, "BENGALI" },
|
|
186 #endif
|
|
187 #ifdef LANG_BULGARIAN
|
|
188 { LANG_BULGARIAN, "BULGARIAN" },
|
|
189 #endif
|
|
190 #ifdef LANG_CATALAN
|
|
191 { LANG_CATALAN, "CATALAN" },
|
|
192 #endif
|
|
193 #ifdef LANG_CHINESE
|
|
194 { LANG_CHINESE, "CHINESE" },
|
|
195 #endif
|
|
196 #ifdef LANG_CROATIAN
|
|
197 { LANG_CROATIAN, "CROATIAN" },
|
|
198 #endif
|
|
199 #ifdef LANG_CZECH
|
|
200 { LANG_CZECH, "CZECH" },
|
|
201 #endif
|
|
202 #ifdef LANG_DANISH
|
|
203 { LANG_DANISH, "DANISH" },
|
|
204 #endif
|
|
205 #ifdef LANG_DUTCH
|
|
206 { LANG_DUTCH, "DUTCH" },
|
|
207 #endif
|
|
208 #ifdef LANG_ENGLISH
|
|
209 { LANG_ENGLISH, "ENGLISH" },
|
|
210 #endif
|
|
211 #ifdef LANG_ESTONIAN
|
|
212 { LANG_ESTONIAN, "ESTONIAN" },
|
|
213 #endif
|
|
214 #ifdef LANG_FAEROESE
|
|
215 { LANG_FAEROESE, "FAEROESE" },
|
|
216 #endif
|
|
217 #ifdef LANG_FARSI
|
|
218 { LANG_FARSI, "FARSI" },
|
|
219 #endif
|
|
220 #ifdef LANG_FINNISH
|
|
221 { LANG_FINNISH, "FINNISH" },
|
|
222 #endif
|
|
223 #ifdef LANG_FRENCH
|
|
224 { LANG_FRENCH, "FRENCH" },
|
|
225 #endif
|
|
226 #ifdef LANG_GEORGIAN
|
|
227 { LANG_GEORGIAN, "GEORGIAN" },
|
|
228 #endif
|
|
229 #ifdef LANG_GERMAN
|
|
230 { LANG_GERMAN, "GERMAN" },
|
|
231 #endif
|
|
232 #ifdef LANG_GREEK
|
|
233 { LANG_GREEK, "GREEK" },
|
|
234 #endif
|
|
235 #ifdef LANG_GUJARATI
|
|
236 { LANG_GUJARATI, "GUJARATI" },
|
|
237 #endif
|
|
238 #ifdef LANG_HEBREW
|
|
239 { LANG_HEBREW, "HEBREW" },
|
|
240 #endif
|
|
241 #ifdef LANG_HINDI
|
|
242 { LANG_HINDI, "HINDI" },
|
|
243 #endif
|
|
244 #ifdef LANG_HUNGARIAN
|
|
245 { LANG_HUNGARIAN, "HUNGARIAN" },
|
|
246 #endif
|
|
247 #ifdef LANG_ICELANDIC
|
|
248 { LANG_ICELANDIC, "ICELANDIC" },
|
|
249 #endif
|
|
250 #ifdef LANG_INDONESIAN
|
|
251 { LANG_INDONESIAN, "INDONESIAN" },
|
|
252 #endif
|
|
253 #ifdef LANG_ITALIAN
|
|
254 { LANG_ITALIAN, "ITALIAN" },
|
|
255 #endif
|
|
256 #ifdef LANG_JAPANESE
|
|
257 { LANG_JAPANESE, "JAPANESE" },
|
|
258 #endif
|
|
259 #ifdef LANG_KANNADA
|
|
260 { LANG_KANNADA, "KANNADA" },
|
|
261 #endif
|
|
262 #ifdef LANG_KASHMIRI
|
|
263 { LANG_KASHMIRI, "KASHMIRI" },
|
|
264 #endif
|
|
265 #ifdef LANG_KAZAK
|
|
266 { LANG_KAZAK, "KAZAK" },
|
|
267 #endif
|
|
268 #ifdef LANG_KONKANI
|
|
269 { LANG_KONKANI, "KONKANI" },
|
|
270 #endif
|
|
271 #ifdef LANG_KOREAN
|
|
272 { LANG_KOREAN, "KOREAN" },
|
|
273 #endif
|
|
274 #ifdef LANG_LATVIAN
|
|
275 { LANG_LATVIAN, "LATVIAN" },
|
|
276 #endif
|
|
277 #ifdef LANG_LITHUANIAN
|
|
278 { LANG_LITHUANIAN, "LITHUANIAN" },
|
|
279 #endif
|
|
280 #ifdef LANG_MACEDONIAN
|
|
281 { LANG_MACEDONIAN, "MACEDONIAN" },
|
|
282 #endif
|
|
283 #ifdef LANG_MALAY
|
|
284 { LANG_MALAY, "MALAY" },
|
|
285 #endif
|
|
286 #ifdef LANG_MALAYALAM
|
|
287 { LANG_MALAYALAM, "MALAYALAM" },
|
|
288 #endif
|
|
289 #ifdef LANG_MANIPURI
|
|
290 { LANG_MANIPURI, "MANIPURI" },
|
|
291 #endif
|
|
292 #ifdef LANG_MARATHI
|
|
293 { LANG_MARATHI, "MARATHI" },
|
|
294 #endif
|
|
295 #ifdef LANG_NEPALI
|
|
296 { LANG_NEPALI, "NEPALI" },
|
|
297 #endif
|
|
298 #ifdef LANG_NEUTRAL
|
|
299 { LANG_NEUTRAL, "NEUTRAL" },
|
|
300 #endif
|
|
301 #ifdef LANG_NORWEGIAN
|
|
302 { LANG_NORWEGIAN, "NORWEGIAN" },
|
|
303 #endif
|
|
304 #ifdef LANG_ORIYA
|
|
305 { LANG_ORIYA, "ORIYA" },
|
|
306 #endif
|
|
307 #ifdef LANG_POLISH
|
|
308 { LANG_POLISH, "POLISH" },
|
|
309 #endif
|
|
310 #ifdef LANG_PORTUGUESE
|
|
311 { LANG_PORTUGUESE, "PORTUGUESE" },
|
|
312 #endif
|
|
313 #ifdef LANG_PUNJABI
|
|
314 { LANG_PUNJABI, "PUNJABI" },
|
|
315 #endif
|
|
316 #ifdef LANG_ROMANIAN
|
|
317 { LANG_ROMANIAN, "ROMANIAN" },
|
|
318 #endif
|
|
319 #ifdef LANG_RUSSIAN
|
|
320 { LANG_RUSSIAN, "RUSSIAN" },
|
|
321 #endif
|
|
322 #ifdef LANG_SANSKRIT
|
|
323 { LANG_SANSKRIT, "SANSKRIT" },
|
|
324 #endif
|
|
325 #ifdef LANG_SERBIAN
|
|
326 { LANG_SERBIAN, "SERBIAN" },
|
|
327 #endif
|
|
328 #ifdef LANG_SINDHI
|
|
329 { LANG_SINDHI, "SINDHI" },
|
|
330 #endif
|
|
331 #ifdef LANG_SLOVAK
|
|
332 { LANG_SLOVAK, "SLOVAK" },
|
|
333 #endif
|
|
334 #ifdef LANG_SLOVENIAN
|
|
335 { LANG_SLOVENIAN, "SLOVENIAN" },
|
|
336 #endif
|
|
337 #ifdef LANG_SPANISH
|
|
338 { LANG_SPANISH, "SPANISH" },
|
|
339 #endif
|
|
340 #ifdef LANG_SWAHILI
|
|
341 { LANG_SWAHILI, "SWAHILI" },
|
|
342 #endif
|
|
343 #ifdef LANG_SWEDISH
|
|
344 { LANG_SWEDISH, "SWEDISH" },
|
|
345 #endif
|
|
346 #ifdef LANG_TAMIL
|
|
347 { LANG_TAMIL, "TAMIL" },
|
|
348 #endif
|
|
349 #ifdef LANG_TATAR
|
|
350 { LANG_TATAR, "TATAR" },
|
|
351 #endif
|
|
352 #ifdef LANG_TELUGU
|
|
353 { LANG_TELUGU, "TELUGU" },
|
|
354 #endif
|
|
355 #ifdef LANG_THAI
|
|
356 { LANG_THAI, "THAI" },
|
|
357 #endif
|
|
358 #ifdef LANG_TURKISH
|
|
359 { LANG_TURKISH, "TURKISH" },
|
|
360 #endif
|
|
361 #ifdef LANG_UKRAINIAN
|
|
362 { LANG_UKRAINIAN, "UKRAINIAN" },
|
|
363 #endif
|
|
364 #ifdef LANG_URDU
|
|
365 { LANG_URDU, "URDU" },
|
|
366 #endif
|
|
367 #ifdef LANG_UZBEK
|
|
368 { LANG_UZBEK, "UZBEK" },
|
|
369 #endif
|
|
370 #ifdef LANG_VIETNAMESE
|
|
371 { LANG_VIETNAMESE, "VIETNAMESE" },
|
|
372 #endif
|
|
373 };
|
|
374
|
|
375 struct lang_to_string sublang_to_string_table[] =
|
|
376 {
|
|
377 { LANG_ARABIC, 0 },
|
|
378 #ifdef SUBLANG_ARABIC_ALGERIA
|
|
379 { SUBLANG_ARABIC_ALGERIA, "ARABIC_ALGERIA" },
|
|
380 #endif
|
|
381 #ifdef SUBLANG_ARABIC_BAHRAIN
|
|
382 { SUBLANG_ARABIC_BAHRAIN, "ARABIC_BAHRAIN" },
|
|
383 #endif
|
|
384 #ifdef SUBLANG_ARABIC_EGYPT
|
|
385 { SUBLANG_ARABIC_EGYPT, "ARABIC_EGYPT" },
|
|
386 #endif
|
|
387 #ifdef SUBLANG_ARABIC_IRAQ
|
|
388 { SUBLANG_ARABIC_IRAQ, "ARABIC_IRAQ" },
|
|
389 #endif
|
|
390 #ifdef SUBLANG_ARABIC_JORDAN
|
|
391 { SUBLANG_ARABIC_JORDAN, "ARABIC_JORDAN" },
|
|
392 #endif
|
|
393 #ifdef SUBLANG_ARABIC_KUWAIT
|
|
394 { SUBLANG_ARABIC_KUWAIT, "ARABIC_KUWAIT" },
|
|
395 #endif
|
|
396 #ifdef SUBLANG_ARABIC_LEBANON
|
|
397 { SUBLANG_ARABIC_LEBANON, "ARABIC_LEBANON" },
|
|
398 #endif
|
|
399 #ifdef SUBLANG_ARABIC_LIBYA
|
|
400 { SUBLANG_ARABIC_LIBYA, "ARABIC_LIBYA" },
|
|
401 #endif
|
|
402 #ifdef SUBLANG_ARABIC_MOROCCO
|
|
403 { SUBLANG_ARABIC_MOROCCO, "ARABIC_MOROCCO" },
|
|
404 #endif
|
|
405 #ifdef SUBLANG_ARABIC_OMAN
|
|
406 { SUBLANG_ARABIC_OMAN, "ARABIC_OMAN" },
|
|
407 #endif
|
|
408 #ifdef SUBLANG_ARABIC_QATAR
|
|
409 { SUBLANG_ARABIC_QATAR, "ARABIC_QATAR" },
|
|
410 #endif
|
|
411 #ifdef SUBLANG_ARABIC_SAUDI_ARABIA
|
|
412 { SUBLANG_ARABIC_SAUDI_ARABIA, "ARABIC_SAUDI_ARABIA" },
|
|
413 #endif
|
|
414 #ifdef SUBLANG_ARABIC_SYRIA
|
|
415 { SUBLANG_ARABIC_SYRIA, "ARABIC_SYRIA" },
|
|
416 #endif
|
|
417 #ifdef SUBLANG_ARABIC_TUNISIA
|
|
418 { SUBLANG_ARABIC_TUNISIA, "ARABIC_TUNISIA" },
|
|
419 #endif
|
|
420 #ifdef SUBLANG_ARABIC_UAE
|
|
421 { SUBLANG_ARABIC_UAE, "ARABIC_UAE" },
|
|
422 #endif
|
|
423 #ifdef SUBLANG_ARABIC_YEMEN
|
|
424 { SUBLANG_ARABIC_YEMEN, "ARABIC_YEMEN" },
|
|
425 #endif
|
|
426 { LANG_AZERI, 0 },
|
|
427 #ifdef SUBLANG_AZERI_CYRILLIC
|
|
428 { SUBLANG_AZERI_CYRILLIC, "AZERI_CYRILLIC" },
|
|
429 #endif
|
|
430 #ifdef SUBLANG_AZERI_LATIN
|
|
431 { SUBLANG_AZERI_LATIN, "AZERI_LATIN" },
|
|
432 #endif
|
|
433 { LANG_CHINESE, 0 },
|
|
434 #ifdef SUBLANG_CHINESE_HONGKONG
|
|
435 { SUBLANG_CHINESE_HONGKONG, "CHINESE_HONGKONG" },
|
|
436 #endif
|
|
437 #ifdef SUBLANG_CHINESE_MACAU
|
|
438 { SUBLANG_CHINESE_MACAU, "CHINESE_MACAU" },
|
|
439 #endif
|
|
440 #ifdef SUBLANG_CHINESE_SIMPLIFIED
|
|
441 { SUBLANG_CHINESE_SIMPLIFIED, "CHINESE_SIMPLIFIED" },
|
|
442 #endif
|
|
443 #ifdef SUBLANG_CHINESE_SINGAPORE
|
|
444 { SUBLANG_CHINESE_SINGAPORE, "CHINESE_SINGAPORE" },
|
|
445 #endif
|
|
446 #ifdef SUBLANG_CHINESE_TRADITIONAL
|
|
447 { SUBLANG_CHINESE_TRADITIONAL, "CHINESE_TRADITIONAL" },
|
|
448 #endif
|
|
449 { LANG_DUTCH, 0 },
|
|
450 #ifdef SUBLANG_DUTCH
|
|
451 { SUBLANG_DUTCH, "DUTCH" },
|
|
452 #endif
|
|
453 #ifdef SUBLANG_DUTCH_BELGIAN
|
|
454 { SUBLANG_DUTCH_BELGIAN, "DUTCH_BELGIAN" },
|
|
455 #endif
|
|
456 { LANG_ENGLISH, 0 },
|
|
457 #ifdef SUBLANG_ENGLISH_AUS
|
|
458 { SUBLANG_ENGLISH_AUS, "ENGLISH_AUS" },
|
|
459 #endif
|
|
460 #ifdef SUBLANG_ENGLISH_BELIZE
|
|
461 { SUBLANG_ENGLISH_BELIZE, "ENGLISH_BELIZE" },
|
|
462 #endif
|
|
463 #ifdef SUBLANG_ENGLISH_CAN
|
|
464 { SUBLANG_ENGLISH_CAN, "ENGLISH_CAN" },
|
|
465 #endif
|
|
466 #ifdef SUBLANG_ENGLISH_CARIBBEAN
|
|
467 { SUBLANG_ENGLISH_CARIBBEAN, "ENGLISH_CARIBBEAN" },
|
|
468 #endif
|
|
469 #ifdef SUBLANG_ENGLISH_EIRE
|
|
470 { SUBLANG_ENGLISH_EIRE, "ENGLISH_EIRE" },
|
|
471 #endif
|
|
472 #ifdef SUBLANG_ENGLISH_JAMAICA
|
|
473 { SUBLANG_ENGLISH_JAMAICA, "ENGLISH_JAMAICA" },
|
|
474 #endif
|
|
475 #ifdef SUBLANG_ENGLISH_NZ
|
|
476 { SUBLANG_ENGLISH_NZ, "ENGLISH_NZ" },
|
|
477 #endif
|
|
478 #ifdef SUBLANG_ENGLISH_PHILIPPINES
|
|
479 { SUBLANG_ENGLISH_PHILIPPINES, "ENGLISH_PHILIPPINES" },
|
|
480 #endif
|
|
481 #ifdef SUBLANG_ENGLISH_SOUTH_AFRICA
|
|
482 { SUBLANG_ENGLISH_SOUTH_AFRICA, "ENGLISH_SOUTH_AFRICA" },
|
|
483 #endif
|
|
484 #ifdef SUBLANG_ENGLISH_TRINIDAD
|
|
485 { SUBLANG_ENGLISH_TRINIDAD, "ENGLISH_TRINIDAD" },
|
|
486 #endif
|
|
487 #ifdef SUBLANG_ENGLISH_UK
|
|
488 { SUBLANG_ENGLISH_UK, "ENGLISH_UK" },
|
|
489 #endif
|
|
490 #ifdef SUBLANG_ENGLISH_US
|
|
491 { SUBLANG_ENGLISH_US, "ENGLISH_US" },
|
|
492 #endif
|
|
493 #ifdef SUBLANG_ENGLISH_ZIMBABWE
|
|
494 { SUBLANG_ENGLISH_ZIMBABWE, "ENGLISH_ZIMBABWE" },
|
|
495 #endif
|
|
496 { LANG_FRENCH, 0 },
|
|
497 #ifdef SUBLANG_FRENCH
|
|
498 { SUBLANG_FRENCH, "FRENCH" },
|
|
499 #endif
|
|
500 #ifdef SUBLANG_FRENCH_BELGIAN
|
|
501 { SUBLANG_FRENCH_BELGIAN, "FRENCH_BELGIAN" },
|
|
502 #endif
|
|
503 #ifdef SUBLANG_FRENCH_CANADIAN
|
|
504 { SUBLANG_FRENCH_CANADIAN, "FRENCH_CANADIAN" },
|
|
505 #endif
|
|
506 #ifdef SUBLANG_FRENCH_LUXEMBOURG
|
|
507 { SUBLANG_FRENCH_LUXEMBOURG, "FRENCH_LUXEMBOURG" },
|
|
508 #endif
|
|
509 #ifdef SUBLANG_FRENCH_MONACO
|
|
510 { SUBLANG_FRENCH_MONACO, "FRENCH_MONACO" },
|
|
511 #endif
|
|
512 #ifdef SUBLANG_FRENCH_SWISS
|
|
513 { SUBLANG_FRENCH_SWISS, "FRENCH_SWISS" },
|
|
514 #endif
|
|
515 { LANG_GERMAN, 0 },
|
|
516 #ifdef SUBLANG_GERMAN
|
|
517 { SUBLANG_GERMAN, "GERMAN" },
|
|
518 #endif
|
|
519 #ifdef SUBLANG_GERMAN_AUSTRIAN
|
|
520 { SUBLANG_GERMAN_AUSTRIAN, "GERMAN_AUSTRIAN" },
|
|
521 #endif
|
|
522 #ifdef SUBLANG_GERMAN_LIECHTENSTEIN
|
|
523 { SUBLANG_GERMAN_LIECHTENSTEIN, "GERMAN_LIECHTENSTEIN" },
|
|
524 #endif
|
|
525 #ifdef SUBLANG_GERMAN_LUXEMBOURG
|
|
526 { SUBLANG_GERMAN_LUXEMBOURG, "GERMAN_LUXEMBOURG" },
|
|
527 #endif
|
|
528 #ifdef SUBLANG_GERMAN_SWISS
|
|
529 { SUBLANG_GERMAN_SWISS, "GERMAN_SWISS" },
|
|
530 #endif
|
|
531 { LANG_ITALIAN, 0 },
|
|
532 #ifdef SUBLANG_ITALIAN
|
|
533 { SUBLANG_ITALIAN, "ITALIAN" },
|
|
534 #endif
|
|
535 #ifdef SUBLANG_ITALIAN_SWISS
|
|
536 { SUBLANG_ITALIAN_SWISS, "ITALIAN_SWISS" },
|
|
537 #endif
|
|
538 { LANG_KASHMIRI, 0 },
|
|
539 #ifdef SUBLANG_KASHMIRI_INDIA
|
|
540 { SUBLANG_KASHMIRI_INDIA, "KASHMIRI_INDIA" },
|
|
541 #endif
|
|
542 { LANG_KOREAN, 0 },
|
|
543 #ifdef SUBLANG_KOREAN
|
|
544 { SUBLANG_KOREAN, "KOREAN" },
|
|
545 #endif
|
|
546 #ifdef SUBLANG_KOREAN_JOHAB
|
|
547 /* NOTE: Omitted in more recent versions of VC++ (e.g. v6.0) */
|
|
548 { SUBLANG_KOREAN_JOHAB, "KOREAN_JOHAB" },
|
|
549 #endif
|
|
550 { LANG_LITHUANIAN, 0 },
|
|
551 #ifdef SUBLANG_LITHUANIAN
|
|
552 { SUBLANG_LITHUANIAN, "LITHUANIAN" },
|
|
553 #endif
|
|
554 #ifdef SUBLANG_LITHUANIAN_CLASSIC
|
|
555 { SUBLANG_LITHUANIAN_CLASSIC, "LITHUANIAN_CLASSIC" },
|
|
556 #endif
|
|
557 { LANG_MALAY, 0 },
|
|
558 #ifdef SUBLANG_MALAY_BRUNEI_DARUSSALAM
|
|
559 { SUBLANG_MALAY_BRUNEI_DARUSSALAM, "MALAY_BRUNEI_DARUSSALAM" },
|
|
560 #endif
|
|
561 #ifdef SUBLANG_MALAY_MALAYSIA
|
|
562 { SUBLANG_MALAY_MALAYSIA, "MALAY_MALAYSIA" },
|
|
563 #endif
|
|
564 { LANG_NEPALI, 0 },
|
|
565 #ifdef SUBLANG_NEPALI_INDIA
|
|
566 { SUBLANG_NEPALI_INDIA, "NEPALI_INDIA" },
|
|
567 #endif
|
|
568 { LANG_NEUTRAL, 0 },
|
|
569 #ifdef SUBLANG_NEUTRAL
|
|
570 { SUBLANG_NEUTRAL, "NEUTRAL" },
|
|
571 #endif
|
|
572 { LANG_NORWEGIAN, 0 },
|
|
573 #ifdef SUBLANG_NORWEGIAN_BOKMAL
|
|
574 { SUBLANG_NORWEGIAN_BOKMAL, "NORWEGIAN_BOKMAL" },
|
|
575 #endif
|
|
576 #ifdef SUBLANG_NORWEGIAN_NYNORSK
|
|
577 { SUBLANG_NORWEGIAN_NYNORSK, "NORWEGIAN_NYNORSK" },
|
|
578 #endif
|
|
579 { LANG_PORTUGUESE, 0 },
|
|
580 #ifdef SUBLANG_PORTUGUESE
|
|
581 { SUBLANG_PORTUGUESE, "PORTUGUESE" },
|
|
582 #endif
|
|
583 #ifdef SUBLANG_PORTUGUESE_BRAZILIAN
|
|
584 { SUBLANG_PORTUGUESE_BRAZILIAN, "PORTUGUESE_BRAZILIAN" },
|
|
585 #endif
|
|
586 { LANG_SERBIAN, 0 },
|
|
587 #ifdef SUBLANG_SERBIAN_CYRILLIC
|
|
588 { SUBLANG_SERBIAN_CYRILLIC, "SERBIAN_CYRILLIC" },
|
|
589 #endif
|
|
590 #ifdef SUBLANG_SERBIAN_LATIN
|
|
591 { SUBLANG_SERBIAN_LATIN, "SERBIAN_LATIN" },
|
|
592 #endif
|
|
593 { LANG_SPANISH, 0 },
|
|
594 #ifdef SUBLANG_SPANISH
|
|
595 { SUBLANG_SPANISH, "SPANISH" },
|
|
596 #endif
|
|
597 #ifdef SUBLANG_SPANISH_ARGENTINA
|
|
598 { SUBLANG_SPANISH_ARGENTINA, "SPANISH_ARGENTINA" },
|
|
599 #endif
|
|
600 #ifdef SUBLANG_SPANISH_BOLIVIA
|
|
601 { SUBLANG_SPANISH_BOLIVIA, "SPANISH_BOLIVIA" },
|
|
602 #endif
|
|
603 #ifdef SUBLANG_SPANISH_CHILE
|
|
604 { SUBLANG_SPANISH_CHILE, "SPANISH_CHILE" },
|
|
605 #endif
|
|
606 #ifdef SUBLANG_SPANISH_COLOMBIA
|
|
607 { SUBLANG_SPANISH_COLOMBIA, "SPANISH_COLOMBIA" },
|
|
608 #endif
|
|
609 #ifdef SUBLANG_SPANISH_COSTA_RICA
|
|
610 { SUBLANG_SPANISH_COSTA_RICA, "SPANISH_COSTA_RICA" },
|
|
611 #endif
|
|
612 #ifdef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
|
|
613 { SUBLANG_SPANISH_DOMINICAN_REPUBLIC, "SPANISH_DOMINICAN_REPUBLIC" },
|
|
614 #endif
|
|
615 #ifdef SUBLANG_SPANISH_ECUADOR
|
|
616 { SUBLANG_SPANISH_ECUADOR, "SPANISH_ECUADOR" },
|
|
617 #endif
|
|
618 #ifdef SUBLANG_SPANISH_EL_SALVADOR
|
|
619 { SUBLANG_SPANISH_EL_SALVADOR, "SPANISH_EL_SALVADOR" },
|
|
620 #endif
|
|
621 #ifdef SUBLANG_SPANISH_GUATEMALA
|
|
622 { SUBLANG_SPANISH_GUATEMALA, "SPANISH_GUATEMALA" },
|
|
623 #endif
|
|
624 #ifdef SUBLANG_SPANISH_HONDURAS
|
|
625 { SUBLANG_SPANISH_HONDURAS, "SPANISH_HONDURAS" },
|
|
626 #endif
|
|
627 #ifdef SUBLANG_SPANISH_MEXICAN
|
|
628 { SUBLANG_SPANISH_MEXICAN, "SPANISH_MEXICAN" },
|
|
629 #endif
|
|
630 #ifdef SUBLANG_SPANISH_MODERN
|
|
631 { SUBLANG_SPANISH_MODERN, "SPANISH_MODERN" },
|
|
632 #endif
|
|
633 #ifdef SUBLANG_SPANISH_NICARAGUA
|
|
634 { SUBLANG_SPANISH_NICARAGUA, "SPANISH_NICARAGUA" },
|
|
635 #endif
|
|
636 #ifdef SUBLANG_SPANISH_PANAMA
|
|
637 { SUBLANG_SPANISH_PANAMA, "SPANISH_PANAMA" },
|
|
638 #endif
|
|
639 #ifdef SUBLANG_SPANISH_PARAGUAY
|
|
640 { SUBLANG_SPANISH_PARAGUAY, "SPANISH_PARAGUAY" },
|
|
641 #endif
|
|
642 #ifdef SUBLANG_SPANISH_PERU
|
|
643 { SUBLANG_SPANISH_PERU, "SPANISH_PERU" },
|
|
644 #endif
|
|
645 #ifdef SUBLANG_SPANISH_PUERTO_RICO
|
|
646 { SUBLANG_SPANISH_PUERTO_RICO, "SPANISH_PUERTO_RICO" },
|
|
647 #endif
|
|
648 #ifdef SUBLANG_SPANISH_URUGUAY
|
|
649 { SUBLANG_SPANISH_URUGUAY, "SPANISH_URUGUAY" },
|
|
650 #endif
|
|
651 #ifdef SUBLANG_SPANISH_VENEZUELA
|
|
652 { SUBLANG_SPANISH_VENEZUELA, "SPANISH_VENEZUELA" },
|
|
653 #endif
|
|
654 { LANG_SWEDISH, 0 },
|
|
655 #ifdef SUBLANG_SWEDISH
|
|
656 { SUBLANG_SWEDISH, "SWEDISH" },
|
|
657 #endif
|
|
658 #ifdef SUBLANG_SWEDISH_FINLAND
|
|
659 { SUBLANG_SWEDISH_FINLAND, "SWEDISH_FINLAND" },
|
|
660 #endif
|
|
661 { LANG_URDU, 0 },
|
|
662 #ifdef SUBLANG_URDU_INDIA
|
|
663 { SUBLANG_URDU_INDIA, "URDU_INDIA" },
|
|
664 #endif
|
|
665 #ifdef SUBLANG_URDU_PAKISTAN
|
|
666 { SUBLANG_URDU_PAKISTAN, "URDU_PAKISTAN" },
|
|
667 #endif
|
|
668 { LANG_UZBEK, 0 },
|
|
669 #ifdef SUBLANG_UZBEK_CYRILLIC
|
|
670 { SUBLANG_UZBEK_CYRILLIC, "UZBEK_CYRILLIC" },
|
|
671 #endif
|
|
672 #ifdef SUBLANG_UZBEK_LATIN
|
|
673 { SUBLANG_UZBEK_LATIN, "UZBEK_LATIN" },
|
|
674 #endif
|
|
675 };
|
|
676
|
|
677 static int
|
|
678 lang_to_langcode (Lisp_Object lang, struct lang_to_string *table,
|
|
679 int table_size)
|
|
680 {
|
|
681 int i;
|
|
682
|
|
683 for (i = 0; i < table_size; i++)
|
|
684 if (!strcmp ((char *) XSTRING_DATA (lang), table[i].string))
|
|
685 return table[i].code;
|
|
686 return -1;
|
|
687 }
|
|
688
|
|
689 static int
|
|
690 sublang_to_langcode (Lisp_Object lang, struct lang_to_string *table,
|
|
691 int table_size)
|
|
692 {
|
|
693 int i;
|
|
694
|
|
695 for (i = 0; i < table_size; i++)
|
|
696 if (table[i].string &&
|
|
697 !strcmp ((char *) XSTRING_DATA (lang), table[i].string))
|
|
698 return table[i].code;
|
|
699
|
|
700 if (!strcmp ((char *) XSTRING_DATA (lang), "NEUTRAL"))
|
|
701 return SUBLANG_NEUTRAL;
|
|
702 if (!strcmp ((char *) XSTRING_DATA (lang), "DEFAULT"))
|
|
703 return SUBLANG_DEFAULT;
|
|
704 if (!strcmp ((char *) XSTRING_DATA (lang), "SYS_DEFAULT"))
|
|
705 return SUBLANG_SYS_DEFAULT;
|
|
706
|
|
707 return -1;
|
|
708 }
|
|
709
|
|
710 static Lisp_Object
|
|
711 langcode_to_lang (int code, struct lang_to_string *table,
|
|
712 int table_size)
|
|
713 {
|
|
714 int i;
|
|
715
|
|
716 for (i = 0; i < table_size; i++)
|
|
717 if (code == table[i].code)
|
|
718 return build_string (table[i].string);
|
|
719 return Qnil;
|
|
720 }
|
|
721
|
|
722 static Lisp_Object
|
|
723 sublangcode_to_lang (int lang, int sublang, struct lang_to_string *table,
|
|
724 int table_size)
|
|
725 {
|
|
726 int i;
|
|
727 int found_lang = 0;
|
|
728
|
|
729 for (i = 0; i < table_size; i++)
|
|
730 {
|
|
731 if (found_lang)
|
|
732 {
|
|
733 if (!table[i].string)
|
|
734 break;
|
|
735 if (sublang == table[i].code)
|
|
736 return build_string (table[i].string);
|
|
737 }
|
|
738 else if (!table[i].string && lang == table[i].code)
|
|
739 found_lang = 1;
|
|
740 }
|
|
741
|
|
742 switch (sublang)
|
|
743 {
|
|
744 case SUBLANG_NEUTRAL:
|
|
745 return build_string ("NEUTRAL");
|
|
746 case SUBLANG_DEFAULT:
|
|
747 return build_string ("DEFAULT");
|
|
748 case SUBLANG_SYS_DEFAULT:
|
|
749 return build_string ("SYS_DEFAULT");
|
|
750 }
|
|
751
|
|
752 return Qnil;
|
|
753 }
|
|
754
|
|
755 static LCID
|
|
756 locale_to_lcid (Lisp_Object locale)
|
|
757 {
|
|
758 int langcode, sublangcode;
|
|
759 Lisp_Object lang, sublang;
|
|
760
|
|
761 if (STRINGP (locale))
|
|
762 {
|
|
763 lang = locale;
|
|
764 sublang = Qnil;
|
|
765 }
|
|
766 else if (CONSP (locale))
|
|
767 {
|
|
768 CHECK_STRING (XCAR (locale));
|
|
769 CHECK_STRING (XCDR (locale));
|
|
770 lang = XCAR (locale);
|
|
771 sublang = XCDR (locale);
|
|
772 }
|
|
773 else
|
|
774 invalid_argument ("Locale must be LANG or (LANG . SUBLANG)", locale);
|
|
775
|
|
776 langcode = lang_to_langcode (lang, lang_to_string_table,
|
|
777 countof (lang_to_string_table));
|
|
778
|
|
779 if (langcode < 0)
|
|
780 invalid_constant ("Unrecognized language", lang);
|
|
781
|
|
782 if (!NILP (sublang))
|
|
783 {
|
|
784 sublangcode = sublang_to_langcode (sublang, sublang_to_string_table,
|
|
785 countof (sublang_to_string_table));
|
|
786 if (sublangcode < 0)
|
|
787 invalid_constant ("Unrecognized sublanguage", sublang);
|
|
788 }
|
|
789 else
|
|
790 sublangcode = SUBLANG_DEFAULT;
|
|
791
|
|
792 return MAKELCID (MAKELANGID (langcode, sublangcode),
|
|
793 SORT_DEFAULT);
|
|
794 }
|
|
795
|
|
796 static Lisp_Object
|
|
797 lcid_to_locale (LCID lcid)
|
|
798 {
|
|
799 int langid = LANGIDFROMLCID (lcid);
|
|
800 int langcode = PRIMARYLANGID (langid);
|
|
801 int sublangcode = SUBLANGID (langid);
|
|
802
|
|
803 return Fcons (langcode_to_lang (langcode, lang_to_string_table,
|
|
804 countof (lang_to_string_table)),
|
|
805 sublangcode_to_lang (langcode, sublangcode,
|
|
806 sublang_to_string_table,
|
|
807 countof (sublang_to_string_table)));
|
|
808 }
|
|
809
|
|
810 int
|
|
811 mswindows_locale_to_code_page (LCID lcid)
|
|
812 {
|
|
813 char codepagestr[10];
|
|
814
|
|
815 GetLocaleInfoA (lcid, LOCALE_IDEFAULTANSICODEPAGE, codepagestr, 10);
|
|
816 return atoi (codepagestr);
|
|
817 }
|
|
818
|
|
819 int
|
|
820 mswindows_locale_to_oem_code_page (LCID lcid)
|
|
821 {
|
|
822 char codepagestr[10];
|
|
823
|
|
824 GetLocaleInfoA (lcid, LOCALE_IDEFAULTCODEPAGE, codepagestr, 10);
|
|
825 return atoi (codepagestr);
|
|
826 }
|
|
827
|
|
828 static void
|
|
829 set_current_lcid (LCID lcid)
|
|
830 {
|
|
831 int cp;
|
|
832
|
|
833 /* This will fail under Win9x, so we remember our own locale rather than
|
|
834 consulting GetThreadLocale. */
|
|
835 SetThreadLocale (lcid);
|
|
836 current_locale = lcid;
|
|
837 cp = mswindows_locale_to_code_page (lcid);
|
|
838 #ifndef NO_EXT_MULTIBYTE_FEATURES
|
|
839 _setmbcp (cp);
|
|
840 #endif
|
|
841 }
|
|
842
|
|
843 DEFUN ("mswindows-set-current-locale", Fmswindows_set_current_locale,
|
|
844 1, 1, 0, /*
|
|
845 Set the current MS Windows locale.
|
|
846
|
|
847 LOCALE should a language string, or a cons (LANG . SUBLANG).
|
|
848 If SUBLANG is omitted, "SUBLANG_DEFAULT" is used.
|
|
849
|
|
850 Recognized language names are
|
|
851 (some may not be recognized if the compiler is older than VC++ 6.0)
|
|
852
|
|
853 "AFRIKAANS"
|
|
854 "ALBANIAN"
|
|
855 "ARABIC"
|
|
856 "ARMENIAN"
|
|
857 "ASSAMESE"
|
|
858 "AZERI"
|
|
859 "BASQUE"
|
|
860 "BELARUSIAN"
|
|
861 "BENGALI"
|
|
862 "BULGARIAN"
|
|
863 "CATALAN"
|
|
864 "CHINESE"
|
|
865 "CROATIAN"
|
|
866 "CZECH"
|
|
867 "DANISH"
|
|
868 "DUTCH"
|
|
869 "ENGLISH"
|
|
870 "ESTONIAN"
|
|
871 "FAEROESE"
|
|
872 "FARSI"
|
|
873 "FINNISH"
|
|
874 "FRENCH"
|
|
875 "GEORGIAN"
|
|
876 "GERMAN"
|
|
877 "GREEK"
|
|
878 "GUJARATI"
|
|
879 "HEBREW"
|
|
880 "HINDI"
|
|
881 "HUNGARIAN"
|
|
882 "ICELANDIC"
|
|
883 "INDONESIAN"
|
|
884 "ITALIAN"
|
|
885 "JAPANESE"
|
|
886 "KANNADA"
|
|
887 "KASHMIRI"
|
|
888 "KAZAK"
|
|
889 "KONKANI"
|
|
890 "KOREAN"
|
|
891 "LATVIAN"
|
|
892 "LITHUANIAN"
|
|
893 "MACEDONIAN"
|
|
894 "MALAY"
|
|
895 "MALAYALAM"
|
|
896 "MANIPURI"
|
|
897 "MARATHI"
|
|
898 "NEPALI"
|
|
899 "NEUTRAL"
|
|
900 "NORWEGIAN"
|
|
901 "ORIYA"
|
|
902 "POLISH"
|
|
903 "PORTUGUESE"
|
|
904 "PUNJABI"
|
|
905 "ROMANIAN"
|
|
906 "RUSSIAN"
|
|
907 "SANSKRIT"
|
|
908 "SERBIAN"
|
|
909 "SINDHI"
|
|
910 "SLOVAK"
|
|
911 "SLOVENIAN"
|
|
912 "SPANISH"
|
|
913 "SWAHILI"
|
|
914 "SWEDISH"
|
|
915 "TAMIL"
|
|
916 "TATAR"
|
|
917 "TELUGU"
|
|
918 "THAI"
|
|
919 "TURKISH"
|
|
920 "UKRAINIAN"
|
|
921 "URDU"
|
|
922 "UZBEK"
|
|
923 "VIETNAMESE"
|
|
924
|
|
925 Recognized sub-language names are
|
|
926 (some may not be recognized if the compiler is older than VC++ 6.0)
|
|
927
|
|
928 "ARABIC_ALGERIA"
|
|
929 "ARABIC_BAHRAIN"
|
|
930 "ARABIC_EGYPT"
|
|
931 "ARABIC_IRAQ"
|
|
932 "ARABIC_JORDAN"
|
|
933 "ARABIC_KUWAIT"
|
|
934 "ARABIC_LEBANON"
|
|
935 "ARABIC_LIBYA"
|
|
936 "ARABIC_MOROCCO"
|
|
937 "ARABIC_OMAN"
|
|
938 "ARABIC_QATAR"
|
|
939 "ARABIC_SAUDI_ARABIA"
|
|
940 "ARABIC_SYRIA"
|
|
941 "ARABIC_TUNISIA"
|
|
942 "ARABIC_UAE"
|
|
943 "ARABIC_YEMEN"
|
|
944 "AZERI_CYRILLIC"
|
|
945 "AZERI_LATIN"
|
|
946 "CHINESE_HONGKONG"
|
|
947 "CHINESE_MACAU"
|
|
948 "CHINESE_SIMPLIFIED"
|
|
949 "CHINESE_SINGAPORE"
|
|
950 "CHINESE_TRADITIONAL"
|
|
951 "DEFAULT"
|
|
952 "DUTCH"
|
|
953 "DUTCH_BELGIAN"
|
|
954 "ENGLISH_AUS"
|
|
955 "ENGLISH_BELIZE"
|
|
956 "ENGLISH_CAN"
|
|
957 "ENGLISH_CARIBBEAN"
|
|
958 "ENGLISH_EIRE"
|
|
959 "ENGLISH_JAMAICA"
|
|
960 "ENGLISH_NZ"
|
|
961 "ENGLISH_PHILIPPINES"
|
|
962 "ENGLISH_SOUTH_AFRICA"
|
|
963 "ENGLISH_TRINIDAD"
|
|
964 "ENGLISH_UK"
|
|
965 "ENGLISH_US"
|
|
966 "ENGLISH_ZIMBABWE"
|
|
967 "FRENCH"
|
|
968 "FRENCH_BELGIAN"
|
|
969 "FRENCH_CANADIAN"
|
|
970 "FRENCH_LUXEMBOURG"
|
|
971 "FRENCH_MONACO"
|
|
972 "FRENCH_SWISS"
|
|
973 "GERMAN"
|
|
974 "GERMAN_AUSTRIAN"
|
|
975 "GERMAN_LIECHTENSTEIN"
|
|
976 "GERMAN_LUXEMBOURG"
|
|
977 "GERMAN_SWISS"
|
|
978 "ITALIAN"
|
|
979 "ITALIAN_SWISS"
|
|
980 "KASHMIRI_INDIA"
|
|
981 "KOREAN"
|
|
982 "KOREAN_JOHAB" (NOTE: omitted in Visual C++ 6.0 and later)
|
|
983 "LITHUANIAN"
|
|
984 "LITHUANIAN_CLASSIC"
|
|
985 "MALAY_BRUNEI_DARUSSALAM"
|
|
986 "MALAY_MALAYSIA"
|
|
987 "NEPALI_INDIA"
|
|
988 "NEUTRAL"
|
|
989 "NORWEGIAN_BOKMAL"
|
|
990 "NORWEGIAN_NYNORSK"
|
|
991 "PORTUGUESE"
|
|
992 "PORTUGUESE_BRAZILIAN"
|
|
993 "SERBIAN_CYRILLIC"
|
|
994 "SERBIAN_LATIN"
|
|
995 "SPANISH"
|
|
996 "SPANISH_ARGENTINA"
|
|
997 "SPANISH_BOLIVIA"
|
|
998 "SPANISH_CHILE"
|
|
999 "SPANISH_COLOMBIA"
|
|
1000 "SPANISH_COSTA_RICA"
|
|
1001 "SPANISH_DOMINICAN_REPUBLIC"
|
|
1002 "SPANISH_ECUADOR"
|
|
1003 "SPANISH_EL_SALVADOR"
|
|
1004 "SPANISH_GUATEMALA"
|
|
1005 "SPANISH_HONDURAS"
|
|
1006 "SPANISH_MEXICAN"
|
|
1007 "SPANISH_MODERN"
|
|
1008 "SPANISH_NICARAGUA"
|
|
1009 "SPANISH_PANAMA"
|
|
1010 "SPANISH_PARAGUAY"
|
|
1011 "SPANISH_PERU"
|
|
1012 "SPANISH_PUERTO_RICO"
|
|
1013 "SPANISH_URUGUAY"
|
|
1014 "SPANISH_VENEZUELA"
|
|
1015 "SWEDISH"
|
|
1016 "SWEDISH_FINLAND"
|
|
1017 "SYS_DEFAULT"
|
|
1018 "URDU_INDIA"
|
|
1019 "URDU_PAKISTAN"
|
|
1020 "UZBEK_CYRILLIC"
|
|
1021 "UZBEK_LATIN"
|
|
1022 */
|
|
1023 (locale))
|
|
1024 {
|
|
1025 LCID lcid = locale_to_lcid (locale);
|
|
1026
|
|
1027 set_current_lcid (lcid);
|
|
1028 return Qnil;
|
|
1029 }
|
|
1030
|
|
1031 #ifdef DEBUG_XEMACS
|
|
1032
|
872
|
1033 int getacp (void);
|
771
|
1034 int
|
|
1035 getacp (void)
|
|
1036 {
|
|
1037 return GetACP ();
|
|
1038 }
|
|
1039
|
|
1040 #endif /* DEBUG_XEMACS */
|
|
1041
|
|
1042 LCID
|
|
1043 mswindows_current_locale (void)
|
|
1044 {
|
|
1045 /* Even if SetThreadLocale() failed, return the right locale anyway */
|
|
1046 return current_locale;
|
|
1047 }
|
|
1048
|
|
1049 DEFUN ("mswindows-current-locale", Fmswindows_current_locale,
|
|
1050 0, 0, 0, /*
|
|
1051 Return the current MS Windows locale.
|
|
1052
|
|
1053 The return value will be a cons (LANG . SUBLANG). See
|
|
1054 `mswindows-set-current-locale' for more info.
|
|
1055 */
|
|
1056 ())
|
|
1057 {
|
|
1058 return lcid_to_locale (mswindows_current_locale ());
|
|
1059 }
|
|
1060
|
|
1061 DEFUN ("mswindows-user-default-locale", Fmswindows_user_default_locale,
|
|
1062 0, 0, 0, /*
|
|
1063 Return the MS Windows user-default locale.
|
|
1064 */
|
|
1065 ())
|
|
1066 {
|
|
1067 return lcid_to_locale (GetUserDefaultLCID ());
|
|
1068 }
|
|
1069
|
|
1070 DEFUN ("mswindows-system-default-locale", Fmswindows_system_default_locale,
|
|
1071 0, 0, 0, /*
|
|
1072 Return the MS Windows system-default locale.
|
|
1073 */
|
|
1074 ())
|
|
1075 {
|
|
1076 return lcid_to_locale (GetSystemDefaultLCID ());
|
|
1077 }
|
|
1078
|
|
1079 DEFUN ("mswindows-locale-code-page", Fmswindows_locale_code_page,
|
|
1080 0, 1, 0, /*
|
|
1081 Return the (ANSI) code page of the specified MS Windows locale.
|
|
1082 If LOCALE is nil or omitted, the current locale is used.
|
|
1083 */
|
|
1084 (locale))
|
|
1085 {
|
|
1086 LCID lcid = NILP (locale) ? current_locale : locale_to_lcid (locale);
|
|
1087 return make_int (mswindows_locale_to_code_page (lcid));
|
|
1088 }
|
|
1089
|
|
1090 DEFUN ("mswindows-locale-oem-code-page", Fmswindows_locale_oem_code_page,
|
|
1091 0, 1, 0, /*
|
|
1092 Return the OEM code page of the specified MS Windows locale.
|
|
1093 If LOCALE is nil or omitted, the current locale is used.
|
|
1094 */
|
|
1095 (locale))
|
|
1096 {
|
|
1097 LCID lcid = NILP (locale) ? current_locale : locale_to_lcid (locale);
|
|
1098 return make_int (mswindows_locale_to_oem_code_page (lcid));
|
|
1099 }
|
|
1100
|
|
1101 static DWORD
|
|
1102 int_from_hex (Char_ASCII *s)
|
|
1103 {
|
|
1104 DWORD val = 0;
|
|
1105 static Char_ASCII hex[] = "0123456789abcdefABCDEF";
|
|
1106 Char_ASCII *p;
|
|
1107
|
|
1108 while (*s && (p = strchr (hex, *s)) != NULL)
|
|
1109 {
|
|
1110 int digit = p - hex;
|
|
1111 if (digit > 15)
|
|
1112 digit -= 6;
|
|
1113 val = val * 16 + digit;
|
|
1114 s++;
|
|
1115 }
|
|
1116 return val;
|
|
1117 }
|
|
1118
|
|
1119 /* We need to build a global list, since the EnumSystemLocale callback
|
|
1120 function isn't given a context pointer. */
|
|
1121 static Lisp_Object Vmswindows_valid_locales;
|
|
1122
|
|
1123 static BOOL CALLBACK
|
|
1124 enum_locale_fn (Char_ASCII *localeNum)
|
|
1125 {
|
|
1126 DWORD id = int_from_hex (localeNum);
|
|
1127 Vmswindows_valid_locales =
|
|
1128 Fcons (lcid_to_locale ((LCID) id), Vmswindows_valid_locales);
|
|
1129 return TRUE;
|
|
1130 }
|
|
1131
|
|
1132 DEFUN ("mswindows-supported-locales", Fmswindows_supported_locales,
|
|
1133 0, 0, 0, /*
|
|
1134 Return a list of the supported MS Windows locales on this system.
|
|
1135 */
|
|
1136 ())
|
|
1137 {
|
|
1138 Vmswindows_valid_locales = Qnil;
|
|
1139
|
|
1140 /* Use the ANSI version because the return value is just a hex number. */
|
|
1141 EnumSystemLocalesA (enum_locale_fn, LCID_SUPPORTED);
|
|
1142
|
|
1143 Vmswindows_valid_locales = Fnreverse (Vmswindows_valid_locales);
|
|
1144 return Vmswindows_valid_locales;
|
|
1145 }
|
|
1146
|
|
1147 /************************************************************************/
|
|
1148 /* Mule functions */
|
|
1149 /************************************************************************/
|
|
1150
|
|
1151 DEFUN ("mswindows-charset-code-page",
|
|
1152 Fmswindows_charset_code_page, 1, 1, 0, /*
|
|
1153 Return the code page for the CHARSET.
|
|
1154
|
|
1155 #### This function may be changed in the near future.
|
|
1156
|
|
1157 Currently defined Windows code pages include (along with their status
|
|
1158 as Ansi, OEM, Mac, EBCDIC, or some combination):
|
|
1159
|
|
1160 EBCDIC 037 EBCDIC
|
|
1161 OEM 437 MS-DOS United States
|
|
1162 EBCDIC 500 EBCDIC "500V1"
|
|
1163 OEM 708 Arabic (ASMO 708)
|
|
1164 OEM 709 Arabic (ASMO 449+, BCON V4)
|
|
1165 OEM 710 Arabic (Transparent Arabic)
|
|
1166 OEM 720 Arabic (Transparent ASMO)
|
|
1167 OEM 737 Greek (formerly 437G)
|
|
1168 OEM 775 Baltic
|
|
1169 OEM 850 MS-DOS Multilingual (Latin I)
|
|
1170 OEM 852 MS-DOS Slavic (Latin II)
|
|
1171 OEM 855 IBM Cyrillic (primarily Russian)
|
|
1172 OEM 857 IBM Turkish
|
|
1173 OEM 860 MS-DOS Portuguese
|
|
1174 OEM 861 MS-DOS Icelandic
|
|
1175 OEM 862 Hebrew
|
|
1176 OEM 863 MS-DOS Canadian-French
|
|
1177 OEM 864 Arabic
|
|
1178 OEM 865 MS-DOS Nordic
|
|
1179 OEM 866 MS-DOS Russian
|
|
1180 OEM 869 IBM Modern Greek
|
|
1181 Ansi/OEM 874 Thai
|
|
1182 EBCDIC 875 EBCDIC
|
|
1183 Ansi/OEM 932 Japanese
|
|
1184 Ansi/OEM 936 Chinese (PRC, Singapore)
|
|
1185 Ansi/OEM 949 Korean
|
|
1186 Ansi/OEM 950 Chinese (Taiwan; Hong Kong SAR, PRC)
|
|
1187 EBCDIC 1026 EBCDIC
|
|
1188 ANSI 1200 Unicode (BMP of ISO 10646)
|
|
1189 ANSI 1250 Windows 3.1 Eastern European
|
|
1190 ANSI 1251 Windows 3.1 Cyrillic
|
|
1191 ANSI 1252 Windows 3.1 US (ANSI)
|
|
1192 ANSI 1253 Windows 3.1 Greek
|
|
1193 ANSI 1254 Windows 3.1 Turkish
|
|
1194 ANSI 1255 Hebrew
|
|
1195 ANSI 1256 Arabic
|
|
1196 ANSI 1257 Baltic
|
|
1197 ANSI 1258 VietNam
|
|
1198 Ansi/OEM 1361 Korean (Johab)
|
|
1199 Mac 10000 Macintosh Roman
|
|
1200 Mac 10001 Macintosh Japanese
|
|
1201 Mac 10006 Macintosh Greek I
|
|
1202 Mac 10007 Macintosh Cyrillic
|
|
1203 Mac 10029 Macintosh Latin 2
|
|
1204 Mac 10079 Macintosh Icelandic
|
|
1205 Mac 10081 Macintosh Turkish
|
|
1206
|
|
1207 A code page is a set of characters, along with an enumeration of these
|
|
1208 characters and an encoding of them in a byte stream. Thus, in XEmacs
|
|
1209 parlance it defines both a "charset" and a "coding system" for this
|
|
1210 charset. Traditional encodings are either simple one-byte encodings, or
|
|
1211 combination one-byte/two-byte encodings (aka MBCS encodings, where MBCS
|
|
1212 stands for "Multibyte Character Set") with the following properties:
|
|
1213
|
|
1214 -- all characters are encoded as a one-byte or two-byte sequence
|
|
1215 -- the encoding is stateless (non-modal)
|
|
1216 -- the lower 128 bytes are compatible with ASCII
|
|
1217 -- in the higher bytes, the value of the first byte ("lead byte")
|
|
1218 determines whether a second byte follows
|
|
1219 -- the values used for second bytes may overlap those used for first bytes,
|
|
1220 and (in some encodings) include values in the low half; thus, moving
|
|
1221 backwards is hard, and pure-ASCII algorithms (e.g. finding the next slash)
|
|
1222 will fail unless rewritten to be MBCS-aware (neither of these problems
|
|
1223 exist in UTF-8 or in the XEmacs internal string encoding)
|
|
1224
|
|
1225 Recent code pages, however, do not necessarily follow these properties --
|
|
1226 code pages have been expanded to include arbitrary encodings, such as UTF-8
|
|
1227 \(may have more than two bytes per character) and ISO-2022-JP (complex modal
|
|
1228 encoding).
|
|
1229
|
|
1230 Every locale has four associated code pages: ANSI (an international
|
|
1231 standard or some Microsoft-created approximation; the native code page
|
|
1232 under Windows), OEM (a DOS encoding, still used in the FAT file system),
|
|
1233 Mac (an encoding used on the Macintosh) and EBCDIC (a non-ASCII-compatible
|
|
1234 encoding used on IBM mainframes, originally based on the BCD or
|
|
1235 "binary-coded decimal" encoding of numbers). All code pages associated
|
|
1236 with a locale follow (as far as I know) the properties listed above for
|
|
1237 traditional code pages.
|
|
1238 */
|
|
1239 (charset))
|
|
1240 {
|
|
1241 charset = Fget_charset (charset);
|
|
1242 return Fgethash (charset, Vmswindows_charset_code_page_table, Qnil);
|
|
1243 }
|
|
1244
|
|
1245 DEFUN ("mswindows-set-charset-code-page",
|
|
1246 Fmswindows_set_charset_code_page, 2, 2, 0, /*
|
|
1247 Set the CODE-PAGE for the CHARSET.
|
|
1248
|
|
1249 #### This function may be changed once full Unicode support is present.
|
|
1250 */
|
|
1251 (charset, code_page))
|
|
1252 {
|
|
1253 charset = Fget_charset (charset);
|
|
1254 CHECK_INT (code_page);
|
|
1255 Fputhash (charset, code_page, Vmswindows_charset_code_page_table);
|
|
1256 return Qnil;
|
|
1257 }
|
|
1258
|
|
1259 Lisp_Object
|
|
1260 mswindows_get_code_page_charset (int code_page)
|
|
1261 {
|
|
1262 Lisp_Object charset_tail;
|
|
1263 Lisp_Object charset = Qunbound;
|
|
1264
|
|
1265 LIST_LOOP (charset_tail, Fcharset_list ())
|
|
1266 {
|
|
1267 Lisp_Object charset_code_page;
|
|
1268
|
|
1269 charset_code_page = Fmswindows_charset_code_page (XCAR (charset_tail));
|
|
1270 if (INTP (charset_code_page) &&
|
|
1271 code_page == XINT (charset_code_page))
|
|
1272 {
|
|
1273 charset = Fget_charset (XCAR (charset_tail));
|
|
1274 break;
|
|
1275 }
|
|
1276 }
|
|
1277 return charset;
|
|
1278 }
|
|
1279
|
872
|
1280 DEFUN ("mswindows-charset-registry",
|
|
1281 Fmswindows_charset_registry, 1, 1, 0, /*
|
|
1282 Return the registry for the CHARSET.
|
|
1283 This is the last item in an MS Windows font spec.
|
|
1284
|
|
1285 #### This function may be changed in the near future.
|
|
1286 */
|
|
1287 (charset))
|
|
1288 {
|
|
1289 charset = Fget_charset (charset);
|
|
1290 return Fgethash (charset, Vmswindows_charset_registry_table, Qnil);
|
|
1291 }
|
|
1292
|
|
1293 DEFUN ("mswindows-set-charset-registry",
|
|
1294 Fmswindows_set_charset_registry, 2, 2, 0, /*
|
|
1295 Set the REGISTRY for the CHARSET.
|
|
1296
|
|
1297 #### This function may be changed once full Unicode support is present.
|
|
1298 */
|
|
1299 (charset, registry))
|
|
1300 {
|
|
1301 charset = Fget_charset (charset);
|
|
1302 CHECK_STRING (registry);
|
|
1303 Fputhash (charset, registry, Vmswindows_charset_registry_table);
|
|
1304 invalidate_charset_font_caches (charset);
|
|
1305 face_property_was_changed (Vdefault_face, Qfont, Qglobal);
|
|
1306 return Qnil;
|
|
1307 }
|
|
1308
|
1111
|
1309 #if 0 /* Unused */
|
|
1310
|
|
1311 static Lisp_Object
|
872
|
1312 mswindows_get_registry_charset (Ibyte *registry)
|
|
1313 {
|
|
1314 Lisp_Object charset_tail;
|
|
1315 Lisp_Object charset = Qunbound;
|
|
1316
|
|
1317 LIST_LOOP (charset_tail, Fcharset_list ())
|
|
1318 {
|
|
1319 Lisp_Object charset_registry;
|
|
1320
|
|
1321 charset_registry = Fmswindows_charset_registry (XCAR (charset_tail));
|
|
1322 if (STRINGP (charset_registry) &&
|
|
1323 !qxestrcasecmp (XSTRING_DATA (charset_registry), registry))
|
|
1324 {
|
|
1325 charset = Fget_charset (XCAR (charset_tail));
|
|
1326 break;
|
|
1327 }
|
|
1328 }
|
|
1329 return charset;
|
|
1330 }
|
|
1331
|
1111
|
1332 #endif /* 0 */
|
|
1333
|
771
|
1334
|
|
1335
|
|
1336 #if 0 /* #### from Emacs 20.6; consider porting */
|
|
1337
|
826
|
1338 DEFUN ("mswindows-get-locale-info", Fmswindows_get_locale_info, 1, 2, 0, /*
|
771
|
1339 Return information about the Windows locale LCID.
|
|
1340 By default, return a three letter locale code which encodes the default
|
|
1341 language as the first two characters, and the country or regionial variant
|
|
1342 as the third letter. For example, ENU refers to `English (United States)',
|
|
1343 while ENC means `English (Canadian)'.
|
|
1344
|
|
1345 If the optional argument LONGFORM is t, the long form of the locale
|
|
1346 name is returned, e.g. `English (United States)' instead; if LONGFORM
|
|
1347 is a number, it is interpreted as an LCTYPE constant and the corresponding
|
|
1348 locale information is returned.
|
|
1349
|
|
1350 If LCID (a 16-bit number) is not a valid locale, the result is nil.
|
|
1351 */
|
|
1352 (lcid, longform))
|
|
1353 {
|
|
1354 int got_abbrev;
|
|
1355 int got_full;
|
|
1356 char abbrev_name[32] = { 0 };
|
|
1357 char full_name[256] = { 0 };
|
|
1358
|
|
1359 CHECK_INT (lcid);
|
|
1360
|
|
1361 if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED))
|
|
1362 return Qnil;
|
|
1363
|
|
1364 if (NILP (longform))
|
|
1365 {
|
|
1366 got_abbrev = GetLocaleInfo (XINT (lcid),
|
|
1367 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
|
|
1368 abbrev_name, sizeof (abbrev_name));
|
|
1369 if (got_abbrev)
|
|
1370 return build_string (abbrev_name);
|
|
1371 }
|
|
1372 else if (EQ (longform, Qt))
|
|
1373 {
|
|
1374 got_full = GetLocaleInfo (XINT (lcid),
|
|
1375 LOCALE_SLANGUAGE | LOCALE_USE_CP_ACP,
|
|
1376 full_name, sizeof (full_name));
|
|
1377 if (got_full)
|
|
1378 return build_string (full_name);
|
|
1379 }
|
|
1380 else if (NUMBERP (longform))
|
|
1381 {
|
|
1382 got_full = GetLocaleInfo (XINT (lcid),
|
|
1383 XINT (longform),
|
|
1384 full_name, sizeof (full_name));
|
|
1385 if (got_full)
|
|
1386 return make_unibyte_string (full_name, got_full);
|
|
1387 }
|
|
1388
|
|
1389 return Qnil;
|
|
1390 }
|
|
1391
|
|
1392 /* We need to build a global list, since the EnumCodePages callback
|
|
1393 function isn't given a context pointer. */
|
|
1394 Lisp_Object Vmswindows_valid_code_pages;
|
|
1395
|
|
1396 BOOL CALLBACK enum_code_page_fn (LPTSTR codepageNum)
|
|
1397 {
|
|
1398 DWORD id = atoi (codepageNum);
|
|
1399 Vmswindows_valid_code_pages = Fcons (make_int (id), Vmswindows_valid_code_pages);
|
|
1400 return TRUE;
|
|
1401 }
|
|
1402
|
826
|
1403 DEFUN ("mswindows-get-valid-code-pages", Fmswindows_get_valid_code_pages, 0, 0, 0, /*
|
771
|
1404 Return list of all valid Windows code pages.
|
|
1405 */
|
|
1406 ())
|
|
1407 {
|
|
1408 Vmswindows_valid_code_pages = Qnil;
|
|
1409
|
|
1410 EnumSystemCodePages (enum_code_page_fn, CP_SUPPORTED);
|
|
1411
|
|
1412 Vmswindows_valid_code_pages = Fnreverse (Vmswindows_valid_code_pages);
|
|
1413 return Vmswindows_valid_code_pages;
|
|
1414 }
|
|
1415
|
826
|
1416 DEFUN ("mswindows-get-console-code-page", Fmswindows_get_console_code_page, 0, 0, 0, /*
|
771
|
1417 Return current Windows code page for console input.
|
|
1418 */
|
|
1419 ())
|
|
1420 {
|
|
1421 return make_int (GetConsoleCP ());
|
|
1422 }
|
|
1423
|
826
|
1424 DEFUN ("mswindows-set-console-code-page", Fmswindows_set_console_code_page, 1, 1, 0, /*
|
771
|
1425 Make Windows code page CP be the current code page setting for Emacs.
|
|
1426 The code page setting affects keyboard input and display in tty mode.
|
|
1427 If successful, the new CP is returned, otherwise nil.
|
|
1428 */
|
|
1429 (cp))
|
|
1430 {
|
|
1431 CHECK_INT (cp);
|
|
1432
|
|
1433 if (!IsValidCodePage (XINT (cp)))
|
|
1434 return Qnil;
|
|
1435
|
|
1436 if (!SetConsoleCP (XINT (cp)))
|
|
1437 return Qnil;
|
|
1438
|
|
1439 return make_int (GetConsoleCP ());
|
|
1440 }
|
|
1441
|
826
|
1442 DEFUN ("mswindows-get-console-output-code-page", Fmswindows_get_console_output_code_page, 0, 0, 0, /*
|
771
|
1443 Return current Windows code page for console output.
|
|
1444 */
|
|
1445 ())
|
|
1446 {
|
|
1447 return make_int (GetConsoleOutputCP ());
|
|
1448 }
|
|
1449
|
826
|
1450 DEFUN ("mswindows-set-console-output-code-page", Fmswindows_set_console_output_code_page, 1, 1, 0, /*
|
771
|
1451 Make Windows code page CP be the current code page setting for Emacs.
|
|
1452 The code page setting affects keyboard input and display in tty mode.
|
|
1453 If successful, the new CP is returned, otherwise nil.
|
|
1454 */
|
|
1455 (cp))
|
|
1456 {
|
|
1457 CHECK_INT (cp);
|
|
1458
|
|
1459 if (!IsValidCodePage (XINT (cp)))
|
|
1460 return Qnil;
|
|
1461
|
|
1462 if (!SetConsoleOutputCP (XINT (cp)))
|
|
1463 return Qnil;
|
|
1464
|
|
1465 return make_int (GetConsoleOutputCP ());
|
|
1466 }
|
|
1467
|
826
|
1468 DEFUN ("mswindows-get-code-page-charset", Fmswindows_get_code_page_charset, 1, 1, 0, /*
|
771
|
1469 Return charset of code page CP.
|
|
1470 Returns nil if the code page is not valid.
|
|
1471 */
|
|
1472 (cp))
|
|
1473 {
|
|
1474 CHARSETINFO info;
|
|
1475
|
|
1476 CHECK_INT (cp);
|
|
1477
|
|
1478 if (!IsValidCodePage (XINT (cp)))
|
|
1479 return Qnil;
|
|
1480
|
|
1481 if (TranslateCharsetInfo ((DWORD *) XINT (cp), &info, TCI_SRCCODEPAGE))
|
|
1482 return make_int (info.ciCharset);
|
|
1483
|
|
1484 return Qnil;
|
|
1485 }
|
|
1486
|
826
|
1487 DEFUN ("mswindows-get-valid-keyboard-layouts", Fmswindows_get_valid_keyboard_layouts, 0, 0, 0, /*
|
771
|
1488 Return list of Windows keyboard languages and layouts.
|
|
1489 The return value is a list of pairs of language id and layout id.
|
|
1490 */
|
|
1491 ())
|
|
1492 {
|
|
1493 int num_layouts = GetKeyboardLayoutList (0, NULL);
|
851
|
1494 HKL * layouts = (HKL *) ALLOCA (num_layouts * sizeof (HKL));
|
771
|
1495 Lisp_Object obj = Qnil;
|
|
1496
|
|
1497 if (GetKeyboardLayoutList (num_layouts, layouts) == num_layouts)
|
|
1498 {
|
|
1499 while (--num_layouts >= 0)
|
|
1500 {
|
|
1501 DWORD kl = (DWORD) layouts[num_layouts];
|
|
1502
|
|
1503 obj = Fcons (Fcons (make_int (kl & 0xffff),
|
|
1504 make_int ((kl >> 16) & 0xffff)),
|
|
1505 obj);
|
|
1506 }
|
|
1507 }
|
|
1508
|
|
1509 return obj;
|
|
1510 }
|
|
1511
|
826
|
1512 DEFUN ("mswindows-get-keyboard-layout", Fmswindows_get_keyboard_layout, 0, 0, 0, /*
|
771
|
1513 Return current Windows keyboard language and layout.
|
|
1514 The return value is the cons of the language id and the layout id.
|
|
1515 */
|
|
1516 ())
|
|
1517 {
|
|
1518 DWORD kl = (DWORD) GetKeyboardLayout (dwWindowsThreadId);
|
|
1519
|
|
1520 return Fcons (make_int (kl & 0xffff),
|
|
1521 make_int ((kl >> 16) & 0xffff));
|
|
1522 }
|
|
1523
|
826
|
1524 DEFUN ("mswindows-set-keyboard-layout", Fmswindows_set_keyboard_layout, 1, 1, 0, /*
|
771
|
1525 Make LAYOUT be the current keyboard layout for Emacs.
|
|
1526 The keyboard layout setting affects interpretation of keyboard input.
|
|
1527 If successful, the new layout id is returned, otherwise nil.
|
|
1528 */
|
|
1529 (layout))
|
|
1530 {
|
|
1531 DWORD kl;
|
|
1532
|
|
1533 CHECK_CONS (layout);
|
|
1534 CHECK_INT (XCAR (layout)));
|
|
1535 CHECK_INT (XCDR (layout)));
|
|
1536
|
|
1537 kl = (XINT (XCAR (layout))) & 0xffff)
|
|
1538 | (XINT (XCDR (layout))) << 16);
|
|
1539
|
|
1540 if (!ActivateKeyboardLayout ((HKL) kl, 0))
|
|
1541 return Qnil;
|
|
1542
|
|
1543 return Fmswindows_get_keyboard_layout ();
|
|
1544 }
|
|
1545
|
|
1546 #endif /* 0 */
|
|
1547
|
|
1548
|
|
1549 /* input method functions. */
|
|
1550
|
|
1551 #ifdef HAVE_MS_WINDOWS
|
|
1552
|
|
1553 void
|
|
1554 mswindows_start_ime_composition (struct frame *f)
|
|
1555 {
|
|
1556 COMPOSITIONFORM form;
|
|
1557 HWND hwnd = FRAME_MSWINDOWS_HANDLE (f);
|
|
1558 HIMC himc = ImmGetContext (hwnd);
|
|
1559
|
|
1560 /* Set a position of composition window. */
|
|
1561 xzero (form);
|
|
1562 form.dwStyle = CFS_POINT;
|
|
1563 form.ptCurrentPos.x = FRAME_MSWINDOWS_CURSOR_X (f);
|
|
1564 form.ptCurrentPos.y = FRAME_MSWINDOWS_CURSOR_Y (f);
|
|
1565 ImmSetCompositionWindow (himc, &form);
|
|
1566
|
|
1567 /* Set composition window font same as current face one. */
|
|
1568 {
|
|
1569 LOGFONTW old_logfont;
|
|
1570 CHARSETINFO info;
|
|
1571 Lisp_Object charset;
|
|
1572
|
|
1573 /* Get Mule charset from current ime font charset. */
|
|
1574 qxeImmGetCompositionFont (himc, &old_logfont);
|
|
1575 TranslateCharsetInfo ((DWORD *) (DWORD) old_logfont.lfCharSet, &info,
|
|
1576 TCI_SRCCHARSET);
|
|
1577 charset = mswindows_get_code_page_charset (info.ciACP);
|
|
1578
|
|
1579 if (CHARSETP (charset))
|
|
1580 {
|
|
1581 Lisp_Object window = FRAME_SELECTED_WINDOW (f);
|
|
1582 struct window *w = XWINDOW (window);
|
|
1583 face_index findex = FRAME_MSWINDOWS_CURSOR_FINDEX (f);
|
|
1584 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, findex);
|
|
1585 Lisp_Object face_font = FACE_CACHEL_FONT (cachel, charset);
|
|
1586
|
|
1587 if (!FONT_INSTANCEP (face_font))
|
|
1588 face_font =
|
|
1589 ensure_face_cachel_contains_charset (cachel, window, charset);
|
|
1590
|
|
1591 if (!EQ (face_font, Vthe_null_font_instance))
|
|
1592 {
|
|
1593 LOGFONTW new_logfont;
|
|
1594
|
|
1595 /* Get LOGFONT from the face font */
|
|
1596 if (qxeGetObject (FONT_INSTANCE_MSWINDOWS_HFONT_VARIANT
|
|
1597 (XFONT_INSTANCE (face_font),
|
|
1598 cachel->underline, cachel->strikethru),
|
|
1599 sizeof (LOGFONTW), (void*) &new_logfont))
|
|
1600 qxeImmSetCompositionFont (himc, &new_logfont);
|
|
1601 }
|
|
1602 }
|
|
1603 }
|
|
1604 ImmReleaseContext (hwnd, himc);
|
|
1605 return;
|
|
1606 }
|
|
1607
|
|
1608 #endif /* HAVE_MS_WINDOWS */
|
|
1609
|
|
1610 #else /* not MULE */
|
|
1611
|
|
1612 int
|
2286
|
1613 mswindows_locale_to_code_page (LCID UNUSED (lcid))
|
771
|
1614 {
|
|
1615 return CP_ACP;
|
|
1616 }
|
|
1617
|
|
1618 #endif /* MULE */
|
|
1619
|
|
1620
|
|
1621 #ifdef CYGWIN
|
|
1622
|
1111
|
1623 /* based on newlib str*() */
|
|
1624
|
|
1625 #ifndef HAVE_WCSCMP
|
|
1626
|
|
1627 int
|
|
1628 wcscmp (const wchar_t *s1, const wchar_t *s2)
|
|
1629 {
|
|
1630 while (*s1 != '\0' && *s1 == *s2)
|
|
1631 {
|
|
1632 s1++;
|
|
1633 s2++;
|
|
1634 }
|
|
1635
|
|
1636 return *s1 - *s2;
|
|
1637 }
|
|
1638
|
|
1639 #endif /* not HAVE_WCSCMP */
|
|
1640
|
|
1641 #ifndef HAVE_WCSLEN
|
|
1642
|
|
1643 size_t
|
|
1644 wcslen (const wchar_t *str)
|
|
1645 {
|
|
1646 const wchar_t *start = str;
|
|
1647
|
|
1648 while (*str)
|
|
1649 str++;
|
|
1650
|
|
1651 return str - start;
|
|
1652 }
|
|
1653
|
|
1654 #endif /* not HAVE_WCSLEN */
|
771
|
1655
|
|
1656 wchar_t *
|
|
1657 wcsncpy (wchar_t *dst0, const wchar_t *src0, size_t count)
|
|
1658 {
|
|
1659 wchar_t *dscan;
|
|
1660 const wchar_t *sscan;
|
|
1661
|
|
1662 dscan = dst0;
|
|
1663 sscan = src0;
|
|
1664 while (count > 0)
|
|
1665 {
|
|
1666 --count;
|
|
1667 if ((*dscan++ = *sscan++) == '\0')
|
|
1668 break;
|
|
1669 }
|
|
1670 while (count-- > 0)
|
|
1671 *dscan++ = '\0';
|
|
1672
|
|
1673 return dst0;
|
|
1674 }
|
|
1675
|
|
1676 wchar_t *
|
|
1677 wcscpy (wchar_t *dst0, const wchar_t *src0)
|
|
1678 {
|
|
1679 wchar_t *s = dst0;
|
|
1680
|
|
1681 while ((*dst0++ = *src0++))
|
|
1682 ;
|
|
1683
|
|
1684 return s;
|
|
1685 }
|
|
1686
|
|
1687 wchar_t *
|
|
1688 wcsdup (const wchar_t *str)
|
|
1689 {
|
|
1690 int len = wcslen (str) + 1;
|
|
1691 void *val = xmalloc (len * sizeof (wchar_t));
|
|
1692
|
|
1693 if (val == 0) return 0;
|
|
1694 return (wchar_t *) memcpy (val, str, len * sizeof (wchar_t));
|
|
1695 }
|
|
1696
|
|
1697 #endif /* CYGWIN */
|
|
1698
|
|
1699
|
|
1700 /************************************************************************/
|
|
1701 /* MS Windows multibyte-to-unicode methods */
|
|
1702 /************************************************************************/
|
|
1703
|
|
1704 enum mswindows_multibyte_cp_type
|
|
1705 {
|
|
1706 MULTIBYTE_ANSI,
|
|
1707 MULTIBYTE_OEM,
|
|
1708 MULTIBYTE_EBCDIC,
|
|
1709 MULTIBYTE_MAC
|
|
1710 };
|
|
1711
|
|
1712 enum mswindows_multibyte_locale_type
|
|
1713 {
|
|
1714 MULTIBYTE_SPECIFIED_LOCALE,
|
|
1715 MULTIBYTE_SPECIFIED_CODE_PAGE,
|
|
1716 MULTIBYTE_CURRENT,
|
|
1717 MULTIBYTE_USER_DEFAULT,
|
|
1718 MULTIBYTE_SYSTEM_DEFAULT
|
|
1719 };
|
|
1720
|
|
1721 struct mswindows_multibyte_to_unicode_coding_system
|
|
1722 {
|
|
1723 enum mswindows_multibyte_cp_type cp_type;
|
|
1724 enum mswindows_multibyte_locale_type locale_type;
|
|
1725 LCID locale; /* if locale_type is MULTIBYTE_SPECIFIED_LOCALE */
|
|
1726 int cp; /* if locale_type is MULTIBYTE_SPECIFIED_CODE_PAGE */
|
|
1727 };
|
|
1728
|
|
1729 struct mswindows_multibyte_to_unicode_coding_stream
|
|
1730 {
|
|
1731 int partial_byte;
|
|
1732 int partial_byte_present;
|
|
1733 int cp;
|
|
1734 };
|
|
1735
|
1204
|
1736 static const struct memory_description
|
771
|
1737 mswindows_multibyte_to_unicode_coding_system_description[] = {
|
|
1738 { XD_END }
|
|
1739 };
|
|
1740
|
1204
|
1741 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (mswindows_multibyte_to_unicode);
|
|
1742
|
771
|
1743 static void
|
|
1744 mswindows_multibyte_to_unicode_init (Lisp_Object codesys)
|
|
1745 {
|
|
1746 struct mswindows_multibyte_to_unicode_coding_system *data =
|
|
1747 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte_to_unicode);
|
|
1748
|
|
1749 data->cp_type = MULTIBYTE_ANSI;
|
|
1750 data->locale_type = MULTIBYTE_CURRENT;
|
|
1751 }
|
|
1752
|
|
1753 static Lisp_Object
|
2286
|
1754 lcid_to_locale_mule_or_no (LCID USED_IF_MULE (lcid))
|
771
|
1755 {
|
|
1756 #ifdef MULE
|
|
1757 return lcid_to_locale (lcid);
|
|
1758 #else
|
|
1759 return Fcons (build_string ("NEUTRAL"), build_string ("DEFAULT"));
|
|
1760 #endif
|
|
1761 }
|
|
1762
|
|
1763 static int
|
2286
|
1764 determine_code_page (Lisp_Object USED_IF_MULE (codesys))
|
771
|
1765 {
|
|
1766 #ifdef MULE
|
|
1767 LCID locale;
|
|
1768 struct mswindows_multibyte_to_unicode_coding_system *data =
|
|
1769 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte_to_unicode);
|
|
1770
|
|
1771 switch (data->locale_type)
|
|
1772 {
|
|
1773 case MULTIBYTE_SPECIFIED_CODE_PAGE:
|
|
1774 return data->cp;
|
|
1775 case MULTIBYTE_SPECIFIED_LOCALE:
|
|
1776 locale = data->locale; break;
|
|
1777 case MULTIBYTE_CURRENT:
|
|
1778 locale = mswindows_current_locale (); break;
|
|
1779 case MULTIBYTE_USER_DEFAULT:
|
|
1780 locale = GetUserDefaultLCID (); break;
|
|
1781 case MULTIBYTE_SYSTEM_DEFAULT:
|
|
1782 locale = GetSystemDefaultLCID (); break;
|
|
1783 default:
|
|
1784 abort (); locale = 0;
|
|
1785 }
|
|
1786
|
|
1787 switch (data->cp_type)
|
|
1788 {
|
|
1789 case MULTIBYTE_ANSI:
|
|
1790 return mswindows_locale_to_code_page (locale);
|
|
1791 case MULTIBYTE_OEM:
|
|
1792 return mswindows_locale_to_oem_code_page (locale);
|
|
1793 case MULTIBYTE_EBCDIC:
|
|
1794 #ifdef LOCALE_IDEFAULTEBCDICCODEPAGE /* Doesn't exist under Cygwin */
|
|
1795 {
|
|
1796 char codepagestr[10];
|
|
1797 GetLocaleInfoA (locale, LOCALE_IDEFAULTEBCDICCODEPAGE, codepagestr,
|
|
1798 10);
|
|
1799 return atoi (codepagestr);
|
|
1800 }
|
|
1801 #else
|
|
1802 invalid_operation ("Unable to determine EBCDIC code page for locale",
|
|
1803 lcid_to_locale (locale));
|
|
1804 return 0;
|
|
1805 #endif
|
|
1806 case MULTIBYTE_MAC:
|
|
1807 #ifdef LOCALE_IDEFAULTMACCODEPAGE /* Doesn't exist under Cygwin */
|
|
1808 {
|
|
1809 char codepagestr[10];
|
|
1810 GetLocaleInfoA (locale, LOCALE_IDEFAULTMACCODEPAGE, codepagestr,
|
|
1811 10);
|
|
1812 return atoi (codepagestr);
|
|
1813 }
|
|
1814 #else
|
|
1815 invalid_operation ("Unable to determine Mac code page for locale",
|
|
1816 lcid_to_locale (locale));
|
|
1817 return 0;
|
|
1818 #endif
|
|
1819 default:
|
|
1820 abort (); return 0;
|
|
1821 }
|
|
1822 #else /* not MULE */
|
|
1823 return CP_ACP;
|
|
1824 #endif
|
|
1825 }
|
|
1826
|
|
1827 static int
|
|
1828 mswindows_multibyte_to_unicode_putprop (Lisp_Object codesys,
|
|
1829 Lisp_Object key,
|
|
1830 Lisp_Object value)
|
|
1831 {
|
|
1832 struct mswindows_multibyte_to_unicode_coding_system *data =
|
|
1833 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte_to_unicode);
|
|
1834
|
|
1835 if (EQ (key, Qcode_page))
|
|
1836 {
|
|
1837 if (EQ (value, Qansi))
|
|
1838 data->cp_type = MULTIBYTE_ANSI;
|
|
1839 else if (EQ (value, Qoem))
|
|
1840 data->cp_type = MULTIBYTE_OEM;
|
|
1841 else if (EQ (value, Qebcdic))
|
|
1842 data->cp_type = MULTIBYTE_EBCDIC;
|
|
1843 else if (EQ (value, Qmac))
|
|
1844 data->cp_type = MULTIBYTE_MAC;
|
|
1845 else
|
|
1846 {
|
|
1847 CHECK_NATNUM (value);
|
|
1848 data->locale_type = MULTIBYTE_SPECIFIED_CODE_PAGE;
|
|
1849 data->cp = XINT (value);
|
|
1850 }
|
|
1851 }
|
|
1852 else if (EQ (key, Qlocale))
|
|
1853 {
|
|
1854 if (EQ (value, Qcurrent))
|
|
1855 data->locale_type = MULTIBYTE_CURRENT;
|
|
1856 else if (EQ (value, Quser_default))
|
|
1857 data->locale_type = MULTIBYTE_USER_DEFAULT;
|
|
1858 else if (EQ (value, Qsystem_default))
|
|
1859 data->locale_type = MULTIBYTE_SYSTEM_DEFAULT;
|
|
1860 else
|
|
1861 {
|
|
1862 data->locale_type = MULTIBYTE_SPECIFIED_LOCALE;
|
|
1863 #ifdef MULE
|
|
1864 data->locale = locale_to_lcid (value);
|
|
1865 #else
|
|
1866 data->locale = 0;
|
|
1867 #endif
|
|
1868 }
|
|
1869 }
|
|
1870 else
|
|
1871 return 0;
|
|
1872 return 1;
|
|
1873 }
|
|
1874
|
|
1875 static Lisp_Object
|
|
1876 mswindows_multibyte_to_unicode_getprop (Lisp_Object coding_system,
|
|
1877 Lisp_Object prop)
|
|
1878 {
|
|
1879 struct mswindows_multibyte_to_unicode_coding_system *data =
|
|
1880 XCODING_SYSTEM_TYPE_DATA (coding_system, mswindows_multibyte_to_unicode);
|
|
1881
|
|
1882 if (EQ (prop, Qcode_page))
|
|
1883 {
|
|
1884 if (data->locale_type == MULTIBYTE_SPECIFIED_CODE_PAGE)
|
|
1885 return make_int (data->cp);
|
|
1886 else
|
|
1887 switch (data->cp_type)
|
|
1888 {
|
|
1889 case MULTIBYTE_ANSI: return Qansi;
|
|
1890 case MULTIBYTE_OEM: return Qoem;
|
|
1891 case MULTIBYTE_EBCDIC: return Qebcdic;
|
|
1892 case MULTIBYTE_MAC: return Qmac;
|
|
1893 default: abort ();
|
|
1894 }
|
|
1895 }
|
|
1896 else if (EQ (prop, Qlocale))
|
|
1897 {
|
|
1898 switch (data->locale_type)
|
|
1899 {
|
|
1900 case MULTIBYTE_CURRENT: return Qcurrent;
|
|
1901 case MULTIBYTE_USER_DEFAULT: return Quser_default;
|
|
1902 case MULTIBYTE_SYSTEM_DEFAULT: return Qsystem_default;
|
|
1903 case MULTIBYTE_SPECIFIED_LOCALE:
|
|
1904 return lcid_to_locale_mule_or_no (data->locale);
|
|
1905
|
|
1906 case MULTIBYTE_SPECIFIED_CODE_PAGE:
|
|
1907 return Qnil;
|
|
1908 default: abort ();
|
|
1909 }
|
|
1910 }
|
|
1911
|
|
1912 return Qunbound;
|
|
1913 }
|
|
1914
|
|
1915 static void
|
2286
|
1916 mswindows_multibyte_to_unicode_print (Lisp_Object cs, Lisp_Object printcharfun,
|
|
1917 int UNUSED (escapeflag))
|
771
|
1918 {
|
|
1919 struct mswindows_multibyte_to_unicode_coding_system *data =
|
|
1920 XCODING_SYSTEM_TYPE_DATA (cs, mswindows_multibyte_to_unicode);
|
|
1921
|
826
|
1922 write_c_string (printcharfun, "(");
|
771
|
1923 if (data->locale_type == MULTIBYTE_SPECIFIED_CODE_PAGE)
|
|
1924 print_internal (make_int (data->cp), printcharfun, 1);
|
|
1925 else
|
|
1926 {
|
800
|
1927 write_fmt_string_lisp (printcharfun, "%s, ", 1, mswindows_multibyte_to_unicode_getprop (cs, Qlocale));
|
|
1928 print_internal (mswindows_multibyte_to_unicode_getprop (cs, Qcode_page), printcharfun, 0);
|
771
|
1929 }
|
826
|
1930 write_c_string (printcharfun, ")");
|
771
|
1931 }
|
|
1932
|
|
1933 /* Convert multibyte to Unicode according to the specified code page
|
|
1934 and return the value as a malloc()ed string. This currently exists
|
|
1935 because the TO_INTERNAL_FORMAT() mechanism -- the normal way to do
|
|
1936 such conversions -- has no way of passing in a parameter to control
|
|
1937 the operation. We could use a global variable to pass this value
|
|
1938 in, but that runs the risk of causing problems due to reentrancy.
|
|
1939 (You might say, yeah, right, how can TO_INTERNAL_FORMAT() get
|
|
1940 called recursively merely when I'm doing a simple conversion
|
|
1941 operation? It turns out this can and does happen, consistently, as
|
|
1942 a result of calling QUIT -- it happens consistently for complicated
|
|
1943 reasons outlined in event-msw.c, WM_KEYDOWN handling.) */
|
|
1944
|
|
1945 Extbyte *
|
|
1946 convert_multibyte_to_unicode_malloc (const Extbyte *src, Bytecount n,
|
|
1947 int cp, Bytecount *size_out)
|
|
1948 {
|
|
1949 Bytecount nout = MultiByteToWideChar (cp, 0, src, n, 0, 0);
|
|
1950 Extbyte *outp = xnew_array (Extbyte, nout * sizeof (WCHAR));
|
|
1951
|
|
1952 MultiByteToWideChar (cp, 0, src, n, (LPWSTR) outp, nout);
|
|
1953 if (size_out)
|
|
1954 *size_out = nout * sizeof (WCHAR);
|
|
1955 return outp;
|
|
1956 }
|
|
1957
|
|
1958 /* Convert MS Windows multibyte to internal, with specified code page.
|
|
1959 See above for why this exists, and the TO_INTERNAL_FORMAT() macros
|
|
1960 aren't just used. */
|
|
1961
|
867
|
1962 Ibyte *
|
771
|
1963 convert_multibyte_to_internal_malloc (const Extbyte *src, Bytecount n,
|
|
1964 int cp, Bytecount *size_out)
|
|
1965 {
|
|
1966 Bytecount size;
|
|
1967 Extbyte *unidata = convert_multibyte_to_unicode_malloc (src, n, cp, &size);
|
867
|
1968 Ibyte *intdata;
|
771
|
1969
|
|
1970 TO_INTERNAL_FORMAT (DATA, (unidata, size), MALLOC, (intdata, size),
|
|
1971 Qmswindows_unicode);
|
|
1972
|
1726
|
1973 xfree (unidata, Extbyte *);
|
771
|
1974
|
|
1975 if (size_out)
|
|
1976 *size_out = size;
|
|
1977
|
|
1978 return intdata;
|
|
1979 }
|
|
1980
|
|
1981 /* Convert multibyte to Unicode according to the specified code page
|
|
1982 and append the results onto the specified Dynarr. See above. */
|
|
1983
|
|
1984 void
|
|
1985 convert_multibyte_to_unicode_dynarr (const Extbyte *src, Bytecount n,
|
|
1986 int cp, unsigned_char_dynarr *dst)
|
|
1987 {
|
|
1988 Bytecount nout = MultiByteToWideChar (cp, 0, src, n, 0, 0);
|
|
1989 void *outp;
|
|
1990
|
|
1991 Dynarr_add_many (dst, 0, nout * sizeof (WCHAR));
|
|
1992 /* dynarr's buffer may be realloc()ed by call above, so access it after */
|
|
1993 outp = Dynarr_atp (dst, Dynarr_length (dst) - nout * sizeof (WCHAR));
|
|
1994 MultiByteToWideChar (cp, 0, src, n, (LPWSTR) outp, nout);
|
|
1995 }
|
|
1996
|
|
1997 /* Convert MS Windows multibyte to Unicode. */
|
|
1998
|
|
1999 static Bytecount
|
|
2000 mswindows_multibyte_to_unicode_convert (struct coding_stream *str,
|
|
2001 const unsigned char *src,
|
|
2002 unsigned_char_dynarr *dst,
|
|
2003 Bytecount n)
|
|
2004 {
|
|
2005 unsigned char *new_src = (unsigned char *) src;
|
|
2006 int i;
|
|
2007 struct mswindows_multibyte_to_unicode_coding_stream *data =
|
|
2008 CODING_STREAM_TYPE_DATA (str, mswindows_multibyte_to_unicode);
|
|
2009 Bytecount orign = n;
|
|
2010
|
|
2011 if (data->cp == 0)
|
|
2012 data->cp = determine_code_page (str->codesys);
|
|
2013 if (data->partial_byte_present)
|
|
2014 {
|
|
2015 new_src = alloca_array (unsigned char, n + 1);
|
|
2016 memcpy (new_src + 1, src, n);
|
|
2017 new_src[0] =
|
|
2018 (unsigned char) data->partial_byte;
|
|
2019 n++;
|
|
2020 }
|
|
2021
|
|
2022 if (str->direction == CODING_DECODE)
|
|
2023 {
|
|
2024 for (i = n - 1; i >= 0; i--)
|
|
2025 {
|
|
2026 if (!IsDBCSLeadByteEx (data->cp, new_src[i]))
|
|
2027 break;
|
|
2028 }
|
|
2029
|
|
2030 i++;
|
|
2031
|
|
2032 for (; i < n; i++)
|
|
2033 {
|
|
2034 if (IsDBCSLeadByteEx (data->cp, new_src[i]))
|
|
2035 i++;
|
|
2036 }
|
|
2037
|
|
2038 if (i > n)
|
|
2039 {
|
|
2040 /* a char is split across the boundary */
|
|
2041 data->partial_byte = new_src[n - 1];
|
|
2042 data->partial_byte_present = 1;
|
|
2043 n--;
|
|
2044 }
|
|
2045 else
|
|
2046 data->partial_byte_present = 0;
|
|
2047
|
|
2048 convert_multibyte_to_unicode_dynarr ((Extbyte *) new_src, n, data->cp,
|
|
2049 dst);
|
|
2050 }
|
|
2051 else
|
|
2052 {
|
|
2053 if (n & 1)
|
|
2054 {
|
|
2055 /* a char is split across the boundary */
|
|
2056 data->partial_byte = new_src[n - 1];
|
|
2057 data->partial_byte_present = 1;
|
|
2058 n--;
|
|
2059 }
|
|
2060 else
|
|
2061 data->partial_byte_present = 0;
|
|
2062
|
|
2063 {
|
|
2064 int nout = WideCharToMultiByte (data->cp, WC_COMPOSITECHECK,
|
|
2065 (LPWSTR) new_src, n / sizeof (WCHAR),
|
|
2066 0, 0, "~", 0);
|
|
2067 void *outp;
|
|
2068
|
|
2069 Dynarr_add_many (dst, 0, nout);
|
|
2070 /* dynarr's buffer may be realloc()ed by call above, so access it
|
|
2071 after */
|
|
2072 outp = Dynarr_atp (dst, Dynarr_length (dst) - nout);
|
|
2073 WideCharToMultiByte (data->cp, WC_COMPOSITECHECK, (LPWSTR) new_src,
|
|
2074 n / sizeof (WCHAR),
|
|
2075 (LPSTR) outp, nout, "~", 0);
|
|
2076 }
|
|
2077 }
|
|
2078 return orign;
|
|
2079 }
|
|
2080
|
|
2081 static enum source_sink_type
|
2286
|
2082 mswindows_multibyte_to_unicode_conversion_end_type (Lisp_Object UNUSED (codesys))
|
771
|
2083 {
|
|
2084 return DECODES_BYTE_TO_BYTE;
|
|
2085 }
|
|
2086
|
|
2087
|
|
2088 /************************************************************************/
|
|
2089 /* MS Windows Multibyte methods */
|
|
2090 /************************************************************************/
|
|
2091
|
|
2092 struct mswindows_multibyte_coding_system
|
|
2093 {
|
|
2094 Lisp_Object code_page;
|
|
2095 Lisp_Object locale;
|
|
2096 };
|
|
2097
|
|
2098 struct mswindows_multibyte_coding_stream
|
|
2099 {
|
|
2100 int dummy;
|
|
2101 };
|
|
2102
|
1204
|
2103 static const struct memory_description
|
771
|
2104 mswindows_multibyte_coding_system_description[] = {
|
|
2105 { XD_LISP_OBJECT,
|
1204
|
2106 offsetof (struct mswindows_multibyte_coding_system, code_page) },
|
771
|
2107 { XD_LISP_OBJECT,
|
1204
|
2108 offsetof (struct mswindows_multibyte_coding_system, locale) },
|
771
|
2109 { XD_END }
|
|
2110 };
|
|
2111
|
1204
|
2112 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (mswindows_multibyte);
|
|
2113
|
771
|
2114 static Bytecount
|
2286
|
2115 mswindows_multibyte_convert (struct coding_stream *UNUSED (str),
|
|
2116 const UExtbyte *UNUSED (src),
|
|
2117 unsigned_char_dynarr *UNUSED (dst), Bytecount n)
|
771
|
2118 {
|
|
2119 Bytecount orign = n;
|
|
2120 /* should never be called; is preprocessed away in the
|
|
2121 canonicalize method */
|
|
2122 abort ();
|
|
2123 return orign;
|
|
2124 }
|
|
2125
|
|
2126 static void
|
|
2127 mswindows_multibyte_init (Lisp_Object codesys)
|
|
2128 {
|
|
2129 struct mswindows_multibyte_coding_system *data =
|
|
2130 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte);
|
|
2131
|
|
2132 data->code_page = Qnil;
|
|
2133 data->locale = Qnil;
|
|
2134 }
|
|
2135
|
|
2136 static void
|
|
2137 mswindows_multibyte_mark (Lisp_Object codesys)
|
|
2138 {
|
|
2139 struct mswindows_multibyte_coding_system *data =
|
|
2140 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte);
|
|
2141
|
|
2142 mark_object (data->code_page);
|
|
2143 mark_object (data->locale);
|
|
2144 }
|
|
2145
|
|
2146 static int
|
|
2147 mswindows_multibyte_putprop (Lisp_Object codesys,
|
|
2148 Lisp_Object key,
|
|
2149 Lisp_Object value)
|
|
2150 {
|
|
2151 struct mswindows_multibyte_coding_system *data =
|
|
2152 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte);
|
|
2153
|
|
2154 if (EQ (key, Qcode_page))
|
|
2155 data->code_page = value;
|
|
2156 else if (EQ (key, Qlocale))
|
|
2157 data->locale = value;
|
|
2158 else
|
|
2159 return 0;
|
|
2160 return 1;
|
|
2161 }
|
|
2162
|
|
2163 static Lisp_Object
|
|
2164 mswindows_multibyte_getprop (Lisp_Object coding_system,
|
|
2165 Lisp_Object prop)
|
|
2166 {
|
|
2167 struct mswindows_multibyte_coding_system *data =
|
|
2168 XCODING_SYSTEM_TYPE_DATA (coding_system, mswindows_multibyte);
|
|
2169
|
|
2170 if (EQ (prop, Qcode_page))
|
|
2171 return data->code_page;
|
|
2172 else if (EQ (prop, Qlocale))
|
|
2173 return data->locale;
|
|
2174 else
|
|
2175 return Qunbound;
|
|
2176 }
|
|
2177
|
|
2178 /* Convert this coding system into the proper chain. */
|
|
2179
|
|
2180 static Lisp_Object
|
|
2181 mswindows_multibyte_canonicalize (Lisp_Object codesys)
|
|
2182 {
|
|
2183 struct mswindows_multibyte_coding_system *data =
|
|
2184 XCODING_SYSTEM_TYPE_DATA (codesys, mswindows_multibyte);
|
|
2185 Lisp_Object m2u;
|
|
2186
|
|
2187 m2u =
|
|
2188 make_internal_coding_system
|
|
2189 (Qnil,
|
|
2190 "internal-mswindows-multibyte-to-unicode",
|
|
2191 Qmswindows_multibyte_to_unicode,
|
|
2192 Qnil, NILP (data->locale) ?
|
|
2193 list2 (Qcode_page, data->code_page) :
|
|
2194 list4 (Qcode_page, data->code_page, Qlocale, data->locale));
|
|
2195
|
|
2196 return make_internal_coding_system (codesys,
|
|
2197 "internal-mswindows-multibyte-chain",
|
|
2198 Qchain, Qunbound,
|
|
2199 list4 (Qchain,
|
|
2200 list2 (m2u, Qmswindows_unicode),
|
|
2201 Qcanonicalize_after_coding,
|
|
2202 codesys));
|
|
2203 }
|
|
2204
|
|
2205
|
|
2206 void
|
|
2207 syms_of_intl_win32 (void)
|
|
2208 {
|
|
2209 #ifdef MULE
|
|
2210 DEFSUBR (Fmswindows_set_current_locale);
|
|
2211 DEFSUBR (Fmswindows_current_locale);
|
|
2212 DEFSUBR (Fmswindows_user_default_locale);
|
|
2213 DEFSUBR (Fmswindows_system_default_locale);
|
|
2214 DEFSUBR (Fmswindows_locale_code_page);
|
|
2215 DEFSUBR (Fmswindows_locale_oem_code_page);
|
|
2216 DEFSUBR (Fmswindows_supported_locales);
|
|
2217 DEFSUBR (Fmswindows_charset_code_page);
|
|
2218 DEFSUBR (Fmswindows_set_charset_code_page);
|
872
|
2219 DEFSUBR (Fmswindows_charset_registry);
|
|
2220 DEFSUBR (Fmswindows_set_charset_registry);
|
771
|
2221
|
|
2222 #if 0
|
|
2223 DEFSUBR (Fmswindows_get_locale_info);
|
|
2224 DEFSUBR (Fmswindows_get_current_locale_id);
|
|
2225 DEFSUBR (Fmswindows_get_default_locale_id);
|
|
2226 DEFSUBR (Fmswindows_get_valid_locale_ids);
|
|
2227 DEFSUBR (Fmswindows_set_current_locale);
|
|
2228
|
|
2229 DEFSUBR (Fmswindows_get_console_code_page);
|
|
2230 DEFSUBR (Fmswindows_set_console_code_page);
|
|
2231 DEFSUBR (Fmswindows_get_console_output_code_page);
|
|
2232 DEFSUBR (Fmswindows_set_console_output_code_page);
|
|
2233 DEFSUBR (Fmswindows_get_valid_code_pages);
|
|
2234 DEFSUBR (Fmswindows_get_code_page_charset);
|
|
2235
|
|
2236 DEFSUBR (Fmswindows_get_valid_keyboard_layouts);
|
|
2237 DEFSUBR (Fmswindows_get_keyboard_layout);
|
|
2238 DEFSUBR (Fmswindows_set_keyboard_layout);
|
|
2239 #endif
|
|
2240 #endif /* MULE */
|
|
2241
|
|
2242 DEFSYMBOL (Qmswindows_tstr);
|
|
2243 DEFSYMBOL (Qmswindows_multibyte);
|
|
2244 DEFSYMBOL (Qmswindows_multibyte_to_unicode);
|
|
2245 DEFSYMBOL (Qmswindows_unicode);
|
|
2246 DEFSYMBOL (Qmswindows_multibyte_system_default);
|
|
2247
|
|
2248 DEFSYMBOL (Qansi);
|
|
2249 DEFSYMBOL (Qoem);
|
|
2250 DEFSYMBOL (Qmac);
|
|
2251 DEFSYMBOL (Qebcdic);
|
|
2252 }
|
|
2253
|
|
2254 void
|
|
2255 coding_system_type_create_intl_win32 (void)
|
|
2256 {
|
|
2257 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA
|
|
2258 (mswindows_multibyte_to_unicode,
|
|
2259 "mswindows-multibyte-to-unicode-coding-system-p");
|
|
2260 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte_to_unicode, init);
|
|
2261 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte_to_unicode, print);
|
|
2262 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte_to_unicode, convert);
|
|
2263 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte_to_unicode, getprop);
|
|
2264 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte_to_unicode, putprop);
|
|
2265 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte_to_unicode,
|
|
2266 conversion_end_type);
|
|
2267
|
|
2268 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA
|
|
2269 (mswindows_multibyte,
|
|
2270 "mswindows-multibyte-coding-system-p");
|
|
2271 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte, convert);
|
|
2272 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte, init);
|
|
2273 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte, mark);
|
|
2274 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte, getprop);
|
|
2275 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte, putprop);
|
|
2276 CODING_SYSTEM_HAS_METHOD (mswindows_multibyte, canonicalize);
|
|
2277 }
|
|
2278
|
|
2279 void
|
|
2280 reinit_coding_system_type_create_intl_win32 (void)
|
|
2281 {
|
|
2282 REINITIALIZE_CODING_SYSTEM_TYPE (mswindows_multibyte_to_unicode);
|
|
2283 REINITIALIZE_CODING_SYSTEM_TYPE (mswindows_multibyte);
|
|
2284 }
|
|
2285
|
|
2286 void
|
|
2287 vars_of_intl_win32 (void)
|
|
2288 {
|
|
2289 #ifdef MULE
|
|
2290 Vmswindows_charset_code_page_table =
|
|
2291 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
2292 staticpro (&Vmswindows_charset_code_page_table);
|
872
|
2293 Vmswindows_charset_registry_table =
|
|
2294 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
2295 staticpro (&Vmswindows_charset_registry_table);
|
771
|
2296 #endif /* MULE */
|
|
2297 }
|
|
2298
|
|
2299 static void
|
|
2300 determine_if_using_unicode (void)
|
|
2301 {
|
|
2302 if (XEUNICODE_P)
|
|
2303 Fdefine_coding_system_alias (Qmswindows_tstr, Qmswindows_unicode);
|
|
2304 else
|
|
2305 Fdefine_coding_system_alias (Qmswindows_tstr,
|
|
2306 Qmswindows_multibyte_system_default);
|
|
2307 }
|
|
2308
|
|
2309 void
|
|
2310 complex_vars_of_intl_win32 (void)
|
|
2311 {
|
|
2312 Fmake_coding_system
|
|
2313 (Qmswindows_unicode, Qunicode,
|
|
2314 build_msg_string ("MS Windows Unicode"),
|
|
2315 nconc2 (list4 (Qdocumentation,
|
|
2316 build_msg_string (
|
|
2317 "Converts to the Unicode encoding for Windows API calls.\n"
|
|
2318 "This encoding is equivalent to standard UTF16, little-endian."
|
|
2319 ),
|
|
2320 Qmnemonic, build_string ("MSW-U")),
|
|
2321 list4 (Qtype, Qutf_16,
|
|
2322 Qlittle_endian, Qt)));
|
|
2323
|
|
2324 #ifdef MULE
|
|
2325 /* Just temporarily. This will get fixed in mule-msw-init.el. */
|
|
2326 Fdefine_coding_system_alias (Qmswindows_multibyte_system_default,
|
|
2327 Qraw_text);
|
|
2328 #else
|
|
2329 /* Not temporarily. These may be referenced by Lisp code so we need to
|
|
2330 define them. */
|
|
2331 Fdefine_coding_system_alias (Qmswindows_multibyte,
|
|
2332 Qraw_text);
|
|
2333 Fdefine_coding_system_alias (Qmswindows_multibyte_system_default,
|
|
2334 Qraw_text);
|
|
2335 Fdefine_coding_system_alias (intern ("mswindows-multibyte-user-default"),
|
|
2336 Qraw_text);
|
|
2337 Fdefine_coding_system_alias (intern ("mswindows-multibyte-oem"),
|
|
2338 Qraw_text);
|
|
2339 Fdefine_coding_system_alias (intern
|
|
2340 ("mswindows-multibyte-oem-system-default"),
|
|
2341 Qraw_text);
|
|
2342 Fdefine_coding_system_alias (intern ("mswindows-multibyte-oem-user-default"),
|
|
2343 Qraw_text);
|
|
2344 #endif /* MULE */
|
|
2345
|
|
2346 determine_if_using_unicode ();
|
|
2347 }
|
|
2348
|
|
2349 void
|
|
2350 init_intl_win32 (void)
|
|
2351 {
|
|
2352 #ifdef MULE
|
|
2353 set_current_lcid (GetUserDefaultLCID ());
|
|
2354 #endif /* MULE */
|
|
2355
|
|
2356 if (initialized)
|
|
2357 /* If not initialized, we also call this, but early -- see the
|
|
2358 previous function. */
|
|
2359 determine_if_using_unicode ();
|
|
2360 }
|