From 94266b99d7a804008912f2354f8d8e7ed55d60a4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 13 Feb 2021 11:42:21 +0100 Subject: config: refactor: add str_to_wchars(), use it when parsing word-delimiters --- config.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 56acb0cf..939a8c7e 100644 --- a/config.c +++ b/config.c @@ -397,6 +397,25 @@ str_to_double(const char *s, double *res) return errno == 0 && *end == '\0'; } +static bool +str_to_wchars(const char *s, wchar_t **res, struct config *conf, + const char *path, int lineno, + const char *section, const char *key) +{ + *res = NULL; + + size_t chars = mbstowcs(NULL, s, 0); + if (chars == (size_t)-1) { + LOG_AND_NOTIFY_ERR("%s:%d: [%s]: %s: invalid string: %s", + path, lineno, section, key, s); + return false; + } + + *res = xmalloc((chars + 1) * sizeof(wchar_t)); + mbstowcs(*res, s, chars + 1); + return true; +} + static bool str_to_color(const char *s, uint32_t *color, bool allow_alpha, struct config *conf, const char *path, int lineno, @@ -712,18 +731,15 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "word-delimiters") == 0) { - size_t chars = mbstowcs(NULL, value, 0); - if (chars == (size_t)-1) { - LOG_AND_NOTIFY_ERR( - "%s:%d: [default]: word-delimiters: invalid string: %s", - path, lineno, value); + wchar_t *word_delimiters; + if (!str_to_wchars(value, &word_delimiters, conf, path, lineno, + "default", "word-delimiters")) + { return false; } - free(conf->word_delimiters); + conf->word_delimiters = word_delimiters; - conf->word_delimiters = xmalloc((chars + 1) * sizeof(wchar_t)); - mbstowcs(conf->word_delimiters, value, chars + 1); } else if (strcmp(key, "notify") == 0) { -- cgit v1.3 From 7bcab0106870b5c1d3de3990d31673b64ab3e9de Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 13 Feb 2021 11:42:40 +0100 Subject: config: add jump-label-letters option --- config.c | 12 ++++++++++++ config.h | 1 + 2 files changed, 13 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 939a8c7e..9ec6960f 100644 --- a/config.c +++ b/config.c @@ -739,7 +739,17 @@ parse_section_main(const char *key, const char *value, struct config *conf, } free(conf->word_delimiters); conf->word_delimiters = word_delimiters; + } + else if (strcmp(key, "jump-label-letters") == 0) { + wchar_t *letters; + if (!str_to_wchars(value, &letters, conf, path, lineno, + "default", "jump-label-letters")) + { + return false; + } + free(conf->jump_label_letters); + conf->jump_label_letters = letters; } else if (strcmp(key, "notify") == 0) { @@ -2142,6 +2152,7 @@ config_load(struct config *conf, const char *conf_path, .title = xstrdup("foot"), .app_id = xstrdup("foot"), .word_delimiters = xwcsdup(L",│`|:\"'()[]{}<>"), + .jump_label_letters = xwcsdup(L"sadfjklewcmpgh"), .size = { .type = CONF_SIZE_PX, .width = 700, @@ -2356,6 +2367,7 @@ config_free(struct config conf) free(conf.title); free(conf.app_id); free(conf.word_delimiters); + free(conf.jump_label_letters); free(conf.scrollback.indicator.text); free_spawn_template(&conf.notify); free_spawn_template(&conf.url_launch); diff --git a/config.h b/config.h index 68a13434..69930ec0 100644 --- a/config.h +++ b/config.h @@ -64,6 +64,7 @@ struct config { char *title; char *app_id; wchar_t *word_delimiters; + wchar_t *jump_label_letters; bool login_shell; struct { -- cgit v1.3