diff options
author | June McEnroe <june@causal.agency> | 2019-03-27 13:10:37 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-03-27 13:10:37 -0400 |
commit | d73c5200017be9a66bf3f65ae4d3c8759188c3b2 (patch) | |
tree | 57e13a2ecf77b60d2484a996b86c5818e2c55eeb | |
parent | Factor out layout code (diff) | |
download | cards-d73c5200017be9a66bf3f65ae4d3c8759188c3b2.tar.gz cards-d73c5200017be9a66bf3f65ae4d3c8759188c3b2.zip |
Add flags to dump
And just use UNIX stuff since it's a utility.
-rw-r--r-- | dump.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/dump.c b/dump.c index d6e705e..5ad4456 100644 --- a/dump.c +++ b/dump.c @@ -14,29 +14,39 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <err.h> #include <stdio.h> #include <stdlib.h> +#include <sysexits.h> +#include <unistd.h> #include <SDL.h> #include "cards.h" -static int fail(const char *prefix) { - fprintf(stderr, "%s: %s\n", prefix, SDL_GetError()); - return EXIT_FAILURE; -} - int main(int argc, char *argv[]) { + enum Cards_Flags flags = 0; + + int opt; + while (0 < (opt = getopt(argc, argv, "abk"))) { + switch (opt) { + break; case 'a': flags |= Cards_AlphaCorners; + break; case 'b': flags |= Cards_BlackBorders; + break; case 'k': flags |= Cards_ColorKey; + break; default: return EX_USAGE; + } + } + struct SDL_RWops *rw; - if (argc > 1) { - rw = SDL_RWFromFile(argv[1], "rb"); + if (optind < argc) { + rw = SDL_RWFromFile(argv[optind], "rb"); } else { rw = SDL_RWFromFP(stdin, SDL_FALSE); } - if (!rw) return fail("SDL_RWFromFile"); + if (!rw) errx(EX_NOINPUT, "SDL_RWFromFile: %s", SDL_GetError()); - struct Cards *cards = Cards_Load(rw, 0); - if (!cards) return fail("Cards_Load"); + struct Cards *cards = Cards_Load(rw, flags); + if (!cards) errx(EX_DATAERR, "Cards_Load: %s", SDL_GetError()); SDL_RWclose(rw); for (int i = 0; i < Cards_Count; ++i) { @@ -44,7 +54,7 @@ int main(int argc, char *argv[]) { char name[sizeof("00.bmp")]; snprintf(name, sizeof(name), "%02d.bmp", i); int error = SDL_SaveBMP(cards->surfaces[i], name); - if (error) return fail("SDL_SaveBMP"); + if (error) errx(EX_CANTCREAT, "SDL_SaveBMP: %s", SDL_GetError()); } Cards_Free(cards); |