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 */
39 /* Suspend. Offer to save things in a file, but charging
40 * some points (so can't win by using saved games to retry
41 * battles or to start over after learning zzword). */
43 if (!YES(input,200,54,54)) return(2012);
44 game.saved=game.saved+5;
48 /* Resume. Read a suspended game back from a file. */
49 if (game.loc != 1 || game.abbrev[1] != 1) {
51 if (!YES(input,200,54,54)) return(2012);
56 name = linenoise("\nFile name: ");
59 fp = fopen(name,(resume ? READ_MODE : WRITE_MODE));
61 printf("Can't open file %s, try again.\n", name);
71 save.version = VRSION;
72 memcpy(&save.game, &game, sizeof(struct game_t));
73 save.bird = OBJSND[BIRD];
74 save.bivalve = OBJTXT[OYSTER];
75 IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
80 IGNORE(fread(&save, sizeof(struct save_t), 1, fp));
82 if (save.version != VRSION) {
83 SETPRM(1,k/10,MOD(k,10));
84 SETPRM(3,VRSION/10,MOD(VRSION,10));
88 memcpy(&game, &save.game, sizeof(struct game_t));
89 OBJSND[BIRD] = save.bird;
90 OBJTXT[OYSTER] = save.bivalve;
91 game.zzword=RNDVOC(3,game.zzword);