home *** CD-ROM | disk | FTP | other *** search
- /*********
- *
- * MEMDUMP.C
- *
- * by Ralph Davis
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * SYNTAX: CALL memdump with <memvar>
- *
- * PARAMETERS: <exp> is any type memory variable
- *
- * RETURNS: No return value.
- *
- * PURPOSE: Gives memory dump of requested variable.
- *
- *********/
-
- #include "trlib.h"
-
- void memdump(s)
- char *s;
- {
- extern segment(), offset(); /* To get address of s */
- extern _xsavescr(), _xrestscr(); /* Clipper functions to save
- and restore screen */
- extern _tr_scroll(); /* TR.LIB procedure to clear screen */
- static char t[5] = " "; /* For segment address as hex string */
- static char u[5] = " "; /* For offset address as hex string */
- static char prompt[] = "\n\nPress any key to continue...";
- char *scrbuff; /* Screen save buffer */
- int i,j, varseg, varoff;
-
- /* Parameters for scroll() */
-
- double lhrow = 0.0, lhcol = 0.0, rhrow = 24.0, rhcol = 79.0, numrows = 0.0;
-
- scrbuff = _tr_allocmem((unsigned)4000); /* Allocate screen save buffer */
-
- if (scrbuff) /* Enough memory? */
- {
- _xsavescr( scrbuff ); /* Yes, save screen */
- _tr_scroll(&lhrow, &lhcol, &rhrow, &rhcol, &numrows,"U"); /* Clear screen */
- }
- segment(s, t); /* Get segment of s in t */
- offset(s, u); /* Get offset of s in u */
- varseg = _tr_htoi(t); /* Convert segment (now hex string) to integer */
- varoff = _tr_htoi(u); /* Convert offset (also hex string) to integer */
- _tr_putch('\n'); /* Carriage return/line feed */
- _tr_hexprint(varseg,4); /* Print segment address */
- _tr_putch(':'); /* Separate segment and offset with a colon */
- _tr_hexprint(varoff,4); /* Print offset address */
- _tr_putch(' '); /* Print two spaces */
- _tr_putch(' ');
-
- for (i = 0; i < 8; i++) /* Print out eight rows of 16 bytes */
- {
- for (j = 0; j < 16; j++) /* Sixteen bytes per row */
- {
- _tr_hexprint(s[(i*16) + j],2); /* Print byte out as two-digit
- hex string */
-
- if (j != 7)
- _tr_putch(' '); /* Separate bytes by a space */
- else
- _tr_putch('-'); /* but put a dash in the middle of the line,
- to mimic DEBUG */
- }
- _tr_putch(' '); /* Two spaces */
- _tr_putch(' ');
- for (j = 0; j < 16; j++) /* Now print the row in ASCII */
- _tr_ascprint(s[(i*16) + j]);
-
- _tr_putch('\n'); /* Skip a line */
-
- if (i < 7)
- {
- varoff += 16; /* Increase offset by sixteen */
- _tr_hexprint(varseg,4); /* Print segment of variable */
- _tr_putch(':'); /* Print colon */
- _tr_hexprint(varoff,4); /* Print new offset address */
- _tr_putch(' '); /* Two spaces till we start the line */
- _tr_putch(' ');
- }
- }
- for (i = 0; prompt[i]; i++) /* "Press any key to continue..." */
- _tr_putch( prompt[i]);
- _tr_getch(); /* Wait for keypress */
-
- if (scrbuff) /* If original screen was saved */
- {
- _xrestscr( scrbuff ); /* restore it */
- _tr_freemem( scrbuff,(unsigned)4000); /* and release the memory */
- }
- }
-
-