From 6f1af831012423b606586b03fbd4db0492232f48 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Sat, 23 Jan 2021 18:37:47 +0100 Subject: [PATCH] Check junk at end of line with the repeat directives. --- assemble.c | 27 ++++++--------------------- parse.c | 19 +++++++++++++++++++ parse.h | 3 +++ rept_irpc.c | 10 ++++++++++ 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/assemble.c b/assemble.c index 6d9ce23..0c1e0f5 100644 --- a/assemble.c +++ b/assemble.c @@ -25,21 +25,6 @@ -static int check_eol( - STACK *stack, - char *cp) -{ - cp = skipwhite(cp); - - if (EOL(*cp)) { - return 1; - } - - report(stack->top, "Junk at end of line ('%c')\n", *cp); - - return 0; -} - #define CHECK_EOL check_eol(stack, cp) /* assemble - read a line from the input stack, assemble it. */ @@ -281,7 +266,7 @@ static int assemble( stack_push(stack, macstr); /* Push macro expansion onto input stream */ - return 1; /* TODO: CHECK_EOL */ + return 1; } /* Try to resolve instruction or pseudo */ @@ -542,7 +527,7 @@ static int assemble( break; /* EOF */ } } - return 1; /* TODO: CHECK_EOL? */ + return 1; case P_IRP: { @@ -550,7 +535,7 @@ static int assemble( if (str) stack_push(stack, str); - return str != NULL; /* TODO: CHECK_EOL */ + return str != NULL; } case P_IRPC: @@ -559,7 +544,7 @@ static int assemble( if (str) stack_push(stack, str); - return str != NULL; /* TODO: CHECK_EOL */ + return str != NULL; } case P_LIBRARY: @@ -701,7 +686,7 @@ static int assemble( { MACRO *mac = defmacro(cp, stack, CALLED_NORMAL); - return mac != NULL; /* TODO: CHECK_EOL */ + return mac != NULL; } case P_MEXIT: @@ -730,7 +715,7 @@ static int assemble( if (reptstr) stack_push(stack, reptstr); - return reptstr != NULL; /* TODO: CHECK_EOL */ + return reptstr != NULL; } case P_ENABL: diff --git a/parse.c b/parse.c index 400c138..2ac13d2 100644 --- a/parse.c +++ b/parse.c @@ -50,6 +50,25 @@ char *skipdelim_comma( return cp; } +/* + * check_eol - check that we're at the end of a line. + * Complain if not. + */ +int check_eol( + STACK *stack, + char *cp) +{ + cp = skipwhite(cp); + + if (EOL(*cp)) { + return 1; + } + + report(stack->top, "Junk at end of line ('%s')\n", cp); + + return 0; +} + /* Parses a string from the input stream. */ /* If not bracketed by <...> or ^/.../, then */ /* the string is delimited by trailing comma or whitespace. */ diff --git a/parse.h b/parse.h index a2b71ec..9739c98 100644 --- a/parse.h +++ b/parse.h @@ -23,6 +23,9 @@ char *skipdelim_comma( SYMBOL *get_op( char *cp, char **endp); +int check_eol( + STACK *stack, + char *cp); char *getstring( char *cp, char **endp); diff --git a/rept_irpc.c b/rept_irpc.c index fec90c1..65f59b6 100644 --- a/rept_irpc.c +++ b/rept_irpc.c @@ -84,6 +84,12 @@ STREAM *expand_rept( free_tree(value); return NULL; } + /* + * Reading the next lines-to-be-repeated overwrites the line buffer + * that the caller is using. So for junk-at-end-of-line checking we + * need to do it here. + */ + check_eol(stack, value->cp); list_value(stack->top, value->data.lit); @@ -214,6 +220,8 @@ STREAM *expand_irp( return NULL; } + check_eol(stack, cp); + gb = new_buffer(); levelmod = 0; @@ -342,6 +350,8 @@ STREAM *expand_irpc( return NULL; } + check_eol(stack, cp); + gb = new_buffer(); levelmod = 0;