From 1eacec796ce359097e9cf312fe0e1c26eeffd5ef Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 22 Jun 2024 13:25:04 -0400 Subject: bas.c: add on_trailing_garbage callback. --- bas.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bas.c b/bas.c index b296b2e..8b62837 100644 --- a/bas.c +++ b/bas.c @@ -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); } } -- cgit v1.2.3