/* Copyright (C) 2019 C. McEnroe * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ #include #include #include #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[]) { struct SDL_RWops *rw; if (argc > 1) { rw = SDL_RWFromFile(argv[1], "rb"); } else { rw = SDL_RWFromFP(stdin, SDL_FALSE); } if (!rw) return fail("SDL_RWFromFile"); struct Cards *cards = Cards_Load(rw, 0); if (!cards) return fail("Cards_Load"); SDL_RWclose(rw); for (int i = 0; i < Cards_Count; ++i) { if (!cards->surfaces[i]) continue; 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"); } Cards_Free(cards); }