From 7b1c38499dbbf5c9fd4b692917b0fbf359afe5ac Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 4 Jul 2019 15:56:08 -0700 Subject: [PATCH 1/2] curses prompting tweak With 'popup_dialog' On, a prompt which exactly fills the available width would start the next line with a space (to separate the prompt from user's answer) and then have the cursor waiting after it. That's unlike other behavior in the curses interface where the line split would be instead of the separating space rather than in addition to it. Old: |long prompt?| | X__________| New: |long prompt?| |X___________| where the X represents the cursor sitting over the start of blank space waiting for user's answer. --- win/curses/cursdial.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/win/curses/cursdial.c b/win/curses/cursdial.c index ccd962fc1..7dccffa78 100644 --- a/win/curses/cursdial.c +++ b/win/curses/cursdial.c @@ -125,9 +125,7 @@ curses_line_input_dialog(const char *prompt, char *answer, int buffer) int map_height, map_width, maxwidth, remaining_buf, winx, winy, count; WINDOW *askwin, *bwin; char *tmpstr; - int prompt_width = (int) strlen(prompt) + buffer + 1; - int prompt_height = 1; - int height = prompt_height; + int prompt_width, prompt_height = 1, height = prompt_height; char input[BUFSZ]; /* if messages were being suppressed for the remainder of the turn, @@ -136,6 +134,8 @@ curses_line_input_dialog(const char *prompt, char *answer, int buffer) if (buffer > (int) sizeof input) buffer = (int) sizeof input; + /* +1: space between prompt and answer; buffer already accounts for \0 */ + prompt_width = (int) strlen(prompt) + 1 + buffer; maxwidth = term_cols - 2; if (iflags.window_inited) { @@ -163,23 +163,20 @@ curses_line_input_dialog(const char *prompt, char *answer, int buffer) free(tmpstr); } - if (iflags.window_inited) { - bwin = curses_create_window(prompt_width, height, UP); - wrefresh(bwin); - getbegyx(bwin, winy, winx); - askwin = newwin(height, prompt_width, winy + 1, winx + 1); - } else { - bwin = curses_create_window(prompt_width, height, CENTER); - wrefresh(bwin); - getbegyx(bwin, winy, winx); - askwin = newwin(height, prompt_width, winy + 1, winx + 1); - } + bwin = curses_create_window(prompt_width, height, + iflags.window_inited ? UP : CENTER); + wrefresh(bwin); + getbegyx(bwin, winy, winx); + askwin = newwin(height, prompt_width, winy + 1, winx + 1); + for (count = 0; count < prompt_height; count++) { tmpstr = curses_break_str(prompt, maxwidth, count + 1); - if (count == (prompt_height - 1)) { /* Last line */ - mvwprintw(askwin, count, 0, "%s ", tmpstr); - } else { - mvwaddstr(askwin, count, 0, tmpstr); + mvwaddstr(askwin, count, 0, tmpstr); + if (count == prompt_height - 1) { /* Last line */ + if ((int) strlen(tmpstr) < maxwidth) + waddch(askwin, ' '); + else + wmove(askwin, count + 1, 0); } free(tmpstr); } @@ -188,7 +185,7 @@ curses_line_input_dialog(const char *prompt, char *answer, int buffer) curs_set(1); wgetnstr(askwin, input, buffer - 1); curs_set(0); - strcpy(answer, input); + Strcpy(answer, input); werase(bwin); delwin(bwin); curses_destroy_win(askwin); From f75deae0bcca5bdd4afddb40291e5e2bb0ecd846 Mon Sep 17 00:00:00 2001 From: Bart House Date: Thu, 4 Jul 2019 18:06:56 -0700 Subject: [PATCH 2/2] When fuzzing, use the number of moves as a proxy for the hour. Every 1000 moves simulates one hour. --- src/hacklib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hacklib.c b/src/hacklib.c index 7cf5a47c6..b97a78a65 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -1129,7 +1129,8 @@ friday_13th() int night() { - register int hour = getlt()->tm_hour; + register int hour = (iflags.debug_fuzzer ? (moves / 1000) % 24 : + getlt()->tm_hour); return (hour < 6 || hour > 21); } @@ -1137,7 +1138,10 @@ night() int midnight() { - return (getlt()->tm_hour == 0); + register int hour = (iflags.debug_fuzzer ? (moves / 1000) % 24 : + getlt()->tm_hour); + + return (hour == 0); } /* strbuf_init() initializes strbuf state for use */