=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-set-option.c,v retrieving revision 1.100 retrieving revision 1.101 diff -c -r1.100 -r1.101 *** src/usr.bin/tmux/cmd-set-option.c 2016/10/14 22:14:22 1.100 --- src/usr.bin/tmux/cmd-set-option.c 2016/10/16 19:04:05 1.101 *************** *** 1,4 **** ! /* $OpenBSD: cmd-set-option.c,v 1.100 2016/10/14 22:14:22 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-set-option.c,v 1.101 2016/10/16 19:04:05 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 27,68 **** * Set an option. */ ! static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *); ! static enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *, ! const char *, const char *); ! static int cmd_set_option_unset(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); ! static int cmd_set_option_set(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); ! static struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); ! static struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); ! static struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); ! static struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); static struct options_entry *cmd_set_option_attributes(struct cmd *, ! struct cmd_q *, const struct options_table_entry *, struct options *, const char *); ! static struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); ! static struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); ! static struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *, ! const struct options_table_entry *, struct options *, ! const char *); const struct cmd_entry cmd_set_option_entry = { .name = "set-option", --- 27,68 ---- * Set an option. */ ! static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *); ! static enum cmd_retval cmd_set_option_user(struct cmd *, struct cmdq_item *, ! const char *, const char *); ! static int cmd_set_option_unset(struct cmd *, struct cmdq_item *, const struct options_table_entry *, struct options *, const char *); ! static int cmd_set_option_set(struct cmd *, struct cmdq_item *, const struct options_table_entry *, struct options *, const char *); ! static struct options_entry *cmd_set_option_string(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); ! static struct options_entry *cmd_set_option_number(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); ! static struct options_entry *cmd_set_option_key(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); ! static struct options_entry *cmd_set_option_colour(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); static struct options_entry *cmd_set_option_attributes(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, struct options *, const char *); ! static struct options_entry *cmd_set_option_flag(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); ! static struct options_entry *cmd_set_option_choice(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); ! static struct options_entry *cmd_set_option_style(struct cmd *, ! struct cmdq_item *, const struct options_table_entry *, ! struct options *, const char *); const struct cmd_entry cmd_set_option_entry = { .name = "set-option", *************** *** 91,101 **** }; static enum cmd_retval ! cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; ! struct session *s = cmdq->state.tflag.s; ! struct winlink *wl = cmdq->state.tflag.wl; struct window *w; struct client *c; const struct options_table_entry *oe; --- 91,101 ---- }; static enum cmd_retval ! cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; ! struct session *s = item->state.tflag.s; ! struct winlink *wl = item->state.tflag.wl; struct window *w; struct client *c; const struct options_table_entry *oe; *************** *** 105,111 **** /* Get the option name and value. */ optstr = args->argv[0]; if (*optstr == '\0') { ! cmdq_error(cmdq, "invalid option"); return (CMD_RETURN_ERROR); } if (args->argc < 2) --- 105,111 ---- /* Get the option name and value. */ optstr = args->argv[0]; if (*optstr == '\0') { ! cmdq_error(item, "invalid option"); return (CMD_RETURN_ERROR); } if (args->argc < 2) *************** *** 115,134 **** /* Is this a user option? */ if (*optstr == '@') ! return (cmd_set_option_user(self, cmdq, optstr, valstr)); /* Find the option entry, try each table. */ oe = NULL; if (options_table_find(optstr, &oe) != 0) { if (!args_has(args, 'q')) { ! cmdq_error(cmdq, "ambiguous option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (oe == NULL) { if (!args_has(args, 'q')) { ! cmdq_error(cmdq, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); --- 115,134 ---- /* Is this a user option? */ if (*optstr == '@') ! return (cmd_set_option_user(self, item, optstr, valstr)); /* Find the option entry, try each table. */ oe = NULL; if (options_table_find(optstr, &oe) != 0) { if (!args_has(args, 'q')) { ! cmdq_error(item, "ambiguous option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (oe == NULL) { if (!args_has(args, 'q')) { ! cmdq_error(item, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); *************** *** 143,152 **** else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(cmdq, "no such window: %s", target); } else ! cmdq_error(cmdq, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; --- 143,152 ---- else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(item, "no such window: %s", target); } else ! cmdq_error(item, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; *************** *** 156,186 **** else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(cmdq, "no such session: %s", target); } else ! cmdq_error(cmdq, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; } else { ! 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, cmdq, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } else { if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { if (!args_has(args, 'q')) { ! cmdq_error(cmdq, "already set: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } ! if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } --- 156,186 ---- else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(item, "no such session: %s", target); } else ! cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; } else { ! cmdq_error(item, "unknown table"); return (CMD_RETURN_ERROR); } /* Unset or set the option. */ if (args_has(args, 'u')) { ! if (cmd_set_option_unset(self, item, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } else { if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { if (!args_has(args, 'q')) { ! cmdq_error(item, "already set: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } ! if (cmd_set_option_set(self, item, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } *************** *** 224,235 **** /* Set user option. */ static enum cmd_retval ! cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, ! const char *valstr) { struct args *args = self->args; ! struct session *s = cmdq->state.tflag.s; ! struct winlink *wl = cmdq->state.tflag.wl; struct options *oo; struct options_entry *o; const char *target; --- 224,235 ---- /* Set user option. */ static enum cmd_retval ! cmd_set_option_user(struct cmd *self, struct cmdq_item *item, ! const char *optstr, const char *valstr) { struct args *args = self->args; ! struct session *s = item->state.tflag.s; ! struct winlink *wl = item->state.tflag.wl; struct options *oo; struct options_entry *o; const char *target; *************** *** 243,252 **** else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(cmdq, "no such window: %s", target); } else ! cmdq_error(cmdq, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; --- 243,252 ---- else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(item, "no such window: %s", target); } else ! cmdq_error(item, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; *************** *** 256,265 **** else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(cmdq, "no such session: %s", target); } else ! cmdq_error(cmdq, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; --- 256,265 ---- else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { ! cmdq_error(item, "no such session: %s", target); } else ! cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; *************** *** 268,280 **** if (args_has(args, 'u')) { if (options_find1(oo, optstr) == NULL) { if (!args_has(args, 'q')) { ! cmdq_error(cmdq, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (valstr != NULL) { ! cmdq_error(cmdq, "value passed to unset option: %s", optstr); return (CMD_RETURN_ERROR); } --- 268,280 ---- if (args_has(args, 'u')) { if (options_find1(oo, optstr) == NULL) { if (!args_has(args, 'q')) { ! cmdq_error(item, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (valstr != NULL) { ! cmdq_error(item, "value passed to unset option: %s", optstr); return (CMD_RETURN_ERROR); } *************** *** 283,295 **** o = options_find1(oo, optstr); if (args_has(args, 'o') && o != NULL) { if (!args_has(args, 'q')) { ! cmdq_error(cmdq, "already set: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (valstr == NULL) { ! cmdq_error(cmdq, "empty value"); return (CMD_RETURN_ERROR); } if (o != NULL && args_has(args, 'a')) --- 283,295 ---- o = options_find1(oo, optstr); if (args_has(args, 'o') && o != NULL) { if (!args_has(args, 'q')) { ! cmdq_error(item, "already set: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (valstr == NULL) { ! cmdq_error(item, "empty value"); return (CMD_RETURN_ERROR); } if (o != NULL && args_has(args, 'a')) *************** *** 302,315 **** /* Unset an option. */ static int ! 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 (value != NULL) { ! cmdq_error(cmdq, "value passed to unset option: %s", oe->name); return (-1); } --- 302,315 ---- /* Unset an option. */ static int ! cmd_set_option_unset(struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; if (value != NULL) { ! cmdq_error(item, "value passed to unset option: %s", oe->name); return (-1); } *************** *** 332,338 **** /* Set an option. */ static int ! cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 332,338 ---- /* Set an option. */ static int ! cmd_set_option_set(struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 344,350 **** break; default: if (value == NULL) { ! cmdq_error(cmdq, "empty value"); return (-1); } } --- 344,350 ---- break; default: if (value == NULL) { ! cmdq_error(item, "empty value"); return (-1); } } *************** *** 352,383 **** o = NULL; switch (oe->type) { case OPTIONS_TABLE_STRING: ! o = cmd_set_option_string(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_NUMBER: ! o = cmd_set_option_number(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_KEY: ! o = cmd_set_option_key(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_COLOUR: ! o = cmd_set_option_colour(self, cmdq, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_ATTRIBUTES: ! o = cmd_set_option_attributes(self, cmdq, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_FLAG: ! o = cmd_set_option_flag(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_CHOICE: ! o = cmd_set_option_choice(self, cmdq, oe, oo, value); break; case OPTIONS_TABLE_STYLE: ! o = cmd_set_option_style(self, cmdq, oe, oo, value); break; } if (o == NULL) --- 352,383 ---- o = NULL; switch (oe->type) { case OPTIONS_TABLE_STRING: ! o = cmd_set_option_string(self, item, oe, oo, value); break; case OPTIONS_TABLE_NUMBER: ! o = cmd_set_option_number(self, item, oe, oo, value); break; case OPTIONS_TABLE_KEY: ! o = cmd_set_option_key(self, item, oe, oo, value); break; case OPTIONS_TABLE_COLOUR: ! o = cmd_set_option_colour(self, item, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_ATTRIBUTES: ! o = cmd_set_option_attributes(self, item, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_FLAG: ! o = cmd_set_option_flag(self, item, oe, oo, value); break; case OPTIONS_TABLE_CHOICE: ! o = cmd_set_option_choice(self, item, oe, oo, value); break; case OPTIONS_TABLE_STYLE: ! o = cmd_set_option_style(self, item, oe, oo, value); break; } if (o == NULL) *************** *** 387,393 **** /* Set a string option. */ static struct options_entry * ! cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 387,393 ---- /* Set a string option. */ static struct options_entry * ! cmd_set_option_string(struct cmd *self, __unused struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 409,415 **** /* Set a number option. */ static struct options_entry * ! cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 409,415 ---- /* Set a number option. */ static struct options_entry * ! cmd_set_option_number(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 418,424 **** ll = strtonum(value, oe->minimum, oe->maximum, &errstr); if (errstr != NULL) { ! cmdq_error(cmdq, "value is %s: %s", errstr, value); return (NULL); } --- 418,424 ---- ll = strtonum(value, oe->minimum, oe->maximum, &errstr); if (errstr != NULL) { ! cmdq_error(item, "value is %s: %s", errstr, value); return (NULL); } *************** *** 427,433 **** /* Set a key option. */ static struct options_entry * ! cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 427,433 ---- /* Set a key option. */ static struct options_entry * ! cmd_set_option_key(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 435,441 **** key = key_string_lookup_string(value); if (key == KEYC_UNKNOWN) { ! cmdq_error(cmdq, "bad key: %s", value); return (NULL); } --- 435,441 ---- key = key_string_lookup_string(value); if (key == KEYC_UNKNOWN) { ! cmdq_error(item, "bad key: %s", value); return (NULL); } *************** *** 444,457 **** /* Set a colour option. */ static struct options_entry * ! 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) { ! cmdq_error(cmdq, "bad colour: %s", value); return (NULL); } --- 444,457 ---- /* Set a colour option. */ static struct options_entry * ! cmd_set_option_colour(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { int colour; if ((colour = colour_fromstring(value)) == -1) { ! cmdq_error(item, "bad colour: %s", value); return (NULL); } *************** *** 460,473 **** /* Set an attributes option. */ static struct options_entry * ! 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) { ! cmdq_error(cmdq, "bad attributes: %s", value); return (NULL); } --- 460,473 ---- /* Set an attributes option. */ static struct options_entry * ! cmd_set_option_attributes(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { int attr; if ((attr = attributes_fromstring(value)) == -1) { ! cmdq_error(item, "bad attributes: %s", value); return (NULL); } *************** *** 476,482 **** /* Set a flag option. */ static struct options_entry * ! cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 476,482 ---- /* Set a flag option. */ static struct options_entry * ! cmd_set_option_flag(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 494,500 **** strcasecmp(value, "no") == 0) flag = 0; else { ! cmdq_error(cmdq, "bad value: %s", value); return (NULL); } } --- 494,500 ---- strcasecmp(value, "no") == 0) flag = 0; else { ! cmdq_error(item, "bad value: %s", value); return (NULL); } } *************** *** 504,510 **** /* Set a choice option. */ static struct options_entry * ! cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 504,510 ---- /* Set a choice option. */ static struct options_entry * ! cmd_set_option_choice(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 523,535 **** continue; if (choice != -1) { ! cmdq_error(cmdq, "ambiguous value: %s", value); return (NULL); } choice = n - 1; } if (choice == -1) { ! cmdq_error(cmdq, "unknown value: %s", value); return (NULL); } } --- 523,535 ---- continue; if (choice != -1) { ! cmdq_error(item, "ambiguous value: %s", value); return (NULL); } choice = n - 1; } if (choice == -1) { ! cmdq_error(item, "unknown value: %s", value); return (NULL); } } *************** *** 539,545 **** /* Set a style option. */ static struct options_entry * ! cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { --- 539,545 ---- /* Set a style option. */ static struct options_entry * ! cmd_set_option_style(struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { *************** *** 549,555 **** append = args_has(args, 'a'); if ((o = options_set_style(oo, oe->name, value, append)) == NULL) { ! cmdq_error(cmdq, "bad style: %s", value); return (NULL); } --- 549,555 ---- append = args_has(args, 'a'); if ((o = options_set_style(oo, oe->name, value, append)) == NULL) { ! cmdq_error(item, "bad style: %s", value); return (NULL); }