diff --git a/backend.c b/backend.c index 356ba41..46f5541 100644 --- a/backend.c +++ b/backend.c @@ -6,7 +6,6 @@ extern unsigned int settings; extern unsigned long longest_name; -extern unsigned long file_count; extern char **content_l; extern char **content_m; extern char **content_r; @@ -15,7 +14,7 @@ extern char *path; void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){ DIR *dir = opendir(path); if (dir) { - unsigned long index = 0; + unsigned long index = 1; //always makes the array at least 1 big, used for metadata like the amount of files struct dirent *entry; while ( entry=readdir(dir) ) { if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files @@ -35,12 +34,12 @@ void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_ closedir(dir); } -void get_dir_content(char *path, char **dir_content){ +void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char **dir_content){ DIR *dir = opendir(path); char content[file_count][longest_name]; memset(content,0,sizeof(content)); if (dir) { - int index = 0; + int index = 1; //skip index 0 as it is used for metadata like file count struct dirent *entry; while ( entry=readdir(dir) ) { if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files @@ -56,7 +55,7 @@ void get_dir_content(char *path, char **dir_content){ } void print_dir(WINDOW *win, char **dir_content){ - for (unsigned long i = 0; i < (unsigned long)file_count; i++ ){ + for (unsigned long i = 1; i < *dir_content[0]; i++ ){ //skip index 0 as it is used for metadata like file count wprintw(win, "%s",dir_content[i]); wmove(win, i, 1); } @@ -64,30 +63,35 @@ void print_dir(WINDOW *win, char **dir_content){ void *populate_dir(void *which){ // 0=left, 1=main, 2=right char wh = (char)which; + unsigned long file_count = 0; + unsigned long longest_name = 0; if (wh) { if (wh==1) { get_dir_size(path, &file_count, &longest_name); - content_m = calloc(file_count, sizeof(*content_m)); - for (unsigned long i = 0; i