From 0c8fe019ddaea7c80bd7a72bab958b729019991d Mon Sep 17 00:00:00 2001 From: Darshan Shaligram Date: Mon, 4 Jan 2010 03:43:02 +0530 Subject: Fix Crawl assert if user tries to repeat a command with Enter macroed to \{13} (Eifeltrampel). --- crawl-ref/source/main.cc | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'crawl-ref/source/main.cc') diff --git a/crawl-ref/source/main.cc b/crawl-ref/source/main.cc index fd4dd7b94e..1ccf335ed8 100644 --- a/crawl-ref/source/main.cc +++ b/crawl-ref/source/main.cc @@ -4259,6 +4259,13 @@ static int _get_num_and_char(const char* prompt, char* buf, int buf_len) return reader.read_line(true); } +static void _cancel_cmd_repeat() +{ + crawl_state.cancel_cmd_again(); + crawl_state.cancel_cmd_repeat(); + flush_input_buffer(FLUSH_REPLAY_SETUP_FAILURE); +} + static void _setup_cmd_repeat() { if (is_processing_macro()) @@ -4287,9 +4294,7 @@ static void _setup_cmd_repeat() { // Was just a single ESCAPE key, so not a macro trigger. canned_msg( MSG_OK ); - crawl_state.cancel_cmd_again(); - crawl_state.cancel_cmd_repeat(); - flush_input_buffer(FLUSH_REPLAY_SETUP_FAILURE); + _cancel_cmd_repeat(); return; } ch = getchm(); @@ -4312,9 +4317,7 @@ static void _setup_cmd_repeat() // Wasn't a macro trigger, just an ordinary escape. canned_msg( MSG_OK ); - crawl_state.cancel_cmd_again(); - crawl_state.cancel_cmd_repeat(); - flush_input_buffer(FLUSH_REPLAY_SETUP_FAILURE); + _cancel_cmd_repeat(); return; } // *WAS* a macro trigger, keep going. @@ -4323,11 +4326,7 @@ static void _setup_cmd_repeat() if (strlen(buf) == 0) { mpr("You must enter the number of times for the command to repeat."); - - crawl_state.cancel_cmd_again(); - crawl_state.cancel_cmd_repeat(); - flush_input_buffer(FLUSH_REPLAY_SETUP_FAILURE); - + _cancel_cmd_repeat(); return; } @@ -4339,9 +4338,7 @@ static void _setup_cmd_repeat() if (count <= 0) { canned_msg( MSG_OK ); - crawl_state.cancel_cmd_again(); - crawl_state.cancel_cmd_repeat(); - flush_input_buffer(FLUSH_REPLAY_SETUP_FAILURE); + _cancel_cmd_repeat(); return; } @@ -4370,7 +4367,7 @@ static void _setup_cmd_repeat() if (!crawl_state.doing_prev_cmd_again) repeat_again_rec.keys.pop_back(); - mpr("Enter command to be repeated: "); + mpr("Enter command to be repeated: ", MSGCH_PROMPT); // Enable the cursor to read input. cursor_control con(true); @@ -4388,9 +4385,7 @@ static void _setup_cmd_repeat() if (!is_processing_macro() && !_cmd_is_repeatable(cmd)) { - crawl_state.cancel_cmd_again(); - crawl_state.cancel_cmd_repeat(); - flush_input_buffer(FLUSH_REPLAY_SETUP_FAILURE); + _cancel_cmd_repeat(); return; } @@ -4413,7 +4408,12 @@ static void _setup_cmd_repeat() while (isdigit(ch) || ch == ' ' || ch == CK_ENTER) { keys.pop_back(); - ASSERT(keys.size() > 0); + // Handle the case where the user has macroed enter to itself. + if (keys.empty()) + { + _cancel_cmd_repeat(); + return; + } ch = keys[keys.size() - 1]; } } -- cgit v1.2.3-54-g00ecf