-O2 related refactoring

This commit is contained in:
nova
2025-07-09 01:09:45 +02:00
parent b6f9633677
commit d96046ac44
10 changed files with 136 additions and 95 deletions

View File

@ -6,6 +6,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include "defines.h"
#include "config.h"
@ -47,6 +48,14 @@ extern int (*order_func)();
void FAIL(char *function, char *str){
noraw();
endwin();
curs_set(1);
echo();
printf("ERROR in function %s: %s", function, str);
kill(getpid(),9);
}
void user_interactions() {
@ -208,19 +217,24 @@ void move_up(int passes){
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK);
pthread_mutex_unlock(&mutex_selection);
}
void move_right(int passes){
void move_left(int passes){
if (passes == 0) {
passes++;
}
int i;
for (i = 0; i < passes; i++) {
chdir("..");
if (chdir("..") != 0) {
/* TODO(2025-07-09T00:30:05) fix */
FAIL("move_left", "unhandled error of chdir");
}
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void move_left(){
void move_right(){
if (file_current->file_type == FILE_TYPE_DIR || file_current->file_type == FILE_TYPE_SYMLINK) {
chdir(file_current->file_name);
if (chdir(file_current->file_name) != 0) {
FAIL("move_right", "unhandled error of chdir");
}
} else {
unsigned long i = 0;
char *mime = get_mimetype(file_current->file_name);
@ -235,7 +249,9 @@ void move_left(){
strcpy(btm_buffer, cmd);
system(cmd);
if (system(cmd) == -1) {
/*do nothing*/
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_RELOAD_FULL);
break;
@ -287,7 +303,9 @@ void open_with(){
cmd = concat(cmd, file_current->file_name);
cmd = concat(cmd, "\"");
system(cmd);
if (system(cmd) == -1) {
FAIL("open_with", "creating subcommand failed unhandled");
}
free(btm_buffer);
btm_buffer = cmd;
@ -326,7 +344,9 @@ void rename_hovered(){
cmd = concat(cmd, str);
cmd = concat(cmd, "\"");
system(cmd);
if (system(cmd) == -1) {
FAIL("rename_hovered", "mv or creating subcommand failed");
};
btm_buffer = cmd;
}
@ -374,15 +394,18 @@ void delete(){
char ch = wgetch(win_b);
if (ch == 'y' || ch == 'Y') {
/* the second loop is used to add "./", wich is not being printed" */
char *cmd;
char *cmd = malloc(sizeof(char));
/* TODO(2025-06-30T02:27:06) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
if (hits) {
/* the second loop is used to add "./", wich is not being printed" */
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
free(cmd);
cmd = concat("rm -rf ./\"", mid_content[i].file_name);
cmd = concat(cmd, "\"");
system(cmd);
if (system(cmd) == -1) {
FAIL("delete", "rm -rf or creating subcommand failed");
}
}
}
free(btm_buffer);
@ -391,9 +414,12 @@ void delete(){
free(btm_buffer);
btm_buffer = concat("deleted: \"", file_current->file_name);
btm_buffer = concat(btm_buffer, "\"");
free(cmd);
cmd = concat("rm -rf ./\"", file_current->file_name);
cmd = concat(cmd, "\"");
system(cmd);
if (system(cmd) == -1) {
FAIL("delete", "rm -rf or creating subcommand failed");
}
}
/*system(cmd);*/
@ -469,11 +495,10 @@ void not_implemented(int passes, int index){
}
void jump_to_dir(int passes, int index){
if ((char*)key_binding[index].black_magic) {
chdir(getenv((char*)key_binding[index].black_magic+1));
} else {
chdir((char*)key_binding[index].black_magic);
}
if (chdir(getenv((char*)key_binding[index].black_magic+1)) != 0) {
FAIL("jump_to_dir", "jumping to black_magic in config.h failed");
}
}
status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_MASK | STATUS_RELOAD_DIRECTORY);
}
void order_by(int passes, int index){
@ -520,26 +545,31 @@ void cmd_on_selected(int passes, int index){
if (ch == 'y' || ch == 'Y') {
/* the second loop is used to add "./", wich is not being printed" */
char *cmd;
char *cmd = malloc(sizeof(char));
/* TODO(2025-07-06T07:23:05) IMPORTANT: this really fucks up when the file has a quotation mark in its name */
if (hits) {
for (i = 0; i < mid_file_count; i++) {
if (mid_content[i].status & FILE_STATUS_SELECTED) {
free(cmd);
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, mid_content[i].file_name);
cmd = concat(cmd, "\"");
system(cmd);
free(cmd);
if (system(cmd) != 0) {
/*do nothing*/
}
}
}
free(btm_buffer);
btm_buffer = concat("completed: ", key_binding[index].black_magic);
} else {
free(btm_buffer);
free(cmd);
cmd = concat((char*)key_binding[index].black_magic, " \"");
cmd = concat(cmd, file_current->file_name);
cmd = concat(cmd, "\"");
system(cmd);
if (system(cmd) != 0) {
/*do nothing*/
}
mvaddstr(10,10, cmd);
}