Two copy modes are exclusive

This commit is contained in:
Arun Prakash Jana 2018-04-17 02:22:23 +05:30
parent f652a4fecb
commit ebb4725204
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 42 additions and 44 deletions

86
nnn.c
View File

@ -305,7 +305,7 @@ static const char messages[][16] =
"HOME not set", "HOME not set",
"no traversal", "no traversal",
"invalid key", "invalid key",
"set NNN_COPIER", "set copy method",
"%F %T %z", "%F %T %z",
}; };
@ -2980,7 +2980,9 @@ nochange:
copycurname(); copycurname();
goto begin; goto begin;
case SEL_COPY: case SEL_COPY:
if (copier && ndents) { if (!(cfg.noxdisplay || copier))
printmsg(messages[STR_COPY_ID]);
else if (ndents) {
if (cfg.copymode) { if (cfg.copymode) {
r = mkpath(path, dents[cur].name, newpath, PATH_MAX); r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
if (!appendfilepath(newpath, r)) if (!appendfilepath(newpath, r))
@ -3007,58 +3009,54 @@ nochange:
spawn(copier, newpath, NULL, NULL, F_NOTRACE); spawn(copier, newpath, NULL, NULL, F_NOTRACE);
printmsg(newpath); printmsg(newpath);
} }
} else if (!copier) }
printmsg(messages[STR_COPY_ID]);
goto nochange; goto nochange;
case SEL_COPYMUL: case SEL_COPYMUL:
if (!copier) { if (!(cfg.noxdisplay || copier))
printmsg(messages[STR_COPY_ID]); printmsg(messages[STR_COPY_ID]);
goto nochange; else if (ndents) {
} else if (!ndents) { cfg.copymode ^= 1;
goto nochange; if (cfg.copymode) {
} g_crc = crc8fast((uchar *)dents, ndents * sizeof(struct entry));
copystartid = cur;
copybufpos = 0;
printmsg("multi-copy on");
DPRINTF_S("copymode on");
} else {
static size_t len;
len = 0;
cfg.copymode ^= 1; /* Handle range selection */
if (cfg.copymode) { if (copybufpos == 0) {
g_crc = crc8fast((uchar *)dents, ndents * sizeof(struct entry));
copystartid = cur;
copybufpos = 0;
printmsg("multi-copy on");
DPRINTF_S("copymode on");
} else {
static size_t len;
len = 0;
/* Handle range selection */ if (cur < copystartid) {
if (copybufpos == 0) { copyendid = copystartid;
copystartid = cur;
} else
copyendid = cur;
if (cur < copystartid) { if (copystartid < copyendid) {
copyendid = copystartid; for (r = copystartid; r <= copyendid; ++r) {
copystartid = cur; len = mkpath(path, dents[r].name, newpath, PATH_MAX);
} else if (!appendfilepath(newpath, len))
copyendid = cur; goto nochange;;
}
if (copystartid < copyendid) { snprintf(newpath, PATH_MAX, "%d files copied", copyendid - copystartid + 1);
for (r = copystartid; r <= copyendid; ++r) { printmsg(newpath);
len = mkpath(path, dents[r].name, newpath, PATH_MAX);
if (!appendfilepath(newpath, len))
goto nochange;;
} }
snprintf(newpath, PATH_MAX, "%d files copied", copyendid - copystartid + 1);
printmsg(newpath);
} }
}
if (copybufpos) { if (copybufpos) {
if (cfg.noxdisplay) if (cfg.noxdisplay)
writecp(pcopybuf, copybufpos - 1); /* Truncate NULL from end */ writecp(pcopybuf, copybufpos - 1); /* Truncate NULL from end */
else else
spawn(copier, pcopybuf, NULL, NULL, F_NOTRACE); spawn(copier, pcopybuf, NULL, NULL, F_NOTRACE);
if (!len) if (!len)
printmsg("files copied"); printmsg("files copied");
} else } else
printmsg("multi-copy off"); printmsg("multi-copy off");
}
} }
goto nochange; goto nochange;
case SEL_QUOTE: case SEL_QUOTE: