Reduce indentation level, simpler boolean checks

This commit is contained in:
Arun Prakash Jana 2018-09-02 21:19:58 +05:30
parent 7d065ff22d
commit ad7c644290
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 62 additions and 62 deletions

124
nnn.c
View File

@ -252,7 +252,7 @@ static uint idletimeout, copybufpos, copybuflen;
static char *player; static char *player;
static char *copier; static char *copier;
static char *editor; static char *editor;
static char *desktop_manager; static char *dmanager; /* desktop file manager */
static blkcnt_t ent_blocks; static blkcnt_t ent_blocks;
static blkcnt_t dir_blocks; static blkcnt_t dir_blocks;
static ulong num_files; static ulong num_files;
@ -1037,7 +1037,7 @@ matches(char *fltr)
ndents = fill(&dents, visible, &re); ndents = fill(&dents, visible, &re);
regfree(&re); regfree(&re);
if (ndents == 0) if (!ndents)
return 0; return 0;
qsort(dents, ndents, sizeof(*dents), entrycmp); qsort(dents, ndents, sizeof(*dents), entrycmp);
@ -1985,8 +1985,8 @@ show_help(char *path)
if (editor) if (editor)
dprintf(fd, "NNN_USE_EDITOR: %s\n", editor); dprintf(fd, "NNN_USE_EDITOR: %s\n", editor);
if (desktop_manager) if (dmanager)
dprintf(fd, "NNN_DE_FILE_MANAGER: %s\n", desktop_manager); dprintf(fd, "NNN_DE_FILE_MANAGER: %s\n", dmanager);
if (idletimeout) if (idletimeout)
dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout); dprintf(fd, "NNN_IDLE_TIMEOUT: %d secs\n", idletimeout);
if (copier) if (copier)
@ -2260,7 +2260,7 @@ populate(char *path, char *oldname, char *fltr)
ndents = dentfill(path, &dents, visible, &re); ndents = dentfill(path, &dents, visible, &re);
regfree(&re); regfree(&re);
if (ndents == 0) if (!ndents)
return 0; return 0;
qsort(dents, ndents, sizeof(*dents), entrycmp); qsort(dents, ndents, sizeof(*dents), entrycmp);
@ -2510,7 +2510,7 @@ nochange:
goto begin; goto begin;
case SEL_GOIN: case SEL_GOIN:
/* Cannot descend in empty directories */ /* Cannot descend in empty directories */
if (ndents == 0) if (!ndents)
goto begin; goto begin;
mkpath(path, dents[cur].name, newpath, PATH_MAX); mkpath(path, dents[cur].name, newpath, PATH_MAX);
@ -2608,7 +2608,6 @@ nochange:
cur = ndents - 1; cur = ndents - 1;
break; break;
case SEL_CD: case SEL_CD:
{
truecd = 0; truecd = 0;
tmp = xreadline(NULL, "cd: "); tmp = xreadline(NULL, "cd: ");
if (tmp == NULL || tmp[0] == '\0') if (tmp == NULL || tmp[0] == '\0')
@ -2616,8 +2615,7 @@ nochange:
if (tmp[0] == '~') { if (tmp[0] == '~') {
/* Expand ~ to HOME absolute path */ /* Expand ~ to HOME absolute path */
char *dir = getenv("HOME"); dir = getenv("HOME");
if (dir) if (dir)
snprintf(newpath, PATH_MAX, "%s%s", dir, tmp + 1); snprintf(newpath, PATH_MAX, "%s%s", dir, tmp + 1);
else { else {
@ -2704,7 +2702,6 @@ nochange:
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;
goto begin; goto begin;
}
case SEL_CDHOME: case SEL_CDHOME:
dir = getenv("HOME"); dir = getenv("HOME");
if (dir == NULL) { if (dir == NULL) {
@ -2809,7 +2806,7 @@ nochange:
copyfilter(); copyfilter();
DPRINTF_S(fltr); DPRINTF_S(fltr);
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto nochange; goto nochange;
case SEL_MFLTR: case SEL_MFLTR:
@ -2818,7 +2815,7 @@ nochange:
presel = FILTER; presel = FILTER;
else { else {
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
/* Start watching the directory */ /* Start watching the directory */
@ -2837,69 +2834,71 @@ nochange:
cfg.showdetail ^= 1; cfg.showdetail ^= 1;
cfg.showdetail ? (printptr = &printent_long) : (printptr = &printent); cfg.showdetail ? (printptr = &printent_long) : (printptr = &printent);
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto begin; goto begin;
case SEL_STATS: case SEL_STATS:
if (ndents > 0) { if (!ndents)
mkpath(path, dents[cur].name, newpath, PATH_MAX); break;
if (lstat(newpath, &sb) == -1) { mkpath(path, dents[cur].name, newpath, PATH_MAX);
if (dents)
dentfree(dents); if (lstat(newpath, &sb) == -1) {
errexit(); if (dents)
} else { dentfree(dents);
if (show_stats(newpath, dents[cur].name, &sb) < 0) { errexit();
printwarn(); }
goto nochange;
} if (show_stats(newpath, dents[cur].name, &sb) < 0) {
} printwarn();
goto nochange;
} }
break; break;
case SEL_LIST: // fallthrough case SEL_LIST: // fallthrough
case SEL_EXTRACT: // fallthrough case SEL_EXTRACT: // fallthrough
case SEL_MEDIA: // fallthrough case SEL_MEDIA: // fallthrough
case SEL_FMEDIA: case SEL_FMEDIA:
if (ndents > 0) { if (!ndents)
mkpath(path, dents[cur].name, newpath, PATH_MAX); break;
mkpath(path, dents[cur].name, newpath, PATH_MAX);
if (sel == SEL_MEDIA || sel == SEL_FMEDIA)
r = show_mediainfo(newpath, run);
else
r = handle_archive(newpath, run, path);
if (r == -1) {
xstrlcpy(newpath, "missing ", PATH_MAX);
if (sel == SEL_MEDIA || sel == SEL_FMEDIA) if (sel == SEL_MEDIA || sel == SEL_FMEDIA)
r = show_mediainfo(newpath, run); xstrlcpy(newpath + 8, utils[cfg.metaviewer], 32);
else else
r = handle_archive(newpath, run, path); xstrlcpy(newpath + 8, utils[ATOOL], 32);
if (r == -1) { printmsg(newpath);
xstrlcpy(newpath, "missing ", PATH_MAX); goto nochange;
if (sel == SEL_MEDIA || sel == SEL_FMEDIA) }
xstrlcpy(newpath + 8, utils[cfg.metaviewer], 32);
else
xstrlcpy(newpath + 8, utils[ATOOL], 32);
printmsg(newpath); /* In case of successful archive extract, reload contents */
goto nochange; if (sel == SEL_EXTRACT) {
} /* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode)
presel = FILTER;
/* In case of successful archive extract, reload contents */ /* Save current */
if (sel == SEL_EXTRACT) { copycurname();
/* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode)
presel = FILTER;
/* Save current */ /* Repopulate as directory content may have changed */
copycurname(); goto begin;
/* Repopulate as directory content may have changed */
goto begin;
}
} }
break; break;
case SEL_DFB: case SEL_DFB:
if (!desktop_manager) { if (!dmanager) {
printmsg("set NNN_DE_FILE_MANAGER"); printmsg("set NNN_DE_FILE_MANAGER");
goto nochange; goto nochange;
} }
spawn(desktop_manager, path, NULL, path, F_NOWAIT | F_NOTRACE); spawn(dmanager, path, NULL, path, F_NOWAIT | F_NOTRACE);
break; break;
case SEL_FSIZE: case SEL_FSIZE:
cfg.sizeorder ^= 1; cfg.sizeorder ^= 1;
@ -2907,7 +2906,7 @@ nochange:
cfg.blkorder = 0; cfg.blkorder = 0;
cfg.copymode = 0; cfg.copymode = 0;
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto begin; goto begin;
case SEL_BSIZE: case SEL_BSIZE:
@ -2920,7 +2919,7 @@ nochange:
cfg.sizeorder = 0; cfg.sizeorder = 0;
cfg.copymode = 0; cfg.copymode = 0;
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto begin; goto begin;
case SEL_MTIME: case SEL_MTIME:
@ -2929,12 +2928,12 @@ nochange:
cfg.blkorder = 0; cfg.blkorder = 0;
cfg.copymode = 0; cfg.copymode = 0;
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto begin; goto begin;
case SEL_REDRAW: case SEL_REDRAW:
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto begin; goto begin;
case SEL_COPY: case SEL_COPY:
@ -3034,7 +3033,7 @@ nochange:
goto nochange; goto nochange;
case SEL_OPEN: // fallthrough case SEL_OPEN: // fallthrough
case SEL_ARCHIVE: case SEL_ARCHIVE:
if (ndents <= 0) if (!ndents)
break; // fallthrough break; // fallthrough
case SEL_NEW: case SEL_NEW:
if (sel == SEL_OPEN) if (sel == SEL_OPEN)
@ -3124,7 +3123,7 @@ nochange:
xstrlcpy(oldname, tmp, NAME_MAX + 1); xstrlcpy(oldname, tmp, NAME_MAX + 1);
goto begin; goto begin;
case SEL_RENAME: case SEL_RENAME:
if (ndents <= 0) if (!ndents)
break; break;
tmp = xreadline(dents[cur].name, ""); tmp = xreadline(dents[cur].name, "");
@ -3180,7 +3179,7 @@ nochange:
spawn(utils[VIDIR], ".", NULL, path, F_NORMAL); spawn(utils[VIDIR], ".", NULL, path, F_NORMAL);
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
goto begin; goto begin;
case SEL_HELP: case SEL_HELP:
@ -3209,11 +3208,12 @@ nochange:
char *curfile = NULL; char *curfile = NULL;
if (ndents > 0) if (ndents)
curfile = dents[cur].name; curfile = dents[cur].name;
spawn(run, tmp, curfile, path, F_NORMAL | F_SIGINT); spawn(run, tmp, curfile, path, F_NORMAL | F_SIGINT);
} } else
printmsg("set NNN_SCRIPT");
} else { } else {
spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER); spawn(run, NULL, NULL, path, F_NORMAL | F_MARKER);
@ -3223,7 +3223,7 @@ nochange:
} }
/* Save current */ /* Save current */
if (ndents > 0) if (ndents)
copycurname(); copycurname();
/* Repopulate as directory content may have changed */ /* Repopulate as directory content may have changed */
@ -3399,7 +3399,7 @@ main(int argc, char *argv[])
player = utils[NLAY]; player = utils[NLAY];
/* Get the desktop file manager, if set */ /* Get the desktop file manager, if set */
desktop_manager = getenv("NNN_DE_FILE_MANAGER"); dmanager = getenv("NNN_DE_FILE_MANAGER");
/* Get screensaver wait time, if set; copier used as tmp var */ /* Get screensaver wait time, if set; copier used as tmp var */
copier = getenv("NNN_IDLE_TIMEOUT"); copier = getenv("NNN_IDLE_TIMEOUT");