summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-03-16 23:01:00 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-03-16 23:02:33 -0400
commitc85f569daf3e0e99c9e8941d0234711afdb58cd7 (patch)
tree347db11ddb49f1f256d7d0f3f24dc15059318e8c /eval.c
parenta7c51baacf0867b1089f683b05811744f01a70af (diff)
downloadbfs-c85f569daf3e0e99c9e8941d0234711afdb58cd7.tar.xz
Give struct expr a CFILE* instead of just a FILE*
This unifies the behaviour of -print and -fprint /dev/stdout.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c50
1 files changed, 14 insertions, 36 deletions
diff --git a/eval.c b/eval.c
index 3cf8965..1a8bc02 100644
--- a/eval.c
+++ b/eval.c
@@ -11,6 +11,7 @@
#include "bfs.h"
#include "bftw.h"
+#include "color.h"
#include "dstring.h"
#include "util.h"
#include <assert.h>
@@ -687,7 +688,8 @@ bool eval_perm(const struct expr *expr, struct eval_state *state) {
* -f?ls action.
*/
bool eval_fls(const struct expr *expr, struct eval_state *state) {
- FILE *file = expr->file;
+ CFILE *cfile = expr->cfile;
+ FILE *file = cfile->file;
const struct BFTW *ftwbuf = state->ftwbuf;
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
@@ -753,14 +755,8 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) {
goto error;
}
- if (file == stdout) {
- if (cfprintf(state->cmdline->cout, " %P", ftwbuf) < 0) {
- goto error;
- }
- } else {
- if (fprintf(file, " %s", ftwbuf->path) < 0) {
- goto error;
- }
+ if (cfprintf(cfile, " %P", ftwbuf) < 0) {
+ goto error;
}
if (ftwbuf->typeflag == BFTW_LNK) {
@@ -788,20 +784,18 @@ error:
}
/**
- * -fprint action.
+ * -f?print action.
*/
bool eval_fprint(const struct expr *expr, struct eval_state *state) {
- const char *path = state->ftwbuf->path;
- if (fputs(path, expr->file) == EOF) {
- goto error;
+ CFILE *cfile = expr->cfile;
+ if (cfile->colors) {
+ fill_statbuf(state);
}
- if (fputc('\n', expr->file) == EOF) {
- goto error;
+
+ if (cfprintf(cfile, "%P\n", state->ftwbuf) < 0) {
+ eval_error(state);
}
- return true;
-error:
- eval_error(state);
return true;
}
@@ -811,7 +805,7 @@ error:
bool eval_fprint0(const struct expr *expr, struct eval_state *state) {
const char *path = state->ftwbuf->path;
size_t length = strlen(path) + 1;
- if (fwrite(path, 1, length, expr->file) != length) {
+ if (fwrite(path, 1, length, expr->cfile->file) != length) {
eval_error(state);
}
return true;
@@ -827,7 +821,7 @@ bool eval_fprintf(const struct expr *expr, struct eval_state *state) {
}
}
- if (bfs_printf(expr->file, expr->printf, state->ftwbuf) != 0) {
+ if (bfs_printf(expr->cfile->file, expr->printf, state->ftwbuf) != 0) {
eval_error(state);
}
@@ -836,22 +830,6 @@ done:
}
/**
- * -print action.
- */
-bool eval_print(const struct expr *expr, struct eval_state *state) {
- CFILE *cout = state->cmdline->cout;
- if (cout->colors) {
- fill_statbuf(state);
- }
-
- if (cfprintf(cout, "%P\n", state->ftwbuf) < 0) {
- eval_error(state);
- }
-
- return true;
-}
-
-/**
* -prune action.
*/
bool eval_prune(const struct expr *expr, struct eval_state *state) {