Oops, you ding dong
This commit is contained in:
parent
011f5e89b7
commit
3baed68df4
1 changed files with 14 additions and 14 deletions
22
main.c
22
main.c
|
@ -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,32 +88,26 @@ 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(" ") < 0) {
|
||||
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;
|
||||
|
@ -173,12 +172,13 @@ static ssize_t dump_fd(int fd) {
|
|||
}
|
||||
|
||||
offset += linesz;
|
||||
total += linesz;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
return offset;
|
||||
return total;
|
||||
|
||||
error_dump_line:
|
||||
error_read:
|
||||
|
|
Loading…
Add table
Reference in a new issue