shithub: riscv

Download patch

ref: c33588da6fc879d6c355cd1df29b4c1a8f75f854
parent: 4df727b57afa439027df111205b29ed4590f6a72
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon May 22 14:40:03 EDT 2023

riow: fix kbdtap reading logic and make it a bit easier to comprehend

--- a/sys/src/cmd/riow.c
+++ b/sys/src/cmd/riow.c
@@ -444,7 +444,7 @@
 main(int argc, char **argv)
 {
 	char b[128];
-	int i, j, n;
+	int i, j, n, r;
 
 	for(n = 0; sticky[n] != nil; n++)
 		;
@@ -468,18 +468,19 @@
 		ws[i].vd = vd;
 	fprint(3, "%d\n", vd);
 
-	for(i = 0;;){
-		if((n = read(0, b+i, sizeof(b)-i)) <= 0)
+	for(n = 0;;){
+		if((r = read(0, b+n, sizeof(b)-n-1)) <= 0)
 			break;
-		n += i;
-		for(j = 0; j < n; j++){
+		n += r;
+		b[n] = 0;
+		for(i = j = 0; j <= n; j++){
 			if(b[j] == 0){
 				process(b+i);
 				i = j+1;
 			}
 		}
-		memmove(b, b+i, j-i);
-		i -= j;
+		n = j-i;
+		memmove(b, b+i, n);
 	}
 
 	exits(nil);