1: #include    "mille.h"
   2: #include    <sys/types.h>
   3: #include    <sys/stat.h>
   4: #ifndef unctrl
   5: #include    "unctrl.h"
   6: #endif
   7: 
   8: # ifdef attron
   9: #	include   <term.h>
  10: #	define    _tty    cur_term->Nttyb
  11: # endif	attron
  12: 
  13: /*
  14:  * @(#)save.c	1.2 (Berkeley) 3/28/83
  15:  */
  16: 
  17: typedef struct stat STAT;
  18: 
  19: char    *ctime();
  20: 
  21: int read(), write();
  22: 
  23: /*
  24:  *	This routine saves the current game for use at a later date
  25:  */
  26: extern int  errno;
  27: extern char *sys_errlist[];
  28: 
  29: save() {
  30: 
  31:     reg char    *sp;
  32:     reg int     outf;
  33:     reg time_t  *tp;
  34:     char        buf[80];
  35:     time_t      tme;
  36:     STAT        junk;
  37: 
  38:     tp = &tme;
  39:     if (Fromfile && getyn(SAMEFILEPROMPT))
  40:         strcpy(buf, Fromfile);
  41:     else {
  42: over:
  43:         prompt(FILEPROMPT);
  44:         leaveok(Board, FALSE);
  45:         refresh();
  46:         sp = buf;
  47:         while ((*sp = readch()) != '\n') {
  48:             if (*sp == killchar())
  49:                 goto over;
  50:             else if (*sp == erasechar()) {
  51:                 if (--sp < buf)
  52:                     sp = buf;
  53:                 else {
  54:                     addch('\b');
  55:                     /*
  56: 					 * if the previous char was a control
  57: 					 * char, cover up two characters.
  58: 					 */
  59:                     if (*sp < ' ')
  60:                         addch('\b');
  61:                     clrtoeol();
  62:                 }
  63:             }
  64:             else
  65:                 addstr(unctrl(*sp++));
  66:             refresh();
  67:         }
  68:         *sp = '\0';
  69:         leaveok(Board, TRUE);
  70:     }
  71: 
  72:     /*
  73: 	 * check for existing files, and confirm overwrite if needed
  74: 	 */
  75: 
  76:     if (sp == buf || (!Fromfile && stat(buf, &junk) > -1
  77:         && getyn(OVERWRITEFILEPROMPT) == FALSE))
  78:         return FALSE;
  79: 
  80:     if ((outf = creat(buf, 0644)) < 0) {
  81:         error(sys_errlist[errno]);
  82:         return FALSE;
  83:     }
  84:     mvwaddstr(Score, ERR_Y, ERR_X, buf);
  85:     wrefresh(Score);
  86:     time(tp);           /* get current time		*/
  87:     strcpy(buf, ctime(tp));
  88:     for (sp = buf; *sp != '\n'; sp++)
  89:         continue;
  90:     *sp = '\0';
  91:     varpush(outf, write);
  92:     close(outf);
  93:     wprintw(Score, " [%s]", buf);
  94:     wclrtoeol(Score);
  95:     wrefresh(Score);
  96:     return TRUE;
  97: }
  98: 
  99: /*
 100:  *	This does the actual restoring.  It returns TRUE if the
 101:  * backup was made on exiting, in which case certain things must
 102:  * be cleaned up before the game starts.
 103:  */
 104: rest_f(file)
 105: reg char    *file; {
 106: 
 107:     reg char    *sp;
 108:     reg int     inf;
 109:     char        buf[80];
 110:     STAT        sbuf;
 111: 
 112:     if ((inf = open(file, 0)) < 0) {
 113:         perror(file);
 114:         exit(1);
 115:     }
 116:     if (fstat(inf, &sbuf) < 0) {        /* get file stats	*/
 117:         perror(file);
 118:         exit(1);
 119:     }
 120:     varpush(inf, read);
 121:     close(inf);
 122:     strcpy(buf, ctime(&sbuf.st_mtime));
 123:     for (sp = buf; *sp != '\n'; sp++)
 124:         continue;
 125:     *sp = '\0';
 126:     /*
 127: 	 * initialize some necessary values
 128: 	 */
 129:     sprintf(Initstr, "%s [%s]\n", file, buf);
 130:     Fromfile = file;
 131:     return !On_exit;
 132: }

Defined functions

rest_f defined in line 104; used 1 times
save defined in line 29; used 3 times

Defined typedef's

STAT defined in line 17; used 2 times

Defined macros

_tty defined in line 10; never used
Last modified: 1986-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1226
Valid CSS Valid XHTML 1.0 Strict