1
0
mirror of https://gittea.dev/nova/th.git synced 2025-10-21 10:20:15 -04:00

Compare commits

...

15 Commits

Author SHA1 Message Date
nova
df726e2f32 delta time no longer reloading images 2025-10-13 23:09:57 +02:00
nova
140457e4b7 fixed copy/paste 2025-10-13 22:47:38 +02:00
nova
23654741bc fixed sort_extension, changes too small to list to other sort methods 2025-10-13 21:44:19 +02:00
nova
fa544204ba implemented jmp_file_index & int passes -> unsigned long 2025-10-12 01:44:27 +02:00
nova
61023ce42e temporary fixes & removal of unused function 2025-10-11 21:49:28 +02:00
nova
3fa16fd8b2 changes too small for proper commit message 2025-10-09 01:01:52 +02:00
nova
ac6d0e8408 avoiding useless memory read/writes & fixing race condition in btm_status 2025-10-09 00:13:25 +02:00
nova
731bfe722a fixing move_right on extensionless files 2025-10-08 23:49:34 +02:00
nova
3082fed378 fixed some race conditions and improved parsing storage size 2025-10-08 21:33:06 +02:00
nova
23ff0b07ec adding forgotten mutex unlocks 2025-10-05 21:56:56 +02:00
nova
c2d88f4909 moving stuff around to avoid 'previous implicit declaration' 2025-10-05 21:46:31 +02:00
nova
0b98e8eb68 removal of stray printf 2025-10-05 14:35:33 +02:00
nova
87ae2a5e8f refactoring of name shortening 2025-10-05 14:34:35 +02:00
nova
f0ad6295f7 removal of rand() in sort_rand 2025-10-05 00:57:18 +02:00
nova
e979209de3 slight likely branch improvements 2025-10-03 16:53:18 +02:00
8 changed files with 353 additions and 218 deletions

View File

