aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-02-14 20:53:20 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-02-14 20:55:42 +0530
commitf2c4890d6e170444599f4411190e6912d0ad84de (patch)
tree04406d796b47d3f8f0d6efe3e68797e27a4e943c /src
parent1ed015e988073a04376f3dbf054a0cf50462f3f5 (diff)
downloadnnn-f2c4890d6e170444599f4411190e6912d0ad84de.tar.gz
Polish PR #476
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 077aaa2..4c81286 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -6451,13 +6451,12 @@ int main(int argc, char *argv[])
#ifndef NOMOUSE
mmask_t mask;
#endif
+ const char* const env_opts = xgetenv(env_cfg[NNN_OPTS], NULL);
+ int env_opts_id = env_opts ? (int)strlen(env_opts) : -1;
- const char* const env_opts = xgetenv(env_cfg[NNN_OPTS], NULL);
- int env_opts_idx = (env_opts ? (int)strlen(env_opts) : -1);
- while ((opt = (--env_opts_idx >= 0 ? env_opts[env_opts_idx] : getopt(argc, argv, "aAb:cdeEgHKnop:QrRs:St:vVxh"))) != -1) {
- if (env_opts_idx >= 0) {
- optarg = NULL;
- }
+ while ((opt = (env_opts_id > 0
+ ? env_opts[--env_opts_id]
+ : getopt(argc, argv, "aAb:cdeEgHKnop:QrRs:St:vVxh"))) != -1) {
switch (opt) {
case 'a':
cfg.mtime = 0;
@@ -6502,9 +6501,9 @@ int main(int argc, char *argv[])
cfg.nonavopen = 1;
break;
case 'p':
- if (!optarg) {
+ if (env_opts_id >= 0)
break;
- }
+
cfg.picker = 1;
if (optarg[0] == '-' && optarg[1] == '\0')
cfg.pickraw = 1;
@@ -6534,39 +6533,26 @@ int main(int argc, char *argv[])
cfg.rollover = 0;
break;
case 's':
- if (!optarg) {
- break;
- }
- session = optarg;
+ if (env_opts_id < 0)
+ session = optarg;
break;
case 't':
- if (!optarg) {
- break;
- }
- idletimeout = atoi(optarg);
+ if (env_opts_id < 0)
+ idletimeout = atoi(optarg);
break;
case 'v':
namecmpfn = &xstrverscasecmp;
break;
case 'V':
- if (env_opts_idx >= 0) {
- break;
- }
fprintf(stdout, "%s\n", VERSION);
return _SUCCESS;
case 'x':
cfg.x11 = 1;
break;
case 'h':
- if (env_opts_idx >= 0) {
- break;
- }
usage();
return _SUCCESS;
default:
- if (env_opts_idx >= 0) {
- fprintf(stderr, "Error: Illegal option '%c' in env var '%s'\n\n", opt, env_cfg[NNN_OPTS]);
- }
usage();
return _FAILURE;
}