fix and clean ttyread(). buf wasn't static.
This commit is contained in:
parent
41a4497ecf
commit
af75c433e5
1 changed files with 20 additions and 14 deletions
34
st.c
34
st.c
|
@ -606,24 +606,31 @@ dump(char c) {
|
||||||
|
|
||||||
void
|
void
|
||||||
ttyread(void) {
|
ttyread(void) {
|
||||||
char buf[BUFSIZ], *ptr;
|
static char buf[BUFSIZ];
|
||||||
char s[UTF_SIZ];
|
|
||||||
int ret, br;
|
|
||||||
static int buflen = 0;
|
static int buflen = 0;
|
||||||
long u;
|
char *ptr;
|
||||||
|
char s[UTF_SIZ];
|
||||||
|
int charsize; /* size of utf8 char in bytes */
|
||||||
|
long utf8c;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* append read bytes to unprocessed bytes */
|
||||||
if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
|
if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
|
||||||
die("Couldn't read from shell: %s\n", SERRNO);
|
die("Couldn't read from shell: %s\n", SERRNO);
|
||||||
else {
|
|
||||||
buflen += ret;
|
/* process every complete utf8 char */
|
||||||
for(ptr=buf; buflen>=UTF_SIZ||isfullutf8(ptr,buflen); buflen-=br) {
|
buflen += ret;
|
||||||
br = utf8decode(ptr, &u);
|
ptr = buf;
|
||||||
utf8encode(&u, s);
|
while(buflen >= UTF_SIZ || isfullutf8(ptr,buflen)) {
|
||||||
tputc(s);
|
charsize = utf8decode(ptr, &utf8c);
|
||||||
ptr += br;
|
utf8encode(&utf8c, s);
|
||||||
}
|
tputc(s);
|
||||||
memcpy(buf, ptr, buflen);
|
ptr += charsize;
|
||||||
|
buflen -= charsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* keep any uncomplete utf8 char for the next call */
|
||||||
|
memcpy(buf, ptr, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1774,7 +1781,6 @@ kpress(XEvent *ev) {
|
||||||
/* 3. X lookup */
|
/* 3. X lookup */
|
||||||
default:
|
default:
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
buf[sizeof(buf)-1] = '\0';
|
|
||||||
if(meta && len == 1)
|
if(meta && len == 1)
|
||||||
ttywrite("\033", 1);
|
ttywrite("\033", 1);
|
||||||
ttywrite(buf, len);
|
ttywrite(buf, len);
|
||||||
|
|
Loading…
Reference in a new issue