diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-12-17 17:07:40 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2018-12-17 17:08:06 -0500 |
commit | f5ba88ebfed936cfdee3a2ab3d6f690d291e9627 (patch) | |
tree | f8df748e71c662e96e682827cb142aebcb2b3b0c /color.c | |
parent | 9f6acdc2f685383f7cae634778ecfde8b15c5252 (diff) | |
download | bfs-f5ba88ebfed936cfdee3a2ab3d6f690d291e9627.tar.xz |
color: Make extension detection case-insensitive
It's what GNU ls does.
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -296,6 +296,23 @@ int cfclose(CFILE *cfile) { return ret; } +static const char *ext_color(const struct colors *colors, const char *filename) { + size_t namelen = strlen(filename); + + for (const struct ext_color *ext = colors->ext_list; ext; ext = ext->next) { + if (namelen < ext->len) { + continue; + } + + const char *suffix = filename + namelen - ext->len; + if (strcasecmp(suffix, ext->ext) == 0) { + return ext->color; + } + } + + return NULL; +} + 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) { @@ -319,14 +336,7 @@ static const char *file_color(const struct colors *colors, const char *filename, } if (!color) { - size_t namelen = strlen(filename); - - for (struct ext_color *ext = colors->ext_list; ext; ext = ext->next) { - if (namelen >= ext->len && memcmp(filename + namelen - ext->len, ext->ext, ext->len) == 0) { - color = ext->color; - break; - } - } + color = ext_color(colors, filename); } if (!color) { |