shithub: libacme

Download patch

ref: 2e2bacc37ba01af14d632a7f698c1899f631ad5c
parent: 9065ae4ede744de5178566b6c577611e36a89873
author: james palmer <foura@biobuf.link>
date: Wed Jun 9 16:51:35 EDT 2021

fix getrune, getdata, getc so aeventnext works

--- a/event.c
+++ b/event.c
@@ -10,7 +10,7 @@
 {
 	char buf[1];
 	
-	if(read(fd, buf, sizeof(buf)) < 0)
+	if(read(fd, buf, sizeof(buf)) > 0)
 		return buf[0];
 	return -1;
 }
@@ -32,15 +32,30 @@
 	return n;
 }
 
-static long;
+static long
 getrune(int fd)
 {
+	int c, i;
 	Rune rune;
 	char buf[UTFmax];
 	
-	if(read(fd, buf, sizeof(buf)))
-		return chartorune(&rune, buf);
+	c = getc(fd);
+	if(c < Runeself)
+		return c;
+	buf[0] = c;
+	
+	for(i = 1; i < UTFmax;) {
+		c = getc(fd);
+		if(c < 0)
+			return c;
+		buf[i++] = c;
 		
+		if(fullrune(buf, i)) {
+			chartorune(&rune, buf);
+			return rune;
+		}
+	}
+	
 	return -1;
 }
 
@@ -48,14 +63,14 @@
 getdata(int fd, AEvent *e)
 {
 	int i, n, o;
-	long r;
+	Rune r;
 	
 	o = 0;
 	n = getnum(fd);
 	for(i = 0; i < n; i++) {
-		if((r = getrune(fd)) < 0)
+		if((r = getrune(fd)) == -1)
 			break;
-		o += runetochar(e->text + o, (Rune*)&r);
+		o += runetochar(e->text + o, &r);
 	}
 	
 	e->text[o] = 0;
@@ -73,6 +88,7 @@
 	e->type = getc(w->eventfd);
 	e->q0 = getnum(w->eventfd);
 	e->q1 = getnum(w->eventfd);
+	e->flags = getnum(w->eventfd);
 	e->ntext = getdata(w->eventfd, e);
 	if(getc(w->eventfd) != '\n') {
 		werrstr("unterminated message");