Add function for 'which utility'

This commit is contained in:
Arun Prakash Jana 2018-12-08 09:44:08 +05:30
parent 674a58880d
commit 1a29b4ef36
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

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