summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-if-shell.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-if-shell.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-if-shell.c')
-rw-r--r--usr.bin/tmux/cmd-if-shell.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c
index 86221f2a8e4..8595074ed47 100644
--- a/usr.bin/tmux/cmd-if-shell.c
+++ b/usr.bin/tmux/cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-if-shell.c,v 1.9 2010/07/24 20:11:59 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.10 2011/01/04 00:42:46 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -35,13 +35,12 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
+ "", 2, 2,
"shell-command command",
- CMD_ARG2, "",
- cmd_target_init,
- cmd_target_parse,
- cmd_if_shell_exec,
- cmd_target_free,
- cmd_target_print
+ 0,
+ NULL,
+ NULL,
+ cmd_if_shell_exec
};
struct cmd_if_shell_data {
@@ -52,12 +51,12 @@ struct cmd_if_shell_data {
int
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{
- struct cmd_target_data *data = self->data;
+ struct args *args = self->args;
struct cmd_if_shell_data *cdata;
struct job *job;
cdata = xmalloc(sizeof *cdata);
- cdata->cmd = xstrdup(data->arg2);
+ cdata->cmd = xstrdup(args->argv[1]);
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
if (ctx->cmdclient != NULL)
@@ -66,7 +65,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->curclient->references++;
job = job_add(NULL, 0, NULL,
- data->arg, cmd_if_shell_callback, cmd_if_shell_free, cdata);
+ args->argv[0], cmd_if_shell_callback, cmd_if_shell_free, cdata);
job_run(job);
return (1); /* don't let client exit */