annotate rogue4/save.c @ 286:3b61f1dfcc91

UltraRogue: don't swap signal handlers. In md_shellescape(), signal handlers for SIGINT and SIGQUIT were saved and restored, but exchanged in the process. This was fixed in the other games by commit 600873555ec0. Deleting md_shellescape() might have been a better fix. It is apparently unused.
author John "Elwin" Edwards
date Fri, 29 Sep 2017 21:21:50 -0400
parents 70aa5808c782
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
1 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
2 * save and restore routines
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
3 *
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
4 * @(#)save.c 4.15 (Berkeley) 5/10/82
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
5 *
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
6 * Rogue: Exploring the Dungeons of Doom
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
7 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
8 * All rights reserved.
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
9 *
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
10 * See the file LICENSE.TXT for full copyright and licensing information.
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
11 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
13 #include <curses.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
14 #include <sys/types.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
15 #include <sys/stat.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
16 #include <errno.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
17 #include <string.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
18 #include <stdlib.h>
280
70aa5808c782 Fix potential segfaults at restore related to ctime().
John "Elwin" Edwards
parents: 279
diff changeset
19 #include <time.h>
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
20 #define KERNEL
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
21 #include <signal.h>
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
22 #undef KERNEL
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
23 #include "rogue.h"
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
24
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
25 void save_file(FILE *savef);
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
26 extern int rs_save_file(FILE *savef);
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
27 extern int rs_restore_file(FILE *inf);
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
28
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
29 typedef struct stat STAT;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
30
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
31 extern char version[], encstr[];
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
32 extern bool _endwin;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
33
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
34 STAT sbuf;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
35
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
36 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
37 * save_game:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
38 * Implement the "save game" command
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
39 */
14
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
40 /* This has to be cleaned up, these goto's are annoying. */
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
41 bool
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
42 save_game(void)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
43 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
44 register FILE *savef;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
45 register int c;
112
ee250e3646fd Don't truncate player name in savefile name or log message.
John "Elwin" Edwards
parents: 85
diff changeset
46 char buf[256];
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
47
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
48 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
49 * get file name
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
50 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
51 mpos = 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
52 over:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
53 if (file_name[0] != '\0')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
54 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
55 for (;;)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
56 {
30
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 14
diff changeset
57 if (use_savedir)
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 14
diff changeset
58 msg("Save game? ");
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 14
diff changeset
59 else
09da55b986ca Slightly modify savefile location and prompt
edwarj4
parents: 14
diff changeset
60 msg("save file (%s)? ", file_name);
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
61 c = getchar();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
62 mpos = 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
63 if (c == ESCAPE)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
64 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
65 msg("");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
66 return FALSE;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
67 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
68 else if (c == 'n' || c == 'N' || c == 'y' || c == 'Y')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
69 break;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
70 else
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
71 msg("please answer Y or N");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
72 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
73 if (c == 'y' || c == 'Y')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
74 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
75 strcpy(buf, file_name);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
76 goto gotfile;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
77 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
78 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
79
14
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
80 if (use_savedir)
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
81 {
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
82 /* You can't change the savefile if you're using the system
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
83 savedir, because that means you have privileges. */
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
84 msg("");
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
85 return FALSE;
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
86 }
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
87
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
88 do
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
89 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
90 mpos = 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
91 msg("file name: ");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
92 buf[0] = '\0';
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
93 if (get_str(buf, stdscr) == QUIT)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
94 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
95 quit:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
96 msg("");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
97 return FALSE;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
98 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
99 mpos = 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
100 gotfile:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
101 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
102 * test to see if the file exists
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
103 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
104 if (stat(buf, &sbuf) >= 0)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
105 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
106 for (;;)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
107 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
108 msg("File exists. Do you wish to overwrite it?");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
109 mpos = 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
110 if ((c = readchar()) == ESCAPE)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
111 goto quit;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
112 if (c == 'y' || c == 'Y')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
113 break;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
114 else if (c == 'n' || c == 'N')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
115 goto over;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
116 else
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
117 msg("Please answer Y or N");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
118 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
119 msg("file name: %s", buf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
120 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
121 strcpy(file_name, buf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
122 if ((savef = fopen(file_name, "w")) == NULL)
14
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
123 {
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
124 msg(strerror(errno)); /* fake perror() */
14
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
125 if (use_savedir)
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
126 return FALSE;
e7dc81b41168 rogue4: prevent changing name or save file when using system savedir
edwarj4
parents: 13
diff changeset
127 }
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
128 } while (savef == NULL);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
129
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
130 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
131 * write out encrpyted file (after a stat)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
132 * The fwrite is to force allocation of the buffer before the write
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
133 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
134 save_file(savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
135 return TRUE;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
136 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
137
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
138 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
139 * auto_save:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
140 * Automatically save a file. This is used if a HUP signal is
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
141 * recieved
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
142 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
143 void
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
144 auto_save(int sig)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
145 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
146 register FILE *savef;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
147
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
148 md_ignore_signals();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
149
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
150 if (file_name[0] != '\0' && (savef = fopen(file_name, "w")) != NULL)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
151 save_file(savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
152 endwin();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
153 exit(1);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
154 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
155
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
156 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
157 * save_file:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
158 * Write the saved game on the file
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
159 */
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
160 void
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
161 save_file(FILE *savef)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
162 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
163 int slines = LINES;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
164 int scols = COLS;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
165
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
166 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
167 * close any open score file
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
168 */
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
169 if (score_file != NULL) {
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
170 fclose(score_file);
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
171 score_file = NULL;
182
1fe660009fd3 rogue4: don't try to close the scorefile if it isn't open.
John "Elwin" Edwards
parents: 123
diff changeset
172 }
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
173 move(LINES-1, 0);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
174 refresh();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
175 fstat(md_fileno(savef), &sbuf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
176 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
177 * DO NOT DELETE. This forces stdio to allocate the output buffer
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
178 * so that malloc doesn't get confused on restart
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
179 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
180 fwrite("junk", 1, 5, savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
181
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
182 fseek(savef, 0L, 0);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
183
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
184 encwrite(version,strlen(version)+1,savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
185 encwrite(&slines,sizeof(slines),savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
186 encwrite(&scols,sizeof(scols),savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
187 msg("");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
188 rs_save_file(savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
189
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
190 fclose(savef);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
191 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
192
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
193 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
194 * restore:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
195 * Restore a saved game from a file with elaborate checks for file
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
196 * integrity from cheaters
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
197 */
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
198 bool
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
199 restore(char *file, char **envp)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
200 {
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
201 FILE *inf;
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
202 register bool syml;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
203 extern char **environ;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
204 char buf[MAXSTR];
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
205 STAT sbuf2;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
206 int slines, scols;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
207
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
208 if (strcmp(file, "-r") == 0)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
209 file = file_name;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
210
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
211 #ifdef SIGTSTP
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
212 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
213 * If a process can be suspended, this code wouldn't work
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
214 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
215 signal(SIGTSTP, SIG_IGN);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
216 #endif
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
217
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
218 if ((inf = fopen(file, "r")) == NULL)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
219 {
13
63b9fd7d70ce rogue4: add -n option and system savedir
edwarj4
parents: 12
diff changeset
220 if (use_savedir && errno == ENOENT)
63b9fd7d70ce rogue4: add -n option and system savedir
edwarj4
parents: 12
diff changeset
221 {
63b9fd7d70ce rogue4: add -n option and system savedir
edwarj4
parents: 12
diff changeset
222 /* We're using a system savefile which doesn't exist.
63b9fd7d70ce rogue4: add -n option and system savedir
edwarj4
parents: 12
diff changeset
223 This isn't a fatal error, it means start a new game. */
63b9fd7d70ce rogue4: add -n option and system savedir
edwarj4
parents: 12
diff changeset
224 return TRUE;
63b9fd7d70ce rogue4: add -n option and system savedir
edwarj4
parents: 12
diff changeset
225 }
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
226 perror(file);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
227 return FALSE;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
228 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
229
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
230 fflush(stdout);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
231 encread(buf, strlen(version) + 1, inf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
232 if (strcmp(buf, version) != 0)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
233 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
234 printf("Sorry, saved game is out of date.\n");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
235 return FALSE;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
236 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
237
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
238 stat(file, &sbuf2);
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
239 fflush(stdout);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
240 syml = issymlink(file);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
241
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
242 fflush(stdout);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
243
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
244 encread(&slines,sizeof(slines),inf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
245 encread(&scols,sizeof(scols),inf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
246
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
247 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
248 * we do not close the file so that we will have a hold of the
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
249 * inode for as long as possible
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
250 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
251
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
252 initscr();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
253
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
254 if (slines > LINES)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
255 {
85
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
256 endwin();
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
257 printf("Sorry, original game was played on a screen with %d lines.\n",slines);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
258 printf("Current screen only has %d lines. Unable to restore game\n",LINES);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
259 return(FALSE);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
260 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
261
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
262 if (scols > COLS)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
263 {
85
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
264 endwin();
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
265 printf("Sorry, original game was played on a screen with %d columns.\n",scols);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
266 printf("Current screen only has %d columns. Unable to restore game\n",COLS);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
267 return(FALSE);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
268 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
269
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
270 hw = newwin(LINES, COLS, 0, 0);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
271 keypad(stdscr,1);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
272
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
273 mpos = 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
274 mvprintw(0, 0, "%s: %s", file, ctime(&sbuf2.st_mtime));
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
275
84
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
276 if (rs_restore_file(inf) == FALSE)
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
277 {
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
278 endwin();
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
279 printf("Cannot restore file\n");
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
280 return(FALSE);
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
281 }
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
282
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
283 if (
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
284 #ifdef WIZARD
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
285 !wizard &&
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
286 #endif
123
8dd4b06a9155 rogue4: fix restoring saved games on Windows/MinGW.
John "Elwin" Edwards
parents: 112
diff changeset
287 md_unlink_open_file(file, inf) < 0)
84
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
288 {
85
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
289 endwin();
84
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
290 printf("Cannot unlink file\n");
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
291 return FALSE;
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
292 }
a0d4caead33b rogue4: don't delete the savefile if the terminal is too small.
John "Elwin" Edwards
parents: 81
diff changeset
293
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
294 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
295 * defeat multiple restarting from the same place
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
296 */
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
297 #ifdef WIZARD
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
298 if (!wizard)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
299 #endif
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
300 if (sbuf2.st_nlink != 1 || syml)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
301 {
85
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
302 endwin();
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
303 printf("Cannot restore from a linked file\n");
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
304 return FALSE;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
305 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
306
85
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
307 if (pstats.s_hpt <= 0) {
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
308 endwin();
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
309 printf("This character is already dead.\n");
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
310 return FALSE;
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
311 }
d852b8f088c5 Refuse to restore if the character is dead.
John "Elwin" Edwards
parents: 84
diff changeset
312
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
313 #ifdef SIGTSTP
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
314 signal(SIGTSTP, tstp);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
315 #endif
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
316 environ = envp;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
317 strcpy(file_name, file);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
318 setup();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
319 clearok(curscr, TRUE);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
320 touchwin(stdscr);
252
3d4252fa2ed3 Use more portable random seed generation.
John "Elwin" Edwards
parents: 215
diff changeset
321 srand(md_random_seed());
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
322 msg("file name: %s", file);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
323 status();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
324 playit();
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
325 return 0;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
326 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
327
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
328 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
329 * encwrite:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
330 * Perform an encrypted write
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
331 */
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
332 void
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
333 encwrite(void *starta, int size, FILE *outf)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
334 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
335 register char *ep;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
336 register char *start = (char *) starta;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
337 ep = encstr;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
338
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
339 while (size--)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
340 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
341 putc(*start++ ^ *ep++, outf);
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
342 if (*ep == '\0')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
343 ep = encstr;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
344 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
345 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
346
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
347 /*
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
348 * encread:
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
349 * Perform an encrypted read
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
350 */
215
1b73a8641b37 rogue4: fix most GCC5 warnings.
John "Elwin" Edwards
parents: 182
diff changeset
351 int
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
352 encread(void *starta, int size, FILE *inf)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
353 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
354 register char *ep;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
355 register int read_size;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
356 register char *start = (char *) starta;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
357
279
d3968e9cb98d Use C stdio functions for score files and save files.
John "Elwin" Edwards
parents: 252
diff changeset
358 if ((read_size = fread(start, 1, size, inf)) == 0)
12
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
359 return read_size;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
360
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
361 ep = encstr;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
362
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
363 while (size--)
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
364 {
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
365 *start++ ^= *ep++;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
366 if (*ep == '\0')
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
367 ep = encstr;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
368 }
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
369
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
370 return read_size;
9535a08ddc39 Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff changeset
371 }