diff options
Diffstat (limited to 'cmd-confirm-before.c')
-rw-r--r-- | cmd-confirm-before.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 2222d696..46eff3e1 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -1,4 +1,4 @@ -/* $Id: cmd-confirm-before.c,v 1.6 2009-07-15 17:50:11 nicm Exp $ */ +/* $Id: cmd-confirm-before.c,v 1.7 2009-07-17 09:26:21 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -29,11 +29,7 @@ int cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *); void cmd_confirm_before_init(struct cmd *, int); int cmd_confirm_before_callback(void *, const char *); - -struct cmd_confirm_before_data { - struct client *c; - char *cmd; -}; +void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { "confirm-before", "confirm", @@ -48,6 +44,11 @@ const struct cmd_entry cmd_confirm_before_entry = { cmd_target_print }; +struct cmd_confirm_before_data { + struct client *c; + char *cmd; +}; + void cmd_confirm_before_init(struct cmd *self, int key) { @@ -91,8 +92,9 @@ cmd_confirm_before_exec(unused struct cmd *self, struct cmd_ctx *ctx) cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(data->arg); cdata->c = c; - status_prompt_set( - cdata->c, buf, cmd_confirm_before_callback, cdata, PROMPT_SINGLE); + status_prompt_set(cdata->c, buf, + cmd_confirm_before_callback, cmd_confirm_before_free, cdata, + PROMPT_SINGLE); xfree(buf); return (1); @@ -108,7 +110,7 @@ cmd_confirm_before_callback(void *data, const char *s) char *cause; if (s == NULL || tolower((u_char) s[0]) != 'y' || s[1] != '\0') - goto out; + return (0); if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) { if (cause != NULL) { @@ -116,7 +118,7 @@ cmd_confirm_before_callback(void *data, const char *s) status_message_set(c, "%s", cause); xfree(cause); } - goto out; + return (0); } ctx.msgdata = NULL; @@ -132,10 +134,15 @@ cmd_confirm_before_callback(void *data, const char *s) cmd_list_exec(cmdlist, &ctx); cmd_list_free(cmdlist); -out: + return (0); +} + +void +cmd_confirm_before_free(void *data) +{ + struct cmd_confirm_before_data *cdata = data; + if (cdata->cmd != NULL) xfree(cdata->cmd); xfree(cdata); - - return (0); } |