From a1722d5c2e545e4cce376848aab8a39465d3a036 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 15:50:42 +0000 Subject: Remove unnecessary initializers of cmd_ctx. --- cmd-confirm-before.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'cmd-confirm-before.c') diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 16607d0e..5e3e4e12 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -108,7 +108,7 @@ cmd_confirm_before_callback(void *data, const char *s) struct cmd_confirm_before_data *cdata = data; struct client *c = cdata->c; struct cmd_list *cmdlist; - struct cmd_ctx ctx; + struct cmd_ctx *ctx; char *cause; if (s == NULL || *s == '\0') @@ -125,17 +125,15 @@ cmd_confirm_before_callback(void *data, const char *s) return (0); } - ctx.msgdata = NULL; - ctx.curclient = c; + ctx = cmd_get_ctx(); + ctx->curclient = c; + ctx->error = key_bindings_error; + ctx->print = key_bindings_print; + ctx->info = key_bindings_info; - ctx.error = key_bindings_error; - ctx.print = key_bindings_print; - ctx.info = key_bindings_info; - - ctx.cmdclient = NULL; - - cmd_list_exec(cmdlist, &ctx); + cmd_list_exec(cmdlist, ctx); cmd_list_free(cmdlist); + cmd_free_ctx(ctx); return (0); } -- cgit From 2243cfbe7559e6cf48194ff95dcd7eb6df5fe41d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 22 Mar 2013 15:54:29 +0000 Subject: Need to set clients in context before changing their reference count. --- cmd-confirm-before.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cmd-confirm-before.c') diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 5e3e4e12..f9491095 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -125,8 +125,7 @@ cmd_confirm_before_callback(void *data, const char *s) return (0); } - ctx = cmd_get_ctx(); - ctx->curclient = c; + ctx = cmd_get_ctx(NULL, c); ctx->error = key_bindings_error; ctx->print = key_bindings_print; ctx->info = key_bindings_info; -- cgit From bb8457b166635bc8d069012bb33d94e44178bfdc Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:27:19 +0000 Subject: Fix error reporting for client commands by adding a flag to cmd_find_client to tell it whether or not to show errors, sometimes it's needed and sometimes not. --- cmd-confirm-before.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd-confirm-before.c') diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index f9491095..765f58df 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -79,7 +79,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) return (CMD_RETURN_ERROR); } - if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) + if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL) return (CMD_RETURN_ERROR); if ((prompt = args_get(args, 'p')) != NULL) -- cgit From 20636d956dd36c1f14152569a4d44a50eea9083d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:54:10 +0000 Subject: Add a command queue to standardize and simplify commands that call other commands and allow a command to block execution of subsequent commands. This allows run-shell and if-shell to be synchronous which has been much requested. Each client has a default command queue and commands are consumed one at a time from it. A command may suspend execution from the queue by returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() - for example run-shell does this from the callback that is fired after the job is freed. When the command queue becomes empty, command clients are automatically exited (unless attaching). A callback is also fired - this is used for nested commands in, for example, if-shell which can block execution of the client's cmdq until a new cmdq becomes empty. Also merge all the old error/info/print functions together and lose the old curclient/cmdclient distinction - a cmdq is bound to one client (or none if in the configuration file), this is a command client if c->session is NULL otherwise an attached client. --- cmd-confirm-before.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'cmd-confirm-before.c') diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 765f58df..6282be2e 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -27,7 +27,7 @@ */ void cmd_confirm_before_key_binding(struct cmd *, int); -enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *); int cmd_confirm_before_callback(void *, const char *); void cmd_confirm_before_free(void *); @@ -43,8 +43,8 @@ const struct cmd_entry cmd_confirm_before_entry = { }; struct cmd_confirm_before_data { - struct client *c; char *cmd; + struct client *client; }; void @@ -66,7 +66,7 @@ cmd_confirm_before_key_binding(struct cmd *self, int key) } enum cmd_retval -cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) +cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct cmd_confirm_before_data *cdata; @@ -74,12 +74,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) char *cmd, *copy, *new_prompt, *ptr; const char *prompt; - if (ctx->curclient == NULL) { - ctx->error(ctx, "must be run interactively"); - return (CMD_RETURN_ERROR); - } - - if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL) + if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL) return (CMD_RETURN_ERROR); if ((prompt = args_get(args, 'p')) != NULL) @@ -93,46 +88,44 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx) cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); - cdata->c = c; - status_prompt_set(cdata->c, new_prompt, NULL, + + cdata->client = c; + cdata->client->references++; + + status_prompt_set(c, new_prompt, NULL, cmd_confirm_before_callback, cmd_confirm_before_free, cdata, PROMPT_SINGLE); free(new_prompt); - return (CMD_RETURN_YIELD); + return (CMD_RETURN_NORMAL); } int cmd_confirm_before_callback(void *data, const char *s) { struct cmd_confirm_before_data *cdata = data; - struct client *c = cdata->c; + struct client *c = cdata->client; struct cmd_list *cmdlist; - struct cmd_ctx *ctx; char *cause; + if (c->flags & CLIENT_DEAD) + return (0); + if (s == NULL || *s == '\0') return (0); if (tolower((u_char) s[0]) != 'y' || s[1] != '\0') return (0); - if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) { + if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { - *cause = toupper((u_char) *cause); - status_message_set(c, "%s", cause); + cmdq_error(c->cmdq, "%s", cause); free(cause); } return (0); } - ctx = cmd_get_ctx(NULL, c); - ctx->error = key_bindings_error; - ctx->print = key_bindings_print; - ctx->info = key_bindings_info; - - cmd_list_exec(cmdlist, ctx); + cmdq_run(c->cmdq, cmdlist); cmd_list_free(cmdlist); - cmd_free_ctx(ctx); return (0); } @@ -141,6 +134,9 @@ void cmd_confirm_before_free(void *data) { struct cmd_confirm_before_data *cdata = data; + struct client *c = cdata->client; + + c->references--; free(cdata->cmd); free(cdata); -- cgit