diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-11-06 11:32:20 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-11-13 10:04:29 +0000 |
| commit | 0c0a78498f4207ca9816cd41c5badaf516230072 (patch) | |
| tree | 6b83ca0f75fb66d7794c59e71389c58c6769f6f8 | |
| parent | config: add {str,value}_to_uint{16,32}() (diff) | |
config: add value_to_dimensions()
| -rw-r--r-- | config.c | 25 | ||||
| -rw-r--r-- | config.h | 4 |
2 files changed, 15 insertions, 14 deletions
@@ -538,6 +538,17 @@ value_to_uint32(struct context *ctx, int base, uint32_t *res) } 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) { const char *s = ctx->value; @@ -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) { @@ -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; |
