home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
PASCAL
/
MADTRB21.ZIP
/
VARDUMP.SRC
< prev
next >
Wrap
Text File
|
1985-10-26
|
2KB
|
59 lines
{->>>>VarDump<<<<----------------------------------------------}
{ }
{ Filename: VARDUMP.SRC -- Last modified 10/26/85 }
{ }
{ This routine displays a hexdump of ANY arbitrary variable, }
{ regardless of type. The variable to be dumped is passed in }
{ Target, and the size of Target (calculated using SizeOf to }
{ be safe) is passed in ItSize. Target is untyped and can }
{ accept as its actual parameter ANY valid type except a file }
{ type. The hex dump is sent to Device, which can be any open }
{ text file including CON (for output to the console) and PRN }
{ (for output to the system printer.) }
{ }
{ VarDump calls WriteHex, which must appear before it in the }
{ compilable source file. }
{--------------------------------------------------------------}
PROCEDURE VarDump(VAR Device : Text; VAR Target; ItSize : Integer);
CONST
Printables : SET OF Char = [' '..'}'];
VAR
I,J : Integer;
Full,Left : Integer;
Dumpit : ARRAY[0..MaxInt] OF Byte ABSOLUTE Target;
PROCEDURE DumpLine(Offset,ByteCount : Integer);
VAR
I : Integer;
BEGIN
FOR I := 0 TO ByteCount-1 DO { Hex dump the data }
BEGIN
WriteHex(Device,Dumpit[(Offset*16)+I]);
Write(Device,' ')
END;
FOR I := 0 TO 56 - (ByteCount*3) DO Write(Device,' '); { Space interval }
Write(Device,'|'); { Show first boundary bar }
FOR I := 0 TO ByteCount-1 DO { Show printable equivalents }
IF Chr(Dumpit[(Offset*16)+I]) IN Printables THEN
Write(Device,Chr(Dumpit[(Offset*16)+I]))
ELSE Write(Device,'.');
Writeln(Device,'|') { Final boundary bar }
END;
BEGIN
Full := ItSize DIV 16; { Number of 16-byte chunks in TARGET }
Left := ItSize MOD 16; { 'Leftover' bytes after last 16-byte chunk }
FOR I := 0 TO Full-1 DO { Not executed if less than 16 bytes in TARGET }
DumpLine(I,16);
IF LEFT > 0 THEN { Not executed if size of TARGET divides by 16 }
DumpLine(Full,Left);
Writeln(Device) { Space down one line after dump }
END; { VarDump }