~torresjrjr/dc

4c6e5dc4847bf0ce0c2ec0baecf06b489b2d19e4 — Byron Torres a month ago 1454fba
add ! subshell cmd
1 files changed, 30 insertions(+), 1 deletions(-)

M dc.ha
M dc.ha => dc.ha +30 -1
@@ 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 == '.') {