6 #include "linenoise/linenoise.h"
9 * (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code;
10 * see the history.adoc file in the source distribution for discussion.
13 #define VRSION 26 /* bump on save format change */
16 * If you change the first three members, the resume function may not properly
17 * reject saves from older versions. Yes, this glues us to a hardware-
18 * dependent length of long. Later members can change, but bump the version
23 long mode; /* not used, must be present for version detection */
31 int saveresume(FILE *input, bool resume)
32 /* Suspend and resume */
38 /* Suspend. Offer to save things in a file, but charging
39 * some points (so can't win by using saved games to retry
40 * battles or to start over after learning zzword). */
42 if (!YES(input,200,54,54)) return GO_CLEAROBJ;
43 game.saved=game.saved+5;
47 /* Resume. Read a suspended game back from a file. */
48 if (game.loc != 1 || game.abbrev[1] != 1) {
50 if (!YES(input,200,54,54)) return GO_CLEAROBJ;
55 char* name = linenoise("\nFile name: ");
58 fp = fopen(name,(resume ? READ_MODE : WRITE_MODE));
60 printf("Can't open file %s, try again.\n", name);
70 save.version = VRSION;
71 memcpy(&save.game, &game, sizeof(struct game_t));
72 save.bird = OBJSND[BIRD];
73 save.bivalve = OBJTXT[OYSTER];
74 IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
79 IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
81 if (save.version != VRSION) {
82 SETPRM(1,k/10,MOD(k,10));
83 SETPRM(3,VRSION/10,MOD(VRSION,10));
86 memcpy(&game, &save.game, sizeof(struct game_t));
87 OBJSND[BIRD] = save.bird;
88 OBJTXT[OYSTER] = save.bivalve;
89 game.zzword=RNDVOC(3,game.zzword);