home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ioctlapi.zip / appsrc.zip / util.c < prev    next >
C/C++ Source or Header  |  1999-11-16  |  2KB  |  75 lines

  1. //-----------------------------------------------------------------------------
  2. // Freeware.  This file may be used freely to promote the ioctl90 mixer API.
  3. //-----------------------------------------------------------------------------
  4.  
  5. #include <stdio.h>
  6. #include <string.h>     // memcpy
  7.  
  8. #include <os2.h>
  9.  
  10. #include "data.h"
  11. #include "util.h"
  12.  
  13.                 /*                                      ----------------------------- HexDump -
  14. ** Display data buffer (debug support)
  15. ** 16 bytes per line with ascii on right
  16. ** Output lines will look like the following
  17. ** *  OFFSET   +0       +4         +8       +C                          ";
  18. ** " 00000000  00000000 00000000 - 00000000 00000000  *................*";
  19. */
  20. void HexDump (char *pszComment, BYTE *pbBuf, unsigned uBufSize)
  21. {
  22.    char AsciiData[17];
  23.    unsigned I, J;
  24.    BYTE bTemp;
  25.    BYTE *pbTmp;
  26.  
  27.    if ( pszComment && *pszComment )
  28.    {
  29.       printf ("* %s\n*\n", pszComment);
  30.    }
  31.  
  32.    AsciiData[16] = '\0';
  33.  
  34.    if ((pbBuf == NULL) ||
  35.       (uBufSize <= 0))
  36.       {
  37.       return;
  38.       }
  39.    printf (
  40.    "* OFFSET   +0       +4         +8       +C                          \n");
  41.  
  42.    for (I = 0; I < uBufSize; I=I+16)
  43.    {
  44.       if (I % 0x10 == 0)
  45.       {
  46.          printf (" %08X  ", I); // Offset
  47.       }
  48.  
  49.       for (J = 0; J < 16; J++)
  50.       {
  51.          if ((I+J) < uBufSize)
  52.          {
  53.             pbTmp = pbBuf + I + J;
  54.             bTemp = *pbTmp;
  55.             printf ("%02X", bTemp);
  56.             if (bTemp < ' ')
  57.                AsciiData[J] = '.';
  58.             else
  59.                AsciiData[J] = bTemp;
  60.          }
  61.          else
  62.          {
  63.             printf ("  ");  // Blanks in hex area
  64.             AsciiData[J] = ' ';
  65.          }
  66.  
  67.          if ((J == 3) || (J == 11))
  68.             printf (" ");
  69.          else if (J == 7)
  70.             printf (" - ");
  71.       } /* for */
  72.       printf ("  *%s*\n", AsciiData);
  73.    } /* for */
  74. }
  75.