From bff09eb8bb9d807ca6923ab47196e38978053df6 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 13 Sep 2023 00:43:08 -0400 Subject: Do a better job of emitting whitespace --- main.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 42a12bc..1eed7e2 100644 --- a/main.c +++ b/main.c @@ -48,6 +48,14 @@ typedef struct _zx_basic_line { uint16_t num, len; } zx_basic_line; +enum zx_basic_token_type { + ZX_BASIC_TOKEN_UNKNOWN, + ZX_BASIC_TOKEN_ALNUM, + ZX_BASIC_TOKEN_QUOTE, + ZX_BASIC_TOKEN_SYMBOL, + ZX_BASIC_TOKEN_WORD, +}; + #define ZX_BASIC_STATE_SIZE 116 #define ZX_BASIC_LINE_LAST 0x7676 @@ -249,6 +257,33 @@ static inline int zx_print(uint8_t c, int tty) { return 0; } +static inline enum zx_basic_token_type zx_basic_token_type_get(uint8_t b) { + if (ZX_CHAR_LOW(b)) { + uint32_t codepoint = zx_charset[b]; + + if ((codepoint >= 'A' && codepoint <= 'Z') + || (codepoint >= '0' && codepoint <= '9')) { + return ZX_BASIC_TOKEN_ALNUM; + } else { + return ZX_BASIC_TOKEN_SYMBOL; + } + } else if (ZX_CHAR_INVERSE(b)) { + return zx_basic_token_type_get(b - ZX_CHAR_INVERSE_START); + } else if (ZX_CHAR_TOKEN_LOW(b)) { + return ZX_BASIC_TOKEN_WORD; + } else if (ZX_CHAR_TOKEN_HIGH(b)) { + char *token = zx_tokens[b-ZX_CHAR_TOKEN_HIGH_START]; + + if (token[0] >= 'A' && token[0] <= 'Z') { + return ZX_BASIC_TOKEN_WORD; + } else { + return ZX_BASIC_TOKEN_SYMBOL; + } + } + + return ZX_BASIC_TOKEN_UNKNOWN; +} + static ssize_t zx_dump_basic(int fd) { void *buf; ssize_t total = 0; @@ -294,17 +329,28 @@ static ssize_t zx_dump_basic(int fd) { for (i=0; i