From e614308b846478e20d548c81bc66d54b35e3292c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 30 Aug 2015 18:00:04 -0400 Subject: Add support for -true and -false. --- bfs.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/bfs.c b/bfs.c index 09f4e89..d5d1dc2 100644 --- a/bfs.c +++ b/bfs.c @@ -174,18 +174,10 @@ static const char *skip_paths(parser_state *state) { } /** - * Always true. + * -false test. */ -static bool eval_true(const char *fpath, const struct BFTW *ftwbuf, const cmdline *cl, const expression *expr, int *ret) { - return true; -} - -/** - * -print action. - */ -static bool eval_print(const char *fpath, const struct BFTW *ftwbuf, const cmdline *cl, const expression *expr, int *ret) { - pretty_print(cl->colors, fpath, ftwbuf->statbuf); - return true; +static bool eval_false(const char *fpath, const struct BFTW *ftwbuf, const cmdline *cl, const expression *expr, int *ret) { + return false; } /** @@ -215,6 +207,21 @@ static bool eval_nohidden(const char *fpath, const struct BFTW *ftwbuf, const cm } } +/** + * -print action. + */ +static bool eval_print(const char *fpath, const struct BFTW *ftwbuf, const cmdline *cl, const expression *expr, int *ret) { + pretty_print(cl->colors, fpath, ftwbuf->statbuf); + return true; +} + +/** + * -true test. + */ +static bool eval_true(const char *fpath, const struct BFTW *ftwbuf, const cmdline *cl, const expression *expr, int *ret) { + return true; +} + /** * -type test. */ @@ -283,6 +290,8 @@ static expression *parse_literal(parser_state *state) { } else if (strcmp(arg, "-nocolor") == 0) { state->cl->color = false; return new_expression(NULL, NULL, eval_true, 0); + } else if (strcmp(arg, "-false") == 0) { + return new_expression(NULL, NULL, eval_false, 0); } else if (strcmp(arg, "-hidden") == 0) { return new_expression(NULL, NULL, eval_hidden, 0); } else if (strcmp(arg, "-nohidden") == 0) { @@ -292,6 +301,8 @@ static expression *parse_literal(parser_state *state) { return new_expression(NULL, NULL, eval_print, 0); } else if (strcmp(arg, "-prune") == 0) { return new_expression(NULL, NULL, eval_prune, 0); + } else if (strcmp(arg, "-true") == 0) { + return new_expression(NULL, NULL, eval_true, 0); } else if (strcmp(arg, "-type") == 0) { return parse_type(state); } else { -- cgit v1.2.3