* Copyright (c) 1983 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)save.c 5.7 (Berkeley) %G%";
# define _tty cur_term->Nttyb
* @(#)save.c 1.2 (Berkeley) 3/28/83
typedef struct stat STAT
;
* This routine saves the current game for use at a later date
if (Fromfile
&& getyn(SAMEFILEPROMPT
))
while ((*sp
= readch()) != '\n') {
else if (*sp
== erasechar()) {
* 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(OVERWRITEFILEPROMPT
) == FALSE
))
if ((outf
= creat(buf
, 0644)) < 0) {
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
(void)sprintf(Initstr
, "%s [%s]\n", file
, buf
);