summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-02-07 12:07:01 -0500
committerJune McEnroe <june@causal.agency>2018-02-07 12:07:01 -0500
commitb6409bf711c315bb910346fb4183717add00c843 (patch)
treea2e71f058b88d06b08a7743663dc7b3517942473 /bin
parentRename title to status in gfcocoa (diff)
downloadsrc-b6409bf711c315bb910346fb4183717add00c843.tar.gz
src-b6409bf711c315bb910346fb4183717add00c843.zip
Exit by returning false from input to gf{b,cocoa}
I haven't built gfb yet, so a fix commit is probably incoming.
Diffstat (limited to '')
-rw-r--r--bin/gfb.c30
-rw-r--r--bin/gfcocoa.m7
-rw-r--r--bin/gfxx.c5
3 files changed, 22 insertions, 20 deletions
diff --git a/bin/gfb.c b/bin/gfb.c
index 9925cc12..d7f32400 100644
--- a/bin/gfb.c
+++ b/bin/gfb.c
@@ -17,6 +17,7 @@
 #include <err.h>
 #include <fcntl.h>
 #include <linux/fb.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -27,18 +28,9 @@
 #include <unistd.h>
 
 extern int init(int argc, char *argv[]);
+extern const char *status(void);
 extern void draw(uint32_t *buf, size_t xres, size_t yres);
-extern void input(char in);
-
-static uint32_t *buf;
-static struct fb_var_screeninfo info;
-
-static uint32_t saveBg;
-static void restoreBg(void) {
-    for (size_t i = 0; i < info.xres * info.yres; ++i) {
-        buf[i] = saveBg;
-    }
-}
+extern bool input(char in);
 
 static struct termios saveTerm;
 static void restoreTerm(void) {
@@ -57,16 +49,14 @@ int main(int argc, char *argv[]) {
     int fb = open(path, O_RDWR);
     if (fb < 0) err(EX_OSFILE, "%s", path);
 
+    struct fb_var_screeninfo info;
     error = ioctl(fb, FBIOGET_VSCREENINFO, &info);
     if (error) err(EX_IOERR, "%s", path);
 
     size_t size = 4 * info.xres * info.yres;
-    buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
+    uint32_t *buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
     if (buf == MAP_FAILED) err(EX_IOERR, "%s", path);
 
-    saveBg = buf[0];
-    atexit(restoreBg);
-
     error = tcgetattr(STDERR_FILENO, &saveTerm);
     if (error) err(EX_IOERR, "tcgetattr");
     atexit(restoreTerm);
@@ -76,6 +66,8 @@ int main(int argc, char *argv[]) {
     error = tcsetattr(STDERR_FILENO, TCSADRAIN, &term);
     if (error) err(EX_IOERR, "tcsetattr");
 
+    uint32_t saveBg = buf[0];
+
     uint32_t back[info.xres * info.yres];
     for (;;) {
         draw(back, info.xres, info.yres);
@@ -86,6 +78,12 @@ int main(int argc, char *argv[]) {
         if (len < 0) err(EX_IOERR, "read");
         if (!len) return EX_DATAERR;
 
-        input(in);
+        if (!input(in)) {
+            for (uint32_t i = 0; i < info.xres * info.yres; ++i) {
+                buf[i] = saveBg;
+            }
+            fprintf(stderr, "%s\n", status());
+            return EX_OK;
+        }
     }
 }
diff --git a/bin/gfcocoa.m b/bin/gfcocoa.m
index 23136d0a..d3d2ef46 100644
--- a/bin/gfcocoa.m
+++ b/bin/gfcocoa.m
@@ -16,6 +16,7 @@
 
 #import <Cocoa/Cocoa.h>
 #import <err.h>
+#import <stdbool.h>
 #import <stdint.h>
 #import <stdlib.h>
 #import <sysexits.h>
@@ -25,7 +26,7 @@
 extern int init(int argc, char *argv[]);
 extern const char *status(void);
 extern void draw(uint32_t *buf, size_t xres, size_t yres);
-extern void input(char in);
+extern bool input(char in);
 
 @interface BufferView : NSView {
     size_t bufSize;
@@ -94,7 +95,9 @@ extern void input(char in);
         remainingRange: NULL
     ];
     if (converted) {
-        input(in);
+        if (!input(in)) {
+            [NSApp terminate: self];
+        }
         [self setWindowTitle];
         [self draw];
     }
diff --git a/bin/gfxx.c b/bin/gfxx.c
index 9a5fd6cd..84991e0e 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -348,11 +348,11 @@ static void setPreset(void) {
     }
 }
 
-extern void input(char in) {
+extern bool input(char in) {
     size_t pixel = (BITS_TOTAL + 7) / 8;
     size_t row = width * pixel;
     switch (in) {
-        case 'q': formatOptions(); printf("%s\n", options); exit(EX_OK);
+        case 'q': return false;
         break; case 'o': formatOptions(); printf("%s\n", options);
         break; case '[': if (!space--) space = COLOR__MAX - 1;
         break; case ']': if (++space == COLOR__MAX) space = 0;
@@ -380,4 +380,5 @@ extern void input(char in) {
         break; case '-': if (scale > 1) scale--;
         break; default: if (in >= '0' && in <= '9') setBit(in);
     }
+    return true;
 }
'> Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-log: ban strcpy()Christian Hesse Git upstream bans strcpy() with commit: automatically ban strcpy() c8af66ab8ad7cd78557f0f9f5ef6a52fd46ee6dd Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-08-28filters: generate anchor links from markdownChristian Hesse This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> 2018-08-03Bump version.Jason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-08-03clone: fix directory traversalJason A. Donenfeld This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev