refractoring & hidden files functionality
This commit is contained in:
parent
8cf1918b0d
commit
c927039b68
40
backend.c
40
backend.c
@ -4,6 +4,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern unsigned int settings;
|
||||||
extern unsigned long longest_name;
|
extern unsigned long longest_name;
|
||||||
extern unsigned long file_count;
|
extern unsigned long file_count;
|
||||||
extern char **content_l;
|
extern char **content_l;
|
||||||
@ -11,18 +12,18 @@ extern char **content_m;
|
|||||||
extern char **content_r;
|
extern char **content_r;
|
||||||
extern char *path;
|
extern char *path;
|
||||||
|
|
||||||
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden){
|
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
if (dir) {
|
if (dir) {
|
||||||
unsigned long index = 0;
|
unsigned long index = 0;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
while ( entry=readdir(dir) ) {
|
while ( entry=readdir(dir) ) {
|
||||||
if (entry->d_name[0] != '.' && !show_hidden) {
|
if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files
|
||||||
index++;
|
index++;
|
||||||
if ((unsigned long)sizeof(entry->d_name) > *longest_name) {
|
if ((unsigned long)sizeof(entry->d_name) > *longest_name) {
|
||||||
*longest_name = sizeof(entry->d_name);
|
*longest_name = sizeof(entry->d_name);
|
||||||
}
|
}
|
||||||
} else if (show_hidden){
|
} else if (settings & 1){ //bit 0 = show_hidden_files
|
||||||
index++;
|
index++;
|
||||||
if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) {
|
if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) {
|
||||||
longest_name = (unsigned long*)sizeof(entry->d_name);
|
longest_name = (unsigned long*)sizeof(entry->d_name);
|
||||||
@ -34,24 +35,19 @@ void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_dir_content(char *path, char **dir_content, char show_hidden){
|
void get_dir_content(char *path, char **dir_content){
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
char content[file_count][longest_name];
|
char content[file_count][longest_name];
|
||||||
memset(content,0,sizeof(content));
|
memset(content,0,sizeof(content));
|
||||||
if (dir) {
|
if (dir) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
while ( entry=readdir(dir) ) {
|
while ( entry=readdir(dir) ) {
|
||||||
if (entry->d_name[0] != '.' && !show_hidden) {
|
if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files
|
||||||
strcpy(dir_content[index], entry->d_name);
|
strcpy(dir_content[index], entry->d_name);
|
||||||
index++;
|
index++;
|
||||||
} else if (show_hidden){
|
} else if (settings & 1){ //bit 0 = show_hidden_files
|
||||||
for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) {
|
strcpy(dir_content[index], entry->d_name);
|
||||||
if ((entry->d_name[i]) != '\0'){
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,43 +56,39 @@ void get_dir_content(char *path, char **dir_content, char show_hidden){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_dir(WINDOW *win, char **dir_content){
|
void print_dir(WINDOW *win, char **dir_content){
|
||||||
char str[longest_name];
|
|
||||||
for (unsigned long i = 0; i < (unsigned long)file_count; i++ ){
|
for (unsigned long i = 0; i < (unsigned long)file_count; i++ ){
|
||||||
strcpy(str, dir_content[i]);
|
wprintw(win, "%s",dir_content[i]);
|
||||||
wprintw(win, "%s",str);
|
|
||||||
wmove(win, i, 1);
|
wmove(win, i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *populate_dir(void *which){ // 0=left, 1=main, 2=right
|
void *populate_dir(void *which){ // 0=left, 1=main, 2=right
|
||||||
char wh = (char)which;
|
char wh = (char)which;
|
||||||
|
|
||||||
|
|
||||||
if (wh) {
|
if (wh) {
|
||||||
if (wh==1) {
|
if (wh==1) {
|
||||||
get_dir_size(path, &file_count, &longest_name, 0);
|
get_dir_size(path, &file_count, &longest_name);
|
||||||
content_m = calloc(file_count, sizeof(*content_m));
|
content_m = calloc(file_count, sizeof(*content_m));
|
||||||
for (unsigned long i = 0; i<file_count; i++) {
|
for (unsigned long i = 0; i<file_count; i++) {
|
||||||
content_m[i] = calloc(longest_name, sizeof(content_m[i]));
|
content_m[i] = calloc(longest_name, sizeof(content_m[i]));
|
||||||
}
|
}
|
||||||
get_dir_content(path, content_m, 0);
|
get_dir_content(path, content_m);
|
||||||
} else {
|
} else {
|
||||||
get_dir_size(path, &file_count, &longest_name, 0);
|
get_dir_size(path, &file_count, &longest_name);
|
||||||
content_r = calloc(file_count, sizeof(*content_r));
|
content_r = calloc(file_count, sizeof(*content_r));
|
||||||
for (unsigned long i = 0; i<file_count; i++) {
|
for (unsigned long i = 0; i<file_count; i++) {
|
||||||
content_r[i] = calloc(longest_name, sizeof(content_r[i]));
|
content_r[i] = calloc(longest_name, sizeof(content_r[i]));
|
||||||
}
|
}
|
||||||
get_dir_content(path, content_r, 0);
|
get_dir_content(path, content_r);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
get_dir_size(path, &file_count, &longest_name, 0);
|
get_dir_size(path, &file_count, &longest_name);
|
||||||
content_l = calloc(file_count, sizeof(*content_l));
|
content_l = calloc(file_count, sizeof(*content_l));
|
||||||
for (unsigned long i = 0; i<file_count; i++) {
|
for (unsigned long i = 0; i<file_count; i++) {
|
||||||
content_l[i] = calloc(longest_name, sizeof(content_l));
|
content_l[i] = calloc(longest_name, sizeof(content_l));
|
||||||
}
|
}
|
||||||
get_dir_content(path, content_l, 0);
|
get_dir_content(path, content_l);
|
||||||
}
|
}
|
||||||
sleep(0);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "backend.c"
|
#include "backend.c"
|
||||||
|
|
||||||
|
|
||||||
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden);
|
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name);
|
||||||
void get_dir_content(char *path, char **dir_content, char show_hidden);
|
void get_dir_content(char *path, char **dir_content);
|
||||||
void print_dir(WINDOW *win, char **dir_content);
|
void print_dir(WINDOW *win, char **dir_content);
|
||||||
void *populate_dir(void *dir);
|
void *populate_dir(void *dir);
|
||||||
|
2
main.c
2
main.c
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
unsigned int terminal_height;
|
unsigned int terminal_height;
|
||||||
unsigned int terminal_width;
|
unsigned int terminal_width;
|
||||||
|
unsigned int settings;
|
||||||
unsigned long file_count;
|
unsigned long file_count;
|
||||||
unsigned long longest_name;
|
unsigned long longest_name;
|
||||||
char **content_l; //content of parent dir, used in left window
|
char **content_l; //content of parent dir, used in left window
|
||||||
@ -22,6 +23,7 @@ int main() {
|
|||||||
WINDOW *winl = newwin(terminal_height, terminal_width/3, terminal_height, (terminal_width/3));
|
WINDOW *winl = newwin(terminal_height, terminal_width/3, terminal_height, (terminal_width/3));
|
||||||
WINDOW *winm = newwin(terminal_height, terminal_width/3, 0, 0);
|
WINDOW *winm = newwin(terminal_height, terminal_width/3, 0, 0);
|
||||||
WINDOW *winr = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2));
|
WINDOW *winr = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2));
|
||||||
|
settings = 1; //bit 0 = show_hidden_files
|
||||||
|
|
||||||
|
|
||||||
while((ch = wgetch(winm)) != 'q'){
|
while((ch = wgetch(winm)) != 'q'){
|
||||||
|
1
window.c
1
window.c
@ -37,7 +37,6 @@ void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char *
|
|||||||
}
|
}
|
||||||
void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
||||||
|
|
||||||
DIR *dir = opendir(".");
|
|
||||||
unsigned int local_width;
|
unsigned int local_width;
|
||||||
unsigned int local_height;
|
unsigned int local_height;
|
||||||
unsigned long file_count = 0;
|
unsigned long file_count = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user