diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 952e1f5b8..4727c5b06 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -2211,6 +2211,7 @@ sound: add 'qtsound' soundlib implementation for use on any platform documentation: when building plain text Guidebook.txt from Guidebook.mn, avoid attempting to use CR font; change doesn't affect building Guidebook.ps which utilizes CR to get various instances of fixed-width text +Unix: implement SELF_RECOVER compile-time option, on by default on linux General New Features diff --git a/sys/unix/hints/linux.370 b/sys/unix/hints/linux.370 index 508785612..081ec8c8c 100755 --- a/sys/unix/hints/linux.370 +++ b/sys/unix/hints/linux.370 @@ -131,6 +131,7 @@ NHCFLAGS+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\" #NHCFLAGS+=-DTTY_SOUND_ESCCODES #NHCFLAGS+=-DNO_CHRONICLE #NHCFLAGS+=-DLIVELOG +NHCFLAGS+=-DSELF_RECOVER ifdef WANT_WIN_CURSES ifeq "$(HAVE_NCURSESW)" "1" NHCFLAGS+=-DCURSES_UNICODE diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 96669d23d..11aaa3e48 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -276,6 +276,9 @@ main(int argc, char *argv[]) } } } + if (gp.program_state.in_self_recover) { + gp.program_state.in_self_recover = FALSE; + } } if (!resuming) { diff --git a/sys/unix/unixunix.c b/sys/unix/unixunix.c index b02345274..f6f11dc11 100644 --- a/sys/unix/unixunix.c +++ b/sys/unix/unixunix.c @@ -102,8 +102,10 @@ eraseoldlocks(void) void getlock(void) { +#ifndef SELF_RECOVER static const char destroy_old_game_prompt[] = "There is already a game in progress under your name. Destroy old game?"; +#endif int i = 0, fd, c, too_old; const char *fq_lock; @@ -176,10 +178,27 @@ getlock(void) if (too_old && eraseoldlocks()) goto gotlock; + /* drop the "perm" lock while the user decides */ + unlock_file(HLOCK); if (iflags.window_inited) { +#ifdef SELF_RECOVER + c = yn_function("Old game in progress. Destroy [y], Recover [r], or Cancel [n]?", "ynr", 'n', FALSE); +#else /* this is a candidate for paranoid_confirmation */ c = y_n(destroy_old_game_prompt); +#endif } else { +#ifdef SELF_RECOVER + (void) raw_printf("\nThere is already a game in progress under your name. Do what?\n"); + (void) raw_printf("\n y - Destroy old game"); + (void) raw_printf("\n r - Try to recover it"); + (void) raw_printf("\n n - Cancel"); + (void) raw_printf("\n\n => "); + (void) fflush(stdout); + do { + c = getchar(); + } while (!strchr("rRyYnN", c) && c != -1); +#else (void) raw_printf("\n%s [yn] ", destroy_old_game_prompt); (void) fflush(stdout); if ((c = getchar()) != EOF) { @@ -190,7 +209,20 @@ getlock(void) while ((tmp = getchar()) != '\n' && tmp != EOF) ; /* eat rest of line and newline */ } +#endif } +#ifdef SELF_RECOVER + if (c == 'r' || c == 'R') { + if (recover_savefile() && gp.program_state.in_self_recover) { + set_levelfile_name(gl.lock, 0); + fq_lock = fqname(gl.lock, LEVELPREFIX, 0); + goto gotlock; + } else { + unlock_file(HLOCK); + error("Couldn't recover old game."); + } + } else +#endif if (c == 'y' || c == 'Y') { if (eraseoldlocks()) { goto gotlock;