diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-24 09:54:11 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-24 09:54:11 +0000 |
commit | 850baabe4d0cd3495529b1629355880ad8e5863b (patch) | |
tree | 0195dd3f04fe64313e533bd611d8141243840fa5 /usr.bin/tmux/cmd-set-option.c | |
parent | 798d2212897db138c9f96aad84193f79fa47060f (diff) |
Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.
Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.
When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.
Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.
Diffstat (limited to 'usr.bin/tmux/cmd-set-option.c')
-rw-r--r-- | usr.bin/tmux/cmd-set-option.c | 121 |
1 files changed, 62 insertions, 59 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index af7cd8d1d6a..5a867ae64af 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.59 2013/03/21 16:17:01 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.60 2013/03/24 09:54:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -27,37 +27,37 @@ * Set an option. */ -enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_ctx *, +enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *, const char *, const char *); -int cmd_set_option_unset(struct cmd *, struct cmd_ctx *, +int cmd_set_option_unset(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -int cmd_set_option_set(struct cmd *, struct cmd_ctx *, +int cmd_set_option_set(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_ctx *, +struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); @@ -82,7 +82,7 @@ const struct cmd_entry cmd_set_window_option_entry = { }; enum cmd_retval -cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) +cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; const struct options_table_entry *table, *oe; @@ -97,7 +97,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) /* Get the option name and value. */ optstr = args->argv[0]; if (*optstr == '\0') { - ctx->error(ctx, "invalid option"); + cmdq_error(cmdq, "invalid option"); return (CMD_RETURN_ERROR); } if (args->argc < 2) @@ -107,16 +107,16 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) /* Is this a user option? */ if (*optstr == '@') - return (cmd_set_option_user(self, ctx, optstr, valstr)); + return (cmd_set_option_user(self, cmdq, optstr, valstr)); /* Find the option entry, try each table. */ table = oe = NULL; if (options_table_find(optstr, &table, &oe) != 0) { - ctx->error(ctx, "ambiguous option: %s", optstr); + cmdq_error(cmdq, "ambiguous option: %s", optstr); return (CMD_RETURN_ERROR); } if (oe == NULL) { - ctx->error(ctx, "unknown option: %s", optstr); + cmdq_error(cmdq, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } @@ -127,7 +127,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 'g')) oo = &global_w_options; else { - wl = cmd_find_window(ctx, args_get(args, 't'), NULL); + wl = cmd_find_window(cmdq, args_get(args, 't'), NULL); if (wl == NULL) return (CMD_RETURN_ERROR); oo = &wl->window->options; @@ -136,22 +136,22 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 'g')) oo = &global_s_options; else { - s = cmd_find_session(ctx, args_get(args, 't'), 0); + s = cmd_find_session(cmdq, args_get(args, 't'), 0); if (s == NULL) return (CMD_RETURN_ERROR); oo = &s->options; } } else { - ctx->error(ctx, "unknown table"); + cmdq_error(cmdq, "unknown table"); return (CMD_RETURN_ERROR); } /* Unset or set the option. */ if (args_has(args, 'u')) { - if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0) + if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } else { - if (cmd_set_option_set(self, ctx, oe, oo, valstr) != 0) + if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } @@ -180,7 +180,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) /* Set user option. */ enum cmd_retval -cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr, +cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char* optstr, const char *valstr) { struct args *args = self->args; @@ -195,7 +195,7 @@ cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr, if (args_has(self->args, 'g')) oo = &global_w_options; else { - wl = cmd_find_window(ctx, args_get(args, 't'), NULL); + wl = cmd_find_window(cmdq, args_get(args, 't'), NULL); if (wl == NULL) return (CMD_RETURN_ERROR); oo = &wl->window->options; @@ -204,7 +204,7 @@ cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr, if (args_has(self->args, 'g')) oo = &global_s_options; else { - s = cmd_find_session(ctx, args_get(args, 't'), 0); + s = cmd_find_session(cmdq, args_get(args, 't'), 0); if (s == NULL) return (CMD_RETURN_ERROR); oo = &s->options; @@ -213,23 +213,25 @@ cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr, if (args_has(args, 'u')) { if (options_find1(oo, optstr) == NULL) { - ctx->error(ctx, "unknown option: %s", optstr); + cmdq_error(cmdq, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } if (valstr != NULL) { - ctx->error(ctx, "value passed to unset option: %s", + cmdq_error(cmdq, "value passed to unset option: %s", optstr); return (CMD_RETURN_ERROR); } options_remove(oo, optstr); } else { if (valstr == NULL) { - ctx->error(ctx, "empty value"); + cmdq_error(cmdq, "empty value"); return (CMD_RETURN_ERROR); } options_set_string(oo, optstr, "%s", valstr); - if (!args_has(args, 'q')) - ctx->info(ctx, "set option: %s -> %s", optstr, valstr); + if (!args_has(args, 'q')) { + cmdq_info(cmdq, "set option: %s -> %s", optstr, + valstr); + } } return (CMD_RETURN_NORMAL); } @@ -237,29 +239,29 @@ cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr, /* Unset an option. */ int -cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; if (args_has(args, 'g')) { - ctx->error(ctx, "can't unset global option: %s", oe->name); + cmdq_error(cmdq, "can't unset global option: %s", oe->name); return (-1); } if (value != NULL) { - ctx->error(ctx, "value passed to unset option: %s", oe->name); + cmdq_error(cmdq, "value passed to unset option: %s", oe->name); return (-1); } options_remove(oo, oe->name); if (!args_has(args, 'q')) - ctx->info(ctx, "unset option: %s", oe->name); + cmdq_info(cmdq, "unset option: %s", oe->name); return (0); } /* Set an option. */ int -cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; @@ -267,32 +269,32 @@ cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx, const char *s; if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) { - ctx->error(ctx, "empty value"); + cmdq_error(cmdq, "empty value"); return (-1); } o = NULL; switch (oe->type) { case OPTIONS_TABLE_STRING: - o = cmd_set_option_string(self, ctx, oe, oo, value); + o = cmd_set_option_string(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_NUMBER: - o = cmd_set_option_number(self, ctx, oe, oo, value); + o = cmd_set_option_number(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_KEY: - o = cmd_set_option_key(self, ctx, oe, oo, value); + o = cmd_set_option_key(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_COLOUR: - o = cmd_set_option_colour(self, ctx, oe, oo, value); + o = cmd_set_option_colour(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_ATTRIBUTES: - o = cmd_set_option_attributes(self, ctx, oe, oo, value); + o = cmd_set_option_attributes(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_FLAG: - o = cmd_set_option_flag(self, ctx, oe, oo, value); + o = cmd_set_option_flag(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_CHOICE: - o = cmd_set_option_choice(self, ctx, oe, oo, value); + o = cmd_set_option_choice(self, cmdq, oe, oo, value); break; } if (o == NULL) @@ -300,13 +302,13 @@ cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx, s = options_table_print_entry(oe, o, 0); if (!args_has(args, 'q')) - ctx->info(ctx, "set option: %s -> %s", oe->name, s); + cmdq_info(cmdq, "set option: %s -> %s", oe->name, s); return (0); } /* Set a string option. */ struct options_entry * -cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx, +cmd_set_option_string(struct cmd *self, unused struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; @@ -327,7 +329,7 @@ cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx, /* Set a number option. */ struct options_entry * -cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_number(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { long long ll; @@ -335,7 +337,7 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx, ll = strtonum(value, oe->minimum, oe->maximum, &errstr); if (errstr != NULL) { - ctx->error(ctx, "value is %s: %s", errstr, value); + cmdq_error(cmdq, "value is %s: %s", errstr, value); return (NULL); } @@ -344,13 +346,13 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx, /* Set a key option. */ struct options_entry * -cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_key(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { int key; if ((key = key_string_lookup_string(value)) == KEYC_NONE) { - ctx->error(ctx, "bad key: %s", value); + cmdq_error(cmdq, "bad key: %s", value); return (NULL); } @@ -359,13 +361,13 @@ cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx, /* Set a colour option. */ struct options_entry * -cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_colour(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { int colour; if ((colour = colour_fromstring(value)) == -1) { - ctx->error(ctx, "bad colour: %s", value); + cmdq_error(cmdq, "bad colour: %s", value); return (NULL); } @@ -374,13 +376,13 @@ cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx, /* Set an attributes option. */ struct options_entry * -cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_attributes(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { int attr; if ((attr = attributes_fromstring(value)) == -1) { - ctx->error(ctx, "bad attributes: %s", value); + cmdq_error(cmdq, "bad attributes: %s", value); return (NULL); } @@ -389,7 +391,7 @@ cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx, /* Set a flag option. */ struct options_entry * -cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx, +cmd_set_option_flag(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { int flag; @@ -406,7 +408,7 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx, strcasecmp(value, "no") == 0) flag = 0; else { - ctx->error(ctx, "bad value: %s", value); + cmdq_error(cmdq, "bad value: %s", value); return (NULL); } } @@ -416,8 +418,9 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx, /* Set a choice option. */ struct options_entry * -cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx, - const struct options_table_entry *oe, struct options *oo, const char *value) +cmd_set_option_choice(unused struct cmd *self, struct cmd_q *cmdq, + const struct options_table_entry *oe, struct options *oo, + const char *value) { const char **choicep; int n, choice = -1; @@ -429,13 +432,13 @@ cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx, continue; if (choice != -1) { - ctx->error(ctx, "ambiguous value: %s", value); + cmdq_error(cmdq, "ambiguous value: %s", value); return (NULL); } choice = n - 1; } if (choice == -1) { - ctx->error(ctx, "unknown value: %s", value); + cmdq_error(cmdq, "unknown value: %s", value); return (NULL); } |