aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-02-23 11:55:29 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-02-23 11:55:29 +0530
commit59a5db2c90a1a46ee6332db8107000fa4d4a4df0 (patch)
tree76bbe4a734e68061ebdbd344f4da6e9037417495
parent5402e1201cfb2c5eb9840987693d19eac1be9469 (diff)
downloadnnn-59a5db2c90a1a46ee6332db8107000fa4d4a4df0.tar.gz
checkpatch fix: refactor run script code
-rw-r--r--src/nnn.c68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/nnn.c b/src/nnn.c
index f8b90d7..d7abbc8 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3851,42 +3851,46 @@ nochange:
goto nochange;
}
- if (S_ISDIR(sb.st_mode)) {
- cfg.runscript ^= 1;
- if (!cfg.runscript && rundir[0]) {
- /*
- * If toggled, and still in the script dir,
- * switch to original directory
- */
- if (strcmp(path, scriptpath) == 0) {
- xstrlcpy(path, rundir, PATH_MAX);
- xstrlcpy(lastname, runfile, NAME_MAX);
- rundir[0] = runfile[0] = '\0';
- setdirwatch();
- goto begin;
- }
- break;
- }
-
- /* Check if directory is accessible */
- if (!xdiraccess(scriptpath))
- goto nochange;
-
- xstrlcpy(rundir, path, PATH_MAX);
- xstrlcpy(path, scriptpath, PATH_MAX);
- if (ndents)
- xstrlcpy(runfile, dents[cur].name, NAME_MAX);
- cfg.runctx = cfg.curctx;
- lastname[0] = '\0';
- setdirwatch();
- goto begin;
- }
-
+ /* Regular script file */
if (S_ISREG(sb.st_mode)) {
tmp = ndents ? dents[cur].name : NULL;
spawn(shell, scriptpath, tmp, path, F_NORMAL | F_SIGINT);
+ break;
}
- break;
+
+ /* Must be a directory or a regular file */
+ if (!S_ISDIR(sb.st_mode))
+ break;
+
+ /* Script directory */
+ cfg.runscript ^= 1;
+ if (!cfg.runscript && rundir[0]) {
+ /*
+ * If toggled, and still in the script dir,
+ * switch to original directory
+ */
+ if (strcmp(path, scriptpath) == 0) {
+ xstrlcpy(path, rundir, PATH_MAX);
+ xstrlcpy(lastname, runfile, NAME_MAX);
+ rundir[0] = runfile[0] = '\0';
+ setdirwatch();
+ goto begin;
+ }
+ break;
+ }
+
+ /* Check if directory is accessible */
+ if (!xdiraccess(scriptpath))
+ goto nochange;
+
+ xstrlcpy(rundir, path, PATH_MAX);
+ xstrlcpy(path, scriptpath, PATH_MAX);
+ if (ndents)
+ xstrlcpy(runfile, dents[cur].name, NAME_MAX);
+ cfg.runctx = cfg.curctx;
+ lastname[0] = '\0';
+ setdirwatch();
+ goto begin;
default: /* SEL_RUNCMD */
#ifndef NORL
if (cfg.picker) {