dc

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

commit 4c6e5dc4847bf0ce0c2ec0baecf06b489b2d19e4
parent 1454fba354853153985a55e39d75493c4649f170
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed, 24 Nov 2021 19:16:37 +0000

add ! subshell cmd

Diffstat:
Mdc.ha | 31++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/dc.ha b/dc.ha @@ -7,6 +7,7 @@ use getopt; use io; use math; use os; +use os::exec; use strconv; use strings; @@ -79,6 +80,35 @@ fn dc(in: io::handle) void = { // misc case 'q' => os::exit(0); + case '!' => + const cmdline = match (bufio::scanline(in)) { + case io::error => + fmt::fatal("dc: IO error"); + case io::EOF => + fmt::errorln("dc: no shell command given")?; + continue; + case input: []u8 => + yield match (strings::try_fromutf8(input)) { + case utf8::invalid => + fmt::errorln("dc: invalid shell command input")?; + continue; + case c: str => + yield c; + }; + }; + const argv = strings::split(cmdline, " "); + const cmd = exec::cmd(argv[0], argv[1..]...)?; + + const pipe = exec::pipe(); + exec::addfile(&cmd, pipe.1, os::stdout_file); + + const proc = exec::start(&cmd)?; + io::close(pipe.1); + + let data = io::drain(pipe.0); + io::close(pipe.0); + + const status = exec::wait(&proc); // printing case 'p' => if (len(S) == 0) { @@ -212,7 +242,6 @@ fn scan_number(in: io::handle) f64 = { case r: rune => yield r; }; - if (ascii::isdigit(r) || (!seen_decimal && r == '.')) { append(num, r: u32: u8); if (r == '.') {