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.

96 lines
2.4 KiB

  1. /****************************************************************************
  2. Lex.cpp : lexicon management functions
  3. Copyright 2000 Microsoft Corp.
  4. History:
  5. 17-MAY-2000 bhshin changed signature for CICERO
  6. 02-FEB-2000 bhshin created
  7. ****************************************************************************/
  8. #include "private.h"
  9. #include "Lex.h"
  10. // OpenLexicon
  11. //
  12. // map the lexicon file into memory
  13. //
  14. // Parameters:
  15. // lpcszLexPath -> (LPCSTR) lexicon path
  16. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  17. //
  18. // Result:
  19. // (TRUE if success, FALSE if failure)
  20. //
  21. // 02FEB2000 bhshin began
  22. BOOL OpenLexicon(LPCSTR lpcszLexPath, MAPFILE *pLexMap)
  23. {
  24. char *pData;
  25. unsigned short nVersion;
  26. pLexMap->hFile = NULL;
  27. pLexMap->hFileMapping = NULL;
  28. pLexMap->pvData = NULL;
  29. // open the file for reading
  30. pLexMap->hFile = CreateFile(lpcszLexPath, GENERIC_READ, FILE_SHARE_READ, NULL,
  31. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  32. if (pLexMap->hFile == INVALID_HANDLE_VALUE)
  33. return FALSE;
  34. // create a file mapping
  35. pLexMap->hFileMapping = CreateFileMappingA(pLexMap->hFile, NULL, PAGE_READONLY, 0, 0, NULL);
  36. if (pLexMap->hFileMapping == NULL)
  37. return FALSE;
  38. // map the entire file for reading
  39. pLexMap->pvData = MapViewOfFileEx(pLexMap->hFileMapping, FILE_MAP_READ, 0, 0, 0, 0);
  40. if (pLexMap->pvData == NULL)
  41. return FALSE;
  42. // check the version # in the first 2 bytes (swap bytes)
  43. pData = (char*)pLexMap->pvData;
  44. nVersion = pData[0];
  45. nVersion |= (pData[1] << 8);
  46. if (nVersion < LEX_VERSION)
  47. {
  48. return FALSE;
  49. }
  50. // check the magic signature
  51. if (strcmp(pData+2, "HJKO") != 0)
  52. {
  53. return FALSE;
  54. }
  55. return TRUE;
  56. }
  57. // CloseLexicon
  58. //
  59. // unmap the lexicon file into memory
  60. //
  61. // Parameters:
  62. // pLexMap -> (MAPFILE*) ptr to lexicon map struct
  63. //
  64. // Result:
  65. // (void)
  66. //
  67. // 02FEB2000 bhshin began
  68. void CloseLexicon(MAPFILE *pLexMap)
  69. {
  70. if (pLexMap->pvData != NULL)
  71. UnmapViewOfFile(pLexMap->pvData);
  72. if (pLexMap->hFileMapping != NULL)
  73. CloseHandle(pLexMap->hFileMapping);
  74. if (pLexMap->hFile != NULL)
  75. CloseHandle(pLexMap->hFile);
  76. pLexMap->hFile = NULL;
  77. pLexMap->hFileMapping = NULL;
  78. pLexMap->pvData = NULL;
  79. }