Re: [dev] [st] utf broken after aa35bbd7a16c6c210a7574a8c45bbe939d5b2922

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Mon, 28 Apr 2014 17:08:39 +0200

Please, could you try this patch?

diff --git a/st.c b/st.c
index cb4b508..22cc0ce 100644
--- a/st.c
+++ b/st.c
_AT_@ -70,8 +70,9 @@ char *argv0;
 #define LEN(a) (sizeof(a) / sizeof(a)[0])
 #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
 #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
-#define ISCONTROLC0(c) (BETWEEN((uchar) (c), 0, 0x1f))
-#define ISCONTROLC1(c) (BETWEEN((uchar) (c), 0x80, 0x9f))
+#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f))
+#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
+#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
 #define IS_SET(flag) ((term.mode & (flag)) != 0)
_AT_@ -403,7 +404,6 @@ static void ttyread(void);
 static void ttyresize(void);
 static void ttysend(char *, size_t);
 static void ttywrite(const char *, size_t);
-static inline bool iscontrol(char);
 
 static void xdraws(char *, Glyph, int, int, int, int);
 static void xhints(void);
_AT_@ -2295,17 +2295,12 @@ tputtab(int n) {
         tmoveto(x, term.c.y);
 }
 
-static inline bool
-iscontrol(char c) {
- return ISCONTROLC0(c) || ISCONTROLC1(c);
-}
-
 void
 techo(char *buf, int len) {
         for(; len > 0; buf++, len--) {
                 char c = *buf;
 
- if(iscontrol(c)) { /* control code */
+ if(ISCONTROL(c)) { /* control code */
                         if(c & 0x80) {
                                 c &= 0x7f;
                                 tputc("^", 1);
_AT_@ -2448,16 +2443,17 @@ tputc(char *c, int len) {
 
         if(len == 1) {
                 width = 1;
- ascii = *c;
+ unicodep = ascii = *c;
         } else {
                 utf8decode(c, &unicodep, UTF_SIZ);
                 width = wcwidth(unicodep);
+ control = ISCONTROLC1(unicodep);
                 ascii = unicodep;
         }
 
- control = iscontrol(ascii) && width == 1;
         if(IS_SET(MODE_PRINT))
                 tprinter(c, len);
+ control = ISCONTROL(unicodep);
 
         /*
          * STR sequence must be checked before anything else
_AT_@ -2469,7 +2465,7 @@ tputc(char *c, int len) {
                 if(width == 1 &&
                    (ascii == '\a' || ascii == 030 ||
                     ascii == 032 || ascii == 033 ||
- ISCONTROLC1(ascii))) {
+ ISCONTROLC1(unicodep))) {
                         term.esc &= ~ESC_STR;
                         term.esc |= ESC_STR_END;
                 } else if(strescseq.len + len < sizeof(strescseq.buf) - 1) {
_AT_@ -2500,7 +2496,7 @@ tputc(char *c, int len) {
          * they must not cause conflicts with sequences.
          */
         if(control) {
- if (tcontrolcode(ascii))
+ if (tcontrolcode(unicodep))
                         return;
         } else if(term.esc & ESC_START) {
                 if(term.esc & ESC_CSI) {



-- 
Roberto E. Vargas Caballero
Received on Mon Apr 28 2014 - 17:08:39 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 28 2014 - 17:12:06 CEST