Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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[])
Expand Down
Loading