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.

87 lines
2.5 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: this is a short program to test the bitmask functionality
  5. //================================================================================
  6. #include <mm.h>
  7. #include <array.h>
  8. #include <bitmask.h>
  9. #include <stdio.h>
  10. PM_BITMASK Bit;
  11. VOID _cdecl
  12. main(
  13. VOID
  14. )
  15. {
  16. DWORD Error;
  17. DWORD Offset;
  18. DWORD BitSize;
  19. DWORD ToSet;
  20. DWORD ToSet1, ToSet2;
  21. DWORD InUseSize;
  22. DWORD UsedSize;
  23. BOOL OldState;
  24. LPBYTE InUse;
  25. LPBYTE Used;
  26. printf("Size of bitmask: "); scanf("%ld", &BitSize);
  27. Error = MemBitInit(&Bit, BitSize);
  28. printf("MemBitInit(&Bit, %ld)=%ld\n", BitSize, Error);
  29. while(1) {
  30. printf("Enter bit to set [-1 to quit loop] from to: "); scanf("%ld %ld", &ToSet1, &ToSet2);
  31. if( -1 == ToSet1 || -1 == ToSet2 ) break;
  32. for( ToSet = ToSet1; ToSet <= ToSet2; ToSet ++ ) {
  33. Error = MemBitSetOrClear(
  34. Bit,
  35. ToSet,
  36. TRUE,
  37. &OldState
  38. );
  39. printf("MemBitSetOrClear(%ld)= %ld,OldState=%ld\n", ToSet, Error, OldState);
  40. }
  41. }
  42. Error = MemBitConvertToCluster(
  43. Bit,
  44. 100,
  45. &InUse,
  46. &InUseSize,
  47. &Used,
  48. &UsedSize
  49. );
  50. printf("MemBitconvert: %ld\n", Error);
  51. if( ERROR_SUCCESS != Error )return;
  52. printf("InUseSize= %ld, UsedSize = %ld\n", InUseSize, UsedSize);
  53. printf("InUse[0] = %ld\n", *(LPDWORD)InUse);
  54. InUse += sizeof(DWORD); InUseSize -= sizeof(DWORD);
  55. while(InUseSize) {
  56. Offset = *(LPDWORD)InUse;
  57. InUse+= sizeof(DWORD);
  58. for( ToSet = 0; ToSet < 32; ToSet ++ )
  59. if( (1<<ToSet) & *(LPDWORD)InUse )
  60. printf("InUse [ %ld ] \n", Offset + ToSet );
  61. InUse+= sizeof(DWORD);
  62. InUseSize -= sizeof(DWORD)*2;
  63. }
  64. printf("Used[0] = %ld\n", *(LPDWORD)Used);
  65. Used += sizeof(DWORD);
  66. UsedSize -= sizeof(DWORD);
  67. while( UsedSize ) {
  68. Offset = *(LPDWORD)Used;
  69. Used += sizeof(DWORD);
  70. UsedSize -= sizeof(DWORD);
  71. printf("Used [ %ld ] \n", Offset);
  72. }
  73. }