Add helpers for the simple case of parse string and add to command queue.

This commit is contained in:
nicm
2020-04-13 18:59:41 +00:00
parent 34804f2709
commit 187277eaad
10 changed files with 135 additions and 163 deletions

View File

@ -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);
}