lel

Fork of Hiltjo's Farbfeld image viewer. (It was just for fun, not much use)
Log | Files | Refs | README | LICENSE

commit 60e3e2ebae4f13828b0493193c9f7f4999c75fd7
parent f7d24a5a31a2dc20e6dd77ac20d9f73f4b4c85ec
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Sun, 18 Apr 2021 22:30:17 -0700

Try all images before exiting due to parse failure

As a consequence you may now delete images from the "queue" by
pressing `x'.

Diffstat:
Mlel.1 | 2++
Mlel.c | 65+++++++++++++++++++++++++++++++++++++++++++++--------------------
2 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/lel.1 b/lel.1 @@ -45,6 +45,8 @@ Reload image. Go to the next image. .It Ic p Go to the previous image. +.It Ic x +Delete image from queue. .It Ic a Full aspect ratio. .It Ic s diff --git a/lel.c b/lel.c @@ -64,6 +64,7 @@ static int paninc = 20; static char **imgs; static int done; +static int lastimg; static int nimgs; static int screen, xfd; static int viewmode; @@ -71,21 +72,21 @@ static int winwidth, winheight; static struct img img; static void -edie(int e, char *s) +warn(char *s) { fputs(getprogname(), stderr); if (s) fprintf(stderr, ": %s", s); - if (e) - fprintf(stderr, ": %s", strerror(e)); + if (errno) + fprintf(stderr, ": %s", strerror(errno)); fputs(".\n", stderr); - exit(1); } static void die(char *s) { - edie(errno, s); + warn(s); + exit(1); } static int @@ -143,7 +144,9 @@ static void ff_close(struct img *img) { img->state &= ~LOADED; - free(img->buf); + if (img->buf) + free(img->buf); + img->buf = NULL; } static int @@ -208,6 +211,16 @@ getbin(char *s) } static void +deleteimg(void) +{ + ff_close(&img); + imgs[img.index] = NULL; + if (--nimgs < 1) + exit(0); + nextimg(); +} + +static void loadimg(void) { int d; @@ -229,8 +242,12 @@ loadimg(void) } fp = fdopen(d, "r"); - if (fp == NULL || ff_open(&img, fp) || ff_read(&img, fp) || fclose(fp)) - die(imgs[img.index]); + if (fp == NULL || ff_open(&img, fp) || ff_read(&img, fp) || fclose(fp)) { + warn(imgs[img.index]); + deleteimg(); + } + + img.state &= ~(DRAWN | SCALED); } static void @@ -245,21 +262,27 @@ reloadimg(void) static void nextimg(void) { - if (img.index >= nimgs - 1) - return; - ff_close(&img); - ++img.index; - reloadimg(); + while (img.index < lastimg && imgs[++img.index] == NULL) + ; + if (imgs[img.index] == NULL) { + nextimg(); + } else { + ff_close(&img); + reloadimg(); + } } static void previmg(void) { - if (img.index <= 0) - return; - ff_close(&img); - --img.index; - reloadimg(); + while (img.index > 0 && imgs[--img.index] == NULL) + ; + if (imgs[img.index] == NULL) { + nextimg(); + } else { + ff_close(&img); + reloadimg(); + } } /* scales imgbuf data to newbuf (ximg->data), nearest neighbour. */ @@ -494,11 +517,12 @@ keypress(XEvent *ev) break; case XK_n: nextimg(); - img.state &= ~(DRAWN | SCALED); break; case XK_p: previmg(); - img.state &= ~(DRAWN | SCALED); + break; + case XK_x: + deleteimg(); break; case XK_a: setview(FULL_ASPECT); @@ -623,6 +647,7 @@ main(int argc, char *argv[]) ++nimgs; *imgs = "/dev/stdin"; } + lastimg = nimgs - 1; loadimg(); setup();