config: add value_to_dimensions()

This commit is contained in:
Daniel Eklöf 2021-11-06 12:32:20 +01:00
parent d29c3cf7b7
commit 0c0a78498f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 15 additions and 14 deletions

View file

@ -537,6 +537,17 @@ value_to_uint32(struct context *ctx, int base, uint32_t *res)
return true;
}
static bool NOINLINE
value_to_dimensions(struct context *ctx, uint32_t *x, uint32_t *y)
{
if (sscanf(ctx->value, "%ux%u", x, y) != 2) {
LOG_CONTEXTUAL_ERR("invalid dimensions (must be on the form AxB)");
return false;
}
return true;
}
static bool NOINLINE
value_to_double(struct context *ctx, float *res)
{
@ -883,27 +894,17 @@ parse_section_main(struct context *ctx)
return value_to_str(ctx, &conf->app_id);
else if (strcmp(key, "initial-window-size-pixels") == 0) {
unsigned width, height;
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
LOG_CONTEXTUAL_ERR("invalid size (must be on the form WIDTHxHEIGHT)");
if (!value_to_dimensions(ctx, &conf->size.width, &conf->size.height))
return false;
}
conf->size.type = CONF_SIZE_PX;
conf->size.width = width;
conf->size.height = height;
}
else if (strcmp(key, "initial-window-size-chars") == 0) {
unsigned width, height;
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
LOG_CONTEXTUAL_ERR("invalid size (must be on the form WIDTHxHEIGHT)");
if (!value_to_dimensions(ctx, &conf->size.width, &conf->size.height))
return false;
}
conf->size.type = CONF_SIZE_CELLS;
conf->size.width = width;
conf->size.height = height;
}
else if (strcmp(key, "pad") == 0) {

View file

@ -74,8 +74,8 @@ struct config {
struct {
enum conf_size_type type;
unsigned width;
unsigned height;
uint32_t width;
uint32_t height;
} size;
unsigned pad_x;