home *** CD-ROM | disk | FTP | other *** search
- program hexdump;
-
- uses {$LOAD hexdump.dump}
- {$U PasLibIntf.p} PasLibIntf,
- {$U IntEnv.p } IntEnv;
- var
- i,j,k,l: integer; {a bunch of integers I might need
- (let's here it for FORTRAN)}
- marker : integer; {to mark eof in asciistring}
- fileEnd,rezOut:boolean; {my way to mark end of file, and -r option}
-
- function GetChar: char;
- var
- theChar:char;
- wasEoln: boolean;
- begin
- {check to see if the next character is an eoln char,
- because Pascal is will return an eoln as a space }
- if eoln then wasEoln := true else wasEoln := false;
- read(input, theChar);
- if wasEoln and not eof then {this is because eoln is true at the end of the file}
- GetChar := chr(13)
- else if eof then
- GetChar := ' ' {we're liable to be called even if already at eof...}
- else
- GetChar := theChar;
- end;
-
- function Get16Chars: string;
- var
- i:integer;
- begin
- Get16Chars := '';
- marker := 16; {the marker is in case we reach eof, so we know how
- many of the 16 are actually good characters.}
- for i:=1 to 16 do
- begin
- Get16Chars[i] := GetChar;
- if eof and (marker=16) then marker := i-1;
- end;
- end;
-
- function HexByte(theChar:char):string;
- var
- i,hiNybble,loNybble: integer;
-
- begin {turn a byte into a 2-digit hex string}
- hiNybble:= ord(theChar) div 16;
- loNybble:= ord(theChar) mod 16;
- HexByte[0] := chr(2);
- if fileEnd then {if we're past eof on a line of 16 chars, make it spaces}
- HexByte:= ' '
- else
- begin
- if hiNybble <= 9 then
- HexByte[1] := chr(hiNybble + ord('0'))
- else
- HexByte[1] := chr(hiNybble - 10 + ord('A'));
- if loNybble <= 9 then
- HexByte[2] := chr(loNybble + ord('0'))
- else
- HexByte[2] := chr(loNybble - 10 + ord('A'));
- end;
- end;
-
- procedure ProcessTheFile;
- var
- i,j:integer;
- asciiString:string;
- begin
- while not eof do
- begin
- asciiString := Get16Chars;
- if rezOut then write(output, '"$');
- i:=1;
- repeat
- for j:=0 to 1 do {this is to print bytes in pairs, but not print
- the second one if the first one was the last char in the file}
- begin
- if not eof or (i+j<=marker) then
- fileEnd := false
- else
- fileEnd := true;
- write(output, HexByte(asciiString[i+j]));
- end;
- write(output, ' ');
- i:=i+2;
- until i>15;
- if rezOut then
- write(output,'" /* |')
- else
- write(output,' |');
- for i:=1 to 16 do
- if (ord(asciiString[i])<32) or (ord(asciiString[i])=127) then
- write(output,chr(255))
- else
- write(output,asciiString[i]);
- if rezOut then
- writeln(output,'| */')
- else
- writeln(output,'|');
- end;
- end;
-
- procedure OpenTheFile;
- begin
- if argC>1 then {check to see if they want Rez-type output}
- if argV^[1]^ = '-r' then rezOut:=true else rezOut:=false;
- end;
-
- {MAIN}
- begin
- OpenTheFile;
- ProcessTheFile;
- IEExit(0);
- end.