-
Notifications
You must be signed in to change notification settings - Fork 1
/
save.c
135 lines (103 loc) · 2.56 KB
/
save.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
save.c - save and restore routines
UltraRogue: The Ultimate Adventure in the Dungeons of Doom
Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
#define _ALL_SOURCE /* need to remove need for this AIXism */
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "rogue.h"
int
save_game(void)
{
FILE *savefd;
char buf[2 * LINELEN];
char oldfile[2*LINELEN];
/* get file name */
strcpy(oldfile,file_name);
do
{
mpos = 0;
if (oldfile[0] != '\0')
msg("Save file [%s]: ", file_name);
else
msg("Save file as: ");
mpos = 0;
buf[0] = '\0';
if (get_string(buf, cw) == QUIT)
{
msg("");
return(FALSE);
}
if ( (buf[0] == 0) && (oldfile[0] != 0) )
strcpy(file_name, oldfile);
else if (buf[0] != 0)
strcpy(file_name, buf);
else
{
msg("");
return(FALSE);
}
wclear(hw);
wmove(hw, LINES - 1, 0);
wrefresh(hw);
if ((savefd = fopen(file_name, "w")) == NULL)
msg(strerror(errno)); /* fake perror() */
}
while (savefd == NULL);
/* write out [compressed?] file */
save_file(savefd);
return(TRUE);
}
int
restore(char *file)
{
FILE *infd;
char *sp;
if (strcmp(file, "-r") == 0)
file = file_name;
if ((infd = fopen(file, "r")) == NULL)
{
perror(file);
return(FALSE);
}
if ( restore_file(infd) == FALSE )
return(FALSE);
/*
* we do not close the file so that we will have a hold of the inode
* for as long as possible
*/
if (remove(file) < 0)
{
printf("Cannot unlink file\n");
return(FALSE);
}
if ((sp = getenv("OPTIONS")) != NULL)
parse_opts(sp);
strcpy(file_name, file);
clearok(cw, TRUE);
touchwin(cw);
noecho();
nonl();
while(playing)
{
do_daemons(BEFORE);
do_fuses(BEFORE);
command(); /* Command execution */
if (after)
do_after_effects();
}
fatal("");
return(FALSE);
}