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.

229 lines
6.3 KiB

  1. #include <mvopsys.h>
  2. #ifdef _DEBUG
  3. static char s_aszModule[] = __FILE__; /* For error report */
  4. #endif
  5. #include <windows.h>
  6. #include <itpropl.h>
  7. #include <atlinc.h>
  8. #include "wwumain.h"
  9. // CompareKeys ****************************************************************
  10. HRESULT PASCAL ScanTempFile(LPFBI lpfbi, LPB lpbOut, LPV lpv)
  11. {
  12. LPB lpbLimit = lpfbi->lrgbBuf + lpfbi->cbBuf;
  13. LPB lpbIn = lpfbi->lrgbBuf + lpfbi->ibBuf;
  14. #define STATE_KEYSIZE 1
  15. #define STATE_KEY 2
  16. #define STATE_DATATYPE 3
  17. #define STATE_SORTORDER 4
  18. #define STATE_PROPSIZE 5
  19. #define STATE_PROPLIST 6
  20. DWORD dwState = STATE_KEYSIZE;
  21. DWORD dwSize;
  22. DWORD dwTemp = sizeof (DWORD);
  23. LPB lpbSaved = lpbOut;
  24. *(LPW)lpbOut = 0;
  25. lpbOut += sizeof (WORD);
  26. for (;; dwState++)
  27. {
  28. if (STATE_KEY == dwState || STATE_PROPLIST == dwState)
  29. dwTemp = dwSize;
  30. if (lpbIn + dwTemp >= lpbLimit)
  31. {
  32. HRESULT hResult;
  33. lpfbi->ibBuf = (WORD)(lpbIn - lpfbi->lrgbBuf);
  34. if (FileBufFill (lpfbi, &hResult) == cbIO_ERROR)
  35. return hResult;
  36. lpfbi->ibBuf = 0;
  37. lpbIn = lpfbi->lrgbBuf;
  38. lpbLimit = lpfbi->lrgbBuf + lpfbi->cbBuf;
  39. /* EOF */
  40. if (lpfbi->ibBuf == lpfbi->cbBuf)
  41. {
  42. break;
  43. }
  44. }
  45. if (STATE_DATATYPE == dwState)
  46. {
  47. *lpbOut = *lpbIn;
  48. lpbIn++;
  49. lpbOut++;
  50. } else if (STATE_KEY != dwState && STATE_PROPLIST != dwState)
  51. {
  52. MEMCPY(lpbOut, lpbIn, sizeof (DWORD));
  53. dwSize = *(DWORD UNALIGNED *)lpbIn;
  54. lpbIn += sizeof(DWORD);
  55. lpbOut += sizeof(DWORD);
  56. }
  57. else
  58. {
  59. MEMCPY(lpbOut, lpbIn, dwSize);
  60. lpbIn += dwSize;
  61. lpbOut += dwSize;
  62. if (STATE_PROPLIST == dwState)
  63. break;
  64. dwTemp = sizeof (DWORD);
  65. }
  66. }
  67. *(LPW)lpbSaved = (WORD)(lpbOut - lpbSaved - sizeof(WORD));
  68. lpfbi->ibBuf = (WORD)(lpbIn - lpfbi->lrgbBuf);
  69. return S_OK;
  70. }
  71. // CompareKeys ****************************************************************
  72. int PASCAL CompareKeys(LPSTR pWord1, LPSTR pWord2, LPV pSortInfo)
  73. {
  74. // Format:
  75. // <dwSize><Key><Data Type><2nd Sort Order><prop size><prop list>
  76. // DWORD n CHAR DWORD DWORD n
  77. IITSortKey *piitsk = (IITSortKey *)pSortInfo;
  78. ITASSERT(piitsk);
  79. // Compare keys
  80. pWord1 += sizeof (WORD);
  81. pWord2 += sizeof (WORD);
  82. CHAR cKey1[2084], cKey2[2048];
  83. ITASSERT(*(DWORD UNALIGNED *)pWord1 <= 2048);
  84. ITASSERT(*(DWORD UNALIGNED *)pWord2 <= 2048);
  85. MEMCPY(cKey1, pWord1 + sizeof (DWORD), *(DWORD UNALIGNED *)pWord1);
  86. MEMCPY(cKey2, pWord2 + sizeof (DWORD), *(DWORD UNALIGNED *)pWord2);
  87. LONG lResult;
  88. if (FAILED(piitsk->Compare(cKey1, cKey2, &lResult, NULL))) {
  89. ITASSERT(0);
  90. }
  91. if (lResult)
  92. return lResult;
  93. // Keys are equal - Compare data type
  94. pWord1 += sizeof(DWORD) + *(DWORD UNALIGNED *)pWord1;
  95. pWord2 += sizeof(DWORD) + *(DWORD UNALIGNED *)pWord2;
  96. if (lResult = *(BYTE UNALIGNED *)pWord1 - *(BYTE UNALIGNED *)pWord2)
  97. return lResult;
  98. pWord1++;
  99. pWord2++;
  100. // Data types are equal - Compare secondary sort ordinal
  101. lResult = *(DWORD UNALIGNED *)pWord1 - *(DWORD UNALIGNED *)pWord2;
  102. return lResult;
  103. } /* CompareKeys */
  104. // PackBytes ******************************************************************
  105. int PASCAL PackBytes(LPB lpbOut, DWORD dwIn)
  106. {
  107. LPB lpbOldOut;
  108. /* Save the old offset */
  109. lpbOldOut = lpbOut;
  110. do
  111. {
  112. *lpbOut =(BYTE)(dwIn & 0x7F); /* Get 7 bits. */
  113. dwIn >>= 7;
  114. if (dwIn)
  115. *lpbOut |= 0x80; /* To be continued... */
  116. lpbOut++;
  117. } while (dwIn);
  118. return (int)(lpbOut - lpbOldOut); /* Return compressed width */
  119. } /* PackBytes */
  120. /***************************************************************************
  121. *
  122. * Name FWriteData
  123. *
  124. * Purpose
  125. * Writes the extra data to the keyword data file.
  126. *
  127. * Arguments
  128. * IStorage* pStream: Destination stream
  129. * PLKW pKW: Pointer to keyword info structure
  130. * LPDWORD pdwWritten: Pointer to return number of bytes written
  131. *
  132. * Returns
  133. * S_OK on success or
  134. * ERR_FAILED, indicating compilation should be aborted.
  135. *
  136. * Notes:
  137. * DWORD : Extra data byte count
  138. * n : Extra data
  139. *
  140. **************************************************************************/
  141. HRESULT FWriteData(IStream *pStream,
  142. const PLKW pKW, LPDWORD pdwWritten, LPBYTE pTempBuffer)
  143. {
  144. HRESULT hr;
  145. DWORD dwTemp;
  146. DWORD dwDataSize = pKW->cbPropData;
  147. // Encode data size byte count
  148. if (FAILED(hr = pStream->Write(&dwDataSize, sizeof(DWORD), &dwTemp)))
  149. return hr;
  150. if (FAILED(hr = pStream->Write(pKW->pPropData, dwDataSize, &dwTemp)))
  151. return hr;
  152. *pdwWritten += sizeof (DWORD) + dwDataSize;
  153. return S_OK;
  154. }
  155. /* ParseKeywordLine ***********************************************************
  156. * @comm
  157. * Input file format:
  158. * DWORD : Key byte length
  159. * BINARY: Key
  160. * %c : PropDest ID
  161. * %08X : Entry order
  162. * %lu : Property List size %c : DELIMITER(\x0E)
  163. * %s : Property List %c : "\n"
  164. *
  165. ******************************************************************************/
  166. LPSTR WINAPI ParseKeywordLine(LPSTR pBuffer, PLKW pKw)
  167. {
  168. // Extract the keyword size
  169. DWORD dwKeySize = *(DWORD UNALIGNED *)pBuffer;
  170. pBuffer += sizeof(DWORD);
  171. *(DWORD UNALIGNED *UNALIGNED)pKw->szKeyword = dwKeySize;
  172. // Extract the keyword string
  173. ITASSERT(dwKeySize <= CBMAX_KWENTRY);
  174. MEMCPY(pKw->szKeyword + sizeof(DWORD), pBuffer, dwKeySize);
  175. pBuffer += dwKeySize;
  176. // Extract the property destination
  177. pKw->bPropDest= *pBuffer++;
  178. ITASSERT(pKw->bPropDest == C_PROPDEST_KEY
  179. || pKw->bPropDest == C_PROPDEST_OCC);
  180. // Skip the Entry Order (it's only used to manipulate sorting)
  181. pBuffer += sizeof(DWORD);
  182. // Extract the property list size
  183. pKw->cbPropData = *(DWORD UNALIGNED *UNALIGNED)pBuffer;
  184. pBuffer += sizeof(DWORD);
  185. // Make sure we don't read past the end of buffer
  186. ITASSERT(!IsBadReadPtr(pBuffer, pKw->cbPropData));
  187. pKw->pPropData = pBuffer;
  188. pBuffer += pKw->cbPropData;
  189. return pBuffer;
  190. }