From 2199c8b55dcd34334ef71f12707e17704f1b3d10 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 2 Sep 2015 11:34:46 -0400 Subject: Print the root file/directory too. --- color.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'color.c') diff --git a/color.c b/color.c index 521fd09..d994d17 100644 --- a/color.c +++ b/color.c @@ -10,11 +10,13 @@ *********************************************************************/ #include "color.h" +#include "bftw.h" #include #include #include #include #include +#include typedef struct ext_color ext_color; @@ -280,28 +282,23 @@ static void print_esc(const char *esc, FILE *file) { fputs("m", file); } -void pretty_print(const color_table *colors, const char *fpath, const struct stat *sb) { +void pretty_print(const color_table *colors, const char *fpath, const struct BFTW *ftwbuf) { if (!colors) { puts(fpath); return; } - const char *filename = strrchr(fpath, '/'); - if (filename) { - ++filename; - } else { - filename = fpath + strlen(fpath); - } + const char *filename = fpath + ftwbuf->base; if (colors->dir) { print_esc(colors->dir, stdout); } - fwrite(fpath, 1, filename - fpath, stdout); + fwrite(fpath, 1, ftwbuf->base, stdout); if (colors->dir) { print_esc(colors->reset, stdout); } - const char *color = file_color(colors, filename, sb); + const char *color = file_color(colors, filename, ftwbuf->statbuf); if (color) { print_esc(color, stdout); } -- cgit v1.2.3