aboutsummaryrefslogtreecommitdiffstats
path: root/src/icon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/icon.c')
-rw-r--r--src/icon.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/icon.c b/src/icon.c
new file mode 100644
index 0000000..d131307
--- /dev/null
+++ b/src/icon.c
@@ -0,0 +1,32 @@
+#include "icon.h"
+#include <stdbool.h>
+#include <string.h>
+
+const char *
+get_file_icon(const char *filename, bool is_dir)
+{
+ if (is_dir) {
+ return DEFAULT_DIR_ICON;
+ }
+
+ size_t exact_count =
+ sizeof(exact_match_icons) / sizeof(exact_match_icons[0]);
+ for (size_t i = 0; i < exact_count; i++) {
+ if (strcmp(filename, exact_match_icons[i].key) == 0) {
+ return exact_match_icons[i].icon;
+ }
+ }
+
+ const char *ext = strrchr(filename, '.');
+ if (ext && ext != filename) {
+ ext++; // skip "."
+ size_t ext_count = sizeof(ext_icons) / sizeof(ext_icons[0]);
+ for (size_t i = 0; i < ext_count; i++) {
+ if (strcasecmp(ext, ext_icons[i].key) == 0) {
+ return ext_icons[i].icon;
+ }
+ }
+ }
+
+ return DEFAULT_FILE_ICON;
+}