hangup revamp (trunk only)

[See cvs log for src/cmd.c for more complete description.]

     This turns clearlocks() into a no-op during the period when the UNIX
port is asking the user to confirm whether to overwrite an existing game.
Also, this removes the duplication of code and function between hangup()
and end_of_input(), and it simplifies the check for whether hangups are
supported by adding new macro HANGUPHANDLING.  (I don't think global.h is
the best place to be defining that but I couldn't figure out where else
it would fit, other than repeating for individual xxxconf.h files.)  And
adds a couple more done_hup checks to try to cope with situations where
rhack() is being bypassed.  Lastly, having readchar() return EOF was
ignored for non-UNIX configs; now everybody gets ESC instead of letting
EOF be seen further inside the core.
This commit is contained in:
nethack.rankin
2007-01-16 04:54:38 +00:00
parent b01f1f804f
commit 151dcad8fa
11 changed files with 53 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)allmain.c 3.5 2006/11/27 */
/* SCCS Id: @(#)allmain.c 3.5 2007/01/12 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -72,6 +72,9 @@ boolean resuming;
context.move = 0;
for(;;) {
#ifdef SAFERHANGUP
if (program_state.done_hup) end_of_input();
#endif
get_nh_event();
#ifdef POSITIONBAR
do_positionbar();

View File

@@ -556,20 +556,28 @@ int lev;
void
clearlocks()
{
#ifdef HANGUPHANDLING
if (program_state.preserve_locks) return;
#endif
#if !defined(PC_LOCKING) && defined(MFLOPPY) && !defined(AMIGA)
eraseall(levels, alllevels);
if (ramdisk)
eraseall(permbones, alllevels);
#else
{
register int x;
# ifndef NO_SIGNAL
(void) signal(SIGINT, SIG_IGN);
# endif
# if defined(UNIX) || defined(VMS)
sethanguphandler((void FDECL((*),(int)))SIG_IGN);
# endif
/* can't access maxledgerno() before dungeons are created -dlc */
for (x = (n_dgns ? maxledgerno() : 0); x >= 0; x--)
delete_levelfile(x); /* not all levels need be present */
#endif
}
#endif /* ?PC_LOCKING,&c */
}
#if defined(SELECTSAVED)

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)mon.c 3.5 2006/10/20 */
/* SCCS Id: @(#)mon.c 3.5 2007/01/12 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -581,6 +581,12 @@ movemon()
*/
for(mtmp = fmon; mtmp; mtmp = nmtmp) {
#ifdef SAFERHANGUP
if (program_state.done_hup) {
somebody_can_move = FALSE;
break;
}
#endif
nmtmp = mtmp->nmon;
if (DEADMONSTER(mtmp)) continue;

View File

@@ -119,7 +119,6 @@ dosave()
program_state.done_hup = 0;
#endif
if(dosave0()) {
program_state.something_worth_saving = 0;
u.uhp = -1; /* universal game's over indicator */
/* make sure they see the Saving message */
display_nhwindow(WIN_MESSAGE, TRUE);
@@ -130,35 +129,6 @@ dosave()
return 0;
}
#if defined(UNIX) || defined(VMS) || defined (__EMX__) || defined(WIN32)
/*ARGSUSED*/
void
hangup(sig_unused) /* called as signal() handler, so sent at least one arg */
int sig_unused;
{
# ifdef NOSAVEONHANGUP
(void) signal(SIGINT, SIG_IGN);
clearlocks();
terminate(EXIT_FAILURE);
# else /* SAVEONHANGUP */
if (!program_state.done_hup++) {
# ifndef SAFERHANGUP
/* When using SAFERHANGUP, the done_hup flag it tested in rhack
* and actual hangup behavior occurs then. This is 'safer'
* because it disallows certain cheats and also protects
* against losing objects in the process of being thrown. */
if (program_state.something_worth_saving)
(void) dosave0();
clearlocks();
terminate(EXIT_FAILURE);
# endif /* !SAFERHANGUP */
}
# endif /* !NOSAVEONHANGUP */
}
#endif
/* returns 1 if save successful */
int
dosave0()
@@ -169,7 +139,7 @@ dosave0()
d_level uz_save;
char whynot[BUFSZ];
if (!SAVEF[0])
if (!program_state.something_worth_saving || !SAVEF[0])
return 0;
fq_save = fqname(SAVEF, SAVEPREFIX, 1); /* level files take 0 */
@@ -316,6 +286,8 @@ dosave0()
delete_levelfile(ledger_no(&u.uz));
delete_levelfile(0);
nh_compress(fq_save);
/* this should probably come sooner... */
program_state.something_worth_saving = 0;
return(1);
}