about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--dump.c32
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);