diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-01-04 00:42:48 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-01-04 00:42:48 +0000 |
commit | 16cb3f3755ad38847f98c31f447e46392ac712fa (patch) | |
tree | 38c22cdaf8c376adff22781d854c9c5c67ed42ed /usr.bin/tmux/cmd-swap-window.c | |
parent | 8e6a3ab86e7918f82355f33fa944cca1df578195 (diff) |
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-swap-window.c')
-rw-r--r-- | usr.bin/tmux/cmd-swap-window.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-swap-window.c b/usr.bin/tmux/cmd-swap-window.c index f6c22626416..e6409c9f144 100644 --- a/usr.bin/tmux/cmd-swap-window.c +++ b/usr.bin/tmux/cmd-swap-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-swap-window.c,v 1.5 2009/11/13 19:53:29 nicm Exp $ */ +/* $OpenBSD: cmd-swap-window.c,v 1.6 2011/01/04 00:42:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,27 +30,29 @@ int cmd_swap_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_swap_window_entry = { "swap-window", "swapw", + "ds:t:", 0, 0, "[-d] " CMD_SRCDST_WINDOW_USAGE, - 0, "d", - cmd_srcdst_init, - cmd_srcdst_parse, - cmd_swap_window_exec, - cmd_srcdst_free, - cmd_srcdst_print + 0, + NULL, + NULL, + cmd_swap_window_exec }; int cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) { - struct cmd_srcdst_data *data = self->data; + struct args *args = self->args; + const char *target_src, *target_dst; struct session *src, *dst; struct session_group *sg_src, *sg_dst; struct winlink *wl_src, *wl_dst; struct window *w; - if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL) + target_src = args_get(args, 's'); + if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL) return (-1); - if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL) + target_dst = args_get(args, 't'); + if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL) return (-1); sg_src = session_group_find(src); @@ -68,7 +70,7 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) wl_dst->window = wl_src->window; wl_src->window = w; - if (!cmd_check_flag(data->chflags, 'd')) { + if (!args_has(self->args, 'd')) { session_select(dst, wl_dst->idx); if (src != dst) session_select(src, wl_src->idx); |