summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-09-02 11:34:46 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-09-02 11:34:46 -0400
commit2199c8b55dcd34334ef71f12707e17704f1b3d10 (patch)
treeda3c847cde3e4e0ab458539515a462b3ca020bad /color.c
parent75377a9db6f9c4e00b9d39828d955ec4443f2ce2 (diff)
downloadbfs-2199c8b55dcd34334ef71f12707e17704f1b3d10.tar.xz
Print the root file/directory too.
Diffstat (limited to 'color.c')
-rw-r--r--color.c15
1 files changed, 6 insertions, 9 deletions
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 <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
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);
}