From 667284c3539546d269cee175cedd43671655499e Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 3 Nov 2022 12:01:04 -0400 Subject: expand ~ in settings paths --- config.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 537bb76..17dbf73 100644 --- a/config.c +++ b/config.c @@ -297,6 +297,7 @@ static void option_string_set(Settings *settings, const OptionString *opt, const static void parse_section_header(ConfigReader *cfg, char *line, ConfigPart *part) { #define SECTION_HEADER_HELP "Section headers should look like this: [(path//)(language.)section-name]" + Ted *ted = cfg->ted; char *closing = strchr(line, ']'); if (!closing) { config_err(cfg, "Unmatched [. " SECTION_HEADER_HELP); @@ -310,8 +311,17 @@ static void parse_section_header(ConfigReader *cfg, char *line, ConfigPart *part char *path_end = strstr(section, "//"); if (path_end) { size_t path_len = (size_t)(path_end - section); - // @TODO: expand ~ - part->context.path = strn_dup(section, path_len); + char path[TED_PATH_MAX]; + path[0] = '\0'; + + // expand ~ + if (section[0] == '~') { + str_cpy(path, sizeof path, ted->home); + ++section; + --path_len; + } + strn_cat(path, sizeof path, section, path_len); + part->context.path = str_dup(path); section = path_end + 2; } -- cgit v1.2.3