aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-30 16:08:27 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-30 16:08:27 +0000
commitf39d848368a7a91c8956979a543293813617ea78 (patch)
tree61b58a6235a7c74371654e7d20f55ae7f6fababa /config.c
parentMerge branch 'use-freetype-to-render-glyphs' (diff)
parentmain: pty buffers appear to be ~20KB on modern linux kernels (diff)
Merge branch 'multithreaded-renderer'
Diffstat (limited to 'config.c')
-rw-r--r--config.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/config.c b/config.c
index 707f7d93..08156d16 100644
--- a/config.c
+++ b/config.c
@@ -107,26 +107,28 @@ get_config_path(void)
}
static bool
-str_to_color(const char *s, uint32_t *color, const char *path, int lineno)
+str_to_ulong(const char *s, int base, unsigned long *res)
{
if (s == NULL)
return false;
errno = 0;
char *end = NULL;
- unsigned long res = strtoul(s, &end, 16);
- if (errno != 0) {
- LOG_ERRNO("%s:%d: invalid color: %s", path, lineno, s);
- return false;
- }
+ *res = strtoul(s, &end, base);
+ return errno == 0 && *end == '\0';
+}
- if (*end != '\0') {
- LOG_ERR("%s:%d: invalid color: %s", path, lineno, s);
+static bool
+str_to_color(const char *s, uint32_t *color, const char *path, int lineno)
+{
+ unsigned long value;
+ if (!str_to_ulong(s, 16, &value)) {
+ LOG_ERRNO("%s:%d: invalid color: %s", path, lineno, s);
return false;
}
- *color = res & 0xffffff;
+ *color = value & 0xffffff;
return true;
}
@@ -145,8 +147,21 @@ parse_section_main(const char *key, const char *value, struct config *conf,
}
else if (strcmp(key, "font") == 0) {
- free(conf->font);
- conf->font = strdup(value);
+ //free(conf->font);
+ //conf->font = strdup(value);
+ char *copy = strdup(value);
+ for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ","))
+ tll_push_back(conf->fonts, strdup(font));
+ free(copy);
+ }
+
+ else if (strcmp(key, "workers") == 0) {
+ unsigned long count;
+ if (!str_to_ulong(value, 10, &count)) {
+ LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value);
+ return false;
+ }
+ conf->render_worker_count = count;
}
else {
@@ -393,7 +408,7 @@ config_load(struct config *conf)
*conf = (struct config) {
.term = strdup("foot"),
.shell = get_shell(),
- .font = strdup("monospace"),
+ .fonts = tll_init(),
.colors = {
.fg = default_foreground,
@@ -427,6 +442,8 @@ config_load(struct config *conf)
.cursor = 0,
},
},
+
+ .render_worker_count = sysconf(_SC_NPROCESSORS_ONLN),
};
char *path = get_config_path();
@@ -449,6 +466,7 @@ config_load(struct config *conf)
fclose(f);
out:
+ tll_push_back(conf->fonts, strdup("monospace"));
free(path);
return ret;
}
@@ -458,5 +476,6 @@ config_free(struct config conf)
{
free(conf.term);
free(conf.shell);
- free(conf.font);
+ //free(conf.font);
+ tll_free_and_free(conf.fonts, free);
}