From 2af21a0875c587360fbe65c5f64d9bf01c27cf63 Mon Sep 17 00:00:00 2001 From: nova Date: Sun, 17 Aug 2025 00:54:13 +0200 Subject: [PATCH] created dir.c & .h, improved header file handling --- backend.c | 269 ------------------------------------------- backend.h | 7 +- config.h | 13 ++- defines.h | 2 - dir.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++ dir.h | 8 ++ file_previews.c | 2 +- file_previews.h | 1 - interactions.c | 13 +-- interactions.h | 4 +- main.c | 10 +- sorting.c | 1 - threading.c | 6 +- window.c | 2 + 14 files changed, 337 insertions(+), 297 deletions(-) create mode 100644 dir.c create mode 100644 dir.h diff --git a/backend.c b/backend.c index 970cc3b..277543a 100644 --- a/backend.c +++ b/backend.c @@ -1,23 +1,3 @@ -#define _POSIX_C_SOURCE 200809L -#include -#include -#include -#include -#include -#include -#include -#include "defines.h" -#include "sorting.h" - -extern unsigned int settings; -extern unsigned int file_modifiers; -extern unsigned int color_count; -extern unsigned int terminal_height; -extern volatile unsigned long selected_file_current; -extern color *colors; -int (*order_func)() = sort_natural; - - char* concat(const char *s1, const char *s2){ const size_t len1 = strlen(s1); const size_t len2 = strlen(s2); @@ -28,252 +8,3 @@ char* concat(const char *s1, const char *s2){ } -unsigned long get_dir_size(char *path){ - DIR *dir = opendir(path); - unsigned long entry_count = 0; - if (dir) { - struct dirent *entry; - while ((entry=readdir(dir))) { - if (entry->d_name[0] != '.' || (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) { - entry_count++; - } - } - } - closedir(dir); - if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { - /* removes files "." and ".." */ - entry_count -= 2; - } - return entry_count; - -} - -void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){ - struct dirent **entry; - if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */ - scandir(path, &entry, skip_dot, alphasort); - } else { - scandir(path, &entry, skip_hidden_files, alphasort); - } - - unsigned long i = 0; - for (i = 0; i < *dir_file_count; i++ ) { - if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) { - } else { - dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1); - strcpy(dir_content[i].file_name, entry[i]->d_name); - dir_content[i].file_name[strlen(entry[i]->d_name)] = '\0'; - - - struct stat *file; - file = malloc(sizeof(struct stat)); - memset(file, ' ', sizeof(struct stat)); - - /* using the full path allows using the same function for all windows */ - unsigned long path_len = strlen(path); - char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/")); - memcpy(full_path, path, strlen(path)); - memcpy(full_path + path_len, "/", sizeof("/")); - memcpy(full_path + path_len + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1); - - lstat(full_path, file); - - dir_content[i].file_size = file->st_size; - dir_content[i].permissions = 1; - dir_content[i].permissions = file->st_mode; - - if (S_ISDIR(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_DIR; - dir_content[i].color_pair = COLOR_DIR; - dir_content[i].file_size = get_dir_size(full_path); - } else if (S_ISLNK(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_SYMLINK; - dir_content[i].color_pair = COLOR_SYMLINK; - dir_content[i].file_size = get_dir_size(full_path); - } else if (file->st_mode & S_IXUSR) { - dir_content[i].file_type = FILE_TYPE_EXEC; - dir_content[i].color_pair = COLOR_EXEC; - } else if (S_ISBLK(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_BLOCK; - dir_content[i].color_pair = COLOR_BLOCK; - } else if (S_ISCHR(file->st_mode)) { - dir_content[i].file_type = COLOR_CHARDEV; - } else if (S_ISFIFO(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_FIFO; - dir_content[i].color_pair = COLOR_FIFO; - } else if (S_ISSOCK(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_SOCK; - dir_content[i].color_pair = COLOR_SOCK; - } else if (S_ISREG(file->st_mode)) { - dir_content[i].file_type = FILE_TYPE_REGULAR; - dir_content[i].color_pair = COLOR_REGULAR; - unsigned long j = 0; - char *extension = strrchr(entry[i]->d_name, '.'); - if (extension) { - for (j = 0; j < color_count; j++) { - if (!strcmp(colors[j].file_extension, extension)) { - dir_content[i].color_pair = colors[j].color_pair; - } - } - } else { - } - } else { - dir_content[i].file_type = COLOR_REGULAR; - dir_content[i].color_pair = COLOR_REGULAR; - unsigned long j = 0; - char *extension = strrchr(entry[i]->d_name, '.'); - if (extension) { - for (j = 0; j < color_count; j++) { - if (!strcmp(colors[j].file_extension, extension)) { - dir_content[i].color_pair = colors[j].color_pair; - } - } - } else { - } - } - free(full_path); - free(file); - } - } - - qsort(dir_content, *dir_file_count, sizeof(file), order_func); - - for (i = 0; i < *dir_file_count; i++) { - free(entry[i]); - } - free(entry); - -} - -void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content){ - /* i am not proud of this function */ - unsigned long line_width = getmaxx(win); - - char *bg = malloc(line_width+1); - memset(bg, ' ', line_width); - bg[line_width] = '\0'; - - unsigned long i = 0; - float file_size; - float printed_size = 0; - char size_char = ' '; - char is_selected = 0; - static const char sizes[6] = { 'B', 'K', 'M', 'G', 'T', 'P' }; - - unsigned long offset_vertical = 0; - unsigned long offset_back = 0; - unsigned long offset_front = 2; - if (print_info) { - if (*dir_file_count > 9) { - offset_front = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1; - } - if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) { - if (selected_file_current + (terminal_height/3) >= *dir_file_count) { - offset_vertical = *dir_file_count - terminal_height+2; - } else { - offset_vertical = selected_file_current - (terminal_height/3)*2; - } - } - } - for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) { - if (print_info) { - file_size = dir_content[i].file_size; - char size_index = 0; - while (file_size > 1) { - printed_size=file_size; - file_size /= 1024; - size_index++; - if (size_index >= 6) { - break; - } - } - size_char = sizes[size_index-1]; - if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) { - offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1); - } else if (size_char =='B') { - offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1); - } else { - offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1); - } - } - - if (dir_content[i].status & FILE_STATUS_SELECTED) { - is_selected = 1; - } else { - is_selected = 0; - } - - if (dir_content[i].status & FILE_STATUS_SELECTED) { - wattron(win, COLOR_PAIR(8)); - } else { - wattron(win, COLOR_PAIR(dir_content[i].color_pair)); - } - if (dir_content[i].status & FILE_STATUS_HOVER) { - wattron(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; - unsigned long file_name_width = strlen(dir_content[i].file_name); - if ((file_name_width + offset_front + is_selected) > offset_back - 1) { - char *extension = strrchr(dir_content[i].file_name, '.'); - if (extension) { - int char_offset = (file_name_width + offset_front + is_selected) - (offset_back - 1) ; - 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'; - } - - mvwaddstr(win, i-offset_vertical, 0, bg); - if(print_info) { - mvwprintw(win, i-offset_vertical, 0, "%ld", i); - 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 || dir_content[i].file_type == FILE_TYPE_SYMLINK) { - mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size); - }else if (size_char =='B') { - mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char); - } else { - mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char); - } - } else { - mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width); - free(file_name); - } - - if (dir_content[i].status & FILE_STATUS_HOVER) { - wattroff(win, A_REVERSE); - } - if (dir_content[i].status & FILE_STATUS_SELECTED) { - wattroff(win, COLOR_PAIR(8)); - } else { - wattroff(win, COLOR_PAIR(dir_content[i].color_pair)); - } - - } - free(bg); -} - diff --git a/backend.h b/backend.h index b0bc9cf..3435102 100644 --- a/backend.h +++ b/backend.h @@ -1,7 +1,8 @@ #include +#ifndef BACKEND_GUARD +#define BACKEND_GUARD #include "backend.c" +#endif -unsigned long get_dir_size(char *path); -void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content); -void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content); +char* concat(const char *s1, const char *s2); diff --git a/config.h b/config.h index d423181..c7b84c6 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,10 @@ +#ifndef CONFIG_GUARD +#define CONFIG_GUARD #include "defines.h" -#include "interactions.h" #include "sorting.h" +#include "interactions.h" +#define SETTINGS_LINE_NUMBERS 2 /* 0 is disabled, 1 is enabled, 2 is relative */ static const mimetype mimetype_default_cmd[] = { /* mimetype shell command @@ -90,4 +93,12 @@ static const binding key_binding[] = { static const unsigned long binding_count = sizeof(key_binding) / sizeof(binding); static const unsigned long mimetype_default_count = sizeof(mimetype_default_cmd) / sizeof(mimetype); static const unsigned long file_extension_default_count = sizeof(file_extension_default_cmd) / sizeof(extension); +#else +static const mimetype mimetype_default_cmd[]; +static const extension file_extension_default_cmd[]; +static const binding key_binding[]; +static const unsigned long binding_count; +static const unsigned long mimetype_default_count; +static const unsigned long file_extension_default_count; +#endif diff --git a/defines.h b/defines.h index cbc46d3..3b9b8c2 100644 --- a/defines.h +++ b/defines.h @@ -91,6 +91,4 @@ typedef struct Yank { char **list; unsigned long count; } yank; - - #endif diff --git a/dir.c b/dir.c new file mode 100644 index 0000000..907de10 --- /dev/null +++ b/dir.c @@ -0,0 +1,296 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "sorting.h" +#include "defines.h" +#include "config.h" + + +extern unsigned int settings; +extern unsigned int file_modifiers; +extern unsigned int color_count; +extern unsigned int terminal_height; +extern volatile unsigned long selected_file_current; +extern color *colors; +int (*order_func)() = sort_natural; + +unsigned long get_dir_size(char *path); +void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content); +void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content); + + + +unsigned long get_dir_size(char *path){ + DIR *dir = opendir(path); + unsigned long entry_count = 0; + if (dir) { + struct dirent *entry; + while ((entry=readdir(dir))) { + if (entry->d_name[0] != '.' || (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) { + entry_count++; + } + } + } + closedir(dir); + if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { + /* removes files "." and ".." */ + entry_count -= 2; + } + return entry_count; + +} + +void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){ + struct dirent **entry; + if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */ + scandir(path, &entry, skip_dot, alphasort); + } else { + scandir(path, &entry, skip_hidden_files, alphasort); + } + + unsigned long i = 0; + for (i = 0; i < *dir_file_count; i++ ) { + if (entry[i]->d_name[0] == '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) { + } else { + dir_content[i].file_name = malloc(strlen(entry[i]->d_name)+1); + strcpy(dir_content[i].file_name, entry[i]->d_name); + dir_content[i].file_name[strlen(entry[i]->d_name)] = '\0'; + + + struct stat *file; + file = malloc(sizeof(struct stat)); + memset(file, ' ', sizeof(struct stat)); + + /* using the full path allows using the same function for all windows */ + unsigned long path_len = strlen(path); + char *full_path = malloc(strlen(path) + strlen(entry[i]->d_name) + 1 + sizeof("/")); + memcpy(full_path, path, strlen(path)); + memcpy(full_path + path_len, "/", sizeof("/")); + memcpy(full_path + path_len + sizeof("/") - 1, entry[i]->d_name, strlen(entry[i]->d_name) + 1); + + lstat(full_path, file); + + dir_content[i].file_size = file->st_size; + dir_content[i].permissions = 1; + dir_content[i].permissions = file->st_mode; + + if (S_ISDIR(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_DIR; + dir_content[i].color_pair = COLOR_DIR; + dir_content[i].file_size = get_dir_size(full_path); + } else if (S_ISLNK(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_SYMLINK; + dir_content[i].color_pair = COLOR_SYMLINK; + dir_content[i].file_size = get_dir_size(full_path); + } else if (file->st_mode & S_IXUSR) { + dir_content[i].file_type = FILE_TYPE_EXEC; + dir_content[i].color_pair = COLOR_EXEC; + } else if (S_ISBLK(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_BLOCK; + dir_content[i].color_pair = COLOR_BLOCK; + } else if (S_ISCHR(file->st_mode)) { + dir_content[i].file_type = COLOR_CHARDEV; + } else if (S_ISFIFO(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_FIFO; + dir_content[i].color_pair = COLOR_FIFO; + } else if (S_ISSOCK(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_SOCK; + dir_content[i].color_pair = COLOR_SOCK; + } else if (S_ISREG(file->st_mode)) { + dir_content[i].file_type = FILE_TYPE_REGULAR; + dir_content[i].color_pair = COLOR_REGULAR; + unsigned long j = 0; + char *extension = strrchr(entry[i]->d_name, '.'); + if (extension) { + for (j = 0; j < color_count; j++) { + if (!strcmp(colors[j].file_extension, extension)) { + dir_content[i].color_pair = colors[j].color_pair; + } + } + } else { + } + } else { + dir_content[i].file_type = COLOR_REGULAR; + dir_content[i].color_pair = COLOR_REGULAR; + unsigned long j = 0; + char *extension = strrchr(entry[i]->d_name, '.'); + if (extension) { + for (j = 0; j < color_count; j++) { + if (!strcmp(colors[j].file_extension, extension)) { + dir_content[i].color_pair = colors[j].color_pair; + } + } + } else { + } + } + free(full_path); + free(file); + } + } + + qsort(dir_content, *dir_file_count, sizeof(file), order_func); + + for (i = 0; i < *dir_file_count; i++) { + free(entry[i]); + } + free(entry); + +} + +void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content){ + /* i am not proud of this function */ + unsigned long line_width = getmaxx(win); + + char *bg = malloc(line_width+1); + memset(bg, ' ', line_width); + bg[line_width] = '\0'; + + unsigned long i = 0; + float file_size; + float printed_size = 0; + char size_char = ' '; + char is_selected = 0; + static const char sizes[6] = { 'B', 'K', 'M', 'G', 'T', 'P' }; + + unsigned long offset_vertical = 0; + unsigned long offset_back = 0; + unsigned long offset_front = 2; + unsigned long offset_index = 2; /* only used for the index of the file itself */ + if (print_info) { + if (*dir_file_count > 9) { + + unsigned long dir_file_count_ = *dir_file_count; + while(dir_file_count_ > 9) { + offset_front++; + dir_file_count_ /= 10; + } + } + if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) { + if (selected_file_current + (terminal_height/3) >= *dir_file_count) { + offset_vertical = *dir_file_count - terminal_height+2; + } else { + offset_vertical = selected_file_current - (terminal_height/3)*2; + } + } + } + for (i = offset_vertical; i < *dir_file_count && i < (terminal_height + offset_vertical); i++) { + + if (print_info) { + file_size = dir_content[i].file_size; + char size_index = 0; + while (file_size > 1) { + printed_size=file_size; + file_size /= 1024; + size_index++; + if (size_index >= 6) { + break; + } + } + size_char = sizes[size_index-1]; + if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) { + offset_back = line_width - (snprintf(NULL,0,"%ld", dir_content[i].file_size) + 1); + } else if (size_char =='B') { + offset_back = line_width - (snprintf(NULL,0,"%0.0lf %c", printed_size, size_char) + 1); + } else { + offset_back = line_width - (snprintf(NULL,0,"%0.2lf %c", printed_size, size_char) + 1); + } + + } + + if (dir_content[i].status & FILE_STATUS_SELECTED) { + is_selected = 1; + } else { + is_selected = 0; + } + + if (dir_content[i].status & FILE_STATUS_SELECTED) { + wattron(win, COLOR_PAIR(8)); + } else { + wattron(win, COLOR_PAIR(dir_content[i].color_pair)); + } + if (dir_content[i].status & FILE_STATUS_HOVER) { + wattron(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; + unsigned long file_name_width = strlen(dir_content[i].file_name); + if ((file_name_width + offset_front + is_selected) > offset_back - 1) { + char *extension = strrchr(dir_content[i].file_name, '.'); + if (extension) { + int char_offset = (file_name_width + offset_front + is_selected) - (offset_back - 1) ; + 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'; + } + + mvwaddstr(win, i-offset_vertical, 0, bg); + if(print_info) { + unsigned long i_ = i; + offset_index = 2; + while(i_ > 9) { + offset_index++; + i_ /= 10; + } + #if SETTINGS_LINE_NUMBERS == 2 + mvwprintw(win, i-offset_vertical, offset_front-offset_index, "a"); + #elif SETTINGS_LINE_NUMBERS == 1 + mvwprintw(win, i-offset_vertical, offset_front-offset_index, "%ld", i); + #endif + + + 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 || dir_content[i].file_type == FILE_TYPE_SYMLINK) { + mvwprintw(win, i-offset_vertical, offset_back, "%ld", dir_content[i].file_size); + }else if (size_char =='B') { + mvwprintw(win, i-offset_vertical, offset_back, "%0.0lf %c", printed_size, size_char); + } else { + mvwprintw(win, i-offset_vertical, offset_back, "%0.2lf %c", printed_size, size_char); + } + } else { + mvwaddnstr(win, i-offset_vertical, 0, file_name, line_width); + free(file_name); + } + + if (dir_content[i].status & FILE_STATUS_HOVER) { + wattroff(win, A_REVERSE); + } + if (dir_content[i].status & FILE_STATUS_SELECTED) { + wattroff(win, COLOR_PAIR(8)); + } else { + wattroff(win, COLOR_PAIR(dir_content[i].color_pair)); + } + + } + free(bg); +} + diff --git a/dir.h b/dir.h new file mode 100644 index 0000000..00ac44b --- /dev/null +++ b/dir.h @@ -0,0 +1,8 @@ +#ifndef DIR_GUARD +#define DIR_GUARD +#include "dir.c" +#endif + +extern unsigned long get_dir_size(char *path); +extern void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content); +extern void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content); diff --git a/file_previews.c b/file_previews.c index 5207277..5f007d7 100644 --- a/file_previews.c +++ b/file_previews.c @@ -1,7 +1,7 @@ #include #include #include -#include "defines.h" +#include "backend.h" static FILE *ueberzug = NULL; extern unsigned int terminal_height; diff --git a/file_previews.h b/file_previews.h index 5107621..2e153ff 100644 --- a/file_previews.h +++ b/file_previews.h @@ -1,4 +1,3 @@ -#include "defines.h" #ifndef PREVIEW_GUARD #define PREVIEW_GUARD #include "file_previews.c" diff --git a/interactions.c b/interactions.c index b2cda07..5e85e41 100644 --- a/interactions.c +++ b/interactions.c @@ -1,15 +1,11 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include + +#include "file_previews.h" +#include "backend.h" #include "defines.h" -#include "config.h" +#include "config.h" extern volatile unsigned long selected_file_current; @@ -55,7 +51,6 @@ void FAIL(char *function, char *str){ curs_set(1); echo(); printf("ERROR in function %s: %s", function, str); - kill(getpid(),9); } void user_interactions() { diff --git a/interactions.h b/interactions.h index 1e976f5..bec8ca9 100644 --- a/interactions.h +++ b/interactions.h @@ -1,5 +1,3 @@ -#include -#include #ifndef INTERACTIONS_GUARD #define INTERACTIONS_GUARD #include "interactions.c" @@ -27,5 +25,5 @@ void not_implemented(int passes, int index); void jump_to_dir(int passes, int index); void order_by(int passes, int index); void cmd_on_selected(int passes, int index); -void yank_file(); +void yank_file(int passes, int index); void paste(); diff --git a/main.c b/main.c index a74eb3c..5aee2df 100644 --- a/main.c +++ b/main.c @@ -2,15 +2,15 @@ #include #include #include -#include -#include +#include #include -#include "threading.h" -#include "window.h" + #include "defines.h" +#include "threading.h" +#include "window.c" #include "colors.h" #include "interactions.h" -#include "file_previews.h" + unsigned int terminal_height; unsigned int terminal_width; diff --git a/sorting.c b/sorting.c index 0164edd..f331483 100644 --- a/sorting.c +++ b/sorting.c @@ -3,7 +3,6 @@ #include #include #include -#include "defines.h" extern unsigned int settings; extern unsigned int file_modifiers; diff --git a/threading.c b/threading.c index 9a9d9a7..0a8a377 100644 --- a/threading.c +++ b/threading.c @@ -5,11 +5,13 @@ #include #include #include -#include "defines.h" -#include "backend.h" +#include + +#include "dir.h" #include "file_previews.h" + pthread_mutex_t mutex_top; pthread_mutex_t mutex_btm; pthread_mutex_t mutex_lft; diff --git a/window.c b/window.c index 91de382..4eef69a 100644 --- a/window.c +++ b/window.c @@ -1,7 +1,9 @@ #include #include #include + #include "defines.h" +#include "dir.h" extern unsigned int status; extern char *input;