code base good enough to actually progress

This commit is contained in:
nova
2025-04-17 01:17:13 +02:00
parent 931d7026ea
commit 38338df254
13 changed files with 430 additions and 289 deletions

View File

@ -1,71 +1,14 @@
#include <curses.h>
#include <string.h>
#include <pthread.h>
#include <strings.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "defines.h"
extern unsigned int settings;
extern unsigned int file_modifiers;
extern unsigned short cpu_cores; //amount of cores/threads the host system reports to have
extern file_data *content_l;
extern file_data *content_m;
extern file_data *content_r;
extern char *path;
int type(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 (file0_type > file1_type) {
return -1;
} else if (file0_type < file1_type) {
return 1;
} else {
return strcmp(file0_name, file1_name);
int skip_hidden_files(const struct dirent *entry){
if (entry->d_name[0] == '.') {
return 0;
}
}
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 strcmp(file0_name, file1_name);
return 1;
}
int alphabetic(const void *f0, const void *f1){
const char *file0_name = ((file_data*)f0)->file_name;
const char *file1_name = ((file_data*)f1)->file_name;
return strcmp(file0_name, file1_name);
}
void sort_dir(unsigned long *file_count, unsigned long *longest_name, file_data *dir_content){
if ((file_modifiers & FILE_MODIFIERS_SORT_BITMASK) == ~FILE_MODIFIERS_SORT_BITMASK) {
qsort(dir_content, *file_count, sizeof(file_data), natural);
} else if (file_modifiers & FILE_MODIFIERS_SORT_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);
}
}