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

global_path handling

This commit is contained in:
nova
2025-11-15 22:08:20 +01:00
parent dd7f5634e2
commit 1e99e9d364
2 changed files with 15 additions and 19 deletions

3
main.c
View File

@@ -22,6 +22,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;
char *global_path;
time_t *seed; time_t *seed;
WINDOW *win_t; WINDOW *win_t;
@@ -91,6 +92,7 @@ int main(){
temp_heigth = terminal_height; temp_heigth = terminal_height;
} }
if (status & STATUS_RUN_BACKEND) { if (status & STATUS_RUN_BACKEND) {
global_path = getcwd(NULL, 0);
pthread_cond_signal(&cond_top); pthread_cond_signal(&cond_top);
pthread_cond_signal(&cond_mid); pthread_cond_signal(&cond_mid);
pthread_cond_signal(&cond_lft); pthread_cond_signal(&cond_lft);
@@ -198,6 +200,7 @@ void init() {
#endif #endif
ESCDELAY = 10; ESCDELAY = 10;
global_path = getcwd(NULL, 0);
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);

View File

@@ -47,6 +47,7 @@ volatile unsigned long selected_file_current = 0;
volatile unsigned long selected_file_last = 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;
unsigned int btm_status; unsigned int btm_status;
@@ -58,13 +59,14 @@ void *thread_mid(){
pthread_cond_wait(&cond_mid, &mutex_mid); pthread_cond_wait(&cond_mid, &mutex_mid);
unsigned int local_status = status; unsigned int local_status = status;
char *path; if (global_path == NULL) {
if((path=getcwd(NULL, 0)) == NULL) {
mid_content = malloc(sizeof(file)); mid_content = malloc(sizeof(file));
mid_content->file_name = "cannot open directory"; mid_content->file_name = "cannot open directory";
mid_file_count = 1; mid_file_count = 1;
} else { } else {
char *path = malloc(strlen(global_path)+1);
memcpy(path, global_path, strlen(global_path)+1);
if (local_status & STATUS_RELOAD_DIRECTORY) { if (local_status & STATUS_RELOAD_DIRECTORY) {
unsigned long i = 0; unsigned long i = 0;
@@ -99,8 +101,8 @@ void *thread_mid(){
pthread_cond_signal(&cond_rgt); pthread_cond_signal(&cond_rgt);
pthread_cond_signal(&cond_btm); pthread_cond_signal(&cond_btm);
free(path);
} }
free(path);
pthread_mutex_unlock(&mutex_mid); pthread_mutex_unlock(&mutex_mid);
} }
pthread_exit(0); pthread_exit(0);
@@ -112,12 +114,13 @@ void *thread_lft(){
pthread_cond_wait(&cond_lft, &mutex_lft); pthread_cond_wait(&cond_lft, &mutex_lft);
unsigned int local_status = status; unsigned int local_status = status;
char *path; if (global_path == NULL) {
if((path=getcwd(NULL, 0)) == NULL) {
lft_content = malloc(sizeof(file)); lft_content = malloc(sizeof(file));
lft_content[0].file_name = "cannot open directory"; lft_content[0].file_name = "cannot open directory";
lft_file_count = 1; lft_file_count = 1;
} else { } else {
char *path = malloc(strlen(global_path)+1);
memcpy(path, global_path, strlen(global_path)+1);
path[strrchr(path, '/')-path] = '\0'; path[strrchr(path, '/')-path] = '\0';
path[0] = '/'; path[0] = '/';
@@ -130,8 +133,8 @@ void *thread_lft(){
get_dir_content(path, &lft_file_count, lft_content); get_dir_content(path, &lft_file_count, lft_content);
} }
free(path);
} }
free(path);
pthread_mutex_unlock(&mutex_lft); pthread_mutex_unlock(&mutex_lft);
} }
pthread_exit(0); pthread_exit(0);
@@ -230,18 +233,16 @@ void *thread_top(){
free(top_buffer); free(top_buffer);
char *path; if(global_path == NULL) {
if((path=getcwd(NULL, 0)) == NULL) {
top_buffer = malloc(sizeof("cannot open directory")); top_buffer = malloc(sizeof("cannot open directory"));
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 = malloc(strlen(path)+1); top_buffer = malloc(strlen(global_path)+1);
memcpy(top_buffer, path, strlen(path)+1); memcpy(top_buffer, global_path, strlen(global_path)+1);
top_width = strlen(top_buffer); top_width = strlen(top_buffer);
} }
free(path);
pthread_mutex_unlock(&mutex_top); pthread_mutex_unlock(&mutex_top);
} }
pthread_exit(0); pthread_exit(0);
@@ -271,14 +272,6 @@ void *thread_btm(){
pthread_mutex_unlock(&mutex_mid); 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); free(ui_btm_right_block);
path = getcwd(NULL, 0); path = getcwd(NULL, 0);