#include #include #include #include #include #include "defines.h" extern unsigned int settings; extern char **content_l; extern char **content_m; extern char **content_r; extern char *path; void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){ DIR *dir = opendir(path); *longest_name = 256; //magic number originates out of readdir(), unless i implement my own name size function, thisll do unsigned long index = 1; //always makes the array at least 1 big, used for metadata like the amount of files if (dir) { struct dirent *entry; while ( (entry=readdir(dir)) ) { if (entry->d_name[0] != '.' && !(settings & SETTINGS_HIDDEN_FILES)) { index++; } else if (settings & SETTINGS_HIDDEN_FILES){ index++; } } } *file_count = index; closedir(dir); } 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 = 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 & SETTINGS_HIDDEN_FILES)) { strcpy(dir_content[index], entry->d_name); index++; } else if (settings & SETTINGS_HIDDEN_FILES) { strcpy(dir_content[index], entry->d_name); index++; } } } closedir(dir); } void print_dir(WINDOW *win, char **dir_content){ 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); } } 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) { free(content_m); get_dir_size(path, &file_count, &longest_name); content_m = calloc(file_count+1, sizeof(*content_m)); //index 0 is used for metadata like file count in dir for (unsigned long i = 0; i