summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-07-21 17:46:02 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-07-21 17:49:16 -0400
commit4a245d3885f99169649cc45e2d1abe606c249d22 (patch)
tree283dc9f8a88a29a9434bb05f6ae86a98190b0559 /eval.c
parent49fa21d023feb89e236ad4d655d96dde3574560e (diff)
downloadbfs-4a245d3885f99169649cc45e2d1abe606c249d22.tar.xz
Implement -printx
Also from NetBSD.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 34ccba8..1d2da7c 100644
--- a/eval.c
+++ b/eval.c
@@ -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) {