static char *home;
static char *initpath;
static char *cfgdir;
-static char *g_cppath;
+static char *g_selpath;
static char *plugindir;
static char *pnamebuf, *pselbuf;
static struct entry *dents;
{
exitcurses();
perror(xitoa(linenum));
- if (!cfg.picker && g_cppath)
- unlink(g_cppath);
+ if (!cfg.picker && g_selpath)
+ unlink(g_selpath);
free(pselbuf);
exit(1);
}
}
/* Writes buflen char(s) from buf to a file */
-static void writecp(const char *buf, const size_t buflen)
+static void writesel(const char *buf, const size_t buflen)
{
- if (cfg.pickraw || !g_cppath)
+ if (cfg.pickraw || !g_selpath)
return;
- FILE *fp = fopen(g_cppath, "w");
+ FILE *fp = fopen(g_selpath, "w");
if (fp) {
if (fwrite(buf, 1, buflen, fp) != buflen)
printwarn(NULL);
}
/* Write selected file paths to fd, linefeed separated */
-static size_t selectiontofd(int fd, uint *pcount)
+static size_t seltofile(int fd, uint *pcount)
{
uint lastpos, count = 0;
char *pbuf = pselbuf;
}
/* List selection from selection buffer */
-static bool showcplist(void)
+static bool listselbuf(void)
{
int fd;
size_t pos;
return FALSE;
}
- pos = selectiontofd(fd, NULL);
+ pos = seltofile(fd, NULL);
close(fd);
if (pos && pos == selbufpos)
}
/* List selection from selection file (another instance) */
-static bool showcpfile(void)
+static bool listselfile(void)
{
struct stat sb;
- if (stat(g_cppath, &sb) == -1)
+ if (stat(g_selpath, &sb) == -1)
return FALSE;
/* Nothing selected if file size is 0 */
if (!sb.st_size)
return FALSE;
- snprintf(g_buf, CMD_LEN_MAX, "cat %s | tr \'\\0\' \'\\n\'", g_cppath);
+ snprintf(g_buf, CMD_LEN_MAX, "cat %s | tr \'\\0\' \'\\n\'", g_selpath);
spawn("sh", "-c", g_buf, NULL, F_NORMAL | F_CMD);
return TRUE;
}
-static bool cpsafe(void)
+static bool selsafe(void)
{
/* Fail if selection file path not generated */
- if (!g_cppath) {
+ if (!g_selpath) {
printmsg("selection file not found");
return FALSE;
}
}
/* Fail if selection file path isn't accessible */
- if (access(g_cppath, R_OK | W_OK) == -1) {
+ if (access(g_selpath, R_OK | W_OK) == -1) {
errno == ENOENT ? printmsg(messages[NONE_SELECTED]) : printwarn(NULL);
return FALSE;
}
}
/* Reset selection indicators */
-static void resetcpind(void)
+static void resetselind(void)
{
int r = 0;
{
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
- "xargs -0 -a %s -%c {} %s {} .", g_cppath, REPLACE_STR, cp);
+ "xargs -0 -a %s -%c {} %s {} .", g_selpath, REPLACE_STR, cp);
#else
- "cat %s | xargs -0 -o -%c {} cp -iRp {} .", g_cppath, REPLACE_STR);
+ "cat %s | xargs -0 -o -%c {} cp -iRp {} .", g_selpath, REPLACE_STR);
#endif
}
{
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
- "xargs -0 -a %s -%c {} %s {} .", g_cppath, REPLACE_STR, mv);
+ "xargs -0 -a %s -%c {} %s {} .", g_selpath, REPLACE_STR, mv);
#else
- "cat %s | xargs -0 -o -%c {} mv -i {} .", g_cppath, REPLACE_STR);
+ "cat %s | xargs -0 -o -%c {} mv -i {} .", g_selpath, REPLACE_STR);
#endif
}
if (cfg.trash) {
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
- "xargs -0 -a %s trash-put", g_cppath);
+ "xargs -0 -a %s trash-put", g_selpath);
#else
- "cat %s | xargs -0 trash-put", g_cppath);
+ "cat %s | xargs -0 trash-put", g_selpath);
#endif
} else {
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
- "xargs -0 -a %s rm -%cr", g_cppath, confirm_force());
+ "xargs -0 -a %s rm -%cr", g_selpath, confirm_force());
#else
- "cat %s | xargs -0 -o rm -%cr", g_cppath, confirm_force());
+ "cat %s | xargs -0 -o rm -%cr", g_selpath, confirm_force());
#endif
}
}
for (i = 0; i < ndents; ++i)
appendfpath(dents[i].name, NAME_MAX);
- selectiontofd(fd1, &count);
- selectiontofd(fd2, NULL);
+ seltofile(fd1, &count);
+ seltofile(fd2, NULL);
close(fd2);
if (dir) /* Don't retain dir entries in selection */
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
- "sed -ze 's|^%s/||' '%s' | xargs -0 %s %s", curpath, g_cppath, cmd, archive);
+ "sed -ze 's|^%s/||' '%s' | xargs -0 %s %s", curpath, g_selpath, cmd, archive);
#else
"cat '%s' | tr '\\0' '\n' | sed -e 's|^%s/||' | tr '\n' '\\0' | xargs -0 %s %s",
- g_cppath, curpath, cmd, archive);
+ g_selpath, curpath, cmd, archive);
#endif
spawn("sh", "-c", buf, curpath, F_NORMAL);
free(buf);
dprintf(fd, "%s: %s\n", env_cfg[i], start);
}
- if (g_cppath)
- dprintf(fd, "SELECTION FILE: %s\n", g_cppath);
+ if (g_selpath)
+ dprintf(fd, "SELECTION FILE: %s\n", g_selpath);
dprintf(fd, "\nv%s\n%s\n", VERSION, GENERAL_INFO);
close(fd);
if (cfg.picker && sel == SEL_GOIN) {
r = mkpath(path, dents[cur].name, newpath);
appendfpath(newpath, r);
- writecp(pselbuf, selbufpos - 1);
+ writesel(pselbuf, selbufpos - 1);
return;
}
* the temporary selection file.
*/
if (!nselected)
- writecp(NULL, 0);
+ writesel(NULL, 0);
/* Do not select if already selected */
if (!(dents[cur].flags & FILE_SELECTED)) {
r = mkpath(path, dents[cur].name, newpath);
if (selbufpos) {
- resetcpind();
+ resetselind();
/* Keep the selection buffer in sync */
selbufpos = 0;
}
appendfpath(newpath, r);
- writecp(newpath, r - 1); /* Truncate NULL from end */
+ writesel(newpath, r - 1); /* Truncate NULL from end */
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
nselected = 1;
cfg.selmode ^= 1;
if (cfg.selmode) {
if (selbufpos) {
- resetcpind();
- writecp(NULL, 0);
+ resetselind();
+ writesel(NULL, 0);
selbufpos = 0;
}
g_crc = crc8fast((uchar *)dents, ndents * sizeof(struct entry));
}
if (selbufpos) { /* File path(s) written to the buffer */
- writecp(pselbuf, selbufpos - 1); /* Truncate NULL from end */
+ writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
if (nselected) { /* Some files cherry picked */
}
continue;
case SEL_SELLST:
- if (showcplist() || showcpfile()) {
+ if (listselbuf() || listselfile()) {
if (cfg.filtermode)
presel = FILTER;
break;
case SEL_MV:
case SEL_RMMUL:
{
- if (!cpsafe()) {
+ if (!selsafe()) {
presel = MSGWAIT;
goto nochange;
}
case SEL_ARCHIVE:
r = get_input("archive selection (else current)? [y/Y confirms]");
if (r == 'y' || r == 'Y') {
- if (!cpsafe()) {
+ if (!selsafe()) {
presel = MSGWAIT;
goto nochange;
}
if (cfg.picker) {
/* Picker mode: reset buffer or clear file */
if (selbufpos)
- cfg.pickraw ? selbufpos = 0 : writecp(NULL, 0);
+ cfg.pickraw ? selbufpos = 0 : writesel(NULL, 0);
} else if (!write_lastdir(path)) {
presel = MSGWAIT;
goto nochange;
/* Set selection file path */
if (!cfg.picker) {
/* Length of "/.config/nnn/.selection" */
- g_cppath = (char *)malloc(len + 3);
- r = xstrlcpy(g_cppath, cfgdir, len + 3);
- xstrlcpy(g_cppath + r - 1, "/.selection", 12);
- DPRINTF_S(g_cppath);
+ g_selpath = (char *)malloc(len + 3);
+ r = xstrlcpy(g_selpath, cfgdir, len + 3);
+ xstrlcpy(g_selpath + r - 1, "/.selection", 12);
+ DPRINTF_S(g_selpath);
}
return TRUE;
static void cleanup(void)
{
- free(g_cppath);
+ free(g_selpath);
free(plugindir);
free(cfgdir);
free(initpath);
}
close(fd);
- g_cppath = realpath(optarg, NULL);
- unlink(g_cppath);
+ g_selpath = realpath(optarg, NULL);
+ unlink(g_selpath);
}
break;
case 'r':
if (cfg.pickraw) {
if (selbufpos) {
- opt = selectiontofd(1, NULL);
+ opt = seltofile(1, NULL);
if (opt != (int)(selbufpos))
xerror();
}
- } else if (!cfg.picker && g_cppath)
- unlink(g_cppath);
+ } else if (!cfg.picker && g_selpath)
+ unlink(g_selpath);
/* Free the selection buffer */
free(pselbuf);