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.

102 lines
2.7 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1997 - 1998, Microsoft Corporation. All Rights Reserved.
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. //#include "stdafx.h"
  7. #include "pch.cxx"
  8. #include "MainDict.h"
  9. static HANDLE hMainDict=0;
  10. ///////////////////////////////////////////////////////////////////////////
  11. // Check if aleady opened. If a processe load multiple DLL it can occur
  12. static WORD DictOpenCount = 0;
  13. BOOL VerifyMainDict(LPSTR lpszLexFileName)
  14. {
  15. _MainDictHeader mainDictHeader;
  16. DWORD readBytes;
  17. HANDLE hDict;
  18. hDict = CreateFile(lpszLexFileName, GENERIC_READ, FILE_SHARE_READ, 0,
  19. OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
  20. if (hDict==INVALID_HANDLE_VALUE)
  21. return FALSE;
  22. ReadFile(hDict, &mainDictHeader, sizeof(_MainDictHeader), &readBytes, 0);
  23. if (readBytes==0 || strcmp(COPYRIGHT_STR, mainDictHeader.COPYRIGHT_HEADER)!=0) {
  24. CloseHandle(hDict);
  25. return FALSE;
  26. }
  27. CloseHandle(hDict);
  28. return TRUE;
  29. }
  30. BOOL OpenMainDict(LPSTR lpszLexFileName)
  31. {
  32. _MainDictHeader mainDictHeader;
  33. DWORD readBytes;
  34. if (DictOpenCount) {
  35. DictOpenCount++; // Incerease reference count
  36. return TRUE;
  37. }
  38. hMainDict = CreateFile(lpszLexFileName,
  39. GENERIC_READ, FILE_SHARE_READ,
  40. 0,
  41. OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
  42. 0);
  43. if (hMainDict != INVALID_HANDLE_VALUE) {
  44. ReadFile(hMainDict,
  45. &mainDictHeader,
  46. sizeof(_MainDictHeader),
  47. &readBytes,
  48. 0);
  49. if (strcmp(COPYRIGHT_STR, mainDictHeader.COPYRIGHT_HEADER) == 0) {
  50. SetFilePointer(hMainDict, MAIN_DICT_HEADER_SIZE, 0, FILE_BEGIN);
  51. if (OpenSilsaDict(hMainDict, mainDictHeader.iSilsa) != FALSE) {
  52. if (OpenHeosaDict(hMainDict, mainDictHeader.iHeosa) != FALSE) {
  53. #ifndef _NO_OYONG_DICT_
  54. if (OpenOyongDict(hMainDict, mainDictHeader.iOyong) == FALSE) {
  55. CloseHeosaDict();
  56. } else {
  57. #endif
  58. DictOpenCount = 1;
  59. return TRUE;
  60. #ifndef _NO_OYONG_DICT_
  61. }
  62. #endif
  63. }
  64. CloseSilsaDict();
  65. }
  66. }
  67. CloseHandle(hMainDict);
  68. }
  69. return FALSE;
  70. }
  71. void CloseMainDict()
  72. {
  73. DictOpenCount--;
  74. if (DictOpenCount==0) {
  75. CloseSilsaDict();
  76. CloseHeosaDict();
  77. #ifndef _NO_OYONG_DICT_
  78. CloseOyongDict();
  79. #endif
  80. CloseHandle(hMainDict);
  81. hMainDict = 0;
  82. }
  83. }