code: 9ferno

ref: 0f7ed22a95660fba1089ca842f0608e64500f473
dir: /appl/cmd/nsbuild.b/

View raw version
implement Nsbuild;

include "sys.m";
	sys: Sys;
include "draw.m";

include "newns.m";

stderr: ref Sys->FD;

Nsbuild: module
{
	init: fn(ctxt: ref Draw->Context, argv: list of string);
};

init(nil: ref Draw->Context, argv: list of string)
{
	sys = load Sys Sys->PATH;
	stderr = sys->fildes(2);

	ns := load Newns "/dis/lib/newns.dis";
	if(ns == nil) {
		sys->fprint(stderr, "nsbuild: can't load %s: %r", Newns->PATH);
		raise "fail:load";
	}

	if(len argv > 2) {
		sys->fprint(stderr, "Usage: nsbuild [nsfile]\n");
		raise "fail:usage";
	}

	nsfile := "namespace";
	if(len argv == 2)
		nsfile = hd tl argv;

   	e := ns->newns(nil, nsfile);
	if(e != ""){
		sys->fprint(stderr, "nsbuild: error building namespace: %s\n", e);
		raise "fail:newns";
	}
}