osmq

openstreetmap for command line
git clone https://logand.com/git/osmq.git/
Log | Files | Refs

commit 0e5e6cec1ace21d11e4b3fd2568b3a7aa0a7cd54
parent 6a6d4be618880c48ef80b4e49eca6ef56b2eff19
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sun,  8 Sep 2019 23:48:55 +0200

cached_file returns 0 if file does not exist yet

Diffstat:
Mosmtile.c | 17+++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/osmtile.c b/osmtile.c @@ -129,7 +129,7 @@ static void cleanup(void) { run(args2); } -static void cached_file(int z, int x, int y, char *dir, char file[4096]) { +static int cached_file(int z, int x, int y, char *dir, char file[4096]) { int max = (1 << z) - 1; if(x < 0) x = max; if(y < 0) y = max; @@ -146,7 +146,8 @@ static void cached_file(int z, int x, int y, char *dir, char file[4096]) { fprintf(stderr, "file path error\n"); exit(1); } - if(!probe(file)) { + if(probe(file)) return 1; + { char url[4096]; int n = snprintf(url, sizeof(url), "https://tile.openstreetmap.org/%d/%d/%d.png", z, x, y); if(n < 0 || sizeof(url) < n) { @@ -162,6 +163,7 @@ static void cached_file(int z, int x, int y, char *dir, char file[4096]) { exit(1); } } + return 1; } static void screen_size(int *w, int *h) { @@ -233,10 +235,13 @@ static int tty(int argc, char *argv[]) { for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { char file[4096]; - cached_file(z, x + i - 1, y + j - 1, dir, file); - int w = min(width, height) / 3; - int h = w; - fprintf(p, "0;1;%d;%d;%d;%d;;;;;%s\n", w * i, h * j, w, h, file); + if(cached_file(z, x + i - 1, y + j - 1, dir, file)) { + int w = min(width, height) / 3; + int h = w; + fprintf(p, "0;1;%d;%d;%d;%d;;;;;%s\n", w * i, h * j, w, h, file); + } else { + full = 0; + } } } pclose(p);