aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-07-30 12:44:16 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-07-30 12:57:28 +0000
commit02f0e0d912838572ff23fb02547eb3a6ac635d95 (patch)
tree60ff5f43a68dc1b5007f227775579ea1037fb9c4
parentdoc: foot.ini: indent lists (diff)
config: include: add support for ~-expansion
Closes #659
-rw-r--r--CHANGELOG.md2
-rw-r--r--config.c16
2 files changed, 17 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a97aa72f..d8c84365 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,8 @@
* Window title in the CSDs
(https://codeberg.org/dnkl/foot/issues/638).
* `-Ddocs=disabled|enabled|auto` meson command line option.
+* Support for `~`-expansion in the `include` directive
+ (https://codeberg.org/dnkl/foot/issues/659).
### Changed
diff --git a/config.c b/config.c
index f671e7e0..6b51c506 100644
--- a/config.c
+++ b/config.c
@@ -644,12 +644,24 @@ parse_section_main(const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno, bool errors_are_fatal)
{
if (strcmp(key, "include") == 0) {
- const char *include_path = value;
+ char *_include_path = NULL;
+ const char *include_path = NULL;
+
+ if (value[0] == '~' && value[1] == '/') {
+ const char *home_dir = get_user_home_dir();
+
+ int chars = snprintf(NULL, 0, "%s/%s", home_dir, &value[2]);
+ _include_path = malloc(chars + 1);
+ snprintf(_include_path, chars + 1, "%s/%s", home_dir, &value[2]);
+ include_path = _include_path;
+ } else
+ include_path = value;
if (include_path[0] != '/') {
LOG_AND_NOTIFY_ERR(
"%s:%d: [default]: %s: not an absolute path",
path, lineno, include_path);
+ free(_include_path);
return false;
}
@@ -659,6 +671,7 @@ parse_section_main(const char *key, const char *value, struct config *conf,
LOG_AND_NOTIFY_ERRNO(
"%s:%d: [default]: %s: failed to open",
path, lineno, include_path);
+ free(_include_path);
return false;
}
@@ -667,6 +680,7 @@ parse_section_main(const char *key, const char *value, struct config *conf,
fclose(include);
LOG_INFO("imported sub-configuration from %s", include_path);
+ free(_include_path);
return ret;
}