summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2020-09-20 15:38:45 -0400
committerBenji Dial <benji6283@gmail.com>2020-09-20 15:38:45 -0400
commit7ec5323d1b3d80567de896fbf00e305a1e0d5bc3 (patch)
treedd37a5fd80525a0c5d03e973db553ae84d106e86 /src/user
parentfadd46012c9974931add6c36e69636d3cbc6906f (diff)
downloadportland-os-7ec5323d1b3d80567de896fbf00e305a1e0d5bc3.tar.gz
new dumphex, abbreviates runs of zeros
Diffstat (limited to 'src/user')
-rw-r--r--src/user/dumphex/dumphex.c82
1 files changed, 67 insertions, 15 deletions
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 <knob/user.h>
#include <knob/format.h>
+#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