diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-12-15 17:55:27 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-12-15 17:55:27 +0000 |
| commit | 0d6b5f522ed755aca8a85c005962fb03232b4c96 (patch) | |
| tree | ac866711302bb71827f5f5b1c8ab439b8a4c0ecc /config.c | |
| parent | csi: SGR 21 is “double underline”, not “disable bold” (according to ECMA-48) (diff) | |
config_font_parse(): return fail/success
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -534,8 +534,16 @@ parse_section_main(const char *key, const char *value, struct config *conf, /* Trim spaces, strictly speaking not necessary, but looks nice :) */ while (*font != '\0' && isspace(*font)) font++; - if (*font != '\0') - tll_push_back(conf->fonts[idx], config_font_parse(font)); + if (*font != '\0') { + struct config_font font_data; + if (!config_font_parse(font, &font_data)) { + LOG_ERR("%s:%d: [default]: %s: invalid font specification", + path, lineno, key); + free(copy); + return false; + } + tll_push_back(conf->fonts[idx], font_data); + } } free(copy); } @@ -2083,8 +2091,14 @@ config_load(struct config *conf, const char *conf_path, conf->colors.selection_bg >> 24 == 0; out: - if (ret && tll_length(conf->fonts[0]) == 0) - tll_push_back(conf->fonts[0], config_font_parse("monospace")); + if (ret && tll_length(conf->fonts[0]) == 0) { + struct config_font font; + if (!config_font_parse("monospace", &font)) { + LOG_ERR("failed to load font 'monospace' - no fonts installed?"); + ret = false; + } else + tll_push_back(conf->fonts[0], font); + } free(conf_file.path); if (conf_file.fd >= 0) @@ -2131,10 +2145,12 @@ config_free(struct config conf) user_notifications_free(&conf.notifications); } -struct config_font -config_font_parse(const char *pattern) +bool +config_font_parse(const char *pattern, struct config_font *font) { FcPattern *pat = FcNameParse((const FcChar8 *)pattern); + if (pat == NULL) + return false; double pt_size = -1.0; FcPatternGetDouble(pat, FC_SIZE, 0, &pt_size); @@ -2150,10 +2166,12 @@ config_font_parse(const char *pattern) char *stripped_pattern = (char *)FcNameUnparse(pat); FcPatternDestroy(pat); - return (struct config_font){ + *font = (struct config_font){ .pattern = stripped_pattern, .pt_size = pt_size, - .px_size = px_size}; + .px_size = px_size + }; + return true; } void |
