aboutsummaryrefslogtreecommitdiff
path: root/config.ha
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2024-11-15 03:09:58 +0100
committerJulian Hurst <ark@mansus.space>2024-11-15 03:11:19 +0100
commite0976a8c3f307d412d425c501c219d622a85555e (patch)
tree8750195076f52596be696fc2d519f5d691ff88fe /config.ha
parent7d984cbd69b92470dad43bd8783c01a3abbd6b84 (diff)
downloadhatask-e0976a8c3f307d412d425c501c219d622a85555e.tar.gz
Support an ini config file
Diffstat (limited to 'config.ha')
-rw-r--r--config.ha52
1 files changed, 52 insertions, 0 deletions
diff --git a/config.ha b/config.ha
index 4936492..a452665 100644
--- a/config.ha
+++ b/config.ha
@@ -1,4 +1,56 @@
+use dirs;
+use path;
+use format::ini;
+use os;
+use fs;
+use strings;
+use io;
+
type config = struct {
tasksdir: str,
context: str,
};
+
+type cerror = !(fs::error | path::error | ini::error);
+
+fn readconfig() (config | cerror) = {
+ const c = dirs::config("hatask");
+ const buf = path::init(c, "config.ini")?;
+ const cpath = path::string(&buf);
+ const f = os::open(cpath)?;
+ defer io::close(f)!;
+ const sc = ini::scan(f);
+ const c = config {
+ tasksdir = strings::dup("tasks"),
+ context = strings::dup("*"),
+ };
+ for (const en => ini::next(&sc)?) {
+ switch (en.1) {
+ case "tasksdir" =>
+ c.tasksdir = strings::dup(strings::trim(en.2));
+ case "context" =>
+ c.tasksdir = strings::dup(strings::trim(en.2));
+ case =>
+ void;
+ };
+ };
+ return c;
+};
+
+fn cfinish(cfg: *config) void = {
+ free(cfg.tasksdir);
+ free(cfg.context);
+};
+
+fn strcerror(e: cerror) str = {
+ return match (e) {
+ case let e: fs::error =>
+ yield fs::strerror(e);
+ case let e: path::error =>
+ yield path::strerror(e);
+ case let e: ini::error =>
+ yield ini::strerror(e);
+ case =>
+ abort();
+ };
+};