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.

295 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. flags.c
  5. Abstract:
  6. dumps the various flags that ACPIKD knows about
  7. Author:
  8. Stephane Plante
  9. Environment:
  10. User
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. ULONG
  15. dumpFlags(
  16. IN ULONGLONG Value,
  17. IN PFLAG_RECORD FlagRecords,
  18. IN ULONG FlagRecordSize,
  19. IN ULONG IndentLevel,
  20. IN ULONG Flags
  21. )
  22. /*++
  23. Routine Description:
  24. This routine dumps the flags specified in Value according to the
  25. description passing into FlagRecords. The formating is affected by
  26. the flags field
  27. Arguments:
  28. Value - The values
  29. FlagRecord - What each bit in the flags means
  30. FlagRecordSize - How many flags there are
  31. IndentLevel - The base indent level
  32. Flags - How we will process the flags
  33. Return Value:
  34. ULONG - the number of characters printed. 0 if we printed nothing
  35. --*/
  36. #define STATUS_PRINTED 0x00000001
  37. #define STATUS_INDENTED 0x00000002
  38. #define STATUS_NEED_COUNTING 0x00000004
  39. #define STATUS_COUNTED 0x00000008
  40. {
  41. PCHAR string;
  42. UCHAR indent[80];
  43. ULONG column = IndentLevel;
  44. ULONG currentStatus = 0;
  45. ULONG fixedSize = 0;
  46. ULONG stringSize;
  47. ULONG tempCount;
  48. ULONG totalCount = 0;
  49. ULONGLONG i, j, k;
  50. IndentLevel = (IndentLevel > 79 ? 79 : IndentLevel);
  51. memset( indent, ' ', IndentLevel );
  52. indent[IndentLevel] = '\0';
  53. //dprintf("DumpFlags( %I64x, %x, %x, %x, %x )\n", Value, FlagRecords, FlagRecordSize, IndentLevel, Flags );
  54. //
  55. // Do we need to make a table?
  56. //
  57. if ( (Flags & DUMP_FLAG_TABLE) &&
  58. !(Flags & DUMP_FLAG_SINGLE_LINE) ) {
  59. currentStatus |= STATUS_NEED_COUNTING;
  60. }
  61. if ( (Flags & DUMP_FLAG_ALREADY_INDENTED) ) {
  62. currentStatus |= STATUS_INDENTED;
  63. }
  64. //
  65. // loop over all the steps that we need to do
  66. //
  67. while (1) {
  68. //dprintf("While(1)\n");
  69. for (i = 0; i < 64; i++) {
  70. k = ((ULONGLONG)1 << i);
  71. for (j = 0; j < FlagRecordSize; j++) {
  72. //dprintf("FlagRecords[%x].Bit = %I64x\n", j, FlagRecords[j].Bit );
  73. if (!(FlagRecords[j].Bit & Value) ) {
  74. //
  75. // Are we looking at the correct bit?
  76. //
  77. if (!(FlagRecords[j].Bit & k) ) {
  78. continue;
  79. }
  80. //
  81. // Yes, we are, so pick the not-present values
  82. //
  83. if ( (Flags & DUMP_FLAG_LONG_NAME && FlagRecords[j].NotLongName == NULL) ||
  84. (Flags & DUMP_FLAG_SHORT_NAME && FlagRecords[j].NotShortName == NULL) ) {
  85. continue;
  86. }
  87. if ( (Flags & DUMP_FLAG_LONG_NAME) ) {
  88. string = FlagRecords[j].NotLongName;
  89. } else if ( (Flags & DUMP_FLAG_SHORT_NAME) ) {
  90. string = FlagRecords[j].NotShortName;
  91. }
  92. } else {
  93. //
  94. // Are we looking at the correct bit?
  95. //
  96. if (!(FlagRecords[j].Bit & k) ) {
  97. continue;
  98. }
  99. //
  100. // Yes, we are, so pick the not-present values
  101. //
  102. if ( (Flags & DUMP_FLAG_LONG_NAME && FlagRecords[j].LongName == NULL) ||
  103. (Flags & DUMP_FLAG_SHORT_NAME && FlagRecords[j].ShortName == NULL) ) {
  104. continue;
  105. }
  106. if ( (Flags & DUMP_FLAG_LONG_NAME) ) {
  107. string = FlagRecords[j].LongName;
  108. } else if ( (Flags & DUMP_FLAG_SHORT_NAME) ) {
  109. string = FlagRecords[j].ShortName;
  110. }
  111. }
  112. if (currentStatus & STATUS_NEED_COUNTING) {
  113. stringSize = strlen( string ) + 1;
  114. if (Flags & DUMP_FLAG_SHOW_BIT) {
  115. stringSize += (4 + ( (ULONG) i / 4));
  116. if ( (i % 4) != 0) {
  117. stringSize++;
  118. }
  119. }
  120. if (stringSize > fixedSize) {
  121. fixedSize = stringSize;
  122. }
  123. continue;
  124. }
  125. if (currentStatus & STATUS_COUNTED) {
  126. stringSize = fixedSize;
  127. } else {
  128. stringSize = strlen( string ) + 1;
  129. if (Flags & DUMP_FLAG_SHOW_BIT) {
  130. stringSize += (4 + ( (ULONG) i / 4));
  131. if ( (i % 4) != 0) {
  132. stringSize++;
  133. }
  134. }
  135. }
  136. if (!(Flags & DUMP_FLAG_SINGLE_LINE) ) {
  137. if ( (stringSize + column) > 79 ) {
  138. dprintf("\n%n", &tempCount);
  139. currentStatus &= ~STATUS_INDENTED;
  140. totalCount += tempCount;
  141. column = 0;
  142. }
  143. }
  144. if (!(Flags & DUMP_FLAG_NO_INDENT) ) {
  145. if (!(currentStatus & STATUS_INDENTED) ) {
  146. dprintf("%s%n", indent, &tempCount);
  147. currentStatus |= STATUS_INDENTED;
  148. totalCount += tempCount;
  149. column += IndentLevel;
  150. }
  151. }
  152. if ( (Flags & DUMP_FLAG_SHOW_BIT) ) {
  153. dprintf("%I64x - %n", k, &tempCount);
  154. tempCount++; // to account for the fact that we dump
  155. // another space at the end of the string
  156. totalCount += tempCount;
  157. column += tempCount;
  158. } else {
  159. tempCount = 0;
  160. }
  161. //
  162. // Actually print the string
  163. //
  164. dprintf( "%.*s %n", (stringSize - tempCount), string, &tempCount );
  165. if (Flags & DUMP_FLAG_SHOW_BIT) {
  166. dprintf(" ");
  167. }
  168. totalCount += tempCount;
  169. column += tempCount;
  170. }
  171. }
  172. //
  173. // Change states
  174. //
  175. if (currentStatus & STATUS_NEED_COUNTING) {
  176. currentStatus &= ~STATUS_NEED_COUNTING;
  177. currentStatus |= STATUS_COUNTED;
  178. continue;
  179. }
  180. if (!(Flags & DUMP_FLAG_NO_EOL) && totalCount != 0) {
  181. dprintf("\n");
  182. totalCount++;
  183. }
  184. //
  185. // Done
  186. //
  187. break;
  188. }
  189. return totalCount;
  190. }