last commit before large rewrite
This commit is contained in:
72
backend.c
72
backend.c
@ -9,16 +9,20 @@
|
||||
|
||||
extern unsigned int settings;
|
||||
extern unsigned int file_modifiers;
|
||||
extern char **content_l;
|
||||
extern char **content_m;
|
||||
extern char **content_r;
|
||||
extern file_data *content_l;
|
||||
extern file_data *content_m;
|
||||
extern file_data *content_r;
|
||||
extern char *path;
|
||||
|
||||
unsigned long file_count_l;
|
||||
unsigned long file_count_m;
|
||||
unsigned long file_count_r;
|
||||
|
||||
|
||||
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
|
||||
unsigned long index = 0;
|
||||
if (dir) {
|
||||
struct dirent *entry;
|
||||
while ( (entry=readdir(dir)) ) {
|
||||
@ -33,19 +37,19 @@ void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char **dir_content){
|
||||
void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, file_data *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
|
||||
unsigned long index = 0;
|
||||
struct dirent *entry;
|
||||
while ( (entry=readdir(dir)) ) {
|
||||
if (entry->d_name[0] != '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
||||
strcpy(dir_content[index], entry->d_name);
|
||||
dir_content[index].file_name = entry->d_name;
|
||||
dir_content[index].file_type = entry->d_type;
|
||||
index++;
|
||||
} else if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
||||
strcpy(dir_content[index], entry->d_name);
|
||||
dir_content[index].file_name = entry->d_name;
|
||||
dir_content[index].file_type = entry->d_type;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@ -53,48 +57,42 @@ void get_dir_content(char *path, unsigned long file_count, unsigned long longest
|
||||
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 print_dir(WINDOW *win, unsigned long file_count, file_data *dir_content){
|
||||
for (unsigned long i = 0; i < file_count; i++ ){ //skip index 0 as it is used for metadata like file count
|
||||
if (dir_content[i].file_name) {
|
||||
wprintw(win, "%s",dir_content[i].file_name);
|
||||
wmove(win, i, 1);
|
||||
} else {
|
||||
wprintw(win, "NULL");
|
||||
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<file_count+1; i++) {
|
||||
content_m[i] = calloc(longest_name, sizeof(content_m[i]));
|
||||
}
|
||||
*content_m[0] = file_count;
|
||||
get_dir_content(path, file_count, longest_name, content_m);
|
||||
sort_dir(&file_count, &longest_name, content_m);
|
||||
get_dir_size(path, &file_count_m, &longest_name);
|
||||
content_m = (file_data*)calloc(file_count_m, sizeof(file_data));
|
||||
get_dir_content(path, file_count_m, longest_name, content_m);
|
||||
sort_dir(&file_count_m, &longest_name, content_m);
|
||||
} else {
|
||||
free(content_r);
|
||||
get_dir_size(path, &file_count, &longest_name);
|
||||
content_r = calloc(file_count+1, sizeof(*content_r));
|
||||
for (unsigned long i = 0; i<file_count+1; i++) {
|
||||
content_r[i] = calloc(longest_name, sizeof(content_r[i]));
|
||||
}
|
||||
*content_r[0] = file_count;
|
||||
get_dir_content(path, file_count, longest_name, content_r);
|
||||
get_dir_size(path, &file_count_r, &longest_name);
|
||||
content_r = calloc(file_count_r, sizeof(file_data));
|
||||
get_dir_content(path, file_count_r, longest_name, content_r);
|
||||
sort_dir(&file_count_m, &longest_name, content_r);
|
||||
}
|
||||
} else {
|
||||
free(content_l);
|
||||
get_dir_size(path, &file_count, &longest_name);
|
||||
content_l = calloc(file_count+1, sizeof(*content_l));
|
||||
for (unsigned long i = 0; i<file_count+1; i++) {
|
||||
content_l[i] = calloc(longest_name, sizeof(content_l));
|
||||
}
|
||||
*content_l[0] = file_count;
|
||||
get_dir_content(path, file_count, longest_name, content_l);
|
||||
get_dir_size(path, &file_count_l, &longest_name);
|
||||
content_l = calloc(file_count_l, sizeof(file_data));
|
||||
get_dir_content(path, file_count_l, longest_name, content_l);
|
||||
sort_dir(&file_count_m, &longest_name, content_l);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user