From fac227c99bd4cee6936f8c530650bca4f98e7fa7 Mon Sep 17 00:00:00 2001 From: dd86k Date: Thu, 28 Apr 2022 22:03:52 -0400 Subject: [PATCH] Fix length on dump Happened if aligned size was greater than requested length --- src/ddhx/ddhx.d | 7 ++++++- src/ddhx/file.d | 7 +++++++ src/ddhx/terminal.d | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ddhx/ddhx.d b/src/ddhx/ddhx.d index ca451b8..558c380 100644 --- a/src/ddhx/ddhx.d +++ b/src/ddhx/ddhx.d @@ -219,7 +219,12 @@ int ddhxDump(long skip, long length) { displayRenderTopRaw(); // mitigate unaligned reads/renders - io.resizeBuffer(globals.rowWidth * 16); + uint a = globals.rowWidth * 16; + io.resizeBuffer(a); + + if (a > length) { + io.resizeBuffer(cast(uint)length); + } // read until EOF or length spec long r; diff --git a/src/ddhx/file.d b/src/ddhx/file.d index 76bf1f6..3e0afa2 100644 --- a/src/ddhx/file.d +++ b/src/ddhx/file.d @@ -109,6 +109,11 @@ struct IoState { // Mostly-stateless, lazy implementation of a FILE using direct OS // functions, since File under x86-omf builds seem iffy, broken // (especially when attempting to get the size of a large file). +//TODO: redo read functions with a simpler api +// e.g., ubyte[] read(ubyte[] buffer) +// on error, sets bool error = true; +// or int error = OS errorcode +//TODO: Move this to os.file private struct OSFile { private OSHANDLE handle; private bool eof; @@ -144,6 +149,7 @@ private struct OSFile { } int seek(ref long npos, Seek origin, long pos) { + version (Trace) trace("origin=%u pos=%u", origin, pos); version (Windows) { LARGE_INTEGER liIn = void, liOut = void; liIn.QuadPart = pos; @@ -160,6 +166,7 @@ private struct OSFile { } int read(ref ubyte[] result, ubyte[] buffer) { + version (Trace) trace("buffer.length=%u", buffer.length); version (Windows) { const uint len = cast(uint)buffer.length; uint r = void; /// size read diff --git a/src/ddhx/terminal.d b/src/ddhx/terminal.d index ca68c3a..6c5809f 100644 --- a/src/ddhx/terminal.d +++ b/src/ddhx/terminal.d @@ -4,9 +4,12 @@ /// Authors: $(LINK2 github.com/dd86k, dd86k) module ddhx.terminal; +//TODO: Move this to os.terminal //TODO: Register function for terminal size change // Under Windows, that's under a regular input event // Under Linux, that's under a signal (and function pointer) +//TODO: readline +// automatically pause input, stdio.readln, resume input // NOTE: Useful links for escape codes // https://man7.org/linux/man-pages/man0/termios.h.0p.html