From cae04995dbb55b24e746c36a8ad326a3438d4103 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 27 Mar 2022 13:43:48 -0400 Subject: parse.c: Use state->last_arg as the location for the expected ) This lets us remove the special case for *argv == NULL. --- parse.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/parse.c b/parse.c index 493b321..6dc8f5f 100644 --- a/parse.c +++ b/parse.c @@ -324,15 +324,9 @@ static void parse_error(const struct parser_state *state, const char *format, .. int error = errno; const struct bfs_ctx *ctx = state->ctx; - // If we're at the end of the command line, highlight the last argument - char **argv = state->argv; - if (!*argv) { - --argv; - } - bool highlight[ctx->argc]; init_highlight(ctx, highlight); - highlight_args(ctx, argv, 1, highlight); + highlight_args(ctx, state->argv, 1, highlight); bfs_argv_error(ctx, highlight); va_list args; @@ -408,15 +402,9 @@ static bool parse_warning(const struct parser_state *state, const char *format, int error = errno; const struct bfs_ctx *ctx = state->ctx; - // If we're at the end of the command line, highlight the last argument - char **argv = state->argv; - if (!*argv) { - --argv; - } - bool highlight[ctx->argc]; init_highlight(ctx, highlight); - highlight_args(ctx, argv, 1, highlight); + highlight_args(ctx, state->argv, 1, highlight); if (!bfs_argv_warning(ctx, highlight)) { return false; } @@ -3458,12 +3446,12 @@ static struct bfs_expr *parse_factor(struct parser_state *state) { arg = state->argv[0]; if (!arg || strcmp(arg, ")") != 0) { - parse_error(state, "Expected a ${red})${rs}.\n"); + parse_argv_error(state, state->last_arg, 1, "Expected a ${red})${rs}.\n"); bfs_expr_free(expr); return NULL; } - parser_advance(state, T_OPERATOR, 1); + parser_advance(state, T_OPERATOR, 1); return expr; } else if (strcmp(arg, "-exclude") == 0) { if (state->excluding) { -- cgit v1.2.3