Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2016-09-26 12:01:12 +01:00
commit 30f2e8ff29
2 changed files with 20 additions and 11 deletions

View File

@ -231,6 +231,7 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
struct session *s = cmdq->state.tflag.s; struct session *s = cmdq->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = cmdq->state.tflag.wl;
struct options *oo; struct options *oo;
struct options_entry *o;
if (args_has(args, 's')) if (args_has(args, 's'))
oo = global_options; oo = global_options;
@ -262,17 +263,21 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
} }
options_remove(oo, optstr); options_remove(oo, optstr);
} else { } else {
if (valstr == NULL) { o = options_find1(oo, optstr);
cmdq_error(cmdq, "empty value"); if (args_has(args, 'o') && o != NULL) {
return (CMD_RETURN_ERROR);
}
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(cmdq, "already set: %s", optstr);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (valstr == NULL) {
cmdq_error(cmdq, "empty value");
return (CMD_RETURN_ERROR);
}
if (o != NULL && args_has(args, 'a'))
options_set_string(oo, optstr, "%s%s", o->str, valstr);
else
options_set_string(oo, optstr, "%s", valstr); options_set_string(oo, optstr, "%s", valstr);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@ -128,19 +128,23 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
{ {
struct options_entry *o; struct options_entry *o;
va_list ap; va_list ap;
char *s;
s = NULL;
if ((o = options_find1(oo, name)) == NULL) { if ((o = options_find1(oo, name)) == NULL) {
o = xmalloc(sizeof *o); o = xmalloc(sizeof *o);
o->name = xstrdup(name); o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o); RB_INSERT(options_tree, &oo->tree, o);
memcpy(&o->style, &grid_default_cell, sizeof o->style); memcpy(&o->style, &grid_default_cell, sizeof o->style);
} else if (o->type == OPTIONS_STRING) } else if (o->type == OPTIONS_STRING)
free(o->str); s = o->str;
va_start(ap, fmt); va_start(ap, fmt);
o->type = OPTIONS_STRING; o->type = OPTIONS_STRING;
xvasprintf(&o->str, fmt, ap); xvasprintf(&o->str, fmt, ap);
va_end(ap); va_end(ap);
free(s);
return (o); return (o);
} }