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.

319 lines
6.8 KiB

  1. /****************************************************************************
  2. Enum.cpp : implementation of Busu/Stroke Enumeration functions
  3. Copyright 2000 Microsoft Corp.
  4. History:
  5. 07-FEB-2000 bhshin created
  6. ****************************************************************************/
  7. #include "private.h"
  8. #include "Enum.h"
  9. #include "Lookup.h"
  10. #include "Hanja.h"
  11. #include "..\common\trie.h"
  12. // GetMaxBusu
  13. //
  14. // get the maximum busu sequence number
  15. //
  16. // Parameters:
  17. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  18. //
  19. // Result:
  20. // (number of busu, -1 if error occurs)
  21. //
  22. // 08FEB2000 bhshin began
  23. short GetMaxBusu(MAPFILE *pLexMap)
  24. {
  25. unsigned char *pLex;
  26. LEXICON_HEADER *pLexHeader;
  27. short cBusu;
  28. // parameter validation
  29. if (pLexMap == NULL)
  30. return -1;
  31. if (pLexMap->pvData == NULL)
  32. return -1;
  33. pLex = (unsigned char*)pLexMap->pvData;
  34. pLexHeader = (LEXICON_HEADER*)pLexMap->pvData;
  35. // lookup BusuInfo table
  36. cBusu = *(pLex + pLexHeader->rgnBusuInfo);
  37. return cBusu;
  38. }
  39. // GetMaxStroke
  40. //
  41. // get the maximum stroke number
  42. //
  43. // Parameters:
  44. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  45. //
  46. // Result:
  47. // (max stroke number, -1 if error occurs)
  48. //
  49. // 08FEB2000 bhshin began
  50. short GetMaxStroke(MAPFILE *pLexMap)
  51. {
  52. unsigned char *pLex;
  53. LEXICON_HEADER *pLexHeader;
  54. short cStroke, nMaxStroke;
  55. // parameter validation
  56. if (pLexMap == NULL)
  57. return -1;
  58. if (pLexMap->pvData == NULL)
  59. return -1;
  60. pLex = (unsigned char*)pLexMap->pvData;
  61. pLexHeader = (LEXICON_HEADER*)pLexMap->pvData;
  62. // lookup StrokeHead table
  63. cStroke = *(pLex + pLexHeader->rgnStrokeHead);
  64. _STROKE_HEAD *pStrokeHead = (_STROKE_HEAD*)(pLex + pLexHeader->rgnStrokeHead + 1);
  65. // get the max stroke
  66. nMaxStroke = pStrokeHead[cStroke-1].bStroke;
  67. return nMaxStroke;
  68. }
  69. // GetFirstBusuHanja
  70. //
  71. // get the first hanja of input busu
  72. //
  73. // Parameters:
  74. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  75. // nBusuID -> (short) busu id
  76. // pwchFirst -> (WCHAR*) output first hanja with input busu ID
  77. //
  78. // Result:
  79. // (FALSE if error occurs, otherwise return TRUE)
  80. //
  81. // 07FEB2000 bhshin began
  82. BOOL GetFirstBusuHanja(MAPFILE *pLexMap, short nBusuID, WCHAR *pwchFirst)
  83. {
  84. unsigned char *pLex;
  85. LEXICON_HEADER *pLexHeader;
  86. short cBusuID;
  87. *pwchFirst = NULL;
  88. // parameter validation
  89. if (pLexMap == NULL)
  90. return FALSE;
  91. if (pLexMap->pvData == NULL)
  92. return FALSE;
  93. if (nBusuID <= 0)
  94. return FALSE;
  95. pLex = (unsigned char*)pLexMap->pvData;
  96. pLexHeader = (LEXICON_HEADER*)pLexMap->pvData;
  97. // lookup BusuHead table to get the Busu Code ID
  98. cBusuID = *(pLex + pLexHeader->rgnBusuHead);
  99. if (nBusuID >= cBusuID)
  100. return FALSE;
  101. _BUSU_HEAD *pBusuHead = (_BUSU_HEAD*)(pLex + pLexHeader->rgnBusuHead + 1);
  102. *pwchFirst = pBusuHead[nBusuID-1].wchHead;
  103. return TRUE;
  104. }
  105. // GetNextBusuHanja
  106. //
  107. // get the next same busu hanja
  108. //
  109. // Parameters:
  110. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  111. // wchHanja -> (int) current hanja
  112. // pwchNext -> (WCHAR*) output next hanja with same busu
  113. //
  114. // Result:
  115. // (FALSE if error occurs, otherwise return TRUE)
  116. //
  117. // 07FEB2000 bhshin began
  118. BOOL GetNextBusuHanja(MAPFILE *pLexMap, WCHAR wchHanja, WCHAR *pwchNext)
  119. {
  120. unsigned char *pLex;
  121. LEXICON_HEADER *pLexHeader;
  122. DWORD dwOffset;
  123. DWORD dwIndex;
  124. *pwchNext = NULL;
  125. // parameter validation
  126. if (pLexMap == NULL)
  127. return FALSE;
  128. if (pLexMap->pvData == NULL)
  129. return FALSE;
  130. pLex = (unsigned char*)pLexMap->pvData;
  131. pLexHeader = (LEXICON_HEADER*)pLexMap->pvData;
  132. dwOffset = pLexHeader->rgnHanja;
  133. if (fIsExtAHanja(wchHanja))
  134. {
  135. dwIndex = (wchHanja - HANJA_EXTA_START);
  136. }
  137. else if (fIsCJKHanja(wchHanja))
  138. {
  139. dwIndex = HANJA_EXTA_END - HANJA_EXTA_START + 1;
  140. dwIndex += (wchHanja - HANJA_CJK_START);
  141. }
  142. else if (fIsCompHanja(wchHanja))
  143. {
  144. dwIndex = HANJA_EXTA_END - HANJA_EXTA_START + 1;
  145. dwIndex += HANJA_CJK_END - HANJA_CJK_START + 1;
  146. dwIndex += (wchHanja - HANJA_COMP_START);
  147. }
  148. else
  149. {
  150. // unknown input
  151. return FALSE;
  152. }
  153. _HANJA_INFO *pHanjaInfo = (_HANJA_INFO*)(pLex + dwOffset);
  154. *pwchNext = pHanjaInfo[dwIndex].wchNextBusu;
  155. return TRUE;
  156. }
  157. // GetFirstStrokeHanja
  158. //
  159. // get the first hanja of input stroke
  160. //
  161. // Parameters:
  162. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  163. // nStroke -> (int) stroke number
  164. // pwchFirst -> (WCHAR*) output first hanja with input stroke
  165. //
  166. // Result:
  167. // (FALSE if error occurs, otherwise return TRUE)
  168. //
  169. // 07FEB2000 bhshin began
  170. BOOL GetFirstStrokeHanja(MAPFILE *pLexMap, short nStroke, WCHAR *pwchFirst)
  171. {
  172. unsigned char *pLex;
  173. LEXICON_HEADER *pLexHeader;
  174. short cStroke, nMaxStroke;
  175. *pwchFirst = NULL;
  176. // parameter validation
  177. if (pLexMap == NULL)
  178. return FALSE;
  179. if (pLexMap->pvData == NULL)
  180. return FALSE;
  181. if (nStroke < 0)
  182. return FALSE;
  183. pLex = (unsigned char*)pLexMap->pvData;
  184. pLexHeader = (LEXICON_HEADER*)pLexMap->pvData;
  185. // lookup StrokeHead table
  186. cStroke = *(pLex + pLexHeader->rgnStrokeHead);
  187. _STROKE_HEAD *pStrokeHead = (_STROKE_HEAD*)(pLex + pLexHeader->rgnStrokeHead + 1);
  188. // check max stroke
  189. nMaxStroke = pStrokeHead[cStroke-1].bStroke;
  190. if (nStroke > nMaxStroke)
  191. return FALSE;
  192. for (int i = 0; i < cStroke; i++)
  193. {
  194. if (pStrokeHead[i].bStroke == nStroke)
  195. break;
  196. }
  197. if (i == cStroke)
  198. {
  199. // not found
  200. *pwchFirst = NULL;
  201. return FALSE;
  202. }
  203. *pwchFirst = pStrokeHead[i].wchHead;
  204. return TRUE;
  205. }
  206. // GetNextStrokeHanja
  207. //
  208. // get the next same stroke hanja
  209. //
  210. // Parameters:
  211. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  212. // wchHanja -> (int) current hanja
  213. // pwchNext -> (WCHAR*) output next hanja with same stroke
  214. //
  215. // Result:
  216. // (FALSE if error occurs, otherwise return TRUE)
  217. //
  218. // 07FEB2000 bhshin began
  219. BOOL GetNextStrokeHanja(MAPFILE *pLexMap, WCHAR wchHanja, WCHAR *pwchNext)
  220. {
  221. unsigned char *pLex;
  222. LEXICON_HEADER *pLexHeader;
  223. DWORD dwOffset;
  224. DWORD dwIndex;
  225. *pwchNext = NULL;
  226. // parameter validation
  227. if (pLexMap == NULL)
  228. return FALSE;
  229. if (pLexMap->pvData == NULL)
  230. return FALSE;
  231. pLex = (unsigned char*)pLexMap->pvData;
  232. pLexHeader = (LEXICON_HEADER*)pLexMap->pvData;
  233. dwOffset = pLexHeader->rgnHanja;
  234. if (fIsExtAHanja(wchHanja))
  235. {
  236. dwIndex = (wchHanja - HANJA_EXTA_START);
  237. }
  238. else if (fIsCJKHanja(wchHanja))
  239. {
  240. dwIndex = HANJA_EXTA_END - HANJA_EXTA_START + 1;
  241. dwIndex += (wchHanja - HANJA_CJK_START);
  242. }
  243. else if (fIsCompHanja(wchHanja))
  244. {
  245. dwIndex = HANJA_EXTA_END - HANJA_EXTA_START + 1;
  246. dwIndex += HANJA_CJK_END - HANJA_CJK_START + 1;
  247. dwIndex += (wchHanja - HANJA_COMP_START);
  248. }
  249. else
  250. {
  251. // unknown input
  252. return FALSE;
  253. }
  254. _HANJA_INFO *pHanjaInfo = (_HANJA_INFO*)(pLex + dwOffset);
  255. *pwchNext = pHanjaInfo[dwIndex].wchNextStroke;
  256. return TRUE;
  257. }