aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2014-04-28 18:32:09 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2014-04-28 18:32:09 +0200
commit3764f38fc805a8846bd18f1d555a10227fd14e29 (patch)
tree2cdc4ea292102e561d4c2a5ae645cecef3489302 /st.c
parent53105cf74fde46229912275c073f8c0f219b05bb (diff)
downloadst-3764f38fc805a8846bd18f1d555a10227fd14e29.tar.gz
st-3764f38fc805a8846bd18f1d555a10227fd14e29.tar.bz2
st-3764f38fc805a8846bd18f1d555a10227fd14e29.zip
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.
Diffstat (limited to 'st.c')
-rw-r--r--st.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/st.c b/st.c
index 0425c72..9a979ea 100644
--- a/st.c
+++ b/st.c
@@ -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)
@@ -402,7 +403,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);
@@ -2300,17 +2300,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);
@@ -2439,16 +2434,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
@@ -2460,7 +2456,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) {