#include <unistd.h>
#include <assert.h>
#include <getopt.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/sysmacros.h>
#include <SDL2/SDL_image.h>
#define TILE_SZ 32
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) {
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;
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",
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) {