commit 09488bc877f5595366f232d0372c28e853c88fe9
parent 017bf8fc1f929bcef3b9a5cfa2f69bc6f4356d33
Author: Tomas Hlavaty <tom@logand.com>
Date: Sun, 8 Sep 2019 23:27:03 +0200
refactor fread into key function
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/osmtile.c b/osmtile.c
@@ -179,6 +179,12 @@ static void screen_size(int *w, int *h) {
#define min(x, y) (x < y ? x : y)
+static unsigned char key(void) {
+ unsigned char c;
+ if(1 != fread(&c, 1, 1, stdin)) exit(0);
+ return c;
+}
+
static int tty(int argc, char *argv[]) {
int width, height;
screen_size(&width, &height);
@@ -200,7 +206,6 @@ static int tty(int argc, char *argv[]) {
double a = a0, o = o0;
int x = long2tilex(o, z);
int y = lat2tiley(a, z);
- unsigned char c;
for(;;) {
FILE *p = popen("w3mimgdisplay", "w");
if(!p) {
@@ -217,13 +222,13 @@ static int tty(int argc, char *argv[]) {
}
}
pclose(p);
- if(1 != fread(&c, 1, 1, stdin)) return 0;
+ unsigned char c = key();
switch(c) {
case 27: /* esc */
- if(1 != fread(&c, 1, 1, stdin)) return 0;
+ c = key();
switch(c) {
case '[':
- if(1 != fread(&c, 1, 1, stdin)) return 0;
+ c = key();
switch(c) {
case 'A': goto up;
case 'B': goto down;