From 7ec5323d1b3d80567de896fbf00e305a1e0d5bc3 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 20 Sep 2020 15:38:45 -0400 Subject: new dumphex, abbreviates runs of zeros --- src/user/dumphex/dumphex.c | 82 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 15 deletions(-) (limited to 'src/user') diff --git a/src/user/dumphex/dumphex.c b/src/user/dumphex/dumphex.c index 4c63a06..2944a2f 100644 --- a/src/user/dumphex/dumphex.c +++ b/src/user/dumphex/dumphex.c @@ -2,28 +2,80 @@ #include #include +#define LINE_LEN 16 + +void print_zero_line(uint32_t offset) { +} + void main(const char *path) { struct file *f = open_file(path); if (!f) { tell_user_sz("Couldn't open file.\n"); return; } - char buf[] = { ' ', '\0', '\0', '\0' }; - uint8_t v; - uint32_t a = 0; - while (read_from_file(f, 1, &v)) { - if (!(a & 0xf)) { - char buf2[] = {'0', 'x', '\0', '\0', '\0', '\0', - '\0', '\0', '\0', '\0', '\0' }; - itosz_h32(a, buf2 + 2); - tell_user_sz(buf2); - tell_user_sz(" |"); + + uint8_t line[LINE_LEN + 2]; + uint8_t len; + uint32_t offset = -LINE_LEN; + + enum { + ZR_NO, + ZR_FIRST, + ZR_REST + } zero_run; + + char nbuf[9]; + + while ((len = read_from_file(f, LINE_LEN, line))) { + offset += LINE_LEN; + + for (uint8_t i = 0; i < LINE_LEN; ++i) + if (line[i]) { + zero_run = ZR_NO; + goto print_normal; + } + + switch (zero_run) { + case ZR_NO: + zero_run = ZR_FIRST; + _log_string("0x"); + itosz_h32(offset, nbuf); + _log_string(nbuf); + _log_string(" | 00 00 00 00 00 00 00 00 " + "00 00 00 00 00 00 00 00 |\n"); + continue; + case ZR_FIRST: + zero_run = ZR_REST; + tell_user_sz("...\n"); + case ZR_REST: + continue; } - itosz_h8(v, buf + 1); - tell_user_sz(buf); - if (!(++a & 0xf)) - tell_user_sz("\n"); + + print_normal: + _log_string("0x"); + itosz_h32(offset, nbuf); + _log_string(nbuf); + _log_string(" |"); + + nbuf[0] = ' '; + for (uint8_t i = 0; i < len; ++i) { + itosz_h8(line[i], nbuf + 1); + _log_string(nbuf); + } + + for (uint8_t i = len; i < LINE_LEN; ++i) + _log_string(" "); + + _log_string(" | "); + + for (uint8_t i = 0; i < len; ++i) + if ((line[i] < 0x20) || (line[i] > 0x7e)) + line[i] = ' '; + line[len] = '\n'; + line[len + 1] = '\0'; + + _log_string(line); } - tell_user_sz("\n"); + close_file(f); } \ No newline at end of file -- cgit v1.2.3