summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-09-26 12:01:12 +0100
committerThomas Adam <thomas@xteddy.org>2016-09-26 12:01:12 +0100
commit30f2e8ff29b112b6b428d1d123187fdfd497e814 (patch)
treea080fb07fdd7ed7ba11f6412eef712f4db447720
parentcbde98f67b5f96abcd95b8560081a7664980a3cf (diff)
parent69e980602b31732348aaceee045a1901dc982d78 (diff)
Merge branch 'obsd-master'
-rw-r--r--cmd-set-option.c25
-rw-r--r--options.c6
2 files changed, 20 insertions, 11 deletions
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 356668ee..491353a8 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -227,10 +227,11 @@ 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 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;
if (args_has(args, 's'))
oo = global_options;
@@ -262,18 +263,22 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
}
options_remove(oo, optstr);
} else {
- if (valstr == NULL) {
- cmdq_error(cmdq, "empty value");
- return (CMD_RETURN_ERROR);
- }
- if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
+ 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);
}
- options_set_string(oo, optstr, "%s", valstr);
+ 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);
}
return (CMD_RETURN_NORMAL);
}
diff --git a/options.c b/options.c
index df79ac4b..cd3bd8ec 100644
--- a/options.c
+++ b/options.c
@@ -128,19 +128,23 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
{
struct options_entry *o;
va_list ap;
+ char *s;
+ s = NULL;
if ((o = options_find1(oo, name)) == NULL) {
o = xmalloc(sizeof *o);
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
memcpy(&o->style, &grid_default_cell, sizeof o->style);
} else if (o->type == OPTIONS_STRING)
- free(o->str);
+ s = o->str;
va_start(ap, fmt);
o->type = OPTIONS_STRING;
xvasprintf(&o->str, fmt, ap);
va_end(ap);
+
+ free(s);
return (o);
}