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-pipe-pane.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'cmd-pipe-pane.c') diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index d287d3b6..6284bf37 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -38,19 +38,18 @@ void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *); const struct cmd_entry cmd_pipe_pane_entry = { "pipe-pane", "pipep", + "ot:", 0, 1, CMD_TARGET_PANE_USAGE "[-o] [command]", - CMD_ARG01, "o", - cmd_target_init, - cmd_target_parse, - cmd_pipe_pane_exec, - cmd_target_free, - cmd_target_print + 0, + NULL, + NULL, + cmd_pipe_pane_exec }; int cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_target_data *data = self->data; + struct args *args = self->args; struct client *c; struct window_pane *wp; char *command; @@ -59,7 +58,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) if ((c = cmd_find_client(ctx, NULL)) == NULL) return (-1); - if (cmd_find_pane(ctx, data->target, NULL, &wp) == NULL) + if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) return (-1); /* Destroy the old pipe. */ @@ -71,7 +70,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) } /* If no pipe command, that is enough. */ - if (data->arg == NULL || *data->arg == '\0') + if (args->argc == 0 || *args->argv[0] == '\0') return (0); /* @@ -80,7 +79,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) * * bind ^p pipep -o 'cat >>~/output' */ - if (cmd_check_flag(data->chflags, 'o') && old_fd != -1) + if (args_has(self->args, 'o') && old_fd != -1) return (0); /* Open the new pipe. */ @@ -114,7 +113,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) closefrom(STDERR_FILENO + 1); - command = status_replace(c, NULL, data->arg, time(NULL), 0); + command = status_replace(c, NULL, args->argv[0], time(NULL), 0); execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL); _exit(1); default: -- cgit