diff options
| -rw-r--r-- | imp.ha | 40 |
1 files changed, 22 insertions, 18 deletions
@@ -76,11 +76,11 @@ export fn main() void = { case 'l' => list = true; case 'g' => - let spl = strings::split(opt.1, ","); + let spl = strings::split(opt.1, ",")!; defer free(spl); append(accfilter.groups, spl...)!; case 'm' => - let spl = strings::split(opt.1, ","); + let spl = strings::split(opt.1, ",")!; defer free(spl); append(accfilter.urls, spl...)!; case 'n' => @@ -111,6 +111,8 @@ export fn main() void = { fmt::fatal(os::exec::strerror(e)); case let e: io::error => fmt::fatal(io::strerror(e)); + case nomem => + fmt::fatal("Insufficient memory"); }; defer free(ini_data); @@ -119,6 +121,8 @@ export fn main() void = { yield e; case let e: format::ini::error => fmt::fatal(format::ini::strerror(e)); + case nomem => + fmt::fatal("Insufficient memory"); }; if (add) { @@ -182,17 +186,17 @@ fn printfilter(f: filter) void = { fmt::fprintln(os::stderr, "printing filter:")!; fmt::fprint(os::stderr, "accs: ")!; - let accnames = strings::join(", ", f.accnames...); + let accnames = strings::join(", ", f.accnames...)!; defer free(accnames); fmt::fprintln(os::stderr, accnames)!; fmt::fprint(os::stderr, "groups: ")!; - let groups = strings::join(", ", f.groups...); + let groups = strings::join(", ", f.groups...)!; defer free(groups); fmt::fprintln(os::stderr, groups)!; fmt::fprint(os::stderr, "urls: ")!; - let urls = strings::join(", ", f.urls...); + let urls = strings::join(", ", f.urls...)!; defer free(urls); fmt::fprintln(os::stderr, urls)!; @@ -269,7 +273,7 @@ fn account_free(acc: account) void = { free(acc.group); }; -fn parse(data: []u8) ([]account | format::ini::error) = { +fn parse(data: []u8) ([]account | format::ini::error | nomem) = { let scanner = format::ini::scan(&memio::fixed(data)); defer format::ini::finish(&scanner); @@ -285,22 +289,22 @@ fn parse(data: []u8) ([]account | format::ini::error) = { }; match (lookupaccount(accounts, entry.0)) { case void => - let name = strings::dup(entry.0); - let spl = strings::split(name, "/"); + let name = strings::dup(entry.0)?; + let spl = strings::split(name, "/")?; defer free(spl); let group = ""; if (len(spl) > 1) { - group = strings::join("/", spl[..len(spl) - 1]...); + group = strings::join("/", spl[..len(spl) - 1]...)?; }; let acc = account { name = name, group = group, ... }; - setfieldaccount(&acc, strings::dup(entry.1), strings::dup(entry.2)); + setfieldaccount(&acc, strings::dup(entry.1)?, strings::dup(entry.2)?); append(accounts, acc)!; case let acc: *account => - setfieldaccount(acc, strings::dup(entry.1), strings::dup(entry.2)); + setfieldaccount(acc, strings::dup(entry.1)?, strings::dup(entry.2)?); }; }; return accounts; @@ -331,7 +335,7 @@ fn setfieldaccount(acc: *account, key: str, val: str) void = { //defer free(val); // Handle quoted values - let valrunes = strings::torunes(val); + let valrunes = strings::torunes(val)!; defer free(valrunes); if (valrunes[0] == '"' && valrunes[len(valrunes)-1] == '"') { val = strings::trim(val, '"'); @@ -358,12 +362,12 @@ fn lookupaccount(accounts: []account, name: str) (*account | void) = { return; }; -fn decrypt(file: str) ([]u8 | os::exec::error | io::error) = { +fn decrypt(file: str) ([]u8 | os::exec::error | io::error | nomem) = { let cmd = os::exec::cmd("gpg", "-d", file)?; let pipe_stdout = os::exec::pipe(); - os::exec::addfile(&cmd, os::stdout_file, pipe_stdout.1); - os::exec::addfile(&cmd, os::stderr_file, os::exec::nullfd); + os::exec::addfile(&cmd, os::stdout_file, pipe_stdout.1)?; + os::exec::addfile(&cmd, os::stderr_file, os::exec::nullfd)?; let proc = os::exec::start(&cmd)?; io::close(pipe_stdout.1)?; @@ -383,7 +387,7 @@ fn decrypt(file: str) ([]u8 | os::exec::error | io::error) = { return out; }; -fn readin(termf: io::file) (str | io::error | utf8::invalid) = { +fn readin(termf: io::file) (str | io::error | utf8::invalid | nomem) = { const scanner = bufio::newscanner(termf); defer bufio::finish(&scanner); const line = match (bufio::scan_line(&scanner)?) { @@ -392,12 +396,12 @@ fn readin(termf: io::file) (str | io::error | utf8::invalid) = { case let line: const str => yield line; }; - return strings::dup(line); + return strings::dup(line)?; }; // Gets user input from the tty (supports pipes) fn getinput(text: str = "", noecho: bool = false) (str | tty::error | io::error - | utf8::invalid | errors::error) = { + | utf8::invalid | errors::error | nomem) = { let termf = tty::open()?; defer io::close(termf)!; |
