home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / aros / hexdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  1.8 KB  |  96 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: hexdump.c,v 1.2 1997/01/27 00:17:40 ldp Exp $
  4.  
  5.     Desc: Prints a hexdump of a memory region
  6.     Lang: english
  7. */
  8. #include <ctype.h>
  9. #include <aros/debug.h>
  10.  
  11. extern struct ExecBase * SysBase;
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME */
  16. #include <proto/aros.h>
  17.  
  18.     void hexdump (
  19.  
  20. /*  SYNOPSIS */
  21.     const void * data,
  22.     IPTR         offset,
  23.     ULONG         count)
  24.  
  25. /*  FUNCTION
  26.     Prints a hexdump of the data beginning at data. The format
  27.     is liks this:
  28.  
  29.     xxxxxxxx: dddddddd dddddddd dddddddd dddddddd aaaaaaaaaaaaaaaa
  30.  
  31.     Where x is the address (8 chars hex), dd is a data byte (2 chars
  32.     hex) and a is the ASCII representation of a data byte or "." if
  33.     the data byte is not printable.
  34.  
  35.     INPUTS
  36.     data - Start here with the dump
  37.     offset - This offset is used as the address in the output. If
  38.         you give 0L here, then the first address will be
  39.         00000000. If you give (IPTR)data here, then the
  40.         first address will be the memory address of the data.
  41.     count - How many bytes to print.
  42.  
  43.     RESULT
  44.     None.
  45.  
  46.     NOTES
  47.  
  48.     EXAMPLE
  49.  
  50.     BUGS
  51.  
  52.     SEE ALSO
  53.  
  54.     INTERNALS
  55.  
  56.     HISTORY
  57.     05-12-96    digulla created
  58.  
  59. ******************************************************************************/
  60. {
  61.     ULONG t, end;
  62.     int   i;
  63.  
  64.     end = (count + 15) & -16;
  65.  
  66.     for (t=0; t<end; t++)
  67.     {
  68.     if ((t&15) == 0)
  69.         kprintf ("%08lx:", offset+t);
  70.  
  71.     if ((t&3) == 0)
  72.         kprintf (" ");
  73.  
  74.     if (t < count)
  75.         kprintf ("%02x", ((UBYTE *)data)[t]);
  76.     else
  77.         kprintf ("  ");
  78.  
  79.     if ((t&15) == 15)
  80.     {
  81.         kprintf (" ");
  82.  
  83.         for (i=15; i>=0; i--)
  84.         {
  85.         if (isprint (((UBYTE *)data)[t-i]))
  86.             kprintf ("%c", ((UBYTE *)data)[t-i]);
  87.         else
  88.             kprintf (".");
  89.         }
  90.  
  91.         kprintf ("\n");
  92.     }
  93.     }
  94. } /* hexdump */
  95.  
  96.