1
0
mirror of https://gittea.dev/nova/th.git synced 2025-12-09 09:10:10 -05:00

Compare commits

...

5 Commits

Author SHA1 Message Date
nova
be9436570c removal of unnecessary null check, during testing it was never null 2025-11-15 22:31:19 +01:00
nova
74166f7283 indentation change, now using continue 2025-11-15 22:28:08 +01:00
nova
9a67b35ebe handling of '/' in thread_lft 2025-11-15 22:21:30 +01:00
nova
1e99e9d364 global_path handling 2025-11-15 22:08:20 +01:00
nova
dd7f5634e2 very simplistic 'handling' of split/non split ncurses 2025-11-15 22:01:33 +01:00
4 changed files with 59 additions and 64 deletions

View File

@@ -1,7 +1,6 @@
CC := gcc
CFLAGS := -Wall -Wextra -O2 -flto=auto
CURSES := -lncursesw -ltinfow #utf8 support
#CURSES := -lncurses -tinfo #no utf8
CURSES := $(shell pkg-config --libs ncurses)
CFLAGS_DEBUG := $(CFLAGS) -g
CFLAGS_PROFILE := $(CFLAGS) -pg
GDB := gdb --tui ./th

8
dir.c
View File

@@ -315,14 +315,6 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
} else {
mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width);
}
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) {
wattroff(win, COLOR_PAIR(8));
} else {

3
main.c
View File

@@ -22,6 +22,7 @@ unsigned int settings;
unsigned int file_modifiers;
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
char *start_path;
char *global_path;
time_t *seed;
WINDOW *win_t;
@@ -91,6 +92,7 @@ int main(){
temp_heigth = terminal_height;
}
if (status & STATUS_RUN_BACKEND) {
global_path = getcwd(NULL, 0);
pthread_cond_signal(&cond_top);
pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft);
@@ -198,6 +200,7 @@ void init() {
#endif
ESCDELAY = 10;
global_path = getcwd(NULL, 0);
char *start_path = getcwd(NULL, 0);
setenv("START_PATH", start_path, 0);
free(start_path);

View File

@@ -47,6 +47,7 @@ volatile unsigned long selected_file_current = 0;
volatile unsigned long selected_file_last = 0;
extern unsigned int terminal_width;
extern unsigned int status;
extern char *global_path;
unsigned int btm_status;
@@ -58,48 +59,49 @@ void *thread_mid(){
pthread_cond_wait(&cond_mid, &mutex_mid);
unsigned int local_status = status;
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
if (global_path == NULL) {
mid_content = malloc(sizeof(file));
mid_content->file_name = "cannot open directory";
mid_file_count = 1;
} else {
pthread_mutex_unlock(&mutex_mid);
continue;
}
char *path = malloc(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;
}
pthread_mutex_lock(&mutex_selection);
update_selected_file();
pthread_mutex_unlock(&mutex_selection);
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';
btm_status = local_status;
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm);
mid_file_count = 0;
}
pthread_mutex_lock(&mutex_selection);
update_selected_file();
pthread_mutex_unlock(&mutex_selection);
}
btm_status = local_status;
pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm);
free(path);
pthread_mutex_unlock(&mutex_mid);
}
@@ -112,13 +114,18 @@ void *thread_lft(){
pthread_cond_wait(&cond_lft, &mutex_lft);
unsigned int local_status = status;
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
if (global_path == NULL) {
lft_content = malloc(sizeof(file));
lft_content[0].file_name = "cannot open directory";
lft_file_count = 1;
} else {
pthread_mutex_unlock(&mutex_lft);
continue;
}
char *path = malloc(strlen(global_path)+1);
memcpy(path, global_path, strlen(global_path)+1);
if (strcmp(path, "/") != 0) {
path[strrchr(path, '/')-path+1] = '\0';
path[strrchr(path, '/')-path] = '\0';
path[0] = '/';
@@ -129,8 +136,11 @@ void *thread_lft(){
memset(lft_content, '\0', lft_file_count * sizeof(file));
get_dir_content(path, &lft_file_count, lft_content);
}
} else {
lft_file_count = 0;
}
free(path);
pthread_mutex_unlock(&mutex_lft);
}
@@ -230,18 +240,17 @@ void *thread_top(){
free(top_buffer);
char *path;
if((path=getcwd(NULL, 0)) == NULL) {
if(global_path == NULL) {
top_buffer = malloc(sizeof("cannot open directory"));
top_width = sizeof("cannot open directory");
top_buffer = "cannot open directory";
} else {
top_buffer = malloc(strlen(path)+1);
memcpy(top_buffer, path, strlen(path)+1);
top_width = strlen(top_buffer);
}
pthread_mutex_unlock(&mutex_top);
continue;
}
top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, global_path, strlen(global_path)+1);
top_width = strlen(top_buffer);
free(path);
pthread_mutex_unlock(&mutex_top);
}
pthread_exit(0);
@@ -271,14 +280,6 @@ void *thread_btm(){
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);