Minor code refactor

This commit is contained in:
Arun Prakash Jana 2019-12-10 08:52:00 +05:30
parent 847bda4380
commit e8183058fd
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 37 additions and 34 deletions

View File

@ -440,23 +440,22 @@ static char * const utils[] = {
#define MSG_COPY_NAME 23 #define MSG_COPY_NAME 23
#define MSG_CONTINUE 24 #define MSG_CONTINUE 24
#define MSG_SEL_MISSING 25 #define MSG_SEL_MISSING 25
#define MSG_SSN_MISSING 26 #define MSG_ACCESS 26
#define MSG_DIR_ACCESS 27 #define MSG_0_CREATED 27
#define MSG_0_CREATED 28 #define MSG_NOT_REG_FILE 28
#define MSG_NOT_REG_FILE 29 #define MSG_PERM_DENIED 29
#define MSG_PERM_DENIED 30 #define MSG_EMPTY_FILE 30
#define MSG_EMPTY_FILE 31 #define MSG_UNSUPPORTED 31
#define MSG_UNSUPPORTED 32 #define MSG_NOT_SET 32
#define MSG_NOT_SET 33 #define MSG_RANGE_SEL_ON 33
#define MSG_RANGE_SEL_ON 34 #define MSG_DIR_CHANGED 34
#define MSG_DIR_CHANGED 35 #define MSG_0_FILES 35
#define MSG_0_FILES 36 #define MSG_EXISTS 36
#define MSG_EXISTS 37 #define MSG_FEW_COLOUMNS 37
#define MSG_FEW_COLOUMNS 38 #define MSG_REMOTE_OPTS 38
#define MSG_REMOTE_OPTS 39 #define MSG_RCLONE_DELAY 39
#define MSG_RCLONE_DELAY 40 #define MSG_APP_NAME 40
#define MSG_APP_NAME 41 #define MSG_ARCHIVE_OPTS 41
#define MSG_ARCHIVE_OPTS 42
static const char * const messages[] = { static const char * const messages[] = {
"no traversal", "no traversal",
@ -484,8 +483,7 @@ static const char * const messages[] = {
"link suffix [@ for none]: ", "link suffix [@ for none]: ",
"copy name: ", "copy name: ",
"\nPress Enter to continue", "\nPress Enter to continue",
"sel file missing", "open failed",
"session file missing",
"dir inaccessible", "dir inaccessible",
"0 created", "0 created",
"not regular file", "not regular file",
@ -2891,7 +2889,7 @@ static void save_session(bool last_session, int *presel)
fsession = fopen(spath, "wb"); fsession = fopen(spath, "wb");
if (!fsession) { if (!fsession) {
printwait(messages[MSG_SSN_MISSING], presel); printwait(messages[MSG_ACCESS], presel);
return; return;
} }
@ -2944,7 +2942,7 @@ static bool load_session(const char *sname, char **path, char **lastdir, char **
fsession = fopen(spath, "rb"); fsession = fopen(spath, "rb");
if (!fsession) { if (!fsession) {
printmsg(messages[MSG_SSN_MISSING]); printmsg(messages[MSG_ACCESS]);
xdelay(XDELAY_INTERVAL_MS); xdelay(XDELAY_INTERVAL_MS);
return FALSE; return FALSE;
} }
@ -3223,7 +3221,7 @@ static void find_accessible_parent(char *path, char *newpath, char *lastname, in
xstrlcpy(path, dir, PATH_MAX); xstrlcpy(path, dir, PATH_MAX);
printmsg(messages[MSG_DIR_ACCESS]); printmsg(messages[MSG_ACCESS]);
xdelay(XDELAY_INTERVAL_MS); xdelay(XDELAY_INTERVAL_MS);
} }
@ -3636,6 +3634,22 @@ static bool run_selected_plugin(char **path, const char *file, char *newpath, ch
return TRUE; return TRUE;
} }
static void launch_app(const char *path, char *newpath)
{
int r = F_NORMAL;
char *tmp = newpath;
mkpath(plugindir, utils[UTIL_LAUNCH], newpath);
if (!(getutil(utils[UTIL_FZF]) || getutil(utils[UTIL_FZY])) || access(newpath, X_OK) < 0) {
tmp = xreadline(NULL, messages[MSG_APP_NAME]);
r = F_NOWAIT | F_NOTRACE | F_MULTI;
}
if (tmp && *tmp) // NOLINT
spawn(tmp, "0", NULL, path, r);
}
static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{ {
(void) fpath; (void) fpath;
@ -5253,18 +5267,7 @@ nochange:
setdirwatch(); setdirwatch();
goto begin; goto begin;
case SEL_LAUNCH: case SEL_LAUNCH:
mkpath(plugindir, utils[UTIL_LAUNCH], newpath); launch_app(path, newpath);
if ((getutil(utils[UTIL_FZF]) || getutil(utils[UTIL_FZY]))
&& access(newpath, X_OK) == 0) {
tmp = newpath;
r = F_NORMAL;
} else {
tmp = xreadline(NULL, messages[MSG_APP_NAME]);
r = F_NOWAIT | F_NOTRACE | F_MULTI;
}
if (tmp && *tmp) // NOLINT
spawn(tmp, "0", NULL, path, r);
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;