aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2010-11-27 21:19:31 +0100
committerAurélien Aptel <aurelien.aptel@gmail.com>2010-11-27 21:19:31 +0100
commitaf75c433e56e74d2ad7a315d504a9303ea532f18 (patch)
tree7f9319cd7d2fe716173f16acf19b8036ba12c45b /st.c
parent41a4497ecfa66c1dbc65202ae80542c18c5d7793 (diff)
downloadst-af75c433e56e74d2ad7a315d504a9303ea532f18.tar.gz
st-af75c433e56e74d2ad7a315d504a9303ea532f18.zip
fix and clean ttyread(). buf wasn't static.
Diffstat (limited to 'st.c')
-rw-r--r--st.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/st.c b/st.c
index e988696..3829e73 100644
--- a/st.c
+++ b/st.c
@@ -606,24 +606,31 @@ dump(char c) {
606 606
607void 607void
608ttyread(void) { 608ttyread(void) {
609 char buf[BUFSIZ], *ptr; 609 static char buf[BUFSIZ];
610 static int buflen = 0;
611 char *ptr;
610 char s[UTF_SIZ]; 612 char s[UTF_SIZ];
611 int ret, br; 613 int charsize; /* size of utf8 char in bytes */
612 static int buflen = 0; 614 long utf8c;
613 long u; 615 int ret;
614 616
617 /* append read bytes to unprocessed bytes */
615 if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) 618 if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
616 die("Couldn't read from shell: %s\n", SERRNO); 619 die("Couldn't read from shell: %s\n", SERRNO);
617 else { 620
618 buflen += ret; 621 /* process every complete utf8 char */
619 for(ptr=buf; buflen>=UTF_SIZ||isfullutf8(ptr,buflen); buflen-=br) { 622 buflen += ret;
620 br = utf8decode(ptr, &u); 623 ptr = buf;
621 utf8encode(&u, s); 624 while(buflen >= UTF_SIZ || isfullutf8(ptr,buflen)) {
622 tputc(s); 625 charsize = utf8decode(ptr, &utf8c);
623 ptr += br; 626 utf8encode(&utf8c, s);
624 } 627 tputc(s);
625 memcpy(buf, ptr, buflen); 628 ptr += charsize;
629 buflen -= charsize;
626 } 630 }
631
632 /* keep any uncomplete utf8 char for the next call */
633 memcpy(buf, ptr, buflen);
627} 634}
628 635
629void 636void
@@ -1774,7 +1781,6 @@ kpress(XEvent *ev) {
1774 /* 3. X lookup */ 1781 /* 3. X lookup */
1775 default: 1782 default:
1776 if(len > 0) { 1783 if(len > 0) {
1777 buf[sizeof(buf)-1] = '\0';
1778 if(meta && len == 1) 1784 if(meta && len == 1)
1779 ttywrite("\033", 1); 1785 ttywrite("\033", 1);
1780 ttywrite(buf, len); 1786 ttywrite(buf, len);