mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 18:30:15 -04:00
Compare commits
2 Commits
4a9c38d034
...
9f3042ccac
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9f3042ccac | ||
![]() |
a05c3ecd96 |
20
defines.h
20
defines.h
@@ -39,16 +39,16 @@
|
|||||||
#define COLOR_ORPHAN 9
|
#define COLOR_ORPHAN 9
|
||||||
#define COLOR_PATH 10
|
#define COLOR_PATH 10
|
||||||
|
|
||||||
#define FILE_TYPE_UNKNOWN COLOR_UNKNOWN
|
#define FILE_TYPE_UNKNOWN 0
|
||||||
#define FILE_TYPE_DIR COLOR_DIR
|
#define FILE_TYPE_EXEC 1
|
||||||
#define FILE_TYPE_EXEC COLOR_EXEC
|
#define FILE_TYPE_REGULAR 2
|
||||||
#define FILE_TYPE_REGULAR COLOR_REGULAR
|
#define FILE_TYPE_BLOCK 3
|
||||||
#define FILE_TYPE_SYMLINK COLOR_SYMLINK
|
#define FILE_TYPE_CHARDEV 4
|
||||||
#define FILE_TYPE_BLOCK COLOR_BLOCK
|
#define FILE_TYPE_SOCK 5
|
||||||
#define FILE_TYPE_CHARDEV COLOR_CHARDEV
|
#define FILE_TYPE_FIFO 6
|
||||||
#define FILE_TYPE_SOCK COLOR_SOCK
|
#define FILE_TYPE_ORPHAN 7
|
||||||
#define FILE_TYPE_FIFO COLOR_FIFO
|
#define FILE_TYPE_DIR 32
|
||||||
#define FILE_TYPE_ORPHAN COLOR_ORPHAN
|
#define FILE_TYPE_SYMLINK 64
|
||||||
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
#define FILE_TYPE_OPEN_FILE 128 /* this is only used in rgt_content to print a file preview, not the dir */
|
||||||
|
|
||||||
#define YANK_IS_USED 1
|
#define YANK_IS_USED 1
|
||||||
|
9
dir.c
9
dir.c
@@ -313,18 +313,23 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
free(bg);
|
free(bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_selected_file(){
|
char update_selected_file(){
|
||||||
|
char ret = -1; /* -1 on empty or inaccessible file, 0 on unchanged file, 1 on changed file */
|
||||||
if (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */
|
if (mid_content->file_name[0] == '\0') { /* only happens if the current path is either empty or inaccessible */
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
if (selected_file_current >= mid_file_count) {
|
if (selected_file_current >= mid_file_count) {
|
||||||
selected_file_current = mid_file_count-1;
|
selected_file_current = mid_file_count-1;
|
||||||
}
|
}
|
||||||
if (selected_file_current != selected_file_last) {
|
if (selected_file_current != selected_file_last) {
|
||||||
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
mid_content[selected_file_last].status &= ~FILE_STATUS_HOVER;
|
||||||
|
ret = 1;
|
||||||
|
} else {
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
||||||
selected_file_last = selected_file_current;
|
selected_file_last = selected_file_current;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current){
|
void dir_set_selected_file_current(unsigned long selected_file_current){
|
||||||
if (mid_content->file_name[0] != '\0') {
|
if (mid_content->file_name[0] != '\0') {
|
||||||
|
2
dir.h
2
dir.h
@@ -6,7 +6,7 @@
|
|||||||
unsigned long get_dir_size(char *path);
|
unsigned long get_dir_size(char *path);
|
||||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
||||||
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file *dir_content);
|
||||||
void update_selected_file();
|
char update_selected_file();
|
||||||
void dir_set_selected_file_current(unsigned long selected_file_current);
|
void dir_set_selected_file_current(unsigned long selected_file_current);
|
||||||
unsigned long dir_get_selected_file_current();
|
unsigned long dir_get_selected_file_current();
|
||||||
void dir_init();
|
void dir_init();
|
||||||
|
@@ -17,6 +17,7 @@ extern unsigned int file_modifiers;
|
|||||||
extern pthread_mutex_t mutex_selection;
|
extern pthread_mutex_t mutex_selection;
|
||||||
extern pthread_mutex_t mutex_rgt;
|
extern pthread_mutex_t mutex_rgt;
|
||||||
extern pthread_mutex_t mutex_mid;
|
extern pthread_mutex_t mutex_mid;
|
||||||
|
extern pthread_cond_t cond_rgt;
|
||||||
extern file *mid_content;
|
extern file *mid_content;
|
||||||
extern file *lft_content;
|
extern file *lft_content;
|
||||||
extern file *rgt_content;
|
extern file *rgt_content;
|
||||||
@@ -807,11 +808,13 @@ void search(){
|
|||||||
for (i = 0; i < mid_file_count; i++) {
|
for (i = 0; i < mid_file_count; i++) {
|
||||||
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
if (smartstrcasestr(mid_content[i].file_name, search_buffer)) {
|
||||||
selected_file_current = i;
|
selected_file_current = i;
|
||||||
update_selected_file();
|
if (update_selected_file()) {
|
||||||
|
pthread_cond_signal(&cond_rgt);
|
||||||
|
}
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_0);
|
||||||
render_pass();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
render_pass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
85
sorting.c
85
sorting.c
@@ -4,6 +4,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
extern unsigned int settings;
|
extern unsigned int settings;
|
||||||
extern unsigned int file_modifiers;
|
extern unsigned int file_modifiers;
|
||||||
|
|
||||||
@@ -20,31 +22,74 @@ int skip_dot(const struct dirent *entry){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sort_natural(const void *file0, const void *file1){
|
int sort_natural(const void *file0_, const void *file1_){
|
||||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
file *file0 = (file*)file0_;
|
||||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
file *file1 = (file*)file1_;
|
||||||
|
|
||||||
char weight = 0;
|
unsigned char *a = file0->file_name;
|
||||||
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
unsigned char *b = file1->file_name;
|
||||||
weight |= 1;
|
|
||||||
}
|
if (file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR) && !(file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR))) {
|
||||||
if (file_type1 == FILE_TYPE_DIR || file_type1 == FILE_TYPE_SYMLINK) {
|
return -1;
|
||||||
weight |= 2;
|
|
||||||
}
|
}
|
||||||
if (weight == 0 || weight == 3) {
|
if (!(file0->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) && file1->file_type & (FILE_TYPE_SYMLINK | FILE_TYPE_DIR)) {
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
} else {
|
|
||||||
if (file_type0 > file_type1) {
|
|
||||||
return 1;
|
return 1;
|
||||||
} else if (file_type0 < file_type1) {
|
}
|
||||||
|
unsigned long num0 = 0;
|
||||||
|
unsigned long num1 = 0;
|
||||||
|
/* bitwise OR a with ' ' turns turns caps into small letters
|
||||||
|
* while doing this on all chars may cause unexpected behaviour on the extended ascii set,
|
||||||
|
* for now i dont care */
|
||||||
|
while ((*a | ' ') == (*b | ' ') && *a != '\0') {
|
||||||
|
if ((*a >= '0') && (*a <= '9')) {
|
||||||
|
while((*a >= '0') && (*a <= '9')) {
|
||||||
|
num0 = (num0 * 10) + (*a - '0');
|
||||||
|
a++;
|
||||||
|
}
|
||||||
|
while((*b >= '0') && (*b <= '9')) {
|
||||||
|
num1 = (num1 * 10) + (*b - '0');
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
if (num0 != num1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
a++;
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (num0 == num1) {
|
||||||
|
if (*a == '\0') {
|
||||||
|
a--;
|
||||||
|
}
|
||||||
|
if (*b == '\0') {
|
||||||
|
b--;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char c0;
|
||||||
|
unsigned char c1;
|
||||||
|
/* in this case we actually check for a through z as otherwise unicode characters get ordered wrongly */
|
||||||
|
if (*a >= 'A' && *a <= 'Z') {
|
||||||
|
c0 = (*a | ' ');
|
||||||
|
} else {
|
||||||
|
c0 = *a;
|
||||||
|
}
|
||||||
|
if (*b >= 'A' && *b <= 'Z') {
|
||||||
|
c1 = (*b | ' ');
|
||||||
|
} else {
|
||||||
|
c1 = *b;
|
||||||
|
}
|
||||||
|
if (c0 > c1) {
|
||||||
|
return 1;
|
||||||
|
} else if (c0 < c1) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
char *file_name0 = ((file*)file0)->file_name;
|
return 0;
|
||||||
char *file_name1 = ((file*)file1)->file_name;
|
|
||||||
return strcasecmp(file_name0, file_name1);
|
|
||||||
}
|
}
|
||||||
|
} else if (num0 > num1) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sort_alpha(const void *file0, const void *file1){
|
int sort_alpha(const void *file0, const void *file1){
|
||||||
|
Reference in New Issue
Block a user