From: Robin Krens Date: Wed, 15 Jun 2022 14:54:40 +0000 (+0200) Subject: tools: bmp2tiles write to seperate output folder X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=df83e79401b3e40e9c6e3491e7507254f867fc4f;p=swan-dev tools: bmp2tiles write to seperate output folder --- diff --git a/tools/bmp2tiles/bmp2tiles.c b/tools/bmp2tiles/bmp2tiles.c index 7da5a38..61ce69c 100644 --- a/tools/bmp2tiles/bmp2tiles.c +++ b/tools/bmp2tiles/bmp2tiles.c @@ -14,6 +14,10 @@ #include #include #include +#include +#include +#include +#include #include #define TILE_SZ 32 @@ -103,7 +107,7 @@ FILE * openstream(const char * name, const char * prefix, unsigned buf_len = 256; char buf[buf_len]; - snprintf(buf, buf_len, "%s%d.%s", name, tile_nr, prefix); + snprintf(buf, buf_len, "%s/%s%d.%s", prefix, name, tile_nr, prefix); //printf("%s\n", buf); if (!append) { @@ -115,6 +119,20 @@ FILE * openstream(const char * name, const char * prefix, return stream; } +int create_dir(const char *name) +{ + struct stat statbuf; + + if (stat(name, &statbuf) == -1) + return mkdir(name, 0755); + + if ((statbuf.st_mode & S_IFMT) != S_IFDIR) + return -1; + + return 0; +} + + int main(int argc, char *argv[]) { SDL_Surface * rawbmp; @@ -178,6 +196,15 @@ int main(int argc, char *argv[]) sprintf(outfile, "out"); } + /* check for existing gfx/ and pal/ directories */ + ret = create_dir("gfx/"); + ret += create_dir("pal/"); + + if (ret) { + fprintf(stderr, "error: can not create output location\n"); + goto cleanup; + } + fprintf(stdout, "generating %d tile(s) \ in %d gfx file(s) \ with %d pal file(s)\n", @@ -185,7 +212,6 @@ int main(int argc, char *argv[]) seperate_gfx ? gfx->row_tiles * gfx->col_tiles : 1, seperate_pal ? gfx->row_tiles * gfx->col_tiles : 1); - for (int i = 0, cnt = 0; i < gfx->row_tiles; ++i) { for (int j = 0; j < gfx->col_tiles; ++j, ++cnt) {