diff options
-rw-r--r-- | sys/src/cmd/sam/sam.h | 2 | ||||
-rw-r--r-- | sys/src/cmd/sam/shell.c | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/sys/src/cmd/sam/sam.h b/sys/src/cmd/sam/sam.h index f99fdae46..9839f8add 100644 --- a/sys/src/cmd/sam/sam.h +++ b/sys/src/cmd/sam/sam.h @@ -400,3 +400,5 @@ void outTsl(Hmesg, int, long); void outTsv(Hmesg, int, vlong); void outflush(void); int needoutflush(void); + +Posn nlcount(File *f, Posn p0, Posn p1); diff --git a/sys/src/cmd/sam/shell.c b/sys/src/cmd/sam/shell.c index 5028e6e4a..fe8f859cb 100644 --- a/sys/src/cmd/sam/shell.c +++ b/sys/src/cmd/sam/shell.c @@ -10,6 +10,36 @@ void checkerrs(void); Buffer cmdbuf; int cmdbufpos; +static void +updateenv(File *f) +{ + static int fd = -1; + int n; + char buf[64], *p, *e; + + if(f == nil){ + putenv("%", ""); + putenv("%dot", ""); + return; + } + + p = Strtoc(&f->name); + putenv("%", p); + free(p); + + p = buf; + e = buf+sizeof(buf); + p = seprint(p, e, "%lud", 1+nlcount(f, 0, f->dot.r.p1)); + p = seprint(p+1, e, "%lud", f->dot.r.p1); + p = seprint(p+1, e, "%lud", f->dot.r.p2); + n = p - buf; + if(fd == -1) + if((fd = create("/env/%dot", OWRITE, 0666)) < 0) + fprint(2, "updateenv create: %r\n"); + if(write(fd, buf, n) != n) + fprint(2, "updateenv write: %r\n"); +} + int plan9(File *f, int type, String *s, int nest) { @@ -93,7 +123,7 @@ plan9(File *f, int type, String *s, int nest) close(0); /* so it won't read from terminal */ open("/dev/null", 0); } - putenv("%", f == nil ? "" : Strtoc(&f->name)); + updateenv(f); execl(SHPATH, SH, "-c", Strtoc(&plan9cmd), nil); exits("exec"); } |