[BACK]Return to cmd-set-option.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd-set-option.c between version 1.100 and 1.101

version 1.100, 2016/10/14 22:14:22 version 1.101, 2016/10/16 19:04:05
Line 27 
Line 27 
  * Set an option.   * Set an option.
  */   */
   
 static enum cmd_retval  cmd_set_option_exec(struct cmd *, struct cmd_q *);  static enum cmd_retval  cmd_set_option_exec(struct cmd *, struct cmdq_item *);
   
 static enum cmd_retval  cmd_set_option_user(struct cmd *, struct cmd_q *,  static enum cmd_retval  cmd_set_option_user(struct cmd *, struct cmdq_item *,
             const char *, const char *);                              const char *, const char *);
   
 static int      cmd_set_option_unset(struct cmd *, struct cmd_q *,  static int      cmd_set_option_unset(struct cmd *, struct cmdq_item *,
                     const struct options_table_entry *, struct options *,                      const struct options_table_entry *, struct options *,
                     const char *);                      const char *);
 static int      cmd_set_option_set(struct cmd *, struct cmd_q *,  static int      cmd_set_option_set(struct cmd *, struct cmdq_item *,
                     const struct options_table_entry *, struct options *,                      const struct options_table_entry *, struct options *,
                     const char *);                      const char *);
   
 static struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_string(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_number(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_key(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_colour(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_attributes(struct cmd *,  static struct options_entry *cmd_set_option_attributes(struct cmd *,
             struct cmd_q *, const struct options_table_entry *,              struct cmdq_item *, const struct options_table_entry *,
             struct options *, const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_flag(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_choice(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
 static struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *,  static struct options_entry *cmd_set_option_style(struct cmd *,
             const struct options_table_entry *, struct options *,              struct cmdq_item *, const struct options_table_entry *,
             const char *);              struct options *, const char *);
   
 const struct cmd_entry cmd_set_option_entry = {  const struct cmd_entry cmd_set_option_entry = {
         .name = "set-option",          .name = "set-option",
Line 91 
Line 91 
 };  };
   
 static enum cmd_retval  static enum cmd_retval
 cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)  cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
 {  {
         struct args                             *args = self->args;          struct args                             *args = self->args;
         struct session                          *s = cmdq->state.tflag.s;          struct session                          *s = item->state.tflag.s;
         struct winlink                          *wl = cmdq->state.tflag.wl;          struct winlink                          *wl = item->state.tflag.wl;
         struct window                           *w;          struct window                           *w;
         struct client                           *c;          struct client                           *c;
         const struct options_table_entry        *oe;          const struct options_table_entry        *oe;
Line 105 
Line 105 
         /* Get the option name and value. */          /* Get the option name and value. */
         optstr = args->argv[0];          optstr = args->argv[0];
         if (*optstr == '\0') {          if (*optstr == '\0') {
                 cmdq_error(cmdq, "invalid option");                  cmdq_error(item, "invalid option");
                 return (CMD_RETURN_ERROR);                  return (CMD_RETURN_ERROR);
         }          }
         if (args->argc < 2)          if (args->argc < 2)
Line 115 
Line 115 
   
         /* Is this a user option? */          /* Is this a user option? */
         if (*optstr == '@')          if (*optstr == '@')
                 return (cmd_set_option_user(self, cmdq, optstr, valstr));                  return (cmd_set_option_user(self, item, optstr, valstr));
   
         /* Find the option entry, try each table. */          /* Find the option entry, try each table. */
         oe = NULL;          oe = NULL;
         if (options_table_find(optstr, &oe) != 0) {          if (options_table_find(optstr, &oe) != 0) {
                 if (!args_has(args, 'q')) {                  if (!args_has(args, 'q')) {
                         cmdq_error(cmdq, "ambiguous option: %s", optstr);                          cmdq_error(item, "ambiguous option: %s", optstr);
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 }                  }
                 return (CMD_RETURN_NORMAL);                  return (CMD_RETURN_NORMAL);
         }          }
         if (oe == NULL) {          if (oe == NULL) {
                 if (!args_has(args, 'q')) {                  if (!args_has(args, 'q')) {
                         cmdq_error(cmdq, "unknown option: %s", optstr);                          cmdq_error(item, "unknown option: %s", optstr);
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 }                  }
                 return (CMD_RETURN_NORMAL);                  return (CMD_RETURN_NORMAL);
Line 143 
Line 143 
                 else if (wl == NULL) {                  else if (wl == NULL) {
                         target = args_get(args, 't');                          target = args_get(args, 't');
                         if (target != NULL) {                          if (target != NULL) {
                                 cmdq_error(cmdq, "no such window: %s",                                  cmdq_error(item, "no such window: %s",
                                     target);                                      target);
                         } else                          } else
                                 cmdq_error(cmdq, "no current window");                                  cmdq_error(item, "no current window");
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 } else                  } else
                         oo = wl->window->options;                          oo = wl->window->options;
Line 156 
Line 156 
                 else if (s == NULL) {                  else if (s == NULL) {
                         target = args_get(args, 't');                          target = args_get(args, 't');
                         if (target != NULL) {                          if (target != NULL) {
                                 cmdq_error(cmdq, "no such session: %s",                                  cmdq_error(item, "no such session: %s",
                                     target);                                      target);
                         } else                          } else
                                 cmdq_error(cmdq, "no current session");                                  cmdq_error(item, "no current session");
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 } else                  } else
                         oo = s->options;                          oo = s->options;
         } else {          } else {
                 cmdq_error(cmdq, "unknown table");                  cmdq_error(item, "unknown table");
                 return (CMD_RETURN_ERROR);                  return (CMD_RETURN_ERROR);
         }          }
   
         /* Unset or set the option. */          /* Unset or set the option. */
         if (args_has(args, 'u')) {          if (args_has(args, 'u')) {
                 if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0)                  if (cmd_set_option_unset(self, item, oe, oo, valstr) != 0)
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
         } else {          } else {
                 if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {                  if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
                         if (!args_has(args, 'q')) {                          if (!args_has(args, 'q')) {
                                 cmdq_error(cmdq, "already set: %s", optstr);                                  cmdq_error(item, "already set: %s", optstr);
                                 return (CMD_RETURN_ERROR);                                  return (CMD_RETURN_ERROR);
                         }                          }
                         return (CMD_RETURN_NORMAL);                          return (CMD_RETURN_NORMAL);
                 }                  }
                 if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)                  if (cmd_set_option_set(self, item, oe, oo, valstr) != 0)
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
         }          }
   
Line 224 
Line 224 
   
 /* Set user option. */  /* Set user option. */
 static enum cmd_retval  static enum cmd_retval
 cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,  cmd_set_option_user(struct cmd *self, struct cmdq_item *item,
     const char *valstr)      const char *optstr, const char *valstr)
 {  {
         struct args             *args = self->args;          struct args             *args = self->args;
         struct session          *s = cmdq->state.tflag.s;          struct session          *s = item->state.tflag.s;
         struct winlink          *wl = cmdq->state.tflag.wl;          struct winlink          *wl = item->state.tflag.wl;
         struct options          *oo;          struct options          *oo;
         struct options_entry    *o;          struct options_entry    *o;
         const char              *target;          const char              *target;
Line 243 
Line 243 
                 else if (wl == NULL) {                  else if (wl == NULL) {
                         target = args_get(args, 't');                          target = args_get(args, 't');
                         if (target != NULL) {                          if (target != NULL) {
                                 cmdq_error(cmdq, "no such window: %s",                                  cmdq_error(item, "no such window: %s",
                                     target);                                      target);
                         } else                          } else
                                 cmdq_error(cmdq, "no current window");                                  cmdq_error(item, "no current window");
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 } else                  } else
                         oo = wl->window->options;                          oo = wl->window->options;
Line 256 
Line 256 
                 else if (s == NULL) {                  else if (s == NULL) {
                         target = args_get(args, 't');                          target = args_get(args, 't');
                         if (target != NULL) {                          if (target != NULL) {
                                 cmdq_error(cmdq, "no such session: %s",                                  cmdq_error(item, "no such session: %s",
                                     target);                                      target);
                         } else                          } else
                                 cmdq_error(cmdq, "no current session");                                  cmdq_error(item, "no current session");
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 } else                  } else
                         oo = s->options;                          oo = s->options;
Line 268 
Line 268 
         if (args_has(args, 'u')) {          if (args_has(args, 'u')) {
                 if (options_find1(oo, optstr) == NULL) {                  if (options_find1(oo, optstr) == NULL) {
                         if (!args_has(args, 'q')) {                          if (!args_has(args, 'q')) {
                                 cmdq_error(cmdq, "unknown option: %s", optstr);                                  cmdq_error(item, "unknown option: %s", optstr);
                                 return (CMD_RETURN_ERROR);                                  return (CMD_RETURN_ERROR);
                         }                          }
                         return (CMD_RETURN_NORMAL);                          return (CMD_RETURN_NORMAL);
                 }                  }
                 if (valstr != NULL) {                  if (valstr != NULL) {
                         cmdq_error(cmdq, "value passed to unset option: %s",                          cmdq_error(item, "value passed to unset option: %s",
                             optstr);                              optstr);
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 }                  }
Line 283 
Line 283 
                 o = options_find1(oo, optstr);                  o = options_find1(oo, optstr);
                 if (args_has(args, 'o') && o != NULL) {                  if (args_has(args, 'o') && o != NULL) {
                         if (!args_has(args, 'q')) {                          if (!args_has(args, 'q')) {
                                 cmdq_error(cmdq, "already set: %s", optstr);                                  cmdq_error(item, "already set: %s", optstr);
                                 return (CMD_RETURN_ERROR);                                  return (CMD_RETURN_ERROR);
                         }                          }
                         return (CMD_RETURN_NORMAL);                          return (CMD_RETURN_NORMAL);
                 }                  }
                 if (valstr == NULL) {                  if (valstr == NULL) {
                         cmdq_error(cmdq, "empty value");                          cmdq_error(item, "empty value");
                         return (CMD_RETURN_ERROR);                          return (CMD_RETURN_ERROR);
                 }                  }
                 if (o != NULL && args_has(args, 'a'))                  if (o != NULL && args_has(args, 'a'))
Line 302 
Line 302 
   
 /* Unset an option. */  /* Unset an option. */
 static int  static int
 cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_unset(struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
         struct args     *args = self->args;          struct args     *args = self->args;
   
         if (value != NULL) {          if (value != NULL) {
                 cmdq_error(cmdq, "value passed to unset option: %s", oe->name);                  cmdq_error(item, "value passed to unset option: %s", oe->name);
                 return (-1);                  return (-1);
         }          }
   
Line 332 
Line 332 
   
 /* Set an option. */  /* Set an option. */
 static int  static int
 cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_set(struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 344 
Line 344 
                 break;                  break;
         default:          default:
                 if (value == NULL) {                  if (value == NULL) {
                         cmdq_error(cmdq, "empty value");                          cmdq_error(item, "empty value");
                         return (-1);                          return (-1);
                 }                  }
         }          }
Line 352 
Line 352 
         o = NULL;          o = NULL;
         switch (oe->type) {          switch (oe->type) {
         case OPTIONS_TABLE_STRING:          case OPTIONS_TABLE_STRING:
                 o = cmd_set_option_string(self, cmdq, oe, oo, value);                  o = cmd_set_option_string(self, item, oe, oo, value);
                 break;                  break;
         case OPTIONS_TABLE_NUMBER:          case OPTIONS_TABLE_NUMBER:
                 o = cmd_set_option_number(self, cmdq, oe, oo, value);                  o = cmd_set_option_number(self, item, oe, oo, value);
                 break;                  break;
         case OPTIONS_TABLE_KEY:          case OPTIONS_TABLE_KEY:
                 o = cmd_set_option_key(self, cmdq, oe, oo, value);                  o = cmd_set_option_key(self, item, oe, oo, value);
                 break;                  break;
         case OPTIONS_TABLE_COLOUR:          case OPTIONS_TABLE_COLOUR:
                 o = cmd_set_option_colour(self, cmdq, oe, oo, value);                  o = cmd_set_option_colour(self, item, oe, oo, value);
                 if (o != NULL)                  if (o != NULL)
                         style_update_new(oo, o->name, oe->style);                          style_update_new(oo, o->name, oe->style);
                 break;                  break;
         case OPTIONS_TABLE_ATTRIBUTES:          case OPTIONS_TABLE_ATTRIBUTES:
                 o = cmd_set_option_attributes(self, cmdq, oe, oo, value);                  o = cmd_set_option_attributes(self, item, oe, oo, value);
                 if (o != NULL)                  if (o != NULL)
                         style_update_new(oo, o->name, oe->style);                          style_update_new(oo, o->name, oe->style);
                 break;                  break;
         case OPTIONS_TABLE_FLAG:          case OPTIONS_TABLE_FLAG:
                 o = cmd_set_option_flag(self, cmdq, oe, oo, value);                  o = cmd_set_option_flag(self, item, oe, oo, value);
                 break;                  break;
         case OPTIONS_TABLE_CHOICE:          case OPTIONS_TABLE_CHOICE:
                 o = cmd_set_option_choice(self, cmdq, oe, oo, value);                  o = cmd_set_option_choice(self, item, oe, oo, value);
                 break;                  break;
         case OPTIONS_TABLE_STYLE:          case OPTIONS_TABLE_STYLE:
                 o = cmd_set_option_style(self, cmdq, oe, oo, value);                  o = cmd_set_option_style(self, item, oe, oo, value);
                 break;                  break;
         }          }
         if (o == NULL)          if (o == NULL)
Line 387 
Line 387 
   
 /* Set a string option. */  /* Set a string option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq,  cmd_set_option_string(struct cmd *self, __unused struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 409 
Line 409 
   
 /* Set a number option. */  /* Set a number option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_number(__unused struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 418 
Line 418 
   
         ll = strtonum(value, oe->minimum, oe->maximum, &errstr);          ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
         if (errstr != NULL) {          if (errstr != NULL) {
                 cmdq_error(cmdq, "value is %s: %s", errstr, value);                  cmdq_error(item, "value is %s: %s", errstr, value);
                 return (NULL);                  return (NULL);
         }          }
   
Line 427 
Line 427 
   
 /* Set a key option. */  /* Set a key option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_key(__unused struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 435 
Line 435 
   
         key = key_string_lookup_string(value);          key = key_string_lookup_string(value);
         if (key == KEYC_UNKNOWN) {          if (key == KEYC_UNKNOWN) {
                 cmdq_error(cmdq, "bad key: %s", value);                  cmdq_error(item, "bad key: %s", value);
                 return (NULL);                  return (NULL);
         }          }
   
Line 444 
Line 444 
   
 /* Set a colour option. */  /* Set a colour option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_colour(__unused struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_colour(__unused struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
         int     colour;          int     colour;
   
         if ((colour = colour_fromstring(value)) == -1) {          if ((colour = colour_fromstring(value)) == -1) {
                 cmdq_error(cmdq, "bad colour: %s", value);                  cmdq_error(item, "bad colour: %s", value);
                 return (NULL);                  return (NULL);
         }          }
   
Line 460 
Line 460 
   
 /* Set an attributes option. */  /* Set an attributes option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_attributes(__unused struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_attributes(__unused struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
         int     attr;          int     attr;
   
         if ((attr = attributes_fromstring(value)) == -1) {          if ((attr = attributes_fromstring(value)) == -1) {
                 cmdq_error(cmdq, "bad attributes: %s", value);                  cmdq_error(item, "bad attributes: %s", value);
                 return (NULL);                  return (NULL);
         }          }
   
Line 476 
Line 476 
   
 /* Set a flag option. */  /* Set a flag option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_flag(__unused struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 494 
Line 494 
                     strcasecmp(value, "no") == 0)                      strcasecmp(value, "no") == 0)
                         flag = 0;                          flag = 0;
                 else {                  else {
                         cmdq_error(cmdq, "bad value: %s", value);                          cmdq_error(item, "bad value: %s", value);
                         return (NULL);                          return (NULL);
                 }                  }
         }          }
Line 504 
Line 504 
   
 /* Set a choice option. */  /* Set a choice option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_choice(__unused struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 523 
Line 523 
                                 continue;                                  continue;
   
                         if (choice != -1) {                          if (choice != -1) {
                                 cmdq_error(cmdq, "ambiguous value: %s", value);                                  cmdq_error(item, "ambiguous value: %s", value);
                                 return (NULL);                                  return (NULL);
                         }                          }
                         choice = n - 1;                          choice = n - 1;
                 }                  }
                 if (choice == -1) {                  if (choice == -1) {
                         cmdq_error(cmdq, "unknown value: %s", value);                          cmdq_error(item, "unknown value: %s", value);
                         return (NULL);                          return (NULL);
                 }                  }
         }          }
Line 539 
Line 539 
   
 /* Set a style option. */  /* Set a style option. */
 static struct options_entry *  static struct options_entry *
 cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq,  cmd_set_option_style(struct cmd *self, struct cmdq_item *item,
     const struct options_table_entry *oe, struct options *oo,      const struct options_table_entry *oe, struct options *oo,
     const char *value)      const char *value)
 {  {
Line 549 
Line 549 
   
         append = args_has(args, 'a');          append = args_has(args, 'a');
         if ((o = options_set_style(oo, oe->name, value, append)) == NULL) {          if ((o = options_set_style(oo, oe->name, value, append)) == NULL) {
                 cmdq_error(cmdq, "bad style: %s", value);                  cmdq_error(item, "bad style: %s", value);
                 return (NULL);                  return (NULL);
         }          }
   

Legend:
Removed from v.1.100  
changed lines
  Added in v.1.101