summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-11-02 19:09:57 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-11-02 19:09:57 -0400
commit2d0b6b31caff9405ae551079ca67e9f1061f9afc (patch)
tree9d7ad529a09268f4987797f375000438876eba9a /parse.c
parentc7a684d16808f0062284a0737503451894be4ce9 (diff)
downloadbfs-2d0b6b31caff9405ae551079ca67e9f1061f9afc.tar.xz
parse: Use a better reference point for incomplete expression errors
This makes `bfs -not type d` complain about nothing following the `-not` rather than the `d`.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 4103e0b..7010f05 100644
--- a/parse.c
+++ b/parse.c
@@ -340,6 +340,8 @@ struct parser_state {
/** Whether an information option like -help or -version was passed. */
bool just_info;
+ /** The last non-path argument. */
+ const char *last_arg;
/** A "-depth"-type argument if any. */
const char *depth_arg;
/** A "-prune"-type argument if any. */
@@ -462,6 +464,10 @@ static char **parser_advance(struct parser_state *state, enum token_type type, s
}
}
+ if (type != T_PATH) {
+ state->last_arg = *state->argv;
+ }
+
char **argv = state->argv;
state->argv += argc;
return argv;
@@ -2707,7 +2713,7 @@ static struct expr *parse_factor(struct parser_state *state) {
const char *arg = state->argv[0];
if (!arg) {
- cfprintf(cerr, "%{er}error: Expression terminated prematurely after '%s'.%{rs}\n", state->argv[-1]);
+ cfprintf(cerr, "%{er}error: Expression terminated prematurely after '%s'.%{rs}\n", state->last_arg);
return NULL;
}
@@ -3090,6 +3096,7 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) {
.warn = stdin_tty,
.non_option_seen = false,
.just_info = false,
+ .last_arg = NULL,
.depth_arg = NULL,
.prune_arg = NULL,
};