sxiv

simple X image viewer
git clone git://git.suckless.org/sxiv
Log | Files | Refs | LICENSE

commit 86dc6860f9def64ad554a7c69eeae28203661e2c
parent d69f39e3aad6a7c5fb110dabb068a7bbb2229750
Author: Paride Legovini <pl@ninthfloor.org>
Date:   Wed, 28 Sep 2016 18:59:15 +0200

Allow opening directories non-recursively

Diffstat:
Makefile | 2+-
main.c | 6+-----
thumbs.c | 2+-
util.c | 5+++--
util.h | 3++-
5 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -VERSION := git-20160810 +VERSION := git-20160928 PREFIX := /usr/local MANPREFIX := $(PREFIX)/share/man diff --git a/main.c b/main.c @@ -818,11 +818,7 @@ int main(int argc, char **argv) if (!S_ISDIR(fstats.st_mode)) { check_add_file(filename, true); } else { - if (!options->recursive) { - error(0, 0, "%s: Is a directory", filename); - continue; - } - if (r_opendir(&dir, filename) < 0) { + if (r_opendir(&dir, filename, options->recursive) < 0) { error(0, errno, "%s", filename); continue; } diff --git a/thumbs.c b/thumbs.c @@ -123,7 +123,7 @@ void tns_clean_cache(tns_t *tns) char *cfile, *filename, *tpos; r_dir_t dir; - if (r_opendir(&dir, cache_dir) < 0) { + if (r_opendir(&dir, cache_dir, true) < 0) { error(0, errno, "%s", cache_dir); return; } diff --git a/util.c b/util.c @@ -89,7 +89,7 @@ void size_readable(float *size, const char **unit) *unit = units[MIN(i, ARRLEN(units) - 1)]; } -int r_opendir(r_dir_t *rdir, const char *dirname) +int r_opendir(r_dir_t *rdir, const char *dirname, bool recursive) { if (*dirname == '\0') return -1; @@ -106,6 +106,7 @@ int r_opendir(r_dir_t *rdir, const char *dirname) rdir->name = (char*) dirname; rdir->d = 0; + rdir->recursive = recursive; return 0; } @@ -167,7 +168,7 @@ char* r_readdir(r_dir_t *rdir) return filename; } - if (rdir->stlen > 0) { + if (rdir->recursive && rdir->stlen > 0) { /* open next subdirectory */ closedir(rdir->dir); if (rdir->d != 0) diff --git a/util.h b/util.h @@ -55,6 +55,7 @@ typedef struct { DIR *dir; char *name; int d; + bool recursive; char **stack; int stcap; @@ -71,7 +72,7 @@ void error(int, int, const char*, ...); void size_readable(float*, const char**); -int r_opendir(r_dir_t*, const char*); +int r_opendir(r_dir_t*, const char*, bool); int r_closedir(r_dir_t*); char* r_readdir(r_dir_t*); int r_mkdir(char*);