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.

74 lines
2.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1997, Microsoft Corporation. All Rights Reserved.
  3. //
  4. // Global fuction for writing to file
  5. //#include "stdafx.h"
  6. #include "pch.cxx"
  7. #include "ReadSilsaDict.h"
  8. static CDoubleFileBSDict *LenDicts[MAX_LENGTH_DICT];
  9. // points to block in the dictionary file.
  10. static _DictHeader dictHeader;
  11. static HANDLE hDict;
  12. static DWORD fpLengthDicBlock[MAX_LENGTH_DICT];
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Open and Read Silsa dictionary index
  15. // offset : offset from start of MainDict to Sialsa Dict.
  16. // for one lex dict.
  17. BOOL OpenSilsaDict(HANDLE _hDict, DWORD offset)
  18. {
  19. DWORD readBytes;
  20. hDict = _hDict;
  21. // hDict = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, 0,
  22. // OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);
  23. //ReadFile(hDict, &stamp, strlen(dictHeader.COPYRIGHT_HEADER), &readBytes, 0);
  24. //stamp[strlen(COPYRIGHT_HEADER)] = 0;
  25. //if (strcmp(COPYRIGHT_HEADER, stamp)!=0) return FALSE;
  26. SetFilePointer(hDict, offset, 0, FILE_BEGIN);
  27. ReadFile(hDict, &dictHeader, sizeof(_DictHeader), &readBytes, 0);
  28. //if (strcmp(COPYRIGHT_STR, dictHeader.COPYRIGHT_HEADER)!=0) return FALSE;
  29. SetFilePointer(hDict, offset+SILSA_DICT_HEADER_SIZE, 0, FILE_BEGIN);
  30. LenDicts[0] = new CDoubleFileBSDict();
  31. LenDicts[0]->LoadIndex(hDict);
  32. fpLengthDicBlock[0] = offset + dictHeader.iBlock;
  33. for (int i=1; i<dictHeader.numOfLenDict; i++) {
  34. LenDicts[i] = new CDoubleFileBSDict();
  35. LenDicts[i]->LoadIndex(hDict);
  36. fpLengthDicBlock[i] = fpLengthDicBlock[i-1] + LenDicts[i-1]->GetBlockSize() *
  37. LenDicts[i-1]->GetNumOfBlocks();
  38. }
  39. return TRUE;
  40. }
  41. void CloseSilsaDict()
  42. {
  43. if (hDict) {
  44. //CloseHandle(hDict);
  45. for (int i=0; i<dictHeader.numOfLenDict; i++) {
  46. delete LenDicts[i];
  47. LenDicts[i] = 0;
  48. }
  49. }
  50. hDict = 0;
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // Find word from silsa dict.
  54. int FindSilsaWord(LPCTSTR lpWord)
  55. {
  56. #ifdef _MBCS
  57. int wordLen = strlen(lpWord)>>1;
  58. #elif _UNICODE
  59. int wordLen = lstrlen(lpWord);
  60. #endif
  61. if (wordLen>MAX_LENGTH_DICT || wordLen <= 0) return 0;
  62. return LenDicts[wordLen-1]->FindWord(hDict, fpLengthDicBlock[wordLen-1], lpWord);
  63. }