summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-03-27 13:43:48 -0400
committerTavian Barnes <tavianator@tavianator.com>2022-03-27 13:43:48 -0400
commitcae04995dbb55b24e746c36a8ad326a3438d4103 (patch)
treed3303410b8cbf9483780545c347e1236f0f42740
parente53d03be299b19694d16c8cbc61dc174a7b56bbc (diff)
downloadbfs-cae04995dbb55b24e746c36a8ad326a3438d4103.tar.xz
parse.c: Use state->last_arg as the location for the expected )
This lets us remove the special case for *argv == NULL.
-rw-r--r--parse.c20
1 files 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) {