diff options
author | XANTRONIX Development | 2023-09-13 17:35:16 -0400 |
---|---|---|
committer | XANTRONIX Development | 2023-09-13 17:35:16 -0400 |
commit | 1b8430ae844e6465915b1841dd8863e5220e3b77 (patch) | |
tree | 0de22ce3b68d71859909749b49983ec5274d3144 /src | |
parent | b98f0041a61740cb1572e30a294c19ca917a76ac (diff) | |
download | zxdump-1b8430ae844e6465915b1841dd8863e5220e3b77.tar.gz zxdump-1b8430ae844e6465915b1841dd8863e5220e3b77.tar.bz2 zxdump-1b8430ae844e6465915b1841dd8863e5220e3b77.zip |
Nailed it
Diffstat (limited to 'src')
-rw-r--r-- | src/basic.c | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/src/basic.c b/src/basic.c index e6eb4bb..d823ec7 100644 --- a/src/basic.c +++ b/src/basic.c @@ -28,6 +28,10 @@ static inline enum zx_basic_token_type zx_basic_token_type_get(uint8_t b) { return ZX81_BASIC_TOKEN_ALNUM; } else if (codepoint == '"') { return ZX81_BASIC_TOKEN_QUOTE; + } else if (codepoint == '(') { + return ZX81_BASIC_TOKEN_PAREN_OPEN; + } else if (codepoint == ')') { + return ZX81_BASIC_TOKEN_PAREN_CLOSE; } else { return ZX81_BASIC_TOKEN_SYMBOL; } @@ -43,6 +47,10 @@ static inline enum zx_basic_token_type zx_basic_token_type_get(uint8_t b) { } else { return ZX81_BASIC_TOKEN_SYMBOL; } + } else if (ZX81_CHAR_TOKEN_INTEGRAL(b)) { + return ZX81_BASIC_TOKEN_INTEGRAL; + } else if (ZX81_CHAR_TOKEN_FLOAT(b)) { + return ZX81_BASIC_TOKEN_FLOAT; } return ZX81_BASIC_TOKEN_UNKNOWN; @@ -114,22 +122,44 @@ ssize_t zx81_basic_dump(int fd, FILE *stream) { int space = 0; - if (type == ZX_BASIC_TOKEN_ALNUM) { - if (type_last == ZX_BASIC_TOKEN_WORD) { - space = 1; - } - } else if (type == ZX_BASIC_TOKEN_QUOTE) { - if (type_last == ZX_BASIC_TOKEN_WORD) { - space = 1; - } - } else if (type == ZX_BASIC_TOKEN_SYMBOL) { - space = 0; - } else if (type == ZX_BASIC_TOKEN_WORD) { - if (type_last != ZX_BASIC_TOKEN_SYMBOL) { - space = 1; - } - } else if (ZX81_CHAR_TOKEN_INTEGRAL(c) || ZX81_CHAR_TOKEN_FLOAT(c)) { - i += 5; + switch (type) { + case ZX81_BASIC_TOKEN_ALNUM: + if (type_last == ZX81_BASIC_TOKEN_WORD) + space = 1; + + break; + + case ZX81_BASIC_TOKEN_QUOTE: + if (type_last == ZX81_BASIC_TOKEN_WORD) + space = 1; + + break; + + case ZX81_BASIC_TOKEN_PAREN_OPEN: + if (type_last == ZX81_BASIC_TOKEN_WORD) + space = 1; + + break; + + case ZX81_BASIC_TOKEN_PAREN_CLOSE: + case ZX81_BASIC_TOKEN_SYMBOL: + space = 0; + break; + + case ZX81_BASIC_TOKEN_WORD: + if (type_last != ZX81_BASIC_TOKEN_SYMBOL + && type_last != ZX81_BASIC_TOKEN_PAREN_OPEN) + space = 1; + + break; + + case ZX81_BASIC_TOKEN_INTEGRAL: + case ZX81_BASIC_TOKEN_FLOAT: + i += 5; + break; + + case ZX81_BASIC_TOKEN_UNKNOWN: + continue; } if (space && fputc(' ', stream) < 0) { @@ -143,10 +173,8 @@ ssize_t zx81_basic_dump(int fd, FILE *stream) { last = c; } - if (!ZX81_CHAR_NEWLINE(((uint8_t *)buf)[i-1])) { - if (fputc('\n', stream) < 0) { - goto error_io; - } + if (fputc('\n', stream) < 0) { + goto error_io; } } |