@@ 10,7 10,7 @@ getc(int fd)
{
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 @@ getnum(int fd)
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 @@ static int
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 @@ loop:
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");