summaryrefslogtreecommitdiff
path: root/appl/cmd/wmimport.b
blob: 2a0d3f3b0710a9a50cc13502c734583bba73da2c (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
implement Wmimport;

#
# Copyright © 2003 Vita Nuova Holdings Limited.
#

include "sys.m";
	sys: Sys;
include "draw.m";
	draw: Draw;
include "arg.m";
include "wmlib.m";
include "sh.m";

# turn wmexport namespace into a Draw->Context.
# usage: wmimport [-d /dev/draw] [-w /mnt/wm] cmd [arg...]

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

init(nil: ref Draw->Context, argv: list of string)
{
	sys = load Sys Sys->PATH;
	draw = load Draw Draw->PATH;
	wmlib := load Wmlib Wmlib->PATH;
	wmlib->init();
	sh := load Sh Sh->PATH;
	arg := load Arg Arg->PATH;

	devdraw := "/dev";
	mntwm := "/mnt/wm";
	arg->init(argv);
	arg->setusage("wmimport [-d /dev] [-w /mnt/wm] cmd [arg...]");
	while((opt := arg->opt()) != 0){
		case opt{
		'd' =>
			devdraw = arg->earg();
		'w' =>
			mntwm = arg->earg();
		* =>
			arg->usage();
		}
	}
	argv = arg->argv();
	if(argv == nil)
		arg->usage();
	arg = nil;
	(ok, nil) := sys->stat(mntwm + "/clone");
	if(ok == -1){
		sys->fprint(sys->fildes(2), "wmimport: no wm at %s\n", mntwm);
		raise "fail:no wm";
	}
	(ctxt, err) := wmlib->importdrawcontext(devdraw, mntwm);
	if(ctxt == nil){
		sys->fprint(sys->fildes(2), "wmimport: remote connect failed; %s\n", err);
		raise "fail:error";
	}

	e := sh->run(ctxt, argv);
	if(e != nil)
		raise "fail:" + e;
}