ref: bcf3db858c6461380f5695a4ed4edd25df52fb5f
parent: 28e7e475832d3d98201e947a0f2f5d7048a08182
author: kvik <kvik@a-b.xyz>
date: Mon Feb 3 16:41:38 EST 2020
Export dot through the environment var %dot
--- a/sam/sam.h
+++ b/sam/sam.h
@@ -272,6 +272,7 @@
void moveto(File*, Range);
File *newfile(void);
void nextmatch(File*, String*, Posn, int);
+Posn nlcount(File *, Posn, Posn);
void notifyf(void*, char*);
void panic(char*);
void printposn(File*, int);
--- a/sam/shell.c
+++ b/sam/shell.c
@@ -10,6 +10,26 @@
Buffer cmdbuf;
int cmdbufpos;
+static void
+updateenv(File *f)
+{+ char buf[64], *p;
+
+ if(f == nil){+ putenv("%", "");+ putenv("%dot", "");+ return;
+ }
+ p = Strtoc(&f->name);
+ putenv("%", p);+ free(p);
+ snprint(buf, sizeof buf, "%lud %lud %lud",
+ 1+nlcount(f, 0, f->dot.r.p1),
+ f->dot.r.p1,
+ f->dot.r.p2);
+ putenv("%dot", buf);+}
+
int
plan9(File *f, int type, String *s, int nest)
{@@ -93,7 +113,7 @@
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");}
--
⑨