summaryrefslogtreecommitdiffstats
path: root/mode-tree.c
diff options
context:
space:
mode:
authornicm <nicm>2020-04-13 18:59:41 +0000
committernicm <nicm>2020-04-13 18:59:41 +0000
commit187277eaadc4a675659bf7ede88f50bfe6cc7be9 (patch)
treec8bc4105ea95d9cc1111e60ec84172f5e25dfa3a /mode-tree.c
parent34804f2709a16dca45dc072fb53d03f79db61e51 (diff)
Add helpers for the simple case of parse string and add to command queue.
Diffstat (limited to 'mode-tree.c')
-rw-r--r--mode-tree.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/mode-tree.c b/mode-tree.c
index d9af2ee3..0177d618 100644
--- a/mode-tree.c
+++ b/mode-tree.c
@@ -1063,36 +1063,22 @@ void
mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
const char *template, const char *name)
{
- struct cmdq_item *new_item;
- struct cmdq_state *new_state;
- char *command;
- struct cmd_parse_result *pr;
+ struct cmdq_state *state;
+ char *command, *error;
+ enum cmd_parse_status status;
command = cmd_template_replace(template, name, 1);
- if (command == NULL || *command == '\0') {
- free(command);
- return;
- }
-
- pr = cmd_parse_from_string(command, NULL);
- switch (pr->status) {
- case CMD_PARSE_EMPTY:
- break;
- case CMD_PARSE_ERROR:
- if (c != NULL) {
- *pr->error = toupper((u_char)*pr->error);
- status_message_set(c, "%s", pr->error);
+ if (command != NULL && *command != '\0') {
+ state = cmdq_new_state(fs, NULL, 0);
+ status = cmd_parse_and_append(command, NULL, c, state, &error);
+ if (status == CMD_PARSE_ERROR) {
+ if (c != NULL) {
+ *error = toupper((u_char)*error);
+ status_message_set(c, "%s", error);
+ }
+ free(error);
}
- free(pr->error);
- break;
- case CMD_PARSE_SUCCESS:
- new_state = cmdq_new_state(fs, NULL, 0);
- new_item = cmdq_get_command(pr->cmdlist, new_state);
- cmdq_free_state(new_state);
- cmdq_append(c, new_item);
- cmd_list_free(pr->cmdlist);
- break;
+ cmdq_free_state(state);
}
-
free(command);
}