summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSigrid <ftrvxmtrx@gmail.com>2020-03-09 13:21:50 +0100
committerSigrid <ftrvxmtrx@gmail.com>2020-03-09 13:21:50 +0100
commit27f36483d44a1f9fcf9a3ffefe688a0f12ace466 (patch)
tree1ed2189b0f11833eafdc94537a6c4582e09ff74b
parent50791b875552b0dc5748aa67c95776736f6ff4b7 (diff)
downloadplan9front-27f36483d44a1f9fcf9a3ffefe688a0f12ace466.tar.xz
sam: add $%dot (thanks kvik)
-rw-r--r--sys/src/cmd/sam/sam.h2
-rw-r--r--sys/src/cmd/sam/shell.c32
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");
}