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.

423 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // File: statchnk.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // Coupling:
  15. //
  16. // Notes:
  17. //
  18. // History: 10-14-1996 ericne Created
  19. //
  20. //----------------------------------------------------------------------------
  21. #include "pch.cxx"
  22. #include "statchnk.hxx"
  23. #include "mydebug.hxx"
  24. #include "utility.hxx"
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Member: CStatChunk::CStatChunk
  28. //
  29. // Synopsis:
  30. //
  31. // Arguments: (none)
  32. //
  33. // Returns:
  34. //
  35. // History: 10-14-1996 ericne Created
  36. //
  37. // Notes:
  38. //
  39. //----------------------------------------------------------------------------
  40. CStatChunk::CStatChunk()
  41. {
  42. // Set the fields equal to zero
  43. idChunk = 0;
  44. breakType = CHUNK_NO_BREAK;
  45. flags = CHUNK_TEXT;
  46. locale = 0;
  47. idChunkSource = 0;
  48. cwcStartSource = 0;
  49. cwcLenSource = 0;
  50. // Set all the sub-fields of the attribute fields to zero
  51. memset( (void*)&attribute, (int)0, sizeof( FULLPROPSPEC ) );
  52. // Reset the value of the ulKind field since a value of 0 indicates pwstr
  53. attribute.psProperty.ulKind = PRSPEC_PROPID;
  54. } //CStatChunk::CStatChunk
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Member: CStatChunk::CStatChunk
  58. //
  59. // Synopsis:
  60. //
  61. // Arguments: [ToCopy] --
  62. //
  63. // Returns:
  64. //
  65. // History: 10-14-1996 ericne Created
  66. //
  67. // Notes:
  68. //
  69. //----------------------------------------------------------------------------
  70. CStatChunk::CStatChunk( const CStatChunk & ToCopy )
  71. {
  72. // Set the fields
  73. idChunk = ToCopy.idChunk;
  74. breakType = ToCopy.breakType;
  75. flags = ToCopy.flags;
  76. locale = ToCopy.locale;
  77. idChunkSource = ToCopy.idChunkSource;
  78. cwcStartSource = ToCopy.cwcStartSource;
  79. cwcLenSource = ToCopy.cwcLenSource;
  80. // First, perform a bitwise copy of the attribute field
  81. memcpy( (void*)&attribute, (void*)&ToCopy.attribute,
  82. sizeof( FULLPROPSPEC ) );
  83. // If the attribute contains a pwstr, create room for it:
  84. if( PRSPEC_LPWSTR == ToCopy.attribute.psProperty.ulKind )
  85. {
  86. size_t lpwstrlen = wcslen( ToCopy.attribute.psProperty.lpwstr );
  87. attribute.psProperty.lpwstr = NEW WCHAR[ lpwstrlen + 1 ];
  88. if( attribute.psProperty.lpwstr )
  89. {
  90. wcscpy( attribute.psProperty.lpwstr,
  91. ToCopy.attribute.psProperty.lpwstr );
  92. }
  93. }
  94. } //CStatChunk::CStatChunk
  95. //+---------------------------------------------------------------------------
  96. //
  97. // Member: CStatChunk::~CStatChunk
  98. //
  99. // Synopsis:
  100. //
  101. // Arguments: (none)
  102. //
  103. // Returns:
  104. //
  105. // History: 10-14-1996 ericne Created
  106. //
  107. // Notes:
  108. //
  109. //----------------------------------------------------------------------------
  110. CStatChunk::~CStatChunk()
  111. {
  112. if( PRSPEC_LPWSTR == attribute.psProperty.ulKind &&
  113. NULL != attribute.psProperty.lpwstr )
  114. {
  115. delete [] attribute.psProperty.lpwstr;
  116. }
  117. } //CStatChunk::~CStatChunk
  118. //+---------------------------------------------------------------------------
  119. //
  120. // Member: CStatChunk::operator=
  121. //
  122. // Synopsis: Overloaded assignment operator. Frees any memory if necessary
  123. // then copies the parameter
  124. //
  125. // Arguments: [ToCopy] -- The object to copy
  126. //
  127. // Returns: a reference to this
  128. //
  129. // History: 10-14-1996 ericne Created
  130. //
  131. // Notes:
  132. //
  133. //----------------------------------------------------------------------------
  134. CStatChunk & CStatChunk::operator=( const CStatChunk & ToCopy )
  135. {
  136. // Make sure this is not a self copy
  137. if( this == &ToCopy )
  138. return( *this );
  139. return( operator=( ( STAT_CHUNK ) ToCopy ) );
  140. } //CStatChunk::operator=
  141. //+---------------------------------------------------------------------------
  142. //
  143. // Member: CStatChunk::operator
  144. //
  145. // Synopsis:
  146. //
  147. // Arguments: [ToCopy] --
  148. //
  149. // Returns:
  150. //
  151. // History: 10-21-1996 ericne Created
  152. //
  153. // Notes:
  154. //
  155. //----------------------------------------------------------------------------
  156. CStatChunk & CStatChunk::operator=( const STAT_CHUNK & ToCopy )
  157. {
  158. // Clean up the old mess
  159. this->~CStatChunk();
  160. // Copy the fields
  161. idChunk = ToCopy.idChunk;
  162. breakType = ToCopy.breakType;
  163. flags = ToCopy.flags;
  164. locale = ToCopy.locale;
  165. idChunkSource = ToCopy.idChunkSource;
  166. cwcStartSource = ToCopy.cwcStartSource;
  167. cwcLenSource = ToCopy.cwcLenSource;
  168. // First, perform a bitwise copy of the attribute field
  169. memcpy( (void*)&attribute, (void*)&ToCopy.attribute,
  170. sizeof( FULLPROPSPEC ) );
  171. // If the attribute contains a lpwstr, create room for it:
  172. if( PRSPEC_LPWSTR == ToCopy.attribute.psProperty.ulKind )
  173. {
  174. size_t lpwstrlen = wcslen( ToCopy.attribute.psProperty.lpwstr );
  175. attribute.psProperty.lpwstr = NEW WCHAR[ lpwstrlen + 1 ];
  176. if( attribute.psProperty.lpwstr )
  177. {
  178. wcscpy( attribute.psProperty.lpwstr,
  179. ToCopy.attribute.psProperty.lpwstr );
  180. }
  181. }
  182. return( *this );
  183. } //CStatChunk::operator
  184. //+---------------------------------------------------------------------------
  185. //
  186. // Member: CStatChunk::Display
  187. //
  188. // Synopsis: Formatted display of the STAT_CHUNK structure
  189. //
  190. // Arguments: [pFileStream] -- Output stream, stdout by default
  191. //
  192. // Returns: void
  193. //
  194. // History: 10-14-1996 ericne Created
  195. //
  196. // Notes:
  197. //
  198. //----------------------------------------------------------------------------
  199. void CStatChunk::Display( FILE* pFileStream ) const
  200. {
  201. TCHAR szGuidBuffer[ GuidBufferSize ];
  202. // Insert a blank line
  203. fwprintf( pFileStream, L"\r\nChunk statistics:\r\n" );
  204. // Print the chunk id
  205. fwprintf( pFileStream, L"Chunk ID: ........... %d\r\n", idChunk);
  206. // Print the break type (in English if possible)
  207. if( CHUNK_NO_BREAK > breakType ||
  208. CHUNK_EOC < breakType ) // not legal
  209. {
  210. fwprintf( pFileStream, L"Illegal Break Type: . %d\r\n", breakType );
  211. }
  212. else
  213. {
  214. fwprintf( pFileStream, L"Chunk Break Type: ... %ls\r\n",
  215. BreakType[ breakType ] );
  216. }
  217. // Print the Chunk state (in English if possible)
  218. if( CHUNK_TEXT == flags || CHUNK_VALUE == flags)
  219. {
  220. fwprintf( pFileStream, L"Chunk State: ........ %ls\r\n",
  221. ChunkState[ flags - 1 ] );
  222. }
  223. else
  224. {
  225. fwprintf( pFileStream, L"Bad Chunk State: .... %d\r\n", flags );
  226. }
  227. // Print the locale
  228. fwprintf( pFileStream, L"Chunk Locale: ....... 0x%08x\r\n", locale );
  229. // Print the Chunk id source
  230. fwprintf( pFileStream, L"Chunk Source ID: .... %d\r\n", idChunkSource );
  231. // Print the start source
  232. fwprintf( pFileStream, L"Chunk Start Source .. 0x%08x\r\n",
  233. cwcStartSource );
  234. // Print the length source
  235. fwprintf( pFileStream, L"Chunk Length Source . 0x%08x\r\n",
  236. cwcLenSource );
  237. // Display the guid
  238. GetStringFromCLSID( attribute.guidPropSet, szGuidBuffer, GuidBufferSize );
  239. fwprintf( pFileStream, L"GUID ................ %s\r\n", szGuidBuffer );
  240. // Display the contents of the PROPSPEC field (careful of the union)
  241. if( PRSPEC_LPWSTR == attribute.psProperty.ulKind )
  242. {
  243. fwprintf( pFileStream, L"Property name ....... %ls\r\n",
  244. attribute.psProperty.lpwstr );
  245. }
  246. else if( PRSPEC_PROPID == attribute.psProperty.ulKind )
  247. {
  248. fwprintf( pFileStream, L"Property ID ......... 0x%08x\r\n",
  249. attribute.psProperty.propid );
  250. }
  251. else
  252. {
  253. fwprintf( pFileStream, L"Bad ulKind field .... %d\r\n",
  254. attribute.psProperty.ulKind );
  255. }
  256. // Insert a blank line
  257. fwprintf( pFileStream, L"\r\n" );
  258. } //CStatChunk::Display
  259. //+---------------------------------------------------------------------------
  260. //
  261. // Function: operator==
  262. //
  263. // Synopsis:
  264. //
  265. // Arguments: [ChunkA] --
  266. // [ChunkB] --
  267. //
  268. // Returns:
  269. //
  270. // History: 10-14-1996 ericne Created
  271. //
  272. // Notes:
  273. //
  274. //----------------------------------------------------------------------------
  275. int operator==( const STAT_CHUNK & ChunkA, const STAT_CHUNK & ChunkB )
  276. {
  277. return( ! ( ChunkA != ChunkB ) );
  278. } //operator
  279. //+---------------------------------------------------------------------------
  280. //
  281. // Function: operator!=
  282. //
  283. // Synopsis:
  284. //
  285. // Arguments: [ChunkA] --
  286. // [ChunkB] --
  287. //
  288. // Returns: 1 If the chunks are not equal
  289. // 0 if the chunks are equal
  290. //
  291. // History: 10-14-1996 ericne Created
  292. //
  293. // Notes:
  294. //
  295. //----------------------------------------------------------------------------
  296. int operator!=( const STAT_CHUNK & ChunkA, const STAT_CHUNK & ChunkB )
  297. {
  298. // Check chunk ID
  299. if( ChunkA.idChunk != ChunkB.idChunk )
  300. {
  301. return( 1 );
  302. }
  303. // Check the breaktype
  304. if( ChunkA.breakType != ChunkB.breakType )
  305. {
  306. return( 1 );
  307. }
  308. // Check the flags
  309. if( ChunkA.flags != ChunkB.flags )
  310. {
  311. return( 1 );
  312. }
  313. // Check the locale
  314. if( ChunkA.locale != ChunkB.locale )
  315. {
  316. return( 1 );
  317. }
  318. // Check the GUID
  319. if( ChunkA.attribute.guidPropSet != ChunkB.attribute.guidPropSet )
  320. {
  321. return( 1 );
  322. }
  323. // Make sure they have the same ulKind
  324. if( ChunkA.attribute.psProperty.ulKind !=
  325. ChunkB.attribute.psProperty.ulKind )
  326. {
  327. return( 1 );
  328. }
  329. if( PRSPEC_PROPID == ChunkA.attribute.psProperty.ulKind &&
  330. PRSPEC_PROPID == ChunkB.attribute.psProperty.ulKind )
  331. {
  332. // compare the propid's
  333. if( ChunkA.attribute.psProperty.propid !=
  334. ChunkB.attribute.psProperty.propid )
  335. {
  336. return( 1 );
  337. }
  338. }
  339. else
  340. {
  341. // compare the pwstr's
  342. if( 0 != _wcsicmp( ChunkA.attribute.psProperty.lpwstr,
  343. ChunkB.attribute.psProperty.lpwstr ) )
  344. {
  345. return( 1 );
  346. }
  347. }
  348. // Check the chunk source
  349. if( ChunkA.idChunkSource != ChunkB.idChunkSource )
  350. {
  351. return( 1 );
  352. }
  353. // Check the start source
  354. if( ChunkA.cwcStartSource != ChunkB.cwcStartSource )
  355. {
  356. return( 1 );
  357. }
  358. // check the source length
  359. if( ChunkA.cwcLenSource != ChunkB.cwcLenSource )
  360. {
  361. return( 1 );
  362. }
  363. // They are equal, return 0:
  364. return( 0 );
  365. } //operator