Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

743 lines
19 KiB

  1. /**************************************************************************\
  2. * Module Name: kcodecnv.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This module contains all the code for the Korean code conversion functions.
  7. *
  8. * History:
  9. * 15-Jul-1995
  10. * 22-Feb-1996 bklee
  11. \**************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #define IDD_2BEOL 100
  15. #define IDD_3BEOL1 101
  16. #define IDD_3BEOL2 102
  17. #define lpSource(lpks) (LPSTR)((LPSTR)lpks+lpks->dchSource)
  18. #define lpDest(lpks) (LPSTR)((LPSTR)lpks+lpks->dchDest)
  19. #define JOHAB_CP 1361
  20. #define WANSUNG_CP 949
  21. #define TWO_BYTE 2
  22. #define ONE_WORD 1
  23. typedef struct tagHIGH_LOW // For high byte and low byte
  24. {
  25. BYTE low, high;
  26. } HIGH_LOW;
  27. typedef union tagWANSUNG // For Wansung character code
  28. {
  29. HIGH_LOW e;
  30. WORD w;
  31. } WANSUNG;
  32. /* Hanguel Mnemonic Table for 2 BeolSik and 3 BeolSik */
  33. CONST WORD HMNTable[3][96] =
  34. {
  35. // For 2 Beolsik.
  36. {
  37. /* 20 SP */ 0xA1A1,
  38. /* 21 ! */ 0xA3A1,
  39. /* 22 " */ 0xA1A8,
  40. /* 23 # */ 0xA3A3,
  41. /* 24 $ */ 0xA3A4,
  42. /* 25 % */ 0xA3A5,
  43. /* 26 & */ 0xA3A6,
  44. /* 27 ` */ 0xA1AE, /* A1AE ? AiA2 */
  45. /* 28 ( */ 0xA3A8,
  46. /* 29 ) */ 0xA3A9,
  47. /* 2A * */ 0xA3AA,
  48. /* 2B + */ 0xA3AB,
  49. /* 2C ' */ 0xA3A7,
  50. /* 2D - */ 0xA3AD,
  51. /* 2E . */ 0xA3AE,
  52. /* 2F / */ 0xA3AF,
  53. /* 30 0 */ 0xA3B0,
  54. /* 31 1 */ 0xA3B1,
  55. /* 32 2 */ 0xA3B2,
  56. /* 33 3 */ 0xA3B3,
  57. /* 34 4 */ 0xA3B4,
  58. /* 35 5 */ 0xA3B5,
  59. /* 36 6 */ 0xA3B6,
  60. /* 37 7 */ 0xA3B7,
  61. /* 38 8 */ 0xA3B8,
  62. /* 39 9 */ 0xA3B9,
  63. /* 3A : */ 0xA3BA,
  64. /* 3B ; */ 0xA3BB,
  65. /* 3C < */ 0xA3BC,
  66. /* 3D = */ 0xA3BD,
  67. /* 3E > */ 0xA3BE,
  68. /* 3F ? */ 0xA3BF,
  69. /* 40 @ */ 0xA3C0,
  70. /* 41 A */ 0xA4B1,
  71. /* 42 B */ 0xA4D0,
  72. /* 43 C */ 0xA4BA,
  73. /* 44 D */ 0xA4B7,
  74. /* 45 E */ 0xA4A8,
  75. /* 46 F */ 0xA4A9,
  76. /* 47 G */ 0xA4BE,
  77. /* 48 H */ 0xA4C7,
  78. /* 49 I */ 0xA4C1,
  79. /* 4A J */ 0xA4C3,
  80. /* 4B K */ 0xA4BF,
  81. /* 4C L */ 0xA4D3,
  82. /* 4D M */ 0xA4D1,
  83. /* 4E N */ 0xA4CC,
  84. /* 4F O */ 0xA4C2,
  85. /* 50 P */ 0xA4C6,
  86. /* 51 Q */ 0xA4B3,
  87. /* 52 R */ 0xA4A2,
  88. /* 53 S */ 0xA4A4,
  89. /* 54 T */ 0xA4B6,
  90. /* 55 U */ 0xA4C5,
  91. /* 56 V */ 0xA4BD,
  92. /* 57 W */ 0xA4B9,
  93. /* 58 X */ 0xA4BC,
  94. /* 59 Y */ 0xA4CB,
  95. /* 5A Z */ 0xA4BB,
  96. /* 5B [ */ 0xA3DB,
  97. /* 5C \ */ 0xA1AC,
  98. /* 5D ] */ 0xA3DD,
  99. /* 5E ^ */ 0xA3DE,
  100. /* 5F _ */ 0xA3DF,
  101. /* 60 ` */ 0xA1A2, /* A1AE ? AiA2 */
  102. /* 61 a */ 0xA4B1,
  103. /* 62 b */ 0xA4D0,
  104. /* 63 c */ 0xA4BA,
  105. /* 64 d */ 0xA4B7,
  106. /* 65 e */ 0xA4A7,
  107. /* 66 f */ 0xA4A9,
  108. /* 67 g */ 0xA4BE,
  109. /* 68 h */ 0xA4C7,
  110. /* 69 i */ 0xA4C1,
  111. /* 6A j */ 0xA4C3,
  112. /* 6B k */ 0xA4BF,
  113. /* 6C l */ 0xA4D3,
  114. /* 6D m */ 0xA4D1,
  115. /* 6E n */ 0xA4CC,
  116. /* 6F o */ 0xA4C0,
  117. /* 70 p */ 0xA4C4,
  118. /* 71 q */ 0xA4B2,
  119. /* 72 r */ 0xA4A1,
  120. /* 73 s */ 0xA4A4,
  121. /* 74 t */ 0xA4B5,
  122. /* 75 u */ 0xA4C5,
  123. /* 76 v */ 0xA4BD,
  124. /* 77 w */ 0xA4B8,
  125. /* 78 x */ 0xA4BC,
  126. /* 79 y */ 0xA4CB,
  127. /* 7A z */ 0xA4BB,
  128. /* 7B { */ 0xA3FB,
  129. /* 7C | */ 0xA3FC,
  130. /* 7D } */ 0xA3FD,
  131. /* 7E ~ */ 0xA1AD,
  132. 0x0000
  133. },
  134. // For KT390.
  135. {
  136. /* Hex Code KSC Code */
  137. /* 20 SP */ 0xA1A1,
  138. /* 21 ! */ 0xA4B8,
  139. /* 22 " */ 0xA1A8,
  140. /* 23 # */ 0xA3A3,
  141. /* 24 $ */ 0xA3A4,
  142. /* 25 % */ 0xA3A5,
  143. /* 26 & */ 0xA3A6,
  144. /* 27 ` */ 0xA1AE,
  145. /* 28 ( */ 0xA3A8,
  146. /* 29 ) */ 0xA3A9,
  147. /* 2A * */ 0xA3AA,
  148. /* 2B + */ 0xA3AB,
  149. /* 2C ' */ 0xA4BC,
  150. /* 2D - */ 0xA3AD,
  151. /* 2E . */ 0xA3AE,
  152. /* 2F / */ 0xA4C7,
  153. /* 30 0 */ 0xA4BB,
  154. /* 31 1 */ 0xA4BE,
  155. /* 32 2 */ 0xA4B6,
  156. /* 33 3 */ 0xA4B2,
  157. /* 34 4 */ 0xA4CB,
  158. /* 35 5 */ 0xA4D0,
  159. /* 36 6 */ 0xA4C1,
  160. /* 37 7 */ 0xA4C6,
  161. /* 38 8 */ 0xA4D2,
  162. /* 39 9 */ 0xA4CC,
  163. /* 3A : */ 0xA3BA,
  164. /* 3B ; */ 0xA4B2,
  165. /* 3C < */ 0xA3B2,
  166. /* 3D = */ 0xA3BD,
  167. /* 3E > */ 0xA3B3,
  168. /* 3F ? */ 0xA3BF,
  169. /* 40 @ */ 0xA3C0,
  170. /* 41 A */ 0xA4A7,
  171. /* 42 B */ 0xA3A1,
  172. /* 43 C */ 0xA4AB,
  173. /* 44 D */ 0xA4AA,
  174. /* 45 E */ 0xA4BB,
  175. /* 46 F */ 0xA4A2,
  176. /* 47 G */ 0xA3AF,
  177. /* 48 H */ 0xA1AF,
  178. /* 49 I */ 0xA3B8,
  179. /* 4A J */ 0xA3B4,
  180. /* 4B K */ 0xA3B5,
  181. /* 4C L */ 0xA3B6,
  182. /* 4D M */ 0xA3B1,
  183. /* 4E N */ 0xA3B0,
  184. /* 4F O */ 0xA3B9,
  185. /* 50 P */ 0xA3BE,
  186. /* 51 Q */ 0xA4BD,
  187. /* 52 R */ 0xA4C2,
  188. /* 53 S */ 0xA4A6,
  189. /* 54 T */ 0xA4C3,
  190. /* 55 U */ 0xA3B7,
  191. /* 56 V */ 0xA4B0,
  192. /* 57 W */ 0xA4BC,
  193. /* 58 X */ 0xA4B4,
  194. /* 59 Y */ 0xA3BC,
  195. /* 5A Z */ 0xA4BA,
  196. /* 5B [ */ 0xA3DB,
  197. /* 5C \ */ 0xA3DC,
  198. /* 5D ] */ 0xA3DD,
  199. /* 5E ^ */ 0xA3DE,
  200. /* 5F _ */ 0xA3DF,
  201. /* 60 ` */ 0xA1AE,
  202. /* 61 a */ 0xA4B7,
  203. /* 62 b */ 0xA4CC,
  204. /* 63 c */ 0xA4C4,
  205. /* 64 d */ 0xA4D3,
  206. /* 65 e */ 0xA4C5,
  207. /* 66 f */ 0xA4BF,
  208. /* 67 g */ 0xA4D1,
  209. /* 68 h */ 0xA4A4,
  210. /* 69 i */ 0xA4B1,
  211. /* 6A j */ 0xA4B7,
  212. /* 6B k */ 0xA4A1,
  213. /* 6C l */ 0xA4B8,
  214. /* 6D m */ 0xA4BE,
  215. /* 6E n */ 0xA4B5,
  216. /* 6F o */ 0xA4BA,
  217. /* 70 p */ 0xA4BD,
  218. /* 71 q */ 0xA4B5,
  219. /* 72 r */ 0xA4C0,
  220. /* 73 s */ 0xA4A4,
  221. /* 74 t */ 0xA4C3,
  222. /* 75 u */ 0xA4A7,
  223. /* 76 v */ 0xA4C7,
  224. /* 77 w */ 0xA4A9,
  225. /* 78 x */ 0xA4A1,
  226. /* 79 y */ 0xA4A9,
  227. /* 7A z */ 0xA4B1,
  228. /* 7B { */ 0xA3FB,
  229. /* 7C | */ 0xA3FC,
  230. /* 7D } */ 0xA3FD,
  231. /* 7E ~ */ 0xA1AD,
  232. 0x0000
  233. },
  234. // For 3 Beolsik Final.
  235. {
  236. /* Hex Code KSC Code */
  237. /* 20 SP */ 0xA1A1,
  238. /* 21 ! */ 0xA4A2,
  239. /* 22 " */ 0xA3AE,
  240. /* 23 # */ 0xA4B8,
  241. /* 24 $ */ 0xA4AF,
  242. /* 25 % */ 0xA4AE,
  243. /* 26 & */ 0xA1B0,
  244. /* 27 ` */ 0xA3AA,
  245. /* 28 ( */ 0xA1A2,
  246. /* 29 ) */ 0xA1AD,
  247. /* 2A * */ 0xA1B1,
  248. /* 2B + */ 0xA3AB,
  249. /* 2C ' */ 0xA4BC,
  250. /* 2D - */ 0xA3A9,
  251. /* 2E . */ 0xA3AE,
  252. /* 2F / */ 0xA4C7,
  253. /* 30 0 */ 0xA4BB,
  254. /* 31 1 */ 0xA4BE,
  255. /* 32 2 */ 0xA4B6,
  256. /* 33 3 */ 0xA4B2,
  257. /* 34 4 */ 0xA4CB,
  258. /* 35 5 */ 0xA4D0,
  259. /* 36 6 */ 0xA4C1,
  260. /* 37 7 */ 0xA4C6,
  261. /* 38 8 */ 0xA4D2,
  262. /* 39 9 */ 0xA4CC, //0x0000
  263. /* 3A : */ 0xA3B4,
  264. /* 3B ; */ 0xA4B2,
  265. /* 3C < */ 0xA3A7,
  266. /* 3D = */ 0xA1B5,
  267. /* 3E > */ 0xA3AE,
  268. /* 3F ? */ 0xA3A1,
  269. /* 40 @ */ 0xA4AA,
  270. /* 41 A */ 0xA4A7,
  271. /* 42 B */ 0xA3BF,
  272. /* 43 C */ 0xA4BC,
  273. /* 44 D */ 0xA4AC,
  274. /* 45 E */ 0xA4A5,
  275. /* 46 F */ 0xA4AB,
  276. /* 47 G */ 0xA4C2,
  277. /* 48 H */ 0xA3B0,
  278. /* 49 I */ 0xA3B7,
  279. /* 4A J */ 0xA3B1,
  280. /* 4B K */ 0xA3B2,
  281. /* 4C L */ 0xA3B3,
  282. /* 4D M */ 0xA1A8,
  283. /* 4E N */ 0xA3AD,
  284. /* 4F O */ 0xA3B8,
  285. /* 50 P */ 0xA3B9,
  286. /* 51 Q */ 0xA4BD,
  287. /* 52 R */ 0xA4B0,
  288. /* 53 S */ 0xA4A6,
  289. /* 54 T */ 0xA4AD,
  290. /* 55 U */ 0xA3B6,
  291. /* 56 V */ 0xA4A3,
  292. /* 57 W */ 0xA4BC,
  293. /* 58 X */ 0xA4B4,
  294. /* 59 Y */ 0xA3B5,
  295. /* 5A Z */ 0xA4BA,
  296. /* 5B [ */ 0xA3A8,
  297. /* 5C \ */ 0xA3BA,
  298. /* 5D ] */ 0xA1B4,
  299. /* 5E ^ */ 0xA3BD,
  300. /* 5F _ */ 0xA3BB,
  301. /* 60 ` */ 0xA3AA,
  302. /* 61 a */ 0xA4B7,
  303. /* 62 b */ 0xA4CC,
  304. /* 63 c */ 0xA4C4,
  305. /* 64 d */ 0xA4D3,
  306. /* 65 e */ 0xA4C5,
  307. /* 66 f */ 0xA4BF,
  308. /* 67 g */ 0xA4D1,
  309. /* 68 h */ 0xA4A4,
  310. /* 69 i */ 0xA4B1,
  311. /* 6A j */ 0xA4B7,
  312. /* 6B k */ 0xA4A1,
  313. /* 6C l */ 0xA4B8,
  314. /* 6D m */ 0xA4BE,
  315. /* 6E n */ 0xA4B5,
  316. /* 6F o */ 0xA4BA,
  317. /* 70 p */ 0xA4BD,
  318. /* 71 q */ 0xA4B5,
  319. /* 72 r */ 0xA4C0,
  320. /* 73 s */ 0xA4A4,
  321. /* 74 t */ 0xA4C3,
  322. /* 75 u */ 0xA4A7,
  323. /* 76 v */ 0xA4C7,
  324. /* 77 w */ 0xA4A9,
  325. /* 78 x */ 0xA4A1,
  326. /* 79 y */ 0xA4B1,
  327. /* 7A z */ 0xA4B1,
  328. /* 7B { */ 0xA3A5,
  329. /* 7C | */ 0xA3CC,
  330. /* 7D } */ 0xA3AF,
  331. /* 7E ~ */ 0xA1AD,
  332. 0x0000
  333. }
  334. };
  335. CONST WORD wKSCompCode[51] = // from 'GiYuk' to 'Yi'.
  336. {
  337. 0x8841,0x8C41,0x8444,0x9041,0x8446,0x8447,0x9441,0x9841,0x9C41,0x844A,
  338. 0x844B,0x844C,0x844D,0x844E,0x844F,0x8450,0xA041,0xA441,0xA841,0x8454,
  339. 0xAC41,0xB041,0xB441,0xB841,0xBC41,0xC041,0xC441,0xC841,0xCC41,0xD041,
  340. 0x8461,0x8481,0x84A1,0x84C1,0x84E1,0x8541,0x8561,0x8581,0x85A1,0x85C1,
  341. 0x85E1,0x8641,0x8661,0x8681,0x86A1,0x86C1,0x86E1,0x8741,0x8761,0x8781,
  342. 0x87A1
  343. };
  344. CONST WORD wKSCompCode2[30] = // from 'GiYuk' to 'HiEut'.
  345. {
  346. 0x8442,0x8443,0x8444,0x8445,0x8446,0x8447,0x8448,0x9841,0x8449,0x844A,
  347. 0x844B,0x844C,0x844D,0x844E,0x844F,0x8450,0x8451,0x8453,0xA841,0x8454,
  348. 0x8455,0x8456,0x8457,0x8458,0xBC41,0x8459,0x845A,0x845B,0x845C,0x845D
  349. };
  350. WORD
  351. JunjaToBanja(
  352. LPSTR lpSrc,
  353. LPSTR lpDest
  354. )
  355. /*++
  356. Routine Description:
  357. Arguments:
  358. Return Value:
  359. --*/
  360. {
  361. WANSUNG wsCode;
  362. WORD wCount = 0;
  363. while (*lpSrc)
  364. {
  365. if ((BYTE)(*lpSrc) < (BYTE)0x80)
  366. {
  367. *lpDest++ = *lpSrc++;
  368. wCount++;
  369. }
  370. else
  371. {
  372. wsCode.e.high = *lpSrc++;
  373. wsCode.e.low = *lpSrc++;
  374. if (wsCode.w == 0xA1A1)
  375. {
  376. *lpDest++ = ' ';
  377. wCount++;
  378. }
  379. else if (wsCode.w >= 0xA3A1 && wsCode.w <= 0xA3FE)
  380. {
  381. *lpDest++ = wsCode.e.low - (BYTE)0x80;
  382. wCount++;
  383. }
  384. else
  385. {
  386. *lpDest++ = wsCode.e.high;
  387. *lpDest++ = wsCode.e.low;
  388. wCount += 2;
  389. }
  390. }
  391. }
  392. *lpDest = '\0';
  393. return (wCount);
  394. }
  395. WORD
  396. BanjaToJunja(
  397. LPSTR lpSrc,
  398. LPSTR lpDest
  399. )
  400. /*++
  401. Routine Description:
  402. Arguments:
  403. Return Value:
  404. --*/
  405. {
  406. WORD wCount = 0;
  407. while (*lpSrc)
  408. {
  409. if ((BYTE)(*lpSrc) < (BYTE)0x80)
  410. {
  411. if (*lpSrc++ == ' ')
  412. {
  413. *lpDest++ = (BYTE)0xA1;
  414. *lpDest++ = (BYTE)0xA1;
  415. wCount += 2;
  416. }
  417. else
  418. {
  419. *lpDest++ = (BYTE)0xA3;
  420. *lpDest++ = *(lpSrc - 1) + (BYTE)0x80;
  421. wCount += 2;
  422. }
  423. }
  424. else
  425. {
  426. *lpDest++ = *lpSrc++;
  427. *lpDest++ = *lpSrc++;
  428. wCount += 2;
  429. }
  430. }
  431. *lpDest = '\0';
  432. return (wCount);
  433. }
  434. WORD
  435. JohabToKs(
  436. LPSTR lpSrc,
  437. LPSTR lpDest
  438. )
  439. /*++
  440. Routine Description:
  441. Arguments:
  442. Return Value:
  443. --*/
  444. {
  445. WORD wCount = 0;
  446. #if defined(OLD_CONV)
  447. WANSUNG wsSCode, wsDCode;
  448. int iHead = 0, iTail = 2349, iMid;
  449. BYTE bCount;
  450. #endif
  451. while (*lpSrc)
  452. {
  453. if ((BYTE)(*lpSrc) < (BYTE)0x80)
  454. {
  455. *lpDest++ = *lpSrc++;
  456. wCount++;
  457. }
  458. else
  459. #if defined(OLD_CONV)
  460. {
  461. wsSCode.e.high = *lpSrc++;
  462. wsSCode.e.low = *lpSrc++;
  463. for (bCount = 0; bCount < 51 && wKSCompCode[bCount] != wsSCode.w; bCount++)
  464. ;
  465. wsDCode.w = (bCount == 51)? 0: bCount + 0xA4A1;
  466. if (wsDCode.w)
  467. {
  468. *lpDest++ = wsDCode.e.high;
  469. *lpDest++ = wsDCode.e.low;
  470. wCount += 2;
  471. continue;
  472. }
  473. for (bCount = 0; bCount < 30 && wKSCompCode2[bCount] != wsSCode.w; bCount++)
  474. ;
  475. wsDCode.w = (bCount == 30)? 0: bCount + 0xA4A1;
  476. if (wsDCode.w)
  477. {
  478. *lpDest++ = wsDCode.e.high;
  479. *lpDest++ = wsDCode.e.low;
  480. wCount += 2;
  481. continue;
  482. }
  483. while (iHead <= iTail && !wsDCode.w)
  484. {
  485. iMid = (iHead + iTail) / 2;
  486. if (wKSCharCode[iMid] > wsSCode.w)
  487. iTail = iMid - 1;
  488. else if (wKSCharCode[iMid] < wsSCode.w)
  489. iHead = iMid + 1;
  490. else
  491. wsDCode.w = ((iMid / 94 + 0xB0) << 8) | (iMid % 94 + 0xA1);
  492. }
  493. if (wsDCode.w)
  494. {
  495. *lpDest++ = wsDCode.e.high;
  496. *lpDest++ = wsDCode.e.low;
  497. wCount += 2;
  498. }
  499. else
  500. {
  501. *lpDest++ = wsSCode.e.high;
  502. *lpDest++ = wsSCode.e.low;
  503. wCount += 2;
  504. }
  505. }
  506. #else
  507. {
  508. // for simple implementation, converting one character by character
  509. // we have to change it string to string conversion.
  510. WCHAR wUni;
  511. CHAR chTmp[2];
  512. chTmp[0] = *lpSrc++;
  513. chTmp[1] = *lpSrc++;
  514. MultiByteToWideChar(JOHAB_CP, MB_PRECOMPOSED, chTmp, TWO_BYTE, &wUni, ONE_WORD);
  515. WideCharToMultiByte(WANSUNG_CP, 0, &wUni, ONE_WORD, chTmp, TWO_BYTE, NULL, NULL);
  516. *lpDest++ = chTmp[0];
  517. *lpDest++ = chTmp[1];
  518. wCount += 2;
  519. }
  520. #endif
  521. }
  522. *lpDest = '\0';
  523. return (wCount);
  524. }
  525. WORD
  526. KsToJohab(
  527. LPSTR lpSrc,
  528. LPSTR lpDest
  529. )
  530. /*++
  531. Routine Description:
  532. Arguments:
  533. Return Value:
  534. --*/
  535. {
  536. #if defined(OLD_CONV)
  537. WANSUNG wsSCode, wsDCode;
  538. WORD wCount = 0, wLoc;
  539. #else
  540. WORD wCount = 0;
  541. #endif
  542. while (*lpSrc)
  543. {
  544. if ((BYTE)(*lpSrc) < (BYTE)0x80)
  545. {
  546. *lpDest++ = *lpSrc++;
  547. wCount++;
  548. }
  549. else
  550. #if defined(OLD_CONV)
  551. {
  552. wsSCode.e.high = *lpSrc++;
  553. wsSCode.e.low = *lpSrc++;
  554. if (wsSCode.w >= (WORD)0xA4A1 && wsSCode.w <= (WORD)0xA4D3)
  555. {
  556. wsDCode.w = wKSCompCode[wsSCode.w - 0xA4A1];
  557. *lpDest++ = wsDCode.e.high;
  558. *lpDest++ = wsDCode.e.low;
  559. }
  560. else if (wsSCode.w >= (WORD)0xB0A1 && wsSCode.w <= (WORD)0xC8FE
  561. && wsSCode.e.low != (BYTE)0xFF)
  562. {
  563. wLoc = (wsSCode.e.high - 176) * 94;
  564. wLoc += wsSCode.e.low - 161;
  565. wsDCode.w = wKSCharCode[wLoc];
  566. *lpDest++ = wsDCode.e.high;
  567. *lpDest++ = wsDCode.e.low;
  568. }
  569. else
  570. {
  571. *lpDest++ = wsSCode.e.high;
  572. *lpDest++ = wsSCode.e.low;
  573. }
  574. wCount += 2;
  575. }
  576. #else
  577. {
  578. WCHAR wUni;
  579. CHAR chTmp[2];
  580. chTmp[0] = *lpSrc++;
  581. chTmp[1] = *lpSrc++;
  582. MultiByteToWideChar(WANSUNG_CP, MB_PRECOMPOSED, chTmp, TWO_BYTE, &wUni, ONE_WORD);
  583. WideCharToMultiByte(JOHAB_CP, 0, &wUni, ONE_WORD, chTmp, TWO_BYTE, NULL, NULL);
  584. *lpDest++ = chTmp[0];
  585. *lpDest++ = chTmp[1];
  586. wCount += 2;
  587. }
  588. #endif
  589. }
  590. *lpDest = '\0';
  591. return (wCount);
  592. }
  593. LRESULT
  594. TransCodeConvert(
  595. HIMC hIMC,
  596. LPIMESTRUCT lpIme
  597. )
  598. /*++
  599. Routine Description:
  600. Arguments:
  601. Return Value:
  602. --*/
  603. {
  604. UNREFERENCED_PARAMETER(hIMC);
  605. switch (lpIme->wParam)
  606. {
  607. case IME_JUNJAtoBANJA:
  608. lpIme->wCount = JunjaToBanja(lpSource(lpIme), lpDest(lpIme));
  609. break;
  610. case IME_BANJAtoJUNJA:
  611. lpIme->wCount = BanjaToJunja(lpSource(lpIme), lpDest(lpIme));
  612. break;
  613. case IME_JOHABtoKS:
  614. lpIme->wCount = JohabToKs(lpSource(lpIme), lpDest(lpIme));
  615. break;
  616. case IME_KStoJOHAB:
  617. lpIme->wCount = KsToJohab(lpSource(lpIme), lpDest(lpIme));
  618. break;
  619. default:
  620. lpIme->wCount = 0;
  621. }
  622. return (lpIme->wCount);
  623. }
  624. LRESULT TransConvertList( HIMC hImc, LPIMESTRUCT lpIme)
  625. {
  626. LPSTR lpSrc;
  627. LPSTR lpDst;
  628. HGLOBAL hCandList;
  629. LPCANDIDATELIST lpCandList;
  630. LPSTR lpCandStr;
  631. UINT i, uBufLen;
  632. LRESULT lRet = 0;
  633. lpSrc = lpSource(lpIme);
  634. lpDst = lpDest(lpIme);
  635. uBufLen = ImmGetConversionListA(GetKeyboardLayout(0), hImc, (LPCSTR)lpSrc,
  636. NULL, 0, GCL_CONVERSION);
  637. if (uBufLen)
  638. {
  639. hCandList = GlobalAlloc(GHND, uBufLen);
  640. lpCandList = (LPCANDIDATELIST)GlobalLock(hCandList);
  641. if (lpCandList == NULL) {
  642. return 0;
  643. }
  644. lRet = ImmGetConversionListA(GetKeyboardLayout(0), hImc, (LPCSTR)lpSrc,
  645. lpCandList, uBufLen, GCL_CONVERSION);
  646. for (i = 0; i < lpCandList->dwCount; i++)
  647. {
  648. lpCandStr = (LPSTR)lpCandList + lpCandList->dwOffset[i];
  649. *lpDst++ = *lpCandStr++;
  650. *lpDst++ = *lpCandStr++;
  651. }
  652. *lpDst = '\0';
  653. lpIme->wCount = (WORD)lpCandList->dwCount * 2;
  654. GlobalUnlock(hCandList);
  655. GlobalFree(hCandList);
  656. }
  657. return (lRet);
  658. }
  659. LRESULT TransGetMNTable( HIMC hImc, LPIMESTRUCT lpIme)
  660. {
  661. LPSTR lpMnemonic;
  662. int iCount, iCIM;
  663. UNREFERENCED_PARAMETER(hImc);
  664. lpMnemonic = (LPSTR)(lpIme->lParam1);
  665. // Better place would be Registry instead of WIN.INI,
  666. // but leave it for now.
  667. iCIM = GetProfileInt(L"WANSUNG", L"InputMethod", IDD_2BEOL) - IDD_2BEOL;
  668. for (iCount = 0; iCount < 96; iCount++, lpMnemonic += 2)
  669. {
  670. *lpMnemonic = LOBYTE(HMNTable[iCIM][iCount]);
  671. *(lpMnemonic+1) = HIBYTE(HMNTable[iCIM][iCount]);
  672. }
  673. return TRUE;
  674. }