mirror of
https://gittea.dev/nova/th.git
synced 2025-12-09 09:10:10 -05:00
Compare commits
5 Commits
5287c77648
...
be9436570c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be9436570c | ||
|
|
74166f7283 | ||
|
|
9a67b35ebe | ||
|
|
1e99e9d364 | ||
|
|
dd7f5634e2 |
3
Makefile
3
Makefile
@@ -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
8
dir.c
@@ -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
3
main.c
@@ -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);
|
||||
|
||||
109
threading.c
109
threading.c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user