From 7502cb3adbb26a2f94445a35626e64041d6769f9 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 4 Jan 2011 00:42:46 +0000 Subject: 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. --- cmd-confirm-before.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'cmd-confirm-before.c') diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index cdde81ac..b19d69d7 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -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, -- cgit v1.2.3