mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
improvenments to random sort
This commit is contained in:
4
dir.c
4
dir.c
@@ -51,9 +51,9 @@ unsigned long get_dir_size(char *path){
|
||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content){
|
||||
struct dirent **entry;
|
||||
if (file_modifiers & FILE_MODIFIERS_HIDDEN_FILES) { /* print hidden files */
|
||||
scandir(path, &entry, skip_dot, alphasort);
|
||||
scandir(path, &entry, skip_dot, NULL);
|
||||
} else {
|
||||
scandir(path, &entry, skip_hidden_files, alphasort);
|
||||
scandir(path, &entry, skip_hidden_files, NULL);
|
||||
}
|
||||
|
||||
unsigned long i = 0;
|
||||
|
4
main.c
4
main.c
@@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "threading.h"
|
||||
@@ -20,6 +21,7 @@ unsigned int settings;
|
||||
unsigned int file_modifiers;
|
||||
unsigned int status = (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
char *start_path;
|
||||
time_t seed;
|
||||
|
||||
WINDOW *win_t;
|
||||
WINDOW *win_b;
|
||||
@@ -188,5 +190,7 @@ void init() {
|
||||
char *start_path = getcwd(NULL, 0);
|
||||
setenv("START_PATH", start_path, 0);
|
||||
free(start_path);
|
||||
time(&seed);
|
||||
srand(seed);
|
||||
|
||||
}
|
||||
|
63
sorting.c
63
sorting.c
@@ -1,11 +1,13 @@
|
||||
#include <curses.h>
|
||||
#include <dirent.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
extern time_t seed;
|
||||
extern unsigned int settings;
|
||||
extern unsigned int file_modifiers;
|
||||
|
||||
@@ -97,55 +99,22 @@ int sort_alpha(const void *file0, const void *file1){
|
||||
char *file_name1 = ((file*)file1)->file_name;
|
||||
return strcmp(file_name0, file_name1);
|
||||
}
|
||||
int sort_random(const void *file0, const void *file1){
|
||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||
static int seed = 0;
|
||||
static int random = 0;
|
||||
|
||||
if (seed == 0) {
|
||||
seed = rand();
|
||||
}
|
||||
if (random == 0) {
|
||||
random = seed;
|
||||
}
|
||||
char weight = 0;
|
||||
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||
weight |= 1;
|
||||
}
|
||||
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
||||
weight |= 2;
|
||||
}
|
||||
if (weight == 0 || weight == 3) {
|
||||
random = random > 1;
|
||||
if ((random & 2) == 2) {
|
||||
int sort_random(const void *file0_, const void *file1_){
|
||||
file *file0 = (file*)file0_;
|
||||
file *file1 = (file*)file1_;
|
||||
if (file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
||||
return -1;
|
||||
} else {
|
||||
if (random & 1){
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (file_type0 > file_type1) {
|
||||
}
|
||||
if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
||||
return 1;
|
||||
} else if (file_type0 < file_type1) {
|
||||
return -1;
|
||||
} else {
|
||||
random = random > 1;
|
||||
if ((random & 2) == 2) {
|
||||
return -1;
|
||||
} else {
|
||||
if (random & 1){
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
int random = rand();
|
||||
if (random & 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
int sort_type(const void *file0, const void *file1){
|
||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||
|
Reference in New Issue
Block a user