~laumann/hadb

10db5a6f9dd88bcff006bee103e4548a27efc489 — Thomas Bracht Laumann Jespersen 1 year, 2 months ago 6beb056
cmd/hadb: add getopt

Not many options, but at least it doesn't crash horribly if you don't
give it an argument.
1 files changed, 31 insertions(+), 2 deletions(-)

M cmd/hadb/main.ha
M cmd/hadb/main.ha => cmd/hadb/main.ha +31 -2
@@ 2,11 2,12 @@ use fmt;
use os;
use os::exec;
use time;
use getopt;

use format::dwarf;
use trace;

export fn main() void = {
fn run(prog: str) void = {
	fmt::printfln("bpinst = 0x{:02x}", bpinst)!;
	match (trace::fork()) {
	case let pid : trace::pid_t =>


@@ 24,8 25,36 @@ export fn main() void = {
		trace::cont(pid);
	case void =>
		trace::traceme();
		let prog = os::args[1];
		let cmd = exec::cmd(prog, prog)!;
		exec::exec(&cmd);
	};
};

fn usage(name: str) void = {
	fmt::printfln("usage: {} <executable-file>", name)!;
};

export fn main() void = {
	const cmd = getopt::parse(os::args,
		"hadb",
		('h', "print this help message and exit"),
		"executable-file"
	);
	defer getopt::finish(&cmd);

	for (let i = 0z; i < len(cmd.opts); i += 1) {
		const opt = cmd.opts[i];
		switch (opt.0) {
		case 'h' =>
			usage(os::args[0]);
			return;
		};
	};

	if (len(cmd.args) < 1) {
		usage(os::args[0]);
		return;
	};
	const prog = cmd.args[0];
	run(prog);
};