summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-07-25 20:14:34 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-07-25 20:14:34 -0400
commit781f5902b7bbb91811f1f810f8a419607ed36294 (patch)
tree8ff1acf48ba81b2f35190a4f3d811ad1b6bf68f7 /color.c
parente674297be6be114a530cd06d2ca773baff1ce7cc (diff)
downloadbfs-781f5902b7bbb91811f1f810f8a419607ed36294.tar.xz
Recover from errors in diropen().
Fixes #4.
Diffstat (limited to 'color.c')
-rw-r--r--color.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/color.c b/color.c
index 6dda4cd..521fd09 100644
--- a/color.c
+++ b/color.c
@@ -274,10 +274,10 @@ static const char *file_color(const color_table *colors, const char *filename, c
return color;
}
-static void print_esc(const char *esc) {
- fputs("\033[", stdout);
- fputs(esc, stdout);
- fputs("m", stdout);
+static void print_esc(const char *esc, FILE *file) {
+ fputs("\033[", file);
+ fputs(esc, file);
+ fputs("m", file);
}
void pretty_print(const color_table *colors, const char *fpath, const struct stat *sb) {
@@ -294,24 +294,39 @@ void pretty_print(const color_table *colors, const char *fpath, const struct sta
}
if (colors->dir) {
- print_esc(colors->dir);
+ print_esc(colors->dir, stdout);
}
fwrite(fpath, 1, filename - fpath, stdout);
if (colors->dir) {
- print_esc(colors->reset);
+ print_esc(colors->reset, stdout);
}
const char *color = file_color(colors, filename, sb);
if (color) {
- print_esc(color);
+ print_esc(color, stdout);
}
fputs(filename, stdout);
if (color) {
- print_esc(colors->reset);
+ print_esc(colors->reset, stdout);
}
fputs("\n", stdout);
}
+void print_error(const color_table *colors, const char *fpath, const struct BFTW *ftwbuf) {
+ const char *color = NULL;
+ if (colors) {
+ color = colors->orphan;
+ }
+
+ if (color) {
+ print_esc(color, stderr);
+ }
+ fprintf(stderr, "Error at %s: %s\n", fpath, strerror(ftwbuf->error));
+ if (color) {
+ print_esc(colors->reset, stderr);
+ }
+}
+
void free_colors(color_table *colors) {
if (colors) {
ext_color *ext = colors->ext_list;