blob: 6a343ebfb8f842e3940bb69896f68079087705d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
};
};
|