Windows NT 4.0 source code leak
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.

368 lines
8.3 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. mondmp.c
  5. Abstract:
  6. This is the main module for the monitor description file dumper.
  7. Author:
  8. Andre Vachon (andreva) 16-Jul-1992
  9. Revision History:
  10. --*/
  11. #include <assert.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <io.h>
  16. #include <fcntl.h>
  17. #include <ctype.h>
  18. #include "nt.h"
  19. #include "monitors.h"
  20. #include "mon.h"
  21. // #define DEBUG_MONITORS
  22. //
  23. // Function declarations
  24. //
  25. int
  26. DumpMonitorFile( void );
  27. int
  28. DumpSection( PLINE_DESCRIPTION LineDescription, char *DataBuffer );
  29. //
  30. // Global Data
  31. //
  32. char *FileName;
  33. FILE *hFile;
  34. int
  35. _CRTAPI1 main( argc, argv )
  36. int argc;
  37. char *argv[];
  38. {
  39. char *p;
  40. int processReturnValue;
  41. if (argc != 2) {
  42. goto end;
  43. }
  44. p = *++argv;
  45. //
  46. // if we have a delimiter for a parameter, case throught the valid
  47. // parameter. Otherwise, the rest of the parameters are the list of
  48. // input files.
  49. //
  50. if (*p == '/' || *p == '-') {
  51. goto end;
  52. }
  53. FileName = *argv;
  54. if ( (hFile = fopen(FileName, "rb")) == 0) {
  55. fprintf(stderr,"MONDMP: Unable to open file %s for read access\n",FileName);
  56. return 1;
  57. }
  58. processReturnValue = DumpMonitorFile();
  59. fclose(hFile);
  60. return 0;
  61. end:
  62. fprintf( stderr, "usage: MONDMP [-?] display this message\n" );
  63. fprintf( stderr, " filename supplies minitor description file to be dumped\n" );
  64. fprintf( stderr, "\n" );
  65. return 0;
  66. }
  67. int
  68. DumpMonitorFile( void )
  69. {
  70. int i, xxx = 1, yyy = 1;
  71. CM_MONITOR_DESCRIPTION monitorDescription;
  72. CM_MONITOR_OPERATIONAL_LIMITS operationalLimits;
  73. CM_MONITOR_PREADJUSTED_TIMING preadjustedTiming;
  74. //
  75. // First allocate a buffer in which we can parse and save the header
  76. // information
  77. //
  78. if (fread(&monitorDescription, sizeof(CM_MONITOR_DESCRIPTION),
  79. 1, hFile) != 1) {
  80. fprintf(stderr, "MONDMP: monitor description could not be read from file\n");
  81. return 1;
  82. }
  83. DumpSection(MonitorDescription, (char *) &monitorDescription);
  84. //
  85. // Fill in the array of Operational Limits, and write each strcuture as
  86. // we go along
  87. //
  88. for (i=0; i < monitorDescription.NumberOperationalLimits; i++) {
  89. if (fread(&operationalLimits, sizeof(CM_MONITOR_OPERATIONAL_LIMITS),
  90. 1, hFile) != 1) {
  91. fprintf(stderr, "MONDMP: operational limits %d could not be read from file\n", i);
  92. return 1;
  93. }
  94. printf("\n\n");
  95. DumpSection(OperationalLimits, (char *) &operationalLimits);
  96. }
  97. //
  98. // Fill in the array of Preadjusted Timings, and write each structure as
  99. // we go along.
  100. //
  101. for (i=0; i < monitorDescription.NumberPreadjustedTimings; i++) {
  102. if (fread(&preadjustedTiming, sizeof(CM_MONITOR_PREADJUSTED_TIMING),
  103. 1, hFile) != 1) {
  104. fprintf(stderr, "MONDMP: PreAdjusted timing %d could not be read from file\n", i);
  105. return 1;
  106. }
  107. printf("\n\n");
  108. DumpSection(PreAdjustedTiming, (char *) &preadjustedTiming);
  109. }
  110. //
  111. // Everything was successful. Return 0
  112. //
  113. return 0;
  114. }
  115. int
  116. DumpSection( LineDescription, DataBuffer )
  117. PLINE_DESCRIPTION LineDescription;
  118. char *DataBuffer;
  119. {
  120. char *character;
  121. int cbChar;
  122. char *buffer;
  123. int floatBits;
  124. int multipleChoiceFound;
  125. int number;
  126. int i;
  127. int desc = 0;
  128. while (LineDescription[desc].LineStruct[0].OptionalField != OP_STOP) {
  129. //
  130. // Process the current line.
  131. //
  132. i = 0;
  133. printf ("\n");
  134. do {
  135. switch (LineDescription[desc].LineStruct[i].FieldType) {
  136. case STRING_FIELD :
  137. if (LineDescription[desc].LineStruct[i].OptionalField ==
  138. OP_MULTIPLE_CHOICE) {
  139. break;
  140. }
  141. if (LineDescription[desc].LineStruct[i].OptionalField ==
  142. OP_MANDATORY) {
  143. printf("%s ", StringTable[LineDescription[desc].LineStruct[i].StringId]);
  144. } else {
  145. if (LineDescription[desc].LineStruct[i].OptionalField ==
  146. OP_STORE) {
  147. #ifdef DEBUG_MONITORS
  148. fprintf( stderr, "\nString Offset is %d\n",
  149. LineDescription[desc].LineStruct[i].StringId);
  150. #endif
  151. for (cbChar = 0,
  152. floatBits = LineDescription[desc].LineStruct[i].FloatBits;
  153. ( *(character = DataBuffer + cbChar +
  154. LineDescription[desc].LineStruct[i].StringId)
  155. != NULL) &&
  156. floatBits &&
  157. (cbChar < LineDescription[desc].LineStruct[i].FloatBits);
  158. cbChar++,
  159. floatBits--) {
  160. printf( "%c", *character );
  161. }
  162. printf (" ");
  163. }
  164. }
  165. break;
  166. case UCHAR_FIELD :
  167. case USHORT_FIELD :
  168. case ULONG_FIELD :
  169. if (LineDescription[desc].LineStruct[i].OptionalField ==
  170. OP_STORE_CHOICE) {
  171. switch (LineDescription[desc].LineStruct[i].FieldType) {
  172. case UCHAR_FIELD :
  173. number = (ULONG) *((UCHAR *) (DataBuffer +
  174. LineDescription[desc].LineStruct[i].StringId));
  175. break;
  176. case USHORT_FIELD :
  177. number = (ULONG) *((USHORT *) (DataBuffer +
  178. LineDescription[desc].LineStruct[i].StringId));
  179. break;
  180. case ULONG_FIELD :
  181. number = *((ULONG *) (DataBuffer +
  182. LineDescription[desc].LineStruct[i].StringId));
  183. break;
  184. }
  185. multipleChoice:
  186. i++;
  187. if (LineDescription[desc].LineStruct[i].OptionalField ==
  188. OP_MULTIPLE_CHOICE) {
  189. if (LineDescription[desc].LineStruct[i].FloatBits ==
  190. number) {
  191. printf("%s ",
  192. StringTable[LineDescription[desc].LineStruct[i].StringId]);
  193. } else {
  194. goto multipleChoice;
  195. }
  196. } else {
  197. i--;
  198. break;
  199. }
  200. break;
  201. }
  202. //
  203. // Extract the data
  204. //
  205. if (LineDescription[desc].LineStruct[i].OptionalField == OP_STORE) {
  206. #ifdef DEBUG_MONITORS
  207. fprintf( stderr, "\nNumber Offset is %d\n",
  208. LineDescription[desc].LineStruct[i].StringId);
  209. #endif
  210. switch (LineDescription[desc].LineStruct[i].FieldType) {
  211. case UCHAR_FIELD :
  212. number = (ULONG) *((UCHAR *) (DataBuffer +
  213. LineDescription[desc].LineStruct[i].StringId));
  214. break;
  215. case USHORT_FIELD :
  216. number = (ULONG) *((USHORT *) (DataBuffer +
  217. LineDescription[desc].LineStruct[i].StringId));
  218. break;
  219. case ULONG_FIELD :
  220. number = *((ULONG *) (DataBuffer +
  221. LineDescription[desc].LineStruct[i].StringId));
  222. break;
  223. }
  224. }
  225. //
  226. // Print the value
  227. //
  228. printf ("%d ", number);
  229. break;
  230. default :
  231. fprintf (stderr, "MONDMP: Internal error in parsing due to invalid field type\n");
  232. return 1;
  233. }
  234. i++;
  235. } while ( (LineDescription[desc].LineStruct[i].FieldType != NO_MORE_FIELDS) &&
  236. (i < MAX_FIELD_ENTRIES) );
  237. //
  238. // Go to the next line of input
  239. //
  240. desc++;
  241. }
  242. return 0;
  243. }