From c8b9286e2184b6d936e6007f81ead3367a4870b6 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 2 Jun 2020 08:48:31 -0700 Subject: feat: started port of st to wayland --- sys/cmd/term/term.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'sys/cmd/term/term.c') diff --git a/sys/cmd/term/term.c b/sys/cmd/term/term.c index a73e8f8..7bac567 100644 --- a/sys/cmd/term/term.c +++ b/sys/cmd/term/term.c @@ -13,10 +13,8 @@ #include #endif -/* Arbitrary sizes */ -#define UTF_INVALID 0xFFFD -#define UTF_SIZ 4 -#define ESC_BUF_SIZ (128*UTF_SIZ) +/* arbitrary sizes */ +#define ESC_BUF_SIZ (128*UTFmax) #define ESC_ARG_SIZ 16 #define STR_BUF_SIZ ESC_BUF_SIZ #define STR_ARG_SIZ ESC_ARG_SIZ @@ -28,7 +26,8 @@ #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) #define ISDELIM(u) (u && wcschr(worddelimiters, u)) -enum term_mode { +enum term_mode +{ MODE_WRAP = 1 << 0, MODE_INSERT = 1 << 1, MODE_ALTSCREEN = 1 << 2, @@ -39,18 +38,21 @@ enum term_mode { MODE_SIXEL = 1 << 7, }; -enum cursor_movement { +enum cursor_movement +{ CURSOR_SAVE, CURSOR_LOAD }; -enum cursor_state { +enum cursor_state +{ CURSOR_DEFAULT = 0, CURSOR_WRAPNEXT = 1, CURSOR_ORIGIN = 2 }; -enum charset { +enum charset +{ CS_GRAPHIC0, CS_GRAPHIC1, CS_UK, @@ -60,7 +62,8 @@ enum charset { CS_FIN }; -enum escape_state { +enum escape_state +{ ESC_START = 1, ESC_CSI = 2, ESC_STR = 4, /* OSC, PM, APC */ @@ -213,10 +216,10 @@ static int iofd = 1; static int cmdfd; static pid_t pid; -static ubyte utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; -static ubyte utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; -static rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; -static rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; +static ubyte utfbyte[UTFmax + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; +static ubyte utfmask[UTFmax + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; +static rune utfmin[UTFmax + 1] = { 0, 0, 0x80, 0x800, 0x10000}; +static rune utfmax[UTFmax + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; ssize_t xwrite(int fd, const char *s, size_t len) @@ -270,11 +273,11 @@ utf8decode(const char *c, rune *u, size_t clen) size_t i, j, len, type; rune udecoded; - *u = UTF_INVALID; + *u = RuneErr; if (!clen) return 0; udecoded = utf8decodebyte(c[0], &len); - if (!BETWEEN(len, 1, UTF_SIZ)) + if (!BETWEEN(len, 1, UTFmax)) return 1; for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); @@ -305,7 +308,7 @@ utf8encode(rune u, char *c) size_t len, i; len = utf8validate(&u, 0); - if (len > UTF_SIZ) + if (len > UTFmax) return 0; for (i = len - 1; i != 0; --i) { @@ -327,7 +330,7 @@ size_t utf8validate(rune *u, size_t i) { if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) - *u = UTF_INVALID; + *u = RuneErr; for (i = 1; *u > utfmax[i]; ++i) ; @@ -583,7 +586,7 @@ getsel(void) if (sel.ob.x == -1) return nil; - bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ; + bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTFmax; ptr = str = xmalloc(bufsize); /* append every set & selected glyph to the selection */ @@ -1179,7 +1182,7 @@ tsetchar(rune u, Glyph *attr, int x, int y) */ if (term.trantbl[term.charset] == CS_GRAPHIC0 && BETWEEN(u, 0x41, 0x7e) && vt100_0[u - 0x41]) - utf8decode(vt100_0[u - 0x41], &u, UTF_SIZ); + utf8decode(vt100_0[u - 0x41], &u, UTFmax); if (term.line[y][x].mode & ATTR_WIDE) { if (x+1 < term.col) { @@ -1987,7 +1990,7 @@ tdumpsel(void) void tdumpline(int n) { - char buf[UTF_SIZ]; + char buf[UTFmax]; Glyph *bp, *end; bp = &term.line[n][0]; @@ -2272,7 +2275,7 @@ eschandle(ubyte ascii) void tputc(rune u) { - char c[UTF_SIZ]; + char c[UTFmax]; int control; int width, len; Glyph *gp; @@ -2330,7 +2333,7 @@ tputc(rune u) * term.esc = 0; * strhandle(); */ - if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2) + if (strescseq.siz > (SIZE_MAX - UTFmax) / 2) return; strescseq.siz *= 2; strescseq.buf = xrealloc(strescseq.buf, strescseq.siz); -- cgit v1.2.1