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.

99 lines
2.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1997, Microsoft Corporation. All Rights Reserved.
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. //#include "stdafx.h"
  7. #include "pch.cxx"
  8. #include "FSADict.h"
  9. //#include "TransTable.h"
  10. #include "ReadHeosaDict.h"
  11. CFSADict::CFSADict(HANDLE fHandle, UINT sparseMatSize, UINT actSize)
  12. {
  13. DWORD NumOfBytesRead;
  14. lpBuffer = (LPSTR)GlobalAlloc(GPTR, sparseMatSize);
  15. Assert(lpBuffer != NULL );
  16. ReadFile(fHandle, lpBuffer, sparseMatSize, &NumOfBytesRead, 0);
  17. // _ASSERT(sparseMatSize == NumOfBytesRead);
  18. if (actSize) {
  19. lpActBuffer = (LPSTR)GlobalAlloc(GPTR, actSize);
  20. Assert(lpActBuffer != NULL);
  21. ReadFile(fHandle, lpActBuffer, actSize, &NumOfBytesRead, 0);
  22. // _ASSERT(actSize == NumOfBytesRead);
  23. } else lpActBuffer = 0;
  24. }
  25. CFSADict::~CFSADict()
  26. {
  27. GlobalFree(lpBuffer);
  28. if (lpActBuffer)
  29. GlobalFree(lpActBuffer);
  30. }
  31. WORD CFSADict::Find(LPCSTR lpWord, BYTE *actCode)
  32. {
  33. WORD base, delta;
  34. WORD hashVal=0;
  35. WORD ret;
  36. //BYTE c;
  37. base = delta = 0;
  38. //delta = ((WORD)(*lpWord) -'A') * 3;
  39. //base = *(WORD *)(lpBuffer + base + delta+1);
  40. //lpWord++;
  41. while(*lpWord) {
  42. if ((BYTE)*(lpBuffer + base + MAX_CHARS*5) == FINAL) return NOT_FOUND;
  43. // if not start state.(input token 0 not used)
  44. //if (base)
  45. delta = ((WORD)(*lpWord)) * 5;
  46. if ( (*(lpBuffer + base + delta)) != (int) (*lpWord) )
  47. return NOT_FOUND;
  48. hashVal += *(WORD*)(lpBuffer + base + delta + 3);
  49. base = *(WORD *)(lpBuffer + base + delta + 1);
  50. if (base==0) return NOT_FOUND;
  51. lpWord++;
  52. }
  53. //c = (BYTE)*(lpBuffer + base + MAX_CHARS*3);
  54. ret = *(WORD*)(lpBuffer + base + MAX_CHARS*5);
  55. if (ret & FINAL)
  56. *actCode = *(lpActBuffer + hashVal);
  57. return ret;
  58. }
  59. WORD CFSAIrrDict::Find(LPCSTR lpWord)
  60. {
  61. WORD base, delta;
  62. //WORD ret;
  63. //BYTE c;
  64. base = delta = 0;
  65. //delta = ((WORD)(*lpWord) -'A') * 3;
  66. //base = *(WORD *)(lpBuffer + base + delta+1);
  67. //lpWord++;
  68. while(*lpWord) {
  69. if ((BYTE)*(lpBuffer + base + MAX_CHARS*3)==FINAL) return NOT_FOUND;
  70. // if not start state.(input token 0 not used)
  71. delta = ((WORD)(*lpWord)) * 3;
  72. if ( (*(lpBuffer + base + delta)) != (int) (*lpWord) )
  73. return NOT_FOUND;
  74. base = *(WORD *)(lpBuffer + base + delta + 1);
  75. if (base==0) return NOT_FOUND;
  76. lpWord++;
  77. }
  78. //c = (BYTE)*(lpBuffer + base + MAX_CHARS*3);
  79. return *(WORD *)(lpBuffer + base + MAX_CHARS*3);
  80. }