~ecs/sd

62d1c8017b5661cd1b237ae29426259a11087127 — Eyal Sawady 9 months ago 3377c5c
registry: move not-found handling to process_cmd

This allows registries to be reused for normal mode
2 files changed, 18 insertions(+), 10 deletions(-)

M common.c
M input.c
M common.c => common.c +1 -8
@@ 252,7 252,6 @@ int
run_command(struct state *state, const char *cmd)
{
	size_t i;
	char *buf;
	for (i = 0; i < state->reg.sz; i++) {
		if (!strcmp(cmd, state->reg.contents[i].cmd)) {
			set_row(&state->status, "");


@@ 260,11 259,5 @@ run_command(struct state *state, const char *cmd)
		}
	}

	buf = malloc(strlen(cmd) + 1);
	strcpy(buf, cmd);
	set_row(&state->status, "Error: invalid command: '");
	append_row(&state->status, buf);
	append_row(&state->status, "'");
	free(buf);
	return 0;
	return -2;
}

M input.c => input.c +17 -2
@@ 157,8 157,23 @@ process_cmd(char c, struct state *state) {
		break;
	case '\r':
	case '\n':
		state->mode = NORMAL;
		return run_command(state, state->status.contents + 1);
		{
			char *ssc = state->status.contents;
			int ret =
				run_command(state, ssc + 1);
			state->mode = NORMAL;
			if (ret == -2) {
				/* +1 for NULL, -1 for ':' */
				char *buf = malloc(strlen(ssc));
				strcpy(buf, ssc + 1);
				set_row(&state->status, "Invalid command: '");
				append_row(&state->status, buf);
				append_row(&state->status, "'");
				free(buf);
				return 0;
			}
			return ret;
		}
	default:
		{
			char buf[2] = {0, 0};