diff options
author | B. Watson <urchlay@slackware.uk> | 2024-06-22 13:25:04 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-06-22 13:25:04 -0400 |
commit | 1eacec796ce359097e9cf312fe0e1c26eeffd5ef (patch) | |
tree | 2deff9277d475b640b4804a1f055bbb4407f3841 | |
parent | 3348585aaeecf700d7fbe596b1b0e084f3c17117 (diff) | |
download | bw-atari8-tools-1eacec796ce359097e9cf312fe0e1c26eeffd5ef.tar.gz |
bas.c: add on_trailing_garbage callback.
-rw-r--r-- | bas.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -273,15 +273,21 @@ CALLBACK_PTR(on_exp_token); CALLBACK_PTR(on_var_token); CALLBACK_PTR(on_string_const); CALLBACK_PTR(on_num_const); +CALLBACK_PTR(on_trailing_garbage); #define CALL(x) if(x) (*x)(lineno, pos, program[pos], end) void walk_code(unsigned int startlineno, unsigned int endlineno) { - int linepos, nextpos, offset, soffset, lineno, pos, end, tok; + int linepos, nextpos, offset, soffset, lineno = -1, tmpno, pos, end, tok; linepos = codestart; while(linepos < filelen) { /* loop over lines */ - lineno = getword(linepos); + tmpno = getword(linepos); + if(tmpno <= lineno) { + fprintf(stderr, "Warning: line number %d at offset $%04x is <= previous line number %d.\n", + tmpno, linepos, lineno); + } + lineno = tmpno; offset = program[linepos + 2]; nextpos = linepos + offset; @@ -355,7 +361,13 @@ void walk_code(unsigned int startlineno, unsigned int endlineno) { CALL(on_end_line); - if(lineno >= endlineno) break; linepos = nextpos; + if(lineno >= endlineno) break; + } + + if(endlineno == 32768 && linepos < filelen) { + if(verbose) + fprintf(stderr, "%s: Trailing garbage at EOF, %d bytes.\n", self, filelen - linepos); + CALL(on_trailing_garbage); } } |