aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bas.c18
1 files 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);
}
}