diff options
Diffstat (limited to 'config.ha')
| -rw-r--r-- | config.ha | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/config.ha b/config.ha new file mode 100644 index 0000000..6a343eb --- /dev/null +++ b/config.ha @@ -0,0 +1,57 @@ +use fmt; +use dirs; +use format::ini; +use time::chrono; +use path; +use io; +use fs; +use os; +use errors; + +type config = struct { + tz: chrono::locality, +}; + +type noexist = !str; + +type conferror = !(path::error | noexist | fs::error | chrono::tzdberror); + +fn loadconfig() (config | conferror) = { + const confdir = dirs::config("distamp"); + const buf = path::init()?; + const confpath = path::push(&buf, confdir, "config.ini")?; + const f = match (os::open(confpath)) { + case let e: errors::noentry => + fmt::errorln("warn: No config file found")!; + return config { + tz = chrono::LOCAL, + }; + case let e: fs::error => + return e; + case let f: io::file => + yield f; + }; + defer io::close(f)!; + const sc = ini::scan(f); + + let tz: chrono::locality = chrono::LOCAL; + for (const e => ini::next(&sc)!) { + if (e.1 == "tz") { + tz = chrono::tz(e.2)?; + }; + }; + return config { + tz = tz, + }; +}; + +fn strconferror(e: conferror) str = { + match (e) { + case let e: path::error => + return path::strerror(e); + case let e: fs::error => + return fs::strerror(e); + case let e: chrono::tzdberror => + return chrono::strerror(e); + }; +}; |
