From bb4f0971acc3dba285c8dcddd0b62f210639f687 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 28 Feb 2025 15:06:22 -0500 Subject: listamsb: don't print a closing " if there isn't one. --- listamsb.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'listamsb.c') diff --git a/listamsb.c b/listamsb.c index eda6d9d..5558e63 100644 --- a/listamsb.c +++ b/listamsb.c @@ -316,25 +316,24 @@ int next_line(void) { byte = read_prog_byte(); if(in_string) { - if(byte == 0x00 || byte == '|') { - /* end of string */ + /* null byte ends both the string and the line of code. + don't print a closing quote because AMSB doesn't. */ + if(byte == 0x00) break; + if (byte == '|') { + /* pipe is how AMSB stores the closing quote. end the string + but not the line of code, and print a " character. */ in_string = 0; if(printing) putc('"', outfile); - - /* if we read a null, that means the line ends with a string - that's missing its closing double-quote. */ - if(byte == 0x00) { - break; - } else { - continue; + } else { + /* normal string character. */ + if(printing) { + putc(byte, outfile); + /* one " character embedded in a string gets printed as "" */ + if(byte == '"') putc(byte, outfile); } } - if(printing) { - putc(byte, outfile); - /* one " character embedded in a string gets printed as "" */ - if(byte == '"') putc(byte, outfile); - } } else if(in_comment) { + /* null byte ends both the comment and the line of code. */ if(byte == 0x00) break; if(printing) putc(byte, outfile); } else if(byte == ':') { @@ -348,6 +347,7 @@ int next_line(void) { in_string = 1; if(printing) putc(byte, outfile); } else if(was_ff) { + /* previous token was $ff, so this is a function token */ if(byte >= MIN_EXT_TOK && byte <= MAX_EXT_TOK) { if(printing) fputs(ext_tokens[byte - MIN_EXT_TOK], outfile); } else { @@ -356,15 +356,19 @@ int next_line(void) { } was_ff = 0; } else if(byte == 0xff) { + /* next token will be a function token */ was_ff = 1; } else if(byte >= MIN_STD_TOK && byte <= MAX_STD_TOK) { + /* statement token */ if(printing) fputs(std_tokens[byte - MIN_STD_TOK], outfile); if(byte == TOK_SQUOTE || byte == TOK_BANG || byte == TOK_REM) in_comment = 1; } else if(byte >= 0x80) { + /* invalid token */ if(printing) unknown_token(byte, 0); warnings++; } else { + /* null byte means the line of code is done */ if(!byte) break; if(byte < 0x20) { /* ATASCII graphics outside of a string */ -- cgit v1.2.3