60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
#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 char **content_l;
|
|
extern char **content_m;
|
|
extern char **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;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
int alphabetic(const void *str1, const void *str2){
|
|
const char *rec1 = *(char**)str1;
|
|
const char *rec2 = *(char**)str2;
|
|
int ret = strcmp(str1, rec2);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void sort_dir(unsigned long *file_count, unsigned long *longest_name, char **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);
|
|
|
|
} else if (file_modifiers & FILE_MODIFIERS_SORT_ALPHABETIC) {
|
|
qsort(dir_content, *file_count, sizeof(longest_name), alphabetic);
|
|
}
|
|
|
|
|
|
|
|
}
|