summaryrefslogtreecommitdiffstats
path: root/cmd-if-shell.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 /cmd-if-shell.c
parent34804f2709a16dca45dc072fb53d03f79db61e51 (diff)
Add helpers for the simple case of parse string and add to command queue.
Diffstat (limited to 'cmd-if-shell.c')
-rw-r--r--cmd-if-shell.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index ab1b588d..75f462ad 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -65,13 +65,12 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
struct cmd_find_state *target = cmdq_get_target(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_if_shell_data *cdata;
- char *shellcmd, *cmd;
+ char *shellcmd, *cmd, *error;
const char *file;
- struct cmdq_item *new_item;
struct client *c = cmd_find_client(item, NULL, 1);
struct session *s = target->s;
struct cmd_parse_input pi;
- struct cmd_parse_result *pr;
+ enum cmd_parse_status status;
shellcmd = format_single_from_target(item, args->argv[0], c);
if (args_has(args, 'F')) {
@@ -91,19 +90,11 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
pi.c = c;
cmd_find_copy_state(&pi.fs, target);
- pr = cmd_parse_from_string(cmd, &pi);
- switch (pr->status) {
- case CMD_PARSE_EMPTY:
- break;
- case CMD_PARSE_ERROR:
- cmdq_error(item, "%s", pr->error);
- free(pr->error);
+ status = cmd_parse_and_insert(cmd, &pi, item, state, &error);
+ if (status == CMD_PARSE_ERROR) {
+ cmdq_error(item, "%s", error);
+ free(error);
return (CMD_RETURN_ERROR);
- case CMD_PARSE_SUCCESS:
- new_item = cmdq_get_command(pr->cmdlist, state);
- cmdq_insert_after(item, new_item);
- cmd_list_free(pr->cmdlist);
- break;
}
return (CMD_RETURN_NORMAL);
}