WILYADDR patch
Here are a couple patches against wily-0.2 for the following:
- When execing a command with an argument, set the WILYADDR environment
variable to the fully-qualified address of the argument, i.e., if the
argument is on line 14 of /etc/services, "WILYADDR=/etc/services:14". As
far as I can tell, this is how Acme handles this.
- If a "Put" fails, use foutput() to put the error message in +Errors.
Otherwise, attempting to write a read-only file fails silently (not
counting the diag() output). Also changed the "null bytes removed"
message to be more in the "Acme" address flavor :-)
diff -r -c -N dist/wily/external.c mine/wily/external.c
*** dist/wily/external.c Mon Sep 4 13:34:56 1995
--- mine/wily/external.c Wed Sep 6 10:58:28 1995
***************
*** 173,178 ****
--- 175,182 ----
int devnull;
char cmdbuf[MAXPATH];
char lblbuf[MAXPATH];
+ char addr[MAXPATH];
+ char addrbuf[MAXPATH + 16]; /* space for ":<line>" */
char *shell;
/* any errors in here, just die and we'll get collected by
parent */
***************
*** 203,208 ****
--- 207,220 ----
sprintf(lblbuf, "WILYLABEL=%s", label);
if(putenv(lblbuf))
diag("putenv %s", lblbuf);
+
+ if(arg && last_selection) {
+ text2label(last_selection, addr);
+ sprintf(addrbuf, "WILYADDR=%s:%d", addr,
+ text_toaddr(last_selection));
+ if(putenv(addrbuf))
+ diag("putenv %s", addrbuf);
+ }
/* find the shell */
shell = (char*)getenv("SHELL");
diff -r -c -N dist/wily/file.c mine/wily/file.c
*** dist/wily/file.c Mon Sep 4 13:34:56 1995
--- mine/wily/file.c Tue Sep 5 18:41:26 1995
***************
*** 54,60 ****
before = (ptr-buf);
after = stripnulls(buf, before);
if(before!= after) {
! foutput(pane->label, "null bytes removed from %s\n",
strrchr(pane->label,'/') + 1);
}
/* let's do it */
--- 54,60 ----
before = (ptr-buf);
after = stripnulls(buf, before);
if(before!= after) {
! foutput(pane->label, "%s: null bytes removed\n",
strrchr(pane->label,'/') + 1);
}
/* let's do it */
***************
*** 81,88 ****
int n,fd,nwritten;
Pane *pane;
if((fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC, 0600))<0){
! diag("couldn't open %s for write\n",fname);
return 1;
}
--- 81,90 ----
int n,fd,nwritten;
Pane *pane;
+ pane = text2pane(t);
+ assert(pane);
if((fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC, 0600))<0){
! foutput(pane->label, "%s: can't open: %s\n", fname,
strerror(errno));
return 1;
}
***************
*** 94,104 ****
close(fd);
if(nwritten!= n) {
! diag("write to %s failed\n", fname);
return 1;
}
- pane = text2pane(t);
- assert(pane);
pane->filestate = t->did;
text_modified(t);
return 0;
--- 96,104 ----
close(fd);
if(nwritten!= n) {
! foutput(pane->label, "%s: write failed: %s\n", fname,
strerror(errno));
return 1;
}
pane->filestate = t->did;
text_modified(t);
return 0;
diff -r -c -N dist/wily/proto.h mine/wily/proto.h
*** dist/wily/proto.h Mon Sep 4 13:34:58 1995
--- mine/wily/proto.h Wed Sep 6 11:00:42 1995
***************
*** 79,84 ****
--- 79,85 ----
void texthighlight2(Text *t, ulong p0, ulong p1, Fcode fc);
void text_goaddr(Text *t, char *addr);
+ int text_toaddr(Text *t);
void search(Text *t, char *,Bool);
void getexpand(Text *t, ulong p0, ulong p1, char *buf, int btn);
diff -r -c -N dist/wily/text.c mine/wily/text.c
*** dist/wily/text.c Mon Sep 4 13:35:05 1995
--- mine/wily/text.c Wed Sep 6 11:01:49 1995
***************
*** 159,164 ****
--- 159,183 ----
}
}
+ /*
+ * return line address of selection
+ */
+ int
+ text_toaddr(Text *t)
+ {
+ int cnt;
+ ulong p;
+ Rune nl = '\n';
+
+ cnt = 0; /* we are in line 'cnt' */
+ for(p=0;p<t->p0; p++) {
+ if (p==0 || t->text[p] == nl) {
+ cnt ++;
+ }
+ }
+ return cnt;
+ }
+
/* Is this rune part of an address?
* i.e. file:addr, file, :addr, ...
*/
Partial thread listing: