This commit is contained in:
nova
2026-06-16 22:22:29 +02:00
parent d8b3706f64
commit f88b86c1f5
3 changed files with 23 additions and 71 deletions
-34
View File
@@ -380,37 +380,3 @@ void dir_init(){
current_linked_dir = list_beginning; current_linked_dir = list_beginning;
} }
void recursive_delete(file current_file){
/*
if (S_ISLNK(current_file.permissions)) {
remove(current_file.file_name);
} else if (current_file.file_type & FILE_TYPE_DIR ) {
unsigned int file_modifiers_tmp = file_modifiers;
file_modifiers |= FILE_MODIFIERS_HIDDEN_FILES;
unsigned long current_file_count = get_dir_size(current_file.file_name);
if (current_file_count != 0) {
file *current_dir = malloc(current_file_count * sizeof(file));
memset(current_dir, '\0', current_file_count * sizeof(file));
get_dir_content(current_file.file_name, &current_file_count, current_dir);
if (chdir(current_file.file_name) != 0) {
return;
}
unsigned long i;
for (i = 0; i < current_file_count; i++) {
recursive_delete(current_dir[i]);
free(current_dir[i].file_name);
}
free(current_dir);
if (chdir("..") != 0) {
return;
}
}
remove(current_file.file_name);
file_modifiers = file_modifiers_tmp;
} else {
remove(current_file.file_name);
}
*/
}
-1
View File
@@ -10,4 +10,3 @@ 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();
void recursive_delete(file current_file);
+23 -36
View File
@@ -41,10 +41,7 @@ yank yank_files = { 0 };
printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\ printf("TODO: %s at %d in %s \n", __func__, __LINE__, __FILE__);\
exit(1); exit(1);
void FAIL(char *function, char *str){ #define skip_if_empty_dir \
printf("ERROR in function %s: %s", function, str);
}
#define continue_if_empty_dir \
if (mid_dir.current_file == NULL) { \ if (mid_dir.current_file == NULL) { \
return; \ return; \
} }
@@ -126,7 +123,6 @@ int read_string(WINDOW *win, int y, int x, char *str){
wmove(win, y, x); wmove(win, y, x);
while(1) { while(1) {
/*ch = mvwgetch(win, y, x + pass);*/
ch = wgetch(win); ch = wgetch(win);
if (ch == '\n') { if (ch == '\n') {
err = 0; err = 0;
@@ -170,7 +166,7 @@ void select_all(){
} }
void move_down(unsigned long passes){ void move_down(unsigned long passes){
continue_if_empty_dir; skip_if_empty_dir;
mid_dir.current_file += passes; mid_dir.current_file += passes;
if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) { if (mid_dir.current_file > mid_dir.file_list + mid_dir.file_count - 1) {
@@ -181,7 +177,7 @@ void move_down(unsigned long passes){
} }
void move_up(unsigned long passes){ void move_up(unsigned long passes){
continue_if_empty_dir; skip_if_empty_dir;
mid_dir.current_file -= passes; mid_dir.current_file -= passes;
if (mid_dir.current_file < mid_dir.file_list) { if (mid_dir.current_file < mid_dir.file_list) {
@@ -200,7 +196,7 @@ void move_left(unsigned long passes){
} }
void move_right(){ void move_right(){
continue_if_empty_dir skip_if_empty_dir
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) { if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
change_dir(mid_dir.current_file->file_name); change_dir(mid_dir.current_file->file_name);
@@ -340,7 +336,6 @@ void delete(unsigned long passes){
unsigned long i; unsigned long i;
unsigned long del_count = 0; unsigned long del_count = 0;
file tmp;
char *cmd; char *cmd;
for (i = 0; i < mid_dir.file_count; i++) { for (i = 0; i < mid_dir.file_count; i++) {
@@ -406,14 +401,6 @@ void enter_shell(unsigned long passes, int index){
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
} }
void not_implemented(unsigned long passes, int index){
(void)passes;
mvaddstr(terminal_height-1, 0, key_binding[index].comment);
mvaddstr(terminal_height-1, strlen(key_binding[index].comment), "\t");
mvaddstr(terminal_height-1, strlen(key_binding[index].comment) + strlen("\t"), "is not yet implemented");
TODO;
}
void jump_to_dir(unsigned long passes, int index){ void jump_to_dir(unsigned long passes, int index){
(void)passes; (void)passes;
@@ -600,13 +587,14 @@ void search(){
unsigned int pass = 0; unsigned int pass = 0;
char ch; char ch;
char err = 0;
wmove(win_b, 0, 1); wmove(win_b, 0, 1);
while(1) { while(1) {
ch = wgetch(win_b); ch = wgetch(win_b);
if (ch == '\n') { if (ch == '\n' || ch == 27 /* esc key */) {
err = 0; /* unlike the other uses of a read string reimplementation,
* here we do not differentiate between accepting and cancle.
* this is intentional */
break; break;
} else if (ch == '\t') { /* tab */ } else if (ch == '\t') { /* tab */
memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)); memcpy(search_buffer + pass, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name));
@@ -617,9 +605,6 @@ void search(){
pass--; pass--;
mvwdelch(win_b, 0, pass+1); mvwdelch(win_b, 0, pass+1);
} }
} else if (ch == 27) { /* esc key */
err = 1;
break;
} }
if (ch) { if (ch) {
mvwaddch(win_b, 0, pass+1, ch); mvwaddch(win_b, 0, pass+1, ch);
@@ -627,7 +612,6 @@ void search(){
pass++; pass++;
unsigned long index = (mid_dir.current_file - mid_dir.file_list); unsigned long index = (mid_dir.current_file - mid_dir.file_list);
unsigned long x = getmaxx(win_b);
for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) { for (; &mid_dir.file_list[index] < mid_dir.file_list + mid_dir.file_count; index++) {
if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) { if (smartstrcasestr(mid_dir.file_list[index].file_name, search_buffer)) {
mid_dir.current_file = &mid_dir.file_list[index]; mid_dir.current_file = &mid_dir.file_list[index];
@@ -675,7 +659,13 @@ void search_previous(){
status |= (STATUS_RUN_BACKEND); status |= (STATUS_RUN_BACKEND);
} }
void jmp_file_index(){ void jmp_file_index(){
echo();
char ch;
char err = 0;
char number_buffer[INPUT_BUFFER_SIZE];
char *num = number_buffer;
unsigned long i; unsigned long i;
for (i = 0; i < terminal_width -1; i++) { for (i = 0; i < terminal_width -1; i++) {
mvwaddch(win_b, 0, i, ' '); mvwaddch(win_b, 0, i, ' ');
@@ -685,14 +675,8 @@ void jmp_file_index(){
curs_set(1); curs_set(1);
echo(); echo();
timeout(-1); /* negative numbers block until enter is pressed */ timeout(-1); /* negative numbers block until enter is pressed */
unsigned int pass = 0;
char ch;
char err = 0;
char number_buffer[INPUT_BUFFER_SIZE];
char *num = number_buffer;
wmove(win_b, 0, 1); wmove(win_b, 0, 1);
while(1) { while(1) {
@@ -704,6 +688,7 @@ void jmp_file_index(){
} else if (ch == '\n') { } else if (ch == '\n') {
break; break;
} else if (ch == 27) { /* esc key */ } else if (ch == 27) { /* esc key */
err = 1;
break; break;
} else if (ch == 127) { /* backspace */ } else if (ch == 127) { /* backspace */
num--; num--;
@@ -715,12 +700,14 @@ void jmp_file_index(){
*num = 0; *num = 0;
num = number_buffer; num = number_buffer;
unsigned long parsed_number = 0; if (err == 0) {
while(*num) { unsigned long parsed_number = 0;
parsed_number = (parsed_number * 10) + (*num - '0'); while(*num) {
num++; parsed_number = (parsed_number * 10) + (*num - '0');
num++;
}
mid_dir.current_file = &mid_dir.file_list[parsed_number];
} }
mid_dir.current_file = &mid_dir.file_list[parsed_number];
noecho(); noecho();
curs_set(0); curs_set(0);