From fd2bb01b96e2bb5262e09eac997e9c7e2ae380e1 Mon Sep 17 00:00:00 2001 From: nova Date: Thu, 25 Jun 2026 00:25:25 +0200 Subject: [PATCH] cleanup --- defines.h | 4 ++++ interactions.c | 49 ++++++++++++++++++++++--------------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/defines.h b/defines.h index 36a3dae..9bd9b9b 100644 --- a/defines.h +++ b/defines.h @@ -63,6 +63,10 @@ #define BTM_WINDOW_HEIGHT_ON_STR_INTERACTION 5 #define INPUT_BUFFER_SIZE 255 +#define ignore_return(in) if (in) { }; +#define unused(in) (void)(in); + + #ifndef STRUCT_GUARD #define STRUCT_GUARD /* complex types are good actually */ diff --git a/interactions.c b/interactions.c index 762fe25..70079fb 100644 --- a/interactions.c +++ b/interactions.c @@ -202,8 +202,7 @@ void move_right(){ change_dir(mid_dir.current_file->file_name); } else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) { char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file); - if (system(cmd)) { - } + ignore_return(system(cmd)); } else { char *mime = get_mimetype(mid_dir.current_file); char *extension = mid_dir.current_file->file_name; @@ -223,14 +222,13 @@ void move_right(){ cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file); pid_t pid = fork(); if (pid == 0 && setsid()) { - system(cmd); + ignore_return(system(cmd)); status = STATUS_QUIT_PROGRAM; exit(1); } } else { cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file); - if (system(cmd)) { - } + ignore_return(system(cmd)); } status |= STATUS_MOVE_RIGHT_MATCH; update(); @@ -245,14 +243,13 @@ void move_right(){ cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file); pid_t pid = fork(); if (pid == 0 && setsid()) { - system(cmd); + ignore_return(system(cmd)); status = STATUS_QUIT_PROGRAM; exit(1); } } else { cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file); - if (system(cmd)) { - } + ignore_return(system(cmd)); } status |= STATUS_MOVE_RIGHT_MATCH; update(); @@ -299,14 +296,13 @@ void open_with(){ cmd = parse_cmd(str+1, mid_dir.current_file); pid_t pid = fork(); if (pid == 0 && setsid()) { - system(cmd); + ignore_return(system(cmd)); status = STATUS_QUIT_PROGRAM; exit(1); } } else { cmd = parse_cmd(str, mid_dir.current_file); - if (system(cmd)) { - } + ignore_return(system(cmd)); } free(cmd); } @@ -325,7 +321,7 @@ void rename_hovered(){ if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) { char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file); char *cmd1 = parse_cmd(cmd0, &tmp); - system(cmd1); + ignore_return(system(cmd1)); free(cmd0); free(cmd1); } @@ -343,7 +339,7 @@ void delete(unsigned long passes){ for (i = 0; i < mid_dir.file_count; i++) { if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) { cmd = parse_cmd(del_cmd, &mid_dir.file_list[i]); - system(cmd); + ignore_return(system(cmd)); free(cmd); del_count++; } @@ -355,7 +351,7 @@ void delete(unsigned long passes){ break; } cmd = parse_cmd(del_cmd, &mid_dir.current_file[i]); - system(cmd); + ignore_return(system(cmd)); free(cmd); } } @@ -369,7 +365,7 @@ void makedir(){ mvwprintw(win_b, 0, 0, ui_makedir_text); if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) { char *cmd = parse_cmd(makedir_cmd, &tmp); - system(cmd); + ignore_return(system(cmd)); free(cmd); } free(tmp.file_name); @@ -383,7 +379,7 @@ void makefile(){ mvwprintw(win_b, 0, 0, ui_makefile_text); if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) { char *cmd = parse_cmd(makefile_cmd, &tmp); - system(cmd); + ignore_return(system(cmd)); free(cmd); } free(tmp.file_name); @@ -391,13 +387,12 @@ void makefile(){ status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); } void enter_shell(unsigned long passes, int index){ - (void)passes; /*remove compiler warning*/ + unused(passes); endwin();\ echo();\ curs_set(1);\ - if (system(key_binding[index].black_magic)) { - } + ignore_return(system(key_binding[index].black_magic)); initscr(); /* start ncurses */ noecho(); /* hide keyboard input */ curs_set(0); @@ -405,7 +400,7 @@ void enter_shell(unsigned long passes, int index){ status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); } void jump_to_dir(unsigned long passes, int index){ - (void)passes; + unused(passes); unsigned long len; char *c = strchr(key_binding[index].black_magic, '/'); @@ -434,7 +429,7 @@ void jump_to_dir(unsigned long passes, int index){ status |= (STATUS_RUN_BACKEND | STATUS_UPDATE_SCREEN_CLEAR | STATUS_RELOAD_DIRECTORY ); } void order_by(unsigned long passes, int index){ - (void)passes; + unused(passes); seed = time(NULL); order_func = key_binding[index].black_magic; @@ -442,17 +437,17 @@ void order_by(unsigned long passes, int index){ status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY); } void cmd_on_selected(unsigned long passes, int index){ - (void)passes; + unused(passes); char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file); - system(cmd); + ignore_return(system(cmd)); free(cmd); status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR); } void yank_file_name(){ char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file); - system(cmd); + ignore_return(system(cmd)); free(cmd); status |= (STATUS_RUN_BACKEND); @@ -464,7 +459,7 @@ void yank_file_path(){ memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1); tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/ char *cmd = parse_cmd(clipboard_cmd, tmp); - system(cmd); + ignore_return(system(cmd)); free(cmd); free(tmp->file_name); free(tmp); @@ -472,7 +467,7 @@ void yank_file_path(){ status |= (STATUS_RUN_BACKEND); } void copy_file(unsigned long passes, int index){ - (void)passes; + unused(passes); yank_files.status = key_binding[index].black_magic; @@ -558,7 +553,7 @@ void paste(unsigned long passes){ } tmp.file_name = dest_file_name; cmd = parse_cmd(cmd, &tmp); - system(cmd); + ignore_return(system(cmd)); free(cmd); free(tmp.file_name); }