diff options
author | suigin <suigin@national.shitposting.agency> | 2015-05-05 13:13:21 -0700 |
---|---|---|
committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2015-05-06 08:15:41 +0200 |
commit | 38af006b5e4a36c77f25affbb3f7e28899db75ed (patch) | |
tree | 83ea7dc03f72f8b9219e8815dd8921d91dfbaa60 /st.c | |
parent | c990abfedf56cb8d3176fe6d5152ff65bb68bff0 (diff) | |
download | st-38af006b5e4a36c77f25affbb3f7e28899db75ed.tar.gz st-38af006b5e4a36c77f25affbb3f7e28899db75ed.zip |
Changed type for UTF-32 codepoints from long to uint_least32_t
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 52 |
1 files changed, 27 insertions, 25 deletions
@@ -183,11 +183,13 @@ typedef unsigned int uint; | |||
183 | typedef unsigned long ulong; | 183 | typedef unsigned long ulong; |
184 | typedef unsigned short ushort; | 184 | typedef unsigned short ushort; |
185 | 185 | ||
186 | typedef uint_least32_t Rune; | ||
187 | |||
186 | typedef XftDraw *Draw; | 188 | typedef XftDraw *Draw; |
187 | typedef XftColor Color; | 189 | typedef XftColor Color; |
188 | 190 | ||
189 | typedef struct { | 191 | typedef struct { |
190 | long u; /* character code */ | 192 | Rune u; /* character code */ |
191 | ushort mode; /* attribute flags */ | 193 | ushort mode; /* attribute flags */ |
192 | ushort fg; /* foreground */ | 194 | ushort fg; /* foreground */ |
193 | ushort bg; /* background */ | 195 | ushort bg; /* background */ |
@@ -389,20 +391,20 @@ static void tmoveato(int, int); | |||
389 | static void tnew(int, int); | 391 | static void tnew(int, int); |
390 | static void tnewline(int); | 392 | static void tnewline(int); |
391 | static void tputtab(int); | 393 | static void tputtab(int); |
392 | static void tputc(long); | 394 | static void tputc(Rune); |
393 | static void treset(void); | 395 | static void treset(void); |
394 | static void tresize(int, int); | 396 | static void tresize(int, int); |
395 | static void tscrollup(int, int); | 397 | static void tscrollup(int, int); |
396 | static void tscrolldown(int, int); | 398 | static void tscrolldown(int, int); |
397 | static void tsetattr(int *, int); | 399 | static void tsetattr(int *, int); |
398 | static void tsetchar(long, Glyph *, int, int); | 400 | static void tsetchar(Rune, Glyph *, int, int); |
399 | static void tsetscroll(int, int); | 401 | static void tsetscroll(int, int); |
400 | static void tswapscreen(void); | 402 | static void tswapscreen(void); |
401 | static void tsetdirt(int, int); | 403 | static void tsetdirt(int, int); |
402 | static void tsetdirtattr(int); | 404 | static void tsetdirtattr(int); |
403 | static void tsetmode(bool, bool, int *, int); | 405 | static void tsetmode(bool, bool, int *, int); |
404 | static void tfulldirt(void); | 406 | static void tfulldirt(void); |
405 | static void techo(long); | 407 | static void techo(Rune); |
406 | static void tcontrolcode(uchar ); | 408 | static void tcontrolcode(uchar ); |
407 | static void tdectest(char ); | 409 | static void tdectest(char ); |
408 | static int32_t tdefcolor(int *, int *, int); | 410 | static int32_t tdefcolor(int *, int *, int); |
@@ -465,11 +467,11 @@ static int y2row(int); | |||
465 | static void getbuttoninfo(XEvent *); | 467 | static void getbuttoninfo(XEvent *); |
466 | static void mousereport(XEvent *); | 468 | static void mousereport(XEvent *); |
467 | 469 | ||
468 | static size_t utf8decode(char *, long *, size_t); | 470 | static size_t utf8decode(char *, Rune *, size_t); |
469 | static long utf8decodebyte(char, size_t *); | 471 | static Rune utf8decodebyte(char, size_t *); |
470 | static size_t utf8encode(long, char *); | 472 | static size_t utf8encode(Rune, char *); |
471 | static char utf8encodebyte(long, size_t); | 473 | static char utf8encodebyte(Rune, size_t); |
472 | static size_t utf8validate(long *, size_t); | 474 | static size_t utf8validate(Rune *, size_t); |
473 | 475 | ||
474 | static ssize_t xwrite(int, const char *, size_t); | 476 | static ssize_t xwrite(int, const char *, size_t); |
475 | static void *xmalloc(size_t); | 477 | static void *xmalloc(size_t); |
@@ -524,8 +526,8 @@ static double defaultfontsize = 0; | |||
524 | 526 | ||
525 | static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; | 527 | static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; |
526 | static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; | 528 | static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; |
527 | static long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; | 529 | static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; |
528 | static long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; | 530 | static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; |
529 | 531 | ||
530 | /* Font Ring Cache */ | 532 | /* Font Ring Cache */ |
531 | enum { | 533 | enum { |
@@ -538,7 +540,7 @@ enum { | |||
538 | typedef struct { | 540 | typedef struct { |
539 | XftFont *font; | 541 | XftFont *font; |
540 | int flags; | 542 | int flags; |
541 | long unicodep; | 543 | Rune unicodep; |
542 | } Fontcache; | 544 | } Fontcache; |
543 | 545 | ||
544 | /* Fontcache is an array now. A new font will be appended to the array. */ | 546 | /* Fontcache is an array now. A new font will be appended to the array. */ |
@@ -586,9 +588,9 @@ xstrdup(char *s) { | |||
586 | } | 588 | } |
587 | 589 | ||
588 | size_t | 590 | size_t |
589 | utf8decode(char *c, long *u, size_t clen) { | 591 | utf8decode(char *c, Rune *u, size_t clen) { |
590 | size_t i, j, len, type; | 592 | size_t i, j, len, type; |
591 | long udecoded; | 593 | Rune udecoded; |
592 | 594 | ||
593 | *u = UTF_INVALID; | 595 | *u = UTF_INVALID; |
594 | if(!clen) | 596 | if(!clen) |
@@ -608,7 +610,7 @@ utf8decode(char *c, long *u, size_t clen) { | |||
608 | return len; | 610 | return len; |
609 | } | 611 | } |
610 | 612 | ||
611 | long | 613 | Rune |
612 | utf8decodebyte(char c, size_t *i) { | 614 | utf8decodebyte(char c, size_t *i) { |
613 | for(*i = 0; *i < LEN(utfmask); ++(*i)) | 615 | for(*i = 0; *i < LEN(utfmask); ++(*i)) |
614 | if(((uchar)c & utfmask[*i]) == utfbyte[*i]) | 616 | if(((uchar)c & utfmask[*i]) == utfbyte[*i]) |
@@ -617,7 +619,7 @@ utf8decodebyte(char c, size_t *i) { | |||
617 | } | 619 | } |
618 | 620 | ||
619 | size_t | 621 | size_t |
620 | utf8encode(long u, char *c) { | 622 | utf8encode(Rune u, char *c) { |
621 | size_t len, i; | 623 | size_t len, i; |
622 | 624 | ||
623 | len = utf8validate(&u, 0); | 625 | len = utf8validate(&u, 0); |
@@ -632,12 +634,12 @@ utf8encode(long u, char *c) { | |||
632 | } | 634 | } |
633 | 635 | ||
634 | char | 636 | char |
635 | utf8encodebyte(long u, size_t i) { | 637 | utf8encodebyte(Rune u, size_t i) { |
636 | return utfbyte[i] | (u & ~utfmask[i]); | 638 | return utfbyte[i] | (u & ~utfmask[i]); |
637 | } | 639 | } |
638 | 640 | ||
639 | size_t | 641 | size_t |
640 | utf8validate(long *u, size_t i) { | 642 | utf8validate(Rune *u, size_t i) { |
641 | if(!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) | 643 | if(!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) |
642 | *u = UTF_INVALID; | 644 | *u = UTF_INVALID; |
643 | for(i = 1; *u > utfmax[i]; ++i) | 645 | for(i = 1; *u > utfmax[i]; ++i) |
@@ -1339,7 +1341,7 @@ ttyread(void) { | |||
1339 | static int buflen = 0; | 1341 | static int buflen = 0; |
1340 | char *ptr; | 1342 | char *ptr; |
1341 | int charsize; /* size of utf8 char in bytes */ | 1343 | int charsize; /* size of utf8 char in bytes */ |
1342 | long unicodep; | 1344 | Rune unicodep; |
1343 | int ret; | 1345 | int ret; |
1344 | 1346 | ||
1345 | /* append read bytes to unprocessed bytes */ | 1347 | /* append read bytes to unprocessed bytes */ |
@@ -1368,7 +1370,7 @@ ttywrite(const char *s, size_t n) { | |||
1368 | void | 1370 | void |
1369 | ttysend(char *s, size_t n) { | 1371 | ttysend(char *s, size_t n) { |
1370 | int len; | 1372 | int len; |
1371 | long u; | 1373 | Rune u; |
1372 | 1374 | ||
1373 | ttywrite(s, n); | 1375 | ttywrite(s, n); |
1374 | if(IS_SET(MODE_ECHO)) | 1376 | if(IS_SET(MODE_ECHO)) |
@@ -1625,7 +1627,7 @@ tmoveto(int x, int y) { | |||
1625 | } | 1627 | } |
1626 | 1628 | ||
1627 | void | 1629 | void |
1628 | tsetchar(long u, Glyph *attr, int x, int y) { | 1630 | tsetchar(Rune u, Glyph *attr, int x, int y) { |
1629 | static char *vt100_0[62] = { /* 0x41 - 0x7e */ | 1631 | static char *vt100_0[62] = { /* 0x41 - 0x7e */ |
1630 | "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ | 1632 | "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ |
1631 | 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ | 1633 | 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ |
@@ -2440,7 +2442,7 @@ tputtab(int n) { | |||
2440 | } | 2442 | } |
2441 | 2443 | ||
2442 | void | 2444 | void |
2443 | techo(long u) { | 2445 | techo(Rune u) { |
2444 | if(ISCONTROL(u)) { /* control code */ | 2446 | if(ISCONTROL(u)) { /* control code */ |
2445 | if(u & 0x80) { | 2447 | if(u & 0x80) { |
2446 | u &= 0x7f; | 2448 | u &= 0x7f; |
@@ -2663,7 +2665,7 @@ eschandle(uchar ascii) { | |||
2663 | } | 2665 | } |
2664 | 2666 | ||
2665 | void | 2667 | void |
2666 | tputc(long u) { | 2668 | tputc(Rune u) { |
2667 | char c[UTF_SIZ]; | 2669 | char c[UTF_SIZ]; |
2668 | bool control; | 2670 | bool control; |
2669 | int width, len; | 2671 | int width, len; |
@@ -3262,7 +3264,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { | |||
3262 | int frcflags, charexists; | 3264 | int frcflags, charexists; |
3263 | int u8fl, u8fblen, u8cblen, doesexist; | 3265 | int u8fl, u8fblen, u8cblen, doesexist; |
3264 | char *u8c, *u8fs; | 3266 | char *u8c, *u8fs; |
3265 | long unicodep; | 3267 | Rune unicodep; |
3266 | Font *font = &dc.font; | 3268 | Font *font = &dc.font; |
3267 | FcResult fcres; | 3269 | FcResult fcres; |
3268 | FcPattern *fcpattern, *fontpattern; | 3270 | FcPattern *fcpattern, *fontpattern; |
@@ -3805,7 +3807,7 @@ kpress(XEvent *ev) { | |||
3805 | KeySym ksym; | 3807 | KeySym ksym; |
3806 | char buf[32], *customkey; | 3808 | char buf[32], *customkey; |
3807 | int len; | 3809 | int len; |
3808 | long c; | 3810 | Rune c; |
3809 | Status status; | 3811 | Status status; |
3810 | Shortcut *bp; | 3812 | Shortcut *bp; |
3811 | 3813 | ||