#define _GNU_SOURCE #include #include #include #include #include "image.h" #include "lbx.h" static const char *progname; #define errmsg(fmt, ...) (\ fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\ ) enum { MODE_NONE, MODE_DECODE, MODE_IDENT, }; int main(int argc, char **argv) { int mode = MODE_NONE, verbose = 0; FILE *inf = stdin, *palf = NULL; const char *name = "stdin"; LBX_IMG *img; int opt; static const char *sopts = "idvf:p:"; static const struct option lopts[] = { { "info", 0, NULL, 'i' }, { "decode", 0, NULL, 'd' }, { "verbose", 0, NULL, 'v' }, { "file", 1, NULL, 'f' }, { "palette", 1, NULL, 'p' }, { 0 } }; progname = "lbximg"; /* argv[0]; */ while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { switch(opt) { case 'i': mode = MODE_IDENT; break; case 'd': mode = MODE_DECODE; break; case 'v': verbose = 1; break; case 'f': if (strcmp(optarg, "-") == 0) break; name = strrchr(optarg, '/'); name = name ? name+1 : optarg; inf = fopen(optarg, "rb"); if (!inf) { errmsg("failed to open %s: %m\n", optarg); return EXIT_FAILURE; } break; case 'p': palf = fopen(optarg, "rb"); if (!palf) { errmsg("failed to open %s: %m\n", optarg); return EXIT_FAILURE; } break; default: return EXIT_FAILURE; } } if (mode == MODE_NONE) { errmsg("you must specify a mode.\n", 0); return EXIT_FAILURE; } img = lbximg_fopen(inf); if (!img) { errmsg("failed to open image: %s.\n", lbx_strerror()); return EXIT_FAILURE; } if (verbose || mode == MODE_IDENT) { struct lbx_imginfo info; lbximg_getinfo(img, &info); printf("%s is %ux%u LBX image, %u frames\n", name, info.width, info.height, info.nframes); } switch (mode) { case MODE_DECODE: errmsg("decode function not yet implemented.\n", 0); break; } lbximg_close(img); return EXIT_SUCCESS; }