home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / rettig.zip / TRSOURCE.EXE / MEMDUMP.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  3KB  |  97 lines

  1. /*********
  2. *
  3. * MEMDUMP.C
  4. *
  5. * by Ralph Davis
  6. *
  7. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  8. *
  9. *     SYNTAX:  CALL memdump with <memvar>
  10. *
  11. * PARAMETERS:  <exp> is any type memory variable
  12. *
  13. *    RETURNS:  No return value.
  14. *
  15. *    PURPOSE:  Gives memory dump of requested variable.
  16. *
  17. *********/
  18.  
  19. #include "trlib.h"
  20.  
  21. void memdump(s)
  22. char *s;
  23. {
  24.    extern segment(), offset();     /* To get address of s */
  25.    extern _xsavescr(), _xrestscr();  /* Clipper functions to save
  26.                                       and restore screen */
  27.    extern _tr_scroll();           /* TR.LIB procedure to clear screen */
  28.    static char t[5] = "    ";    /* For segment address as hex string */
  29.    static char u[5] = "    ";    /* For offset address as hex string */
  30.    static char prompt[] = "\n\nPress any key to continue...";
  31.    char *scrbuff;                /* Screen save buffer */
  32.    int i,j, varseg, varoff;
  33.  
  34.    /* Parameters for scroll() */
  35.  
  36.    double lhrow = 0.0, lhcol = 0.0, rhrow = 24.0, rhcol = 79.0, numrows = 0.0;
  37.  
  38.    scrbuff = _tr_allocmem((unsigned)4000);  /* Allocate screen save buffer */
  39.  
  40.    if (scrbuff)  /* Enough memory? */
  41.    {
  42.       _xsavescr( scrbuff );  /* Yes, save screen */
  43.       _tr_scroll(&lhrow, &lhcol, &rhrow, &rhcol, &numrows,"U");   /* Clear screen */
  44.    }
  45.    segment(s, t);    /* Get segment of s in t */
  46.    offset(s, u);     /* Get offset of s in u */
  47.    varseg = _tr_htoi(t);  /* Convert segment (now hex string) to integer */
  48.    varoff = _tr_htoi(u);  /* Convert offset (also hex string) to integer */
  49.    _tr_putch('\n');       /* Carriage return/line feed */
  50.    _tr_hexprint(varseg,4);  /* Print segment address */
  51.    _tr_putch(':');          /* Separate segment and offset with a colon */
  52.    _tr_hexprint(varoff,4);  /* Print offset address */
  53.    _tr_putch(' ');          /* Print two spaces */ 
  54.    _tr_putch(' ');
  55.  
  56.    for (i = 0; i < 8; i++)  /* Print out eight rows of 16 bytes */
  57.    {
  58.       for (j = 0; j < 16; j++)  /* Sixteen bytes per row */
  59.       {
  60.          _tr_hexprint(s[(i*16) + j],2);  /* Print byte out as two-digit
  61.                                             hex string */
  62.  
  63.          if (j != 7)
  64.             _tr_putch(' ');  /* Separate bytes by a space */
  65.          else
  66.             _tr_putch('-');  /*   but put a dash in the middle of the line,
  67.                                   to mimic DEBUG */
  68.       }
  69.       _tr_putch(' ');        /* Two spaces */
  70.       _tr_putch(' ');
  71.       for (j = 0; j < 16; j++)  /* Now print the row in ASCII */
  72.          _tr_ascprint(s[(i*16) + j]);
  73.  
  74.       _tr_putch('\n');          /* Skip a line */
  75.  
  76.       if (i < 7)
  77.       {
  78.          varoff += 16;          /* Increase offset by sixteen */
  79.         _tr_hexprint(varseg,4); /* Print segment of variable */
  80.         _tr_putch(':');         /* Print colon */ 
  81.         _tr_hexprint(varoff,4); /* Print new offset address */ 
  82.         _tr_putch(' ');         /* Two spaces till we start the line */ 
  83.         _tr_putch(' ');
  84.       }
  85.    }
  86.    for (i = 0; prompt[i]; i++)  /* "Press any key to continue..." */
  87.       _tr_putch( prompt[i]);
  88.    _tr_getch();                 /* Wait for keypress */
  89.  
  90.    if (scrbuff)                 /* If original screen was saved */ 
  91.    {
  92.       _xrestscr( scrbuff );      /*   restore it */
  93.       _tr_freemem( scrbuff,(unsigned)4000);   /*   and release the memory */
  94.    }
  95. }
  96.  
  97.