diff options
author | XANTRONIX Development | 2023-09-11 20:47:33 -0400 |
---|---|---|
committer | XANTRONIX Development | 2023-09-11 20:47:33 -0400 |
commit | b24b0f33d24b508b9ffcd1458dc7fd70e2add785 (patch) | |
tree | 356a4fa3f9e77595110593b8c5f05b75ebfe6da6 | |
parent | cbd7bf625b8df13ea93cb48c485099f6d058f515 (diff) | |
download | zxdump-b24b0f33d24b508b9ffcd1458dc7fd70e2add785.tar.gz zxdump-b24b0f33d24b508b9ffcd1458dc7fd70e2add785.tar.bz2 zxdump-b24b0f33d24b508b9ffcd1458dc7fd70e2add785.zip |
Think I nailed it?
-rw-r--r-- | main.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -40,6 +40,9 @@ #define ZX_CHAR_TOKEN_HIGH(c) \ (c >= 0xc0) +#define ZX_CHAR_TOKEN(c) \ + (ZX_CHAR_TOKEN_LOW(c) || ZX_CHAR_TOKEN_HIGH(c)) + #define ZX_BASIC_STATE_LEN 116 #define ZX_CHAR_TOKEN_INTEGRAL(c) \ @@ -268,7 +271,7 @@ static ssize_t zx_dump_basic(int fd) { while (1) { ssize_t readlen, len, i; zx_basic_line line; - uint8_t last = 0; + uint8_t last = 0xc0; if ((readlen = read(fd, &line, sizeof(line))) < 0) { goto error_io; @@ -276,27 +279,30 @@ static ssize_t zx_dump_basic(int fd) { break; } + len = le16toh(line.len); + + if (be16toh(line.num) == len) { + break; + } + if (printf("%d", (int)be16toh(line.num)) < 0) { goto error_io; } - len = le16toh(line.len); - if (read(fd, buf, len) < 0) { goto error_io; } for (i=0; i<len; i++) { uint8_t c = ((uint8_t *)buf)[i]; + int token = ZX_CHAR_TOKEN(c), + token_last = ZX_CHAR_TOKEN(last); - if (ZX_CHAR_TOKEN_LOW(c) || ZX_CHAR_TOKEN_HIGH(c) - || ZX_CHAR_TOKEN_LOW(last) || ZX_CHAR_TOKEN_HIGH(last)) { + if (token || token_last) { if (putchar(' ') < 0) { goto error_io; } - } - - if (ZX_CHAR_TOKEN_INTEGRAL(c) || ZX_CHAR_TOKEN_FLOAT(c)) { + } else if (ZX_CHAR_TOKEN_INTEGRAL(c) || ZX_CHAR_TOKEN_FLOAT(c)) { i += 5; } |