/* ### cmd.c ### */
+E char NDECL(randomkey);
E int NDECL(doconduct);
E int NDECL(domonability);
E char FDECL(cmd_from_func, (int NDECL((*))));
* behaviour of various NetHack functions and probably warrant
* a structure of their own elsewhere some day.
*/
+ boolean debug_fuzzer; /* fuzz testing */
boolean defer_plname; /* X11 hack: askname() might not set plname */
boolean herecmd_menu; /* use menu when mouseclick on yourself */
boolean invis_goldsym; /* gold symbol is ' '? */
continue;
}
- if (iflags.sanity_check)
+ if (iflags.sanity_check || iflags.debug_fuzzer)
sanity_check();
#ifdef CLIPPING
{
register int ch;
+ if (iflags.debug_fuzzer)
+ return randomkey();
if (!(ch = popch()))
ch = nhgetch();
return (char) ch;
STATIC_PTR int
wiz_panic(VOID_ARGS)
{
+ if (iflags.debug_fuzzer) {
+ u.uhp = u.uhpmax = 1000;
+ u.uen = u.uenmax = 1000;
+ return 0;
+ }
if (yn("Do you want to call panic() and end your game?") == 'y')
panic("Crash test.");
return 0;
return FALSE;
}
+char
+randomkey()
+{
+ static int i = 0;
+ char c;
+
+ switch (rn2(12)) {
+ default: c = '\033'; break;
+ case 0: c = '\n'; break;
+ case 1:
+ case 2:
+ case 3:
+ case 4: c = (char)(' ' + rn2((int)('~' - ' '))); break;
+ case 5: c = '\t'; break;
+ case 6: c = (char)('a' + rn2((int)('z' - 'a'))); break;
+ case 7: c = (char)('A' + rn2((int)('Z' - 'A'))); break;
+ case 8: c = extcmdlist[(i++) % SIZE(extcmdlist)].key; break;
+ case 9: c = '#'; break;
+ }
+
+ return c;
+}
+
int
ch2spkeys(c, start, end)
char c;
register int sym;
int x = u.ux, y = u.uy, mod = 0;
+ if (iflags.debug_fuzzer)
+ return randomkey();
if (*readchar_queue)
sym = *readchar_queue++;
else
return 1;
}
if (ledger_no(&u.uz) == 1) {
+ if (iflags.debug_fuzzer)
+ return 0;
if (yn("Beware, there will be no return! Still climb?") != 'y')
return 0;
}
int
done2()
{
+ if (iflags.debug_fuzzer)
+ return 0;
if (!paranoid_query(ParanoidQuit, "Really quit?")) {
#ifndef NO_SIGNAL
(void) signal(SIGINT, (SIG_RET_TYPE) done1);
/* XXX can we move this above the prints? Then we'd be able to
* suppress "it may be possible to rebuild" based on dosave0()
* or say it's NOT possible to rebuild. */
- if (program_state.something_worth_saving) {
+ if (program_state.something_worth_saving && !iflags.debug_fuzzer) {
set_error_savefile();
if (dosave0()) {
/* os/win port specific recover instructions */
bot();
}
+ if (iflags.debug_fuzzer) {
+ if (!(program_state.panicking || how == PANICKED)) {
+ savelife(how);
+ killer.name[0] = 0;
+ killer.format = 0;
+ return;
+ }
+ } else
if (how == ASCENDED || (!killer.name[0] && how == GENOCIDED))
killer.format = NO_KILLER_PREFIX;
/* Avoid killed by "a" burning or "a" starvation */
return;
#endif /* SIMPLE_MAIL */
#ifdef DEF_MAILREADER /* This implies that UNIX is defined */
+ if (iflags.debug_fuzzer)
+ return;
display_nhwindow(WIN_MESSAGE, FALSE);
if (!(mr = nh_getenv("MAILREADER")))
mr = DEF_MAILREADER;
{
struct mail_info *brdcst;
+ if (iflags.debug_fuzzer)
+ return;
if (u.uswallow || !flags.biff)
return;
Vsprintf(pbuf, s, VA_ARGS);
pbuf[BUFSZ - 1] = '\0'; /* sanity */
paniclog("impossible", pbuf);
+ if (iflags.debug_fuzzer)
+ panic(pbuf);
pline("%s", VA_PASS1(pbuf));
pline(VA_PASS1(
"Program in disorder! (Saving and reloading may fix this problem.)"));
int
dosave()
{
+ if (iflags.debug_fuzzer)
+ return 0;
clear_nhwindow(WIN_MESSAGE);
if (yn("Really save?") == 'n') {
clear_nhwindow(WIN_MESSAGE);
char buf[BUFSZ];
boolean force_dest = FALSE;
+ if (iflags.debug_fuzzer)
+ goto random_levtport;
if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz))
&& !wizard) {
You_feel("very disoriented for a moment.");
killer.name[0] = 0; /* still alive, so far... */
+ if (iflags.debug_fuzzer && newlev < 0)
+ goto random_levtport;
if (newlev < 0 && !force_dest) {
if (*u.ushops0) {
/* take unpaid inventory items off of shop bills */
coord cc;
DWORD count;
really_move_cursor();
+ if (iflags.debug_fuzzer)
+ return randomkey();
return (program_state.done_hup)
? '\033'
: keyboard_handler.pCheckInput(
coord cc;
DWORD count;
really_move_cursor();
+ if (iflags.debug_fuzzer)
+ return randomkey();
ch = (program_state.done_hup)
? '\033'
: keyboard_handler.pCheckInput(
void
tty_nhbell()
{
- if (flags.silent)
+ if (flags.silent || iflags.debug_fuzzer)
return;
Beep(8000, 500);
}
clock_t goal;
int k;
+ if (iflags.debug_fuzzer)
+ return;
+
goal = 50 + clock();
back_buffer_flip();
while (goal > clock()) {
#if defined(MICRO)
register int i;
#endif
+ if (iflags.debug_fuzzer)
+ return;
#ifdef TIMED_DELAY
if (flags.nap) {
(void) fflush(stdout);
/* avoid recursion -- only happens from interrupts */
if (ttyDisplay->inmore++)
return;
+ if (iflags.debug_fuzzer)
+ return;
if (ttyDisplay->toplin) {
tty_curs(BASE_WINDOW, cw->curx + 1, cw->cury);
*/
if (WIN_MESSAGE != WIN_ERR && wins[WIN_MESSAGE])
wins[WIN_MESSAGE]->flags &= ~WIN_STOP;
+ if (iflags.debug_fuzzer) {
+ i = randomkey();
+ } else {
#ifdef UNIX
i = (++nesting == 1) ? tgetch()
: (read(fileno(stdin), (genericptr_t) &nestbuf, 1)
#else
i = tgetch();
#endif
+ }
if (!i)
i = '\033'; /* map NUL to ESC since nethack doesn't expect NUL */
else if (i == EOF)