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.

197 lines
4.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1998 - 1999, Microsoft Corporation.
  4. //
  5. // Routine: DllMain
  6. //
  7. // Returns: True if successful, else False.
  8. //
  9. // History: Weibz, 10-Sep-1997, created it.
  10. //
  11. //---------------------------------------------------------------------------
  12. #include <pch.cxx>
  13. #include "basecore.hpp"
  14. #include "basecode.hpp"
  15. #include "basedef.hpp"
  16. #include "basegbl.hpp"
  17. #include "MainDict.h"
  18. #include "stemkor.h"
  19. HSTM g_hStm;
  20. BOOL g_fLoad;
  21. CRITICAL_SECTION ThCritSect;
  22. extern char TempJumpNum[], TempSujaNum[],TempBaseNum[];
  23. extern char TempNumNoun[], TempSuffixOut[];
  24. extern char bTemp[], TempETC[], TempDap[];
  25. extern LenDict JumpNum;
  26. extern LenDict SujaNum;
  27. extern LenDict BaseNum;
  28. extern LenDict NumNoun;
  29. extern LenDict Suffix;
  30. extern LenDict B_Dict;
  31. extern LenDict T_Dict;
  32. extern LenDict Dap;
  33. BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
  34. {
  35. switch(dwReason)
  36. {
  37. case DLL_PROCESS_ATTACH :
  38. DisableThreadLibraryCalls(hDLL);
  39. InitializeCriticalSection (&ThCritSect);
  40. JumpNum.InitLenDict(TempJumpNum, 5, 5);
  41. SujaNum.InitLenDict(TempSujaNum, 8, 27);
  42. BaseNum.InitLenDict(TempBaseNum, 5, 3);
  43. NumNoun.InitLenDict(TempNumNoun, 8, 32);
  44. Suffix.InitLenDict(TempSuffixOut, 8, 8);
  45. B_Dict.InitLenDict(bTemp, 5, 1);
  46. T_Dict.InitLenDict(TempETC, 10, 7);
  47. Dap.InitLenDict(TempDap, 5, 1);
  48. g_fLoad = FALSE;
  49. #ifdef KORDBG
  50. OutputDebugString("\nKorwbrkr: DLL_PROCESS_ATTACH\n");
  51. #endif
  52. #ifdef KORDBG
  53. OutputDebugString("\nInit is OK\n");
  54. #endif
  55. break ;
  56. case DLL_THREAD_ATTACH:
  57. break;
  58. case DLL_THREAD_DETACH:
  59. break;
  60. case DLL_PROCESS_DETACH :
  61. if (g_fLoad) {
  62. StemmerCloseMdr(g_hStm);
  63. StemmerTerminate(g_hStm);
  64. }
  65. DeleteCriticalSection (&ThCritSect);
  66. break ;
  67. } //switch
  68. return TRUE ;
  69. }
  70. BOOL StemInit()
  71. {
  72. if ( g_fLoad )
  73. return TRUE;
  74. EnterCriticalSection( &ThCritSect );
  75. do
  76. {
  77. // Someone else got here first.
  78. if ( g_fLoad )
  79. break;
  80. SRC src;
  81. HKEY KeyStemm;
  82. DWORD dwType, dwSize;
  83. char lpszTemp[MAX_PATH],szSysPath[MAX_PATH];
  84. src = StemmerInit(&g_hStm);
  85. if (src != NULL)
  86. {
  87. #ifdef KORDBG
  88. OutputDebugString("Korwbrkr: StemmerInit( ) returns error\n");
  89. #endif
  90. break;
  91. }
  92. src = StemmerSetOption(g_hStm,SO_NOUNPHRASE|SO_ALONE|SO_AUXILIARY |
  93. SO_COMPOUND | SO_SUFFIX | SO_NP_NOUN |SO_NP_PRONOUN |
  94. SO_NP_NUMBER | SO_NP_DEPENDENT | SO_SUFFIX_JEOG);
  95. if ( src != NULL )
  96. {
  97. #ifdef KORDBG
  98. OutputDebugString("Korwbrkr: StemmerSetOption( )returns error\n");
  99. #endif
  100. break;
  101. }
  102. if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,STEMMERKEY,
  103. 0L,
  104. KEY_QUERY_VALUE,
  105. &KeyStemm ) == ERROR_SUCCESS )
  106. {
  107. dwSize = MAX_PATH;
  108. if ( (RegQueryValueEx(KeyStemm,
  109. STEM_DICTIONARY,
  110. (LPDWORD)NULL,
  111. &dwType,
  112. (LPBYTE)lpszTemp,
  113. &dwSize) == ERROR_SUCCESS)
  114. && (dwType==REG_SZ) )
  115. {
  116. lpszTemp [dwSize] = '\0';
  117. GetSystemDirectory( szSysPath, sizeof(szSysPath)/sizeof(szSysPath[0]) );
  118. strcat(szSysPath, "\\");
  119. strcat(szSysPath, lpszTemp);
  120. #ifdef KORDBG
  121. OutputDebugString("Korwbrkr: the dict is ");
  122. OutputDebugString(szSysPath);
  123. #endif
  124. src = StemmerOpenMdr(g_hStm,szSysPath);
  125. if ( src != NULL )
  126. {
  127. #ifdef KORDBG
  128. OutputDebugString("Korwbrkr: StemmerOpenMdr returns err\n");
  129. #endif
  130. RegCloseKey (KeyStemm);
  131. break;
  132. }
  133. }
  134. else
  135. {
  136. #ifdef KORDBG
  137. OutputDebugString("Korwbrkr: RegQueryValueEx returns err\n");
  138. #endif
  139. RegCloseKey( KeyStemm );
  140. break;
  141. }
  142. RegCloseKey (KeyStemm);
  143. }
  144. else
  145. {
  146. #ifdef KORDBG
  147. OutputDebugString("Korwbrkr:RegOpenKeyEx returns error\n");
  148. #endif
  149. break;
  150. }
  151. g_fLoad = TRUE;
  152. } while ( FALSE );
  153. LeaveCriticalSection( &ThCritSect );
  154. return g_fLoad;
  155. }