shithub: riscv

Download patch

ref: 006b925a2aedeff506430c4b028a04687e8560ff
parent: a5c6374b77610cb2bcb794551475e092d990ef8b
author: Jacob Moody <moody@posixcafe.org>
date: Mon Jan 30 14:28:44 EST 2023

ktrans: simplify kbdtap read loop

we were not handling multi null delimted messages
with one read. This makes us a bit more uniform to
other handling on the system as well ... something about clever
code.

--- a/sys/src/cmd/ktrans/main.c
+++ b/sys/src/cmd/ktrans/main.c
@@ -696,7 +696,7 @@
 {
 	char m[Msgsize];
 	char buf[128];
-	char *p, *e;
+	char *p;
 	int n;
 
 	threadsetname("kbdtap");
@@ -705,7 +705,7 @@
 		n = read(kbdin, buf, sizeof buf);
 		if(n < 0)
 			break;
-		for(p = buf; p < buf+n;){
+		for(p = buf; p < buf+n; p += strlen(p) + 1){
 			switch(*p){
 			case 'c': case 'k': case 'K':
 			case 'z':
@@ -713,10 +713,7 @@
 			default:
 				goto Drop;
 			}
-			*m = *p++;
-			e = utfecpy(m+1, m + Msgsize - 1, p);
-			p += e - m;
-			p++;
+			strcpy(m, p);
 			if(send(input, m) == -1)
 				return;
 		}