dc

Tiny reverse polish desk calculator
Log | Files | Refs | README | LICENSE

commit f437c515b43132ed75b0689c63ffcee192f142ed
parent 1c73944df8806b9a34073bae3251457e07a5ca2f
Author: Byron Torres <b@torresjrjr.com>
Date:   Sat, 16 Apr 2022 02:28:27 +0100

handle IO errors

Diffstat:
Mdc.ha | 29+++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/dc.ha b/dc.ha @@ -42,14 +42,24 @@ export fn main() void = { defer io::close(file); const in = bufio::buffered(file, buf, []); - dc(&in); + match (dc(&in)) { + case void => + void; + case io::error => + fmt::fatal("dc: IO error"); + }; }; const in = bufio::buffered(os::stdin, buf, []); - dc(&in); + match (dc(&in)) { + case void => + void; + case io::error => + fmt::fatal("dc: IO error"); + }; }; -fn dc(in: *bufio::bufstream) void = { +fn dc(in: *bufio::bufstream) (void | io::error) = { for (true) { const r = match (bufio::scanrune(&in.stream)) { case utf8::invalid => @@ -98,18 +108,21 @@ fn dc(in: *bufio::bufstream) void = { }; }; const argv = strings::split(cmdline, " "); - const cmd = exec::cmd(argv[0], argv[1..]...)?; + if (len(argv) == 0) { + continue; + }; + const cmd = os::exec::cmd(argv[0], argv[1..]...)!; //TODO - const pipe = exec::pipe(); - exec::addfile(&cmd, pipe.1, os::stdout_file); + const pipe = os::exec::pipe(); + os::exec::addfile(&cmd, pipe.1, os::stdout_file); - const proc = exec::start(&cmd)?; + const proc = os::exec::start(&cmd)!; //TODO io::close(pipe.1); let data = io::drain(pipe.0); io::close(pipe.0); - const status = exec::wait(&proc); + const status = os::exec::wait(&proc); // printing case 'p' => if (len(S) == 0) {