commit 961e05da6a5498cf913d5929ae3b9a206c93d225
Author: Raniconduh <clagv.randomgames@gmail.com>
Date: Sun Dec 05 21:17:10 2021 +0000
diff --git a/README.md b/README.md
index 28657b6..d608e9e 100644
--- a/README.md
+++ b/README.md
@@ -186 +188 @@ Files will be highlighted and shown with an identifier in correspondence to the
* Blue, `/`: Directory
* Cyan, `@`: Symbolic link
* Magenta, `=`: Unix socket
+* Magenta, No identifier: Media file
+* Red, No identifier: Archive or compressed file
* White, No identifier: Regular file
Files that are executable but have another identifier will keep the identifier but be colored green. Symbolic links that point to directories will be suffixed with `@ => /` and may be entered as a normal directory. Otherwise, deletion of a symbolic link will not delete whatever the link points to; only the link itself and opening one will open what the link points to.
diff --git a/include/dir.h b/include/dir.h
index bcf4c3b..b5074af 100644
--- a/include/dir.h
+++ b/include/dir.h
@@ -2010 +2017 @@ enum file_type_t {
FILE_UNKNOWN
};
+enum mime_type_t {
+ MIME_UNKNOWN,
+ MIME_MEDIA,
+ MIME_ARCHIVE
+};
+
struct dir_entry_t {
char * name;
enum file_type_t file_type;
enum file_type_t under_link;
+ enum mime_type_t m_type;
bool exec;
bool marked;
};
diff --git a/include/type.h b/include/type.h
new file mode 100644
index 0000000..0323b1d
--- /dev/null
+++ b/include/type.h
@@ -00 +114 @@
+#ifndef TYPE_H
+#define TYPE_H
+
+char * get_ext(char *);
+int scmp(const void *, const void *);
+void lowers(char *);
+
+#define n_media_exts 68
+#define n_archive_exts 55
+
+extern char * media_exts[n_media_exts];
+extern char * archive_exts[n_archive_exts];
+
+#endif
diff --git a/src/dir.c b/src/dir.c
index 98dab3a..e479c94 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -76 +77 @@
#include <unistd.h>
#include <errno.h>
+#include "type.h"
#include "dir.h"
#include "io.h"
@@ -956 +9621 @@ int list_dir(char * dir_path) {
free(tmp_path);
free(buf);
+ 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->marked = false;
dir_entries[n_dir_entries] = dir_entry;
diff --git a/src/io.c b/src/io.c
index 6179b57..9ae2f13 100644
--- a/src/io.c
+++ b/src/io.c
@@ -916 +9118 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
cp = WHITE;
f_ident = ' ';
}
+
+ switch (dir_entry->m_type) {
+ case MIME_MEDIA:
+ cp = MAGENTA;
+ break;
+ case MIME_ARCHIVE:
+ cp = RED;
+ break;
+ case MIME_UNKNOWN:
+ default:
+ break;
+ }
cp = COLOR_PAIR((unsigned)cp);
if (highlight) cp |= A_REVERSE;
diff --git a/src/type.c b/src/type.c
new file mode 100644
index 0000000..e5ee850
--- /dev/null
+++ b/src/type.c
@@ -00 +152 @@
+#include <string.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"
+};
+
+
+char * get_ext(char * s) {
+ char * ns = strrchr(s, '.');
+ if (!ns) return NULL;
+ return ns + 1;
+}
+
+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
+}