diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2017-07-21 17:46:02 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2017-07-21 17:49:16 -0400 |
commit | 4a245d3885f99169649cc45e2d1abe606c249d22 (patch) | |
tree | 283dc9f8a88a29a9434bb05f6ae86a98190b0559 /eval.c | |
parent | 49fa21d023feb89e236ad4d655d96dde3574560e (diff) | |
download | bfs-4a245d3885f99169649cc45e2d1abe606c249d22.tar.xz |
Implement -printx
Also from NetBSD.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -670,6 +670,44 @@ done: } /** + * -printx action. + */ +bool eval_fprintx(const struct expr *expr, struct eval_state *state) { + FILE *file = expr->cfile->file; + const char *path = state->ftwbuf->path; + + while (true) { + size_t span = strcspn(path, " \t\n\\$'\"`"); + if (fwrite(path, 1, span, file) != span) { + goto error; + } + path += span; + + char c = path[0]; + if (!c) { + break; + } + + char escaped[] = {'\\', c}; + if (fwrite(escaped, 1, sizeof(escaped), file) != sizeof(escaped)) { + goto error; + } + ++path; + } + + + if (fputc('\n', file) == EOF) { + goto error; + } + + return true; + +error: + eval_error(state); + return true; +} + +/** * -prune action. */ bool eval_prune(const struct expr *expr, struct eval_state *state) { |