home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * dumpm.c dump memory from ptr for num bytes, in hex and ASCII
- *
- */
-
- #include "cbtree.h"
- #include <ctype.h>
-
- #define hexc(x) '0' + ((x) > 9 ? (x) + 7 : (x)) /* hex nibble to ASCII */
-
- void dumpm(ptr, num)
- char *ptr;
- int num; /* number of characters tp dump */
- {
- char *p = ptr; /* ascii pointer */
- int n = num;
- char x, y;
- char displine[83];
- char *dlp = displine;
- register int j;
-
- while (num > 0)
- {
- sprintf(dlp, "\n%08lx: ", p);
- dlp += 11;
-
- for (j = 16; j-- != 0; ) /* first hex */
- {
- if (n-- == 0)
- {
- repeat
- {
- sprintf(dlp, " "); /* count exhausted */
- dlp += 3;
- }
- until(j-- == 0);
- break;
- }
- else
- {
- x = *p >> 4 & 0x0f; /* display 2 hex digits */
- y = *p++ & 0x0f;
- sprintf(dlp, "%c%c ", hexc(x), hexc(y));
- dlp += 3;
- }
- }
- sprintf(dlp, " "); /* then ascii */
- dlp += 2;
- for (j = 16; j-- != 0; )
- {
- if (num-- == 0)
- break;
- x = *ptr++ & 0x7f;
- sprintf(dlp, "%c", isprint(x) ? x : '.');
- ++dlp;
- }
- printf("%s", dlp = displine);
- }
- printf("\n");
- }
-
- #ifndef NOTEST
-
- void main() /**** test harness ****/
-
- {
-
- dumpm(main,0x33);
-
- }
-
- #endif
-
-