last commit before large rewrite
This commit is contained in:
68
sorting.c
68
sorting.c
@ -12,46 +12,58 @@
|
||||
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 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;
|
||||
|
||||
int natural(const void *file0, const void *file1){
|
||||
const char *rec1 = *(char**)file0;
|
||||
const char *rec2 = *(char**)file1;
|
||||
int ret = 0;
|
||||
struct stat f0;
|
||||
struct stat f1;
|
||||
stat(rec1, &f0);
|
||||
stat(rec2, &f1);
|
||||
|
||||
|
||||
if (S_ISDIR(f0.st_mode) > S_ISDIR(f1.st_mode)) {
|
||||
ret = 1;
|
||||
} else if (S_ISDIR(f0.st_mode) < S_ISDIR(f1.st_mode)) {
|
||||
ret = -1;
|
||||
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 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){
|
||||
const char *rec1 = *(char**)str1;
|
||||
const char *rec2 = *(char**)str2;
|
||||
int ret = strcmp(str1, rec2);
|
||||
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);
|
||||
|
||||
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) {
|
||||
qsort(dir_content, *file_count, sizeof(longest_name), alphabetic);
|
||||
qsort(dir_content, *file_count, sizeof(longest_name), natural);
|
||||
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(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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user