Compare commits
49 Commits
da4c90d243
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a31f452ea | ||
|
|
daf43daa00 | ||
|
|
cf03a230b6 | ||
|
|
87bfdd1b86 | ||
|
|
20fee198ae | ||
|
|
632904fd89 | ||
|
|
dd5307b411 | ||
|
|
41933eb6d0 | ||
|
|
0a45d1e3e8 | ||
|
|
d33ac88de2 | ||
|
|
e42d55e66a | ||
|
|
f6380ddeda | ||
|
|
905f6e8588 | ||
|
|
095cf7b357 | ||
|
|
9f7ed73885 | ||
|
|
41af25e0b1 | ||
|
|
f807fe56b5 | ||
|
|
adb10b6d5d | ||
|
|
c692a1a992 | ||
|
|
8c80a6e3da | ||
|
|
1aa66c82fb | ||
|
|
f5d0c8bc85 | ||
|
|
9e8bd3c022 | ||
|
|
f40cc91cce | ||
|
|
a5483335c5 | ||
|
|
a7d4a6322c | ||
|
|
749dba1ce8 | ||
|
|
ac0b644bcb | ||
|
|
b4acda1aa6 | ||
|
|
b7124cbb1d | ||
|
|
adac32fcc1 | ||
|
|
dcb47d420b | ||
|
|
689565f732 | ||
|
|
58f99eb2cf | ||
|
|
673c7e5414 | ||
|
|
93c70aa07a | ||
|
|
edcf093269 | ||
|
|
557e0eb416 | ||
|
|
3c0f26efee | ||
|
|
491c00b9d4 | ||
|
|
955d8f439b | ||
|
|
d9d1ed115d | ||
|
|
41293c6afd | ||
|
|
1a85a2d810 | ||
|
|
e5625ada08 | ||
|
|
b639ad3998 | ||
|
|
1711926003 | ||
|
|
6372dbba69 | ||
|
|
acb7db1617 |
102
backend.c
102
backend.c
@@ -80,29 +80,91 @@ char* smartstrcasestr(const char *haystack, const char *needle){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* parse_cmd_char(const char *cmd, const char *path){
|
|
||||||
char *index = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
if (index) {
|
char* parse_cmd(const char *cmd, file *f){
|
||||||
out = malloc(strlen(cmd) + 1 + strlen(path) + 1);
|
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
||||||
char *o = out;
|
|
||||||
memcpy(out, cmd, index - cmd);
|
int count = 0;
|
||||||
o += index-cmd;
|
char *out;
|
||||||
*o = '\"';
|
char *pos;
|
||||||
o++;
|
unsigned long i = 0;
|
||||||
memcpy(o, path, strlen(path));
|
while(f->file_name[i]) {
|
||||||
o += strlen(path);
|
if (f->file_name[i] == '\'') {
|
||||||
*o = '\"';
|
count++;
|
||||||
memcpy(o+1, index + 1, strlen(index+1));
|
}
|
||||||
*(o+strlen(index+1)+1) = '\0';
|
i++;
|
||||||
return out;
|
}
|
||||||
|
|
||||||
|
out = malloc(strlen(cmd) + 1 + (strlen(f->file_name)+(count*3)) + 3);
|
||||||
|
|
||||||
|
pos = out;
|
||||||
|
if (offset) {
|
||||||
|
memcpy(pos, cmd, offset - cmd);
|
||||||
|
pos += offset - cmd;
|
||||||
} else {
|
} else {
|
||||||
concat(out, cmd, " ./\"", 0);
|
memcpy(pos, cmd, strlen(cmd));
|
||||||
concat(out, out, path, 1);
|
pos += strlen(cmd) + 1;
|
||||||
concat(out, out, "\"", 1);
|
pos[-1] = ' ';
|
||||||
|
}
|
||||||
|
*pos = '\'';
|
||||||
|
pos++;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(f->file_name[i]) {
|
||||||
|
if (f->file_name[i] == '\'') {
|
||||||
|
*pos++ = '\'';
|
||||||
|
*pos++ = '\\';
|
||||||
|
*pos++ = '\'';
|
||||||
|
}
|
||||||
|
*pos = f->file_name[i];
|
||||||
|
pos++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
*pos = '\'';
|
||||||
|
|
||||||
|
if (offset) {
|
||||||
|
pos[1]= ' ';
|
||||||
|
memcpy(pos + 1, offset+1, strlen(offset)+1);
|
||||||
|
pos[strlen(offset)+1] = '\0';
|
||||||
|
} else {
|
||||||
|
pos[1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
}
|
||||||
|
char* parse_path(char *path){
|
||||||
|
int count = 0;
|
||||||
|
char *out;
|
||||||
|
char *pos;
|
||||||
|
unsigned long i = 0;
|
||||||
|
while(path[i]) {
|
||||||
|
if (path[i] == '\'') {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
out = malloc((strlen(path)+(count*3)) + 4);
|
||||||
|
|
||||||
|
pos = out;
|
||||||
|
pos++;
|
||||||
|
|
||||||
|
out[0] = '\'';
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while(path[i]) {
|
||||||
|
if (path[i] == '\'') {
|
||||||
|
*pos++ = '\'';
|
||||||
|
*pos++ = '\\';
|
||||||
|
*pos++ = '\'';
|
||||||
|
}
|
||||||
|
*pos = path[i];
|
||||||
|
pos++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
pos[0] = '\'';
|
||||||
|
pos[1]= ' ';
|
||||||
|
pos[2] = '\0';
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
|
|
||||||
/*char* concat(const char *s1, const char *s2);*/
|
/*char* concat(const char *s1, const char *s2);*/
|
||||||
char* smartstrcasestr(const char *haystack, const char *needle);
|
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||||
char* parse_cmd_char(const char *cmd, const char *path);
|
char* parse_cmd(const char *cmd, file *f);
|
||||||
|
|
||||||
|
|||||||
6
colors.c
6
colors.c
@@ -9,9 +9,6 @@
|
|||||||
unsigned int color_count;
|
unsigned int color_count;
|
||||||
color *colors;
|
color *colors;
|
||||||
|
|
||||||
extern file *rgt_content;
|
|
||||||
extern unsigned long rgt_file_count;
|
|
||||||
|
|
||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
|
|
||||||
@@ -105,8 +102,7 @@ void colors_init() {
|
|||||||
while (getline(&line, &size, dircolors) != -1) {
|
while (getline(&line, &size, dircolors) != -1) {
|
||||||
fg = 7;
|
fg = 7;
|
||||||
bg = 0;
|
bg = 0;
|
||||||
if (line[0] == '.') {
|
if (line[0] == '.' && (extension = strtok(line, " ")) != NULL) {
|
||||||
extension = strtok(line, " ");
|
|
||||||
colors[i].file_extension = malloc(strlen(extension)+1);
|
colors[i].file_extension = malloc(strlen(extension)+1);
|
||||||
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
memcpy(colors[i].file_extension, extension, strlen(extension)+1);
|
||||||
|
|
||||||
|
|||||||
54
config.h
54
config.h
@@ -2,8 +2,9 @@
|
|||||||
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
|
#define SETTINGS_UEBERZUG_IMAGE_PREVIEW 1 /* 0 is disabled, 1 is enabled, 2 is with caching; depends on ueberzug */
|
||||||
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
|
#define SETTINGS_RELOAD_DIR_DELTA 10 /* 0 is disabled, time in seconds between automatic refresh of dir contents */
|
||||||
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
#define SETTINGS_CURSES_TIMEOUT 100 /* read: inopts(3NCURSES), blocking time between user inputs */
|
||||||
#define SETTINGS_COMMAND_REPLACE_STR "%" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name
|
#define SETTINGS_COMMAND_REPLACE_STR "^" /* if a command in any cmd inside this fle contains this string, it will be replaced with the hovered/selected file name
|
||||||
* as of right now, this character cannot be escaped; i.e ``command\% --arg`` will parse into ``command\path_of_hovered_file --arg``*/
|
* as of right now, this character cannot be escaped; i.e ``command\^ --arg`` will parse into ``command\path_of_hovered_file --arg``*/
|
||||||
|
#define SETTINGS_COMMAND_FORK '@' /* commands starting with this character will be forked into a new non blokcing detached process */
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
#ifndef CONFIG_GUARD
|
#ifndef CONFIG_GUARD
|
||||||
@@ -13,6 +14,11 @@
|
|||||||
#include "interactions.h"
|
#include "interactions.h"
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
static const char clipboard_cmd[] = "echo ^ | xsel -ib --trim"; /*used in yank_text*/
|
||||||
|
static const char rename_cmd[] = "mv"; /* as used in rename_hovered, makedir and makefile */
|
||||||
|
static const char makefile_cmd[] = "touch"; /*as of now both only do ``rename_cmd new_name``*/
|
||||||
|
static const char makedir_cmd[] = "mkdir";
|
||||||
|
|
||||||
static const mimetype mimetype_default_cmd[] = {
|
static const mimetype mimetype_default_cmd[] = {
|
||||||
/* mimetype shell command
|
/* mimetype shell command
|
||||||
* ^ substring of "file --mime-type -b ./hovered"
|
* ^ substring of "file --mime-type -b ./hovered"
|
||||||
@@ -21,21 +27,21 @@ static const mimetype mimetype_default_cmd[] = {
|
|||||||
* file --mime-type -b ./image.gif
|
* file --mime-type -b ./image.gif
|
||||||
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
* gives us "image/gif", thusly if we want to open gif in mpv rather than feh,
|
||||||
* we need to define "gif" before "image" */
|
* we need to define "gif" before "image" */
|
||||||
{ "text", "$EDITOR" },
|
{ "text", "$EDITOR" },
|
||||||
{ "avif", "nohup mpv % >/dev/null 2>&1 &" },
|
{ "avif", "@ mpv" },
|
||||||
{ "gif", "nohup mpv --loop-file=\"inf\" % >/dev/null 2>&1 &" },
|
{ "gif", "@ mpv --loop-file=\"inf\"" },
|
||||||
{ "image", "feh % >/dev/null 2>&1 &" },
|
{ "image", "@ feh" },
|
||||||
{ "video", "nohup mpv % >/dev/null 2>&1 &" },
|
{ "video", "@ mpv" },
|
||||||
{ "audio", "mpv" },
|
{ "audio", "mpv" },
|
||||||
{ "pdf", "zathura" },
|
{ "pdf", "@ zathura" },
|
||||||
};
|
};
|
||||||
static const extension file_extension_default_cmd[] = {
|
static const extension file_extension_default_cmd[] = {
|
||||||
/* extension shell command
|
/* extension shell command
|
||||||
* similar to mimetype_default_cmd, however it searches for exact string matches
|
* similar to mimetype_default_cmd, however it searches for exact string matches
|
||||||
* and is checked before mimetype_default_cmd */
|
* and is checked before mimetype_default_cmd */
|
||||||
{ ".exe", "wine"},
|
{ ".exe", "wine"},
|
||||||
{ ".cbz", "mcomix % &"},
|
{ ".cbz", "@ mcomix"},
|
||||||
{ ".cbr", "mcomix % &"},
|
{ ".cbr", "@ mcomix"},
|
||||||
{ ".json", "$EDITOR"},
|
{ ".json", "$EDITOR"},
|
||||||
{ ".csv", "$EDITOR"},
|
{ ".csv", "$EDITOR"},
|
||||||
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
|
{ ".blend", "blender-bin-5.0.0"}, /* version number in bin in main repo? yea idc */
|
||||||
@@ -62,12 +68,12 @@ static const binding key_binding[] = {
|
|||||||
{ "n", move_up, NULL, "move up" },
|
{ "n", move_up, NULL, "move up" },
|
||||||
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
{ "s", move_right, NULL, "move right" }, /* if a dir is hovered, cd into it, if a file is selected, see mimetype_default_cmd */
|
||||||
|
|
||||||
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* opens the hovered file with an arbitrary command */
|
{ "\n", open_with, NULL, "open \"open with\" dialog" }, /* execute shell cmd on file, accounts for SETTINGS_COMMAND_FORK */
|
||||||
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
{ "r", rename_hovered, NULL, "rename hovered file" }, /* renames currently hovered file/directory */
|
||||||
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
{ "dD", delete, NULL, "delete file" }, /* deletes currently hovered OR selected file/directory
|
||||||
* this means that it does not delete the hovered files if files are already selected */
|
* this means that it does not delete the hovered files if files are already selected */
|
||||||
{ "yn", yank_text, "name", "yank filename of hovered file" },
|
{ "yn", yank_file_name, NULL, "yank filename of hovered file" },
|
||||||
{ "yp", yank_text, "path", "yank path of hovered file" },
|
{ "yp", yank_file_path, NULL, "yank path of hovered file" },
|
||||||
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
{ "yy", yank_file, "copy", "copy/yank file/directory" },
|
||||||
{ "dd", yank_file, "cut", "cut file/directory" },
|
{ "dd", yank_file, "cut", "cut file/directory" },
|
||||||
{ "pp", paste, NULL, "paste" },
|
{ "pp", paste, NULL, "paste" },
|
||||||
@@ -113,13 +119,12 @@ static const binding key_binding[] = {
|
|||||||
|
|
||||||
static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */
|
static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this defines the maximum size unit, deleting everything except B results in all sizes being displayed in byte */
|
||||||
|
|
||||||
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */
|
|
||||||
static const char ui_btm_text_storage_left[] = "total free";
|
static const char ui_btm_text_storage_left[] = "total free";
|
||||||
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
static const char ui_btm_current_dir_size[] = "sum of dir,";
|
||||||
static const char ui_open_with_text_0[] = "open"; /*ui_open_with_text_0 \"selected_file\" ui_open_with_text_1*/
|
static const char ui_open_with_text[] = "open "SETTINGS_COMMAND_REPLACE_STR" with:";
|
||||||
static const char ui_open_with_text_1[] = "with:";
|
static const char ui_rename_text[] = "rename "SETTINGS_COMMAND_REPLACE_STR" to:";
|
||||||
static const char ui_rename_text_0[] = "rename"; /*ui_rename_text_0 \"selected_file\" ui_rename_text_1*/
|
static const char ui_makefile_text[] = "makedir:";
|
||||||
static const char ui_rename_text_1[] = "to:";
|
static const char ui_makedir_text[] = "makefile:";
|
||||||
static const char ui_delete_text[] = "delete:";
|
static const char ui_delete_text[] = "delete:";
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
@@ -129,6 +134,9 @@ static const unsigned long file_extension_default_count = sizeof(file_extension_
|
|||||||
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
|
static const char size_unit_count = (sizeof(size_unit) / sizeof(size_unit[0])) - 1;
|
||||||
#else
|
#else
|
||||||
static const char clipboard_cmd[];
|
static const char clipboard_cmd[];
|
||||||
|
static const char rename_cmd[];
|
||||||
|
static const char makefile_cmd[];
|
||||||
|
static const char makedir_cmd[];
|
||||||
static const mimetype mimetype_default_cmd[];
|
static const mimetype mimetype_default_cmd[];
|
||||||
static const extension file_extension_default_cmd[];
|
static const extension file_extension_default_cmd[];
|
||||||
static const binding key_binding[];
|
static const binding key_binding[];
|
||||||
@@ -137,10 +145,10 @@ static const unsigned long mimetype_default_count;
|
|||||||
static const unsigned long file_extension_default_count;
|
static const unsigned long file_extension_default_count;
|
||||||
static const char size_unit[];
|
static const char size_unit[];
|
||||||
static const char size_unit_count;
|
static const char size_unit_count;
|
||||||
static const char ui_open_with_text_0[];
|
static const char ui_open_with_text[];
|
||||||
static const char ui_open_with_text_1[];
|
static const char ui_makedir_text[];
|
||||||
static const char ui_rename_text_0[];
|
static const char ui_makefile_text[];
|
||||||
static const char ui_rename_text_1[];
|
static const char ui_rename_text[];
|
||||||
static const char ui_delete_text[];
|
static const char ui_delete_text[];
|
||||||
#endif
|
#endif
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
26
defines.h
26
defines.h
@@ -3,16 +3,23 @@
|
|||||||
#define STATUS_QUIT_PROGRAM 1
|
#define STATUS_QUIT_PROGRAM 1
|
||||||
#define STATUS_RUN_BACKEND 2
|
#define STATUS_RUN_BACKEND 2
|
||||||
#define STATUS_RELOAD_DIRECTORY 4
|
#define STATUS_RELOAD_DIRECTORY 4
|
||||||
#define STATUS_UPDATE_SCREEN_MASK 24 /* 11000 */
|
#define STATUS_UPDATE_ASYNC_REFRESH 8
|
||||||
#define STATUS_UPDATE_SCREEN_0 8
|
|
||||||
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
#define STATUS_UPDATE_SCREEN_RESIZE 16
|
||||||
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
|
#define STATUS_UPDATE_SCREEN_CLEAR 32
|
||||||
#define STATUS_USER_ROOT 64
|
#define STATUS_UPDATE_SCREEN_MASK (STATUS_UPDATE_ASYNC_REFRESH | STATUS_UPDATE_SCREEN_RESIZE | STATUS_UPDATE_SCREEN_CLEAR)
|
||||||
#define STATUS_INPUT_MATCH 128
|
#define STATUS_USER_ROOT 128
|
||||||
#define STATUS_DELTA_TIME 256
|
#define STATUS_INPUT_MATCH 256
|
||||||
|
#define STATUS_DELTA_TIME 512
|
||||||
|
#define STATUS_MOVE_RIGHT_MATCH 1024
|
||||||
|
|
||||||
#define SETTINGS_HAS_COLOR 1
|
#define SETTINGS_HAS_COLOR 1
|
||||||
|
|
||||||
|
#define RENDER_QUEUE_TOP 0
|
||||||
|
#define RENDER_QUEUE_LFT 1
|
||||||
|
#define RENDER_QUEUE_MID 2
|
||||||
|
#define RENDER_QUEUE_RGT 3
|
||||||
|
#define RENDER_QUEUE_BTM 4
|
||||||
|
|
||||||
#define FILE_MODIFIERS_HIDDEN_FILES 1
|
#define FILE_MODIFIERS_HIDDEN_FILES 1
|
||||||
#define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/
|
#define FILE_MODIFIERS_SORT_BITMASK 126 /* 00000000000000000000000001111110*/
|
||||||
#define FILE_MODIFIERS_SORT_ALPHABETIC 2
|
#define FILE_MODIFIERS_SORT_ALPHABETIC 2
|
||||||
@@ -70,6 +77,11 @@ typedef struct File {
|
|||||||
unsigned long file_size; /*if its a file, its in bytes, if its a dir, its the count of files within that dir */
|
unsigned long file_size; /*if its a file, its in bytes, if its a dir, its the count of files within that dir */
|
||||||
char *file_name;
|
char *file_name;
|
||||||
} file;
|
} file;
|
||||||
|
typedef struct Dir {
|
||||||
|
file *current_file;
|
||||||
|
file *file_list;
|
||||||
|
unsigned long file_count;
|
||||||
|
} dir;
|
||||||
typedef struct Color {
|
typedef struct Color {
|
||||||
char *file_extension;
|
char *file_extension;
|
||||||
short color_pair;
|
short color_pair;
|
||||||
@@ -96,7 +108,7 @@ typedef struct Yank {
|
|||||||
} yank;
|
} yank;
|
||||||
typedef struct Linked_dir {
|
typedef struct Linked_dir {
|
||||||
char *path;
|
char *path;
|
||||||
unsigned long selected_file_current;
|
unsigned long index;
|
||||||
struct Linked_dir *next;
|
struct Linked_dir *next;
|
||||||
} linked_dir;
|
} linked_dir;
|
||||||
|
|
||||||
|
|||||||
273
dir.c
273
dir.c
@@ -12,121 +12,125 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
extern file *mid_content;
|
extern dir mid_dir;
|
||||||
extern unsigned long mid_file_count;
|
|
||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern volatile unsigned long selected_file_current;
|
extern char *global_path;
|
||||||
extern volatile unsigned long selected_file_last;
|
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
int (*order_func)() = sort_natural;
|
int (*order_func)() = sort_natural;
|
||||||
linked_dir *visited_dirs;
|
linked_dir *list_beginning;
|
||||||
linked_dir *current_dir;
|
linked_dir *current_linked_dir;
|
||||||
|
|
||||||
|
|
||||||
unsigned long get_dir_size(char *path){
|
unsigned long get_dir_size(char *path){
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
unsigned long entry_count = 0;
|
unsigned long entry_count = 0;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
if (dir && file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
if (dir) {
|
||||||
while ((entry=readdir(dir))) {
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||||
entry_count++;
|
while ((entry=readdir(dir))) {
|
||||||
}
|
|
||||||
/* removes files "." and ".." */
|
|
||||||
entry_count -= 2;
|
|
||||||
} else if (dir) {
|
|
||||||
while ((entry=readdir(dir))) {
|
|
||||||
if (entry->d_name[0] != '.') {
|
|
||||||
entry_count++;
|
entry_count++;
|
||||||
}
|
}
|
||||||
|
/* removes files "." and ".." */
|
||||||
|
entry_count -= 2;
|
||||||
|
} else {
|
||||||
|
while ((entry=readdir(dir))) {
|
||||||
|
if (entry->d_name[0] != '.') {
|
||||||
|
entry_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
closedir(dir);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
|
||||||
return entry_count;
|
return entry_count;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
void get_dir_content(char *path, dir *dir){
|
||||||
struct dirent **entry = NULL;
|
struct dirent **entry = NULL;
|
||||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||||
scandir(path, &entry, skip_dot, NULL);
|
scandir(path, &entry, skip_dot, NULL);
|
||||||
} else {
|
} else {
|
||||||
scandir(path, &entry, skip_hidden_files, NULL);
|
scandir(path, &entry, skip_hidden_files, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *full_path = NULL;
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
for (i = 0; i < *dir_file_count; i++ ) {
|
for (i = 0; i < dir->file_count; i++ ) {
|
||||||
|
dir->file_list[i].file_name = NULL;
|
||||||
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
||||||
} else {
|
} else {
|
||||||
dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
dir->file_list[i].file_name = malloc(strlen(entry[i]->d_name)+1);
|
||||||
memcpy(dir_content[i].file_name, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
memcpy(dir->file_list[i].file_name, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||||
|
dir->file_list[i].status = 0;
|
||||||
|
|
||||||
|
|
||||||
struct stat *file;
|
struct stat *file;
|
||||||
file = malloc(sizeof(struct stat));
|
file = malloc(sizeof(struct stat));
|
||||||
|
|
||||||
/* using the full path allows using the same function for all windows */
|
/* using the full path allows using the same function for all windows */
|
||||||
char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
|
full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/"));
|
||||||
memcpy(full_path, path, strlen(path));
|
memcpy(full_path, path, strlen(path));
|
||||||
memcpy(full_path + strlen(path) + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
memcpy(full_path + strlen(path) + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1);
|
||||||
full_path[strlen(path)] = '/';
|
full_path[strlen(path)] = '/';
|
||||||
|
|
||||||
lstat(full_path, file);
|
lstat(full_path, file);
|
||||||
|
|
||||||
dir_content[i].file_size = file->st_size;
|
dir->file_list[i].file_size = file->st_size;
|
||||||
dir_content[i].permissions = file->st_mode;
|
dir->file_list[i].permissions = file->st_mode;
|
||||||
|
|
||||||
if (S_ISLNK(file->st_mode)) {
|
if (S_ISLNK(file->st_mode)) {
|
||||||
stat(full_path, file);
|
stat(full_path, file);
|
||||||
if (S_ISDIR(file->st_mode)) {
|
if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
dir->file_list[i].file_type = FILE_TYPE_DIR | FILE_TYPE_SYMLINK;
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
dir->file_list[i].color_pair = COLOR_SYMLINK;
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
dir->file_list[i].file_size = get_dir_size(full_path);
|
||||||
} else {
|
} else {
|
||||||
dir_content[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
dir->file_list[i].file_type = FILE_TYPE_REGULAR | FILE_TYPE_SYMLINK;
|
||||||
dir_content[i].color_pair = COLOR_SYMLINK;
|
dir->file_list[i].color_pair = COLOR_SYMLINK;
|
||||||
}
|
}
|
||||||
} else if (S_ISDIR(file->st_mode)) {
|
} else if (S_ISDIR(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_DIR;
|
dir->file_list[i].file_type = FILE_TYPE_DIR;
|
||||||
dir_content[i].color_pair = COLOR_DIR;
|
dir->file_list[i].color_pair = COLOR_DIR;
|
||||||
dir_content[i].file_size = get_dir_size(full_path);
|
dir->file_list[i].file_size = get_dir_size(full_path);
|
||||||
} else if (file->st_mode & S_IXUSR) {
|
} else if (file->st_mode & S_IXUSR) {
|
||||||
dir_content[i].file_type = FILE_TYPE_EXEC;
|
dir->file_list[i].file_type = FILE_TYPE_EXEC;
|
||||||
dir_content[i].color_pair = COLOR_EXEC;
|
dir->file_list[i].color_pair = COLOR_EXEC;
|
||||||
} else if (S_ISREG(file->st_mode)) {
|
} else if (S_ISREG(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_REGULAR;
|
dir->file_list[i].file_type = FILE_TYPE_REGULAR;
|
||||||
dir_content[i].color_pair = COLOR_REGULAR;
|
dir->file_list[i].color_pair = COLOR_REGULAR;
|
||||||
unsigned long j = 0;
|
unsigned long j = 0;
|
||||||
char *extension = strrchr(entry[i]->d_name, '.');
|
char *extension = strrchr(entry[i]->d_name, '.');
|
||||||
if (extension) {
|
if (extension) {
|
||||||
for (j = 0; j < color_count; j++) {
|
for (j = 0; j < color_count; j++) {
|
||||||
if (!strcmp(colors[j].file_extension, extension)) {
|
if (!strcmp(colors[j].file_extension, extension)) {
|
||||||
dir_content[i].color_pair = colors[j].color_pair;
|
dir->file_list[i].color_pair = colors[j].color_pair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (S_ISBLK(file->st_mode)) {
|
} else if (S_ISBLK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_BLOCK;
|
dir->file_list[i].file_type = FILE_TYPE_BLOCK;
|
||||||
dir_content[i].color_pair = COLOR_BLOCK;
|
dir->file_list[i].color_pair = COLOR_BLOCK;
|
||||||
} else if (S_ISCHR(file->st_mode)) {
|
} else if (S_ISCHR(file->st_mode)) {
|
||||||
dir_content[i].file_type = COLOR_CHARDEV;
|
dir->file_list[i].file_type = COLOR_CHARDEV;
|
||||||
} else if (S_ISFIFO(file->st_mode)) {
|
} else if (S_ISFIFO(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_FIFO;
|
dir->file_list[i].file_type = FILE_TYPE_FIFO;
|
||||||
dir_content[i].color_pair = COLOR_FIFO;
|
dir->file_list[i].color_pair = COLOR_FIFO;
|
||||||
} else if (S_ISSOCK(file->st_mode)) {
|
} else if (S_ISSOCK(file->st_mode)) {
|
||||||
dir_content[i].file_type = FILE_TYPE_SOCK;
|
dir->file_list[i].file_type = FILE_TYPE_SOCK;
|
||||||
dir_content[i].color_pair = COLOR_SOCK;
|
dir->file_list[i].color_pair = COLOR_SOCK;
|
||||||
} else {
|
} else {
|
||||||
dir_content[i].file_type = COLOR_REGULAR;
|
dir->file_list[i].file_type = COLOR_REGULAR;
|
||||||
dir_content[i].color_pair = COLOR_REGULAR;
|
dir->file_list[i].color_pair = COLOR_REGULAR;
|
||||||
unsigned long j = 0;
|
unsigned long j = 0;
|
||||||
char *extension = strrchr(entry[i]->d_name, '.');
|
char *extension = strrchr(entry[i]->d_name, '.');
|
||||||
if (extension) {
|
if (extension) {
|
||||||
for (j = 0; j < color_count; j++) {
|
for (j = 0; j < color_count; j++) {
|
||||||
if (!strcmp(colors[j].file_extension, extension)) {
|
if (!strcmp(colors[j].file_extension, extension)) {
|
||||||
dir_content[i].color_pair = colors[j].color_pair;
|
dir->file_list[i].color_pair = colors[j].color_pair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -138,20 +142,16 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(dir_content, *dir_file_count, sizeof(file), order_func);
|
qsort(dir->file_list, dir->file_count, sizeof(file), order_func);
|
||||||
|
|
||||||
free(entry);
|
free(entry);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content){
|
void print_dir(WINDOW *win, char print_info, dir *dir){
|
||||||
/* i am not proud of this function */
|
/* i am not proud of this function */
|
||||||
unsigned long line_width = getmaxx(win);
|
unsigned long line_width = getmaxx(win);
|
||||||
|
|
||||||
char *bg = malloc(line_width+1);
|
|
||||||
memset(bg, ' ', line_width);
|
|
||||||
bg[line_width] = '\0';
|
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
float file_size;
|
float file_size;
|
||||||
float printed_size = 0;
|
float printed_size = 0;
|
||||||
@@ -165,22 +165,23 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
#else
|
#else
|
||||||
long offset_front = 2;
|
long offset_front = 2;
|
||||||
#endif
|
#endif
|
||||||
|
unsigned long selected_file_current = dir->current_file - dir->file_list;
|
||||||
|
|
||||||
long offset_index = 2; /* only used for the index of the file itself */
|
long offset_index = 2; /* only used for the index of the file itself */
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
if (*dir_file_count > 9) {
|
if (dir->file_count > 9) {
|
||||||
|
|
||||||
#if SETTINGS_LINE_NUMBERS != 0
|
#if SETTINGS_LINE_NUMBERS != 0
|
||||||
unsigned long dir_file_count_ = *dir_file_count;
|
unsigned long dir_file_count_ = dir->file_count;
|
||||||
while(dir_file_count_ > 9) {
|
while(dir_file_count_ > 9) {
|
||||||
offset_front++;
|
offset_front++;
|
||||||
dir_file_count_ /= 10;
|
dir_file_count_ /= 10;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) {
|
if (selected_file_current > (terminal_height/3)*2 && dir->file_count > terminal_height - 2) {
|
||||||
if (selected_file_current + (terminal_height/3) >= *dir_file_count) {
|
if (selected_file_current + (terminal_height/3) >= dir->file_count) {
|
||||||
offset_vertical = *dir_file_count - terminal_height+2;
|
offset_vertical = dir->file_count - terminal_height+2;
|
||||||
} else {
|
} else {
|
||||||
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
offset_vertical = selected_file_current - (terminal_height/3)*2;
|
||||||
}
|
}
|
||||||
@@ -188,12 +189,12 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
} else {
|
} else {
|
||||||
offset_front = 0;
|
offset_front = 0;
|
||||||
}
|
}
|
||||||
for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) {
|
for (i = offset_vertical; i < dir->file_count && i < (terminal_height + offset_vertical); i++) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (print_info) {
|
if (print_info) {
|
||||||
file_size = dir_content[i].file_size;
|
file_size = dir->file_list[i].file_size;
|
||||||
char size_index = -1;
|
char size_index = -1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -203,8 +204,8 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
} while (file_size > 1 && size_index < size_unit_count);
|
} while (file_size > 1 && size_index < size_unit_count);
|
||||||
size_char = size_unit[(unsigned)size_index];
|
size_char = size_unit[(unsigned)size_index];
|
||||||
|
|
||||||
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%ld", dir->file_list[i].file_size) + 1);
|
||||||
} else if (size_char =='B') {
|
} else if (size_char =='B') {
|
||||||
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -214,24 +215,29 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
offset_back = line_width;
|
offset_back = line_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
is_selected = 1;
|
is_selected = 1;
|
||||||
} else {
|
} else {
|
||||||
is_selected = 0;
|
is_selected = 0;
|
||||||
}
|
}
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
wattron(win, COLOR_PAIR(8));
|
wattron(win, COLOR_PAIR(8));
|
||||||
} else {
|
} else {
|
||||||
wattron(win, COLOR_PAIR(dir_content[i].color_pair));
|
wattron(win, COLOR_PAIR(dir->file_list[i].color_pair));
|
||||||
}
|
}
|
||||||
if (dir_content[i].status & FILE_STATUS_HOVER) {
|
if (&dir->file_list[i] == dir->current_file) {
|
||||||
wattron(win, A_REVERSE);
|
wattron(win, A_REVERSE);
|
||||||
|
unsigned long bg = 0;
|
||||||
|
for (bg = 0; bg < line_width; bg++) {
|
||||||
|
mvwaddch(win, i-offset_vertical, bg, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wattroff(win, A_REVERSE);
|
wattroff(win, A_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mvwaddstr(win, i-offset_vertical, 0, bg);
|
|
||||||
if(print_info) {
|
if(print_info) {
|
||||||
#if SETTINGS_LINE_NUMBERS == 2
|
#if SETTINGS_LINE_NUMBERS == 2
|
||||||
long i_ = (selected_file_current) - i;
|
long i_ = (selected_file_current) - i;
|
||||||
@@ -264,93 +270,113 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (dir_content[i].file_type &= FILE_TYPE_DIR) {
|
if (dir->file_list[i].file_type & FILE_TYPE_DIR) {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size);
|
mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir->file_list[i].file_size);
|
||||||
}else if (size_char =='B') {
|
}else if (size_char =='B') {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char);
|
||||||
} else {
|
} else {
|
||||||
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
|
mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char *extension = strrchr(dir_content[i].file_name, '.');
|
char *extension = strrchr(dir->file_list[i].file_name, '.');
|
||||||
|
|
||||||
size_t printable_size = offset_back-offset_front-is_selected-2;
|
unsigned long printable_size = offset_back-offset_front-is_selected-2;
|
||||||
|
|
||||||
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, dir_content[i].file_name, printable_size);
|
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, dir->file_list[i].file_name, printable_size);
|
||||||
if (extension && printable_size <= strlen(dir_content[i].file_name)) {
|
if (extension && printable_size <= strlen(dir->file_list[i].file_name)) {
|
||||||
mvwaddnstr(win, i-offset_vertical, offset_back-strlen(extension)-1, extension, strlen(extension));
|
mvwaddnstr(win, i-offset_vertical, offset_back-strlen(extension)-1, extension, strlen(extension));
|
||||||
mvwaddnstr(win, i-offset_vertical, offset_back-strlen(extension)-2, "~", 1);
|
mvwaddnstr(win, i-offset_vertical, offset_back-strlen(extension)-2, "~", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dir_content[i].status & FILE_STATUS_SELECTED) {
|
if (dir->file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
wattroff(win, COLOR_PAIR(8));
|
wattroff(win, COLOR_PAIR(8));
|
||||||
} else {
|
} else {
|
||||||
wattroff(win, COLOR_PAIR(dir_content[i].color_pair));
|
wattroff(win, COLOR_PAIR(dir->file_list[i].color_pair));
|
||||||
}
|
}
|
||||||
/*free(file_name);*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
free(bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
char update_selected_file(){
|
|
||||||
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
|
||||||
|
|
||||||
if (selected_file_current >= mid_file_count) {
|
|
||||||
selected_file_current = mid_file_count-1;
|
|
||||||
}
|
|
||||||
if (selected_file_current != selected_file_last && selected_file_last <= mid_file_count) {
|
|
||||||
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
|
||||||
ret = 1;
|
|
||||||
} else {
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
|
||||||
selected_file_last = selected_file_current;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current){
|
|
||||||
if (mid_content->file_name) {
|
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
void dir_changed(){
|
||||||
|
|
||||||
unsigned long dir_get_selected_file_current(){
|
|
||||||
|
|
||||||
current_dir = visited_dirs;
|
|
||||||
if (mid_content->file_name[0] == '\0') {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
char hit = 0;
|
|
||||||
char *path = getcwd(NULL, 0);
|
char *path = getcwd(NULL, 0);
|
||||||
while(current_dir->next != NULL) {
|
current_linked_dir = list_beginning;
|
||||||
if (strcmp(path, current_dir->path) == 0) {
|
while (current_linked_dir->next != NULL) {
|
||||||
hit = 1;
|
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
}
|
}
|
||||||
current_dir = current_dir->next;
|
|
||||||
}
|
}
|
||||||
if (hit == 0) {
|
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||||
current_dir->next = malloc(sizeof(linked_dir));
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
current_dir->next->next = NULL;
|
|
||||||
current_dir->next->path = path;
|
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
free(path);
|
/**/
|
||||||
return current_dir->selected_file_current;
|
|
||||||
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
|
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||||
|
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||||
|
current_linked_dir->next->next = NULL;
|
||||||
|
current_linked_dir->next->index = 0;
|
||||||
|
|
||||||
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
void change_dir(char *new_path){
|
||||||
|
|
||||||
|
char *old_path = getcwd(NULL, 0);
|
||||||
|
current_linked_dir = list_beginning;
|
||||||
|
while (current_linked_dir->next != NULL) {
|
||||||
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(current_linked_dir->path, old_path) == 0) {
|
||||||
|
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
chdir(new_path);
|
||||||
|
char *new_path_real = getcwd(NULL, 0);
|
||||||
|
|
||||||
|
current_linked_dir = list_beginning;
|
||||||
|
while (current_linked_dir->next != NULL) {
|
||||||
|
if(strcmp(current_linked_dir->path, new_path_real) == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(current_linked_dir->path, new_path_real) != 0) {
|
||||||
|
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||||
|
current_linked_dir = current_linked_dir->next;
|
||||||
|
current_linked_dir->path = malloc(strlen(new_path_real)+1);
|
||||||
|
memcpy(current_linked_dir->path, new_path_real, strlen(new_path_real)+1);
|
||||||
|
current_linked_dir->next = NULL;
|
||||||
|
current_linked_dir->index = 0;
|
||||||
|
/*TODO(2026-05-25T22:49:30)
|
||||||
|
*handle if new_path == "..", should this case be true, focus the index on which the old_path falls on*/
|
||||||
|
}
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||||
|
|
||||||
|
free(old_path);
|
||||||
|
free(new_path_real);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void dir_init(){
|
void dir_init(){
|
||||||
visited_dirs = malloc(sizeof(linked_dir));
|
list_beginning = malloc(sizeof(linked_dir));
|
||||||
visited_dirs->path = getcwd(NULL, 0);
|
list_beginning->path = getcwd(NULL, 0);
|
||||||
visited_dirs->selected_file_current = 0;
|
list_beginning->index = 0;
|
||||||
visited_dirs->next = NULL;
|
list_beginning->next = NULL;
|
||||||
current_dir = visited_dirs;
|
current_linked_dir = list_beginning;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void recursive_delete(file current_file){
|
void recursive_delete(file current_file){
|
||||||
|
/*
|
||||||
if (S_ISLNK(current_file.permissions)) {
|
if (S_ISLNK(current_file.permissions)) {
|
||||||
remove(current_file.file_name);
|
remove(current_file.file_name);
|
||||||
} else if (current_file.file_type & FILE_TYPE_DIR ) {
|
} else if (current_file.file_type & FILE_TYPE_DIR ) {
|
||||||
@@ -380,4 +406,5 @@ void recursive_delete(file current_file){
|
|||||||
} else {
|
} else {
|
||||||
remove(current_file.file_name);
|
remove(current_file.file_name);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
4
dir.h
4
dir.h
@@ -4,8 +4,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned long get_dir_size(char *path);
|
unsigned long get_dir_size(char *path);
|
||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
void get_dir_content(char *path, dir *dir);
|
||||||
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
void print_dir(WINDOW *win, char print_info, dir *dir);
|
||||||
char update_selected_file();
|
char update_selected_file();
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current);
|
void dir_set_selected_file_current(unsigned long selected_file_current);
|
||||||
unsigned long dir_get_selected_file_current();
|
unsigned long dir_get_selected_file_current();
|
||||||
|
|||||||
@@ -13,26 +13,19 @@ extern unsigned int terminal_height;
|
|||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
char previewd;
|
char previewd;
|
||||||
|
|
||||||
char* text(char *path, unsigned long *file_size);
|
char* text(file *f);
|
||||||
void images_print(char *file_name);
|
void images_print(char *file_name);
|
||||||
void images_clear();
|
void images_clear();
|
||||||
char* generic(char *path);
|
char* generic(file *f);
|
||||||
|
|
||||||
char* get_mimetype(char *path){
|
char* get_mimetype(file *f){
|
||||||
static char *cmd_str = "file --mime-type -b ./\"";
|
static const char *cmd_str = "file --mime-type -b";
|
||||||
unsigned long cmd_len = strlen(cmd_str);
|
char *cmd = parse_cmd(cmd_str, f);
|
||||||
unsigned int path_len = strlen(path);
|
|
||||||
|
|
||||||
char *cmd = malloc((cmd_len + path_len) + 2);
|
|
||||||
memset(cmd, ' ', cmd_len + path_len);
|
|
||||||
memcpy(cmd, cmd_str, cmd_len);
|
|
||||||
memcpy(cmd + cmd_len, path, path_len);
|
|
||||||
cmd[cmd_len + path_len] = '\"';
|
|
||||||
cmd[cmd_len + path_len + 1] = '\0';
|
|
||||||
|
|
||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
if (getline(&line, &size, cmd_open) != -1){
|
if (getline(&line, &size, cmd_open) != -1){
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
@@ -42,57 +35,59 @@ char* get_mimetype(char *path){
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* preview_file(char *file_name, unsigned long file_size){
|
char* preview_file(file *f){
|
||||||
/* this calls "file" on path */
|
/* this calls "file" on path */
|
||||||
|
|
||||||
char *file_buffer;
|
char *file_buffer;
|
||||||
|
|
||||||
|
char *mime = get_mimetype(f);
|
||||||
char *mime = get_mimetype(file_name);
|
|
||||||
|
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (strstr(mime, "text")) {
|
if (strstr(mime, "text")) {
|
||||||
file_buffer = text(file_name, &file_size);
|
file_buffer = text(f);
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
} else if (strstr(mime, "image")) {
|
} else if (strstr(mime, "image")) {
|
||||||
file_buffer = generic(file_name);
|
file_buffer = generic(f);
|
||||||
images_print(file_name);
|
images_print(f->file_name);
|
||||||
previewd = 1;
|
previewd = 1;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
file_buffer = generic(file_name);
|
file_buffer = generic(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(mime);
|
free(mime);
|
||||||
return file_buffer;
|
return file_buffer;
|
||||||
|
|
||||||
}
|
}
|
||||||
char* text(char *path, unsigned long *file_size){
|
char* text(file *f){
|
||||||
|
|
||||||
unsigned long size = (terminal_width/2) * terminal_height;
|
unsigned long size = (terminal_width/2) * terminal_height;
|
||||||
if (size > *file_size) {
|
if (size > f->file_size) {
|
||||||
size = *file_size;
|
size = f->file_size;
|
||||||
}
|
}
|
||||||
char *file_buffer = malloc(size + 1);
|
char *file_buffer = malloc(size + 1);
|
||||||
FILE *fp = fopen(path, "r");
|
FILE *fp = fopen(f->file_name, "r");
|
||||||
if (fread(file_buffer, size, 1, fp) != 0) {
|
if (fread(file_buffer, size, 1, fp) != 0) {
|
||||||
|
fclose(fp);
|
||||||
file_buffer[size] = '\0';
|
file_buffer[size] = '\0';
|
||||||
return file_buffer;
|
return file_buffer;
|
||||||
} else {
|
} else {
|
||||||
|
fclose(fp);
|
||||||
return "failed reading file";
|
return "failed reading file";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* generic(char *path){
|
char* generic(file *f){
|
||||||
char *cmd;
|
static const char *cmd_str = "file";
|
||||||
concat(cmd, "file ./\"", path, 0);
|
char *cmd = parse_cmd(cmd_str, f);
|
||||||
concat(cmd, cmd, "\"", 1);
|
|
||||||
|
|
||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
|
free(cmd);
|
||||||
if (getline(&line, &size, cmd_open) != -1) {
|
if (getline(&line, &size, cmd_open) != -1) {
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
return line;
|
return line;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* preview_file(char *file_name, unsigned long file_size);
|
char* preview_file(file *f);
|
||||||
char* get_mimetype(char *path);
|
char* get_mimetype(file *f);
|
||||||
void images_clear();
|
void images_clear();
|
||||||
void ueberzug_init();
|
void ueberzug_init();
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
|
|||||||
939
interactions.c
939
interactions.c
@@ -12,50 +12,36 @@
|
|||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
|
|
||||||
|
|
||||||
extern volatile unsigned long selected_file_current;
|
|
||||||
extern volatile unsigned long selected_file_last;
|
|
||||||
|
|
||||||
extern unsigned int file_modifiers;
|
|
||||||
extern pthread_mutex_t mutex_selection;
|
|
||||||
extern pthread_mutex_t mutex_rgt;
|
|
||||||
extern pthread_mutex_t mutex_mid;
|
extern pthread_mutex_t mutex_mid;
|
||||||
extern pthread_mutex_t mutex_btm;
|
extern pthread_mutex_t mutex_render;
|
||||||
extern pthread_cond_t cond_rgt;
|
extern WINDOW *win_b;
|
||||||
extern file *mid_content;
|
extern WINDOW *win_m;
|
||||||
extern file *lft_content;
|
extern dir mid_dir;
|
||||||
extern file *rgt_content;
|
|
||||||
|
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
|
|
||||||
extern WINDOW *win_b;
|
|
||||||
|
|
||||||
extern char *rgt_buffer;
|
|
||||||
extern char *btm_buffer;
|
|
||||||
extern unsigned long mid_file_count;
|
|
||||||
|
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
extern char *start_path;
|
extern char *start_path;
|
||||||
|
extern char *global_path;
|
||||||
extern char *input;
|
extern char *input;
|
||||||
|
|
||||||
extern time_t *seed;
|
extern time_t seed;
|
||||||
|
|
||||||
char search_buffer[INPUT_BUFFER_SIZE];
|
char search_buffer[INPUT_BUFFER_SIZE];
|
||||||
unsigned int input_pass;
|
unsigned int input_pass;
|
||||||
unsigned long parsed_input_number;
|
unsigned long parsed_input_number;
|
||||||
yank yank_files = { 0 };
|
yank yank_files = { 0 };
|
||||||
|
|
||||||
extern void render_pass();
|
|
||||||
extern void window_btm(WINDOW *win, char force_render);
|
|
||||||
extern int (*order_func)();
|
|
||||||
|
|
||||||
|
|
||||||
|
#define TODO noraw(); \
|
||||||
|
endwin();\
|
||||||
|
curs_set(1);\
|
||||||
|
echo();\
|
||||||
|
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
|
||||||
|
exit(1);
|
||||||
|
|
||||||
void FAIL(char *function, char *str){
|
void FAIL(char *function, char *str){
|
||||||
noraw();
|
|
||||||
endwin();
|
|
||||||
curs_set(1);
|
|
||||||
echo();
|
|
||||||
printf("ERROR in function %s: %s", function, str);
|
printf("ERROR in function %s: %s", function, str);
|
||||||
}
|
}
|
||||||
void user_interactions() {
|
void user_interactions() {
|
||||||
@@ -74,7 +60,6 @@ void user_interactions() {
|
|||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
input_pass = 0;
|
input_pass = 0;
|
||||||
}
|
}
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,6 +72,9 @@ void user_interactions() {
|
|||||||
input++;
|
input++;
|
||||||
number_length++;
|
number_length++;
|
||||||
}
|
}
|
||||||
|
if (parsed_input_number == 0) {
|
||||||
|
parsed_input_number = 1;
|
||||||
|
}
|
||||||
input -= number_length;
|
input -= number_length;
|
||||||
|
|
||||||
char cmp_len = strlen(input);
|
char cmp_len = strlen(input);
|
||||||
@@ -96,8 +84,10 @@ void user_interactions() {
|
|||||||
for (i = 0; i < binding_count; i++) {
|
for (i = 0; i < binding_count; i++) {
|
||||||
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
if (strncmp(input + number_length, key_binding[i].key, cmp_len) == 0) {
|
||||||
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
if (strcmp(input + number_length, key_binding[i].key) == 0) {
|
||||||
|
pthread_mutex_lock(&mutex_mid);
|
||||||
func_ptr = key_binding[i].func;
|
func_ptr = key_binding[i].func;
|
||||||
func_ptr(parsed_input_number, i);
|
func_ptr(parsed_input_number, i);
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
|
timeout(SETTINGS_CURSES_TIMEOUT); /* blocking timeout of getch() */
|
||||||
} else {
|
} else {
|
||||||
@@ -137,19 +127,19 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
err = 0;
|
err = 0;
|
||||||
break;
|
break;
|
||||||
} else if (ch == '\t') { /* tab */
|
} else if (ch == '\t') { /* tab */
|
||||||
memcpy(str + pass, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
memcpy(str + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||||
mvwaddstr(win, y, x +pass, mid_content[selected_file_current].file_name);
|
mvwaddstr(win, y, x + pass, mid_dir.current_file->file_name);
|
||||||
pass += strlen(mid_content[selected_file_current].file_name);
|
pass += strlen(mid_dir.current_file->file_name);
|
||||||
} else if (ch == 127) { /* backspace */
|
} else if (ch == 127) { /* backspace */
|
||||||
if (pass > 0) {
|
if (pass > 0) {
|
||||||
pass--;
|
pass--;
|
||||||
mvwdelch(win, y, pass);
|
mvwdelch(win, y, x + pass);
|
||||||
}
|
}
|
||||||
} else if (ch == 27) { /* esc key */
|
} else if (ch == 27) { /* esc key */
|
||||||
err = 1;
|
err = 1;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
mvwaddch(win, y, x +pass, ch);
|
mvwaddch(win, y, x + pass, ch);
|
||||||
str[pass] = ch;
|
str[pass] = ch;
|
||||||
pass++;
|
pass++;
|
||||||
}
|
}
|
||||||
@@ -163,386 +153,221 @@ int read_string(WINDOW *win, int y, int x, char *str){
|
|||||||
void quit_program(){
|
void quit_program(){
|
||||||
status = STATUS_QUIT_PROGRAM;
|
status = STATUS_QUIT_PROGRAM;
|
||||||
}
|
}
|
||||||
|
void update(){
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
||||||
|
}
|
||||||
void select_all(){
|
void select_all(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for(i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_dir.file_count; i++) {
|
||||||
mid_content[i].status ^= FILE_STATUS_SELECTED;
|
mid_dir.file_list[i].status ^= FILE_STATUS_SELECTED;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
}
|
}
|
||||||
void move_down(unsigned long passes){
|
void move_down(unsigned long passes){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
|
||||||
if (passes == 0) {
|
mid_dir.current_file += passes;
|
||||||
passes++;
|
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
||||||
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
}
|
}
|
||||||
selected_file_current += passes;
|
|
||||||
|
|
||||||
update_selected_file();
|
status |= (STATUS_RUN_BACKEND);
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
}
|
}
|
||||||
void move_up(unsigned long passes){
|
void move_up(unsigned long passes){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
|
||||||
if (passes == 0) {
|
mid_dir.current_file -= passes;
|
||||||
passes++;
|
if (mid_dir.current_file < mid_dir.file_list) {
|
||||||
}
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
unsigned long tmp = selected_file_current;
|
|
||||||
selected_file_current -= passes;
|
|
||||||
if (tmp < selected_file_current) {
|
|
||||||
selected_file_current = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update_selected_file();
|
status |= (STATUS_RUN_BACKEND);
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
}
|
}
|
||||||
void move_left(unsigned long passes){
|
void move_left(unsigned long passes){
|
||||||
if (passes == 0) {
|
|
||||||
passes++;
|
|
||||||
}
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
for (i = 0; i < passes; i++) {
|
for (i = 0; i < passes; i++) {
|
||||||
if (chdir("..") != 0) {
|
change_dir("..");
|
||||||
/* TODO(2025-07-09T00:30:05) fix */
|
|
||||||
FAIL("move_left", "unhandled error of chdir");
|
|
||||||
} else {
|
|
||||||
selected_file_current = dir_get_selected_file_current();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
update_selected_file();
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
|
||||||
}
|
}
|
||||||
void move_right(){
|
void move_right(){
|
||||||
if (mid_content->file_name[0] == '\0') {
|
|
||||||
return;
|
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
}
|
change_dir(mid_dir.current_file->file_name);
|
||||||
if ((mid_content[selected_file_current].file_type & FILE_TYPE_DIR) == FILE_TYPE_DIR) {
|
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||||
if (chdir(mid_content[selected_file_current].file_name) != 0) {
|
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
||||||
FAIL("move_right", "unhandled error of chdir");
|
if (system(cmd)) {
|
||||||
} else {
|
|
||||||
selected_file_current = dir_get_selected_file_current();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned long i = 0;
|
char *mime = get_mimetype(mid_dir.current_file);
|
||||||
char match = 0;
|
char *extension = mid_dir.current_file->file_name;
|
||||||
char *mime = get_mimetype(mid_content[selected_file_current].file_name);
|
char *cmd = NULL;
|
||||||
char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
|
while (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||||
if (extension != NULL) {
|
if (*extension == '.') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
extension++;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long i;
|
||||||
|
if (extension <= mid_dir.current_file->file_name + strlen(mid_dir.current_file->file_name)) {
|
||||||
for (i = 0; i < file_extension_default_count; i++) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
|
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
||||||
char *cmd;
|
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||||
concat(cmd, file_extension_default_cmd[i].command, " ./\'", 0);
|
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
|
||||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
pid_t pid = fork();
|
||||||
concat(cmd, cmd, "\'", 1);
|
if (pid == 0 && setsid()) {
|
||||||
|
system(cmd);
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
if (system(cmd) == -1) {
|
exit(1);
|
||||||
/*do nothing*/
|
}
|
||||||
|
} else {
|
||||||
|
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
|
||||||
|
if (system(cmd)) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||||
match = 1;
|
update();
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match == 0) {
|
if (!(status & STATUS_MOVE_RIGHT_MATCH)) {
|
||||||
for (i = 0; i < mimetype_default_count; i++) {
|
for (i = 0; i < mimetype_default_count; i++) {
|
||||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||||
|
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||||
char *cmd = parse_cmd_char(mimetype_default_cmd[i].command, mid_content[selected_file_current].file_name);
|
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
|
||||||
if (system(cmd) == -1) {
|
pid_t pid = fork();
|
||||||
/*do nothing*/
|
if (pid == 0 && setsid()) {
|
||||||
|
system(cmd);
|
||||||
|
status = STATUS_QUIT_PROGRAM;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
|
||||||
|
if (system(cmd)) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
curs_set(1); /*for some reason, 1 here turns it invisible once again */
|
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
status &= ~STATUS_MOVE_RIGHT_MATCH;
|
||||||
|
free(cmd);
|
||||||
free(mime);
|
free(mime);
|
||||||
}
|
}
|
||||||
update_selected_file();
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
|
||||||
}
|
}
|
||||||
void toggle_hidden_files(){
|
void toggle_hidden_files(){
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RELOAD_FULL | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void toggle_selection(){
|
void toggle_selection(unsigned long passes){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
unsigned long i;
|
||||||
pthread_mutex_lock(&mutex_mid);
|
for (i = 0; i < passes; i++) {
|
||||||
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
|
mid_dir.current_file->status ^= FILE_STATUS_SELECTED;
|
||||||
status |= (STATUS_UPDATE_SCREEN_MASK);
|
move_down(1);
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
}
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
status |= (STATUS_RUN_BACKEND);
|
||||||
move_down(1);
|
|
||||||
}
|
}
|
||||||
void jump_bottom(){
|
void jump_bottom(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
selected_file_current = 0 - 1;
|
status |= (STATUS_RUN_BACKEND);
|
||||||
update_selected_file();
|
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
}
|
}
|
||||||
void jump_top(){
|
void jump_top(){
|
||||||
pthread_mutex_lock(&mutex_selection);
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
selected_file_current = 0;
|
status |= (STATUS_RUN_BACKEND);
|
||||||
update_selected_file();
|
|
||||||
current_dir->selected_file_current = selected_file_current;
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
|
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_with(){
|
void open_with(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
wclear(win_b);
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
|
||||||
|
|
||||||
concat(btm_buffer, ui_open_with_text_0, " \'", 0);
|
|
||||||
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
|
||||||
concat(btm_buffer, btm_buffer, "\' ", 1);
|
|
||||||
concat(btm_buffer, btm_buffer, ui_open_with_text_1, 1);
|
|
||||||
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
|
||||||
|
|
||||||
|
|
||||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
|
||||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0 , str);
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
|
||||||
|
if (str[0] == SETTINGS_COMMAND_FORK) {
|
||||||
|
cmd = parse_cmd(str+1, mid_dir.current_file);
|
||||||
if (err == 0) {
|
pid_t pid = fork();
|
||||||
char *cmd;
|
if (pid == 0 && setsid()) {
|
||||||
concat(cmd, str, " ./\'", 0);
|
system(cmd);
|
||||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
status = STATUS_QUIT_PROGRAM;
|
||||||
concat(cmd, cmd, "\'", 1);
|
exit(1);
|
||||||
|
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
|
||||||
images_clear();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
endwin();
|
|
||||||
if (system(cmd) == -1) {
|
|
||||||
FAIL("open_with", "creating subcommand failed unhandled");
|
|
||||||
}
|
|
||||||
initscr();
|
|
||||||
}
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
|
|
||||||
free(btm_buffer);
|
|
||||||
btm_buffer = btm_buffer_tmp;
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
|
|
||||||
free(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rename_hovered(){
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
|
||||||
|
|
||||||
concat(btm_buffer, ui_rename_text_0, " \'", 0);
|
|
||||||
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
|
||||||
concat(btm_buffer, btm_buffer, "\' ", 1);
|
|
||||||
concat(btm_buffer, btm_buffer, ui_rename_text_1, 1);
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
|
||||||
|
|
||||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
|
||||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
|
||||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
|
||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
|
||||||
|
|
||||||
|
|
||||||
if (!err) {
|
|
||||||
char *cmd;
|
|
||||||
concat(cmd, "mv ./\'", mid_content[selected_file_current].file_name, 0);
|
|
||||||
concat(cmd, cmd, "\' ./\'", 1);
|
|
||||||
concat(cmd, cmd, str, 1);
|
|
||||||
concat(cmd, cmd, "\'", 1);
|
|
||||||
|
|
||||||
if (system(cmd) == -1) {
|
|
||||||
FAIL("rename_hovered", "mv or creating subcommand failed");
|
|
||||||
};
|
|
||||||
btm_buffer = cmd;
|
|
||||||
}
|
|
||||||
free(str);
|
|
||||||
free(btm_buffer);
|
|
||||||
btm_buffer = btm_buffer_tmp;
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void delete(){
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
|
||||||
|
|
||||||
unsigned int i = 0;
|
|
||||||
unsigned int hits = 0;
|
|
||||||
char *file_str = "";
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
concat(file_str, file_str, "\'", 0);
|
|
||||||
concat(file_str, file_str, mid_content[i].file_name, 1);
|
|
||||||
concat(file_str, file_str, "\' ", 1);
|
|
||||||
hits++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width);
|
|
||||||
btm_buffer = malloc(BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
|
||||||
memset(btm_buffer, ' ', BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width);
|
|
||||||
|
|
||||||
memcpy(btm_buffer, ui_delete_text ,strlen(ui_delete_text));
|
|
||||||
|
|
||||||
/*this horrendous check tries to copy everything until the last line, while keeping said last line unwritten*/
|
|
||||||
/*lets hope im never gonna need to format something like this ever again*/
|
|
||||||
memcpy(btm_buffer + strlen(ui_delete_text)+1, file_str,
|
|
||||||
(strlen(file_str) > ((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) ?
|
|
||||||
((BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width) - terminal_width) :
|
|
||||||
strlen(file_str)));
|
|
||||||
|
|
||||||
memcpy(btm_buffer + (BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width - terminal_width) , "(y/N)", strlen("(y/N)"));
|
|
||||||
btm_buffer[BTM_WINDOW_HEIGHT_ON_STR_INTERACTION * terminal_width-1] = '\0';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
|
||||||
char ch = wgetch(win_b);
|
|
||||||
|
|
||||||
if (ch == 'y' || ch == 'Y') {
|
|
||||||
if (hits) {
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
recursive_delete(mid_content[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mid_content[selected_file_current].file_type & FILE_TYPE_DIR) {
|
cmd = parse_cmd(str, mid_dir.current_file);
|
||||||
recursive_delete(mid_content[selected_file_current]);
|
if (system(cmd)) {
|
||||||
}
|
}
|
||||||
remove(mid_content[selected_file_current].file_name);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
free(cmd);
|
||||||
}
|
}
|
||||||
free(btm_buffer);
|
free(parsed_ui_text);
|
||||||
btm_buffer = btm_buffer_tmp;
|
|
||||||
if (hits) {
|
|
||||||
free(file_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
}
|
|
||||||
|
|
||||||
void makedir(){
|
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
|
||||||
|
|
||||||
btm_buffer = "create dir: ";
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
|
||||||
|
|
||||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
|
||||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
|
||||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
|
||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
|
||||||
|
|
||||||
if (!err) {
|
|
||||||
concat(btm_buffer, btm_buffer, str, 0);
|
|
||||||
mode_t mask = umask(0);
|
|
||||||
mkdir(str, 0755); /*magic number from default permissions as created by mkdir*/
|
|
||||||
umask(mask);
|
|
||||||
}
|
|
||||||
free(str);
|
free(str);
|
||||||
free(btm_buffer);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
btm_buffer = btm_buffer_tmp;
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
}
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
void rename_hovered(){
|
||||||
|
wclear(win_b);
|
||||||
|
file tmp;
|
||||||
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
|
||||||
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
|
||||||
|
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
|
||||||
|
char *cmd1 = parse_cmd(cmd0, &tmp);
|
||||||
|
system(cmd1);
|
||||||
|
free(cmd0);
|
||||||
|
free(cmd1);
|
||||||
|
}
|
||||||
|
free(parsed_ui_text);
|
||||||
|
free(tmp.file_name);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
|
}
|
||||||
|
void delete(){
|
||||||
|
TODO;
|
||||||
|
}
|
||||||
|
void makedir(){
|
||||||
|
wclear(win_b);
|
||||||
|
file tmp;
|
||||||
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
|
mvwprintw(win_b, 0, 0, ui_makedir_text);
|
||||||
|
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
|
||||||
|
char *cmd = parse_cmd(makedir_cmd, &tmp);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
}
|
||||||
|
free(tmp.file_name);
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void makefile(){
|
void makefile(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
wclear(win_b);
|
||||||
|
file tmp;
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
werase(win_b);
|
mvwprintw(win_b, 0, 0, ui_makefile_text);
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
char *cmd = parse_cmd(makefile_cmd, &tmp);
|
||||||
|
system(cmd);
|
||||||
btm_buffer = "create file: ";
|
free(cmd);
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
|
||||||
|
|
||||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
|
||||||
memset(str, ' ', INPUT_BUFFER_SIZE);
|
|
||||||
str[INPUT_BUFFER_SIZE-1] = '\0';
|
|
||||||
int err = read_string(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION - 1, 0, str);
|
|
||||||
|
|
||||||
if (!err) {
|
|
||||||
concat(btm_buffer, btm_buffer, str, 0);
|
|
||||||
FILE *fp;
|
|
||||||
fp = fopen(str, "w");
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
free(str);
|
free(tmp.file_name);
|
||||||
free(btm_buffer);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
btm_buffer = btm_buffer_tmp;
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(){
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
}
|
}
|
||||||
void enter_shell(unsigned long passes, int index){
|
void enter_shell(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes; /*remove compiler warning*/
|
||||||
|
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
endwin();\
|
||||||
images_clear();
|
echo();\
|
||||||
#endif
|
curs_set(1);\
|
||||||
endwin();
|
if (system(key_binding[index].black_magic)) {
|
||||||
if (system(key_binding[index].black_magic) != 0) {
|
|
||||||
/*do nothing*/
|
|
||||||
}
|
}
|
||||||
initscr();
|
initscr(); /* start ncurses */
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
noecho(); /* hide keyboard input */
|
||||||
|
curs_set(0);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
|
|
||||||
}
|
}
|
||||||
void not_implemented(unsigned long passes, int index){
|
void not_implemented(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
@@ -550,381 +375,171 @@ void not_implemented(unsigned long passes, int index){
|
|||||||
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
|
||||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
|
||||||
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
|
||||||
|
TODO;
|
||||||
}
|
}
|
||||||
void jump_to_dir(unsigned long passes, int index){
|
void jump_to_dir(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
char *ch = (char*)key_binding[index].black_magic;
|
unsigned long len;
|
||||||
char slash = 0;
|
char *c = strchr(key_binding[index].black_magic, '/');
|
||||||
unsigned int env_len = 0;
|
if (c) {
|
||||||
while (*ch != '\0') {
|
len = c - (char*)key_binding[index].black_magic;
|
||||||
if (*ch == '/') {
|
|
||||||
slash = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
env_len++;
|
|
||||||
ch++;
|
|
||||||
}
|
|
||||||
char *env_str = NULL;
|
|
||||||
char *env_parsed = NULL;
|
|
||||||
char *path = NULL;
|
|
||||||
ch = (char*)key_binding[index].black_magic;
|
|
||||||
if (*ch == '/') {
|
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
|
||||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
|
||||||
} else if (slash) {
|
|
||||||
env_str = malloc(env_len * sizeof(char));
|
|
||||||
memcpy(env_str, (char*)key_binding[index].black_magic +1, env_len);
|
|
||||||
env_str[env_len-1] = '\0';
|
|
||||||
env_parsed = getenv(env_str);
|
|
||||||
if (env_parsed) {
|
|
||||||
concat(path, env_parsed, (char*)key_binding[index].black_magic + env_len, 0);
|
|
||||||
} else {
|
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
|
||||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
env_parsed = getenv((char*)key_binding[index].black_magic +1);
|
len = strlen(key_binding[index].black_magic);
|
||||||
if (env_parsed) {
|
|
||||||
path = malloc(strlen(env_parsed)+1);
|
|
||||||
memcpy(path, env_parsed, strlen(env_parsed)+1);
|
|
||||||
} else {
|
|
||||||
path = malloc(strlen((char*)key_binding[index].black_magic));
|
|
||||||
memcpy(path, (char*)key_binding[index].black_magic, strlen((char*)key_binding[index].black_magic)+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (chdir(path) != 0) {
|
|
||||||
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
|
|
||||||
} else {
|
|
||||||
selected_file_current = dir_get_selected_file_current();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*env_parsed shall not be modified (read: free'd) - the man page*/
|
char *to_env = malloc(len + 1);
|
||||||
if (env_str) {
|
memcpy(to_env, key_binding[index].black_magic, len);
|
||||||
free(env_str);
|
to_env[len] = '\0';
|
||||||
}
|
char *env = getenv(to_env + 1); /*+1 to remove the '$' prefix, freeing env always segfaults*/
|
||||||
if(path) {
|
|
||||||
|
if (env) {
|
||||||
|
char *path = malloc(strlen(key_binding[index].black_magic) + strlen(env) + 1);
|
||||||
|
memcpy(path, env, strlen(env));
|
||||||
|
memcpy(path + strlen(env), key_binding[index].black_magic + len, strlen(key_binding[index].black_magic)+1);
|
||||||
|
change_dir(path);
|
||||||
free(path);
|
free(path);
|
||||||
|
} else {
|
||||||
|
change_dir(key_binding[index].black_magic);
|
||||||
}
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
free(to_env);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY );
|
||||||
}
|
}
|
||||||
void order_by(unsigned long passes, int index){
|
void order_by(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
|
|
||||||
free(seed);
|
seed = time(NULL);
|
||||||
seed = NULL;
|
|
||||||
seed = malloc(sizeof(time_t));
|
|
||||||
*seed = time(NULL);
|
|
||||||
|
|
||||||
order_func = key_binding[index].black_magic;
|
order_func = key_binding[index].black_magic;
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void cmd_on_selected(unsigned long passes, int index){
|
void cmd_on_selected(unsigned long passes, int index){
|
||||||
(void)passes;
|
(void)passes;
|
||||||
pthread_mutex_lock(&mutex_btm);
|
|
||||||
|
|
||||||
char *btm_buffer_tmp = btm_buffer;
|
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
|
||||||
btm_buffer = "";
|
system(cmd);
|
||||||
unsigned int i = 0;
|
|
||||||
unsigned int hits = 0;
|
|
||||||
char *file_str = "";
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
concat(file_str, file_str, "\'", 0);
|
|
||||||
concat(file_str, file_str, mid_content[i].file_name, 1);
|
|
||||||
concat(file_str, file_str, "\' ", 1);
|
|
||||||
hits++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hits) {
|
|
||||||
concat(btm_buffer, key_binding[index].black_magic, file_str, 2);
|
|
||||||
} else {
|
|
||||||
concat(btm_buffer, key_binding[index].black_magic, "\'", 0);
|
|
||||||
concat(btm_buffer, btm_buffer, mid_content[selected_file_current].file_name, 1);
|
|
||||||
concat(btm_buffer, btm_buffer, "\'", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
concat(btm_buffer, btm_buffer, "?", 1);
|
|
||||||
concat(btm_buffer, btm_buffer, "\n\n", 1);
|
|
||||||
concat(btm_buffer, btm_buffer, "(y/N)", 1);
|
|
||||||
|
|
||||||
werase(win_b);
|
|
||||||
mvwin(win_b, terminal_height-6, 0);
|
|
||||||
wresize(win_b, BTM_WINDOW_HEIGHT_ON_STR_INTERACTION, terminal_width/3); /*the div3 just looks cool*/
|
|
||||||
|
|
||||||
window_btm(win_b, 1);
|
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
|
||||||
/* TODO(2025-07-06T07:22:49) fix fixed buffer size */
|
|
||||||
char ch = wgetch(win_b);
|
|
||||||
|
|
||||||
if (ch == 'y' || ch == 'Y') {
|
|
||||||
/* the second loop is used to add "./", wich is not being printed" */
|
|
||||||
char *cmd = malloc(sizeof(char));
|
|
||||||
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
|
|
||||||
endwin();
|
|
||||||
if (hits) {
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
free(cmd);
|
|
||||||
concat(cmd, (char*)key_binding[index].black_magic, " \'", 0);
|
|
||||||
concat(cmd, cmd, mid_content[i].file_name, 1);
|
|
||||||
concat(cmd, cmd, "\'", 1);
|
|
||||||
if (system(cmd) != 0) {
|
|
||||||
/*do nothing*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
free(cmd);
|
|
||||||
concat(cmd, (char*)key_binding[index].black_magic, " \'", 0);
|
|
||||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
|
||||||
concat(cmd, cmd, "\'", 1);
|
|
||||||
if (system(cmd) != 0) {
|
|
||||||
/*do nothing*/
|
|
||||||
}
|
|
||||||
mvaddstr(10,10, cmd);
|
|
||||||
|
|
||||||
}
|
|
||||||
/*system(cmd);*/
|
|
||||||
free(cmd);
|
|
||||||
initscr();
|
|
||||||
|
|
||||||
}
|
|
||||||
free(btm_buffer);
|
|
||||||
btm_buffer = btm_buffer_tmp;
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
}
|
|
||||||
void yank_text(unsigned long passes, int index){
|
|
||||||
(void)passes;
|
|
||||||
char *cmd;
|
|
||||||
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
|
|
||||||
char *path=getcwd(NULL, 0);
|
|
||||||
concat(cmd, "echo \'", path, 0);
|
|
||||||
concat(cmd, cmd, "/", 1);
|
|
||||||
concat(cmd, cmd, mid_content[selected_file_current].file_name, 1);
|
|
||||||
concat(cmd, cmd, "\' | ", 1);
|
|
||||||
concat(cmd, cmd, clipboard_cmd, 1);
|
|
||||||
free(path);
|
|
||||||
} else {
|
|
||||||
concat(cmd, "echo \'", mid_content[selected_file_current].file_name, 0);
|
|
||||||
concat(cmd, cmd, "\' | ", 1);
|
|
||||||
concat(cmd, cmd, clipboard_cmd, 1);
|
|
||||||
}
|
|
||||||
if (system(cmd) == -1) {
|
|
||||||
/*do nothing*/
|
|
||||||
}
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
|
}
|
||||||
|
void yank_file_name(){
|
||||||
|
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
}
|
||||||
|
void yank_file_path(){
|
||||||
|
file *tmp = malloc(sizeof(file));
|
||||||
|
tmp->file_name = malloc(strlen(global_path)+1+strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
memcpy(tmp->file_name, global_path, strlen(global_path));
|
||||||
|
memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/
|
||||||
|
char *cmd = parse_cmd(clipboard_cmd, tmp);
|
||||||
|
system(cmd);
|
||||||
|
free(cmd);
|
||||||
|
free(tmp->file_name);
|
||||||
|
free(tmp);
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void yank_file(unsigned long passes, int index){
|
void yank_file(unsigned long passes, int index){
|
||||||
(void)passes;
|
TODO;
|
||||||
|
|
||||||
unsigned long i;
|
|
||||||
if (yank_files.status & YANK_IS_USED) {
|
|
||||||
for (i = 0; i < yank_files.count; i++) {
|
|
||||||
free(yank_files.list[i]);
|
|
||||||
}
|
|
||||||
free(yank_files.list);
|
|
||||||
free(yank_files.path);
|
|
||||||
yank_files.count = 0;
|
|
||||||
yank_files.status = 0;
|
|
||||||
}
|
|
||||||
yank_files.path=getcwd(NULL, 0);
|
|
||||||
yank_files.count = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
yank_files.count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (yank_files.count == 0) {
|
|
||||||
yank_files.count = 1;
|
|
||||||
yank_files.list = (char**)malloc(yank_files.count * sizeof(char*));
|
|
||||||
*yank_files.list = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
|
||||||
memcpy(*yank_files.list, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name)+1);
|
|
||||||
} else {
|
|
||||||
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
if (mid_content[i].status & FILE_STATUS_SELECTED) {
|
|
||||||
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
|
|
||||||
memcpy(*yank_files.list, mid_content[i].file_name, strlen(mid_content[i].file_name)+1);
|
|
||||||
yank_files.list += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
yank_files.list -= yank_files.count;
|
|
||||||
}
|
|
||||||
yank_files.status |= YANK_IS_USED;
|
|
||||||
if (strncmp((char*)key_binding[index].black_magic, "cut", 3) == 0) {
|
|
||||||
yank_files.status |= YANK_CUT;
|
|
||||||
yank_files.status &= ~YANK_COPY;
|
|
||||||
} else {
|
|
||||||
yank_files.status |= YANK_COPY;
|
|
||||||
yank_files.status &= ~YANK_CUT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void paste(){
|
void paste(){
|
||||||
unsigned long i;
|
TODO;
|
||||||
for (i = 0; i < yank_files.count; i++) {
|
|
||||||
char *cmd;
|
|
||||||
if (yank_files.status & YANK_COPY) {
|
|
||||||
concat(cmd, "false | cp -ri \'", yank_files.path, 0);
|
|
||||||
} else {
|
|
||||||
concat(cmd, "mv \'", yank_files.path, 0);
|
|
||||||
}
|
|
||||||
concat(cmd, cmd, "/", 1);
|
|
||||||
concat(cmd, cmd, *yank_files.list, 1);
|
|
||||||
concat(cmd, cmd, "\' ./", 1);
|
|
||||||
concat(cmd, cmd, " 2>&1", 1);
|
|
||||||
char *line = malloc(INPUT_BUFFER_SIZE);
|
|
||||||
FILE *cmd_open;
|
|
||||||
while (1) {
|
|
||||||
cmd_open = popen(cmd, "r");
|
|
||||||
if (fgets(line, INPUT_BUFFER_SIZE, cmd_open) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (strstr(line, "are the same file")) {
|
|
||||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
|
||||||
concat(cmd, cmd, "_", 1);
|
|
||||||
concat(cmd, cmd, " 2>&1", 1);
|
|
||||||
} else if ((strstr(line, "overwrite"))) {
|
|
||||||
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
|
|
||||||
concat(cmd, cmd, "_", 1);
|
|
||||||
concat(cmd, cmd, " 2>&1", 1);
|
|
||||||
} else if ((strstr(line, "No such file or directory"))) {
|
|
||||||
pclose(cmd_open);
|
|
||||||
break;
|
|
||||||
} else if ((strstr(line, "into itself"))) {
|
|
||||||
pclose(cmd_open);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (pclose(cmd_open) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
|
|
||||||
yank_files.list++;
|
|
||||||
}
|
|
||||||
yank_files.list -= yank_files.count;
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
|
|
||||||
}
|
}
|
||||||
void search(){
|
void search(){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
echo();
|
||||||
|
unsigned long i;
|
||||||
unsigned long local_height;
|
for (i = 0; i < terminal_width -1; i++) {
|
||||||
local_height = getmaxy(win_b);
|
mvwaddch(win_b, 0, i, ' ');
|
||||||
memset(search_buffer, '\0', INPUT_BUFFER_SIZE);
|
}
|
||||||
|
mvwaddch(win_b, 0, 0, '/');
|
||||||
window_btm(win_b, 1);
|
memset(search_buffer, 0, INPUT_BUFFER_SIZE);
|
||||||
|
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
|
echo();
|
||||||
|
|
||||||
timeout(-1); /* negative numbers block until enter is pressed */
|
timeout(-1); /* negative numbers block until enter is pressed */
|
||||||
|
|
||||||
unsigned int pass = 0;
|
unsigned int pass = 0;
|
||||||
char ch;
|
char ch;
|
||||||
|
char err = 0;
|
||||||
|
|
||||||
wmove(win_b, local_height-1, 1);
|
wmove(win_b, 0, 1);
|
||||||
while(1) {
|
while(1) {
|
||||||
/*ch = mvwgetch(win, y, x + pass);*/
|
|
||||||
werase(win_b);
|
|
||||||
mvwaddch(win_b, local_height-1, 0, '/');
|
|
||||||
mvwaddstr(win_b, local_height-1, 1, search_buffer);
|
|
||||||
ch = wgetch(win_b);
|
ch = wgetch(win_b);
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
|
err = 0;
|
||||||
break;
|
break;
|
||||||
} else if (ch == '\t') { /* tab */
|
} else if (ch == '\t') { /* tab */
|
||||||
memcpy(search_buffer, mid_content[selected_file_current].file_name, strlen(mid_content[selected_file_current].file_name));
|
memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
|
||||||
mvwaddstr(win_b, local_height-1, pass, mid_content[selected_file_current].file_name);
|
mvwaddstr(win_b, 0, pass+1, mid_dir.current_file->file_name);
|
||||||
pass = strlen(mid_content[selected_file_current].file_name);
|
pass += strlen(mid_dir.current_file->file_name);
|
||||||
} else if (ch == 127) { /* backspace */
|
} else if (ch == 127) { /* backspace */
|
||||||
mvwdelch(win_b, local_height-1, 1);
|
if (pass > 0) {
|
||||||
wdelch(win_b);
|
|
||||||
if (pass != 0) {
|
|
||||||
search_buffer[pass-1] = '\0';
|
|
||||||
pass--;
|
pass--;
|
||||||
|
mvwdelch(win_b, 0, pass+1);
|
||||||
}
|
}
|
||||||
} else if (ch == 27) { /* esc key */
|
} else if (ch == 27) { /* esc key */
|
||||||
|
err = 1;
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
if (ch) {
|
||||||
|
mvwaddch(win_b, 0, pass+1, ch);
|
||||||
search_buffer[pass] = ch;
|
search_buffer[pass] = ch;
|
||||||
pass++;
|
pass++;
|
||||||
unsigned long i;
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
unsigned long index = (mid_dir.current_file - mid_dir.file_list);
|
||||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
unsigned long x = getmaxx(win_b);
|
||||||
selected_file_current = i;
|
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
||||||
if (update_selected_file()) {
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
pthread_cond_signal(&cond_rgt);
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
}
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
/* re-render current dir */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
|
||||||
|
werase(win_m);
|
||||||
|
print_dir(win_m, 1, &mid_dir);
|
||||||
|
|
||||||
|
wnoutrefresh(win_m);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
render_pass();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
search_buffer[pass] = '\0';
|
search_buffer[pass] = '\0';
|
||||||
|
|
||||||
|
noecho();
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
|
|
||||||
current_dir->selected_file_current = selected_file_current;
|
status |= (STATUS_RUN_BACKEND);
|
||||||
|
|
||||||
update_selected_file();
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
|
||||||
}
|
}
|
||||||
void search_next(){
|
void search_next(){
|
||||||
unsigned long i;
|
long index = (mid_dir.current_file - mid_dir.file_list) + 1;
|
||||||
for (i = selected_file_current+1; i < mid_file_count; i++) {
|
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
|
||||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
selected_file_current = i;
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
update_selected_file();
|
|
||||||
render_pass();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void search_previous(){
|
void search_previous(){
|
||||||
unsigned long i;
|
long index = (mid_dir.current_file - mid_dir.file_list) - 1;
|
||||||
for (i = selected_file_current-1;; i--) {
|
for (; &mid_dir.file_list[index] >= mid_dir.file_list; index--) {
|
||||||
if(i > selected_file_current) {
|
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
|
||||||
break;
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
}
|
|
||||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
|
||||||
selected_file_current = i;
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
update_selected_file();
|
|
||||||
render_pass();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
status |= (STATUS_RUN_BACKEND);
|
||||||
}
|
}
|
||||||
void jmp_file_index(){
|
void jmp_file_index(){
|
||||||
char *index = malloc(INPUT_BUFFER_SIZE);
|
TODO;
|
||||||
memset(index, ' ', INPUT_BUFFER_SIZE);
|
|
||||||
index[INPUT_BUFFER_SIZE-1] = '\0';
|
|
||||||
unsigned long local_height;
|
|
||||||
local_height = getmaxy(win_b);
|
|
||||||
read_string(win_b, local_height - 1, 0, index);
|
|
||||||
|
|
||||||
unsigned long new_index = 0;
|
|
||||||
while((*index >= '0') && (*index <= '9')) {
|
|
||||||
new_index = (new_index * 10) + (*index - '0');
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (new_index > mid_file_count) {
|
|
||||||
selected_file_current = mid_file_count;
|
|
||||||
} else {
|
|
||||||
selected_file_current = new_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
|
||||||
update_selected_file();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ void not_implemented(unsigned long passes, int index);
|
|||||||
void jump_to_dir(unsigned long passes, int index);
|
void jump_to_dir(unsigned long passes, int index);
|
||||||
void order_by(unsigned long passes, int index);
|
void order_by(unsigned long passes, int index);
|
||||||
void cmd_on_selected(unsigned long passes, int index);
|
void cmd_on_selected(unsigned long passes, int index);
|
||||||
void yank_text(unsigned long passes, int index);
|
void yank_file_name();
|
||||||
|
void yank_file_path();
|
||||||
void yank_file(unsigned long passes, int index);
|
void yank_file(unsigned long passes, int index);
|
||||||
void paste();
|
void paste();
|
||||||
void search();
|
void search();
|
||||||
|
|||||||
77
main.c
77
main.c
@@ -19,11 +19,10 @@ unsigned int terminal_width;
|
|||||||
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
unsigned int temp_heigth = 0; /*used for screen refresh*/
|
||||||
unsigned int temp_width = 0;
|
unsigned int temp_width = 0;
|
||||||
unsigned int settings;
|
unsigned int settings;
|
||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers = 0;
|
||||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY) & ~STATUS_UPDATE_SCREEN_RESIZE;
|
||||||
char *start_path;
|
|
||||||
char *global_path;
|
char *global_path;
|
||||||
time_t *seed;
|
time_t seed;
|
||||||
|
|
||||||
WINDOW *win_t;
|
WINDOW *win_t;
|
||||||
WINDOW *win_b;
|
WINDOW *win_b;
|
||||||
@@ -31,8 +30,13 @@ WINDOW *win_l;
|
|||||||
WINDOW *win_m;
|
WINDOW *win_m;
|
||||||
WINDOW *win_r;
|
WINDOW *win_r;
|
||||||
|
|
||||||
|
extern pthread_mutex_t mutex_top;
|
||||||
|
extern pthread_mutex_t mutex_btm;
|
||||||
|
extern pthread_mutex_t mutex_lft;
|
||||||
|
extern pthread_mutex_t mutex_mid;
|
||||||
|
extern pthread_mutex_t mutex_rgt;
|
||||||
|
|
||||||
char *input; /*used in user_interactions*/
|
char *input; /*used in user_interactions*/
|
||||||
char *terminal_width_empty_line; /* used in user_interactions */
|
|
||||||
|
|
||||||
void render_pass();
|
void render_pass();
|
||||||
void init();
|
void init();
|
||||||
@@ -59,7 +63,6 @@ int main(){
|
|||||||
pthread_t thread_m;
|
pthread_t thread_m;
|
||||||
pthread_t thread_r;
|
pthread_t thread_r;
|
||||||
|
|
||||||
terminal_width_empty_line = malloc(terminal_width);
|
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
time_t t;
|
time_t t;
|
||||||
time_t dt;
|
time_t dt;
|
||||||
@@ -72,37 +75,29 @@ int main(){
|
|||||||
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
pthread_create(&thread_r, NULL, thread_rgt, &status); /*child_content slash win_r*/
|
||||||
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
pthread_create(&thread_b, NULL, thread_btm, &status); /*bottom bar*/
|
||||||
|
|
||||||
|
|
||||||
/* running through all once manually in order to get an as fast as possible first render on the screen */
|
|
||||||
pthread_cond_signal(&cond_top);
|
|
||||||
pthread_cond_signal(&cond_mid);
|
|
||||||
pthread_cond_signal(&cond_lft);
|
|
||||||
user_interactions();
|
|
||||||
render_pass();
|
|
||||||
timeout(SETTINGS_CURSES_TIMEOUT);
|
timeout(SETTINGS_CURSES_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
getmaxyx(stdscr, terminal_height, terminal_width);
|
getmaxyx(stdscr, terminal_height, terminal_width);
|
||||||
|
|
||||||
|
if (status & STATUS_RUN_BACKEND) {
|
||||||
|
free(global_path);
|
||||||
|
global_path = getcwd(NULL, 0);
|
||||||
|
pthread_cond_signal(&cond_mid);
|
||||||
|
pthread_cond_signal(&cond_lft);
|
||||||
|
status &= ~(STATUS_RUN_BACKEND);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(terminal_height == temp_heigth) || !(terminal_width == temp_width)) {
|
if (!(terminal_height == temp_heigth) || !(terminal_width == temp_width)) {
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_RESIZE);
|
||||||
temp_width = terminal_width;
|
temp_width = terminal_width;
|
||||||
temp_heigth = terminal_height;
|
temp_heigth = terminal_height;
|
||||||
}
|
}
|
||||||
if (status & STATUS_RUN_BACKEND) {
|
|
||||||
free(global_path);
|
|
||||||
global_path = getcwd(NULL, 0);
|
|
||||||
pthread_cond_signal(&cond_top);
|
|
||||||
pthread_cond_signal(&cond_mid);
|
|
||||||
pthread_cond_signal(&cond_lft);
|
|
||||||
status &= ~(STATUS_RUN_BACKEND);
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
} else {
|
|
||||||
status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
|
|
||||||
}
|
|
||||||
user_interactions();
|
user_interactions();
|
||||||
|
|
||||||
render_pass();
|
render_pass();
|
||||||
|
|
||||||
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
#if SETTINGS_RELOAD_DIR_DELTA != 0
|
||||||
@@ -118,7 +113,6 @@ int main(){
|
|||||||
ueberzug_close();
|
ueberzug_close();
|
||||||
#endif
|
#endif
|
||||||
threading_free();
|
threading_free();
|
||||||
free(start_path);
|
|
||||||
|
|
||||||
delwin(win_l);
|
delwin(win_l);
|
||||||
delwin(win_m);
|
delwin(win_m);
|
||||||
@@ -135,11 +129,11 @@ int main(){
|
|||||||
|
|
||||||
void render_pass(){
|
void render_pass(){
|
||||||
|
|
||||||
|
if (status & STATUS_UPDATE_SCREEN_CLEAR) {
|
||||||
|
clear();
|
||||||
|
status &= ~STATUS_UPDATE_SCREEN_CLEAR;
|
||||||
|
}
|
||||||
if (status & STATUS_UPDATE_SCREEN_RESIZE) {
|
if (status & STATUS_UPDATE_SCREEN_RESIZE) {
|
||||||
if (status & STATUS_UPDATE_SCREEN_RELOAD_FULL) {
|
|
||||||
clear();
|
|
||||||
status &= ~STATUS_UPDATE_SCREEN_RELOAD_FULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
wresize(win_t, 1, terminal_width);
|
wresize(win_t, 1, terminal_width);
|
||||||
wresize(win_l, terminal_height-2, terminal_width/8);
|
wresize(win_l, terminal_height-2, terminal_width/8);
|
||||||
@@ -154,22 +148,11 @@ void render_pass(){
|
|||||||
mvwin(win_r, 1, ((terminal_width/2)));
|
mvwin(win_r, 1, ((terminal_width/2)));
|
||||||
mvwin(win_b, terminal_height-1, 0);
|
mvwin(win_b, terminal_height-1, 0);
|
||||||
|
|
||||||
|
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
|
||||||
}
|
}
|
||||||
|
if (pthread_mutex_lock(&mutex_render) == 0 || status & STATUS_UPDATE_SCREEN_MASK) {
|
||||||
if (status & STATUS_UPDATE_SCREEN_MASK) {
|
doupdate();
|
||||||
status &= ~(STATUS_UPDATE_SCREEN_MASK);
|
status &= ~STATUS_UPDATE_SCREEN_MASK;
|
||||||
window_top(win_t);
|
pthread_mutex_unlock(&mutex_render);
|
||||||
window_lft(win_l);
|
|
||||||
window_mid(win_m);
|
|
||||||
window_rgt(win_r);
|
|
||||||
window_btm(win_b, 0);
|
|
||||||
wrefresh(win_t);
|
|
||||||
wrefresh(win_l);
|
|
||||||
wrefresh(win_m);
|
|
||||||
wrefresh(win_r);
|
|
||||||
wrefresh(win_b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
/*this function exists for things done at startup (initialization, reading config, etc)*/
|
||||||
@@ -187,7 +170,6 @@ void init() {
|
|||||||
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
/*file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);*/
|
||||||
input = malloc(INPUT_BUFFER_SIZE); /* size of input buffer, out of bounds access will not be accounted for */
|
input = malloc(INPUT_BUFFER_SIZE); /* size of input buffer, out of bounds access will not be accounted for */
|
||||||
memset(input, 0, INPUT_BUFFER_SIZE);
|
memset(input, 0, INPUT_BUFFER_SIZE);
|
||||||
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
status |= STATUS_USER_ROOT;
|
status |= STATUS_USER_ROOT;
|
||||||
}
|
}
|
||||||
@@ -205,7 +187,6 @@ void init() {
|
|||||||
setenv("START_PATH", start_path, 0);
|
setenv("START_PATH", start_path, 0);
|
||||||
free(start_path);
|
free(start_path);
|
||||||
|
|
||||||
seed = malloc(sizeof(time_t));
|
seed = time(NULL);
|
||||||
*seed = time(NULL);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
23
sorting.c
23
sorting.c
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
extern time_t *seed;
|
extern time_t seed;
|
||||||
|
|
||||||
int skip_hidden_files(const struct dirent *entry){
|
int skip_hidden_files(const struct dirent *entry){
|
||||||
|
|
||||||
@@ -117,15 +117,22 @@ int sort_random(const void *file0, const void *file1){
|
|||||||
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
time_t num = ((time_t)&sort_random)^((time_t)sort_natural);
|
/* seed is the only value that actually changes whenever this funcion is called.
|
||||||
int i = 1;
|
* seed only updates when the order_by binding is executed.
|
||||||
for (; i < 6; i++) {
|
* this means that the random output only changes on the command of the user, and not SETTINGS_RELOAD_DIR_DELTA, this is intentional.
|
||||||
num += *seed;
|
* well the other stuff like file sizes and file count in a dir may also change, but this needs user intervention too.
|
||||||
num ^= num << ((((time_t)&seed)%6)+i);
|
* that is unless the user decides to sort random in /var/log or something, which begs the question: why would you do that?
|
||||||
num ^= num >> ((((time_t)&num)%9)+i);
|
*/
|
||||||
|
time_t num = (((time_t)&sort_random) + (time_t)seed) ^ (((file*)file0)->file_size + ((file*)file1)->file_size);
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < (((time_t)&getpid)%3); i++) {
|
||||||
|
num ^= num << ((((time_t)&file0)%27)+i);
|
||||||
|
num ^= num >> ((((time_t)&file1)%18)+i);
|
||||||
|
num ^= ((time_t)&getpid) ^ (((time_t)&getpid) >> ((time_t)getpid())%10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((num%3) - 1);
|
return (((num & (3 << seed%16)) >> seed%16) - 1);
|
||||||
|
/*return ((num%3) - 1);*/
|
||||||
|
|
||||||
}
|
}
|
||||||
int sort_type(const void *file0, const void *file1){
|
int sort_type(const void *file0, const void *file1){
|
||||||
|
|||||||
119
string.h
Normal file
119
string.h
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#include <curses.h>
|
||||||
|
#ifndef BACKEND_GUARD
|
||||||
|
#define BACKEND_GUARD
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
#define SETTINGS_COMMAND_REPLACE_STR "%"
|
||||||
|
|
||||||
|
typedef struct String {
|
||||||
|
char *data;
|
||||||
|
size_t size;
|
||||||
|
} string;
|
||||||
|
|
||||||
|
#define s(str) { \
|
||||||
|
return (string) { \
|
||||||
|
.data = str; \
|
||||||
|
.size = strlen(str); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define concat(out, s1, s2, _free) { \
|
||||||
|
concat## _free(out, s1, s2); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define concat0(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
|
||||||
|
#define concat1(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s1); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
#define concat2(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s2); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
#define concat3(out, s1, s2) \
|
||||||
|
char *result = malloc(strlen(s1) + strlen(s2) + 1); \
|
||||||
|
memcpy(result, s1, strlen(s1)); \
|
||||||
|
memcpy(result + strlen(s1), s2, strlen(s2) + 1); \
|
||||||
|
free(s1); \
|
||||||
|
free(s2); \
|
||||||
|
out = result;
|
||||||
|
|
||||||
|
/*
|
||||||
|
int s_strcmp(const char *s0, char string *s1) {
|
||||||
|
size_t size = s1->size - s0->size;
|
||||||
|
if (size) {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
size = s0.size;
|
||||||
|
while (*s0->data == *s0->data && size) {
|
||||||
|
s0->data += 1;
|
||||||
|
s1->data += 1;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
char* smartstrcasestr(const char *haystack, const char *needle){
|
||||||
|
char smart = 0;
|
||||||
|
char *ret;
|
||||||
|
char passes = 0;
|
||||||
|
while (*needle) {
|
||||||
|
if (*needle >= 'A' && *needle <= 'Z') {
|
||||||
|
smart = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
passes++;
|
||||||
|
needle++;
|
||||||
|
}
|
||||||
|
needle -= passes;
|
||||||
|
if (smart == 0) {
|
||||||
|
char *needle_case = malloc(strlen(needle)+1);
|
||||||
|
memcpy(needle_case, needle, strlen(needle)+1);
|
||||||
|
passes = 0;
|
||||||
|
while (*needle_case) {
|
||||||
|
*needle_case = *needle_case | ' ';
|
||||||
|
needle_case++;
|
||||||
|
passes++;
|
||||||
|
}
|
||||||
|
needle_case -= passes;
|
||||||
|
|
||||||
|
char *haystack_case = malloc(strlen(haystack)+1);
|
||||||
|
memcpy(haystack_case, haystack, strlen(haystack)+1);
|
||||||
|
passes = 0;
|
||||||
|
while (*haystack_case) {
|
||||||
|
*haystack_case = *haystack_case | ' ';
|
||||||
|
haystack_case++;
|
||||||
|
passes++;
|
||||||
|
}
|
||||||
|
haystack_case -= passes;
|
||||||
|
|
||||||
|
ret = strstr(haystack_case, needle_case);
|
||||||
|
free(needle_case);
|
||||||
|
free(haystack_case);
|
||||||
|
} else {
|
||||||
|
ret = strstr(haystack, needle);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*char* concat(const char *s1, const char *s2);*/
|
||||||
|
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||||
362
threading.c
362
threading.c
@@ -4,7 +4,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
@@ -19,7 +18,7 @@ pthread_mutex_t mutex_btm;
|
|||||||
pthread_mutex_t mutex_lft;
|
pthread_mutex_t mutex_lft;
|
||||||
pthread_mutex_t mutex_mid;
|
pthread_mutex_t mutex_mid;
|
||||||
pthread_mutex_t mutex_rgt;
|
pthread_mutex_t mutex_rgt;
|
||||||
pthread_mutex_t mutex_selection;
|
pthread_mutex_t mutex_render;
|
||||||
pthread_cond_t cond_mid;
|
pthread_cond_t cond_mid;
|
||||||
pthread_cond_t cond_rgt;
|
pthread_cond_t cond_rgt;
|
||||||
pthread_cond_t cond_lft;
|
pthread_cond_t cond_lft;
|
||||||
@@ -27,24 +26,24 @@ pthread_cond_t cond_top;
|
|||||||
pthread_cond_t cond_btm;
|
pthread_cond_t cond_btm;
|
||||||
|
|
||||||
|
|
||||||
file *rgt_content;
|
dir rgt_dir;
|
||||||
file *mid_content;
|
dir mid_dir;
|
||||||
file *lft_content;
|
dir lft_dir;
|
||||||
char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
|
char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
|
||||||
char *btm_buffer;
|
char *btm_buffer;
|
||||||
char *top_buffer; /* current path */
|
char *top_buffer; /* current path */
|
||||||
|
|
||||||
|
extern WINDOW *win_t;
|
||||||
|
extern WINDOW *win_b;
|
||||||
|
extern WINDOW *win_l;
|
||||||
|
extern WINDOW *win_m;
|
||||||
|
extern WINDOW *win_r;
|
||||||
|
|
||||||
|
|
||||||
unsigned long rgt_file_count = 0;
|
|
||||||
unsigned long mid_file_count = 0;
|
|
||||||
unsigned long lft_file_count;
|
|
||||||
unsigned long top_width;
|
unsigned long top_width;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
volatile unsigned long selected_file_current = 0;
|
|
||||||
volatile unsigned long selected_file_last = 0;
|
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
extern unsigned int status;
|
extern unsigned int status;
|
||||||
extern char *global_path;
|
extern char *global_path;
|
||||||
@@ -53,55 +52,86 @@ unsigned int btm_status;
|
|||||||
|
|
||||||
|
|
||||||
void *thread_mid(){
|
void *thread_mid(){
|
||||||
|
dir tmp;
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
|
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
pthread_cond_wait(&cond_mid, &mutex_mid);
|
pthread_cond_wait(&cond_mid, &mutex_mid);
|
||||||
unsigned int local_status = status;
|
|
||||||
|
|
||||||
if (global_path == NULL) {
|
if (global_path == NULL) {
|
||||||
mid_content = malloc(sizeof(file));
|
mid_dir.current_file = NULL;
|
||||||
mid_content->file_name = "cannot open directory";
|
mid_dir.file_count = 0;
|
||||||
mid_file_count = 1;
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char *path = malloc(strlen(global_path)+1);
|
char *path = malloc(strlen(global_path)+1);
|
||||||
memcpy(path, global_path, strlen(global_path)+1);
|
memcpy(path, global_path, strlen(global_path)+1);
|
||||||
|
|
||||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
|
||||||
unsigned long i = 0;
|
|
||||||
for (i = 0; i < mid_file_count; i++) {
|
|
||||||
free(mid_content[i].file_name);
|
|
||||||
}
|
|
||||||
free(mid_content);
|
|
||||||
mid_file_count = get_dir_size(path);
|
|
||||||
if (mid_file_count != 0) {
|
|
||||||
mid_content = malloc(mid_file_count * sizeof(file));
|
|
||||||
memset(mid_content, '\0', mid_file_count * sizeof(file));
|
|
||||||
get_dir_content(path, &mid_file_count, mid_content);
|
|
||||||
} else {
|
|
||||||
selected_file_current = 0;
|
|
||||||
mid_content = malloc(sizeof(file));
|
|
||||||
mid_content->file_type = 0;
|
|
||||||
mid_content->file_size = 0;
|
|
||||||
mid_content->permissions = 0;
|
|
||||||
mid_content->color_pair = 0;
|
|
||||||
mid_content->file_name = malloc(sizeof(char));
|
|
||||||
mid_content->file_name[0] = '\0';
|
|
||||||
|
|
||||||
mid_file_count = 0;
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
|
long index = mid_dir.current_file - mid_dir.file_list;
|
||||||
|
|
||||||
|
tmp = mid_dir;
|
||||||
|
|
||||||
|
mid_dir.file_count = get_dir_size(path);
|
||||||
|
mid_dir.file_list = malloc(mid_dir.file_count * sizeof(file));
|
||||||
|
if (mid_dir.file_count) { /* fails if dir empty */
|
||||||
|
get_dir_content(path, &mid_dir);
|
||||||
|
mid_dir.current_file = &mid_dir.file_list[index];
|
||||||
|
|
||||||
|
} else { /* the hovered dir is empty */
|
||||||
|
mid_dir.current_file = NULL;
|
||||||
}
|
}
|
||||||
update_selected_file();
|
|
||||||
|
unsigned long i;
|
||||||
|
for(i = 0; i < mid_dir.file_count && i < tmp.file_count; i++) {
|
||||||
|
mid_dir.file_list[i].status = tmp.file_list[i].status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btm_status = local_status;
|
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
|
||||||
pthread_cond_signal(&cond_rgt);
|
mid_dir.current_file = mid_dir.file_list + mid_dir.file_count - 1;
|
||||||
pthread_cond_signal(&cond_btm);
|
}
|
||||||
|
if (mid_dir.current_file < mid_dir.file_list) {
|
||||||
|
mid_dir.current_file = mid_dir.file_list;
|
||||||
|
}
|
||||||
|
|
||||||
free(path);
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
|
pthread_cond_signal(&cond_top);
|
||||||
|
pthread_cond_signal(&cond_btm);
|
||||||
|
pthread_cond_signal(&cond_rgt);
|
||||||
|
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_m);
|
||||||
|
if (mid_dir.file_count == 0) {
|
||||||
|
mvwaddstr(win_m, 0, 0, "empty");
|
||||||
|
} else {
|
||||||
|
print_dir(win_m, 1, &mid_dir);
|
||||||
|
}
|
||||||
|
wnoutrefresh(win_m);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
|
free(tmp.file_list[i].file_name);
|
||||||
|
}
|
||||||
|
free(tmp.file_list);
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
@@ -110,12 +140,10 @@ void *thread_lft(){
|
|||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_lft);
|
pthread_mutex_lock(&mutex_lft);
|
||||||
pthread_cond_wait(&cond_lft, &mutex_lft);
|
pthread_cond_wait(&cond_lft, &mutex_lft);
|
||||||
unsigned int local_status = status;
|
|
||||||
|
|
||||||
if (global_path == NULL) {
|
if (global_path == NULL) {
|
||||||
lft_content = malloc(sizeof(file));
|
lft_dir.current_file = NULL;
|
||||||
lft_content[0].file_name = "cannot open directory";
|
lft_dir.file_count = 0;
|
||||||
lft_file_count = 1;
|
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -127,20 +155,36 @@ void *thread_lft(){
|
|||||||
path[strrchr(path, '/')-path] = '\0';
|
path[strrchr(path, '/')-path] = '\0';
|
||||||
path[0] = '/';
|
path[0] = '/';
|
||||||
|
|
||||||
if (local_status & STATUS_RELOAD_DIRECTORY) {
|
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||||
lft_file_count = get_dir_size(path);
|
unsigned long i = 0;
|
||||||
free(lft_content);
|
for (i = 0; i < lft_dir.file_count; i++) {
|
||||||
lft_content = malloc(lft_file_count * sizeof(file));
|
free(lft_dir.file_list[i].file_name);
|
||||||
memset(lft_content, '\0', lft_file_count * sizeof(file));
|
}
|
||||||
get_dir_content(path, &lft_file_count, lft_content);
|
free(lft_dir.file_list);
|
||||||
|
lft_dir.file_count = get_dir_size(path);
|
||||||
|
if (lft_dir.file_count != 0) {
|
||||||
|
lft_dir.file_list = malloc(lft_dir.file_count * sizeof(file));
|
||||||
|
get_dir_content(path, &lft_dir);
|
||||||
|
} else {
|
||||||
|
lft_dir.current_file = NULL;
|
||||||
|
lft_dir.file_count = 0;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lft_file_count = 0;
|
lft_dir.file_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_l);
|
||||||
|
print_dir(win_l, 0, &lft_dir);
|
||||||
|
wnoutrefresh(win_l);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
|
||||||
free(path);
|
free(path);
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
|
||||||
@@ -148,83 +192,80 @@ void *thread_lft(){
|
|||||||
}
|
}
|
||||||
void *thread_rgt(){
|
void *thread_rgt(){
|
||||||
|
|
||||||
file file_current;
|
dir tmp;
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_rgt);
|
pthread_mutex_lock(&mutex_rgt);
|
||||||
pthread_cond_wait(&cond_rgt, &mutex_rgt);
|
pthread_cond_wait(&cond_rgt, &mutex_rgt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
char *path = mid_content[selected_file_current].file_name;
|
|
||||||
memcpy(&file_current, &mid_content[selected_file_current], sizeof(file));
|
char *file_name = malloc(strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
file_name = memcpy(file_name, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
|
||||||
|
rgt_dir.file_list = malloc(sizeof(file));
|
||||||
|
memcpy(rgt_dir.file_list, mid_dir.current_file, sizeof(file));
|
||||||
|
rgt_dir.file_list->file_name = file_name;
|
||||||
|
rgt_dir.current_file = rgt_dir.file_list;
|
||||||
|
rgt_dir.file_count = 1;
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
|
||||||
if (file_current.permissions & S_IRUSR) {
|
|
||||||
if (file_current.file_type &= FILE_TYPE_DIR) {
|
|
||||||
|
if (rgt_dir.current_file->permissions & S_IRUSR) {
|
||||||
|
if (rgt_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
|
||||||
images_clear();
|
images_clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned long i = 0;
|
tmp = rgt_dir;
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
|
||||||
if (rgt_content[i].file_name) {
|
|
||||||
free(rgt_content[i].file_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(rgt_content);
|
|
||||||
|
|
||||||
rgt_file_count = get_dir_size(path);
|
rgt_dir.file_count = get_dir_size(rgt_dir.current_file->file_name);
|
||||||
if (rgt_file_count) { /* fails if dir empty */
|
rgt_dir.file_list = malloc(rgt_dir.file_count * sizeof(file));
|
||||||
rgt_content = malloc(rgt_file_count * sizeof(file));
|
if (rgt_dir.file_count) { /* fails if dir empty */
|
||||||
memset(rgt_content, '\0', rgt_file_count * sizeof(file));
|
get_dir_content(tmp.current_file->file_name, &rgt_dir);
|
||||||
get_dir_content(path, &rgt_file_count, rgt_content);
|
|
||||||
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
|
||||||
|
|
||||||
free(rgt_buffer);
|
|
||||||
rgt_buffer = malloc(sizeof(char));
|
|
||||||
rgt_buffer[0] = '\0';
|
|
||||||
} else { /* the hovered dir is empty */
|
} else { /* the hovered dir is empty */
|
||||||
rgt_content = malloc(sizeof(file));
|
rgt_dir.current_file = NULL;
|
||||||
rgt_content->file_type = 0;
|
|
||||||
rgt_content->permissions = mid_content[selected_file_current].permissions;
|
|
||||||
}
|
}
|
||||||
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && mid_file_count > 0) {
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_r);
|
||||||
|
print_dir(win_r, 0, &rgt_dir);
|
||||||
|
wnoutrefresh(win_r);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
unsigned long i = 0;
|
} else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME && rgt_dir.file_count > 0) {
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
|
||||||
if (rgt_content[i].file_name) {
|
|
||||||
free(rgt_content[i].file_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(rgt_content);
|
|
||||||
rgt_file_count = 0;
|
|
||||||
rgt_content = malloc(sizeof(file));
|
|
||||||
|
|
||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
rgt_buffer = preview_file(rgt_dir.current_file);
|
||||||
rgt_content->status = FILE_STATUS_HOVER;
|
rgt_dir.current_file->file_type |= FILE_TYPE_OPEN_FILE;
|
||||||
rgt_buffer = preview_file(path, file_current.file_size);
|
pthread_mutex_lock(&mutex_render);
|
||||||
}
|
werase(win_r);
|
||||||
} else {
|
if (rgt_dir.current_file->file_type & FILE_TYPE_OPEN_FILE) {
|
||||||
unsigned long i = 0;
|
mvwaddnstr(win_r, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||||
for (i = 0; i < rgt_file_count; i++) {
|
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
||||||
if (rgt_content[i].file_name) {
|
mvwaddstr(win_r, 0, 0, "not accessible");
|
||||||
free(rgt_content[i].file_name);
|
|
||||||
}
|
}
|
||||||
|
wnoutrefresh(win_r);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
}
|
}
|
||||||
free(rgt_content);
|
|
||||||
rgt_file_count = 0;
|
|
||||||
rgt_content = malloc(sizeof(file));
|
|
||||||
|
|
||||||
free(rgt_buffer);
|
|
||||||
rgt_buffer = malloc(sizeof(char));
|
|
||||||
rgt_buffer[0] = '\0';
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
free(path);
|
|
||||||
*/
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < tmp.file_count; i++) {
|
||||||
|
free(tmp.file_list[i].file_name);
|
||||||
|
}
|
||||||
|
free(tmp.file_list);
|
||||||
|
tmp.current_file = NULL;
|
||||||
|
tmp.file_list = NULL;
|
||||||
|
tmp.file_count = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
@@ -234,6 +275,7 @@ void *thread_top(){
|
|||||||
pthread_mutex_lock(&mutex_top);
|
pthread_mutex_lock(&mutex_top);
|
||||||
pthread_cond_wait(&cond_top, &mutex_top);
|
pthread_cond_wait(&cond_top, &mutex_top);
|
||||||
|
|
||||||
|
|
||||||
free(top_buffer);
|
free(top_buffer);
|
||||||
|
|
||||||
if(global_path == NULL) {
|
if(global_path == NULL) {
|
||||||
@@ -243,10 +285,28 @@ void *thread_top(){
|
|||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
top_buffer = malloc(strlen(global_path)+1);
|
|
||||||
memcpy(top_buffer, global_path, strlen(global_path)+1);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
|
|
||||||
|
top_buffer = malloc(strlen(global_path)+1 + strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
memcpy(top_buffer, global_path, strlen(global_path));
|
||||||
|
memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
|
top_buffer[strlen(global_path)] = '/';
|
||||||
top_width = strlen(top_buffer);
|
top_width = strlen(top_buffer);
|
||||||
/*printing of mid_content[selected_file_current].file_name is done directly in window.c window_top()*/
|
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_t);
|
||||||
|
wattron(win_t, COLOR_PAIR(COLOR_PATH));
|
||||||
|
mvwaddnstr(win_t, 0, 0, top_buffer, strlen(global_path)+1);
|
||||||
|
wattroff(win_t, COLOR_PAIR(COLOR_PATH));
|
||||||
|
mvwaddstr(win_t, 0, strlen(global_path)+1, top_buffer+strlen(global_path)+1);
|
||||||
|
wnoutrefresh(win_t);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
}
|
}
|
||||||
@@ -261,17 +321,16 @@ void *thread_btm(){
|
|||||||
while(!(status & STATUS_QUIT_PROGRAM)){
|
while(!(status & STATUS_QUIT_PROGRAM)){
|
||||||
pthread_mutex_lock(&mutex_btm);
|
pthread_mutex_lock(&mutex_btm);
|
||||||
pthread_cond_wait(&cond_btm, &mutex_btm);
|
pthread_cond_wait(&cond_btm, &mutex_btm);
|
||||||
unsigned int local_status = btm_status;
|
|
||||||
|
|
||||||
|
|
||||||
if (local_status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
|
if (status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
|
||||||
/*{{{ parse storage info; the fold of shame*/
|
/*{{{ parse storage info; the fold of shame*/
|
||||||
pthread_mutex_lock(&mutex_mid);
|
pthread_mutex_lock(&mutex_mid);
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
float total_dir_size = 0;
|
float total_dir_size = 0;
|
||||||
for(i = 0; i < mid_file_count; i++) {
|
for(i = 0; i < mid_dir.file_count; i++) {
|
||||||
if ((mid_content[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
|
if ((mid_dir.file_list[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
|
||||||
total_dir_size += mid_content[i].file_size;
|
total_dir_size += mid_dir.file_list[i].file_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
@@ -345,29 +404,38 @@ void *thread_btm(){
|
|||||||
|
|
||||||
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
|
||||||
|
|
||||||
btm_buffer[0] = (S_ISLNK(mid_content[selected_file_current].permissions)) ? 'l':
|
btm_buffer[0] = (S_ISLNK(mid_dir.current_file->permissions)) ? 'l':
|
||||||
(S_ISDIR(mid_content[selected_file_current].permissions) ? 'd': '-');
|
(S_ISDIR(mid_dir.current_file->permissions) ? 'd': '-');
|
||||||
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
|
btm_buffer[1] = (mid_dir.current_file->permissions & S_IRUSR) ? 'r' : '-';
|
||||||
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
|
btm_buffer[2] = (mid_dir.current_file->permissions & S_IWUSR) ? 'w' : '-';
|
||||||
btm_buffer[3] = (mid_content[selected_file_current].permissions & S_IXUSR) ? 'x' : '-';
|
btm_buffer[3] = (mid_dir.current_file->permissions & S_IXUSR) ? 'x' : '-';
|
||||||
btm_buffer[4] = (mid_content[selected_file_current].permissions & S_IRGRP) ? 'r' : '-';
|
btm_buffer[4] = (mid_dir.current_file->permissions & S_IRGRP) ? 'r' : '-';
|
||||||
btm_buffer[5] = (mid_content[selected_file_current].permissions & S_IWGRP) ? 'w' : '-';
|
btm_buffer[5] = (mid_dir.current_file->permissions & S_IWGRP) ? 'w' : '-';
|
||||||
btm_buffer[6] = (mid_content[selected_file_current].permissions & S_IXGRP) ? 'x' : '-';
|
btm_buffer[6] = (mid_dir.current_file->permissions & S_IXGRP) ? 'x' : '-';
|
||||||
btm_buffer[7] = (mid_content[selected_file_current].permissions & S_IROTH) ? 'r' : '-';
|
btm_buffer[7] = (mid_dir.current_file->permissions & S_IROTH) ? 'r' : '-';
|
||||||
btm_buffer[8] = (mid_content[selected_file_current].permissions & S_IWOTH) ? 'w' : '-';
|
btm_buffer[8] = (mid_dir.current_file->permissions & S_IWOTH) ? 'w' : '-';
|
||||||
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-';
|
btm_buffer[9] = (mid_dir.current_file->permissions & S_IXOTH) ? 'x' : '-';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* rendering */
|
||||||
|
pthread_mutex_lock(&mutex_render);
|
||||||
|
werase(win_b);
|
||||||
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
|
mvwprintw(win_b, 0, 0, "%s", btm_buffer);
|
||||||
|
}
|
||||||
|
wnoutrefresh(win_b);
|
||||||
|
pthread_mutex_unlock(&mutex_render);
|
||||||
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
|
/*the printing of all possible inputs are done in user_interactions */
|
||||||
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void threading_init(){
|
void threading_init(){
|
||||||
rgt_content = malloc(sizeof(file));
|
|
||||||
mid_content = malloc(sizeof(file));
|
|
||||||
lft_content = malloc(sizeof(file));
|
|
||||||
|
|
||||||
top_buffer = malloc(sizeof(char));
|
top_buffer = malloc(sizeof(char));
|
||||||
rgt_buffer = malloc(sizeof(char));
|
rgt_buffer = malloc(sizeof(char));
|
||||||
@@ -376,35 +444,21 @@ void threading_init(){
|
|||||||
memset(rgt_buffer, '\0', sizeof(char));
|
memset(rgt_buffer, '\0', sizeof(char));
|
||||||
memset(btm_buffer, '\0', sizeof(char));
|
memset(btm_buffer, '\0', sizeof(char));
|
||||||
|
|
||||||
mid_content->file_type = 0;
|
|
||||||
mid_content->file_size = 0;
|
|
||||||
mid_content->file_name = "";
|
|
||||||
|
|
||||||
rgt_content->file_type = 0;
|
pthread_mutex_init(&mutex_top, NULL);
|
||||||
rgt_content->file_size = 0;
|
pthread_mutex_init(&mutex_mid, NULL);
|
||||||
rgt_content->file_name = "";
|
pthread_mutex_init(&mutex_lft, NULL);
|
||||||
|
pthread_mutex_init(&mutex_btm, NULL);
|
||||||
|
pthread_mutex_init(&mutex_rgt, NULL);
|
||||||
volatile char vol; /* needed to make sure higher optimization steps dont move these around */
|
pthread_mutex_init(&mutex_render, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_top, NULL);
|
pthread_cond_init(&cond_rgt, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_mid, NULL);
|
pthread_cond_init(&cond_lft, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_lft, NULL);
|
pthread_cond_init(&cond_mid, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_btm, NULL);
|
pthread_cond_init(&cond_top, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_rgt, NULL);
|
pthread_cond_init(&cond_btm, NULL);
|
||||||
vol = pthread_mutex_init(&mutex_selection, NULL);
|
|
||||||
vol = pthread_cond_init(&cond_rgt, NULL);
|
|
||||||
vol = pthread_cond_init(&cond_lft, NULL);
|
|
||||||
vol = pthread_cond_init(&cond_mid, NULL);
|
|
||||||
vol = pthread_cond_init(&cond_top, NULL);
|
|
||||||
vol = pthread_cond_init(&cond_btm, NULL);
|
|
||||||
vol;
|
|
||||||
selected_file_current = 0;
|
|
||||||
selected_file_last = 0;
|
|
||||||
}
|
}
|
||||||
void threading_free(){
|
void threading_free(){
|
||||||
free(rgt_content);
|
|
||||||
free(mid_content);
|
|
||||||
free(lft_content);
|
|
||||||
free(top_buffer);
|
free(top_buffer);
|
||||||
|
|
||||||
pthread_mutex_destroy(&mutex_top);
|
pthread_mutex_destroy(&mutex_top);
|
||||||
|
|||||||
71
window.c
71
window.c
@@ -14,17 +14,14 @@ extern unsigned int timeout_time;
|
|||||||
extern unsigned int color_count;
|
extern unsigned int color_count;
|
||||||
extern color *colors;
|
extern color *colors;
|
||||||
|
|
||||||
extern file *mid_content;
|
extern dir rgt_dir;
|
||||||
extern file *lft_content;
|
extern dir mid_dir;
|
||||||
extern file *rgt_content;
|
extern dir lft_dir;
|
||||||
extern char *top_buffer;
|
extern char *top_buffer;
|
||||||
extern char *rgt_buffer;
|
extern char *rgt_buffer;
|
||||||
extern char *btm_buffer;
|
extern char *btm_buffer;
|
||||||
|
|
||||||
|
|
||||||
extern unsigned long lft_file_count;
|
|
||||||
extern unsigned long mid_file_count;
|
|
||||||
extern unsigned long rgt_file_count;
|
|
||||||
extern unsigned long top_width;
|
extern unsigned long top_width;
|
||||||
|
|
||||||
extern pthread_mutex_t mutex_top;
|
extern pthread_mutex_t mutex_top;
|
||||||
@@ -34,7 +31,6 @@ extern pthread_mutex_t mutex_mid;
|
|||||||
extern pthread_mutex_t mutex_rgt;
|
extern pthread_mutex_t mutex_rgt;
|
||||||
|
|
||||||
void window_top(WINDOW *win){
|
void window_top(WINDOW *win){
|
||||||
werase(win);
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_top) == 0) {
|
if (pthread_mutex_trylock(&mutex_top) == 0) {
|
||||||
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
@@ -42,18 +38,19 @@ void window_top(WINDOW *win){
|
|||||||
mvwaddstr(win, 0, 0, top_buffer);
|
mvwaddstr(win, 0, 0, top_buffer);
|
||||||
mvwaddch(win, 0, strlen(top_buffer), '/');
|
mvwaddch(win, 0, strlen(top_buffer), '/');
|
||||||
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
wattroff(win, COLOR_PAIR(COLOR_PATH));
|
||||||
if (mid_file_count != 0) {
|
if (mid_dir.file_count != 0) {
|
||||||
mvwaddstr(win, 0, strlen(top_buffer)+1, mid_content[selected_file_current].file_name);
|
mvwaddstr(win, 0, strlen(top_buffer)+1, mid_dir.current_file->file_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex_top);
|
pthread_mutex_unlock(&mutex_top);
|
||||||
} else {
|
} else {
|
||||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
/*
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_btm(WINDOW *win, char force_render){
|
void window_btm(WINDOW *win){
|
||||||
werase(win);
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
if (pthread_mutex_trylock(&mutex_btm) == 0) {
|
||||||
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
if (*top_buffer != ' ') { /*printing ' ' (standard initialized value, see threading_init) makes valgrind throw a fuss*/
|
||||||
@@ -62,62 +59,60 @@ void window_btm(WINDOW *win, char force_render){
|
|||||||
pthread_mutex_unlock(&mutex_btm);
|
pthread_mutex_unlock(&mutex_btm);
|
||||||
/*the printing of the input char is done in user_interactions*/
|
/*the printing of the input char is done in user_interactions*/
|
||||||
/*the printing of all possible inputs are done in user_interactions */
|
/*the printing of all possible inputs are done in user_interactions */
|
||||||
} else if (force_render) {
|
} else {
|
||||||
/*force_render is used in stuff like open_with, search, and other functions that take over win_b,
|
|
||||||
* while needing to avoid possible conflicts like thread_btm itself*/
|
|
||||||
mvwprintw(win, 0, 0, "%s", btm_buffer);
|
|
||||||
} else {
|
|
||||||
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
mvwaddstr(win, 0, terminal_width/2, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
/*
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_lft(WINDOW *win){
|
void window_lft(WINDOW *win){
|
||||||
werase(win);
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_lft) == 0) {
|
if (pthread_mutex_trylock(&mutex_lft) == 0) {
|
||||||
print_dir(win, 0, &lft_file_count, lft_content);
|
print_dir(win, 0, &lft_dir);
|
||||||
pthread_mutex_unlock(&mutex_lft);
|
pthread_mutex_unlock(&mutex_lft);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
|
mvwaddstr(win, terminal_height/2, terminal_width/8, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
/*
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_mid(WINDOW *win){
|
void window_mid(WINDOW *win){
|
||||||
werase(win);
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_mid) == 0) {
|
if (pthread_mutex_trylock(&mutex_mid) == 0) {
|
||||||
if (mid_file_count == 0) {
|
if (mid_dir.file_count == 0) {
|
||||||
mvwaddstr(win, 0, 0, "empty");
|
mvwaddstr(win, 0, 0, "empty");
|
||||||
} else {
|
} else {
|
||||||
print_dir(win, 1, &mid_file_count, mid_content);
|
print_dir(win, 1, &mid_dir);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&mutex_mid);
|
pthread_mutex_unlock(&mutex_mid);
|
||||||
} else {
|
} else {
|
||||||
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
/*
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void window_rgt(WINDOW *win){
|
void window_rgt(WINDOW *win){
|
||||||
werase(win);
|
|
||||||
|
|
||||||
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
|
if (pthread_mutex_trylock(&mutex_rgt) == 0) {
|
||||||
if (rgt_file_count == 0) {
|
if (!rgt_dir.current_file) {
|
||||||
if (rgt_content[0].file_type == FILE_TYPE_OPEN_FILE) {
|
mvwaddstr(win, 0, 0, "not accessible");
|
||||||
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
}else if (rgt_dir.current_file->file_type == FILE_TYPE_OPEN_FILE) {
|
||||||
} else if (rgt_content->permissions & S_IRUSR) {
|
mvwaddnstr(win, 0, 0, rgt_buffer, (terminal_width/2) * terminal_width);
|
||||||
mvwaddstr(win, 0, 0, "not accessible");
|
} else if ((rgt_dir.current_file->permissions & S_IRUSR) == 0) {
|
||||||
} else {
|
mvwaddstr(win, 0, 0, "not accessible");
|
||||||
mvwaddstr(win, 0, 0, "empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print_dir(win, 0, &rgt_file_count, rgt_content);
|
print_dir(win, 0, &rgt_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&mutex_rgt);
|
pthread_mutex_unlock(&mutex_rgt);
|
||||||
} else {
|
} else {
|
||||||
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
mvwaddstr(win, terminal_height/2, terminal_width/4, "LOADING");
|
||||||
status |= STATUS_UPDATE_SCREEN_0;
|
/*
|
||||||
|
status |= STATUS_UPDATE_SCREEN_GENERIC;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
window.h
2
window.h
@@ -1,7 +1,7 @@
|
|||||||
#include "window.c"
|
#include "window.c"
|
||||||
|
|
||||||
void window_top(WINDOW *win);
|
void window_top(WINDOW *win);
|
||||||
void window_btm(WINDOW *win, char force_render);
|
void window_btm(WINDOW *win);
|
||||||
void window_lft(WINDOW *win);
|
void window_lft(WINDOW *win);
|
||||||
void window_mid(WINDOW *win);
|
void window_mid(WINDOW *win);
|
||||||
void window_rgt(WINDOW *win);
|
void window_rgt(WINDOW *win);
|
||||||
|
|||||||
Reference in New Issue
Block a user