From ebb6f153b51332ce2b64b3e717ea956484749d4c Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 3 May 2020 16:16:14 +0530 Subject: Context code '+' to create context smartly --- src/nnn.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nnn.c b/src/nnn.c index d9a20df..5e215d7 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -4234,16 +4234,24 @@ static void rmlistpath() static void readpipe(int fd, char **path, char **lastname, char **lastdir) { - char *nextpath = NULL; + int r; + char ctx, *nextpath = NULL; ssize_t len = read(fd, g_buf, 1); if (len != 1) return; - char ctx = g_buf[0] - '0'; - - if (ctx > CTX_MAX) - return; + if (g_buf[0] == '+') { + r = cfg.curctx; + do + r = (r + 1) & ~CTX_MAX; + while (g_ctx[r].c_cfg.ctxactive && (r != cfg.curctx)); + ctx = r + 1; + } else { + ctx = g_buf[0] - '0'; + if (ctx > CTX_MAX) + return; + } len = read(fd, g_buf, 1); if (len != 1) @@ -4269,7 +4277,7 @@ static void readpipe(int fd, char **path, char **lastname, char **lastdir) xstrsncpy(*lastdir, *path, PATH_MAX); xstrsncpy(*path, nextpath, PATH_MAX); } else { - int r = ctx - 1; + r = ctx - 1; g_ctx[r].c_cfg.ctxactive = 0; savecurctx(&cfg, nextpath, dents[cur].name, r); -- cgit v1.2.3-70-g09d2