summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-confirm-before.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2011-01-04 00:42:46 +0000
committernicm <nicm@openbsd.org>2011-01-04 00:42:46 +0000
commitca7befcc5189fa88f5a692b06394473e8d9ada88 (patch)
treed067816fbc088f99c228eb4c8bc0954e84c0eab1 /usr.bin/tmux/cmd-confirm-before.c
parentPartial cleanup of argument count validation in mdoc(7): (diff)
downloadwireguard-openbsd-ca7befcc5189fa88f5a692b06394473e8d9ada88.tar.xz
wireguard-openbsd-ca7befcc5189fa88f5a692b06394473e8d9ada88.zip
Clean up and simplify tmux command argument parsing.
Originally, tmux commands were parsed in the client process into a struct with the command data which was then serialised and sent to the server to be executed. The parsing was later moved into the server (an argv was sent from the client), but the parse step and intermediate struct was kept. This change removes that struct and the separate parse step. Argument parsing and printing is now common to all commands (in arguments.c) with each command left with just an optional check function (to validate the arguments at parse time), the exec function and a function to set up any key bindings (renamed from the old init function). This is overall more simple and consistent. There should be no changes to any commands behaviour or syntax although as this touches every command please watch for any unexpected changes.
Diffstat (limited to 'usr.bin/tmux/cmd-confirm-before.c')
-rw-r--r--usr.bin/tmux/cmd-confirm-before.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c
index 1c5ca9e91de..f72563f0cd3 100644
--- a/usr.bin/tmux/cmd-confirm-before.c
+++ b/usr.bin/tmux/cmd-confirm-before.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-confirm-before.c,v 1.9 2009/11/13 19:53:29 nicm Exp $ */
+/* $OpenBSD: cmd-confirm-before.c,v 1.10 2011/01/04 00:42:46 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -25,21 +25,20 @@
* Asks for confirmation before executing a command.
*/
+void cmd_confirm_before_key_binding(struct cmd *, int);
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 *);
void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = {
"confirm-before", "confirm",
+ "t:", 1, 1,
CMD_TARGET_CLIENT_USAGE " command",
- CMD_ARG1, "",
- cmd_confirm_before_init,
- cmd_target_parse,
- cmd_confirm_before_exec,
- cmd_target_free,
- cmd_target_print
+ 0,
+ cmd_confirm_before_key_binding,
+ NULL,
+ cmd_confirm_before_exec
};
struct cmd_confirm_before_data {
@@ -48,19 +47,17 @@ struct cmd_confirm_before_data {
};
void
-cmd_confirm_before_init(struct cmd *self, int key)
+cmd_confirm_before_key_binding(struct cmd *self, int key)
{
- struct cmd_target_data *data;
-
- cmd_target_init(self, key);
- data = self->data;
-
switch (key) {
case '&':
- data->arg = xstrdup("kill-window");
+ self->args = args_create(1, "kill-window");
break;
case 'x':
- data->arg = xstrdup("kill-pane");
+ self->args = args_create(1, "kill-pane");
+ break;
+ default:
+ self->args = args_create(0);
break;
}
}
@@ -68,7 +65,7 @@ cmd_confirm_before_init(struct cmd *self, int key)
int
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
{
- struct cmd_target_data *data = self->data;
+ struct args *args = self->args;
struct cmd_confirm_before_data *cdata;
struct client *c;
char *buf, *cmd, *ptr;
@@ -78,17 +75,17 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
- if ((c = cmd_find_client(ctx, data->target)) == NULL)
+ if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
return (-1);
- ptr = xstrdup(data->arg);
+ ptr = xstrdup(args->argv[0]);
if ((cmd = strtok(ptr, " \t")) == NULL)
cmd = ptr;
xasprintf(&buf, "Confirm '%s'? (y/n) ", cmd);
xfree(ptr);
cdata = xmalloc(sizeof *cdata);
- cdata->cmd = xstrdup(data->arg);
+ cdata->cmd = xstrdup(args->argv[0]);
cdata->c = c;
status_prompt_set(cdata->c, buf,
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,