@@ -48,6 +48,7 @@ static const binding key_binding[] = {
{ "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */ { "e", update, NULL, "rerun all backend" }, /* executes the entire backend and redrawing of the screen */
{ "B", enter_shell, "$SHELL", "enter $SHELL shell" }, { "B", enter_shell, "$SHELL", "enter $SHELL shell" },
{ "/", search, NULL, "search" }, { "/", search, NULL, "search" },
{ ":", jmp_file_index, NULL, "jump to file on input number" },
{ "l", search_next, NULL, "search next" }, { "l", search_next, NULL, "search next" },
{ "L", search_previous, NULL, "search previous" }, { "L", search_previous, NULL, "search previous" },
@@ -69,8 +70,11 @@ static const binding key_binding[] = {
{ "G", jump_bottom, NULL, "jump to last file in dir" }, { "G", jump_bottom, NULL, "jump to last file in dir" },
{ "gg", jump_top, NULL, "jump to first file in dir" }, { "gg", jump_top, NULL, "jump to first file in dir" },
{ "gh", jump_to_dir, "$HOME", "jump to $HOME" }, { "gh", jump_to_dir, "$HOME", "jump to $HOME" },
{ "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" }, { "gs", jump_to_dir, "$START_PATH", "jump to $START_PATH" }, /* the path you started th in */
{ "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" }, { "gD", jump_to_dir, "$HOME/Downloads", "jump to $HOME/Downloads" },
{ "gC", jump_to_dir, "$HOME/Documents", "jump to $HOME/Documents" },
{ "gP", jump_to_dir, "$HOME/Pictures", "jump to $HOME/Pictures" },
{ "gM", jump_to_dir, "$HOME/Music", "jump to $HOME/Music" },
{ "gd", jump_to_dir, "/dev", "jump to /dev" }, { "gd", jump_to_dir, "/dev", "jump to /dev" },
{ "ge", jump_to_dir, "/etc", "jump to /etc" }, { "ge", jump_to_dir, "/etc", "jump to /etc" },
{ "gp", jump_to_dir, "/etc/portage", "jump to /etc/portage" }, { "gp", jump_to_dir, "/etc/portage", "jump to /etc/portage" },
@@ -87,11 +91,10 @@ static const binding key_binding[] = {
{ "uz", cmd_on_selected, "unzip ", "unzip zip" }, { "uz", cmd_on_selected, "unzip ", "unzip zip" },
{ "on", order_by, sort_natural, "order natural" }, { "on", order_by, sort_natural, "order natural" },
{ "or", not_implemented, "", "order reverse" }, { "oe", order_by, sort_extension, "order extension" },
{ "oe", not_implemented, "", "order extension" },
{ "os", order_by, sort_size, "order size" }, { "os", order_by, sort_size, "order size" },
{ "ot", order_by, sort_type, "order type" }, { "ot", order_by, sort_type, "order type" },
{ "oz", order_by, sort_random, "order random" }, { "or", order_by, sort_random, "order random" },
{ "oa", order_by, sort_alpha, "order alphabetically" }, { "oa", order_by, sort_alpha, "order alphabetically" },
{ "mk", makedir, NULL, "create directory" }, { "mk", makedir, NULL, "create directory" },
@@ -105,7 +108,7 @@ static const char size_unit[] = { 'B', 'K', 'M', 'G', 'T', 'P' }; /* this define
static const char clipboard_cmd[] = "xsel -ib --trim"; /* assembles the following shell cmd: echo "hovered_file" | clipboard_cmd */ 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 unsigned long binding_count = sizeof(key_binding) / sizeof(binding); static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding);

View File

@@ -9,6 +9,7 @@
#define STATUS_UPDATE_SCREEN_RELOAD_FULL 32 #define STATUS_UPDATE_SCREEN_RELOAD_FULL 32
#define STATUS_USER_ROOT 64 #define STATUS_USER_ROOT 64
#define STATUS_INPUT_MATCH 128 #define STATUS_INPUT_MATCH 128
#define STATUS_DELTA_TIME 256
#define SETTINGS_HAS_COLOR 1 #define SETTINGS_HAS_COLOR 1

87
dir.c
View File

@@ -54,7 +54,7 @@ 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, unsigned long *dir_file_count, file *dir_content){
struct dirent **entry; 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 {
@@ -147,7 +147,10 @@ void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_conten
for (i = 0; i < *dir_file_count; i++) { for (i = 0; i < *dir_file_count; i++) {
free(entry[i]); free(entry[i]);
} }
free(entry); if (entry != NULL) {
free(entry);
} else {
}
} }
@@ -192,42 +195,11 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
offset_vertical = selected_file_current - (terminal_height/3)*2; offset_vertical = selected_file_current - (terminal_height/3)*2;
} }
} }
} else {
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++) {
/* shortens the printed file name if it is too long
* example input: aaaaaaaa.txt
* example output: aaa~.txt
* if no extension is found, the name will truncate */
char *file_name;
unsigned long file_name_width = strlen(dir_content[i].file_name);
if ((file_name_width + offset_front + is_selected) > line_width - 3) {
char *extension = strrchr(dir_content[i].file_name, '.');
if (extension) {
int char_offset = (file_name_width + offset_front + is_selected) - (line_width - 3) ;
if ((file_name_width - char_offset - strlen(extension) - 1) > 1) {
file_name = malloc(file_name_width - char_offset + 1);
memcpy(file_name, dir_content[i].file_name, file_name_width - char_offset);
memcpy(file_name + (file_name_width - char_offset - strlen(extension)), extension, strlen(extension));
file_name[file_name_width - char_offset - strlen(extension) - 1] = '~';
file_name[file_name_width - char_offset] = '\0';
} else {
file_name = malloc(strlen(extension)+1);
file_name[0] = '~';
memcpy(file_name+1, extension, strlen(extension));
file_name[strlen(extension)] = '\0';
}
} else {
file_name = malloc(file_name_width+1);
memcpy(file_name, dir_content[i].file_name, file_name_width);
file_name[file_name_width] = '\0';
}
} else {
file_name = malloc(file_name_width+1);
memcpy(file_name, dir_content[i].file_name, file_name_width);
file_name[file_name_width] = '\0';
}
if (print_info) { if (print_info) {
@@ -248,7 +220,8 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
} else { } else {
offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1); offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1);
} }
} else {
offset_back = line_width;
} }
if (dir_content[i].status & FILE_STATUS_SELECTED) { if (dir_content[i].status & FILE_STATUS_SELECTED) {
@@ -267,6 +240,37 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
wattroff(win, A_REVERSE); wattroff(win, A_REVERSE);
} }
/* shortens the printed file name if it is too long
* example input: aaaaaaaa.txt
* example output: aaa~.txt
* if no extension is found, the name will truncate */
char *file_name = NULL;
unsigned long printable_size = (offset_back - is_selected - offset_front);
if (strlen(dir_content[i].file_name) > printable_size) {
char *extension = strrchr(dir_content[i].file_name, '.');
if (extension && extension != dir_content[i].file_name) {
file_name = malloc(printable_size);
printable_size -= strlen(extension);
memcpy(file_name, dir_content[i].file_name, printable_size);
memcpy(file_name + printable_size-1, extension, strlen(extension));
file_name[printable_size + strlen(extension)-1] = '\0';
file_name[printable_size - 2] = '~';
} else {
file_name = malloc(printable_size-1);
memcpy(file_name, dir_content[i].file_name, printable_size);
file_name[printable_size-2] = '~';
file_name[printable_size-1] = '\0';
}
} else {
file_name = malloc(strlen(dir_content[i].file_name)+1);
memcpy(file_name, dir_content[i].file_name, strlen(dir_content[i].file_name)+1);
}
mvwaddstr(win, i-offset_vertical, 0, bg); mvwaddstr(win, i-offset_vertical, 0, bg);
if(print_info) { if(print_info) {
#if SETTINGS_LINE_NUMBERS == 2 #if SETTINGS_LINE_NUMBERS == 2
@@ -300,7 +304,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
#endif #endif
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2); mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
free(file_name);
if (dir_content[i].file_type &= FILE_TYPE_DIR) { if (dir_content[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_content[i].file_size);
@@ -311,9 +314,15 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
} }
} else { } else {
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width); mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
free(file_name);
} }
if (file_name != NULL) {
/* sometimes NULL remains, need to do deeper analysis soon */
free(file_name);
} else {
printf("file_name remains NULL on %s, if this happens consistent on the same file, please inform me", dir_content[i].file_name);
volatile static int debug_print_dir;
debug_print_dir++;
}
if (dir_content[i].status & FILE_STATUS_SELECTED) { if (dir_content[i].status & FILE_STATUS_SELECTED) {
wattroff(win, COLOR_PAIR(8)); wattroff(win, COLOR_PAIR(8));
} else { } else {

View File

@@ -1,7 +1,9 @@
#include <curses.h> #include <curses.h>
#include <pthread.h> #include <pthread.h>
#include <dirent.h> #include <dirent.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "file_previews.h" #include "file_previews.h"
#include "backend.h" #include "backend.h"
@@ -36,16 +38,15 @@ extern unsigned int status;
extern char *start_path; extern char *start_path;
extern char *input; extern char *input;
extern time_t seed; extern time_t *seed;
char search_buffer[255]; char search_buffer[255];
unsigned int timeout_time = 0; unsigned int timeout_time = 0;
unsigned int input_pass; unsigned int input_pass;
int parsed_input_number; unsigned long parsed_input_number;
yank yank_files = { 0 }; yank yank_files = { 0 };
int read_string(WINDOW *win, int y, int x, char *str); int read_string(WINDOW *win, int y, int x, char *str);
int strcmp_offset(char *in0, char *in1, char offset);
extern void render_pass(); extern void render_pass();
extern int (*order_func)(); extern int (*order_func)();
@@ -69,7 +70,7 @@ void user_interactions() {
ch = getch(); ch = getch();
if(ch != ERR) { if(ch != ERR) {
timeout(1); /* blocking timeout of getch() */ timeout(10); /* blocking timeout of getch() */
input[input_pass] = ch; input[input_pass] = ch;
mvaddstr(terminal_height-1, (terminal_width/3)*2, input); mvaddstr(terminal_height-1, (terminal_width/3)*2, input);
input_pass++; input_pass++;
@@ -82,6 +83,8 @@ void user_interactions() {
} }
binding_pass = 0; binding_pass = 0;
status |= STATUS_UPDATE_SCREEN_0; status |= STATUS_UPDATE_SCREEN_0;
} else {
timeout(100);
} }
@@ -118,7 +121,7 @@ void user_interactions() {
} }
if (status & STATUS_INPUT_MATCH) { if (status & STATUS_INPUT_MATCH) {
attron(A_UNDERLINE); attron(A_UNDERLINE);
mvaddstr(terminal_height-binding_matches-2, 0, "input\tcommand\t\t"); mvwprintw(stdscr, terminal_height-binding_matches-2, 0, "input\tcommand\t\t");
attroff(A_UNDERLINE); attroff(A_UNDERLINE);
status &= ~STATUS_INPUT_MATCH; status &= ~STATUS_INPUT_MATCH;
} else if (number_length != strlen(input)) { } else if (number_length != strlen(input)) {
@@ -166,35 +169,14 @@ int read_string(WINDOW *win, int y, int x, char *str){
} }
str[pass] = '\0'; str[pass] = '\0';
timeout(10); timeout(100);
curs_set(0); curs_set(0);
return err; return err;
} }
int strcmp_offset(char *in0, char *in1, char offset){
int i = 0;
while (in0[i] != '\0' && in1[i] != '\0') {
if (in0[i+offset] != in1[i]) {
return 1;
}
i++;
in1++;
}
return 0;
}
void quit_program(){ void quit_program(){
status = STATUS_QUIT_PROGRAM; status = STATUS_QUIT_PROGRAM;
} }
void toggle_selection(){
pthread_mutex_lock(&mutex_selection);
pthread_mutex_lock(&mutex_mid);
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
status |= (STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_mid);
pthread_mutex_unlock(&mutex_selection);
}
void select_all(){ void select_all(){
pthread_mutex_lock(&mutex_selection); pthread_mutex_lock(&mutex_selection);
pthread_mutex_lock(&mutex_mid); pthread_mutex_lock(&mutex_mid);
@@ -205,7 +187,7 @@ void select_all(){
pthread_mutex_unlock(&mutex_mid); pthread_mutex_unlock(&mutex_mid);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
} }
void move_down(int passes){ void move_down(unsigned long passes){
pthread_mutex_lock(&mutex_selection); pthread_mutex_lock(&mutex_selection);
if (passes == 0) { if (passes == 0) {
passes++; passes++;
@@ -218,7 +200,7 @@ void move_down(int passes){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
} }
void move_up(int passes){ void move_up(unsigned long passes){
pthread_mutex_lock(&mutex_selection); pthread_mutex_lock(&mutex_selection);
if (passes == 0) { if (passes == 0) {
passes++; passes++;
@@ -235,11 +217,11 @@ void move_up(int passes){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
} }
void move_left(int passes){ void move_left(unsigned long passes){
if (passes == 0) { if (passes == 0) {
passes++; passes++;
} }
int i; unsigned long i;
for (i = 0; i < passes; i++) { for (i = 0; i < passes; i++) {
if (chdir("..") != 0) { if (chdir("..") != 0) {
/* TODO(2025-07-09T00:30:05) fix */ /* TODO(2025-07-09T00:30:05) fix */
@@ -265,20 +247,22 @@ void move_right(){
char match = 0; char match = 0;
char *mime = get_mimetype(mid_content[selected_file_current].file_name); char *mime = get_mimetype(mid_content[selected_file_current].file_name);
char *extension = strrchr(mid_content[selected_file_current].file_name, '.'); char *extension = strrchr(mid_content[selected_file_current].file_name, '.');
for (i = 0; i < file_extension_default_count; i++) { if (extension != NULL) {
if (strstr(extension, file_extension_default_cmd[i].file_extension)) { for (i = 0; i < file_extension_default_count; i++) {
char *cmd = concat(file_extension_default_cmd[i].command, " ./\""); if (strstr(extension, file_extension_default_cmd[i].file_extension)) {
cmd = concat(cmd, mid_content[selected_file_current].file_name); char *cmd = concat(file_extension_default_cmd[i].command, " ./\"");
cmd = concat(cmd, "\""); cmd = concat(cmd, mid_content[selected_file_current].file_name);
cmd = concat(cmd, "\"");
if (system(cmd) == -1) { if (system(cmd) == -1) {
/*do nothing*/ /*do nothing*/
}
curs_set(1); /*for some reason, 1 here turns it invisible once again */
match = 1;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
} }
curs_set(1); /*for some reason, 1 here turns it invisible once again */
match = 1;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
} }
} }
if (match == 0) { if (match == 0) {
@@ -312,6 +296,15 @@ void toggle_hidden_files(){
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES; file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
} }
void toggle_selection(){
pthread_mutex_lock(&mutex_selection);
pthread_mutex_lock(&mutex_mid);
mid_content[selected_file_current].status ^= FILE_STATUS_SELECTED;
status |= (STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_mid);
pthread_mutex_unlock(&mutex_selection);
move_down(1);
}
void jump_bottom(){ void jump_bottom(){
pthread_mutex_lock(&mutex_selection); pthread_mutex_lock(&mutex_selection);
selected_file_current = 0 - 1; selected_file_current = 0 - 1;
@@ -385,7 +378,9 @@ void rename_hovered(){
mvwin(win_b, terminal_height-6, 0); mvwin(win_b, terminal_height-6, 0);
wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/ wresize(win_b, 5, terminal_width/3); /*the div3 just looks cool*/
pthread_mutex_unlock(&mutex_btm);
render_pass(); render_pass();
pthread_mutex_lock(&mutex_btm);
unsigned long local_height; unsigned long local_height;
local_height = getmaxy(win_b); local_height = getmaxy(win_b);
@@ -407,6 +402,7 @@ void rename_hovered(){
}; };
btm_buffer = cmd; btm_buffer = cmd;
} }
pthread_mutex_unlock(&mutex_btm);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
@@ -547,13 +543,14 @@ void makefile(){
fclose(fp); fclose(fp);
} }
free(str); free(str);
pthread_mutex_unlock(&mutex_btm);
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
} }
void update(){ void update(){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
} }
void enter_shell(int passes, int index){ void enter_shell(unsigned long passes, int index){
(void)passes; (void)passes;
#if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0 #if SETTINGS_UEBERZUG_IMAGE_PREVIEW != 0
@@ -566,14 +563,14 @@ void enter_shell(int passes, int index){
initscr(); initscr();
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
} }
void not_implemented(int passes, int index){ void not_implemented(unsigned long passes, int index){
(void)passes; (void)passes;
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");
} }
void jump_to_dir(int passes, int index){ void jump_to_dir(unsigned long passes, int index){
(void)passes; (void)passes;
char *ch = (char*)key_binding[index].black_magic; char *ch = (char*)key_binding[index].black_magic;
@@ -630,15 +627,18 @@ void jump_to_dir(int passes, int index){
} }
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY); status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
} }
void order_by(int passes, int index){ void order_by(unsigned long passes, int index){
(void)passes; (void)passes;
seed = time(NULL); free(seed);
srand(seed); 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_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
} }
void cmd_on_selected(int passes, int index){ void cmd_on_selected(unsigned long passes, int index){
(void)passes; (void)passes;
pthread_mutex_lock(&mutex_btm); pthread_mutex_lock(&mutex_btm);
@@ -726,7 +726,7 @@ void cmd_on_selected(int passes, int index){
} }
pthread_mutex_unlock(&mutex_btm); pthread_mutex_unlock(&mutex_btm);
} }
void yank_text(int passes, int index){ void yank_text(unsigned long passes, int index){
(void)passes; (void)passes;
char *cmd; char *cmd;
if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) { if (strncmp((char*)key_binding[index].black_magic, "path", 4) == 0) {
@@ -747,17 +747,18 @@ void yank_text(int passes, int index){
} }
free(cmd); free(cmd);
} }
void yank_file(int passes, int index){ void yank_file(unsigned long passes, int index){
(void)passes; (void)passes;
unsigned long i; unsigned long i;
if (yank_files.status & YANK_IS_USED) { if (yank_files.status & YANK_IS_USED) {
free(yank_files.path);
for (i = 0; i < yank_files.count; i++) { for (i = 0; i < yank_files.count; i++) {
free(yank_files.list[i]); free(yank_files.list[i]);
} }
free(yank_files.list); free(yank_files.list);
free(yank_files.path);
yank_files.count = 0; yank_files.count = 0;
yank_files.status = 0;
} }
yank_files.path=getcwd(NULL, 0); yank_files.path=getcwd(NULL, 0);
yank_files.count = 0; yank_files.count = 0;
@@ -774,7 +775,7 @@ void yank_file(int passes, int index){
strcpy(*yank_files.list, mid_content[selected_file_current].file_name); strcpy(*yank_files.list, mid_content[selected_file_current].file_name);
} else { } else {
yank_files.list = malloc(yank_files.count * sizeof(char*)); yank_files.list = malloc(yank_files.count * sizeof(char*));
for (i = 0; i < mid_file_count && i < yank_files.count; i++) { for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) { if (mid_content[i].status & FILE_STATUS_SELECTED) {
*yank_files.list = malloc(strlen(mid_content[i].file_name)+1); *yank_files.list = malloc(strlen(mid_content[i].file_name)+1);
strcpy(*yank_files.list, mid_content[i].file_name); strcpy(*yank_files.list, mid_content[i].file_name);
@@ -798,32 +799,41 @@ void paste(){
/*TODO(2025-08-14T22:10:44) escape path*/ /*TODO(2025-08-14T22:10:44) escape path*/
char *cmd; char *cmd;
if (yank_files.status & YANK_COPY) { if (yank_files.status & YANK_COPY) {
cmd = concat("false | cp -r -i ", yank_files.path); cmd = concat("false | cp -riv ", yank_files.path);
} else { } else {
cmd = concat("mv ", yank_files.path); cmd = concat("mv ", yank_files.path);
} }
cmd = concat(cmd, "/"); cmd = concat(cmd, "/");
cmd = concat(cmd, *yank_files.list); cmd = concat(cmd, *yank_files.list);
cmd = concat(cmd, " ./"); cmd = concat(cmd, " ./");
mvprintw(i, 0, cmd); cmd = concat(cmd, *yank_files.list);
if (system(cmd) != 0) { cmd = concat(cmd, " 2>&1");
cmd = concat(cmd, *yank_files.list); char *line = malloc(255);
char *line = NULL; FILE *cmd_open;
size_t size = 0; while (1) {
FILE *cmd_open; cmd_open = popen(cmd, "r");
while (1) { if (fgets(line, 255, cmd_open) == 0) {
cmd_open = popen(cmd, "r"); break;
int val = getline(&line, &size, cmd_open);
if (pclose(cmd_open) == 0) {
break;
} else if (val == 0 || val == -1) {
break;
}
cmd = concat(cmd, "_");
} }
if (strstr(line, "are the same file")) {
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
cmd = concat(cmd, "_");
cmd = concat(cmd, " 2>&1");
} else if ((strstr(line, "overwrite"))) {
cmd[strlen(cmd)-strlen(" 2>&1")] = '\0';
cmd = concat(cmd, "_");
cmd = concat(cmd, " 2>&1");
} else if ((strstr(line, "No such file or directory"))) {
pclose(cmd_open);
break;
} else if (pclose(cmd_open) == 0) {
break;
}
pclose(cmd_open);
} }
free(cmd);
yank_files.list++; yank_files.list++;
} }
yank_files.list -= yank_files.count; yank_files.list -= yank_files.count;
@@ -925,3 +935,25 @@ void search_previous(){
} }
} }
} }
void jmp_file_index(){
char *index = malloc(255);
memset(index, ' ', 255);
index[254] = '\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();
}

View File

@@ -9,9 +9,9 @@ void quit_program();
void toggle_selection(); void toggle_selection();
void select_all(); void select_all();
void move_right(); void move_right();
void move_up(int passes); void move_up(unsigned long passes);
void move_down(int passes); void move_down(unsigned long passes);
void move_left(int passes); void move_left(unsigned long passes);
void jump_bottom(); void jump_bottom();
void jump_top(); void jump_top();
void toggle_hidden_files(); void toggle_hidden_files();
@@ -21,14 +21,15 @@ void delete();
void makedir(); void makedir();
void makefile(); void makefile();
void update(); void update();
void enter_shell(int passes, int index); void enter_shell(unsigned long passes, int index);
void not_implemented(int passes, int index); void not_implemented(unsigned long passes, int index);
void jump_to_dir(int passes, int index); void jump_to_dir(unsigned long passes, int index);
void order_by(int passes, int index); void order_by(unsigned long passes, int index);
void cmd_on_selected(int passes, int index); void cmd_on_selected(unsigned long passes, int index);
void yank_text(int passes, int index); void yank_text(unsigned long passes, int index);
void yank_file(int passes, int index); void yank_file(unsigned long passes, int index);
void paste(); void paste();
void search(); void search();
void search_next(); void search_next();
void search_previous(); void search_previous();
void jmp_file_index();

13
main.c
View File

@@ -21,7 +21,7 @@ unsigned int settings;
unsigned int file_modifiers; unsigned int file_modifiers;
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);
char *start_path; char *start_path;
time_t seed; time_t *seed;
WINDOW *win_t; WINDOW *win_t;
WINDOW *win_b; WINDOW *win_b;
@@ -81,7 +81,7 @@ int main(){
temp_heigth = terminal_height; temp_heigth = terminal_height;
} }
if (threading) { if (threading) {
status &= ~(STATUS_RELOAD_DIRECTORY); status &= ~(STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
threading = 0; threading = 0;
} }
if (status & STATUS_RUN_BACKEND) { if (status & STATUS_RUN_BACKEND) {
@@ -101,8 +101,7 @@ int main(){
time(&dt); time(&dt);
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) { if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
time(&t); time(&t);
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_DELTA_TIME);
srand(seed);
} }
#endif #endif
@@ -113,6 +112,7 @@ int main(){
threading_free(); threading_free();
free(start_path); free(start_path);
/*
if (threading) { if (threading) {
pthread_join(thread_l, NULL); pthread_join(thread_l, NULL);
pthread_join(thread_r, NULL); pthread_join(thread_r, NULL);
@@ -120,6 +120,7 @@ int main(){
pthread_join(thread_t, NULL); pthread_join(thread_t, NULL);
pthread_join(thread_b, NULL); pthread_join(thread_b, NULL);
} }
*/
delwin(win_l); delwin(win_l);
delwin(win_m); delwin(win_m);
@@ -209,6 +210,8 @@ void init() {
char *start_path = getcwd(NULL, 0); char *start_path = getcwd(NULL, 0);
setenv("START_PATH", start_path, 0); setenv("START_PATH", start_path, 0);
free(start_path); free(start_path);
seed = time(NULL);
seed = malloc(sizeof(time_t));
*seed = time(NULL);
} }

101
sorting.c
View File

@@ -4,12 +4,11 @@
#include <strings.h> #include <strings.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h>
#include "defines.h" #include "defines.h"
extern time_t seed; extern time_t *seed;
extern unsigned int settings;
extern unsigned int file_modifiers;
int skip_hidden_files(const struct dirent *entry){ int skip_hidden_files(const struct dirent *entry){
@@ -43,38 +42,37 @@ int sort_natural(const void *file0, const void *file1){
char result = 0; char result = 0;
do { do {
is_num = 0;
if ((*a >= '0') && (*a <= '9')) { if ((*a <= '9') && (*a >= '0')) {
parsed_number0 = 0; parsed_number0 = 0;
while((*a >= '0') && (*a <= '9')) { do {
parsed_number0 = (parsed_number0 * 10) + (*a - '0'); parsed_number0 = (parsed_number0 * 10) + (*a - '0');
a++; a++;
} } while((*a <= '9') && (*a >= '0'));
is_num |= 1; is_num |= 1;
} }
if ((*b >= '0') && (*b <= '9')) { if ((*b <= '9') && (*b >= '0')) {
parsed_number1 = 0; parsed_number1 = 0;
while((*b >= '0') && (*b <= '9')) { do {
parsed_number1 = (parsed_number1 * 10) + (*b - '0'); parsed_number1 = (parsed_number1 * 10) + (*b - '0');
b++; b++;
} } while((*b <= '9') && (*b >= '0'));
is_num |= 2; is_num |= 2;
} }
if (is_num) { if (is_num) {
if (is_num == 1) { if (is_num == 1) {
if (*b < '0') { if (*b > '9') {
result = 1;
} else {
result = -1; result = -1;
} else {
result = 1;
} }
break; break;
} else if (is_num == 2) { } else if (is_num == 2) {
if (*a < '0') { if (*a > '9') {
result = -1;
} else {
result = 1; result = 1;
} else {
result = -1;
} }
break; break;
} else { } else {
@@ -88,6 +86,7 @@ int sort_natural(const void *file0, const void *file1){
} }
/* those breaks are not set here, due to the possibillity that both numbers are equal /* those breaks are not set here, due to the possibillity that both numbers are equal
* in which case the comparison should continue */ * in which case the comparison should continue */
is_num = 0;
} }
unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a; unsigned char aa = ((*a >= 'A') && (*a <= 'Z')) ? (*a | ' ') : *a;
@@ -119,8 +118,21 @@ 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)&seed;
time_t i;
for (i = num%2; i < 6+(((time_t)&seed)%2); i++){
num ^= *seed;
if (num%2) {
num ^= (time_t)&num;
num ^= num << (i + (((time_t)&seed)%5));
} else {
num ^= (time_t)&seed;
num ^= num >> (i + (((time_t)&num)%5));
}
}
num ^= getpid();
return ((rand()%3)-1); return ((num%3) - 1);
} }
int sort_type(const void *file0, const void *file1){ int sort_type(const void *file0, const void *file1){
@@ -132,13 +144,13 @@ int sort_type(const void *file0, const void *file1){
return 1; return 1;
} }
if (((file*)file0)->file_type == ((file*)file1)->file_type) { if (((file*)file0)->file_type > ((file*)file1)->file_type) {
/*somehow relying on the else below, occasionaly trips either one of the checked for conditions*/
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
} else if (((file*)file0)->file_type > ((file*)file1)->file_type) {
return -1; return -1;
} } else if (((file*)file0)->file_type < ((file*)file1)->file_type) {
return 1; return 1;
} else {
return sort_natural(file0, file1);
}
} }
int sort_size(const void *file0, const void *file1){ int sort_size(const void *file0, const void *file1){
@@ -149,10 +161,43 @@ int sort_size(const void *file0, const void *file1){
return 1; return 1;
} }
if (((file*)file0)->file_size == ((file*)file1)->file_size) { if (((file*)file0)->file_size > ((file*)file1)->file_size) {
return strcasecmp(((file*)file0)->file_name, ((file*)file1)->file_name);
} else if (((file*)file0)->file_size > ((file*)file1)->file_size) {
return -1; return -1;
} } else if (((file*)file0)->file_size < ((file*)file1)->file_size) {
return 1; return 1;
} else {
return sort_natural(file0, file1);
}
}
int sort_extension(const void *file0, const void *file1){
if ((((file*)file0)->file_type & FILE_TYPE_DIR) && !(((file*)file1)->file_type & FILE_TYPE_DIR)) {
return -1;
}
if (!(((file*)file0)->file_type & FILE_TYPE_DIR) && (((file*)file1)->file_type & FILE_TYPE_DIR)) {
return 1;
}
char *extension0 = strrchr(((file*)file0)->file_name, '.');
char *extension1 = strrchr(((file*)file1)->file_name, '.');
if (extension0 && extension1) {
if ((strcmp(extension0, extension1)) == 0) {
return sort_natural(file0, file1);
} else {
file f0;
file f1;
memcpy(&f0, file0, sizeof(file));
memcpy(&f1, file1, sizeof(file));
f0.file_name = extension0;
f1.file_name = extension1;
return sort_natural(&f0, &f1);
}
} else if (extension0 != NULL && extension1 == NULL) {
return 1;
} else if (extension0 == NULL && extension1 != NULL) {
return -1;
} else {
return sort_natural(file0, file1);
}
} }

View File

@@ -48,12 +48,15 @@ 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;
unsigned int btm_status;
void *thread_mid(){ void *thread_mid(){
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;
char *path; char *path;
if((path=getcwd(NULL, 0)) == NULL) { if((path=getcwd(NULL, 0)) == NULL) {
@@ -63,7 +66,7 @@ void *thread_mid(){
} else { } else {
if (status & STATUS_RELOAD_DIRECTORY) { if (local_status & STATUS_RELOAD_DIRECTORY) {
unsigned long i = 0; unsigned long i = 0;
for (i = 0; i < mid_file_count; i++) { for (i = 0; i < mid_file_count; i++) {
free(mid_content[i].file_name); free(mid_content[i].file_name);
@@ -92,6 +95,7 @@ void *thread_mid(){
pthread_mutex_unlock(&mutex_selection); pthread_mutex_unlock(&mutex_selection);
} }
btm_status = local_status;
pthread_cond_signal(&cond_rgt); pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm); pthread_cond_signal(&cond_btm);
@@ -106,6 +110,7 @@ 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;
char *path; char *path;
if((path=getcwd(NULL, 0)) == NULL) { if((path=getcwd(NULL, 0)) == NULL) {
@@ -117,7 +122,7 @@ void *thread_lft(){
path[strrchr(path, '/')-path] = '\0'; path[strrchr(path, '/')-path] = '\0';
path[0] = '/'; path[0] = '/';
if (status & STATUS_RELOAD_DIRECTORY) { if (local_status & STATUS_RELOAD_DIRECTORY) {
lft_file_count = get_dir_size(path); lft_file_count = get_dir_size(path);
free(lft_content); free(lft_content);
lft_content = malloc(lft_file_count * sizeof(file)); lft_content = malloc(lft_file_count * sizeof(file));
@@ -178,7 +183,7 @@ void *thread_rgt(){
free(rgt_buffer); free(rgt_buffer);
rgt_buffer = malloc(sizeof(char)); rgt_buffer = malloc(sizeof(char));
rgt_buffer[0] = '\0'; rgt_buffer[0] = '\0';
} else { } else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) {
unsigned long i = 0; unsigned long i = 0;
for (i = 0; i < rgt_file_count; i++) { for (i = 0; i < rgt_file_count; i++) {
@@ -231,7 +236,8 @@ void *thread_top(){
top_width = sizeof("cannot open directory"); top_width = sizeof("cannot open directory");
top_buffer = "cannot open directory"; top_buffer = "cannot open directory";
} else { } else {
top_buffer = getcwd(NULL, 0); top_buffer = malloc(strlen(path)+1);
memcpy(top_buffer, path, strlen(path)+1);
top_width = strlen(top_buffer); top_width = strlen(top_buffer);
} }
@@ -241,17 +247,104 @@ void *thread_top(){
pthread_exit(0); pthread_exit(0);
} }
void *thread_btm(){ void *thread_btm(){
char *path = NULL;
char *ui_btm_right_block = malloc(sizeof(char));
unsigned int ui_btm_right_block_size = 0;
unsigned int buffer_width = 0;
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;
free(btm_buffer); if (local_status & (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY)) {
int buffer_width = terminal_width; /*{{{ parse storage info; the fold of shame*/
btm_buffer = malloc(buffer_width); pthread_mutex_lock(&mutex_mid);
memset(btm_buffer, ' ', buffer_width); unsigned long i;
float total_dir_size = 0;
for(i = 0; i < mid_file_count; i++) {
if ((mid_content[i].file_type & (FILE_TYPE_DIR)) != FILE_TYPE_DIR) {
total_dir_size += mid_content[i].file_size;
}
}
pthread_mutex_unlock(&mutex_mid);
if (path != NULL) {
/* sometimes NULL remains, need to do deeper analysis soon */
free(path);
path = NULL;
} else {
volatile static int debug_thread_btm;
debug_thread_btm++;
}
free(ui_btm_right_block);
path = getcwd(NULL, 0);
struct statvfs fs;
statvfs(path, &fs);
float disk_size_free = fs.f_bsize * fs.f_bavail;
float parsed_number[2] = { 0 };
char size_index[2] = { 0 };
if (total_dir_size > 1) {
size_index[0] = -1;
while (total_dir_size > 1 && size_index[0] < size_unit_count) {
parsed_number[0]=total_dir_size;
size_index[0]++;
total_dir_size /= 1024;
}
} else {
size_index[0] = 0;
parsed_number[0] = 0;
}
if (disk_size_free > 1) {
size_index[1] = -1;
while (disk_size_free > 1 && size_index[1] < size_unit_count) {
parsed_number[1]=disk_size_free;
size_index[1]++;
disk_size_free /= 1024;
}
} else {
size_index[1] = 0;
}
if (size_index[0] > 0 && size_index[1] > 0) {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.2lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.2lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
} else if (size_index[0] <= 0 && size_index[1] > 0) {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.0lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.0lf%c %s %0.2lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
} else if (size_index[0] > 0 && size_index[1] <= 0) {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.2lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.2lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
} else {
ui_btm_right_block_size = snprintf(NULL, 0, "%0.0lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left)+1;
ui_btm_right_block = malloc(ui_btm_right_block_size);
sprintf(ui_btm_right_block, "%0.0lf%c %s %0.0lf%c %s", parsed_number[0], size_unit[(unsigned)size_index[0]], ui_btm_current_dir_size, parsed_number[1], size_unit[(unsigned)size_index[1]], ui_btm_text_storage_left);
}
/*}}}*/
}
if (buffer_width != terminal_width) {
buffer_width = terminal_width;
free(btm_buffer);
btm_buffer = malloc(buffer_width);
memset(btm_buffer, ' ', buffer_width/2);
}
memset(btm_buffer + (buffer_width/2), ' ', buffer_width/2);
btm_buffer[buffer_width] = '\0'; btm_buffer[buffer_width] = '\0';
memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size);
btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-'; btm_buffer[0] = (S_ISDIR(mid_content[selected_file_current].permissions)) ? 'd' : '-';
btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-'; btm_buffer[1] = (mid_content[selected_file_current].permissions & S_IRUSR) ? 'r' : '-';
btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-'; btm_buffer[2] = (mid_content[selected_file_current].permissions & S_IWUSR) ? 'w' : '-';
@@ -264,58 +357,6 @@ void *thread_btm(){
btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-'; btm_buffer[9] = (mid_content[selected_file_current].permissions & S_IXOTH) ? 'x' : '-';
char *path;
path=getcwd(NULL, 0);
struct statvfs fs;
statvfs(path, &fs);
float disk_size_free = fs.f_bsize * fs.f_bavail;
float parsed_number = 0;
int offset_back = buffer_width - strlen(ui_btm_text_storage_left);
strcpy(btm_buffer + offset_back, ui_btm_text_storage_left);
char *float_str = malloc(buffer_width / 4);
char size_index = -1;
pthread_mutex_lock(&mutex_mid);
unsigned long i;
unsigned long total_dir_size = 0;
for(i = 0; i < mid_file_count; i++) {
if (!(mid_content[i].file_type & (FILE_TYPE_DIR))) {
total_dir_size += mid_content[i].file_size;
}
}
pthread_mutex_unlock(&mutex_mid);
do {
parsed_number=disk_size_free;
disk_size_free /= 1024;
size_index++;
} while (disk_size_free > 1 && size_index < size_unit_count);
snprintf(float_str, 10, "%0.2lf", parsed_number);
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
offset_back -= strlen(float_str) + 2;
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
parsed_number = 0;
size_index = -1;
do {
parsed_number=total_dir_size;
total_dir_size /= 1024;
size_index++;
} while (total_dir_size > 1 && size_index < size_unit_count);
offset_back -= strlen(ui_btm_current_dir_size) + 5;
memcpy(btm_buffer + offset_back, ui_btm_current_dir_size, strlen(ui_btm_current_dir_size));
snprintf(float_str, 10, "%0.2lf", parsed_number);
btm_buffer[offset_back - 2] = size_unit[(unsigned)size_index];
offset_back -= strlen(float_str) + 2;
memcpy(btm_buffer + offset_back, float_str, strlen(float_str));
free(path);
pthread_mutex_unlock(&mutex_btm); pthread_mutex_unlock(&mutex_btm);
} }