diff options
author | pommicket <pommicket@gmail.com> | 2022-11-03 12:01:04 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-11-03 12:01:04 -0400 |
commit | 667284c3539546d269cee175cedd43671655499e (patch) | |
tree | 5e9a4119564c04bd00462fe59d6e0b72592bae63 /config.c | |
parent | 0c8dfbc15c074b2c1bff216aed844a462f46f59c (diff) |
expand ~ in settings paths
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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; } |