implement Cmds; include "sys.m"; sys: Sys; include "draw.m"; Context: import Draw; include "bufio.m"; bufio : Bufio; Iobuf: import bufio; include "cmd.m"; init(nil: ref Context, nil: list of string) { sys = load Sys Sys->PATH; bufio = load Bufio Bufio->PATH; } new_cmd() : ref Cmd { n := array[15] of byte; # too lazy to find out proper length clone := sys->open("/cmd/clone", Sys->OREAD); if(clone == nil) raise "perhaps you didn't do bind -a \"#C\" /"; n[sys->read(clone, n, len n -1)] = byte 0; ctl := sys->open("/cmd/" + string n + "/ctl", Sys->ORDWR); out := sys->open("/cmd/" + string n + "/data", Sys->OWRITE); in := sys->open("/cmd/" + string n + "/data", Sys->OREAD); return ref Cmd(nil, nil, clone, nil); } Cmd.wctl(c : self ref Cmd, msg : string) { c.ctl.puts(msg + "\n"); c.ctl.flush(); }