Oops, you ding dong

This commit is contained in:
XANTRONIX Development 2023-09-11 02:08:32 -04:00
parent 011f5e89b7
commit 3baed68df4

22
main.c
View file

@ -67,6 +67,10 @@ static inline int zx_putchar(uint8_t c) {
uint8_t sequence[4]; uint8_t sequence[4];
size_t len = utf8_encode(sequence, zx_charset[c]); 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) { if (fwrite(sequence, len, 1, stdout) < 1) {
goto error_io; goto error_io;
} }
@ -84,32 +88,26 @@ static ssize_t dump_line(off_t offset, void *buf, size_t len, int tty) {
goto error_io; 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 (i > 0 && (i % ZXDUMP_STRIDE_GROUP) == 0) {
if (putchar(' ') < 0) { if (putchar(' ') < 0) {
goto error_io; goto error_io;
} }
} }
if (i < len) {
if (printf("%02x", ((uint8_t *)buf)[offset+i]) < 0) { if (printf("%02x", ((uint8_t *)buf)[offset+i]) < 0) {
goto error_io; goto error_io;
} }
} else {
if (printf(" ") < 0) {
goto error_io;
}
}
} }
if (printf(" ") < 0) { if (printf(" ") < 0) {
goto error_io; 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]; uint8_t c = ((uint8_t *)buf)[offset+i];
if (c < ZXDUMP_CHARSET_LEN) { if (c <= 0x3f) {
if (zx_putchar(c) < 0) { if (zx_putchar(c) < 0) {
goto error_io; goto error_io;
} }
@ -144,7 +142,7 @@ error_io:
static ssize_t dump_fd(int fd) { static ssize_t dump_fd(int fd) {
void *buf; void *buf;
ssize_t offset = 0; ssize_t total = 0;
struct stat st; struct stat st;
if (fstat(fd, &st) < 0) { if (fstat(fd, &st) < 0) {
@ -157,6 +155,7 @@ static ssize_t dump_fd(int fd) {
while (1) { while (1) {
ssize_t len, i; ssize_t len, i;
off_t offset = 0;
if ((len = read(fd, buf, st.st_blksize)) < 0) { if ((len = read(fd, buf, st.st_blksize)) < 0) {
goto error_read; goto error_read;
@ -173,12 +172,13 @@ static ssize_t dump_fd(int fd) {
} }
offset += linesz; offset += linesz;
total += linesz;
} }
} }
free(buf); free(buf);
return offset; return total;
error_dump_line: error_dump_line:
error_read: error_read: