extern long randrange(long);
extern long score(enum termination);
extern void terminate(enum termination) __attribute__((noreturn));
-extern int savefile(FILE *);
+extern int savefile(FILE *, long);
extern int suspend(void);
extern int resume(void);
extern int restore(FILE *);
char *savefilename = NULL;
long numdie = 0;
long saved = 1;
+ long version = 0;
/* Options. */
- const char* opts = "d:s:o:";
- const char* usage = "Usage: %s [-d numdie] [-s numsaves] -o savefilename \n";
+ const char* opts = "d:s:v:o:";
+ const char* usage = "Usage: %s [-d numdie] [-s numsaves] [-v version] -o savefilename \n";
while ((ch = getopt(argc, argv, opts)) != EOF) {
switch (ch) {
case 'd':
case 's':
saved = (long)atoi(optarg);
break;
+ case 'v':
+ version = (long)atoi(optarg);;
+ break;
case 'o':
savefilename = optarg;
break;
" -d number of deaths. Signed integer value.'\n");
fprintf(stderr,
" -s number of saves. Signed integer value.\n");
+ fprintf(stderr,
+ " -v version number of save format.\n");
fprintf(stderr,
" -o file name of save game to write.\n");
exit(-1);
fp = fopen(savefilename, WRITE_MODE);
if (fp == NULL)
{
- printf("Can't open file %s. Exiting.\n", savefilename);
+ fprintf(stderr,
+ "Can't open file %s. Exiting.\n", savefilename);
exit(-1);
}
- savefile(fp);
+ savefile(fp, version);
+
printf("cheat: %s created.\n", savefilename);
return 0;
}
};
struct save_t save;
-int savefile(FILE *fp)
+int savefile(FILE *fp, long version)
/* Save game to file. No input or output from user. */
{
long i, k;
k = i + 650 * k;
save.savetime = k;
save.mode = -1;
- save.version = VRSION;
+
+ save.version = (version == 0) ? VRSION : version;
+
memcpy(&save.game, &game, sizeof(struct game_t));
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
return(0);
linenoiseFree(name);
}
- savefile(fp);
- IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
+ savefile(fp, VRSION);
fclose(fp);
rspeak(RESUME_HELP);
exit(0);
done; \
rm -f scratch.tmp
regress:
- $(ECHO) -n "Generate cheat file: "
+ $(ECHO) -n "Generate save file with -1000 deaths: "
../cheat -d -1000 -o cheat_numdie.adv
+ $(ECHO) -n "Generate save file with version -1337: "
+ ../cheat -v -1337 -o resume_badversion.adv
@for file in $(TESTLOADS); do \
$(ECHO) -n " $${file} "; grep '##' $${file}.log || echo ' ## (no description)'; \
OPTS=`sed -n /#options:/s///p <$${file}.log`; \
seed 1240742801
resume
y
-resume_badversion.testsave
\ No newline at end of file
+resume_badversion.adv
\ No newline at end of file