1 /* NetHack 3.6 pcunix.c $NHDT-Date: 1432512787 2015/05/25 00:13:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Michael Allison, 2006. */
4 /* NetHack may be freely redistributed. See license for details. */
6 /* This file collects some Unix dependencies; pager.c contains some more */
20 #if defined(TTY_GRAPHICS)
21 extern void NDECL(backsp);
22 extern void NDECL(clear_screen);
26 static struct stat buf;
30 static struct stat hbuf;
34 static int NDECL(eraseoldlocks);
44 pline("Cannot get status of saved level? ");
47 if(buf.st_mtime < hbuf.st_mtime) {
48 pline("Saved level is out of date. ");
52 #if (defined(MICRO)) && !defined(NO_FSTAT)
54 if(moves > 1) pline("Cannot get status of saved level? ");
55 else pline("Cannot get status of saved game.");
58 if(comp_times(buf.st_mtime)) {
59 if(moves > 1) pline("Saved level is out of date.");
60 else pline("Saved game is out of date. ");
61 /* This problem occurs enough times we need to give the player
62 * some more information about what causes it, and how to fix.
65 pline("Make sure that your system's date and time are correct.");
66 pline("They must be more current than NetHack.EXE's date/time stamp.");
71 #endif /* WANT_GETHDATE */
82 /* cannot use maxledgerno() here, because we need to find a lock name
83 * before starting everything (including the dungeon initialization
84 * that sets astral_level, needed for maxledgerno()) up
86 for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
87 /* try to remove all */
88 set_levelfile_name(lock, i);
89 (void) unlink(fqname(lock, LEVELPREFIX, 0));
91 set_levelfile_name(lock, 0);
92 #ifdef HOLD_LOCKFILE_OPEN
95 if (unlink(fqname(lock, LEVELPREFIX, 0)))
96 return 0; /* cannot remove it */
97 return (1); /* success! */
103 register int fd, c, ci, ct, ern;
107 #if defined(MSDOS) && defined(NO_TERMS)
108 int grmode = iflags.grmode;
110 /* we ignore QUIT and INT at this point */
111 if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
113 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
119 /* regularize(lock); */ /* already done in pcmain */
120 Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0));
121 set_levelfile_name(lock, 0);
122 fq_lock = fqname(lock, LEVELPREFIX, 1);
123 if ((fd = open(fq_lock, 0)) == -1) {
125 goto gotlock; /* no such file */
126 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
131 error("Cannot open %s", fq_lock);
136 if (iflags.window_inited) {
138 c = yn("There are files from a game in progress under your name. "
141 pline("There is already a game in progress under your name.");
142 pline("You may be able to use \"recover %s\" to get it back.\n",
144 c = yn("Do you want to destroy the old game?");
147 #if defined(MSDOS) && defined(NO_TERMS)
148 grmode = iflags.grmode;
155 msmsg("There are files from a game in progress under your name. "
158 msmsg("\nThere is already a game in progress under your name.\n");
159 msmsg("If this is unexpected, you may be able to use \n");
160 msmsg("\"recover %s\" to get it back.", tbuf);
161 msmsg("\nDo you want to destroy the old game? [yn] ");
163 while ((ci = nhgetch()) != '\n') {
169 if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
176 if (c == 'y' || c == 'Y')
178 if (eraseoldlocks()) {
182 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
185 error("Couldn't destroy old game.");
187 #else /*SELF_RECOVER*/
188 if (recover_savefile()) {
189 #if defined(TTY_GRAPHICS)
190 if (WINDOWPORT("tty"))
191 clear_screen(); /* display gets fouled up otherwise */
196 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
199 error("Couldn't recover old game.");
201 #endif /*SELF_RECOVER*/
204 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
207 error("%s", "Cannot start a new game.");
211 fd = creat(fq_lock, fcmask);
216 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
219 error("cannot creat file (%s.)", fq_lock);
221 if (write(fd, (char *) &hackpid, sizeof(hackpid))
222 != sizeof(hackpid)) {
223 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
226 error("cannot write lock (%s)", fq_lock);
228 if (nhclose(fd) == -1) {
229 #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
232 error("cannot close lock (%s)", fq_lock);
235 #if defined(MSDOS) && defined(NO_TERMS)
240 #endif /* PC_LOCKING */
245 * normalize file name - we don't like .'s, /'s, spaces, and
246 * lots of other things
253 register unsigned char *lp;
255 for (lp = s; *lp; lp++)
256 if (*lp <= ' ' || *lp == '"' || (*lp >= '*' && *lp <= ',')
257 || *lp == '.' || *lp == '/' || (*lp >= ':' && *lp <= '?') ||
259 *lp == '&' || *lp == '(' || *lp == ')' ||
261 *lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']'))