diff options
author | XANTRONIX Development | 2023-09-11 02:08:32 -0400 |
---|---|---|
committer | XANTRONIX Development | 2023-09-11 02:08:32 -0400 |
commit | 3baed68df43a850424c4c2c8a2c89d29e5b8eb5b (patch) | |
tree | 1b0ca580fde7146e41d27aa5b7e592688e8e7296 | |
parent | 011f5e89b7dee4b306504e243052bfaf933b2685 (diff) | |
download | zxdump-3baed68df43a850424c4c2c8a2c89d29e5b8eb5b.tar.gz zxdump-3baed68df43a850424c4c2c8a2c89d29e5b8eb5b.tar.bz2 zxdump-3baed68df43a850424c4c2c8a2c89d29e5b8eb5b.zip |
Oops, you ding dong
-rw-r--r-- | main.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -67,6 +67,10 @@ static inline int zx_putchar(uint8_t c) { uint8_t sequence[4]; size_t len = utf8_encode(sequence, zx_charset[c]); + if (c > 63) { + fprintf(stderr, "What the fuck? Got c %02x\n", c); + } + if (fwrite(sequence, len, 1, stdout) < 1) { goto error_io; } @@ -84,21 +88,15 @@ static ssize_t dump_line(off_t offset, void *buf, size_t len, int tty) { goto error_io; } - for (i=0; i<ZXDUMP_STRIDE_LINE; i++) { + for (i=0; i<len; i++) { if (i > 0 && (i % ZXDUMP_STRIDE_GROUP) == 0) { if (putchar(' ') < 0) { goto error_io; } } - if (i < len) { - if (printf("%02x", ((uint8_t *)buf)[offset+i]) < 0) { - goto error_io; - } - } else { - if (printf(" ") < 0) { - goto error_io; - } + if (printf("%02x", ((uint8_t *)buf)[offset+i]) < 0) { + goto error_io; } } @@ -106,10 +104,10 @@ static ssize_t dump_line(off_t offset, void *buf, size_t len, int tty) { goto error_io; } - for (i=0; i<ZXDUMP_STRIDE_LINE; i++) { + for (i=0; i<len; i++) { uint8_t c = ((uint8_t *)buf)[offset+i]; - if (c < ZXDUMP_CHARSET_LEN) { + if (c <= 0x3f) { if (zx_putchar(c) < 0) { goto error_io; } @@ -144,7 +142,7 @@ error_io: static ssize_t dump_fd(int fd) { void *buf; - ssize_t offset = 0; + ssize_t total = 0; struct stat st; if (fstat(fd, &st) < 0) { @@ -157,6 +155,7 @@ static ssize_t dump_fd(int fd) { while (1) { ssize_t len, i; + off_t offset = 0; if ((len = read(fd, buf, st.st_blksize)) < 0) { goto error_read; @@ -166,19 +165,20 @@ static ssize_t dump_fd(int fd) { for (i=0; i<len; i+=ZXDUMP_STRIDE_LINE) { size_t left = len - i, - linesz = left < ZXDUMP_STRIDE_LINE? left: ZXDUMP_STRIDE_LINE; + linesz = left < ZXDUMP_STRIDE_LINE? left: ZXDUMP_STRIDE_LINE; if (dump_line(offset, buf, linesz, isatty(fileno(stdout))) < 0) { goto error_dump_line; } offset += linesz; + total += linesz; } } free(buf); - return offset; + return total; error_dump_line: error_read: |