Refactor set_time_type()

This commit is contained in:
Arun Prakash Jana 2020-04-14 22:38:33 +05:30
parent e0cdbcb521
commit 30a6caf8bc
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -615,12 +615,6 @@ static const char * const envs[] = {
#define T_CHANGE 1 #define T_CHANGE 1
#define T_MOD 2 #define T_MOD 2
static const char * const time_type[] = {
"'a'ccess",
"'c'hange",
"'m'od",
};
#ifdef __linux__ #ifdef __linux__
static char cp[] = "cp -iRp"; static char cp[] = "cp -iRp";
static char mv[] = "mv -i"; static char mv[] = "mv -i";
@ -4784,43 +4778,31 @@ static int set_sort_flags(int r)
static bool set_time_type(int *presel) static bool set_time_type(int *presel)
{ {
char buf[24]; bool ret = FALSE;
bool first = TRUE; char buf[] = "'a'ccess / 'c'hange / 'm'od [ ]";
int r = 0;
size_t chars = 0;
for (; r < (int)ELEMENTS(time_type); ++r) buf[sizeof(buf) - 3] = cfg.timetype == T_MOD ? 'm' : (cfg.timetype == T_ACCESS ? 'a' : 'c');
if (r != cfg.timetype) {
chars += xstrsncpy(buf + chars, time_type[r], sizeof(buf) - chars) - 1; int r = get_input(buf);
if (first) {
buf[chars++] = ' ';
buf[chars++] = '/';
buf[chars++] = ' ';
first = FALSE;
} else {
buf[chars++] = '?';
buf[chars] = '\n';
}
}
r = get_input(buf);
if (r == 'a' || r == 'c' || r == 'm') { if (r == 'a' || r == 'c' || r == 'm') {
r = (r == 'm') ? T_MOD : ((r == 'a') ? T_ACCESS : T_CHANGE); r = (r == 'm') ? T_MOD : ((r == 'a') ? T_ACCESS : T_CHANGE);
if (cfg.timetype == r) { if (cfg.timetype != r) {
printwait(messages[MSG_NOCHNAGE], presel); cfg.timetype = r;
return FALSE;
}
cfg.timetype = r; if (cfg.filtermode || g_ctx[cfg.curctx].c_fltr[1])
*presel = FILTER;
if (cfg.filtermode || g_ctx[cfg.curctx].c_fltr[1]) ret = TRUE;
*presel = FILTER; } else
r = MSG_NOCHNAGE;
} else
r = MSG_INVALID_KEY;
return TRUE; if (!ret)
} printwait(messages[r], presel);
printwait(messages[MSG_INVALID_KEY], presel); return ret;
return FALSE;
} }
static void statusbar(char *path) static void statusbar(char *path)