base layout for multithreading
This commit is contained in:
94
window.c
94
window.c
@ -1,78 +1,19 @@
|
||||
#include "curses.h"
|
||||
#include "string.h"
|
||||
#include <stdlib.h>
|
||||
#include <curses.h>
|
||||
#include <dirent.h>
|
||||
#include "backend.h"
|
||||
|
||||
extern unsigned int terminal_height;
|
||||
extern unsigned int terminal_width;
|
||||
|
||||
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden) {
|
||||
DIR *dir = opendir(path);
|
||||
if (dir) {
|
||||
unsigned long index = 0;
|
||||
struct dirent *entry;
|
||||
while ( entry=readdir(dir) ) {
|
||||
if (entry->d_name[0] != '.' && !show_hidden) {
|
||||
index++;
|
||||
if ((unsigned long)sizeof(entry->d_name) > *longest_name) {
|
||||
*longest_name = sizeof(entry->d_name);
|
||||
}
|
||||
} else if (show_hidden){
|
||||
index++;
|
||||
if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) {
|
||||
longest_name = (unsigned long*)sizeof(entry->d_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
*file_count = index;
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char *dir_content[file_count], char show_hidden){
|
||||
DIR *dir = opendir(path);
|
||||
char content[file_count][longest_name];
|
||||
memset(content,0,sizeof(content));
|
||||
if (dir) {
|
||||
int index = 0;
|
||||
struct dirent *entry;
|
||||
while ( entry=readdir(dir) ) {
|
||||
if (entry->d_name[0] != '.' && !show_hidden) {
|
||||
// for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) {
|
||||
// if ((entry->d_name[i]) != '\0'){
|
||||
// dir_content[index][i] = entry->d_name[i];
|
||||
// } else {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
strcpy(dir_content[index], entry->d_name);
|
||||
index++;
|
||||
} else if (show_hidden){
|
||||
for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) {
|
||||
if ((entry->d_name[i]) != '\0'){
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
void print_dir(WINDOW *win, unsigned long file_count, unsigned long longest_name, char **dir_content){
|
||||
char str[longest_name];
|
||||
for (unsigned long i = 0; i < (unsigned long)file_count; i++ ){
|
||||
strcpy(str, dir_content[i]);
|
||||
wprintw(win, "%s",str);
|
||||
wmove(win, i, 1);
|
||||
}
|
||||
}
|
||||
extern unsigned long longest_name;
|
||||
extern unsigned long file_count;
|
||||
|
||||
|
||||
|
||||
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){
|
||||
|
||||
|
||||
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
||||
|
||||
//WINDOW *win = (window_data)window_data.win;
|
||||
unsigned int local_width;
|
||||
unsigned int local_height;
|
||||
unsigned long file_count = 0;
|
||||
@ -86,24 +27,15 @@ void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){
|
||||
//}}}
|
||||
|
||||
wmove(win, 1, 1);
|
||||
wprintw(win, "meow");
|
||||
get_dir_size(".", &file_count, &longest_name, 0);
|
||||
char **dir_content;
|
||||
dir_content = calloc(file_count, sizeof(*dir_content));
|
||||
for (unsigned long i = 0; i<file_count; i++) {
|
||||
dir_content[i] = calloc(longest_name, sizeof(*dir_content[i]));
|
||||
}
|
||||
|
||||
get_dir_content(".", file_count, longest_name, dir_content, 0);
|
||||
print_dir(win, file_count, longest_name, dir_content);
|
||||
print_dir(win, dir_content);
|
||||
|
||||
|
||||
free(*dir_content);
|
||||
|
||||
box(win,0,0);
|
||||
wrefresh(win);
|
||||
}
|
||||
void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x){
|
||||
void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
||||
|
||||
DIR *dir = opendir(".");
|
||||
unsigned int local_width;
|
||||
@ -118,13 +50,15 @@ void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x){
|
||||
wclear(win);
|
||||
//}}}
|
||||
|
||||
wmove(win, 0, 0);
|
||||
wmove(win, 1, 1);
|
||||
|
||||
print_dir(win, dir_content);
|
||||
|
||||
|
||||
box(win,0,0);
|
||||
wrefresh(win);
|
||||
}
|
||||
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x){
|
||||
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
||||
|
||||
wmove(win, 0, 0);
|
||||
unsigned int local_width;
|
||||
|
Reference in New Issue
Block a user