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.

149 lines
3.4 KiB

  1. /****************************************************************************
  2. IHJDict.cpp : Implementation of CHJDict
  3. Copyright 2000 Microsoft Corp.
  4. History:
  5. 02-AUG-2000 bhshin remove unused method for Hand Writing team
  6. 17-MAY-2000 bhshin remove unused method for CICERO
  7. 02-FEB-2000 bhshin created
  8. ****************************************************************************/
  9. #include "private.h"
  10. #include "HjDict.h"
  11. #include "IHJDict.h"
  12. #include "Lookup.h"
  13. #include "..\inc\common.h"
  14. // maximum output buffer size
  15. #define MAX_OUT_BUFFER 512
  16. #define SZLEX_FILENAME "hanja.lex"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CHJDict
  19. // CHJDict::~CHjDict
  20. //
  21. // load main lexicon
  22. //
  23. // Parameters:
  24. // lpcszPath -> (LPCSTR) lexicon path
  25. //
  26. // Result:
  27. // (HRESULT)
  28. //
  29. // 02AUG2000 bhshin began
  30. CHJDict::~CHJDict()
  31. {
  32. if (m_fLexOpen)
  33. CloseLexicon(&m_LexMap);
  34. }
  35. // CHJDict::Init
  36. //
  37. // load main lexicon
  38. //
  39. // Parameters:
  40. // lpcszPath -> (LPCSTR) lexicon path
  41. //
  42. // Result:
  43. // (HRESULT)
  44. //
  45. // 02FEB2000 bhshin began
  46. STDMETHODIMP CHJDict::Init()
  47. {
  48. CHAR szLexPath[MAX_PATH], szLexPathExpanded[MAX_PATH] ;
  49. HKEY hKey;
  50. DWORD dwCb, dwType;
  51. if (m_fLexOpen)
  52. {
  53. CloseLexicon(&m_LexMap);
  54. m_fLexOpen = FALSE;
  55. }
  56. // default value
  57. StringCchCopy(szLexPath, MAX_PATH, "%WINDIR%\\IME\\IMKR6_1\\Dicts\\");
  58. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, g_szIMEDirectoriesKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  59. {
  60. dwCb = sizeof(szLexPath);
  61. dwType = REG_EXPAND_SZ;
  62. RegQueryValueEx(hKey, g_szDicPath, NULL, &dwType, (LPBYTE)szLexPath, &dwCb);
  63. RegCloseKey(hKey);
  64. }
  65. ExpandEnvironmentStrings(szLexPath, szLexPathExpanded, sizeof(szLexPathExpanded));
  66. if (szLexPathExpanded[lstrlen(szLexPathExpanded)-1] != '\\')
  67. StringCchCat(szLexPathExpanded, MAX_PATH, "\\");
  68. StringCchCat(szLexPathExpanded, MAX_PATH, SZLEX_FILENAME);
  69. if (!OpenLexicon(szLexPathExpanded, &m_LexMap))
  70. return E_FAIL;
  71. m_fLexOpen = TRUE;
  72. return S_OK;
  73. }
  74. // CHJDict::LookupHangulOfHanja
  75. //
  76. // lookup hangul of input hanja string
  77. //
  78. // Parameters:
  79. // pwszHanja -> (LPCWSTR) input hanja string
  80. // pwszHangul -> (WCHAR *) output hangul string
  81. // cchHangul -> (int) output buffer size
  82. //
  83. // Result:
  84. // (HRESULT)
  85. //
  86. // 02FEB2000 bhshin began
  87. STDMETHODIMP CHJDict::LookupHangulOfHanja(LPCWSTR pwszHanja,
  88. WCHAR *pwszHangul,
  89. int cchHangul)
  90. {
  91. int cchHanja;
  92. BOOL fLookup;
  93. cchHanja = wcslen(pwszHanja);
  94. if (cchHanja == 0)
  95. return E_FAIL;
  96. // output buffer insufficient
  97. if (cchHangul < cchHanja)
  98. return E_FAIL;
  99. fLookup = ::LookupHangulOfHanja(&m_LexMap, pwszHanja, cchHanja, pwszHangul, cchHangul);
  100. if (!fLookup)
  101. return E_FAIL; // it shoud be found
  102. return S_OK;
  103. }
  104. // CHJDict::LookupMeaning
  105. //
  106. // lookup hanja meaning
  107. //
  108. // Parameters:
  109. // wchHanja -> (WCHAR) input hanja unicode
  110. // pwszMeaning -> (LPWSTR) output meaning
  111. // cchMeaning -> (int) output buffer size
  112. //
  113. // Result:
  114. // (HRESULT)
  115. //
  116. // 09FEB2000 bhshin began
  117. STDMETHODIMP CHJDict::LookupMeaning(WCHAR wchHanja, LPWSTR pwszMeaning, int cchMeaning)
  118. {
  119. BOOL fLookup;
  120. fLookup = ::LookupMeaning(&m_LexMap, (WCHAR)wchHanja, pwszMeaning, cchMeaning);
  121. if (!fLookup)
  122. return E_FAIL;
  123. return S_OK;
  124. }