~foura/libacme

2e2bacc37ba01af14d632a7f698c1899f631ad5c — james palmer 5 months ago 9065ae4
fix getrune, getdata, getc so aeventnext works
1 files changed, 23 insertions(+), 7 deletions(-)

M event.c
M event.c => event.c +23 -7
@@ 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");