aboutsummaryrefslogtreecommitdiff
path: root/lib/config.ha
diff options
context:
space:
mode:
authorAutumn2026-08-23 11:44:35 +0100
committerAutumn2026-08-23 11:44:35 +0100
commit4708d5e010f8e787a06d2ec3361d70756d03d75f (patch)
treef2937193437394ae2464543696675f59936b83c3 /lib/config.ha
parent6337a8d398a223345e2e22ede0911d5e6dcab019 (diff)
[bunnytask] added config file support
Diffstat (limited to 'lib/config.ha')
-rw-r--r--lib/config.ha50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/config.ha b/lib/config.ha
new file mode 100644
index 0000000..def33dd
--- /dev/null
+++ b/lib/config.ha
@@ -0,0 +1,50 @@
+use dirs;
+use format::ini;
+use fs;
+use io;
+use strings;
+use os;
+
+export type config = struct { files: []str };
+
+fn load_item(scanner: *ini::scanner) (ini::entry | done) = {
+ match(ini::next(scanner)) {
+ case let entry: ini::entry => return entry;
+ case => return done;
+ };
+};
+
+// caller must free after use using [[config_free]]
+export fn config_read() (*config | fs::error | nomem) = {
+
+ const config_file = dirs::config("bunnytask");
+ const config_file = strings::concat(config_file, "/config.ini")?;
+ defer free(config_file);
+
+ // open
+ const config_file = os::open(config_file)?;
+ defer io::close(config_file)!;
+
+ const scanner = ini::scan(config_file);
+ defer ini::finish(&scanner);
+
+ // read
+ let files: []str = [];
+
+ for (let entry => load_item(&scanner)) {
+ if (strings::trim(entry.1) == "todo_file") {
+ // TODO shell expand
+ const file = strings::trim(entry.2);
+
+ append(files, strings::dup(file)?)?;
+ };
+ };
+
+ // return
+ return alloc(config { files = files })?;
+};
+
+export fn config_free(config: *config) void = {
+ strings::freeall(config.files);
+ free(config);
+};