From 28c787b0dcbae9e6c7dfc0013bdaff25d0a2f009 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 2 Jan 2019 22:12:36 -0500 Subject: color: Fix more incompatibilities with GNU ls --- color.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'color.c') diff --git a/color.c b/color.c index 5807184..a877ff7 100644 --- a/color.c +++ b/color.c @@ -184,25 +184,20 @@ struct colors *parse_colors(const char *ls_colors) { } char *start = colors->data; - char *end; + size_t colon; struct ext_color *ext; - for (end = strchr(start, ':'); *start && end; start = end + 1, end = strchr(start, ':')) { + for (colon = strcspn(start, ":"); *start; start += colon + 1, colon = strcspn(start, ":")) { + start[colon] = '\0'; + char *equals = strchr(start, '='); if (!equals) { continue; } - *equals = '\0'; - *end = '\0'; const char *key = start; const char *value = equals + 1; - // Ignore all-zero values - if (strspn(value, "0") == strlen(value)) { - continue; - } - if (key[0] == '*') { ext = malloc(sizeof(struct ext_color)); if (ext) { @@ -213,6 +208,11 @@ struct colors *parse_colors(const char *ls_colors) { colors->ext_list = ext; } } else { + // All-zero values should be treated like NULL, to fall + // back on any other relevant coloring for that file + if (strcmp(key, "rs") != 0 && strspn(value, "0") == strlen(value)) { + value = NULL; + } set_color(colors, key, value); } } @@ -307,7 +307,11 @@ static const char *ext_color(const struct colors *colors, const char *filename) static const char *file_color(const struct colors *colors, const char *filename, const struct BFTW *ftwbuf) { const struct bfs_stat *sb = ftwbuf->statbuf; if (!sb) { - return colors->orphan; + if (colors->missing) { + return colors->missing; + } else { + return colors->orphan; + } } const char *color = NULL; @@ -318,7 +322,7 @@ static const char *file_color(const struct colors *colors, const char *filename, color = colors->setuid; } else if (sb->mode & S_ISGID) { color = colors->setgid; - } else if (bfs_check_capabilities(ftwbuf)) { + } else if (colors->capable && bfs_check_capabilities(ftwbuf)) { color = colors->capable; } else if (sb->mode & 0111) { color = colors->exec; @@ -356,9 +360,8 @@ static const char *file_color(const struct colors *colors, const char *filename, break; case S_IFLNK: - if (xfaccessat(ftwbuf->at_fd, ftwbuf->at_path, F_OK) == 0) { - color = colors->link; - } else { + color = colors->link; + if (colors->orphan && xfaccessat(ftwbuf->at_fd, ftwbuf->at_path, F_OK) != 0) { color = colors->orphan; } break; -- cgit v1.2.3