From 24fe4a4aa423eb01a495ed6005a36f68e9737b58 Mon Sep 17 00:00:00 2001 From: nova Date: Mon, 13 Jul 2026 18:03:00 +0200 Subject: [PATCH] removal of top_buffer --- threading.c | 52 ++++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/threading.c b/threading.c index 0d22f9e..b4a7bef 100644 --- a/threading.c +++ b/threading.c @@ -31,7 +31,6 @@ dir mid_dir; dir lft_dir; char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */ char *btm_buffer; -char *top_buffer; /* current path */ extern WINDOW *win_t; extern WINDOW *win_b; @@ -289,34 +288,20 @@ void *thread_top(){ pthread_cond_wait(&cond_top, &mutex_top); - free(top_buffer); - - if(global_path == NULL) { - top_buffer = malloc(sizeof("cannot open directory")); - top_width = sizeof("cannot open directory"); - top_buffer = "cannot open directory"; - pthread_mutex_unlock(&mutex_top); - continue; - } - pthread_mutex_lock(&mutex_mid); - - if (mid_dir.current_file != NULL) { - top_buffer = malloc(strlen(global_path)+1 + strlen(mid_dir.current_file->file_name)+1); - memcpy(top_buffer, global_path, strlen(global_path)); - if (strlen(global_path) != 1) { - memcpy(top_buffer + strlen(global_path) + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1); - top_buffer[strlen(global_path)] = '/'; - } else { /* dir '/' */ - memcpy(top_buffer + 1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1); - } - - top_width = strlen(top_buffer); - } else { - top_buffer = malloc(strlen(global_path)+1); - memcpy(top_buffer, global_path, strlen(global_path)+1); + if(global_path == NULL) { + mvwaddstr(win_t, 0, 0, "cannot open directory"); + pthread_mutex_unlock(&mutex_top); + pthread_mutex_unlock(&mutex_mid); + continue; + } else if (mid_dir.current_file == NULL) { + mvwaddstr(win_t, 0, 0, "cannot open file"); + pthread_mutex_unlock(&mutex_top); + pthread_mutex_unlock(&mutex_mid); + continue; } - pthread_mutex_unlock(&mutex_mid); + + /* rendering */ @@ -324,20 +309,21 @@ void *thread_top(){ werase(win_t); if (strlen(global_path) != 1) { wattron(win_t, COLOR_PAIR(COLOR_PATH)); - mvwaddnstr(win_t, 0, 0, top_buffer, strlen(global_path)+1); + mvwaddnstr(win_t, 0, 0, global_path, strlen(global_path)+1); + mvwaddch(win_t, 0, strlen(global_path), '/'); wattroff(win_t, COLOR_PAIR(COLOR_PATH)); - mvwaddstr(win_t, 0, strlen(global_path)+1, top_buffer+strlen(global_path)+1); + mvwaddstr(win_t, 0, strlen(global_path)+1, mid_dir.current_file->file_name); } else { /* dir '/' */ wattron(win_t, COLOR_PAIR(COLOR_PATH)); - mvwaddnstr(win_t, 0, 0, top_buffer, 1); + mvwaddnstr(win_t, 0, 0, global_path, 1); wattroff(win_t, COLOR_PAIR(COLOR_PATH)); - mvwaddstr(win_t, 0, 1, top_buffer+1); + mvwaddstr(win_t, 0, 1, mid_dir.current_file->file_name); } /*wnoutrefresh(win_t);*/ wrefresh(win_t); pthread_mutex_unlock(&mutex_render); - + pthread_mutex_unlock(&mutex_mid); pthread_mutex_unlock(&mutex_top); } pthread_exit(0); @@ -476,7 +462,6 @@ void *thread_btm(){ void threading_init(){ - top_buffer = NULL; rgt_buffer = NULL; btm_buffer = NULL; @@ -494,7 +479,6 @@ void threading_init(){ } void threading_free(){ - free(top_buffer); pthread_mutex_destroy(&mutex_top); pthread_mutex_destroy(&mutex_mid);