~torresjrjr/dc

f437c515b43132ed75b0689c63ffcee192f142ed — Byron Torres 1 year, 7 months ago 1c73944
handle IO errors
1 files changed, 21 insertions(+), 8 deletions(-)

M dc.ha
M dc.ha => dc.ha +21 -8
@@ 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) {