summaryrefslogtreecommitdiff
path: root/appl/cmd/nsbuild.b
blob: 36c5b86ae3f8a5b501279b01b88a9aa3008fc842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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";
	}
}