Fix tputc control code handling

The patch 53105cf modified how control codes were detected, because
it tried to handle also C1 control codes (0x80-0x9f), that have
upper bit to 1, so they are multi byte character in utf8.
Code was checking the value of width in order to known that after
decoding the unicode point had a width of 1 byte, but it as incorrect
because this width is the columnb width.
dev
Roberto E. Vargas Caballero 2014-04-28 18:32:09 +02:00
parent 53105cf74f
commit 3764f38fc8
1 changed files with 8 additions and 12 deletions

20
st.c
View File

@ -70,8 +70,9 @@ char *argv0;
#define LEN(a) (sizeof(a) / sizeof(a)[0]) #define LEN(a) (sizeof(a) / sizeof(a)[0])
#define DEFAULT(a, b) (a) = (a) ? (a) : (b) #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
#define ISCONTROLC0(c) (BETWEEN((uchar) (c), 0, 0x1f)) #define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f))
#define ISCONTROLC1(c) (BETWEEN((uchar) (c), 0x80, 0x9f)) #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 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 ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
#define IS_SET(flag) ((term.mode & (flag)) != 0) #define IS_SET(flag) ((term.mode & (flag)) != 0)
@ -402,7 +403,6 @@ static void ttyread(void);
static void ttyresize(void); static void ttyresize(void);
static void ttysend(char *, size_t); static void ttysend(char *, size_t);
static void ttywrite(const 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 xdraws(char *, Glyph, int, int, int, int);
static void xhints(void); static void xhints(void);
@ -2300,17 +2300,12 @@ tputtab(int n) {
tmoveto(x, term.c.y); tmoveto(x, term.c.y);
} }
static inline bool
iscontrol(char c) {
return ISCONTROLC0(c) || ISCONTROLC1(c);
}
void void
techo(char *buf, int len) { techo(char *buf, int len) {
for(; len > 0; buf++, len--) { for(; len > 0; buf++, len--) {
char c = *buf; char c = *buf;
if(iscontrol(c)) { /* control code */ if(ISCONTROL(c)) { /* control code */
if(c & 0x80) { if(c & 0x80) {
c &= 0x7f; c &= 0x7f;
tputc("^", 1); tputc("^", 1);
@ -2439,16 +2434,17 @@ tputc(char *c, int len) {
if(len == 1) { if(len == 1) {
width = 1; width = 1;
ascii = *c; unicodep = ascii = *c;
} else { } else {
utf8decode(c, &unicodep, UTF_SIZ); utf8decode(c, &unicodep, UTF_SIZ);
width = wcwidth(unicodep); width = wcwidth(unicodep);
control = ISCONTROLC1(unicodep);
ascii = unicodep; ascii = unicodep;
} }
control = iscontrol(ascii) && width == 1;
if(IS_SET(MODE_PRINT)) if(IS_SET(MODE_PRINT))
tprinter(c, len); tprinter(c, len);
control = ISCONTROL(unicodep);
/* /*
* STR sequence must be checked before anything else * STR sequence must be checked before anything else
@ -2460,7 +2456,7 @@ tputc(char *c, int len) {
if(width == 1 && if(width == 1 &&
(ascii == '\a' || ascii == 030 || (ascii == '\a' || ascii == 030 ||
ascii == 032 || ascii == 033 || ascii == 032 || ascii == 033 ||
ISCONTROLC1(ascii))) { ISCONTROLC1(unicodep))) {
term.esc &= ~ESC_STR; term.esc &= ~ESC_STR;
term.esc |= ESC_STR_END; term.esc |= ESC_STR_END;
} else if(strescseq.len + len < sizeof(strescseq.buf) - 1) { } else if(strescseq.len + len < sizeof(strescseq.buf) - 1) {