dispdata.c
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 6k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /*++
  2. Copyright (c) 1992  Microsoft Corporation
  3. Module Name:
  4.     Dispdata.c
  5. Abstract:
  6.     This module contains the DisplayData function which is part of the
  7.     Configuration Registry Tools (CRTools) library.
  8. Author:
  9.     David J. Gilman (davegi) 02-Jan-1992
  10. Environment:
  11.     Windows, Crt - User Mode
  12. --*/
  13. #include <ctype.h>
  14. #include <stdio.h>
  15. #include "crtools.h"
  16. VOID
  17. DisplayData(
  18.     IN PBYTE ValueData,
  19.     IN DWORD ValueDataLength
  20.     )
  21. /*++
  22. Routine Description:
  23.     Display (on stdout) the supplied data in hex and ascii formats, in
  24.     16 byte chunks.
  25. Arguments:
  26.     ValueData - Supplies a pointer to the data to display.
  27.     ValueDataLength - Supplies the number of bytes of data to display.
  28. Return Value:
  29.     None.
  30. --*/
  31. {
  32.     DWORD       DataIndex;
  33.     DWORD       DataIndex2;
  34.     WORD        SeperatorChars;
  35.     ASSERT( ARGUMENT_PRESENT( ValueData ));
  36.     //
  37.     // DataIndex2 tracks multiples of 16.
  38.     //
  39.     DataIndex2 = 0;
  40.     //
  41.     // Display label.
  42.     //
  43.     printf( "Data:nn" );
  44.     //
  45.     // Display rows of 16 bytes of data.
  46.     //
  47.     for(
  48.         DataIndex = 0;
  49.         DataIndex < ( ValueDataLength >> 4 );
  50.         DataIndex++,
  51.         DataIndex2 = DataIndex << 4 ) {
  52.         printf( "%08x   "
  53.                 "%02x %02x %02x %02x %02x %02x %02x %02x - "
  54.                 "%02x %02x %02x %02x %02x %02x %02x %02x  "
  55.                 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%cn",
  56.                 DataIndex2,
  57.                 ValueData[ DataIndex2 + 0  ],
  58.                 ValueData[ DataIndex2 + 1  ],
  59.                 ValueData[ DataIndex2 + 2  ],
  60.                 ValueData[ DataIndex2 + 3  ],
  61.                 ValueData[ DataIndex2 + 4  ],
  62.                 ValueData[ DataIndex2 + 5  ],
  63.                 ValueData[ DataIndex2 + 6  ],
  64.                 ValueData[ DataIndex2 + 7  ],
  65.                 ValueData[ DataIndex2 + 8  ],
  66.                 ValueData[ DataIndex2 + 9  ],
  67.                 ValueData[ DataIndex2 + 10 ],
  68.                 ValueData[ DataIndex2 + 11 ],
  69.                 ValueData[ DataIndex2 + 12 ],
  70.                 ValueData[ DataIndex2 + 13 ],
  71.                 ValueData[ DataIndex2 + 14 ],
  72.                 ValueData[ DataIndex2 + 15 ],
  73.                 isprint( ValueData[ DataIndex2 + 0  ] )
  74.                     ? ValueData[ DataIndex2 + 0  ]  : '.',
  75.                 isprint( ValueData[ DataIndex2 + 1  ] )
  76.                     ? ValueData[ DataIndex2 + 1  ]  : '.',
  77.                 isprint( ValueData[ DataIndex2 + 2  ] )
  78.                     ? ValueData[ DataIndex2 + 2  ]  : '.',
  79.                 isprint( ValueData[ DataIndex2 + 3  ] )
  80.                     ? ValueData[ DataIndex2 + 3  ]  : '.',
  81.                 isprint( ValueData[ DataIndex2 + 4  ] )
  82.                     ? ValueData[ DataIndex2 + 4  ]  : '.',
  83.                 isprint( ValueData[ DataIndex2 + 5  ] )
  84.                     ? ValueData[ DataIndex2 + 5  ]  : '.',
  85.                 isprint( ValueData[ DataIndex2 + 6  ] )
  86.                     ? ValueData[ DataIndex2 + 6  ]  : '.',
  87.                 isprint( ValueData[ DataIndex2 + 7  ] )
  88.                     ? ValueData[ DataIndex2 + 7  ]  : '.',
  89.                 isprint( ValueData[ DataIndex2 + 8  ] )
  90.                     ? ValueData[ DataIndex2 + 8  ]  : '.',
  91.                 isprint( ValueData[ DataIndex2 + 9  ] )
  92.                     ? ValueData[ DataIndex2 + 9  ]  : '.',
  93.                 isprint( ValueData[ DataIndex2 + 10 ] )
  94.                     ? ValueData[ DataIndex2 + 10 ]  : '.',
  95.                 isprint( ValueData[ DataIndex2 + 11 ] )
  96.                     ? ValueData[ DataIndex2 + 11 ]  : '.',
  97.                 isprint( ValueData[ DataIndex2 + 12 ] )
  98.                     ? ValueData[ DataIndex2 + 12 ]  : '.',
  99.                 isprint( ValueData[ DataIndex2 + 13 ] )
  100.                     ? ValueData[ DataIndex2 + 13 ]  : '.',
  101.                 isprint( ValueData[ DataIndex2 + 14 ] )
  102.                     ? ValueData[ DataIndex2 + 14 ]  : '.',
  103.                 isprint( ValueData[ DataIndex2 + 15 ] )
  104.                     ? ValueData[ DataIndex2 + 15 ]  : '.'
  105.                 );
  106.     }
  107.     //
  108.     // If the ValueDataLength is not an even multiple of 16
  109.     // then there is one additonal line of data to display.
  110.     //
  111.     if( ValueDataLength % 16 != 0 ) {
  112.         //
  113.         // No seperator characters displayed so far.
  114.         //
  115.         SeperatorChars = 0;
  116.         printf( "%08x   ", DataIndex << 4 );
  117.         //
  118.         // Display the remaining data, one byte at a time in hex.
  119.         //
  120.         for(
  121.             DataIndex = DataIndex2;
  122.             DataIndex < ValueDataLength;
  123.             DataIndex++ ) {
  124.             printf( "%02x ", ValueData[ DataIndex ] );
  125.             //
  126.             // If eight data values have been displayed, print
  127.             // the seperator.
  128.             //
  129.             if( DataIndex % 8 == 7 ) {
  130.                 printf( "- " );
  131.                 //
  132.                 // Remember that two seperator characters were
  133.                 // displayed.
  134.                 //
  135.                 SeperatorChars = 2;
  136.             }
  137.         }
  138.         //
  139.         // Fill with blanks to the printable characters position.
  140.         // That is position 63 less 8 spaces for the 'address',
  141.         // 3 blanks, 3 spaces for each value displayed, possibly
  142.         // two for the seperator plus two blanks at the end.
  143.         //
  144.         printf( "%*c",
  145.                 64
  146.                 - ( 8 + 3
  147.                 + (( DataIndex % 16 ) * 3 )
  148.                 + SeperatorChars
  149.                 + 2 ), ' ' );
  150.         //
  151.         // Display the remaining data, one byte at a time as
  152.         // printable characters.
  153.         //
  154.         for(
  155.             DataIndex = DataIndex2;
  156.             DataIndex < ValueDataLength;
  157.             DataIndex++ ) {
  158.             printf( "%c",
  159.                 isprint( ValueData[ DataIndex ] )
  160.                     ? ValueData[ DataIndex ] : '.'
  161.                 );
  162.         }
  163.         printf( "n" );
  164.     }
  165. }