#include <stdint.h>
#include <stdbool.h>
#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
#include <SDL2/SDL_image.h>
#define TILE_SZ 32
}
}
-int main(void)
+int main(int argc, char *argv[])
{
SDL_Surface * rawbmp;
FILE * ostream;
- char filename[] = "test.bmp";
- char outname[] = "test.gfx";
- rawbmp = SDL_LoadBMP(filename);
-
+ int opt;
+ char * infile;
+ char outfile[256];
+ bool bout = false;
+
+ while ((opt = getopt(argc, argv, "po:sv:")) != -1) {
+ switch (opt) {
+ case 'p':
+ printf("include palette");
+ break;
+ case 'o':
+ printf("output file %s\n", optarg);
+ strcpy(outfile, optarg);
+ bout = true;
+ break;
+ case 's':
+ printf("generate gfx per 16x16 tile \n");
+ break;
+ case 'v':
+ break;
+ default: /* '?' */
+ fprintf(stderr, "Usage: %s [-s] [-o output] file \n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Expected infile\n");
+ fprintf(stderr, "Usage: %s [-s] [-o output] [file]\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ infile = argv[optind];
+
+ rawbmp = SDL_LoadBMP(infile);
if (!rawbmp) {
- fprintf(stderr, "can not load .bmp file\n");
+ fprintf(stderr, "can not load %s file\n", infile);
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
- ostream = fopen(outname, "w");
+ if (!bout)
+ ostream = fopen("out.gfx", "w");
+ else {
+ printf("opening %s\n", outfile);
+ ostream = fopen(outfile, "w");
+ }
+
if (!ostream) {
fprintf(stderr, "can not open file for writing!\n");
exit(EXIT_FAILURE);