Source code of Windows XP (NT5)
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.

303 lines
7.6 KiB

  1. //////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1997 - 1998, Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File : CONVERT.CPP
  6. // Project : Project SIK
  7. //
  8. //////////////////////////////////////////////////
  9. #define _UNICODE
  10. #include <string.h>
  11. #include <windows.h>
  12. #ifdef WIN32
  13. #include <windowsx.h>
  14. #endif
  15. #include <stdlib.h>
  16. #include <tchar.h>
  17. #include <malloc.h>
  18. #include "convert.hpp"
  19. #include "cho2in.hpp"
  20. #include "basedef.hpp"
  21. #include "stemkor.h"
  22. #include "unitoint.h"
  23. void CODECONVERT::AppendIN(char *s, char *d, int &wordptr)
  24. {
  25. for (int j = 0; s[j] != 0; j++)
  26. d[wordptr++] = s[j];
  27. d[wordptr] = NULLCHAR;
  28. }
  29. void CODECONVERT::ReverseIN(char *w, char *rw)
  30. {
  31. int i = lstrlen(w) - 1;
  32. for (int j = 0; j <= i; j++)
  33. rw[j] = w[i-j];
  34. rw[j] = NULLCHAR;
  35. }
  36. void CODECONVERT::AppendHAN(WCHAR s, WCHAR *d, int &wordptr)
  37. {
  38. d[wordptr++] = s;
  39. d[wordptr] = NULLCHAR;
  40. }
  41. void CODECONVERT::ReverseHAN(WCHAR *w, WCHAR *rw)
  42. {
  43. int i = wcslen(w) - 1;
  44. for (int j = 0; j <= i; j++) {
  45. rw[j] = w[i-j];
  46. }
  47. rw[j] = NULLCHAR;
  48. }
  49. int CODECONVERT::HAN2INS(char *wansung, char *internal, int code)
  50. {
  51. if(code == codeWanSeong)
  52. {
  53. LPWSTR unicode;
  54. int len;
  55. len = MultiByteToWideChar(UWANSUNG_CODE_PAGE, 0, wansung, -1, NULL, 0);
  56. unicode = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR) * len);
  57. // add a check for this point
  58. if (unicode == NULL ) {
  59. return FALSE;
  60. }
  61. len = MultiByteToWideChar (UWANSUNG_CODE_PAGE, 0, wansung, -1, unicode, len);
  62. UniToInternal(unicode, internal, len-1);
  63. // we must free the memory.
  64. LocalFree(unicode);
  65. }
  66. else
  67. return FALSE;
  68. return SUCCESS;
  69. }
  70. int CODECONVERT::HAN2INR(char *h, char *rc, int code)
  71. {
  72. char c[80];
  73. _fmemset(c, NULL, 80);
  74. if (HAN2INS(h, c, code) == SUCCESS)
  75. {
  76. ReverseIN(c, rc);
  77. return SUCCESS;
  78. }
  79. else
  80. {
  81. return FAIL;
  82. }
  83. }
  84. // Commented by hjw
  85. int CODECONVERT::INR2HAN(char *c, char *h, int code)
  86. {
  87. char flag=NULLCHAR;
  88. char incode[5], rcode[5];
  89. WCHAR rh[80], hcode, unicode [80];
  90. _fmemset(incode, NULL, 5);
  91. _fmemset(rcode, NULL, 5);
  92. rh [0] = 0;
  93. int WP = 0, i = 0;
  94. int wordptr = 0;
  95. while (c[WP] != NULLCHAR)
  96. {
  97. incode[i] = c[WP++];
  98. if (incode[i] < __V_k)
  99. {
  100. if ((flag == 1) || (c[WP] == 0))
  101. {
  102. incode[i+1] = NULLCHAR; i = 0; flag = 0;
  103. }
  104. else
  105. {
  106. i++;
  107. }
  108. }
  109. else
  110. {
  111. if ((c[WP] == 0) || (c[WP] >= __V_k))
  112. {
  113. incode[i+1] = NULLCHAR; i = 0; flag = 0;
  114. }
  115. else
  116. {
  117. flag = 1; i++;
  118. }
  119. }
  120. if (i == 0)
  121. {
  122. ReverseIN(incode, rcode);
  123. IN2UNI(rcode, &hcode);
  124. AppendHAN(hcode, rh, wordptr);
  125. }
  126. }
  127. ReverseHAN(rh, unicode);
  128. if (code == codeWanSeong)
  129. {
  130. WideCharToMultiByte (UWANSUNG_CODE_PAGE, 0, unicode, -1, h, wcslen (unicode)*2+1, NULL, NULL);
  131. }
  132. return SUCCESS;
  133. }
  134. int CODECONVERT::INS2HAN(char *c, char *h, int code)
  135. {
  136. char rc[80];
  137. _fmemset(rc, NULL, 80);
  138. ReverseIN(c, rc);
  139. if(INR2HAN(rc, h, code) == FAIL)
  140. {
  141. return FAIL;
  142. }
  143. return SUCCESS;
  144. }
  145. // Cho sung mapping table
  146. static
  147. WORD ChoSungUniTable[] =
  148. {
  149. 0x0000, // Fill code
  150. 0xAC00, // KIYEOK 1
  151. 0xAE4C, // SSANGKIYEOK 2
  152. 0xB098, // NIEUN 3
  153. 0x0000, // SSANGNIEUN 4 // not used
  154. 0xB2E4, // TIKEUT 5
  155. 0xB530, // SSANGTIKEUT 6
  156. 0xB77C, // RIEUL 7
  157. 0x0000, // SSANGRIEUL 8 // not used
  158. 0x0000, // not defined 9
  159. 0xB9C8, // MIEUM 10
  160. 0xBC14, // PIEUP 11
  161. 0xBE60, // SSANGPIEUP 12
  162. 0xC0AC, // SIOS 13
  163. 0xC2F8, // SSANGSIOS 14
  164. 0xC544, // IEUNG 15
  165. 0xC790, // CIEUC 16
  166. 0xC9DC, // SSANGCIEUC 17
  167. 0xCC28, // CHIEUCH 18
  168. 0xCE74, // KHIEUKH 19
  169. 0xD0C0, // THIEUTH 20
  170. 0xD30C, // PHIEUPH 21
  171. 0xD558, // HIEUH 22
  172. };
  173. // Cho sung mapping table
  174. static
  175. WORD JamoUniTable[] =
  176. {
  177. 0x0000, // Fill code
  178. 0x3131, // KIYEOK 1
  179. 0x3132, // SSANGKIYEOK 2
  180. 0x3134, // NIEUN 3
  181. 0x0000, // SSANGNIEUN 4 // not used
  182. 0x3137, // TIKEUT 5
  183. 0x3138, // SSANGTIKEUT 6
  184. 0x3139, // RIEUL 7
  185. 0x0000, // SSANGRIEUL 8 // not used
  186. 0x0000, // not defined 9
  187. 0x3141, // MIEUM 10
  188. 0x3142, // PIEUP 11
  189. 0x3143, // SSANGPIEUP 12
  190. 0x3145, // SIOS 13
  191. 0x3146, // SSANGSIOS 14
  192. 0x3147, // IEUNG 15
  193. 0x3148, // CIEUC 16
  194. 0x3149, // SSANGCIEUC 17
  195. 0x314A, // CHIEUCH 18
  196. 0x314B, // KHIEUKH 19
  197. 0x314C, // THIEUTH 20
  198. 0x314D, // PHIEUPH 21
  199. 0x314E, // HIEUH 22
  200. 0x314F, // A 23
  201. 0x3150, // AE 24
  202. 0x3151, // YA 25
  203. 0x3152, // YAE 26
  204. 0x3153, // EO 27
  205. 0x3154, // E 28
  206. 0x3155, // YEO 29
  207. 0x3156, // YE 30
  208. 0x3157, // O 31
  209. 0x3158, // WA 33
  210. 0x3159, // WAE 34
  211. 0x315A, // OE 35
  212. 0x315B, // YO 36
  213. 0x315C, // U 37
  214. 0x315D, // WEO 38
  215. 0x315E, // WE 39
  216. 0x315F, // WI 40
  217. 0x3160, // YU 41
  218. 0x3161, // EU 42
  219. 0x3162, // YI 43
  220. 0x3163 // I 44
  221. };
  222. int CODECONVERT::IN2UNI(char *c, WORD *wch)
  223. {
  224. if (lstrlen(c) > 1 && c [0] < __V_k && c [1] >= __V_k)
  225. {
  226. *wch = ChoSungUniTable [(int) c [0]];
  227. char stTmp [3];
  228. for (int i2 = 0; i2 < CHUNG; i2++)
  229. if (MapI2 [i2] == c [1])
  230. break;
  231. *wch += (i2 - 1) * CHONG;
  232. if (lstrlen(c) > 2)
  233. {
  234. stTmp[0]=c[2];
  235. stTmp[1]=c[3];
  236. stTmp[2]='\0';
  237. for(int i3 = 0;i3 < CHONG;i3 ++)
  238. if (! (strcmp(MapI3[i3], stTmp)))
  239. {
  240. *wch += (WORD)i3;
  241. break;
  242. }
  243. }
  244. }
  245. else if (lstrlen (c) == 1)
  246. *wch = JamoUniTable [(int) c [0]];
  247. // BUG : SSANGJAMO
  248. return SUCCESS;
  249. }