diff --git a/console.c b/console.c index 2f27db6ad..6ba021467 100644 --- a/console.c +++ b/console.c @@ -160,12 +160,43 @@ static char **parse_args(char *line, int *argcp) return argv; } +/* Handles forced console termination for record_error and do_quit */ +static bool force_quit(int argc, char *argv[]) +{ + cmd_element_t *c = cmd_list; + bool ok = true; + while (c) { + cmd_element_t *ele = c; + c = c->next; + free_block(ele, sizeof(cmd_element_t)); + } + + param_element_t *p = param_list; + while (p) { + param_element_t *ele = p; + p = p->next; + free_block(ele, sizeof(param_element_t)); + } + + while (buf_stack) + pop_file(); + + for (int i = 0; i < quit_helper_cnt; i++) { + ok = ok && quit_helpers[i](argc, argv); + } + + quit_flag = true; + return ok; +} + static void record_error() { err_cnt++; if (err_cnt >= err_limit) { - report(1, "Error limit exceeded. Stopping command execution"); - quit_flag = true; + report( + 1, + "Error limit exceeded. Stopping command execution, and quitting"); + force_quit(0, NULL); } } @@ -226,30 +257,7 @@ void set_echo(bool on) /* Built-in commands */ static bool do_quit(int argc, char *argv[]) { - cmd_element_t *c = cmd_list; - bool ok = true; - while (c) { - cmd_element_t *ele = c; - c = c->next; - free_block(ele, sizeof(cmd_element_t)); - } - - param_element_t *p = param_list; - while (p) { - param_element_t *ele = p; - p = p->next; - free_block(ele, sizeof(param_element_t)); - } - - while (buf_stack) - pop_file(); - - for (int i = 0; i < quit_helper_cnt; i++) { - ok = ok && quit_helpers[i](argc, argv); - } - - quit_flag = true; - return ok; + return force_quit(argc, argv); } static bool do_help(int argc, char *argv[])