2 Simple DirectMedia Layer
3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
23 #define INCL_DOSERRORS
30 typedef struct _CP2NAME {
35 typedef struct _NAME2CP {
40 static CP2NAME aCP2Name[] = {
41 {367, "ANSI_X3.4-1968"},
49 {896, "JISX0201-1976"},
65 {1200, "ISO-10646-UCS-2"},
71 {1236, "ISO-10646-UCS-4"},
87 static NAME2CP aName2CP[] = {
91 {"ANSI_X3.4-1968", 367},
92 {"ANSI_X3.4-1986", 367},
113 {"CSEUCPKDFMTJAPANESE", 954},
116 {"CSHALFWIDTHKATAKANA", 896},
117 {"CSHPROMAN8", 1051},
119 {"CSISOLATIN1", 819},
120 {"CSISOLATIN2", 912},
121 {"CSISOLATIN3", 913},
122 {"CSISOLATIN4", 914},
123 {"CSISOLATIN5", 920},
124 {"CSISOLATINARABIC", 1089},
125 {"CSISOLATINCYRILLIC", 915},
126 {"CSISOLATINGREEK", 813},
127 {"CSISOLATINHEBREW", 62210},
129 {"CSKSC56011987", 970},
130 {"CSMACINTOSH", 1275},
131 {"CSPC850MULTILINGUAL", 850},
132 {"CSPC862LATINHEBREW", 862},
136 {"CSUNICODE11", 1204},
150 {"EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE", 954},
163 {"ISO-10646-UCS-2", 1200},
164 {"ISO-10646-UCS-4", 1236},
166 {"ISO-8859-13", 901},
167 {"ISO-8859-15", 923},
172 {"ISO-8859-6", 1089},
174 {"ISO-8859-8", 62210},
181 {"ISO-IR-127", 1089},
182 {"ISO-IR-138", 62210},
200 {"ISO8859-8", 62210},
202 {"ISO_646.IRV:1991", 367},
204 {"ISO_8859-13", 901},
205 {"ISO_8859-15", 923},
206 {"ISO_8859-15:1998", 923},
207 {"ISO_8859-1:1987", 819},
209 {"ISO_8859-2:1987", 912},
211 {"ISO_8859-3:1988", 913},
213 {"ISO_8859-4:1988", 914},
215 {"ISO_8859-5:1988", 915},
216 {"ISO_8859-6", 1089},
217 {"ISO_8859-6:1987", 1089},
219 {"ISO_8859-7:1987", 813},
220 {"ISO_8859-7:2003", 813},
221 {"ISO_8859-8", 62210},
222 {"ISO_8859-8:1988", 62210},
224 {"ISO_8859-9:1989", 920},
225 {"JISX0201-1976", 896},
231 {"KS_C_5601-1987", 970},
232 {"KS_C_5601-1989", 970},
266 {"TIS620.2529-1", 874},
267 {"TIS620.2533-0", 874},
268 {"TIS620.2533-1", 874},
272 {"UNICODE-1-1", 1204},
273 {"UNICODEBIG", 1204},
284 {"VISCII1.1-1", 1129},
285 {"WINBALTRIM", 1257},
286 {"WINDOWS-1250", 1250},
287 {"WINDOWS-1251", 1251},
288 {"WINDOWS-1252", 1252},
289 {"WINDOWS-1253", 1253},
290 {"WINDOWS-1254", 1254},
291 {"WINDOWS-1255", 1255},
292 {"WINDOWS-1256", 1256},
293 {"WINDOWS-1257", 1257},
294 {"WINDOWS-936", 1386},
298 char *os2cpToName(unsigned long cp)
301 ULONG ulHi = (sizeof(aCP2Name) / sizeof(struct _CP2NAME)) - 1;
305 if (cp == SYSTEM_CP) {
309 if (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)
315 if (aCP2Name[0].ulCode > cp || aCP2Name[ulHi].ulCode < cp)
318 if (aCP2Name[0].ulCode == cp)
319 return aCP2Name[0].pszName;
321 if (aCP2Name[ulHi].ulCode == cp)
322 return aCP2Name[ulHi].pszName;
324 while ((ulHi - ulLo) > 1) {
325 ulNext = (ulLo + ulHi) / 2;
327 if (aCP2Name[ulNext].ulCode < cp)
329 else if (aCP2Name[ulNext].ulCode > cp)
337 return (lFound == -1)? NULL : aCP2Name[lFound].pszName;
340 unsigned long os2cpFromName(char *cp)
343 ULONG ulHi = (sizeof(aName2CP) / sizeof(struct _NAME2CP)) - 1;
354 return (DosQueryCp(sizeof(aulCP), aulCP, &cCP) != NO_ERROR)? 0 : aulCP[0];
360 pcEnd = strchr(cp, ' ');
362 pcEnd = strchr(cp, '\0');
365 if (ulNext >= sizeof(acBuf))
368 memcpy(acBuf, cp, ulNext);
369 acBuf[ulNext] = '\0';
372 lCmp = strcmp(aName2CP[0].pszName, acBuf);
376 return aName2CP[0].ulCode;
378 lCmp = strcmp(aName2CP[ulHi].pszName, acBuf);
382 return aName2CP[ulHi].ulCode;
384 while ((ulHi - ulLo) > 1) {
385 ulNext = (ulLo + ulHi) / 2;
387 lCmp = strcmp(aName2CP[ulNext].pszName, acBuf);
398 return (lFound == -1)? 0 : aName2CP[lFound].ulCode;
401 /* vi: set ts=4 sw=4 expandtab: */