summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-12-17 17:07:40 -0500
committerTavian Barnes <tavianator@tavianator.com>2018-12-17 17:08:06 -0500
commitf5ba88ebfed936cfdee3a2ab3d6f690d291e9627 (patch)
treef8df748e71c662e96e682827cb142aebcb2b3b0c
parent9f6acdc2f685383f7cae634778ecfde8b15c5252 (diff)
downloadbfs-f5ba88ebfed936cfdee3a2ab3d6f690d291e9627.tar.xz
color: Make extension detection case-insensitive
It's what GNU ls does.
-rw-r--r--color.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/color.c b/color.c
index dfda9fc..cdc79a6 100644
--- a/color.c
+++ b/color.c
@@ -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) {