summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-set-buffer.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-set-buffer.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-set-buffer.c')
-rw-r--r--usr.bin/tmux/cmd-set-buffer.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-set-buffer.c b/usr.bin/tmux/cmd-set-buffer.c
index 24ab324132d..8aff8dada35 100644
--- a/usr.bin/tmux/cmd-set-buffer.c
+++ b/usr.bin/tmux/cmd-set-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-buffer.c,v 1.7 2010/12/30 23:16:18 nicm Exp $ */
+/* $OpenBSD: cmd-set-buffer.c,v 1.8 2011/01/04 00:42:47 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,36 +30,45 @@ int cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_set_buffer_entry = {
"set-buffer", "setb",
+ "b:", 1, 1,
CMD_BUFFER_USAGE " data",
- CMD_ARG1, "",
- cmd_buffer_init,
- cmd_buffer_parse,
- cmd_set_buffer_exec,
- cmd_buffer_free,
- cmd_buffer_print
+ 0,
+ NULL,
+ NULL,
+ cmd_set_buffer_exec
};
int
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
- struct cmd_buffer_data *data = self->data;
- u_int limit;
- char *pdata;
- size_t psize;
+ struct args *args = self->args;
+ u_int limit;
+ char *pdata, *cause;
+ size_t psize;
+ int buffer;
limit = options_get_number(&global_options, "buffer-limit");
- pdata = xstrdup(data->arg);
+ pdata = xstrdup(args->argv[0]);
psize = strlen(pdata);
- if (data->buffer == -1) {
+ if (!args_has(args, 'b')) {
paste_add(&global_buffers, pdata, psize, limit);
return (0);
}
- if (paste_replace(&global_buffers, data->buffer, pdata, psize) != 0) {
- ctx->error(ctx, "no buffer %d", data->buffer);
+
+ buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
+ if (cause != NULL) {
+ ctx->error(ctx, "buffer %s", cause);
+ xfree(cause);
+ return (-1);
+ }
+
+ if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
+ ctx->error(ctx, "no buffer %d", buffer);
xfree(pdata);
return (-1);
}
+
return (0);
}