#include #include #include #include #include #include #include #include #include "lcmap.h" int main(int argc,char *argv[]) { SDL_Surface *surface; FILE *fp; char packmode=0; Uint8 *mapdata; Uint32 maplen; int bytes; if(argc<4) { printf("Usage:\nlcmap \n"); return 0; } if(strcmp(argv[1],"pack")==0) packmode=1; else if(strcmp(argv[1],"unpack")) { printf("Unrecognized mode: \"%s\"\n",argv[1]); return 1; } if(SDL_Init(SDL_INIT_VIDEO)) { printf("Error: %s\n",SDL_GetError()); return 1; } if(packmode) { surface=IMG_Load(argv[2]); if(surface==NULL) { printf("IMG_Load error: %s\n",SDL_GetError()); return 1; } mapdata=surface_to_lcmap(&maplen,surface); SDL_FreeSurface(surface); if(mapdata==NULL) { printf("Error occured while converting to LCMAP\n"); return 1; } fp=fopen(argv[3],"w"); if(fp) { perror(argv[3]); return 1; } printf("Map is %d bytes long.\n",maplen); bytes=fwrite(mapdata,maplen,1,fp); if(bytes