struct save_t {
char magic[sizeof(ADVENT_MAGIC)];
int32_t version;
+ int32_t canary;
struct game_t game;
};
extern int32_t randrange(int32_t);
extern int score(enum termination);
extern void terminate(enum termination) __attribute__((noreturn));
-extern int savefile(FILE *, int32_t);
+extern int savefile(FILE *);
#if defined ADVENT_AUTOSAVE
extern void autosave(void);
#endif
{
int ch;
char *savefilename = NULL;
- int version = 0;
FILE *fp = NULL;
// Initialize game variables
printf("cheat: game.turns = %d\n", game.turns);
break;
case 'v':
- version = atoi(optarg);
- printf("cheat: version = %d\n", version);
+ save.version = atoi(optarg);
+ printf("cheat: version = %d\n", save.version);
break;
case 'o':
savefilename = optarg;
exit(EXIT_FAILURE);
}
- savefile(fp, version);
+ savefile(fp);
fclose(fp);
{
if (autosave_fp != NULL) {
rewind(autosave_fp);
- savefile(autosave_fp, /* version (auto): */0);
+ savefile(autosave_fp);
fflush(autosave_fp);
}
}
#define IGNORE(r) do{if (r){}}while(0)
-int savefile(FILE *fp, int32_t version)
+int savefile(FILE *fp)
/* Save game to file. No input or output from user. */
{
memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
- save.version = (version == 0) ? SAVE_VERSION : version;
+ if (save.version == 0)
+ save.version = SAVE_VERSION;
save.game = game;
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
free(name);
}
- savefile(fp, SAVE_VERSION);
+ savefile(fp);
fclose(fp);
rspeak(RESUME_HELP);
exit(EXIT_SUCCESS);