config: add value_to_str()

Takes a pointer to a char*, free:s it, and strdups the current value.
This commit is contained in:
Daniel Eklöf 2021-11-06 11:32:11 +01:00
parent c2127fb2de
commit 3b27a665da
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -524,6 +524,14 @@ value_to_double(struct context *ctx, double *res)
return true;
}
static bool NOINLINE
value_to_str(struct context *ctx, char **res)
{
free(*res);
*res = xstrdup(ctx->value);
return true;
}
static bool NOINLINE
value_to_wchars(struct context *ctx, wchar_t **res)
{
@ -825,32 +833,23 @@ parse_section_main(struct context *ctx)
return ret;
}
else if (strcmp(key, "term") == 0) {
free(conf->term);
conf->term = xstrdup(value);
}
else if (strcmp(key, "term") == 0)
return value_to_str(ctx, &conf->term);
else if (strcmp(key, "shell") == 0) {
free(conf->shell);
conf->shell = xstrdup(value);
}
else if (strcmp(key, "shell") == 0)
return value_to_str(ctx, &conf->shell);
else if (strcmp(key, "login-shell") == 0) {
else if (strcmp(key, "login-shell") == 0)
return value_to_bool(ctx, &conf->login_shell);
}
else if (strcmp(key, "title") == 0) {
free(conf->title);
conf->title = xstrdup(value);
}
else if (strcmp(key, "title") == 0)
return value_to_str(ctx, &conf->title);
else if (strcmp(key, "locked-title") == 0)
return value_to_bool(ctx, &conf->locked_title);
else if (strcmp(key, "app-id") == 0) {
free(conf->app_id);
conf->app_id = xstrdup(value);
}
else if (strcmp(key, "app-id") == 0)
return value_to_str(ctx, &conf->app_id);
else if (strcmp(key, "initial-window-size-pixels") == 0) {
unsigned width, height;