From 4a245d3885f99169649cc45e2d1abe606c249d22 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 21 Jul 2017 17:46:02 -0400 Subject: Implement -printx Also from NetBSD. --- parse.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'parse.c') diff --git a/parse.c b/parse.c index f5bb5e1..d4e945c 100644 --- a/parse.c +++ b/parse.c @@ -1698,6 +1698,18 @@ static struct expr *parse_printf(struct parser_state *state, int arg1, int arg2) return expr; } +/** + * Parse -printx. + */ +static struct expr *parse_printx(struct parser_state *state, int arg1, int arg2) { + struct expr *expr = parse_nullary_action(state, eval_fprintx); + if (expr) { + expr->always_true = true; + expr->cfile = state->cmdline->cout; + } + return expr; +} + /** * Parse -prune. */ @@ -2178,6 +2190,9 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) { cfprintf(cout, " %{blu}-exit%{rs} %{bld}[STATUS]%{rs}\n"); cfprintf(cout, " Exit immediately with the given status (%d if unspecified)\n", EXIT_SUCCESS); + cfprintf(cout, " %{blu}-printx%{rs}\n"); + cfprintf(cout, " Like %{blu}-print%{rs}, but escape whitespace and quotation characters, to make the\n"); + cfprintf(cout, " output safe for %{ex}xargs%{rs}. Consider using %{blu}-print0%{rs} and %{ex}xargs%{rs} %{bld}-0%{rs} instead.\n"); cfprintf(cout, " %{blu}-rm%{rs}\n"); cfprintf(cout, " Delete any found files (same as %{blu}-delete%{rs}; implies %{blu}-depth%{rs})\n\n"); @@ -2299,6 +2314,7 @@ static const struct table_entry parse_table[] = { {"-print", false, parse_print}, {"-print0", false, parse_print0}, {"-printf", false, parse_printf}, + {"-printx", false, parse_printx}, {"-prune", false, parse_prune}, {"-quit", false, parse_quit}, {"-readable", false, parse_access, R_OK}, -- cgit v1.2.3