diff options
-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; } |