annotate rogue3/save.c @ 51:a1dc75e38e73

rogue4: ported to autoconf.
author elwin
date Tue, 11 Oct 2011 15:20:40 +0000
parents 2dcd75e6a736
children d852b8f088c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
1 /*
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
2 * save and restore routines
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
3 *
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
4 * @(#)save.c 3.9 (Berkeley) 6/16/81
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
5 *
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
6 * Rogue: Exploring the Dungeons of Doom
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
8 * All rights reserved.
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
9 *
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
10 * See the file LICENSE.TXT for full copyright and licensing information.
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
11 */
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
12
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
13 #include "curses.h"
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
14 #include <ctype.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
15 #include <sys/types.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
16 #include <sys/stat.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
17 #include <signal.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
18 #include <errno.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
19 #include <string.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
20 #include <stdlib.h>
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
21 #include "machdep.h"
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
22 #include "rogue.h"
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
23
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
24 typedef struct stat STAT;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
25
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
26 extern char version[], encstr[];
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
27
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
28 STAT sbuf;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
29
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
30 int
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
31 save_game()
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
32 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
33 FILE *savef;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
34 int c;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
35 char buf[80];
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
36
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
37 /*
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
38 * get file name
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
39 */
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
40 mpos = 0;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
41 if (file_name[0] != '\0')
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
42 {
30
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 2
diff changeset
43 if (use_savedir)
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 2
diff changeset
44 msg("Save game? ");
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 2
diff changeset
45 else
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 2
diff changeset
46 msg("Save file (%s)? ", file_name);
0
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
47 do
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
48 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
49 c = readchar(cw);
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
50 } while (c != 'n' && c != 'N' && c != 'y' && c != 'Y');
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
51 mpos = 0;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
52 if (c == 'y' || c == 'Y')
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
53 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
54 msg("File name: %s", file_name);
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
55 goto gotfile;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
56 }
2
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
57 if (use_savedir)
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
58 return FALSE;
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
59 /* because you're not allowed to change the savefile if
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
60 you're using the system savedir! */
0
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
61 }
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
62
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
63 do
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
64 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
65 msg("File name: ");
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
66 mpos = 0;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
67 buf[0] = '\0';
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
68 if (get_str(buf, cw) == QUIT)
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
69 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
70 msg("");
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
71 return FALSE;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
72 }
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
73 strcpy(file_name, buf);
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
74 gotfile:
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
75 if ((savef = fopen(file_name, "w")) == NULL)
2
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
76 {
0
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
77 msg(strerror(errno)); /* fake perror() */
2
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
78 if (use_savedir)
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
79 return FALSE;
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
80 }
0
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
81 } while (savef == NULL);
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
82
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
83 /*
2
e676d52b5d09 Prevent changing name or save file when using system savedir
edwarj4
parents: 1
diff changeset
84 * write out encrypted file (after a stat)
0
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
85 * The fwrite is to force allocation of the buffer before the write
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
86 */
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
87 if (save_file(savef) != 0)
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
88 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
89 msg("Save game failed!");
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
90 return FALSE;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
91 }
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
92 return TRUE;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
93 }
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
94
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
95 /*
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
96 * automatically save a file. This is used if a HUP signal is
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
97 * recieved
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
98 */
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
99 void
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
100 auto_save(int p)
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
101 {
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
102 FILE *savef;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
103 int i;
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
104
527e2150eaf0 Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents: