static char sccsid
[] = "@(#)save.c 4.1 12/24/82";
typedef struct stat STAT
;
* This routine saves the current game for use at a later date
extern char *sys_errlist
[];
if (Fromfile
&& getyn("Same file? "))
mvaddstr(MOVE_Y
, MOVE_X
, "file: ");
while ((*sp
= getch()) != '\n') {
else if (*sp
== _tty
.sg_erase
) {
* if the previous char was a control
* char, cover up two characters.
* check for existing files, and confirm overwrite if needed
if (sp
== buf
|| (!Fromfile
&& stat(buf
, &junk
) > -1
&& getyn("Overwrite File? ") == FALSE
))
if ((outf
= creat(buf
, 0644)) < 0) {
error(sys_errlist
[errno
]);
mvwaddstr(Score
, ERR_Y
, ERR_X
, buf
);
time(tp
); /* get current time */
for (sp
= buf
; *sp
!= '\n'; sp
++)
wprintw(Score
, " [%s]", buf
);
* This does the actual restoring. It returns TRUE if the
* backup was made on exiting, in which case certain things must
* be cleaned up before the game starts.
if ((inf
= open(file
, 0)) < 0) {
if (fstat(inf
, &sbuf
) < 0) { /* get file stats */
strcpy(buf
, ctime(&sbuf
.st_mtime
));
for (sp
= buf
; *sp
!= '\n'; sp
++)
* initialize some necessary values
sprintf(Initstr
, "%s [%s]\n", file
, buf
);