last commit before large rewrite
This commit is contained in:
parent
2a1d273bc0
commit
931d7026ea
72
backend.c
72
backend.c
@ -9,16 +9,20 @@
|
|||||||
|
|
||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
extern char **content_l;
|
extern file_data *content_l;
|
||||||
extern char **content_m;
|
extern file_data *content_m;
|
||||||
extern char **content_r;
|
extern file_data *content_r;
|
||||||
extern char *path;
|
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){
|
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
*longest_name = 256; //magic number originates out of readdir(), unless i implement my own name size function, thisll do
|
*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) {
|
if (dir) {
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
while ( (entry=readdir(dir)) ) {
|
while ( (entry=readdir(dir)) ) {
|
||||||
@ -33,19 +37,19 @@ void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_
|
|||||||
closedir(dir);
|
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);
|
DIR *dir = opendir(path);
|
||||||
char content[file_count][longest_name];
|
|
||||||
memset(content,0,sizeof(content));
|
|
||||||
if (dir) {
|
if (dir) {
|
||||||
int index = 1; //skip index 0 as it is used for metadata like file count
|
unsigned long index = 0;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
while ( (entry=readdir(dir)) ) {
|
while ( (entry=readdir(dir)) ) {
|
||||||
if (entry->d_name[0] != '.' && !(file_modifiers & FILE_MODIFIERS_HIDDEN_FILES)) {
|
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++;
|
index++;
|
||||||
} else if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) {
|
} 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++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,48 +57,42 @@ void get_dir_content(char *path, unsigned long file_count, unsigned long longest
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_dir(WINDOW *win, char **dir_content){
|
void print_dir(WINDOW *win, unsigned long file_count, file_data *dir_content){
|
||||||
for (unsigned long i = 1; i < *dir_content[0]; i++ ){ //skip index 0 as it is used for metadata like file count
|
for (unsigned long i = 0; i < file_count; i++ ){ //skip index 0 as it is used for metadata like file count
|
||||||
wprintw(win, "%s",dir_content[i]);
|
if (dir_content[i].file_name) {
|
||||||
wmove(win, i, 1);
|
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
|
void *populate_dir(void *which){ // 0=left, 1=main, 2=right
|
||||||
char wh = (char)which;
|
char wh = (char)which;
|
||||||
unsigned long file_count = 0;
|
|
||||||
unsigned long longest_name = 0;
|
unsigned long longest_name = 0;
|
||||||
|
|
||||||
if (wh) {
|
if (wh) {
|
||||||
if (wh == 1) {
|
if (wh == 1) {
|
||||||
free(content_m);
|
free(content_m);
|
||||||
get_dir_size(path, &file_count, &longest_name);
|
get_dir_size(path, &file_count_m, &longest_name);
|
||||||
content_m = calloc(file_count+1, sizeof(*content_m)); //index 0 is used for metadata like file count in dir
|
content_m = (file_data*)calloc(file_count_m, sizeof(file_data));
|
||||||
for (unsigned long i = 0; i<file_count+1; i++) {
|
get_dir_content(path, file_count_m, longest_name, content_m);
|
||||||
content_m[i] = calloc(longest_name, sizeof(content_m[i]));
|
sort_dir(&file_count_m, &longest_name, content_m);
|
||||||
}
|
|
||||||
*content_m[0] = file_count;
|
|
||||||
get_dir_content(path, file_count, longest_name, content_m);
|
|
||||||
sort_dir(&file_count, &longest_name, content_m);
|
|
||||||
} else {
|
} else {
|
||||||
free(content_r);
|
free(content_r);
|
||||||
get_dir_size(path, &file_count, &longest_name);
|
get_dir_size(path, &file_count_r, &longest_name);
|
||||||
content_r = calloc(file_count+1, sizeof(*content_r));
|
content_r = calloc(file_count_r, sizeof(file_data));
|
||||||
for (unsigned long i = 0; i<file_count+1; i++) {
|
get_dir_content(path, file_count_r, longest_name, content_r);
|
||||||
content_r[i] = calloc(longest_name, sizeof(content_r[i]));
|
sort_dir(&file_count_m, &longest_name, content_r);
|
||||||
}
|
|
||||||
*content_r[0] = file_count;
|
|
||||||
get_dir_content(path, file_count, longest_name, content_r);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
free(content_l);
|
free(content_l);
|
||||||
get_dir_size(path, &file_count, &longest_name);
|
get_dir_size(path, &file_count_l, &longest_name);
|
||||||
content_l = calloc(file_count+1, sizeof(*content_l));
|
content_l = calloc(file_count_l, sizeof(file_data));
|
||||||
for (unsigned long i = 0; i<file_count+1; i++) {
|
get_dir_content(path, file_count_l, longest_name, content_l);
|
||||||
content_l[i] = calloc(longest_name, sizeof(content_l));
|
sort_dir(&file_count_m, &longest_name, content_l);
|
||||||
}
|
|
||||||
*content_l[0] = file_count;
|
|
||||||
get_dir_content(path, file_count, longest_name, content_l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name);
|
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name);
|
||||||
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);
|
||||||
void print_dir(WINDOW *win, char **dir_content);
|
void print_dir(WINDOW *win, unsigned long file_count, file_data *dir_content);
|
||||||
void sort_dir(unsigned long *file_count, unsigned long *longest_name, char **dir_content);
|
//void sort_dir(unsigned long *file_count, unsigned long *longest_name, file_data *dir_content);
|
||||||
void *populate_dir(void *dir);
|
void *populate_dir(void *dir);
|
||||||
|
@ -13,3 +13,11 @@
|
|||||||
#define FILE_MODIFIERS_SORT_RANDOM 32
|
#define FILE_MODIFIERS_SORT_RANDOM 32
|
||||||
#define FILE_MODIFIERS_SORT_REVERSE 64
|
#define FILE_MODIFIERS_SORT_REVERSE 64
|
||||||
//FILE_MODIFIERS_SORT_NATURAL is when bitmask is 0
|
//FILE_MODIFIERS_SORT_NATURAL is when bitmask is 0
|
||||||
|
|
||||||
|
#ifndef HEADER_GUARD
|
||||||
|
#define HEADER_GUARD
|
||||||
|
typedef struct file_data {
|
||||||
|
char *file_name;
|
||||||
|
unsigned char file_type;
|
||||||
|
} file_data;
|
||||||
|
#endif
|
||||||
|
@ -4,16 +4,22 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern unsigned int file_modifiers;
|
||||||
|
|
||||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings, unsigned int *file_modifiers) {
|
void user_interactions(char *input, unsigned int *status, unsigned int *settings) {
|
||||||
if (*input == 'q') {
|
if (*input == 'q') {
|
||||||
*status ^= STATUS_QUIT_PROGRAM;
|
*status ^= STATUS_QUIT_PROGRAM;
|
||||||
} else if (*input == *"KEY_BACKSPACE") {
|
} else if (*input == *"KEY_BACKSPACE") {
|
||||||
*file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
} else if (*input == 'a') {
|
} else if (*input == 'a') {
|
||||||
*file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
||||||
|
} else if (*input == 'o') {
|
||||||
|
file_modifiers ^= FILE_MODIFIERS_SORT_BITMASK;
|
||||||
|
} else if (*input == 'e') {
|
||||||
|
file_modifiers ^= FILE_MODIFIERS_SORT_ALPHABETIC;
|
||||||
|
} else if (*input == 'u') {
|
||||||
|
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
else {
|
*status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
}
|
|
||||||
*status ^= STATUS_RUN_BACKEND;
|
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "interactions.c"
|
#include "interactions.c"
|
||||||
|
|
||||||
void user_interactions(char *input, unsigned int *status, unsigned int *settings, unsigned int *file_modifiers);
|
void user_interactions(char *input, unsigned int *status, unsigned int *settings);
|
||||||
|
25
main.c
25
main.c
@ -15,9 +15,9 @@ unsigned int settings;
|
|||||||
unsigned int file_modifiers;
|
unsigned int file_modifiers;
|
||||||
unsigned int status; //bit 0 = enable
|
unsigned int status; //bit 0 = enable
|
||||||
unsigned short cpu_cores; //amount of cores/threads the host system reports to have
|
unsigned short cpu_cores; //amount of cores/threads the host system reports to have
|
||||||
char **content_l; //content of parent dir, used in left window
|
file_data *content_l; //content of parent dir, used in left window
|
||||||
char **content_m; //content of current dir, used in main window
|
file_data *content_m; //content of current dir, used in main window
|
||||||
char **content_r; //content of child dir, used in right window
|
file_data *content_r; //content of child dir, used in right window
|
||||||
char *path = ".";
|
char *path = ".";
|
||||||
char input = 0;
|
char input = 0;
|
||||||
|
|
||||||
@ -52,7 +52,8 @@ int main() {
|
|||||||
pthread_join(populate_l, NULL);
|
pthread_join(populate_l, NULL);
|
||||||
pthread_join(populate_m, NULL);
|
pthread_join(populate_m, NULL);
|
||||||
pthread_join(populate_r, NULL);
|
pthread_join(populate_r, NULL);
|
||||||
status ^= STATUS_UPDATE_SCREEN_0;
|
status ^= STATUS_RUN_BACKEND;
|
||||||
|
status |= STATUS_UPDATE_SCREEN_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,12 +68,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wmove(stdscr,0,0);
|
wmove(stdscr,0,0);
|
||||||
status &= ~STATUS_UPDATE_SCREEN_MASK;
|
//status &= ~STATUS_UPDATE_SCREEN_MASK;
|
||||||
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((input = getch())) {
|
if ((input = getch())) {
|
||||||
user_interactions(&input, &status, &settings, &file_modifiers);
|
user_interactions(&input, &status, &settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(content_l);
|
free(content_l);
|
||||||
@ -88,11 +90,12 @@ int main() {
|
|||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
cpu_cores = get_nprocs();
|
cpu_cores = get_nprocs();
|
||||||
file_modifiers ^= FILE_MODIFIERS_HIDDEN_FILES;
|
//file_modifiers = (FILE_MODIFIERS_HIDDEN_FILES | FILE_MODIFIERS_SORT_BITMASK);
|
||||||
status ^= STATUS_RUN_BACKEND;
|
file_modifiers = FILE_MODIFIERS_SORT_BITMASK;
|
||||||
|
status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
|
|
||||||
content_l = calloc(1, sizeof(*content_l)); //allocation in order to allow a more streamlined backend
|
content_l = (file_data*)calloc(1, sizeof(file_data)); //allocation in order to allow a more streamlined backend
|
||||||
content_m = calloc(1, sizeof(*content_m));
|
content_m = (file_data*)calloc(1, sizeof(file_data));
|
||||||
content_r = calloc(1, sizeof(*content_r));
|
content_r = (file_data*)calloc(1, sizeof(file_data));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
68
sorting.c
68
sorting.c
@ -12,46 +12,58 @@
|
|||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
extern unsigned short cpu_cores; //amount of cores/threads the host system reports to have
|
extern unsigned short cpu_cores; //amount of cores/threads the host system reports to have
|
||||||
extern char **content_l;
|
extern file_data *content_l;
|
||||||
extern char **content_m;
|
extern file_data *content_m;
|
||||||
extern char **content_r;
|
extern file_data *content_r;
|
||||||
extern char *path;
|
extern char *path;
|
||||||
|
|
||||||
int natural(const void *file0, const void *file1){
|
int type(const void *f0, const void *f1){
|
||||||
const char *rec1 = *(char**)file0;
|
const char *file0_name = ((file_data*)f0)->file_name;
|
||||||
const char *rec2 = *(char**)file1;
|
const char *file1_name = ((file_data*)f1)->file_name;
|
||||||
int ret = 0;
|
const char file0_type = ((file_data*)f0)->file_type;
|
||||||
struct stat f0;
|
const char file1_type = ((file_data*)f1)->file_type;
|
||||||
struct stat f1;
|
if (file0_type > file1_type) {
|
||||||
stat(rec1, &f0);
|
return -1;
|
||||||
stat(rec2, &f1);
|
} else if (file0_type < file1_type) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
if (S_ISDIR(f0.st_mode) > S_ISDIR(f1.st_mode)) {
|
return strcmp(file0_name, file1_name);
|
||||||
ret = 1;
|
}
|
||||||
} else if (S_ISDIR(f0.st_mode) < S_ISDIR(f1.st_mode)) {
|
}
|
||||||
ret = -1;
|
int natural(const void *f0, const void *f1){
|
||||||
|
const char *file0_name = ((file_data*)f0)->file_name;
|
||||||
|
const char *file1_name = ((file_data*)f1)->file_name;
|
||||||
|
const char file0_type = ((file_data*)f0)->file_type;
|
||||||
|
const char file1_type = ((file_data*)f1)->file_type;
|
||||||
|
if (S_ISDIR(file0_type) || S_ISDIR(file1_type)) {
|
||||||
|
if (file0_type == file1_type) {
|
||||||
|
return strcmp(file0_name, file1_name);
|
||||||
|
} else if (S_ISDIR(file1_type)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
//return strcmp(file0_name, file1_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int alphabetic(const void *str1, const void *str2){
|
int alphabetic(const void *f0, const void *f1){
|
||||||
const char *rec1 = *(char**)str1;
|
const char *file0_name = ((file_data*)f0)->file_name;
|
||||||
const char *rec2 = *(char**)str2;
|
const char *file1_name = ((file_data*)f1)->file_name;
|
||||||
int ret = strcmp(str1, rec2);
|
return strcmp(file0_name, file1_name);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sort_dir(unsigned long *file_count, unsigned long *longest_name, char **dir_content){
|
void sort_dir(unsigned long *file_count, unsigned long *longest_name, file_data *dir_content){
|
||||||
|
|
||||||
if (file_modifiers & ~FILE_MODIFIERS_SORT_BITMASK) {
|
if ((file_modifiers & FILE_MODIFIERS_SORT_BITMASK) == ~FILE_MODIFIERS_SORT_BITMASK) {
|
||||||
qsort(dir_content, *file_count, sizeof(longest_name), alphabetic);
|
qsort(dir_content, *file_count, sizeof(file_data), natural);
|
||||||
qsort(dir_content, *file_count, sizeof(longest_name), natural);
|
|
||||||
|
|
||||||
} else if (file_modifiers & FILE_MODIFIERS_SORT_ALPHABETIC) {
|
} else if (file_modifiers & FILE_MODIFIERS_SORT_ALPHABETIC) {
|
||||||
qsort(dir_content, *file_count, sizeof(longest_name), alphabetic);
|
qsort(dir_content, *file_count, sizeof(file_data), alphabetic);
|
||||||
|
|
||||||
|
} else if (file_modifiers & FILE_MODIFIERS_SORT_TYPE) {
|
||||||
|
qsort(dir_content, *file_count, sizeof(file_data), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "sorting.c"
|
#include "sorting.c"
|
||||||
|
|
||||||
void sort_dir(unsigned long *file_count, unsigned long *longest_name, char **dir_content);
|
void sort_dir(unsigned long *file_count, unsigned long *longest_name, file_data *dir_content);
|
||||||
|
|
||||||
|
4
structs.h
Normal file
4
structs.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
typedef struct data {
|
||||||
|
char *file_name;
|
||||||
|
unsigned char file_type;
|
||||||
|
} file_data;
|
16
window.c
16
window.c
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
extern unsigned int terminal_height;
|
extern unsigned int terminal_height;
|
||||||
extern unsigned int terminal_width;
|
extern unsigned int terminal_width;
|
||||||
|
extern unsigned long file_count_l;
|
||||||
|
extern unsigned long file_count_m;
|
||||||
|
extern unsigned long file_count_r;
|
||||||
|
|
||||||
|
|
||||||
|
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, file_data *dir_content){
|
||||||
|
|
||||||
|
|
||||||
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
|
||||||
|
|
||||||
//WINDOW *win = (window_data)window_data.win;
|
//WINDOW *win = (window_data)window_data.win;
|
||||||
unsigned int local_width;
|
unsigned int local_width;
|
||||||
@ -24,14 +24,14 @@ void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char *
|
|||||||
|
|
||||||
wmove(win, 1, 1);
|
wmove(win, 1, 1);
|
||||||
|
|
||||||
print_dir(win, dir_content);
|
print_dir(win, file_count_m, dir_content);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
box(win,0,0);
|
box(win,0,0);
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
}
|
}
|
||||||
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, file_data *dir_content){
|
||||||
|
|
||||||
unsigned int local_width;
|
unsigned int local_width;
|
||||||
unsigned int local_height;
|
unsigned int local_height;
|
||||||
@ -45,13 +45,13 @@ void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char *
|
|||||||
|
|
||||||
wmove(win, 1, 1);
|
wmove(win, 1, 1);
|
||||||
|
|
||||||
print_dir(win, dir_content);
|
print_dir(win, file_count_l, dir_content);
|
||||||
|
|
||||||
|
|
||||||
box(win,0,0);
|
box(win,0,0);
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
}
|
}
|
||||||
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){
|
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, file_data *dir_content){
|
||||||
|
|
||||||
wmove(win, 0, 0);
|
wmove(win, 0, 0);
|
||||||
unsigned int local_width;
|
unsigned int local_width;
|
||||||
|
6
window.h
6
window.h
@ -1,7 +1,7 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include "window.c"
|
#include "window.c"
|
||||||
|
|
||||||
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, file_data *dir_content);
|
||||||
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content);
|
void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, file_data *dir_content);
|
||||||
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content);
|
void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, file_data *dir_content);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user