home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBOPAS / TP-UTIL.ARK / VARDUMP2.SRC < prev    next >
Text File  |  1986-01-06  |  2KB  |  59 lines

  1. {->>>>VarDump<<<<----------------------------------------------}
  2. {                                                              }
  3. { Filename: VARDUMP.SRC -- Last modified 10/26/85              }
  4. {                                                              }
  5. { This routine displays a hexdump of ANY arbitrary variable,   }
  6. { regardless of type.  The variable to be dumped is passed in  }
  7. { Target, and the size of Target (calculated using SizeOf to   }
  8. { be safe) is passed in ItSize.  Target is untyped and can     }
  9. { accept as its actual parameter ANY valid type except a file  }
  10. { type.  The hex dump is sent to Device, which can be any open }
  11. { text file including CON (for output to the console) and PRN  }
  12. { (for output to the system printer.)                          }
  13. {                                                              }
  14. { VarDump calls WriteHex, which must appear before it in the   }
  15. { compilable source file.                                      }
  16. {--------------------------------------------------------------}
  17.  
  18. PROCEDURE VarDump(VAR Device : Text; VAR Target; ItSize : Integer);
  19.  
  20. CONST
  21.   Printables : SET OF Char = [' '..'}'];
  22.  
  23. VAR
  24.   I,J       : Integer;
  25.   Full,Left : Integer;
  26.   Dumpit    : ARRAY[0..MaxInt] OF Byte ABSOLUTE Target;
  27.  
  28.  
  29. PROCEDURE DumpLine(Offset,ByteCount : Integer);
  30.  
  31. VAR
  32.   I : Integer;
  33.  
  34. BEGIN
  35.   FOR I := 0 TO ByteCount-1 DO               { Hex dump the data }
  36.     BEGIN
  37.       WriteHex(Device,Dumpit[(Offset*16)+I]);
  38.       Write(Device,' ')
  39.     END;
  40.   FOR I := 0 TO 56 - (ByteCount*3) DO Write(Device,' ');  { Space interval }
  41.     Write(Device,'|');                        { Show first boundary bar }
  42.   FOR I := 0 TO ByteCount-1 DO               { Show printable equivalents }
  43.     IF Chr(Dumpit[(Offset*16)+I]) IN Printables THEN
  44.       Write(Device,Chr(Dumpit[(Offset*16)+I]))
  45.     ELSE Write(Device,'.');
  46.   Writeln(Device,'|')                         { Final boundary bar }
  47. END;
  48.  
  49.  
  50. BEGIN
  51.   Full := ItSize DIV 16;   { Number of 16-byte chunks in TARGET }
  52.   Left := ItSize MOD 16;   { 'Leftover' bytes after last 16-byte chunk }
  53.   FOR I := 0 TO Full-1 DO  { Not executed if less than 16 bytes in TARGET }
  54.     DumpLine(I,16);
  55.   IF LEFT > 0 THEN         { Not executed if size of TARGET divides by 16 }
  56.     DumpLine(Full,Left);
  57.   Writeln(Device)          { Space down one line after dump }
  58. END;  { VarDump }
  59. nd duck out of proc   }