Simplify the signature of savefile().
This commit is contained in:
parent
58cf204eba
commit
4b08b726f9
4 changed files with 10 additions and 9 deletions
3
advent.h
3
advent.h
|
@ -248,6 +248,7 @@ typedef struct {
|
||||||
struct save_t {
|
struct save_t {
|
||||||
char magic[sizeof(ADVENT_MAGIC)];
|
char magic[sizeof(ADVENT_MAGIC)];
|
||||||
int32_t version;
|
int32_t version;
|
||||||
|
int32_t canary;
|
||||||
struct game_t game;
|
struct game_t game;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -277,7 +278,7 @@ extern void set_seed(int32_t);
|
||||||
extern int32_t randrange(int32_t);
|
extern int32_t randrange(int32_t);
|
||||||
extern int score(enum termination);
|
extern int score(enum termination);
|
||||||
extern void terminate(enum termination) __attribute__((noreturn));
|
extern void terminate(enum termination) __attribute__((noreturn));
|
||||||
extern int savefile(FILE *, int32_t);
|
extern int savefile(FILE *);
|
||||||
#if defined ADVENT_AUTOSAVE
|
#if defined ADVENT_AUTOSAVE
|
||||||
extern void autosave(void);
|
extern void autosave(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
7
cheat.c
7
cheat.c
|
@ -19,7 +19,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
char *savefilename = NULL;
|
char *savefilename = NULL;
|
||||||
int version = 0;
|
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
// Initialize game variables
|
// Initialize game variables
|
||||||
|
@ -59,8 +58,8 @@ int main(int argc, char *argv[])
|
||||||
printf("cheat: game.turns = %d\n", game.turns);
|
printf("cheat: game.turns = %d\n", game.turns);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
version = atoi(optarg);
|
save.version = atoi(optarg);
|
||||||
printf("cheat: version = %d\n", version);
|
printf("cheat: version = %d\n", save.version);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
savefilename = optarg;
|
savefilename = optarg;
|
||||||
|
@ -89,7 +88,7 @@ int main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
savefile(fp, version);
|
savefile(fp);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
|
2
main.c
2
main.c
|
@ -24,7 +24,7 @@ void autosave(void)
|
||||||
{
|
{
|
||||||
if (autosave_fp != NULL) {
|
if (autosave_fp != NULL) {
|
||||||
rewind(autosave_fp);
|
rewind(autosave_fp);
|
||||||
savefile(autosave_fp, /* version (auto): */0);
|
savefile(autosave_fp);
|
||||||
fflush(autosave_fp);
|
fflush(autosave_fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,12 @@ struct save_t save;
|
||||||
|
|
||||||
#define IGNORE(r) do{if (r){}}while(0)
|
#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. */
|
/* Save game to file. No input or output from user. */
|
||||||
{
|
{
|
||||||
memcpy(&save.magic, ADVENT_MAGIC, sizeof(ADVENT_MAGIC));
|
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;
|
save.game = game;
|
||||||
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
|
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
|
||||||
|
@ -84,7 +85,7 @@ int suspend(void)
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
savefile(fp, SAVE_VERSION);
|
savefile(fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
rspeak(RESUME_HELP);
|
rspeak(RESUME_HELP);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue