]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - mille/save.c
This patch cleans up the handling of the variable `saved' in
[bsdgames-darwin.git] / mille / save.c
index 0467454a3616434c778d5fb3292f70c4508becbd..3715f7b0ae84e4f863ee8c27c8b7f985d56a10fc 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: save.c,v 1.7 1999/03/29 05:12:39 mrg Exp $     */
+
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static char sccsid[] = "@(#)save.c     5.6 (Berkeley) 6/1/90";
+#if 0
+static char sccsid[] = "@(#)save.c     8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: save.c,v 1.7 1999/03/29 05:12:39 mrg Exp $");
+#endif
 #endif /* not lint */
 
-#include       "mille.h"
-#include       <sys/types.h>
-#include       <sys/stat.h>
-#include       <string.h>
+#include "mille.h"
+
 #ifndef        unctrl
-#include       "unctrl.h"
+#include "unctrl.h"
 #endif
 
-# ifdef        attron
-#      include <term.h>
-#      define  _tty    cur_term->Nttyb
-# endif        attron
-
 /*
  * @(#)save.c  1.2 (Berkeley) 3/28/83
  */
 
 typedef        struct stat     STAT;
 
-char   *ctime();
-
-int    read(), write();
-
 /*
  *     This routine saves the current game for use at a later date
+ *     Returns FALSE if it couldn't be done.
  */
-
-save() {
-
-       extern int      errno;
-       reg char        *sp;
-       reg int         outf;
-       reg time_t      *tp;
-       char            buf[80];
-       time_t          tme;
-       STAT            junk;
-
+bool
+save()
+{
+       char    *sp;
+       int     outf;
+       time_t  *tp;
+       char    buf[80];
+       time_t  tme;
+       STAT    junk;
+       bool    rv;
+
+       sp = NULL;
        tp = &tme;
        if (Fromfile && getyn(SAMEFILEPROMPT))
                strcpy(buf, Fromfile);
@@ -123,16 +121,20 @@ over:
        mvwaddstr(Score, ERR_Y, ERR_X, buf);
        wrefresh(Score);
        time(tp);                       /* get current time             */
-       strcpy(buf, ctime(tp));
-       for (sp = buf; *sp != '\n'; sp++)
-               continue;
-       *sp = '\0';
-       varpush(outf, write);
+       rv = varpush(outf, writev);
        close(outf);
-       wprintw(Score, " [%s]", buf);
+       if (rv == FALSE) {
+               unlink(buf);
+       } else {
+               strcpy(buf, ctime(tp));
+               for (sp = buf; *sp != '\n'; sp++)
+                       continue;
+               *sp = '\0';
+               wprintw(Score, " [%s]", buf);
+       }
        wclrtoeol(Score);
        wrefresh(Score);
-       return TRUE;
+       return rv;
 }
 
 /*
@@ -140,23 +142,25 @@ over:
  * backup was made on exiting, in which case certain things must
  * be cleaned up before the game starts.
  */
+bool
 rest_f(file)
-reg char       *file; {
+       char    *file;
+{
 
-       reg char        *sp;
-       reg int         inf;
-       char            buf[80];
-       STAT            sbuf;
+       char    *sp;
+       int     inf;
+       char    buf[80];
+       STAT    sbuf;
 
        if ((inf = open(file, 0)) < 0) {
-               perror(file);
+               warn("%s", file);
                exit(1);
        }
        if (fstat(inf, &sbuf) < 0) {            /* get file stats       */
-               perror(file);
+               warn("%s", file);
                exit(1);
        }
-       varpush(inf, read);
+       varpush(inf, readv);
        close(inf);
        strcpy(buf, ctime(&sbuf.st_mtime));
        for (sp = buf; *sp != '\n'; sp++)
@@ -169,4 +173,3 @@ reg char    *file; {
        Fromfile = file;
        return !On_exit;
 }
-