=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-set-option.c,v retrieving revision 1.58 retrieving revision 1.59 diff -c -r1.58 -r1.59 *** src/usr.bin/tmux/cmd-set-option.c 2013/03/21 16:15:52 1.58 --- src/usr.bin/tmux/cmd-set-option.c 2013/03/21 16:17:01 1.59 *************** *** 1,4 **** ! /* $OpenBSD: cmd-set-option.c,v 1.58 2013/03/21 16:15:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-set-option.c,v 1.59 2013/03/21 16:17:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 27,34 **** * Set an option. */ ! enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_ctx *); int cmd_set_option_unset(struct cmd *, struct cmd_ctx *, const struct options_table_entry *, struct options *, const char *); --- 27,37 ---- * Set an option. */ ! enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_ctx *); + enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_ctx *, + const char *, const char *); + int cmd_set_option_unset(struct cmd *, struct cmd_ctx *, const struct options_table_entry *, struct options *, const char *); *************** *** 102,107 **** --- 105,114 ---- else valstr = args->argv[1]; + /* Is this a user option? */ + if (*optstr == '@') + return (cmd_set_option_user(self, ctx, optstr, valstr)); + /* Find the option entry, try each table. */ table = oe = NULL; if (options_table_find(optstr, &table, &oe) != 0) { *************** *** 170,175 **** --- 177,239 ---- return (CMD_RETURN_NORMAL); } + + /* Set user option. */ + enum cmd_retval + cmd_set_option_user(struct cmd *self, struct cmd_ctx *ctx, const char* optstr, + const char *valstr) + { + struct args *args = self->args; + struct session *s; + struct winlink *wl; + struct options *oo; + + if (args_has(args, 's')) + oo = &global_options; + else if (args_has(self->args, 'w') || + self->entry == &cmd_set_window_option_entry) { + if (args_has(self->args, 'g')) + oo = &global_w_options; + else { + wl = cmd_find_window(ctx, args_get(args, 't'), NULL); + if (wl == NULL) + return (CMD_RETURN_ERROR); + oo = &wl->window->options; + } + } else { + if (args_has(self->args, 'g')) + oo = &global_s_options; + else { + s = cmd_find_session(ctx, args_get(args, 't'), 0); + if (s == NULL) + return (CMD_RETURN_ERROR); + oo = &s->options; + } + } + + if (args_has(args, 'u')) { + if (options_find1(oo, optstr) == NULL) { + ctx->error(ctx, "unknown option: %s", optstr); + return (CMD_RETURN_ERROR); + } + if (valstr != NULL) { + ctx->error(ctx, "value passed to unset option: %s", + optstr); + return (CMD_RETURN_ERROR); + } + options_remove(oo, optstr); + } else { + if (valstr == NULL) { + ctx->error(ctx, "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); + } + return (CMD_RETURN_NORMAL); + } + /* Unset an option. */ int