implement Envcmd; # # Copyright © 2000 Vita Nuova Limited. All rights reserved. # include "sys.m"; include "draw.m"; Envcmd: 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; stdout := sys->fildes(1); stderr := sys->fildes(2); if (tl argv != nil) { sys->fprint(stderr, "usage: env \n"); exit; } pid := sys->pctl(0, nil); envf := "/prog/" + string pid + "/env"; efd := sys->open(envf, Sys->OREAD); if (efd == nil) { sys->bind("#p", "/prog", Sys->MREPL); efd = sys->open(envf, Sys->OREAD); if (efd == nil) { sys->fprint(stderr, "cannot open prog device\n"); exit; } } buf := array[256] of byte; while ((n := sys->read(efd, buf, len buf)) > 0) sys->write(stdout, buf, n); }