diff options
-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: |