commit 1e580b84aa6a20481601da11d4ac158f5fb20ed6
Author: Raniconduh <clagv.randomgames@gmail.com>
Date: Fri Jan 07 00:22:59 2022 +0000
diff --git a/include/icons.h b/include/icons.h
index 65bb47b..76568ae 100644
--- a/include/icons.h
+++ b/include/icons.h
@@ -16 +18 @@
#ifndef ICONS_H
#define ICONS_H
+#include "type.h"
+
#define ICON_DIR "\uf74a"
#define ICON_GEAR "\uf013"
@@ -2879 +30199 @@
#define ICON_AUDIO "\uf722"
#define ICON_VIDEO "\uf72a"
+#define ICON_IMAGE "\uf1c5"
#define ICON_GENERIC "\uf15b"
#define ICON_ARCHIVE "\uf1c6"
-struct icon_pair {
- char * ext;
- char * icon;
-};
-
struct icon_pair icons[] = {
+ {"1", ICON_ARCHIVE},
+ {"3g2", ICON_VIDEO},
+ {"3gp", ICON_VIDEO},
+ {"7z", ICON_ARCHIVE},
+ {"7zip",ICON_ARCHIVE},
/* A */
+ {"a", ICON_ARCHIVE},
+ {"aac", ICON_AUDIO},
+ {"ac3", ICON_AUDIO},
+ {"ai", ICON_IMAGE},
+ {"aif", ICON_AUDIO},
+ {"alz", ICON_ARCHIVE},
+ {"amv", ICON_VIDEO},
{"apk", ICON_APK},
+ {"asec",ICON_APK},
+ {"asf", ICON_VIDEO},
{"asm", ICON_GEAR},
+ {"avi", ICON_VIDEO},
/* B */
- {"bash", ICON_SHELL},
+ {"bash",ICON_SHELL},
{"bin", ICON_EXEC},
+ {"bmp", ICON_IMAGE},
+ {"bz2", ICON_ARCHIVE},
/* C */
- {"c", ICON_C},
+ {"c", ICON_C},
{"c++", ICON_CPP},
- {"cc", ICON_CPP},
- {"class", ICON_JAVA},
- {"cs", ICON_CS},
+ {"cc", ICON_CPP},
+ {"cbr", ICON_ARCHIVE},
+ {"cda", ICON_AUDIO},
+ {"class",ICON_JAVA},
+ {"cpgz",ICON_ARCHIVE},
+ {"cs", ICON_CS},
+ {"cso", ICON_ARCHIVE},
{"css", ICON_CSS},
/* D */
+ {"dar", ICON_ARCHIVE},
+ {"dbz", ICON_ARCHIVE},
+ {"deb", ICON_ARCHIVE},
+ {"drc", ICON_VIDEO},
+ {"dz", ICON_ARCHIVE},
/* E */
+ {"ear", ICON_ARCHIVE},
+ {"eps", ICON_IMAGE},
/* F */
{"f#", ICON_FSHARP},
+ {"f4a", ICON_AUDIO},
+ {"f4b", ICON_AUDIO},
+ {"f4p", ICON_VIDEO},
+ {"f4v", ICON_VIDEO},
+ {"flv", ICON_VIDEO},
{"fish", ICON_SHELL},
/* G */
+ {"gif", ICON_IMAGE},
+ {"gifv",ICON_VIDEO},
+ {"gip", ICON_ARCHIVE},
{"git", ICON_GIT},
- {"go", ICON_GO},
+ {"go", ICON_GO},
+ {"gz", ICON_ARCHIVE},
/* H */
- {"h", ICON_C},
- {"hh", ICON_CPP},
+ {"h", ICON_C},
+ {"h264",ICON_VIDEO},
+ {"heif",ICON_IMAGE},
+ {"hh", ICON_CPP},
{"hpp", ICON_CPP},
{"htm", ICON_HTML},
- {"html", ICON_HTML},
+ {"html",ICON_HTML},
+ {"htmlz",ICON_ARCHIVE},
/* I */
+ {"ico", ICON_IMAGE},
+ {"igz", ICON_ARCHIVE},
+ {"ipa", ICON_ARCHIVE},
/* J */
- {"java", ICON_JAVA},
- {"js", ICON_JS},
- {"json", ICON_JSON},
+ {"jar", ICON_JAVA},
+ {"java",ICON_JAVA},
+ {"jpeg",ICON_IMAGE},
+ {"jpg", ICON_IMAGE},
+ {"js", ICON_JS},
+ {"json",ICON_JSON},
/* K */
/* L */
{"lua", ICON_LUA},
+ {"lz", ICON_ARCHIVE},
+ {"lz4", ICON_ARCHIVE},
/* M */
- {"md", ICON_MD},
+ {"m2ts",ICON_VIDEO},
+ {"m2v", ICON_VIDEO},
+ {"m4a", ICON_AUDIO},
+ {"m4p", ICON_AUDIO},
+ {"m4v", ICON_VIDEO},
+ {"maff",ICON_ARCHIVE},
+ {"md", ICON_MD},
+ {"mid", ICON_AUDIO},
+ {"midi",ICON_AUDIO},
+ {"mkv", ICON_VIDEO},
+ {"mng", ICON_IMAGE},
+ {"mov", ICON_VIDEO},
+ {"mp3", ICON_AUDIO},
+ {"mp4", ICON_VIDEO},
+ {"mpeg",ICON_VIDEO},
+ {"mpg", ICON_VIDEO},
+ {"mpq", ICON_ARCHIVE},
+ {"mts", ICON_VIDEO},
+ {"mxf", ICON_VIDEO},
/* N */
+ {"npk", ICON_ARCHIVE},
+ {"nsv", ICON_VIDEO},
+ {"nxz", ICON_ARCHIVE},
/* O */
- {"o", ICON_EXEC},
+ {"o", ICON_EXEC},
+ {"ogg", ICON_AUDIO},
+ {"ogv", ICON_VIDEO},
{"out", ICON_EXEC},
/* P */
- {"py", ICON_PY},
+ {"pbm", ICON_IMAGE},
+ {"pgm", ICON_IMAGE},
+ {"pkg", ICON_ARCHIVE},
+ {"png", ICON_IMAGE},
+ {"pnm", ICON_IMAGE},
+ {"ppm", ICON_IMAGE},
+ {"ps", ICON_IMAGE},
+ {"psd", ICON_IMAGE},
+ {"pup", ICON_ARCHIVE},
+ {"py", ICON_PY},
{"pyc", ICON_PY},
{"pyd", ICON_PY},
{"pyo", ICON_PY},
+ {"pz", ICON_ARCHIVE},
+ {"pzip",ICON_ARCHIVE},
/* Q */
+ {"qt", ICON_VIDEO},
/* R */
- {"rb", ICON_RB},
+ {"rar", ICON_ARCHIVE},
+ {"rb", ICON_RB},
+ {"rm", ICON_VIDEO},
+ {"rmvb",ICON_VIDEO},
+ {"roq", ICON_VIDEO},
+ {"rpa", ICON_ARCHIVE},
+ {"rpm", ICON_ARCHIVE},
/* S */
- {"scala", ICON_SCALA},
- {"sh", ICON_SHELL},
- {"so", ICON_EXEC},
+ {"sar", ICON_ARCHIVE},
+ {"scala",ICON_SCALA},
+ {"sh", ICON_SHELL},
+ {"shar",ICON_ARCHIVE},
+ {"sis", ICON_ARCHIVE},
+ {"sisx",ICON_ARCHIVE},
+ {"so", ICON_EXEC},
+ {"svg", ICON_IMAGE},
+ {"svi", ICON_VIDEO},
/* T */
+ {"tar", ICON_ARCHIVE},
+ {"tgz", ICON_ARCHIVE},
+ {"tif", ICON_IMAGE},
+ {"tiff",ICON_IMAGE},
+ {"ts", ICON_VIDEO},
+ {"txz", ICON_ARCHIVE},
/* U */
+ {"uha", ICON_ARCHIVE},
/* V */
{"vim", ICON_VIM},
- {"vimrc", ICON_VIM},
+ {"vimrc",ICON_VIM},
+ {"viv", ICON_VIDEO},
+ {"vob", ICON_VIDEO},
+ {"vsix",ICON_ARCHIVE},
/* W */
+ {"wav", ICON_AUDIO},
+ {"webm",ICON_VIDEO},
+ {"webp",ICON_IMAGE},
+ {"wma", ICON_AUDIO},
+ {"wmv", ICON_VIDEO},
/* X */
+ {"xap", ICON_ARCHIVE},
{"xml", ICON_XML},
+ {"xz", ICON_ARCHIVE},
+ {"xzm", ICON_ARCHIVE},
+ {"xzn", ICON_ARCHIVE},
/* Y */
+ {"yuv", ICON_VIDEO},
/* Z */
+ {"z", ICON_ARCHIVE},
+ {"zab", ICON_ARCHIVE},
+ {"zi", ICON_ARCHIVE},
+ {"zip", ICON_ARCHIVE},
+ {"zlib",ICON_ARCHIVE},
{"zsh", ICON_SHELL},
+ {"zst", ICON_ARCHIVE},
+ {"zstd",ICON_ARCHIVE},
+ {"zxp", ICON_ARCHIVE},
+ {"zz", ICON_ARCHIVE},
};
#define n_icons (sizeof(icons)/sizeof(icons[0]))
diff --git a/include/type.h b/include/type.h
index e9fd420..dac50ec 100644
--- a/include/type.h
+++ b/include/type.h
@@ -115 +121 @@
#ifndef TYPE_H
#define TYPE_H
-char * get_ext(char *);
-int scmp(const void *, const void *);
-void lowers(char *);
+#define ICON_DIR "\uf74a"
+#define ICON_GEAR "\uf013"
+#define ICON_GENERIC "\uf15b"
+
+#include "dir.h"
+struct icon_pair {
+ char * ext;
+ char * icon;
+};
-#define n_media_exts 68
-#define n_archive_exts 55
-extern char * media_exts[n_media_exts];
-extern char * archive_exts[n_archive_exts];
+char * get_ext(char *);
+void lowers(char *);
+enum mime_type_t get_mime(char *);
+char * get_icon(char *);
#endif /* TYPE_H */
diff --git a/src/dir.c b/src/dir.c
index 040957d..19d478b 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -15020 +1507 @@ int list_dir(char * dir_path) {
free(buf);
// figure out file 'mime' type
- char * t_ext = get_ext(dir_entry->name);
- if (t_ext && *t_ext) {
- char * ext = malloc(strlen(t_ext));
- strcpy(ext, t_ext);
- lowers(ext);
- // extension is a media filw
- if (bsearch(&ext, media_exts, n_media_exts, sizeof(char*), scmp))
- dir_entry->m_type = MIME_MEDIA;
- // extension is a compressed or archive file
- else if (bsearch(&ext, archive_exts, n_archive_exts, sizeof(char*), scmp))
- dir_entry->m_type = MIME_ARCHIVE;
- free(ext);
- } else
- dir_entry->m_type = MIME_UNKNOWN;
+ dir_entry->m_type = get_mime(dir_entry->name);
dir_entry->marked = false;
diff --git a/src/io.c b/src/io.c
index 23e50d4..85172c0 100644
--- a/src/io.c
+++ b/src/io.c
@@ -107 +106 @@
#include <grp.h>
#if ICONS
-#include "icons.h"
#include "type.h"
#endif
#include "opts.h"
@@ -1056 +1049 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
case FILE_DIR:
cp = BLUE;
f_ident = '/';
+#if ICONS
+ icon = ICON_DIR;
+#endif
break;
case FILE_FIFO:
cp = YELLOW;
@@ -13615 +1389 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
switch (dir_entry->m_type) {
case MIME_MEDIA:
cp = MAGENTA;
-#if ICONS
- icon = ICON_VIDEO;
-#endif
break;
case MIME_ARCHIVE:
cp = RED;
-#if ICONS
- icon = ICON_ARCHIVE;
-#endif
break;
case MIME_UNKNOWN:
default:
@@ -15221 +14810 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
}
#if ICONS
- // find icon if it is not media or an archive
+ // find icon if it is not a dir
if (!icon && show_icons) {
- char * t_ext = get_ext(dir_entry->name);
- if (t_ext && *t_ext) {
- char * ext = malloc(strlen(t_ext));
- strcpy(ext, t_ext);
- lowers(ext);
- struct icon_pair * t_icon =
- bsearch(&ext, icons, n_icons, sizeof(icons[0]), icmp);
- if (t_icon) icon = t_icon->icon;
- free(ext);
- }
+ icon = get_icon(dir_entry->name);
}
-
- if (!icon && dir_entry->file_type == FILE_DIR) icon = ICON_DIR;
#endif
if ((dir_entry->mode & POWNER(M_EXEC)) &&
diff --git a/src/type.c b/src/type.c
index e671b91..eef7e35 100644
--- a/src/type.c
+++ b/src/type.c
@@ -138 +18 @@
#include <string.h>
+#include <stdlib.h>
#include "type.h"
-
-
-char * media_exts[] = {
- "3g2", "3gp", "aac", "ac3", "ai",
- "aif", "amv", "asf", "avi", "bmp",
- "cda", "drc", "eps", "f4a", "f4b",
- "f4p", "f4v", "flv", "gif", "gifv",
- "h264", "heif", "ico", "jpeg", "jpg",
- "m2ts", "m2v", "m4a", "m4p", "m4v",
- "mid", "midi", "mkv", "mng", "mov",
- "mp3", "mp4", "mpeg", "mpg", "mts",
- "mxf", "nsv", "ogg", "ogv", "pbm",
- "pgm", "png", "pnm", "ppm", "ps",
- "psd", "qt", "rm", "rmvb", "roq",
- "svg", "svi", "tif", "tiff", "ts",
- "viv", "vob", "wav", "webm", "webp",
- "wma", "wmv", "yuv"
-};
-
-char * archive_exts[] = {
- "7zip", "a", "alz", "apk", "asec",
- "bz2", "cbr", "cmp", "cpgz", "cso",
- "dar", "dbz", "deb", "dz", "ear",
- "exe", "gip", "gz", "htmlz", "igz",
- "ipa", "jar", "lz", "lz4", "maff",
- "mpq", "npk", "nxz", "pkg", "pup",
- "pz", "pzip", "rar", "rpa", "sar",
- "shar", "sis", "sisx", "tar", "tgz",
- "txz", "uha", "vsix", "xap", "xz",
- "xzm", "xzn", "z", "zab", "zi",
- "zip", "zlib", "zst", "zxp", "zz"
-};
+#include "icons.h"
char * get_ext(char * s) {
@@ -4214 +1246 @@ char * get_ext(char * s) {
}
-int scmp(const void * a, const void * b) {
- return strcmp(*(const char**)a, *(const char**)b);
-}
-
-
void lowers(char * s) {
for (char * p = s; *p; p++)
// A to Z
if (*p >= 65 && *p <= 90)
*p += 32; // convert upper to lower
}
+
+enum mime_type_t get_mime(char * file) {
+ char * t_ext = get_ext(file);
+ if (!t_ext) return MIME_UNKNOWN;
+
+ char * ext = malloc(strlen(t_ext));
+ strcpy(ext, t_ext);
+ lowers(ext);
+
+ struct icon_pair * t =
+ bsearch(&ext, icons, n_icons, sizeof(icons[0]), icmp);
+ free(ext);
+ if (!t) return MIME_UNKNOWN;
+
+ if (!strcmp(t->icon, ICON_ARCHIVE))
+ return MIME_ARCHIVE;
+ else if (!strcmp(t->icon, ICON_AUDIO) ||
+ !strcmp(t->icon, ICON_VIDEO) ||
+ !strcmp(t->icon, ICON_IMAGE))
+ return MIME_MEDIA;
+ else return MIME_UNKNOWN;
+}
+
+char * get_icon(char * file) {
+ char * t_ext = get_ext(file);
+ if (!t_ext) return NULL;
+
+ char * ext = malloc(strlen(t_ext));
+ strcpy(ext, t_ext);
+ lowers(ext);
+
+ struct icon_pair * t =
+ bsearch(&ext, icons, n_icons, sizeof(icons[0]), icmp);
+ free(ext);
+ if (!t) return NULL;
+ return t->icon;
+}