shithub: aplenty

Download patch

ref: e173b7ee0d3c26b54531c287d68aac00ec50f199
parent: 4dcc894ba6700ac9ade6a46b64334a1a59784229
author: B. Wilson <x@wilsonb.com>
date: Wed Jul 16 03:54:21 EDT 2025

Treat prompt as part of input line

--- a/aplenty.c
+++ b/aplenty.c
@@ -20,17 +20,20 @@
 		k = b[0]; b++;
 		t = atol(strtok(b, " \n"));
 		n = atol(strtok(nil, " \n"));
-		o = atol(strtok(nil, " \n"));
-		b = malloc(n);
-		seek(text, o, 0);
-		readn(text, b, n);
+		o = atol(b = strtok(nil, " \n"));
+		for(; *b != '\0'; b++); b++;
 		if(debug > 1)
-			fprintf(stderr, "ride: %c %ld %ld %ld\n", k, t, n, o);
+			fprintf(stderr, "ride: %c %ld %ld %ld %s\n", k, t, n, o);
 
-		if(strchr("po", k))
+		if(k == 'p')
 			write(out, b, n);
 
-		free(b);
+		if(k == 'o' && t != 14){ /* ignore echoed input */
+			b = malloc(n);
+			pread(text, b, n, o);
+			write(out, b, n);
+			free(b);
+		}
 	}
 }
 
@@ -37,7 +40,7 @@
 void
 handlerootevents(int wid, int in, int out){
 	Biobuf *bin, *bxdata, *btag;
-	int fdctl, fdevent, fdaddr, fdbody;
+	int fdevent, fdaddr, fdbody;
 	char o, t;        /* event origin, type */
 	long n, m, f, l;  /*       addr n, addr m, flag, len */
 	Rune *r;          /*       runes */
@@ -48,7 +51,6 @@
 	/* setup files */
 	snprintf(s, sizeof(s), "/mnt/acme/%i", wid);
 	chdir(s);
-	fdctl   = open("ctl", OWRITE);
 	fdevent = open("event", OWRITE);
 	fdaddr  = open("addr", ORDWR);
 	fdbody  = open("body", OWRITE);
@@ -59,8 +61,6 @@
 
 	/* initial prompt not setup by ride */
 	write(fdbody, "      ", 6);
-	write(fdaddr, "$", 1);
-	fprint(fdctl, "dot=addr");
 
 	/* event handle loop: cf acme(4):/event */
 	r = malloc((2+4*12 + 256)*sizeof(*r));
@@ -77,9 +77,8 @@
 
 		/* Ride-triggered edits */
 		if(o == 'E'){
-			seek(fdaddr, 0, 0);
-			write(fdaddr, "$", 1);
-			read(fdaddr, s, 12);
+			write(fdaddr, "$-/^/", 5);
+			pread(fdaddr, s, 12, 0);
 			n = atol(strtok(s, " "));
 			caddr = n;
 			continue;
@@ -89,12 +88,12 @@
 		if(!strchr("Dd", t)){
 			fprint(fdaddr, "#%ld,#%ld", n, m);
 			if(strchr("ILX", t)){
-				bxdata  = Bopen("xdata", OREAD);
+				bxdata = Bopen("xdata", OREAD);
 				for(i = 0, c = Bgetrune(bxdata); c >= 0; i++, c = Bgetrune(bxdata))
 					r[i] = c;
 				Bterm(bxdata);
 			} else if(strchr("ilx", t)) {
-				btag    = Bopen("tag", OREAD);
+				btag = Bopen("tag", OREAD);
 				for(i = 0, c = Bgetrune(btag); c >= 0; i++, c = Bgetrune(btag))
 					r[i] = c;
 				Bterm(btag);
@@ -103,10 +102,16 @@
 	
 			/* XXX: Only execute first line if multiline input */
 			if(t == 'I' && n >= caddr || t == 'X'){
-				fprint(fdaddr, "#%lld,$", caddr);
+				fprint(fdaddr, "#%lld,#%ld", caddr, m);
 				bxdata  = Bopen("xdata", OREAD);
 				ln = Brdline(bxdata, '\n');
-				if(ln) write(out, ln, Blinelen(bxdata));
+				if(ln){
+					write(out, ln, Blinelen(bxdata));
+					write(fdaddr, "$-/^/", 5);
+					pread(fdaddr, s, 12, 0);
+					n = atol(strtok(s, " "));
+					caddr = n;
+				}
 				Bterm(bxdata);
 			}
 		}
@@ -169,8 +174,7 @@
 	write(rctl, b, strlen(b));
 
 	/* connection id */
-	seek(rctl, 0, 0);
-	read(rctl, b, sizeof(b));
+	pread(rctl, b, sizeof(b), 0);
 	sprintf(p, "\n");
 	rid = atoi(strtok(b, p));
 
--