mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
improvements to sort_rand
This commit is contained in:
@@ -35,6 +35,8 @@ extern unsigned int status;
|
||||
extern char *start_path;
|
||||
extern char *input;
|
||||
|
||||
extern time_t seed;
|
||||
|
||||
char search_buffer[255];
|
||||
unsigned int timeout_time = 0;
|
||||
unsigned int input_pass;
|
||||
@@ -595,6 +597,8 @@ void jump_to_dir(int passes, int index){
|
||||
void order_by(int passes, int index){
|
||||
(void)passes;
|
||||
|
||||
seed = time(NULL);
|
||||
srand(seed);
|
||||
order_func = key_binding[index].black_magic;
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
|
4
main.c
4
main.c
@@ -102,6 +102,7 @@ int main(){
|
||||
if (dt - t >= SETTINGS_RELOAD_DIR_DELTA) {
|
||||
time(&t);
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
srand(seed);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -205,7 +206,6 @@ void init() {
|
||||
char *start_path = getcwd(NULL, 0);
|
||||
setenv("START_PATH", start_path, 0);
|
||||
free(start_path);
|
||||
time(&seed);
|
||||
srand(seed);
|
||||
seed = time(NULL);
|
||||
|
||||
}
|
||||
|
16
sorting.c
16
sorting.c
@@ -103,21 +103,15 @@ 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_){
|
||||
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))) {
|
||||
int sort_random(const void *file0, const void *file1){
|
||||
|
||||
if (((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
||||
return -1;
|
||||
}
|
||||
if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
||||
if (!(((file*)file0)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && ((file*)file1)->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
||||
return 1;
|
||||
}
|
||||
int random = rand();
|
||||
if (random & 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return ((rand()%3)-1);
|
||||
|
||||
}
|
||||
int sort_type(const void *file0, const void *file1){
|
||||
|
Reference in New Issue
Block a user