Forum > General
[SOLVED]A case of blindness, probably. Old hands, plz help.
Thaddy:
I found some old code by me, myself and I, but it is not correct and I can not see where it fails.
DON'T comment on the programming style - that is sound, but old -, but find the error, please... ;D
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program hexdump;{ Simple Hexdump, unix like clone. Has error! Where? This is an adapted version of my original. (c)1991-2024, Thaddy de Koning. Use as you like, no license }{$mode objfpc}{$I-}{$H-}const maxchar = 15;type TByteOrChar = packed record case boolean of false:(asByte : packed array[0..maxchar] of byte); true :(asChar : packed array[0..maxchar] of AnsiChar); end; function ByteToHex(const value:byte):string;inline; const HexDigits = '0123456789ABCDEF'; begin ByteToHex := HexDigits[hi(value)+1]+HexDigits[lo(value)+1]; end; var f: file of TByteOrChar; bor: TByteOrChar; i,r: integer;begin if ParamCount > 0 then begin Assign(f,paramstr(1)); filemode := 0; reset(f); r:= IOResult; if r = 0 then begin while not eof(f) do begin write(HexStr(FilePos(f) * 16,8):10); read(f,bor); for i := 0 to maxchar do begin write(ByteToHex(bor.asbyte[i]):3); if (bor.asbyte[i] < 32 ) or (bor.asbyte[i] > 127 ) then bor.aschar[i]:='.'; end; writeln('|':2,bor.asChar,'|'); end; close(f); end else case r of 2:writeln('File not found'); 5:writeln('Access denied'); else writeln('A less common error occurred:',r:4); end; end else writeln('Use: hexdump <filename>');end.Problem at hand is that I am missing the last line, compared to e.g. the standard hexdump on linux.
I can't see it? must be easy for old hands... 8-)
The error is the last line of the output missing.
MarkMLl:
Nothing springs out. I suspect that the issue is that the unix variant of the code first outputs an address and then looks to see how much (if any) data is to follow it, then repeats.
MarkMLl
Zvoni:
Copy line 38 between line 46 and 47
The writing of the FilePos (L38) happens within the loop, so the moment Line39 returns EOF....
EDIT: Modified to reflect Mark's answer
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program hexdump;{ Simple Hexdump, unix like clone. Has error! Where? (c)1991-2024, Thaddy de Koning. Use as you like, no license }{$mode objfpc}{$I-}{$H-}const maxchar = 15;type TByteOrChar = packed record case boolean of false:(asByte : packed array[0..maxchar] of byte); true :(asChar : packed array[0..maxchar] of AnsiChar); end; function ByteToHex(const value:byte):string;inline; const HexDigits = '0123456789ABCDEF'; begin ByteToHex := HexDigits[hi(value)+1]+HexDigits[lo(value)+1]; end; var f: file of TByteOrChar; bor: TByteOrChar; i,r: integer;begin if ParamCount > 0 then begin Assign(f,paramstr(1)); filemode := 0; reset(f); r:= IOResult; if r = 0 then begin write(HexStr(FilePos(f) * 16,8):10); //Added/Moved while not eof(f) do begin //write(HexStr(FilePos(f) * 16,8):10); read(f,bor); for i := 0 to maxchar do begin write(ByteToHex(bor.asbyte[i]):3); if (bor.asbyte[i] < 32 ) or (bor.asbyte[i] > 127 ) then bor.aschar[i]:='.'; end; writeln('|':2,bor.asChar,'|'); write(HexStr(FilePos(f) * 16,8):10); //Added end; close(f); end else case r of 2:writeln('File not found'); 5:writeln('Access denied'); else writeln('A less common error occurred:',r:4); end; end else writeln('Use: hexdump <filename>');end.
Thaddy:
TNX Zvoni and Mark! Identical output. (apart from the space, but that does not matter).
Sometimes you need 4 extra eyes... Again, thanks.
Code compiles in all modes that I use and is cross platform.
Zvoni:
--- Quote from: Thaddy on September 04, 2024, 10:13:24 am ---Identical output. (apart from the space, but that does not matter).
--- End quote ---
Line 36 / 47 in my modified code: Remove the ":10" (or change to ":8")
In Line 43 add two leading spaces to the Write
*shrug*
Navigation
[0] Message Index
[#] Next page