diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-03-26 15:36:37 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-03-26 15:39:00 -0400 |
commit | d0565f9830b483d8f307e966e22fde01478b26df (patch) | |
tree | cb545a02b780d917880fa5474277b2bf1ac0c0a5 /parse.c | |
parent | 30e55d140074749809c419bba2a1a9fd1a4c7de9 (diff) | |
download | bfs-d0565f9830b483d8f307e966e22fde01478b26df.tar.xz |
parse: Stop warning for options after tests/actions
Part of the bfs design philosophy is to care less about the order of
arguments. As such, there's no good reason to be warning-compatible
with GNU find in this case. I don't even think things like this are
confusing:
bfs -print -color
so why warn about it?
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 51 |
1 files changed, 7 insertions, 44 deletions
@@ -244,8 +244,6 @@ struct parser_state { bool implicit_root; /** Whether the expression has started. */ bool expr_started; - /** Whether any non-option arguments have been encountered. */ - bool non_option_seen; /** Whether an information option like -help or -version was passed. */ bool just_info; /** Whether we are currently parsing an -exclude expression. */ @@ -393,10 +391,6 @@ static struct bfs_expr *parse_expr(struct parser_state *state); static char **parser_advance(struct parser_state *state, enum token_type type, size_t argc) { if (type != T_FLAG && type != T_PATH) { state->expr_started = true; - - if (type != T_OPTION) { - state->non_option_seen = true; - } } if (type != T_PATH) { @@ -628,15 +622,7 @@ static struct bfs_expr *parse_unary_flag(struct parser_state *state) { * Parse a single option. */ static struct bfs_expr *parse_option(struct parser_state *state, size_t argc) { - const char *arg = *parser_advance(state, T_OPTION, argc); - - if (state->non_option_seen) { - parse_warning(state, - "The ${blu}%s${rs} option applies to the entire command line. For clarity, place\n" - "it before any non-option arguments.\n\n", - arg); - } - + parser_advance(state, T_OPTION, argc); return &bfs_true; } @@ -655,28 +641,6 @@ static struct bfs_expr *parse_unary_option(struct parser_state *state) { } /** - * Parse a single positional option. - */ -static struct bfs_expr *parse_positional_option(struct parser_state *state, size_t argc) { - parser_advance(state, T_OPTION, argc); - return &bfs_true; -} - -/** - * Parse a positional option that doesn't take a value. - */ -static struct bfs_expr *parse_nullary_positional_option(struct parser_state *state) { - return parse_positional_option(state, 1); -} - -/** - * Parse a positional option that takes a single value. - */ -static struct bfs_expr *parse_unary_positional_option(struct parser_state *state) { - return parse_positional_option(state, 2); -} - -/** * Parse a single test. */ static struct bfs_expr *parse_test(struct parser_state *state, bfs_eval_fn *eval_fn, size_t argc) { @@ -872,14 +836,14 @@ static struct bfs_expr *parse_optlevel(struct parser_state *state, int arg1, int } /** - * Parse -[PHL], -(no)?follow. + * Parse -[PHL], -follow. */ static struct bfs_expr *parse_follow(struct parser_state *state, int flags, int option) { struct bfs_ctx *ctx = state->ctx; ctx->flags &= ~(BFTW_FOLLOW_ROOTS | BFTW_FOLLOW_ALL); ctx->flags |= flags; if (option) { - return parse_nullary_positional_option(state); + return parse_nullary_option(state); } else { return parse_nullary_flag(state); } @@ -1126,7 +1090,7 @@ static struct bfs_expr *parse_daystart(struct parser_state *state, int arg1, int state->now.tv_sec = time; state->now.tv_nsec = 0; - return parse_nullary_positional_option(state); + return parse_nullary_option(state); } /** @@ -1304,7 +1268,7 @@ static struct bfs_expr *parse_files0_from(struct parser_state *state, int arg1, return NULL; } - struct bfs_expr *expr = parse_unary_positional_option(state); + struct bfs_expr *expr = parse_unary_option(state); while (true) { char *path = xgetdelim(file, '\0'); @@ -2351,7 +2315,7 @@ static struct bfs_expr *parse_regextype(struct parser_state *state, int arg1, in goto list_types; } - return parse_unary_positional_option(state); + return parse_unary_option(state); list_types: cfprintf(cfile, "Supported types are:\n\n"); @@ -2650,7 +2614,7 @@ fail: */ static struct bfs_expr *parse_warn(struct parser_state *state, int warn, int arg2) { state->ctx->warn = warn; - return parse_nullary_positional_option(state); + return parse_nullary_option(state); } /** @@ -3777,7 +3741,6 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { .use_color = use_color, .implicit_print = true, .implicit_root = true, - .non_option_seen = false, .just_info = false, .excluding = false, .last_arg = NULL, |