diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2015-09-16 12:25:53 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2015-09-26 12:31:18 -0400 |
commit | 309c9a29e32edc07cb06e329669be7e30f8d9ed5 (patch) | |
tree | d7e82bee613d2724f99573a1e8ab3f1ab9cebf09 /color.c | |
parent | 7a60efa76f4f79a118e06b640d7af9d51f8b539e (diff) | |
download | bfs-309c9a29e32edc07cb06e329669be7e30f8d9ed5.tar.xz |
bftw() interface improvements:
- Use enums instead of ints where it makes sense
- Move the file path inside struct BFTW
- Expose a fd and relative path for *at() calls
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -282,18 +282,20 @@ static void print_esc(const char *esc, FILE *file) { fputs("m", file); } -void pretty_print(const color_table *colors, const char *fpath, const struct BFTW *ftwbuf) { +void pretty_print(const color_table *colors, const struct BFTW *ftwbuf) { + const char *path = ftwbuf->path; + if (!colors) { - puts(fpath); + puts(path); return; } - const char *filename = fpath + ftwbuf->base; + const char *filename = path + ftwbuf->nameoff; if (colors->dir) { print_esc(colors->dir, stdout); } - fwrite(fpath, 1, ftwbuf->base, stdout); + fwrite(path, 1, ftwbuf->nameoff, stdout); if (colors->dir) { print_esc(colors->reset, stdout); } @@ -309,7 +311,7 @@ void pretty_print(const color_table *colors, const char *fpath, const struct BFT fputs("\n", stdout); } -void print_error(const color_table *colors, const char *fpath, int error) { +void print_error(const color_table *colors, const char *path, int error) { const char *color = NULL; if (colors) { color = colors->orphan; @@ -318,7 +320,7 @@ void print_error(const color_table *colors, const char *fpath, int error) { if (color) { print_esc(color, stderr); } - fprintf(stderr, "Error at %s: %s\n", fpath, strerror(error)); + fprintf(stderr, "Error at %s: %s\n", path, strerror(error)); if (color) { print_esc(colors->reset, stderr); } |