src/nnn.c | 41 ++++++++++++++++++++++++----------------- diff --git a/src/nnn.c b/src/nnn.c index 1f7c4a37400ab9a82cc7c32f8a3988b519c0b8ec..e4ed61c589e94a35b48d57e9f8073703a25118cb 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1829,6 +1829,13 @@ return NULL; } +static bool getutil(char *util) { + if (!get_output(g_buf, CMD_LEN_MAX, "which", util, NULL, FALSE)) + return FALSE; + + return TRUE; +} + static char *xgetpwuid(uid_t uid) { struct passwd *pwd = getpwuid(uid); @@ -1975,21 +1982,21 @@ return svb.f_bavail << ffs(svb.f_frsize >> 1); } -static int show_mediainfo(char *fpath, char *arg) +static bool show_mediainfo(char *fpath, char *arg) { - if (!get_output(g_buf, CMD_LEN_MAX, "which", utils[cfg.metaviewer], NULL, FALSE)) - return -1; + if (!getutil(utils[cfg.metaviewer])) + return FALSE; exitcurses(); get_output(NULL, 0, utils[cfg.metaviewer], fpath, arg, TRUE); refresh(); - return 0; + return TRUE; } -static int handle_archive(char *fpath, char *arg, char *dir) +static bool handle_archive(char *fpath, char *arg, char *dir) { - if (!get_output(g_buf, CMD_LEN_MAX, "which", utils[ATOOL], NULL, FALSE)) - return -1; + if (!getutil(utils[ATOOL])) + return FALSE; if (arg[1] == 'x') spawn(utils[ATOOL], arg, fpath, dir, F_NORMAL); @@ -1999,7 +2006,7 @@ get_output(NULL, 0, utils[ATOOL], arg, fpath, TRUE); refresh(); } - return 0; + return TRUE; } /* @@ -2953,23 +2960,23 @@ case SEL_EXTRACT: r = handle_archive(newpath, "-x", path); break; case SEL_RUNEDIT: - r = 0; + r = TRUE; spawn(editor, editor_arg, dents[cur].name, path, F_NORMAL); break; case SEL_RUNPAGE: - r = 0; + r = TRUE; spawn(pager, pager_arg, dents[cur].name, path, F_NORMAL); break; case SEL_LOCK: - r = 0; + r = TRUE; spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT); break; default: - r = 0; + r = TRUE; break; } - if (r == -1) { + if (r == FALSE) { printmsg("utility missing"); goto nochange; } @@ -3268,8 +3275,8 @@ spawn(tmp, ptr1, ptr2, path, r); } else if (sel == SEL_ARCHIVE) { /* newpath is used as temporary buffer */ - if (!get_output(newpath, PATH_MAX, "which", utils[APACK], NULL, FALSE)) { - printmsg("apack missing"); + if (!getutil(utils[APACK])) { + printmsg("utility missing"); continue; } @@ -3368,8 +3375,8 @@ close(fd); xstrlcpy(lastname, tmp, NAME_MAX + 1); goto begin; case SEL_RENAMEALL: - if (!get_output(g_buf, CMD_LEN_MAX, "which", utils[VIDIR], NULL, FALSE)) { - printmsg("vidir missing"); + if (!getutil(utils[VIDIR])) { + printmsg("utility missing"); goto nochange; }