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: #include <sys/cdefs.h>
33: #ifndef lint
34: #if 0
35: static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
36: #else
37: __RCSID("$NetBSD: save.c,v 1.11 2003/08/07 09:37:26 agc Exp $");
38: #endif
39: #endif
40:
41: #include <time.h>
42:
43: #include "mille.h"
44:
45: #ifndef unctrl
46: #include "unctrl.h"
47: #endif
48:
49:
50:
51:
52:
53: typedef struct stat STAT;
54:
55:
56:
57:
58:
59: bool
60: save()
61: {
62: char *sp;
63: int outf;
64: time_t *tp;
65: char buf[80];
66: time_t tme;
67: STAT junk;
68: bool rv;
69:
70: sp = NULL;
71: tp = &tme;
72: if (Fromfile && getyn(SAMEFILEPROMPT))
73: strcpy(buf, Fromfile);
74: else {
75: over:
76: prompt(FILEPROMPT);
77: leaveok(Board, FALSE);
78: refresh();
79: sp = buf;
80: while ((*sp = readch()) != '\n' && *sp != '\r') {
81: if (*sp == killchar())
82: goto over;
83: else if (*sp == erasechar()) {
84: if (--sp < buf)
85: sp = buf;
86: else {
87: addch('\b');
88:
89:
90:
91:
92: if (*sp < ' ')
93: addch('\b');
94: clrtoeol();
95: }
96: }
97: else {
98: addstr(unctrl(*sp));
99: ++sp;
100: }
101: refresh();
102: }
103: *sp = '\0';
104: leaveok(Board, TRUE);
105: }
106:
107:
108:
109:
110:
111: if (sp == buf || (!Fromfile && stat(buf, &junk) > -1
112: && getyn(OVERWRITEFILEPROMPT) == FALSE))
113: return FALSE;
114:
115: if ((outf = creat(buf, 0644)) < 0) {
116: error(strerror(errno));
117: return FALSE;
118: }
119: mvwaddstr(Score, ERR_Y, ERR_X, buf);
120: wrefresh(Score);
121: time(tp);
122: rv = varpush(outf, writev);
123: close(outf);
124: if (rv == FALSE) {
125: unlink(buf);
126: } else {
127: strcpy(buf, ctime(tp));
128: for (sp = buf; *sp != '\n'; sp++)
129: continue;
130: *sp = '\0';
131: wprintw(Score, " [%s]", buf);
132: }
133: wclrtoeol(Score);
134: wrefresh(Score);
135: return rv;
136: }
137:
138:
139:
140:
141:
142:
143: bool
144: rest_f(file)
145: const char *file;
146: {
147:
148: char *sp;
149: int inf;
150: char buf[80];
151: STAT sbuf;
152:
153: if ((inf = open(file, O_RDONLY)) < 0) {
154: warn("%s", file);
155: exit(1);
156: }
157: if (fstat(inf, &sbuf) < 0) {
158: warn("%s", file);
159: exit(1);
160: }
161: varpush(inf, readv);
162: close(inf);
163: strcpy(buf, ctime(&sbuf.st_mtime));
164: for (sp = buf; *sp != '\n'; sp++)
165: continue;
166: *sp = '\0';
167:
168:
169:
170: (void)sprintf(Initstr, "%s [%s]\n", file, buf);
171: Fromfile = file;
172: return !On_exit;
173: }